1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | *
|
---|
9 | * Copyright (C) 2004 by SEIKO EPSON Corp, JAPAN
|
---|
10 | *
|
---|
11 | * ä¸è¨è使¨©è
|
---|
12 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
13 | * ã«ãã£ã¦å
|
---|
14 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
15 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
16 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
17 | å¸ï¼ä»¥ä¸ï¼
|
---|
18 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
19 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
20 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
21 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
22 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
23 | * ç¨ã§ããå½¢ã§åé
|
---|
24 | å¸ããå ´åã«ã¯ï¼åé
|
---|
25 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
26 | * è
|
---|
27 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
28 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
29 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
30 | * ç¨ã§ããªãå½¢ã§åé
|
---|
31 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
32 | * ã¨ï¼
|
---|
33 | * (a) åé
|
---|
34 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
35 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
36 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
37 | * (b) åé
|
---|
38 | å¸ã®å½¢æ
|
---|
39 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
40 | * å ±åãããã¨ï¼
|
---|
41 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
42 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
43 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
44 | 責ãããã¨ï¼
|
---|
45 | *
|
---|
46 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
47 | ã
|
---|
48 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
49 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
50 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
51 | *
|
---|
52 | */
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * ã¿ã¼ã²ããä¾åã·ãªã¢ã«I/Oã¢ã¸ã¥ã¼ã«(LUXUN2)
|
---|
56 | */
|
---|
57 |
|
---|
58 | #ifndef _HW_SERIAL_H_
|
---|
59 | #define _HW_SERIAL_H_
|
---|
60 |
|
---|
61 | #include "s_services.h"
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * ã·ãªã¢ã«I/Oã®å²è¾¼ã¿ãã³ãã©ã®ãã¯ã¿çªå·
|
---|
65 | */
|
---|
66 | #define INHNO_SERIAL_IN S1C33_INHNO_SERIAL0RX
|
---|
67 | #define INHNO_SERIAL_OUT S1C33_INHNO_SERIAL0TX
|
---|
68 | #define INHNO_SERIAL_ERR S1C33_INHNO_SERIAL0ERR
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * ã³ã¼ã«ããã¯ã«ã¼ãã³ã®èå¥çªå·
|
---|
72 | */
|
---|
73 | #define SIO_ERDY_SND 1 /* éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
74 | #define SIO_ERDY_RCV 2 /* åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
75 |
|
---|
76 | #define INDEX_SIO(sioid) ((UINT)((sioid) - 1))
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * SIOå²ãè¾¼ã¿è¦å ãã©ã° ãããä½ç½®
|
---|
80 | */
|
---|
81 | #define SIO_INT_ERR 0x01
|
---|
82 | #define SIO_INT_RCV 0x02
|
---|
83 | #define SIO_INT_SND 0x04
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * ã¨ã©ã¼ãã©ã° ãããä½ç½®
|
---|
87 | */
|
---|
88 | #define SIO_ERR_FRAME 0x10
|
---|
89 | #define SIO_ERR_PARITY 0x08
|
---|
90 | #define SIO_ERR_OVERRUN 0x04
|
---|
91 |
|
---|
92 | #ifndef _MACRO_ONLY
|
---|
93 | /*
|
---|
94 | * ã·ãªã¢ã«ãã¼ãã®ãã¼ãã¦ã§ã¢ä¾åæ
|
---|
95 | å ±ã®å®ç¾©
|
---|
96 | */
|
---|
97 | typedef struct {
|
---|
98 | UB ch_no; /* SIOãã£ãã«çªå· */
|
---|
99 | UB err_vector; /* éä¿¡ã¨ã©ã¼å²ãè¾¼ã¿ãã¯ã¿çªå· */
|
---|
100 | UB rx_vector; /* åä¿¡å²ãè¾¼ã¿ãã¯ã¿çªå· */
|
---|
101 | UB tx_vector; /* éä¿¡å®äºå²ãè¾¼ã¿ãã¯ã¿çªå· */
|
---|
102 | } SIOPINIB;
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡ãããã¯
|
---|
106 | */
|
---|
107 | typedef struct {
|
---|
108 | const SIOPINIB *inib; /* åæåããã㯠*/
|
---|
109 | VP_INT exinf; /* æ¡å¼µæ
|
---|
110 | å ± */
|
---|
111 | BOOL openflag; /* ãªã¼ãã³æ¸ã¿ãã©ã° */
|
---|
112 | BOOL tx_cbrflag; /* éä¿¡ã³ã¼ã«ããã¯å®è¡ãã©ã°*/
|
---|
113 | BOOL rx_cbrflag; /* åä¿¡ã³ã¼ã«ããã¯å®è¡ãã©ã°*/
|
---|
114 | } SIOPCB;
|
---|
115 |
|
---|
116 | extern SIOPCB siopcb_table[TNUM_PORT];
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * å¤é¨é¢æ°ã®åç
|
---|
120 | §
|
---|
121 | */
|
---|
122 | extern void sio_initialize (void);
|
---|
123 | extern void sio_ena_cbr(SIOPCB *siopcb, UINT cbrtn);
|
---|
124 | extern void sio_dis_cbr(SIOPCB *siopcb, UINT cbrtn);
|
---|
125 | extern void serial_handler_in(ID portid);
|
---|
126 | extern void serial_handler_out(ID portid);
|
---|
127 | extern void sio_ierdy_snd(VP_INT exinf);
|
---|
128 | extern void sio_ierdy_rcv(VP_INT exinf);
|
---|
129 | extern ER ena_int(INTNO);
|
---|
130 | extern ER dis_int(INTNO);
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * ã·ãªã¢ã«ãã¼ãã®åæå
|
---|
134 | */
|
---|
135 | Inline SIOPCB
|
---|
136 | *sio_opn_por(ID siopid, VP_INT exinf)
|
---|
137 | {
|
---|
138 | B temp;
|
---|
139 |
|
---|
140 | /*
|
---|
141 | * å²ãè¾¼ã¿ã®ç¦æ¢
|
---|
142 | */
|
---|
143 | if(siopid == 1){
|
---|
144 | dis_int(S1C33_INHNO_SERIAL0RX);
|
---|
145 | dis_int(S1C33_INHNO_SERIAL0TX);
|
---|
146 | #ifdef SIO_ERR_HANDLER
|
---|
147 | dis_int(S1C33_INHNO_SERIAL0ERR);
|
---|
148 | #endif
|
---|
149 | } else {
|
---|
150 | dis_int(S1C33_INHNO_SERIAL1RX);
|
---|
151 | dis_int(S1C33_INHNO_SERIAL1TX);
|
---|
152 | #ifdef SIO_ERR_HANDLER
|
---|
153 | dis_int(S1C33_INHNO_SERIAL1ERR);
|
---|
154 | #endif
|
---|
155 | }
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * ã·ãªã¢ã«I/Fã®è¨å®
|
---|
159 | *
|
---|
160 | * 8bit調æ©åæ ããªãã£ãªã ã¹ãããããã1bit å¤é¨ã¯ããã¯
|
---|
161 | */
|
---|
162 | ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bControl = 0x07;
|
---|
163 |
|
---|
164 | ((s1c33Port_t *)S1C33_PORT_BASE)->stPPort[INDEX_SIO(siopid)].bFuncSwitch = 0x07;
|
---|
165 | ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bIrDA = 0x00;
|
---|
166 |
|
---|
167 | ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bControl = 0xc7;
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * å²è¾¼ã¿è¦å ãã¯ãªã¢
|
---|
171 | */
|
---|
172 | (*(s1c33Intc_t *) S1C33_INTC_BASE).bIntFactor[6] |= (0x07 << INDEX_SIO(siopid));
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * åä¿¡ãããã¡ã®ã¯ãªã¢
|
---|
176 | */
|
---|
177 | temp = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bRxd;
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * å¶å¾¡æ
|
---|
181 | å ±ã®è¨å®
|
---|
182 | */
|
---|
183 | siopcb_table[INDEX_SIO(siopid)].openflag = TRUE;
|
---|
184 | if(exinf != NULL){
|
---|
185 | siopcb_table[INDEX_SIO(siopid)].exinf = exinf;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * å²ãè¾¼ã¿ã®è¨±å¯
|
---|
190 | */
|
---|
191 | if(siopid == 1){
|
---|
192 | ena_int(S1C33_INHNO_SERIAL0RX);
|
---|
193 | ena_int(S1C33_INHNO_SERIAL0TX);
|
---|
194 | #ifdef SIO_ERR_HANDLER
|
---|
195 | ena_int(S1C33_INHNO_SERIAL0ERR);
|
---|
196 | #endif
|
---|
197 | } else {
|
---|
198 | ena_int(S1C33_INHNO_SERIAL1RX);
|
---|
199 | ena_int(S1C33_INHNO_SERIAL1TX);
|
---|
200 | #ifdef SIO_ERR_HANDLER
|
---|
201 | ena_int(S1C33_INHNO_SERIAL1ERR);
|
---|
202 | #endif
|
---|
203 | }
|
---|
204 |
|
---|
205 | return (&(siopcb_table[INDEX_SIO(siopid)]));
|
---|
206 | }
|
---|
207 |
|
---|
208 | /*
|
---|
209 | * éä¿¡ã®åæ¢
|
---|
210 | */
|
---|
211 | Inline void
|
---|
212 | sio_cls_por(SIOPCB *siopcb)
|
---|
213 | {
|
---|
214 | UB ch_no;
|
---|
215 |
|
---|
216 | ch_no = siopcb->inib->ch_no;
|
---|
217 | /*
|
---|
218 | * 転éå®äºãå¾
|
---|
219 | ã¤
|
---|
220 | */
|
---|
221 | while(((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus & 0x20){
|
---|
222 | ;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /*
|
---|
226 | * éä¿¡ãç¦æ¢ãã
|
---|
227 | */
|
---|
228 | ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bControl = 0x07;
|
---|
229 |
|
---|
230 | return;
|
---|
231 | }
|
---|
232 |
|
---|
233 | /*
|
---|
234 | * éä¿¡æ©è½ã®ç¶æ
|
---|
235 | ãåå¾
|
---|
236 | */
|
---|
237 | Inline BOOL
|
---|
238 | sio_get_txready(UB ch_no)
|
---|
239 | {
|
---|
240 | UB bSioSts;
|
---|
241 |
|
---|
242 | bSioSts = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus;
|
---|
243 |
|
---|
244 | return(!(bSioSts & 0x20));
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * åä¿¡æ©è½ã®ç¶æ
|
---|
249 | ãåå¾
|
---|
250 | */
|
---|
251 | Inline BOOL
|
---|
252 | sio_get_rxready(UB ch_no)
|
---|
253 | {
|
---|
254 | UB bSioSts;
|
---|
255 |
|
---|
256 | bSioSts = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus;
|
---|
257 |
|
---|
258 | return(bSioSts & 0x01);
|
---|
259 | }
|
---|
260 |
|
---|
261 | /*
|
---|
262 | * åä¿¡ãã1æåãèªã¿è¾¼ã
|
---|
263 | */
|
---|
264 | Inline INT
|
---|
265 | sio_rcv_chr(SIOPCB *siopcb)
|
---|
266 | {
|
---|
267 | BOOL blRxSts;
|
---|
268 | UB ch_no;
|
---|
269 |
|
---|
270 |
|
---|
271 | ch_no = siopcb->inib->ch_no;
|
---|
272 | blRxSts = sio_get_rxready(ch_no);
|
---|
273 |
|
---|
274 | if(blRxSts){
|
---|
275 | return (((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bRxd);
|
---|
276 | }
|
---|
277 |
|
---|
278 | return (-1);
|
---|
279 | }
|
---|
280 |
|
---|
281 | /*
|
---|
282 | * éä¿¡ãã1æåãæ¸ãè¾¼ã
|
---|
283 | */
|
---|
284 | Inline BOOL
|
---|
285 | sio_snd_chr(SIOPCB *siopcb, char c)
|
---|
286 | {
|
---|
287 | BOOL blTxSts;
|
---|
288 | UB ch_no;
|
---|
289 |
|
---|
290 | ch_no = siopcb->inib->ch_no;
|
---|
291 | blTxSts = sio_get_txready(ch_no);
|
---|
292 | if(blTxSts){
|
---|
293 | ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bTxd = c;
|
---|
294 | }
|
---|
295 |
|
---|
296 | return(blTxSts);
|
---|
297 | }
|
---|
298 |
|
---|
299 | /*
|
---|
300 | * æå®ãããSIOãã£ãã«ã®å²ãè¾¼ã¿è¦å ãã¯ãªã¢ãã
|
---|
301 | */
|
---|
302 | Inline void
|
---|
303 | sio_clr_factor(UB bFlag)
|
---|
304 | {
|
---|
305 | ((volatile s1c33Intc_t *) S1C33_INTC_BASE)->bIntFactor[6] |= bFlag;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* æå®ãããSIOãã£ãã«ã®ã¨ã©ã¼ãã©ã°ãã¯ãªã¢ãã
|
---|
309 | *
|
---|
310 | */
|
---|
311 | Inline void
|
---|
312 | sio_clr_errflag(UB ch_no)
|
---|
313 | {
|
---|
314 | ((volatile s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus
|
---|
315 | &= ~(SIO_ERR_OVERRUN | SIO_ERR_PARITY | SIO_ERR_FRAME);
|
---|
316 | }
|
---|
317 |
|
---|
318 | #endif /* _MACRO_ONLY */
|
---|
319 | #endif /* _HW_SERIAL_H_ */
|
---|