RasPi Direct Hardware Access
Integrated peripheral access without operating system drivers.
Main Page
Modules
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Macros
Groups
Pages
uart.h
Go to the documentation of this file.
1
35
#ifndef RASPI_UART_H
36
#define RASPI_UART_H
37
38
#include "
raspi/hw.h
"
39
#include <stdint.h>
40
43
static
inline
void
uart_init
(
unsigned
int
bitrate)
44
{
45
const
uint32_t UARTCLK = 3000000;
46
47
HW
.UART0.CR.B.UARTEN = 0;
48
while
(
HW
.UART0.FR.B.BUSY);
49
50
HW
.UART0.CR.U = 0;
51
HW
.UART0.CR.B.TXE = 1;
52
HW
.UART0.CR.B.RXE = 1;
53
54
HW
.UART0.LCRH.U = 0;
55
HW
.UART0.LCRH.B.FEN = 1;
56
HW
.UART0.LCRH.B.WLEN = 3;
57
58
HW
.UART0.IBRD.B.IBRD = UARTCLK/bitrate/16;
59
HW
.UART0.FBRD.B.FBRD = UARTCLK*4/bitrate;
60
HW
.UART0.CR.B.UARTEN = 1;
61
memory_barrier
();
62
63
gpio_configure
(14, Alt0);
64
gpio_configure
(15, Alt0);
65
memory_barrier
();
66
}
67
68
72
static
inline
int
uart_poll
(
int
num)
73
{
74
if
(num <= 0)
return
1;
75
return
!
HW
.UART0.FR.B.RXFE;
76
}
77
78
80
static
inline
uint8_t
uart_read
(
void
)
81
{
82
while
(
HW
.UART0.FR.B.RXFE);
83
return
HW
.UART0.DR.B.DATA;
84
}
85
86
88
static
inline
void
uart_write
(uint8_t data)
89
{
90
while
(
HW
.UART0.FR.B.TXFF);
91
HW
.UART0.DR.B.DATA = data;
92
}
93
94
96
static
inline
void
uart_flush
()
97
{
98
while
(!
HW
.UART0.FR.B.TXFE ||
HW
.UART0.FR.B.BUSY);
99
}
100
101
102
#endif
103
Generated on Fri Jan 17 2014 13:43:08 for RasPi Direct Hardware Access by
1.8.3.1