-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.c
51 lines (45 loc) · 1.4 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
volatile unsigned int * const USART1_PTR = (unsigned int *)0x40011004;
volatile unsigned int * const USART2_PTR = (unsigned int *)0x40004404;
volatile unsigned int * const USART3_PTR = (unsigned int *)0x40004804;
volatile unsigned int * const UART4_PTR = (unsigned int *)0x40004c04;
volatile unsigned int * const UART5_PTR = (unsigned int *)0x40005004;
volatile unsigned int * const USART6_PTR = (unsigned int *)0x40011404;
void display(const char *string, volatile unsigned int * uart_addr)//write stuff to UART address
{
while(*string != '\0'){
*uart_addr = *string;
string++;
}
}
void hex_to_str(int val, volatile unsigned int * uart_addr)//write an integer in hex text to a UART
{
unsigned int pos;
char c;
pos = 32;
while(1)
{
pos -= 4;
c = (val >> pos) & 0xF;
if (c>9) c += 0x37;
else c += 0x30;
*uart_addr = c;
if (pos == 0) break;
}
*uart_addr = 0x20;
}
int my_init(){
display("1\n", USART1_PTR);
display("2\n", USART2_PTR);
display("3\n", USART3_PTR);
display("4\n", UART4_PTR);
display("5\n", UART5_PTR);
display("6\n", USART6_PTR);
//dump all addrs to UART 1 as sanity check
hex_to_str((int)USART1_PTR, USART1_PTR);
hex_to_str((int)USART2_PTR, USART1_PTR);
hex_to_str((int)USART3_PTR, USART1_PTR);
hex_to_str((int)UART4_PTR, USART1_PTR);
hex_to_str((int)UART5_PTR, USART1_PTR);
hex_to_str((int)USART6_PTR, USART1_PTR);
display("\n", USART1_PTR);
}