small system SRAM info output
[cortex-from-scratch] / lib.c
1 #include <stdbool.h>
2 #include <stddef.h>
3 #include <stdint.h>
4 #include <stm32.h>
5 //#include <mmap.h>
6
7 /* Temporary libc functions, which can later be 
8  * replaced by a *real* library */
9
10 char hexbuf[8];
11
12 /* Still kind of a debug function */
13 void addrtohex(uint32_t addr) {
14         char tmpbuf[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
15         memset(&hexbuf, 0, sizeof(uint32_t) * 8);
16
17         for (int i = 0; i < 8 ; i++) {
18                 uint32_t tmp = addr;
19                 tmp = tmp >> (i * 4);
20                 tmp = tmp & 0xF;
21                 if ((tmp >= 0) && tmp < 10) {
22                         hexbuf[i] = (char) tmp + 48;
23                 }
24                 else {
25                         hexbuf[i] = tmpbuf[tmp - 10];
26                 }
27         }
28
29         //uart_puts("ADDRESS: 0x");
30          for (int i = 7; i >= 0; i--) {
31                 uart_putc(hexbuf[i]);
32         } 
33         //uart_puts(hexbuf);
34         //uart_putc('\n');
35 }
36
37
38