-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.c
43 lines (35 loc) · 793 Bytes
/
os.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
#define TOP_OF_RAM 0x1ffff
volatile unsigned char *leds = (unsigned char *)TOP_OF_RAM;
volatile unsigned char *uart_out = (unsigned char *)TOP_OF_RAM - 1;
volatile unsigned char *uart_in = (unsigned char *)TOP_OF_RAM - 2;
static char *hello = "Hello World\r\n";
void uart_send_str(const char *str);
void uart_send_char(char ch);
char uart_read_char();
void run() {
uart_send_str(hello);
while (1) {
const char ch = uart_read_char();
uart_send_char(ch);
*leds = ch;
}
}
void uart_send_str(const char *str) {
while (*str) {
while (*uart_out)
;
*uart_out = *str;
str++;
}
}
void uart_send_char(const char ch) {
while (*uart_out)
;
*uart_out = ch;
}
char uart_read_char() {
char ch = 0;
while ((ch = *uart_in) == 0)
;
return ch;
}