1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2006 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | * Copyright (C) 2005-2006 by Logic Research Co., Ltd.
|
---|
9 | *
|
---|
10 | * ä¸è¨è使¨©è
|
---|
11 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
12 | * ã«ãã£ã¦å
|
---|
13 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
14 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
15 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
16 | å¸ï¼ä»¥ä¸ï¼
|
---|
17 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
18 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
19 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
20 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
21 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
22 | * ç¨ã§ããå½¢ã§åé
|
---|
23 | å¸ããå ´åã«ã¯ï¼åé
|
---|
24 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
25 | * è
|
---|
26 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
27 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
28 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
29 | * ç¨ã§ããªãå½¢ã§åé
|
---|
30 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
31 | * ã¨ï¼
|
---|
32 | * (a) åé
|
---|
33 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
34 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
35 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
36 | * (b) åé
|
---|
37 | å¸ã®å½¢æ
|
---|
38 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
39 | * å ±åãããã¨ï¼
|
---|
40 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
41 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
42 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
43 | 責ãããã¨ï¼
|
---|
44 | *
|
---|
45 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
46 | ã
|
---|
47 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
48 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
49 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
50 | *
|
---|
51 | */
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * FRK_ADuC å
|
---|
55 | 鍿©è½ç¨ãã©ã¤ã
|
---|
56 | */
|
---|
57 |
|
---|
58 | #include <s_services.h>
|
---|
59 | #include "frk_aduc.h"
|
---|
60 |
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
64 | */
|
---|
65 | const SIOPINIB siopinib_table[TNUM_SIOP] = {
|
---|
66 | {(VP)COMRX, (VP)COMDIV0, (VP)COMDIV1,
|
---|
67 | (VP)COMIEN0, (VP)COMIID0, (VP)COMCON0,
|
---|
68 | (VP)COMSTA0, IRQ_UART}
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®ã¨ãªã¢
|
---|
74 | */
|
---|
75 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * ã·ãªã¢ã«I/Oãã¼ãIDãã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
81 | */
|
---|
82 | #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
|
---|
83 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 | /*
|
---|
88 | * æåãåä¿¡ããã?
|
---|
89 | */
|
---|
90 | Inline BOOL
|
---|
91 | uart_getready(SIOPCB *siopcb)
|
---|
92 | {
|
---|
93 | return(((sil_rew_mem((VP)(siopcb->siopinib->line_status)) & COMSTA0_DR)!=0));
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * æåãéä¿¡ã§ããã?
|
---|
99 | */
|
---|
100 | Inline BOOL
|
---|
101 | uart_putready(SIOPCB *siopcb)
|
---|
102 | {
|
---|
103 | return((sil_rew_mem((VP)(siopcb->siopinib->line_status)) & COMSTA0_TEMT)!=0);
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * åä¿¡ããæåã®åãåºã
|
---|
109 | */
|
---|
110 | Inline UB
|
---|
111 | uart_getchar(SIOPCB *siopcb)
|
---|
112 | {
|
---|
113 | return(sil_rew_mem((VP)(siopcb->siopinib->uart_data)));
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
119 | */
|
---|
120 | Inline void
|
---|
121 | uart_putchar(SIOPCB *siopcb, UB c)
|
---|
122 | {
|
---|
123 | sil_wrw_mem((VP)(siopcb->siopinib->uart_data), c);
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * éä¿¡å²è¾¼ã¿è¨±å¯
|
---|
129 | */
|
---|
130 | Inline void
|
---|
131 | uart_enable_send(SIOPCB *siopcb)
|
---|
132 | {
|
---|
133 | sil_wrw_mem((VP)(siopcb->siopinib->int_enable),
|
---|
134 | (sil_rew_mem((VP)(siopcb->siopinib->int_enable)) | COMIEN0_ETBEI));
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * éä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
140 | */
|
---|
141 | Inline void
|
---|
142 | uart_disable_send(SIOPCB *siopcb)
|
---|
143 | {
|
---|
144 | sil_wrw_mem((VP)(siopcb->siopinib->int_enable),
|
---|
145 | (sil_rew_mem((VP)(siopcb->siopinib->int_enable)) & ~COMIEN0_ETBEI));
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * åä¿¡å²è¾¼ã¿è¨±å¯
|
---|
151 | */
|
---|
152 | Inline void
|
---|
153 | uart_enable_rcv(SIOPCB *siopcb)
|
---|
154 | {
|
---|
155 | sil_wrw_mem((VP)(siopcb->siopinib->int_enable),
|
---|
156 | (sil_rew_mem((VP)(siopcb->siopinib->int_enable)) | COMIEN0_ERBFI));
|
---|
157 | }
|
---|
158 |
|
---|
159 | /*
|
---|
160 | * åä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
161 | */
|
---|
162 | Inline void
|
---|
163 | uart_disable_rcv(SIOPCB *siopcb)
|
---|
164 | {
|
---|
165 | sil_wrw_mem((VP)(siopcb->siopinib->int_enable),
|
---|
166 | (sil_rew_mem((VP)(siopcb->siopinib->int_enable)) & ~COMIEN0_ERBFI));
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * ã«ã¼ãã«èµ·åæã®ãã°åºåç¨ã®åæå
|
---|
173 | */
|
---|
174 | void
|
---|
175 | init_uart(void){
|
---|
176 | /* Disable Interrupt */
|
---|
177 | sil_wrw_mem((VP)COMIEN0, 0);
|
---|
178 | /* 9600bps */
|
---|
179 | sil_wrw_mem((VP)COMCON0, COMCON0_DLAB);
|
---|
180 | sil_wrw_mem((VP)COMDIV0, COMDIV0_BR9600);
|
---|
181 | sil_wrw_mem((VP)COMDIV1, COMDIV1_BR9600);
|
---|
182 | /* 8Data, 1Stop, No Parity */
|
---|
183 | sil_wrw_mem((VP)COMCON0, (COMCON0_STOP|COMCON0_WLS_8b));
|
---|
184 | /* Enabel Receive Interrupt */
|
---|
185 | sil_wrw_mem((VP)COMIEN0, (COMIEN0_ERBFI|COMIEN0_ETBEI));
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * ãªã³ãããã®UARTããã®ãã¼ãªã³ã°åºå
|
---|
191 | */
|
---|
192 | void
|
---|
193 | uart_putc(char c)
|
---|
194 | {
|
---|
195 | int i;
|
---|
196 |
|
---|
197 | while((sil_rew_mem((VP)COMSTA0) & COMSTA0_TEMT)!=COMSTA0_TEMT);
|
---|
198 |
|
---|
199 | sil_wrw_mem((VP)COMTX, (VW)c);
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | /*
|
---|
204 | * SIOãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
205 | * 1ãã¼ããããªãããï¼ãã¾ãæå³ã¯ãªã
|
---|
206 | */
|
---|
207 | void
|
---|
208 | uart_initialize()
|
---|
209 | {
|
---|
210 | SIOPCB *siopcb;
|
---|
211 | UINT i;
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®åæå
|
---|
215 | */
|
---|
216 | for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
|
---|
217 | siopcb->siopinib = &(siopinib_table[i]);
|
---|
218 | siopcb->openflag = FALSE;
|
---|
219 | siopcb->sendflag = FALSE;
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | /*
|
---|
225 | * ãªã¼ãã³ãã¦ãããã¼ããããã
|
---|
226 | */
|
---|
227 | BOOL
|
---|
228 | uart_openflag(void)
|
---|
229 | {
|
---|
230 | return(siopcb_table[0].openflag);
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /*
|
---|
235 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
236 | */
|
---|
237 | SIOPCB *
|
---|
238 | uart_opn_por(ID siopid, VP_INT exinf)
|
---|
239 | {
|
---|
240 | int i;
|
---|
241 |
|
---|
242 | SIOPCB *siopcb;
|
---|
243 | const SIOPINIB *siopinib;
|
---|
244 |
|
---|
245 | siopcb = get_siopcb(siopid);
|
---|
246 | siopinib = siopcb->siopinib;
|
---|
247 |
|
---|
248 | /* Disable Interrupt */
|
---|
249 | sil_wrw_mem((VP)siopinib->int_enable, 0);
|
---|
250 | /* 9600bps */
|
---|
251 | sil_wrw_mem((VP)siopinib->line_control, COMCON0_DLAB);
|
---|
252 | sil_wrw_mem((VP)siopinib->divisor_lo, COMDIV0_BR9600);
|
---|
253 | sil_wrw_mem((VP)siopinib->divisor_hi, COMDIV1_BR9600);
|
---|
254 |
|
---|
255 | /* 8Data, 1Stop, No Parity */
|
---|
256 | sil_wrw_mem((VP)siopinib->line_control, (COMCON0_STOP|COMCON0_WLS_8b));
|
---|
257 |
|
---|
258 | /*
|
---|
259 | * å²è¾¼ã¿é¢é£ã®è¨å®
|
---|
260 | */
|
---|
261 | sil_wrw_mem((VP)siopinib->int_enable, (COMIEN0_ERBFI|COMIEN0_ETBEI)); /* Enable Interrupt */
|
---|
262 | sil_wrw_mem((VP)IRQEN, siopinib->irq_bit); /*Enable interrupt register*/
|
---|
263 |
|
---|
264 | siopcb->exinf = exinf;
|
---|
265 | siopcb->getready = siopcb->putready = FALSE;
|
---|
266 | siopcb->openflag = TRUE;
|
---|
267 |
|
---|
268 | return(siopcb);
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 | /*
|
---|
273 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
274 | */
|
---|
275 | void
|
---|
276 | uart_cls_por(SIOPCB *siopcb)
|
---|
277 | {
|
---|
278 | sil_wrw_mem((VP)(siopcb->siopinib->line_control),
|
---|
279 | (sil_rew_mem((VP)(siopcb->siopinib->line_control))|COMCON0_BRK)); /* Disable Interrupt */
|
---|
280 |
|
---|
281 | siopcb->openflag = FALSE;
|
---|
282 | }
|
---|
283 |
|
---|
284 |
|
---|
285 | /*
|
---|
286 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®æåéä¿¡
|
---|
287 | */
|
---|
288 | BOOL
|
---|
289 | uart_snd_chr(SIOPCB *siopcb, char c)
|
---|
290 | {
|
---|
291 | if (uart_putready(siopcb)){
|
---|
292 | uart_putchar(siopcb, c);
|
---|
293 | return(TRUE);
|
---|
294 | }
|
---|
295 | return(FALSE);
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | /*
|
---|
300 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
301 | */
|
---|
302 | INT
|
---|
303 | uart_rcv_chr(SIOPCB *siopcb)
|
---|
304 | {
|
---|
305 | if (uart_getready(siopcb)) {
|
---|
306 | return((INT)(UB) uart_getchar(siopcb));
|
---|
307 | }
|
---|
308 | return(-1);
|
---|
309 | }
|
---|
310 |
|
---|
311 | /*
|
---|
312 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®è¨±å¯
|
---|
313 | */
|
---|
314 | void
|
---|
315 | uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
316 | {
|
---|
317 | switch (cbrtn) {
|
---|
318 | case SIO_ERDY_SND:
|
---|
319 | uart_enable_send(siopcb);
|
---|
320 | break;
|
---|
321 | case SIO_ERDY_RCV:
|
---|
322 | uart_enable_rcv(siopcb);
|
---|
323 | break;
|
---|
324 | }
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | /*
|
---|
329 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®ç¦æ¢
|
---|
330 | */
|
---|
331 | void
|
---|
332 | uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
333 | {
|
---|
334 | switch (cbrtn) {
|
---|
335 | case SIO_ERDY_SND:
|
---|
336 | uart_disable_send(siopcb);
|
---|
337 | break;
|
---|
338 | case SIO_ERDY_RCV:
|
---|
339 | uart_disable_rcv(siopcb);
|
---|
340 | break;
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | /*
|
---|
346 | * ã·ãªã¢ã«I/Oãã¼ãã«å¯¾ããå²è¾¼ã¿å¦ç
|
---|
347 | */
|
---|
348 | static void
|
---|
349 | uart_isr_siop(SIOPCB *siopcb)
|
---|
350 | {
|
---|
351 | volatile UW iid;
|
---|
352 |
|
---|
353 | if (uart_getready(siopcb)) {
|
---|
354 | /*
|
---|
355 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
356 | */
|
---|
357 | uart_ierdy_rcv(siopcb->exinf);
|
---|
358 | }
|
---|
359 | if (uart_putready(siopcb)) {
|
---|
360 | iid = sil_rew_mem((VP)COMIID0);
|
---|
361 | /*
|
---|
362 | * éä¿¡å¯è½ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
363 | */
|
---|
364 | uart_ierdy_snd(siopcb->exinf);
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | /*
|
---|
370 | * SIOã®å²è¾¼ã¿ãµã¼ãã¹ã«ã¼ãã³
|
---|
371 | */
|
---|
372 | void
|
---|
373 | uart_isr()
|
---|
374 | {
|
---|
375 | uart_isr_siop(&(siopcb_table[0]));
|
---|
376 | }
|
---|
377 |
|
---|