-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
37 lines (32 loc) · 796 Bytes
/
debug.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
#define UART3_THR (*(volatile unsigned int *)0x49020000)
#define UART3_RHR (*(volatile unsigned int *)0x49020000)
#define UART3_LSR (*(volatile unsigned int *)0x49020014)
#define TX_FIFO_E (1<<5)
#define RX_FIFO_E (1<<0)
// Prototypes
char dputchar( char c );
int debug( const char *s );
int main() {
debug( "Hello world!\n\r" );
return 0;
}
// This function sends the character c over UART3
// and will return also c
char dputchar( char c ) {
// wait until TX-Buffer is empty
while( ( UART3_LSR & TX_FIFO_E ) == 0 )
;
// send character
UART3_THR = c;
return c;
}
// This function sends a Null-terminates String via dputchar().
// It will return the number of transmitted chars.
int debug( const char *s ) {
int i = 0;
while( *s != 0 ) {
dputchar( *s++ );
i++;
}
return i;
}