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