[363] | 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 | * 2003 by Advanced Data Controls, Corp
|
---|
| 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 | * @(#) $Id: integrator.c,v 1.4 2003/12/24 08:05:00 honda Exp $
|
---|
| 52 | *
|
---|
| 53 | */
|
---|
| 54 |
|
---|
| 55 | /*
|
---|
| 56 | * Integrator å
|
---|
| 57 | é¨æ©è½ç¨ãã©ã¤ã
|
---|
| 58 | */
|
---|
| 59 | #include <s_services.h>
|
---|
| 60 | #include <integrator.h>
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | /*
|
---|
| 64 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
| 65 | */
|
---|
| 66 | const SIOPINIB siopinib_table[TNUM_SIOP] = {
|
---|
| 67 | {(VP)UART1_DR,(VP)UART1_CR,(VP)UART1_LCRL,
|
---|
| 68 | (VP)UART1_LCRM,(VP)UART1_LCRH,(VP)UART1_IIR,
|
---|
| 69 | (VP)UART1_FR,IRQ_UART1
|
---|
| 70 | }
|
---|
| 71 | #if TNUM_SIOP >= 2
|
---|
| 72 | ,
|
---|
| 73 | {(VP)UART0_DR,(VP)UART0_CR,(VP)UART0_LCRL,
|
---|
| 74 | (VP)UART0_LCRM,(VP)UART0_LCRH,(VP)UART0_IIR,
|
---|
| 75 | (VP)UART0_FR,IRQ_UART0
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | #endif /* TNUM_SIOP >= 2 */
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®ã¨ãªã¢
|
---|
| 84 | */
|
---|
| 85 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * ã·ãªã¢ã«I/Oãã¼ãIDãã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
| 90 | */
|
---|
| 91 | #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
|
---|
| 92 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /*
|
---|
| 96 | * æåãåä¿¡ããã?
|
---|
| 97 | */
|
---|
| 98 | Inline BOOL
|
---|
| 99 | uart_getready(SIOPCB *siopcb)
|
---|
| 100 | {
|
---|
| 101 | return((sil_rew_mem((VP)(siopcb->siopinib->int_identifier)) & IIR_RIS)!=0);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /*
|
---|
| 105 | * æåãéä¿¡ã§ããã?
|
---|
| 106 | */
|
---|
| 107 | Inline BOOL
|
---|
| 108 | uart_putready(SIOPCB *siopcb)
|
---|
| 109 | {
|
---|
| 110 | return((sil_rew_mem((VP)(siopcb->siopinib->flag_register)) & UFR_BUSY)==0);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /*
|
---|
| 114 | * åä¿¡ããæåã®åãåºã
|
---|
| 115 | */
|
---|
| 116 | Inline UB
|
---|
| 117 | uart_getchar(SIOPCB *siopcb)
|
---|
| 118 | {
|
---|
| 119 | return(sil_rew_mem((VP)(siopcb->siopinib->uart_data)));
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
| 124 | */
|
---|
| 125 | Inline void
|
---|
| 126 | uart_putchar(SIOPCB *siopcb, UB c)
|
---|
| 127 | {
|
---|
| 128 | sil_wrw_mem((VP)(siopcb->siopinib->uart_data),c);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /*
|
---|
| 132 | * éä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 133 | */
|
---|
| 134 | Inline void
|
---|
| 135 | uart_enable_send(SIOPCB *siopcb)
|
---|
| 136 | {
|
---|
| 137 | sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
|
---|
| 138 | (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) | UCR_TIE));
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /*
|
---|
| 142 | * éä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 143 | */
|
---|
| 144 | Inline void
|
---|
| 145 | uart_disable_send(SIOPCB *siopcb)
|
---|
| 146 | {
|
---|
| 147 | sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
|
---|
| 148 | (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) & ~UCR_TIE));
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * åä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 154 | */
|
---|
| 155 | Inline void
|
---|
| 156 | uart_enable_rcv(SIOPCB *siopcb)
|
---|
| 157 | {
|
---|
| 158 | sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
|
---|
| 159 | (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) | UCR_RIE));
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /*
|
---|
| 163 | * åä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 164 | */
|
---|
| 165 | Inline void
|
---|
| 166 | uart_disable_rcv(SIOPCB *siopcb)
|
---|
| 167 | {
|
---|
| 168 |
|
---|
| 169 | sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
|
---|
| 170 | (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) & ~UCR_RIE));
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | /*
|
---|
| 177 | * SIOãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
| 178 | * 1ãã¼ããããªãããï¼ãã¾ãæå³ã¯ãªã
|
---|
| 179 | */
|
---|
| 180 | void
|
---|
| 181 | uart_initialize()
|
---|
| 182 | {
|
---|
| 183 | SIOPCB *siopcb;
|
---|
| 184 | UINT i;
|
---|
| 185 |
|
---|
| 186 | /*
|
---|
| 187 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®åæå
|
---|
| 188 | */
|
---|
| 189 | for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
|
---|
| 190 | siopcb->siopinib = &(siopinib_table[i]);
|
---|
| 191 | siopcb->openflag = FALSE;
|
---|
| 192 | siopcb->sendflag = FALSE;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /*
|
---|
| 197 | * ãªã¼ãã³ãã¦ãããã¼ããããã
|
---|
| 198 | */
|
---|
| 199 | BOOL
|
---|
| 200 | uart_openflag(void)
|
---|
| 201 | {
|
---|
| 202 | return(siopcb_table[0].openflag);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | /*
|
---|
| 206 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 207 | */
|
---|
| 208 | SIOPCB *
|
---|
| 209 | uart_opn_por(ID siopid, VP_INT exinf)
|
---|
| 210 | {
|
---|
| 211 | SIOPCB *siopcb;
|
---|
| 212 | const SIOPINIB *siopinib;
|
---|
| 213 |
|
---|
| 214 | siopcb = get_siopcb(siopid);
|
---|
| 215 | siopinib = siopcb->siopinib;
|
---|
| 216 |
|
---|
| 217 | /* Disable Interrupt */
|
---|
| 218 | sil_wrw_mem((VP)siopinib->uart_control, ~UCR_UARTEN);
|
---|
| 219 | /* 19200bps */
|
---|
| 220 | sil_wrw_mem((VP)siopinib->linectrl_lo, ULCRL_19200);
|
---|
| 221 | sil_wrw_mem((VP)siopinib->linectrl_mid, ULCRM_19200);
|
---|
| 222 | /* 8Data, 1Stop, No Parity */
|
---|
| 223 | sil_wrw_mem((VP)siopinib->linectrl_hi, ULCRH_WLEN_8BIT);
|
---|
| 224 |
|
---|
| 225 |
|
---|
| 226 | /*
|
---|
| 227 | * å²è¾¼ã¿é¢é£ã®è¨å®
|
---|
| 228 | */
|
---|
| 229 | sil_wrw_mem((VP)siopinib->uart_control, UCR_UARTEN); /* Enable Interrupt */
|
---|
| 230 | sil_wrw_mem((VP)IRQ0_ENABLESET,siopinib->irq_bit);/*Enable interrupt register*/
|
---|
| 231 |
|
---|
| 232 | siopcb->exinf = exinf;
|
---|
| 233 | siopcb->getready = siopcb->putready = FALSE;
|
---|
| 234 | siopcb->openflag = TRUE;
|
---|
| 235 |
|
---|
| 236 | return(siopcb);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | /*
|
---|
| 242 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
| 243 | */
|
---|
| 244 | void
|
---|
| 245 | uart_cls_por(SIOPCB *siopcb)
|
---|
| 246 | {
|
---|
| 247 | sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
|
---|
| 248 | (sil_rew_mem((VP)(siopcb->siopinib->uart_control))&~UCR_UARTEN)); /* Disable Interrupt */
|
---|
| 249 |
|
---|
| 250 | siopcb->openflag = FALSE;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | /*
|
---|
| 254 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®æåéä¿¡
|
---|
| 255 | */
|
---|
| 256 | BOOL
|
---|
| 257 | uart_snd_chr(SIOPCB *siopcb, char c)
|
---|
| 258 | {
|
---|
| 259 | if (uart_putready(siopcb)){
|
---|
| 260 | uart_putchar(siopcb, c);
|
---|
| 261 | return(TRUE);
|
---|
| 262 | }
|
---|
| 263 | return(FALSE);
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | /*
|
---|
| 267 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
| 268 | */
|
---|
| 269 | INT
|
---|
| 270 | uart_rcv_chr(SIOPCB *siopcb)
|
---|
| 271 | {
|
---|
| 272 | if (uart_getready(siopcb)) {
|
---|
| 273 | return((INT)(UB) uart_getchar(siopcb));
|
---|
| 274 | }
|
---|
| 275 | return(-1);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | /*
|
---|
| 279 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®è¨±å¯
|
---|
| 280 | */
|
---|
| 281 | void
|
---|
| 282 | uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 283 | {
|
---|
| 284 | switch (cbrtn) {
|
---|
| 285 | case SIO_ERDY_SND:
|
---|
| 286 | uart_enable_send(siopcb);
|
---|
| 287 | break;
|
---|
| 288 | case SIO_ERDY_RCV:
|
---|
| 289 | uart_enable_rcv(siopcb);
|
---|
| 290 | break;
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 | /*
|
---|
| 296 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®ç¦æ¢
|
---|
| 297 | */
|
---|
| 298 | void
|
---|
| 299 | uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 300 | {
|
---|
| 301 | switch (cbrtn) {
|
---|
| 302 | case SIO_ERDY_SND:
|
---|
| 303 | uart_disable_send(siopcb);
|
---|
| 304 | break;
|
---|
| 305 | case SIO_ERDY_RCV:
|
---|
| 306 | uart_disable_rcv(siopcb);
|
---|
| 307 | break;
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 | /*
|
---|
| 314 | * ã·ãªã¢ã«I/Oãã¼ãã«å¯¾ããå²è¾¼ã¿å¦ç
|
---|
| 315 | */
|
---|
| 316 | static void
|
---|
| 317 | uart_isr_siop(SIOPCB *siopcb)
|
---|
| 318 | {
|
---|
| 319 | if (uart_getready(siopcb)) {
|
---|
| 320 | /*
|
---|
| 321 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 322 | */
|
---|
| 323 | uart_ierdy_rcv(siopcb->exinf);
|
---|
| 324 | }
|
---|
| 325 | if (uart_putready(siopcb)) {
|
---|
| 326 | /*
|
---|
| 327 | * éä¿¡å¯è½ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 328 | */
|
---|
| 329 | uart_ierdy_snd(siopcb->exinf);
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 |
|
---|
| 334 | /*
|
---|
| 335 | * SIOã®å²è¾¼ã¿ãµã¼ãã¹ã«ã¼ãã³
|
---|
| 336 | */
|
---|
| 337 | void
|
---|
| 338 | uart_isr0()
|
---|
| 339 | {
|
---|
| 340 | uart_isr_siop(&(siopcb_table[0]));
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | #if TNUM_SIOP >= 2
|
---|
| 344 | void
|
---|
| 345 | uart_isr1()
|
---|
| 346 | {
|
---|
| 347 | uart_isr_siop(&(siopcb_table[1]));
|
---|
| 348 | }
|
---|
| 349 | #endif
|
---|