-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
40 lines (33 loc) · 999 Bytes
/
main.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
#define UART_EV_TX 0x1
#define UART_BASE 0xe0001800
#define CSR_UART_RXTX_ADDR (UART_BASE + 0x00)
#define CSR_UART_TXFULL_ADDR (UART_BASE + 0x04)
#define CSR_UART_EV_PENDING_ADDR (UART_BASE + 0x10)
#define CSR_UART_EV_ENABLE_ADDR (UART_BASE + 0x14)
void putc(unsigned char c);
void puts(char *str);
void putc(unsigned char c) {
unsigned char r;
/* pending */
r = *(volatile unsigned int*)CSR_UART_EV_PENDING_ADDR;
*(volatile unsigned int*)CSR_UART_EV_PENDING_ADDR = r;
/* enable */
*(volatile unsigned int*)CSR_UART_EV_ENABLE_ADDR = UART_EV_TX;
/* wait for space */
do {
r = *(volatile unsigned int*)CSR_UART_TXFULL_ADDR;
} while (r);
/* write */
*(volatile unsigned int*)CSR_UART_RXTX_ADDR = c;
}
void puts(char *str) {
while (*str != '\0') putc(*(str++));
}
int main(void) {
puts("Hello World!\n");
for (int i = 0; i < 30; i++) {
puts("hello World again!\n");
}
puts("The end.\n");
return 0;
}