-
Notifications
You must be signed in to change notification settings - Fork 0
/
scif.c
62 lines (49 loc) · 974 Bytes
/
scif.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
#include "types.h"
#include "defs.h"
#include "scif.h"
int xv6_scif_init=0;
void scif_init(void)
{
xv6_scif_init = 1;
SCSCR = 0; /* disable everything */
SCFCR = FCR_RFRST | FCR_TFRST | /* clear FIFO */
FCR_TTRG_1 | FCR_RTRG_1; /* set FIFO trigger */
SCSMR = 0; /* 8 bits data, No parity, 1 stop bit */
SCBRR = SCIF_BPS_115200; /* set baudrate to 115200bps */
//SCFCR = FCR_TTRG_1 | FCR_RTRG_1;
SCFCR = 0;
IPRC_SCIF1(0xa);
SCSCR = SCR_RIE | SCR_TE | SCR_RE; /* enable transmit */
}
int scif_putc(unsigned char c)
{
while(!(SCFSR & FSR_TDFE));
SCFTDR = c;
SCFSR &= ~FSR_TDFE;
return c;
}
int scif_get(void)
{
unsigned char c;
unsigned int s;
s = SCFDR & 0xFF;
if (!s)
return -1;
c = SCFRDR;
return c;
}
/* interrupt handler */
void do_scif_read(void)
{
consoleintr(scif_get);
SCFSR &= ~(FSR_RDF | FSR_DR);
return;
}
int putc(int c)
{
scif_putc(c);
if(c == '\n') {
scif_putc('\r');
}
return c;
}