1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17:
18:
19: #include <tk/tkernel.h>
20:
21: #if USE_TMONITOR
22: #include "../../libtm.h"
23:
24: #ifdef IOTE_RZA2M
25: #if TM_COM_SERIAL_DEV
26:
27:
28: #define SCIFA_BASE 0xE8009000
29: #define SCIFA_SMR (SCIFA_BASE + 0x0000)
30: #define SCIFA_BRR (SCIFA_BASE + 0x0002)
31: #define SCIFA_SCR (SCIFA_BASE + 0x0004)
32: #define SCIFA_FTDR (SCIFA_BASE + 0x0006)
33: #define SCIFA_FSR (SCIFA_BASE + 0x0008)
34: #define SCIFA_FRDR (SCIFA_BASE + 0x000A)
35: #define SCIFA_FCR (SCIFA_BASE + 0x000C)
36: #define SCIFA_FDR (SCIFA_BASE + 0x000E)
37: #define SCIFA_SPTR (SCIFA_BASE + 0x0010)
38: #define SCIFA_LSR (SCIFA_BASE + 0x0012)
39: #define SCIFA_SEMR (SCIFA_BASE + 0x0014)
40: #define SCIFA_FTCR (SCIFA_BASE + 0x0016)
41:
42: #define SCR_TE 0x0020
43: #define SCR_RE 0x0010
44:
45: #define FSR_ER 0x0080
46: #define FSR_TEND 0x0040
47: #define FSR_TDFE 0x0020
48: #define FSR_BRK 0x0010
49: #define FSR_FER 0x0008
50: #define FSR_PER 0x0004
51: #define FSR_RDF 0x0002
52: #define FSR_DR 0x0001
53: #define FSR_ERROR (FSR_ER|FSR_BRK|FSR_FER|FSR_PER)
54:
55: #define FCR_TFRST 0x0004
56: #define FCR_RFRST 0x0002
57:
58: #define LSR_ORER 0x0001
59:
60:
61: EXPORT void tm_snd_dat( const UB* buf, INT size )
62: {
63: _UH d;
64: while(size--) {
65:
66: do {
67: d = in_h(SCIFA_FSR);
68: } while(!(d&FSR_TDFE));
69: out_b(SCIFA_FTDR, *buf++);
70: and_h(SCIFA_FSR, ~(FSR_TEND|FSR_TDFE));
71: }
72: while(!(in_h(SCIFA_FSR) & FSR_TEND));
73: }
74:
75: EXPORT void tm_rcv_dat( UB* buf, INT size )
76: {
77: while(size--) {
78: while(!(in_h(SCIFA_FSR) & (FSR_RDF|FSR_DR))) {
79: if((in_h(SCIFA_FSR) & FSR_ERROR) || (in_h(SCIFA_LSR) & LSR_ORER)) {
80:
81: and_h(SCIFA_SCR, ~SCR_RE);
82: or_h(SCIFA_FCR, FCR_RFRST);
83: and_h(SCIFA_FCR, ~FCR_RFRST);
84: and_h(SCIFA_FSR, ~FSR_ERROR);
85: and_h(SCIFA_LSR, ~LSR_ORER);
86: or_h(SCIFA_SCR, SCR_RE);
87: }
88: }
89: *buf++ = in_b(SCIFA_FRDR);
90: and_h(SCIFA_FSR, ~(FSR_RDF|FSR_DR));
91: }
92: return;
93: }
94:
95: EXPORT void tm_com_init(void)
96: {
97: out_h(SCIFA_SCR, 0);
98: out_h(SCIFA_FCR, FCR_RFRST|FCR_TFRST);
99:
100: and_h(SCIFA_FSR, ~(FSR_ER | FSR_BRK | FSR_DR));
101: and_h(SCIFA_LSR, ~LSR_ORER);
102:
103:
104:
105: out_h(SCIFA_SMR, 0);
106: out_b(SCIFA_SEMR, 0);
107: out_b(SCIFA_BRR, 17);
108:
109: out_h(SCIFA_FCR, 0x00000030);
110: or_h(SCIFA_SPTR, 0x00000003);
111: out_h(SCIFA_SCR, (SCR_TE|SCR_RE));
112:
113: return;
114: }
115:
116: #endif
117: #endif
118: #endif