[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 | *
|
---|
| 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: lm32.c,v 1.14 2007/07/27 11:28:44 honda Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #include <s_services.h>
|
---|
| 54 | #include <lm32.h>
|
---|
| 55 |
|
---|
| 56 | const SIOPINIB siopinib_table[TNUM_SIOP] = {
|
---|
| 57 | {
|
---|
| 58 | (VP)UART1_RX_TX,
|
---|
| 59 | (VP)UART1_IER,
|
---|
| 60 | (VP)UART1_IIR,
|
---|
| 61 | (VP)UART1_LCR,
|
---|
| 62 | (VP)UART1_MCR,
|
---|
| 63 | (VP)UART1_LSR,
|
---|
| 64 | (VP)UART1_MSR,
|
---|
| 65 | (VP)UART1_DIV
|
---|
| 66 | }
|
---|
| 67 | #if TNUM_SIOP >= 2
|
---|
| 68 | ,
|
---|
| 69 | {
|
---|
| 70 | (VP)UART2_RX_TX,
|
---|
| 71 | (VP)UART2_IER,
|
---|
| 72 | (VP)UART2_IIR,
|
---|
| 73 | (VP)UART2_LCR,
|
---|
| 74 | (VP)UART2_MCR,
|
---|
| 75 | (VP)UART2_LSR,
|
---|
| 76 | (VP)UART2_MSR,
|
---|
| 77 | (VP)UART2_DIV
|
---|
| 78 | }
|
---|
| 79 | #endif /* TNUM_SIOP >= 2 */
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
| 83 |
|
---|
| 84 | #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
|
---|
| 85 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
| 86 |
|
---|
| 87 | Inline BOOL
|
---|
| 88 | uart_getready(SIOPCB *siopcb)
|
---|
| 89 | {
|
---|
| 90 | return(sil_rew_mem((VP)(siopcb->siopinib->lsr)) & UART_LSR_RX_RDY_MASK);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | Inline BOOL
|
---|
| 94 | uart_putready(SIOPCB *siopcb)
|
---|
| 95 | {
|
---|
| 96 | return(sil_rew_mem((VP)(siopcb->siopinib->lsr)) & UART_LSR_TX_RDY_MASK);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | Inline UB
|
---|
| 100 | uart_getchar(SIOPCB *siopcb)
|
---|
| 101 | {
|
---|
| 102 | return(sil_rew_mem((VP)(siopcb->siopinib->rxtx)));
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | Inline void
|
---|
| 106 | uart_putchar(SIOPCB *siopcb, UB c)
|
---|
| 107 | {
|
---|
| 108 | sil_wrw_mem((VP)(siopcb->siopinib->rxtx), c);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | Inline void
|
---|
| 112 | uart_enable_send(SIOPCB *siopcb)
|
---|
| 113 | {
|
---|
| 114 | const SIOPINIB *siopinib;
|
---|
| 115 | siopinib = siopcb->siopinib;
|
---|
| 116 | siopcb->ier_snapshot |= UART_IER_TX_INT_MASK;
|
---|
| 117 | sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | Inline void
|
---|
| 121 | uart_disable_send(SIOPCB *siopcb)
|
---|
| 122 | {
|
---|
| 123 | const SIOPINIB *siopinib;
|
---|
| 124 | siopinib = siopcb->siopinib;
|
---|
| 125 | siopcb->ier_snapshot &= (~UART_IER_TX_INT_MASK);
|
---|
| 126 | sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | Inline void
|
---|
| 130 | uart_enable_rcv(SIOPCB *siopcb)
|
---|
| 131 | {
|
---|
| 132 | const SIOPINIB *siopinib;
|
---|
| 133 | siopinib = siopcb->siopinib;
|
---|
| 134 | siopcb->ier_snapshot |= UART_IER_RX_INT_MASK;
|
---|
| 135 | sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | Inline void
|
---|
| 139 | uart_disable_rcv(SIOPCB *siopcb)
|
---|
| 140 | {
|
---|
| 141 | const SIOPINIB *siopinib;
|
---|
| 142 | siopinib = siopcb->siopinib;
|
---|
| 143 | siopcb->ier_snapshot &= (~UART_IER_RX_INT_MASK);
|
---|
| 144 | sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | void
|
---|
| 148 | init_uart(void)
|
---|
| 149 | {
|
---|
| 150 | volatile unsigned int divisor;
|
---|
| 151 | UW sr;
|
---|
| 152 |
|
---|
| 153 | sil_wrw_mem((VP)UART1_IER, 0);
|
---|
| 154 |
|
---|
| 155 | /* 8Data, 1Stop, No Parity*/
|
---|
| 156 | sil_wrw_mem((VP)UART1_LCR, 0x3);
|
---|
| 157 |
|
---|
| 158 | /* 115200bps */
|
---|
| 159 | divisor = ((1048576.0 * (DEFAULT_UART_BAUDRATE/100)) / (MICO32_CPU_CLOCK_HZ/100)) + 0.5;
|
---|
| 160 | //divisor = 0x12e0;
|
---|
| 161 | sil_wrw_mem((VP)UART1_DIV, divisor);
|
---|
| 162 |
|
---|
| 163 | sil_wrw_mem((VP)UART1_IER, UART_IER_RX_INT_MASK);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | void
|
---|
| 167 | uart_putc(char c)
|
---|
| 168 | {
|
---|
| 169 | volatile unsigned int lsr;
|
---|
| 170 |
|
---|
| 171 | while(1)
|
---|
| 172 | {
|
---|
| 173 | lsr = sil_rew_mem((VP)(UART1_LSR));
|
---|
| 174 | if(lsr & UART_LSR_TX_RDY_MASK)
|
---|
| 175 | {
|
---|
| 176 | sil_wrw_mem((VP)UART1_RX_TX, (VW)c);
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void
|
---|
| 183 | uart_initialize()
|
---|
| 184 | {
|
---|
| 185 | SIOPCB *siopcb;
|
---|
| 186 | UINT i;
|
---|
| 187 |
|
---|
| 188 | for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
|
---|
| 189 | siopcb->siopinib = &(siopinib_table[i]);
|
---|
| 190 | siopcb->openflag = FALSE;
|
---|
| 191 | siopcb->sendflag = FALSE;
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | BOOL
|
---|
| 196 | uart_openflag(void)
|
---|
| 197 | {
|
---|
| 198 | return(siopcb_table[0].openflag);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | SIOPCB *
|
---|
| 202 | uart_opn_por(ID siopid, VP_INT exinf)
|
---|
| 203 | {
|
---|
| 204 | SIOPCB *siopcb;
|
---|
| 205 | const SIOPINIB *siopinib;
|
---|
| 206 | volatile unsigned int divisor;
|
---|
| 207 | UW sr;
|
---|
| 208 |
|
---|
| 209 | siopcb = get_siopcb(siopid);
|
---|
| 210 | siopinib = siopcb->siopinib;
|
---|
| 211 |
|
---|
| 212 | sil_wrw_mem((VP)siopinib->ier, 0);
|
---|
| 213 |
|
---|
| 214 | /* 8Data, 1Stop, No Parity*/
|
---|
| 215 | sil_wrw_mem((VP)siopinib->lcr, 0x3);
|
---|
| 216 |
|
---|
| 217 | /* 115200bps */
|
---|
| 218 | divisor = ((1048576.0 * (DEFAULT_UART_BAUDRATE/100)) / (MICO32_CPU_CLOCK_HZ/100)) + 0.5;
|
---|
| 219 | //divisor = 0x12e0;
|
---|
| 220 | sil_wrw_mem((VP)siopinib->div, divisor);
|
---|
| 221 |
|
---|
| 222 | siopcb->ier_snapshot = UART_IER_RX_INT_MASK;
|
---|
| 223 | sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
|
---|
| 224 |
|
---|
| 225 | Asm("rcsr %0, im" : "=r"(sr));
|
---|
| 226 | sr |= (1 << INHNO_SIO1);
|
---|
| 227 | Asm("wcsr im, %0" : : "r"(sr) );
|
---|
| 228 |
|
---|
| 229 | siopcb->exinf = exinf;
|
---|
| 230 | siopcb->getready = siopcb->putready = FALSE;
|
---|
| 231 | siopcb->openflag = TRUE;
|
---|
| 232 |
|
---|
| 233 | return(siopcb);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | void
|
---|
| 237 | uart_cls_por(SIOPCB *siopcb)
|
---|
| 238 | {
|
---|
| 239 | const SIOPINIB *siopinib;
|
---|
| 240 | siopinib = siopcb->siopinib;
|
---|
| 241 | sil_wrw_mem((VP)siopinib->ier, 0);
|
---|
| 242 | siopcb->openflag = FALSE;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | BOOL
|
---|
| 246 | uart_snd_chr(SIOPCB *siopcb, char c)
|
---|
| 247 | {
|
---|
| 248 | if (uart_putready(siopcb)){
|
---|
| 249 | uart_putchar(siopcb, c);
|
---|
| 250 | return(TRUE);
|
---|
| 251 | }
|
---|
| 252 | return(FALSE);
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | INT
|
---|
| 256 | uart_rcv_chr(SIOPCB *siopcb)
|
---|
| 257 | {
|
---|
| 258 | if (uart_getready(siopcb)) {
|
---|
| 259 | return((INT)(UB) uart_getchar(siopcb));
|
---|
| 260 | }
|
---|
| 261 | return(-1);
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | void
|
---|
| 265 | uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 266 | {
|
---|
| 267 | switch (cbrtn) {
|
---|
| 268 | case SIO_ERDY_SND:
|
---|
| 269 | uart_enable_send(siopcb);
|
---|
| 270 | break;
|
---|
| 271 | case SIO_ERDY_RCV:
|
---|
| 272 | uart_enable_rcv(siopcb);
|
---|
| 273 | break;
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | void
|
---|
| 278 | uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
| 279 | {
|
---|
| 280 | switch (cbrtn) {
|
---|
| 281 | case SIO_ERDY_SND:
|
---|
| 282 | uart_disable_send(siopcb);
|
---|
| 283 | break;
|
---|
| 284 | case SIO_ERDY_RCV:
|
---|
| 285 | uart_disable_rcv(siopcb);
|
---|
| 286 | break;
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | static void
|
---|
| 291 | uart_isr_siop(SIOPCB *siopcb)
|
---|
| 292 | {
|
---|
| 293 | volatile UW iir;
|
---|
| 294 |
|
---|
| 295 | iir = sil_rew_mem((VP)(siopcb->siopinib->iir));
|
---|
| 296 |
|
---|
| 297 | if (uart_getready(siopcb)) {
|
---|
| 298 | uart_ierdy_rcv(siopcb->exinf);
|
---|
| 299 | }
|
---|
| 300 | if (uart_putready(siopcb)) {
|
---|
| 301 | uart_ierdy_snd(siopcb->exinf);
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | void
|
---|
| 306 | uart_isr0()
|
---|
| 307 | {
|
---|
| 308 | uart_isr_siop(&(siopcb_table[0]));
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | #if TNUM_SIOP >= 2
|
---|
| 312 | void
|
---|
| 313 | uart_isr1()
|
---|
| 314 | {
|
---|
| 315 | uart_isr_siop(&(siopcb_table[1]));
|
---|
| 316 | }
|
---|
| 317 | #endif
|
---|
| 318 |
|
---|