simple timer input push/pull, output open-drain
[cortex-from-scratch] / sysinfo.c
index 2d6f047..2792f14 100644 (file)
--- a/sysinfo.c
+++ b/sysinfo.c
@@ -1,58 +1,63 @@
+/* (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 <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
-#include <stm32.h>
-#include <mmap.h>
 
-#define MEM_SIZE       0x00010000 
-#define MEM_OFFSET     0x20000000
+#include <sys/robsys.h>
+#include <sys/mmap.h>
+
+#include <lib/tinyprintf.h>
+#include <lib/regfunc.h>
+
 
 uint32_t get_msp(void);
 
 void sysinfo() {
 
        uint32_t tmp = *MCU_ID;
-       uart_puts("# ROBSYS 0.1 LOADING...\n");
-       uart_puts("# DEVICE ID: ");
+       printf("# DEVICE ID: ");
 
        if (tmp & 0x414) 
-               uart_puts("HIGH DENSITY\n");
+               printf("HIGH DENSITY\n");
        else {
-               uart_puts("UNKNOWN\n");
+               printf("UNKNOWN\n");
        }
 
        tmp = (tmp >> 16);
-       uart_puts("# REVISION: ");
+       printf("# REVISION: ");
        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 = (MEM_OFFSET + MEM_SIZE) - current_stack;
-       uint32_t data_bss = &_endofbss - MEM_OFFSET;
-       uint32_t mem_free = MEM_SIZE - stack_usage - data_bss;
+       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;
 
-       uart_puts("# TOTAL MEMORY: ");
-       addrtohex(MEM_SIZE);
-       uart_putc('\n');
-       uart_puts("# FREE MEMORY: ");
-       addrtohex(mem_free);
-       uart_putc('\n');
-       uart_puts("# STACK USAGE: ");
-       addrtohex(stack_usage);
-       uart_putc('\n');
+       printf("# TOTAL MEMORY: %#x\n", SRAM_SIZE);
+       printf("# FREE MEMORY: %#x\n", mem_free);
+       printf("# STACK USAGE: %#x\n", stack_usage);
 
 }