-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserial.c
92 lines (73 loc) · 1.57 KB
/
serial.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* serial.c
*/
#include "arch/arm/mach-pxa/pxa255.h"
#include "kernel/types.h"
/* --- PXA255 specific implementation --- */
void SerialOutputByte(const char);
int SerialInputByte(char *);
void SerialInit(void)
{
/* GP39, GP40, GP41 UART(10) */
GAFR1_L |= 0x000A8000;
GPDR1 |= 0x00000380;
/* 8-bit, 1 stop, no parity */
rFFLCR = 0x00000003;
/* Reset tx, rx FIFO. clear. FIFO enable */
rFFFCR = 0x00000007;
/* UART Enable Interrupt */
rFFIER = 0x00000040;
/* DLAB set=latch registers, DLAB clear= . */
rFFLCR |= 0x00000080;
/* baud rate */
rFFDLL = SERIAL_BAUD_115200;
/* DLAB clear */
rFFLCR &= 0xFFFFFF7F;
/* Transmit Shift Register, Transmit Holding Register, FIFO
* wait for ready */
while (!(rFFLSR & 0x00000040))
/* wait */ ;
return;
}
void SerialOutputByte(const char c)
{
/* FIFO
* wait for ready */
while ((rFFLSR & 0x00000020) == 0 )
/* wait */ ;
rFFTHR = ((ulong)c & 0xFF);
/* regardless of c=='\n' or "\n\r", the same output. */
if (c=='\n')
SerialOutputByte('\r');
}
int SerialInputByte(char *c)
{
/* FIFO */
if ((rFFLSR & 0x00000001) == 0) {
return 0;
}
else {
*(volatile char *) c = (char) rFFRBR;
return 1;
}
}
/**
* @brief check if serial is ready
* @retval 1 if the data received
*/
int SerialIsReadyChar(void)
{
/* Make sure the data is received. */
if (rFFLSR & 0x00000001)
return 1;
return 0;
}
/**
* @brief Receives a character from serial device
* @retval
*/
char SerialIsGetChar(void)
{
/* received data */
return (char) rFFRBR;
}