eeprom, cases for n=1, n=2 and n>2
[cortex-from-scratch] / sysinfo.c
1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
2  * 
3  * $LOG$
4  * 2019/7/20 - ROBIN KRENS      
5  * Initial version 
6  * 
7  * */
8
9 #include <stdbool.h>
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include <sys/robsys.h>
14 #include <sys/mmap.h>
15
16 #include <lib/tinyprintf.h>
17 #include <lib/regfunc.h>
18
19
20 uint32_t get_msp(void);
21
22 void sysinfo() {
23
24         uint32_t tmp = *MCU_ID;
25         printf("# DEVICE ID: ");
26
27         if (tmp & 0x414) 
28                 printf("HIGH DENSITY\n");
29         else {
30                 printf("UNKNOWN\n");
31         }
32
33         tmp = (tmp >> 16);
34         printf("# REVISION: ");
35         switch  (tmp) {
36                 case 0x1000:
37                       printf("REVISION A\n");
38                       break;
39                 case 0x1001:
40                       printf("REVISION Z\n");
41                       break;
42                 case 0x1003:
43                       printf("REVISION 1/2/3/X/Y\n");
44                       break;
45                 default:
46                       printf("UNKNOWN\n");
47         }
48
49         extern char _endofbss;
50         
51         uint32_t current_stack = get_msp();
52         uint32_t stack_usage = (SRAM_OFFSET + SRAM_SIZE) - current_stack;
53         uint32_t data_bss = &_endofbss - SRAM_OFFSET;
54         uint32_t mem_free = SRAM_SIZE - stack_usage - data_bss;
55
56         printf("# TOTAL MEMORY: %#x\n", SRAM_SIZE);
57 //      cputs(regtohex(SRAM_SIZE));
58 //      cputchar('\n');
59         printf("# FREE MEMORY: %#x\n", mem_free);
60 //      cputs(regtohex(mem_free));
61 //      cputchar('\n');
62         printf("# STACK USAGE: %#x\n", stack_usage);
63 //      cputs(regtohex(stack_usage));
64 //      cputchar('\n');
65
66 }
67
68 /* Get the master stack pointer's position
69  * Here we use a so-called naked function, 
70  * that doesn't automatically push and pop  */
71
72 uint32_t get_msp(void) __attribute__( ( naked ) );
73 uint32_t get_msp(void)
74 {
75   uint32_t msp = 0;
76   __asm__ volatile ("mrs %0, msp\n\t" 
77                   "mov r0, %0 \n\t"
78                   "bx lr     \n\t"  : "=r" (msp) );
79   return(msp);
80 }