blob: d1290b54b5d6848281f9abc1ce5c8b0c1b07063f (
plain)
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
|
//#include <stdio.h>
#include "peripherie.h"
////////////////////////////////////////
// common defines
#define bit_is_set(mem, bv) (mem & bv)
#define bit_is_clear(mem, bv) (!(mem & bv))
#define loop_until_bit_is_set(mem, bv) do {} while( bit_is_clear(mem, bv))
#define loop_until_bit_is_clear(mem, bv) do {} while( bit_is_set(mem, bv))
////////////////////////////////////////
// uart functions
void uart_init( void)
{
uart0->scaler = UART_SCALER;
uart0->ctrl = UART_CONTROL_TX_ENABLE | UART_CONTROL_RX_ENABLE;
}
unsigned int uart_check_receiver()
{
return ( bit_is_set( uart0->status, UART_STATUS_DATA_READY) != 0);
}
char uart_getchar()
{
loop_until_bit_is_set(uart0->status, UART_STATUS_DATA_READY);
return uart0->data;
}
void uart_putchar_raw( char c)
{
#if UART_FIFOSIZE==1 || !defined(UART_FIFOSIZE)
loop_until_bit_is_set( uart0->status, UART_STATUS_TX_REG_EMPTY);
#else
loop_until_bit_is_clear( uart0->status, UART_STATUS_TX_FIFO_FULL);
#endif
uart0->data = c;
}
char uart_putchar( char c)
{
if (c == '\n')
uart_putchar_raw( '\r');
uart_putchar_raw( c);
return 0;
}
|