-
Notifications
You must be signed in to change notification settings - Fork 0
/
scif.c
75 lines (60 loc) · 1.29 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "types.h"
#include "defs.h"
#include "param.h"
#include "sh4.h"
void do_scif_read(void);
void scif_init(void)
{
SCIF.SCSCR = 0; /* disable everything */
SCIF.SCFCR = SCFCR_RFRST | SCFCR_TFRST | /* clear FIFO */
SCFCR_TTRG1 | SCFCR_RTRG1; /* set FIFO trigger */
SCIF.SCSMR = 0; /* 8 bits data, No parity, 1 stop bit */
SCIF.SCBRR = SCIF_BPS_VALUE; /* set baudrate to 115200bps */
SCIF.SCFCR = 0;
SCIF.SCSCR = SCSCR_RIE | SCSCR_TE | SCSCR_RE; /* enable transmit */
IPRC_SCIF(TINTLVL);
#if defined(SH7780) || defined(SH7751)
*IMSKC = INTR_CLEAR_SCIF;
#elif defined(RP1)
*IMSKC2 = IMSK_SCIF;
#endif
register_handler(SCIF_RXI_INTEVT, (handler_t) do_scif_read);
}
int scif_putc(int c)
{
while(!(SCIF.SCFSR & SCFSR_TDFE));
SCIF.SCFTDR = c;
SCIF.SCFSR &= ~(SCFSR_TDFE|SCFSR_TEND);
return c;
}
int scif_get(void)
{
unsigned char c;
unsigned int s;
#if defined(SH7751)
s = SCIF.SCFDR & 0xFF;
#elif defined(SH7780)
s = SCIF.SCFSR & SCFSR_RDF;
#elif defined(RP1)
s = SCIF.SCFSR & SCFSR_RDF;
#endif
if (!s)
return -1;
c = SCIF.SCFRDR;
SCIF.SCFSR &= ~(SCFSR_RDF);
return c;
}
/* interrupt handler */
void do_scif_read(void)
{
consoleintr(scif_get);
return;
}
int putc(int c)
{
scif_putc(c);
if(c == '\n') {
scif_putc('\r');
}
return c;
}