uart small ping pong receive, update of register functions
[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 void addrtohex(uint32_t addr) {
13         char tmpbuf[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
14         memset(&hexbuf, 0, sizeof(uint32_t) * 8);
15
16         for (int i = 0; i < 8 ; i++) {
17                 uint32_t tmp = addr;
18                 tmp = tmp >> (i * 4);
19                 tmp = tmp & 0xF;
20                 if ((tmp >= 0) && tmp < 10) {
21                         hexbuf[i] = (char) tmp + 48;
22                 }
23                 else {
24                         hexbuf[i] = tmpbuf[tmp - 10];
25                 }
26         }
27
28         uart_puts("ADDRESS: 0x");
29          for (int i = 7; i >= 0; i--) {
30                 uart_putc(hexbuf[i]);
31         } 
32         //uart_puts(hexbuf);
33         uart_putc('\n');
34 }
35
36
37