X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=sysinfo.c;h=85ca01c731ac2bc3fc8c2a72814f21c1b33048fe;hb=9844c168a86cd64b8e698e82724de09eca344dae;hp=3971d3b9bef83ee7c461d3bae983073f982bb5f3;hpb=e9d02925e4e4cd03ef878ad9b4af6c94f1cac9cc;p=cortex-from-scratch diff --git a/sysinfo.c b/sysinfo.c index 3971d3b..85ca01c 100644 --- a/sysinfo.c +++ b/sysinfo.c @@ -1,40 +1,80 @@ +/* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL + * + * $LOG$ + * 2019/7/20 - ROBIN KRENS + * Initial version + * Display some system information, calculate + * the amount of SRAM available + * + * */ + #include #include #include -#include -#include + +#include +#include + +#include +#include +uint32_t get_msp(void); + void sysinfo() { uint32_t tmp = *MCU_ID; + printf("SYSTEM LOADING...\n\n"); + printf("DEV ID: "); - uart_puts("CHECKING SYS INFO\n"); - uart_puts("# DEVICE ID: "); - - if (tmp & 0x414) { - uart_puts("HIGH DENSITY\n"); - } + if (tmp & 0x414) + printf("H. DENSITY\n"); else { - uart_puts("UNKNOWN\n"); + printf("UNKNOWN\n"); } - tmp = (tmp >> 16); - uart_puts("# REVISION: "); -// addrtohex(tmp); + /* tmp = (tmp >> 16); + printf("REV: "); switch (tmp) { case 0x1000: - uart_puts("REVISION A\n"); + printf("REVISION A\n"); break; case 0x1001: - uart_puts("REVISION Z\n"); + printf("REVISION Z\n"); break; case 0x1003: - uart_puts("REVISION 1/2/3/X/Y\n"); + printf("REVISION 1/2/3/X/Y\n"); break; default: - uart_puts("UNKNOWN\n"); - } + printf("UNKNOWN\n"); + } */ + + extern char _endofbss; + + uint32_t current_stack = get_msp(); + uint32_t stack_usage = (SRAM_OFFSET + SRAM_SIZE) - current_stack; + uint32_t data_bss = (uint32_t) &_endofbss - SRAM_OFFSET; + uint32_t mem_free = SRAM_SIZE - stack_usage - data_bss; + + extern uint32_t KHEAP_SIZE; + + printf("TOTAL MEM: %#x\n", SRAM_SIZE); + printf("FREE MEM: %#x\n", mem_free); + printf("STACK USE: %#x\n", stack_usage); + printf("HEAP_SIZE: %#x\n\n", &KHEAP_SIZE); } +/* Get the master stack pointer's position + * Here we use a so-called naked function, + * that doesn't automatically push and pop */ + +uint32_t get_msp(void) __attribute__( ( naked ) ); +uint32_t get_msp(void) +{ + uint32_t msp = 0; + __asm__ volatile ("mrs %0, msp\n\t" + "mov r0, %0 \n\t" + "bx lr \n\t" : "=r" (msp) ); + return(msp); +}