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