[26] | 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) 2005- by Monami software, LP.
|
---|
| 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$
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | /*
|
---|
| 55 | * LPC2214 å
|
---|
| 56 | é¨æ©è½ç¨ãã©ã¤ã
|
---|
| 57 | */
|
---|
| 58 | #include <s_services.h>
|
---|
| 59 | #include <lpc2214.h>
|
---|
| 60 |
|
---|
| 61 | /*
|
---|
| 62 | * å
|
---|
| 63 | é¨UARTç¨ ç°¡æSIOãã©ã¤ã
|
---|
| 64 | */
|
---|
| 65 |
|
---|
| 66 | /*
|
---|
| 67 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
| 68 | */
|
---|
| 69 | typedef struct sio_port_initialization_block {
|
---|
| 70 |
|
---|
| 71 | } SIOPINIB;
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯
|
---|
| 75 | */
|
---|
| 76 | struct sio_port_control_block {
|
---|
| 77 | const SIOPINIB *siopinib; /* ã·ãªã¢ã«I/Oãã¼ãåæåããã㯠*/
|
---|
| 78 | VP_INT exinf; /* æ¡å¼µæ
|
---|
| 79 | å ± */
|
---|
| 80 | BOOL openflag; /* ãªã¼ãã³æ¸ã¿ãã©ã° */
|
---|
| 81 | BOOL sendflag; /* éä¿¡å²è¾¼ã¿ã¤ãã¼ãã«ãã©ã° */
|
---|
| 82 | BOOL getready; /* æåãåä¿¡ããç¶æ
|
---|
| 83 | */
|
---|
| 84 | BOOL putready; /* æåãéä¿¡ã§ããç¶æ
|
---|
| 85 | */
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
| 90 | */
|
---|
| 91 | const SIOPINIB siopinib_table[TNUM_SIOP] = {{}};
|
---|
| 92 |
|
---|
| 93 | /*
|
---|
| 94 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®ã¨ãªã¢
|
---|
| 95 | */
|
---|
| 96 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | * ã·ãªã¢ã«I/Oãã¼ãIDãã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
| 100 | */
|
---|
| 101 | #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
|
---|
| 102 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /*
|
---|
| 106 | * æåãåä¿¡ããã?
|
---|
| 107 | */
|
---|
| 108 | Inline BOOL
|
---|
| 109 | uart_getready(SIOPCB *siopcb)
|
---|
| 110 | {
|
---|
| 111 | return (sil_rew_mem(UART_LSR) & 0x01) != 0;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /*
|
---|
| 115 | * æåãéä¿¡ã§ããã?
|
---|
| 116 | */
|
---|
| 117 | Inline BOOL
|
---|
| 118 | uart_putready(SIOPCB *siopcb)
|
---|
| 119 | {
|
---|
| 120 | return (sil_rew_mem(UART_LSR) & 0x20) != 0;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /*
|
---|
| 124 | * åä¿¡ããæåã®åãåºã
|
---|
| 125 | */
|
---|
| 126 | Inline UB
|
---|
| 127 | uart_getchar(SIOPCB *siopcb)
|
---|
| 128 | {
|
---|
| 129 | return (UB)sil_rew_mem(UART_RBR);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /*
|
---|
| 133 | * éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
| 134 | */
|
---|
| 135 | void
|
---|
| 136 | uart_putchar(SIOPCB *siopcb, UB c)
|
---|
| 137 | {
|
---|
| 138 | sil_wrw_mem(UART_THR, (VW)c);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /*
|
---|
| 142 | * éä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 143 | */
|
---|
| 144 | Inline void
|
---|
| 145 | uart_enable_send(SIOPCB *siopcb)
|
---|
| 146 | {
|
---|
| 147 | VW wbits;
|
---|
| 148 | wbits = sil_rew_mem(UART_IER);
|
---|
| 149 | wbits |= UART_INT_T;
|
---|
| 150 | sil_wrw_mem(UART_IER,wbits);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | /*
|
---|
| 154 | * éä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 155 | */
|
---|
| 156 | Inline void
|
---|
| 157 | uart_disable_send(SIOPCB *siopcb)
|
---|
| 158 | {
|
---|
| 159 | VW wbits;
|
---|
| 160 | wbits = sil_rew_mem(UART_IER);
|
---|
| 161 | wbits &= ~UART_INT_T;
|
---|
| 162 | sil_wrw_mem(UART_IER,wbits);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /*
|
---|
| 166 | * åä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 167 | */
|
---|
| 168 | Inline void
|
---|
| 169 | uart_enable_rcv(SIOPCB *siopcb)
|
---|
| 170 | {
|
---|
| 171 | VW wbits;
|
---|
| 172 | wbits = sil_rew_mem(UART_IER);
|
---|
| 173 | wbits |= UART_INT_R;
|
---|
| 174 | sil_wrw_mem(UART_IER,wbits);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | /*
|
---|
| 178 | * åä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 179 | */
|
---|
| 180 | Inline void
|
---|
| 181 | uart_disable_rcv(SIOPCB *siopcb)
|
---|
| 182 | {
|
---|
| 183 | VW wbits;
|
---|
| 184 | wbits = sil_rew_mem(UART_IER);
|
---|
| 185 | wbits &= ~UART_INT_R;
|
---|
| 186 | sil_wrw_mem(UART_IER,wbits);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | /*
|
---|
| 192 | * ã«ã¼ãã«èµ·åæã®ãã°åºåç¨ã®åæå
|
---|
| 193 | */
|
---|
| 194 | void
|
---|
| 195 | uart_init(void){
|
---|
| 196 | UW wbits;
|
---|
| 197 | UH devisor;
|
---|
| 198 |
|
---|
| 199 | #if 0
|
---|
| 200 | /*
|
---|
| 201 | * GP34ã41 ã FFUART ã¨ãã¦å©ç¨
|
---|
| 202 | */
|
---|
| 203 | wbits = sil_rew_mem(GPIO_GAFR0_y);
|
---|
| 204 | wbits = (wbits & 0xfff0000f) | 0x000a9550;
|
---|
| 205 | sil_wrw_mem(GPIO_GAFR0_y, wbits);
|
---|
| 206 |
|
---|
| 207 | /*
|
---|
| 208 | * TXD, RTS/RTS ãåºåã«ãã
|
---|
| 209 | */
|
---|
| 210 | wbits = sil_rew_mem(GPIO_GPDR_y);
|
---|
| 211 | wbits = (wbits & 0xfffffc7f) | 0x00000380;
|
---|
| 212 | sil_wrw_mem(GPIO_GPDR_y, wbits);
|
---|
| 213 |
|
---|
| 214 | /*
|
---|
| 215 | * RS232C ãã©ã¤ããã¼ãã¦ã§ã¢ã®ã¤ãã¼ãã«
|
---|
| 216 | */
|
---|
| 217 | wbits = sil_rew_mem(CQ_PXA250_CONFIG);
|
---|
| 218 | wbits |= 0x200;
|
---|
| 219 | sil_wrw_mem(CQ_PXA250_CONFIG, wbits);
|
---|
| 220 | #endif
|
---|
| 221 |
|
---|
| 222 | /*
|
---|
| 223 | * UART_BPS ã14以ä¸ã®ã¨ãã
|
---|
| 224 | * æ¼ç®çµæããªã¼ãããã¼ããã
|
---|
| 225 | * å®éã«ãããªæ°å¤ã«ãããã¨ã¯
|
---|
| 226 | * ããããªãã念ã®ããã
|
---|
| 227 | */
|
---|
| 228 | #if (UART_BPS < 15)
|
---|
| 229 | #error UART_BPS is too small or undefined.
|
---|
| 230 | #endif
|
---|
| 231 |
|
---|
| 232 | devisor = 921600 / UART_BPS;
|
---|
| 233 |
|
---|
| 234 | sil_wrw_mem(UART_LCR, 0x80);
|
---|
| 235 | sil_wrw_mem(UART_DLL, devisor & 0xff);
|
---|
| 236 | sil_wrw_mem(UART_DLH, (devisor >> 8) & 0xff);
|
---|
| 237 | sil_wrw_mem(UART_LCR, 0x3);
|
---|
| 238 | sil_wrw_mem(UART_FCR, 0x1);
|
---|
| 239 | sil_wrw_mem(UART_MCR, 0x3);
|
---|
| 240 | sil_wrw_mem(UART_IER, 0x40);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | /*
|
---|
| 245 | * ãªã³ãããã®UARTããã®ãã¼ãªã³ã°åºå
|
---|
| 246 | */
|
---|
| 247 | void
|
---|
| 248 | uart_putc(char c)
|
---|
| 249 | {
|
---|
| 250 | UW buf_level;
|
---|
| 251 |
|
---|
| 252 | while((sil_rew_mem(UART_LSR) & 0x20) == 0) {
|
---|
| 253 | /* spin lock */
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | sil_wrw_mem(UART_THR,(VW)c);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | /*
|
---|
| 260 | * SIOãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
| 261 | * 1ãã¼ããããªãããï¼ãã¾ãæå³ã¯ãªã
|
---|
| 262 | */
|
---|
| 263 | void
|
---|
| 264 | uart_initialize()
|
---|
| 265 | {
|
---|
| 266 | SIOPCB *siopcb;
|
---|
| 267 | UINT i;
|
---|
| 268 |
|
---|
| 269 | /*
|
---|
| 270 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®åæå
|
---|
| 271 | */
|
---|
| 272 | for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
|
---|
| 273 | siopcb->siopinib = &(siopinib_table[i]);
|
---|
| 274 | siopcb->openflag = FALSE;
|
---|
| 275 | siopcb->sendflag = FALSE;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | /*
|
---|
| 280 | * ãªã¼ãã³ãã¦ãããã¼ããããã
|
---|
| 281 | */
|
---|
| 282 | BOOL
|
---|
| 283 | uart_openflag(void)
|
---|
| 284 | {
|
---|
| 285 | return(siopcb_table[0].openflag);
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 | /*
|
---|
| 290 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 291 | */
|
---|
| 292 | SIOPCB *
|
---|
| 293 | uart_opn_por(ID siopid, VP_INT exinf)
|
---|
| 294 | {
|
---|
| 295 | SIOPCB *siopcb;
|
---|
| 296 | const SIOPINIB *siopinib;
|
---|
| 297 |
|
---|
| 298 | siopcb = get_siopcb(siopid);
|
---|
| 299 | siopinib = siopcb->siopinib;
|
---|
| 300 |
|
---|
| 301 | uart_init();
|
---|
| 302 |
|
---|
| 303 | siopcb->exinf = exinf;
|
---|
| 304 | siopcb->getready = siopcb->putready = FALSE;
|
---|
| 305 | siopcb->openflag = TRUE;
|
---|
| 306 |
|
---|
| 307 | /* clear FIFO TxThr = 0 RxThr = 1*/
|
---|
| 308 | sil_wrw_mem(UART_FCR,(VW)(UART_FCR_TC | UART_FCR_RC));
|
---|
| 309 |
|
---|
| 310 | /* set interrupt */
|
---|
| 311 | sil_wrw_mem(UART_IER, 0x42);
|
---|
| 312 |
|
---|
| 313 | return(siopcb);
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | /*
|
---|
| 317 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
| 318 | */
|
---|
| 319 | void
|
---|
| 320 | uart_cls_por(SIOPCB *siopcb)
|
---|
| 321 | {
|
---|
| 322 | siopcb->openflag = FALSE;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | /*
|
---|
| 326 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®æåéä¿¡
|
---|
| 327 | */
|
---|
| 328 | BOOL
|
---|
| 329 | uart_snd_chr(SIOPCB *siopcb, char c)
|
---|
| 330 | {
|
---|
| 331 | if (uart_putready(siopcb)){
|
---|
| 332 | uart_putchar(siopcb, c);
|
---|
| 333 | return(TRUE);
|
---|
| 334 | }
|
---|
| 335 | return(FALSE);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | /*
|
---|
| 339 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
| 340 | */
|
---|
| 341 | INT
|
---|
| 342 | uart_rcv_chr(SIOPCB *siopcb)
|
---|
| 343 | {
|
---|
| 344 | if (uart_getready(siopcb)) {
|
---|
| 345 | return((INT)(UB) uart_getchar(siopcb));
|
---|
| 346 | }
|
---|
| 347 | return(-1);
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | /*
|
---|
| 351 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®è¨±å¯
|
---|
| 352 | */
|
---|
| 353 | void
|
---|
| 354 | uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 355 | {
|
---|
| 356 | switch (cbrtn) {
|
---|
| 357 | case SIO_ERDY_SND:
|
---|
| 358 | uart_enable_send(siopcb);
|
---|
| 359 | break;
|
---|
| 360 | case SIO_ERDY_RCV:
|
---|
| 361 | uart_enable_rcv(siopcb);
|
---|
| 362 | break;
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 |
|
---|
| 367 | /*
|
---|
| 368 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®ç¦æ¢
|
---|
| 369 | */
|
---|
| 370 | void
|
---|
| 371 | uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 372 | {
|
---|
| 373 | switch (cbrtn) {
|
---|
| 374 | case SIO_ERDY_SND:
|
---|
| 375 | uart_disable_send(siopcb);
|
---|
| 376 | break;
|
---|
| 377 | case SIO_ERDY_RCV:
|
---|
| 378 | uart_disable_rcv(siopcb);
|
---|
| 379 | break;
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 | /*
|
---|
| 386 | * ã·ãªã¢ã«I/Oãã¼ãã«å¯¾ããå²è¾¼ã¿å¦ç
|
---|
| 387 | */
|
---|
| 388 | static void
|
---|
| 389 | uart_isr_siop(SIOPCB *siopcb)
|
---|
| 390 | {
|
---|
| 391 | if (uart_getready(siopcb)) {
|
---|
| 392 | /*
|
---|
| 393 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 394 | */
|
---|
| 395 | uart_ierdy_rcv(siopcb->exinf);
|
---|
| 396 | }
|
---|
| 397 | if (uart_putready(siopcb)) {
|
---|
| 398 | /*
|
---|
| 399 | * éä¿¡å¯è½ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 400 | */
|
---|
| 401 | uart_ierdy_snd(siopcb->exinf);
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 |
|
---|
| 406 | /*
|
---|
| 407 | * SIOã®å²è¾¼ã¿ãµã¼ãã¹ã«ã¼ãã³
|
---|
| 408 | */
|
---|
| 409 | void
|
---|
| 410 | uart_isr()
|
---|
| 411 | {
|
---|
| 412 | sil_wrw_mem((VP *)0xe002800c, 0x40000000);
|
---|
| 413 |
|
---|
| 414 | uart_isr_siop(&(siopcb_table[0]));
|
---|
| 415 | }
|
---|
| 416 |
|
---|