-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaremetal_riscv_C_test.c
More file actions
61 lines (46 loc) · 863 Bytes
/
Copy pathbaremetal_riscv_C_test.c
File metadata and controls
61 lines (46 loc) · 863 Bytes
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
52
53
54
55
56
57
58
59
60
61
unsigned char* const UART = (unsigned char*) 0x10000000;
#define LSR_DATA_READY 0x01
static void tty_write(char data)
{
*UART = data;
}
static char tty_read(void)
{
unsigned char line_status_reg = *(UART + 5);
if ((line_status_reg & LSR_DATA_READY) == 0)
{
return 0xff;
}
return *UART;
}
static void print_string(const char *str)
{
while (*str != '\0')
{
tty_write(*str);
str++;
}
}
void c_test_main(void)
{
unsigned const char *hello_msg = "Hello from C !\n";
#if 0
while (*hello_msg != '\0')
{
*UART = *hello_msg;
hello_msg++;
}
#endif
print_string(hello_msg);
//*UART = 'A';
//*UART = 'B';
//*UART = 'C';
while (1)
{
char val = tty_read();
if (val != 0xff)
{
tty_write(val);
}
}
}