Landzo_K60Z_WebServer/src/system_utilities.c

125 lines
2.7 KiB
C

#include <stdio.h>
#include "board.h"
#include "clock_config.h"
#include "peripherals.h"
#include "pin_mux.h"
#define SRAM_BASE (0x60000000)
#define SRAM_SIZE (512 * 1024)
void print_hardware(void) {
uint32_t kinetis_revid = (SIM->SDID & SIM_SDID_REVID_MASK) >> SIM_SDID_REVID_SHIFT;
uint32_t kinetis_family = (SIM->SDID & SIM_SDID_FAMID_MASK) >> SIM_SDID_FAMID_SHIFT;
uint32_t kinetis_pinid = (SIM->SDID & SIM_SDID_PINID_MASK) >> SIM_SDID_PINID_SHIFT;
char *family_str = NULL;
switch(kinetis_family) {
case 0:
family_str = "K10";
break;
case 1:
family_str = "K20";
break;
case 2:
family_str = "K30";
break;
case 3:
family_str = "K40";
break;
case 4:
family_str = "K60";
break;
case 6:
family_str = "K50/K52";
break;
case 7:
family_str = "K51/K53";
break;
default:
family_str = "UNKNOWN";
break;
}
char *pin_str = NULL;
switch(kinetis_pinid) {
case 0x06:
pin_str = "80";
break;
case 0x07:
pin_str = "81";
break;
case 0x08:
pin_str = "100";
break;
case 0x09:
pin_str = "121";
break;
case 0x0A:
pin_str = "144";
break;
default:
pin_str = "UNKNOWN";
break;
}
char *rev_str = NULL;
switch(kinetis_revid) {
case 0:
rev_str = "1.0 (0M33Z)";
break;
case 1:
rev_str = "1.1 (0N30D)";
break;
case 2:
rev_str = "1.2 (1N30D/2N30D)";
break;
case 3:
rev_str = "1.4 (4N30D)";
break;
case 7:
rev_str = "1.8 (8N30D)";
break;
case 10:
rev_str = "2.2 (2N22D)";
break;
case 12:
rev_str = "2.4 (4N22D)";
break;
case 13:
rev_str = "2.5 (5N22D)";
break;
default:
rev_str = "UNKNOWN";
break;
}
printf("This is %s with Rev. (Mask Set): %s, %s pins.\r\n", family_str, rev_str, pin_str);
}
void sram_test(void) {
printf("SRAM write... ");
for(uint32_t i = SRAM_BASE; i < SRAM_BASE + SRAM_SIZE; i += 4) {
*(volatile uint32_t *)i = i;
}
printf("done, SRAM read... ");
for(uint32_t i = SRAM_BASE; i < SRAM_BASE + SRAM_SIZE; i += 4) {
if(*(volatile uint32_t *)i != i) {
printf("error.\r\n");
return;
}
}
printf("done.\r\n");
}
int set_rtc_time(int sec) {
RTC->SR &= ~(RTC_SR_TCE_MASK);
RTC->TSR = sec;
RTC->SR |= RTC_SR_TCE_MASK;
return 0;
}