[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 | * Copyright (C) 2007 by Embedded and Real-Time Systems Laboratory
|
---|
| 9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 10 | *
|
---|
| 11 | * ä¸è¨èä½æ¨©è
|
---|
| 12 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 13 | * ã«ãã£ã¦å
|
---|
| 14 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 15 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 16 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 17 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 18 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 19 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 20 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 21 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 22 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 23 | * ç¨ã§ããå½¢ã§åé
|
---|
| 24 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 25 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 26 | * è
|
---|
| 27 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 28 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 29 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 30 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 31 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 32 | * ã¨ï¼
|
---|
| 33 | * (a) åé
|
---|
| 34 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 35 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 36 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 37 | * (b) åé
|
---|
| 38 | å¸ã®å½¢æ
|
---|
| 39 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 40 | * å ±åãããã¨ï¼
|
---|
| 41 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 42 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 43 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 44 | 責ãããã¨ï¼
|
---|
| 45 | *
|
---|
| 46 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 47 | ã
|
---|
| 48 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 49 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 50 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 51 | *
|
---|
| 52 | * @(#) $Id: hw_serial.c,v 1.2 2007/05/28 02:03:55 honda Exp $
|
---|
| 53 | */
|
---|
| 54 |
|
---|
| 55 | /*
|
---|
| 56 | * ã·ãªã¢ã«I/Oããã¤ã¹ï¼SIOï¼ãã©ã¤ãï¼M32102å
|
---|
| 57 | èµéåæã·ãªã¢ã«ç¨ï¼
|
---|
| 58 | */
|
---|
| 59 |
|
---|
| 60 | #include <sil.h>
|
---|
| 61 | #include <hw_serial.h>
|
---|
| 62 |
|
---|
| 63 | #include <cpu_rename.h>
|
---|
| 64 | #include <sys_rename.h>
|
---|
| 65 |
|
---|
| 66 | SIOPCB siopcb_table[TNUM_PORT];
|
---|
| 67 |
|
---|
| 68 | extern FP InterruptHandlerEntry[];
|
---|
| 69 |
|
---|
| 70 | /*
|
---|
| 71 | * ä½æ¥ç¨é¢æ°
|
---|
| 72 | */
|
---|
| 73 | #define ID_PORT(x) ((x) + 1)
|
---|
| 74 | #define INDEX_PORT(x) ((x) - 1)
|
---|
| 75 | #define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
|
---|
| 76 |
|
---|
| 77 | /*
|
---|
| 78 | * ã·ãªã¢ã«ãã¼ãã®åæå
|
---|
| 79 | */
|
---|
| 80 | void
|
---|
| 81 | sio_initialize(void)
|
---|
| 82 | {
|
---|
| 83 | int i;
|
---|
| 84 |
|
---|
| 85 | for(i=0;i<TNUM_PORT;i++)
|
---|
| 86 | {
|
---|
| 87 | siopcb_table[i].flags = SIO_TYP_M32RUART;
|
---|
| 88 | siopcb_table[i].port = i;
|
---|
| 89 | siopcb_table[i].exinf = 0;
|
---|
| 90 |
|
---|
| 91 | InterruptHandlerEntry[INT_SIO0RCV + (siopcb_table[i].port * 2) - 1] = sio_handler_in;
|
---|
| 92 | InterruptHandlerEntry[INT_SIO0XMT + (siopcb_table[i].port * 2) - 1] = sio_handler_out;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /*
|
---|
| 97 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 98 | */
|
---|
| 99 | SIOPCB *
|
---|
| 100 | sio_opn_por(ID siopid, VP_INT exinf)
|
---|
| 101 | {
|
---|
| 102 | SIOPCB * siopcb = GET_SIOPCB(siopid);
|
---|
| 103 |
|
---|
| 104 | siopcb->exinf = exinf;
|
---|
| 105 |
|
---|
| 106 | switch(SIO_TYP(siopcb->flags))
|
---|
| 107 | {
|
---|
| 108 | case SIO_TYP_M32RUART:
|
---|
| 109 | /* UARTåæå */
|
---|
| 110 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
|
---|
| 111 |
|
---|
| 112 | /* ãã¼ããéã(UART0) */
|
---|
| 113 | sil_wrb_mem((void *)PDATA(5), 0);
|
---|
| 114 | sil_wrb_mem((void *)PDIR(5), 0x80);
|
---|
| 115 |
|
---|
| 116 | /* UART, Non-parity, 1 stop-bit */
|
---|
| 117 | sil_wrb_mem((void *)(SIOMOD0(siopcb->port)+3), 0);
|
---|
| 118 |
|
---|
| 119 | /* 8bit, internal clock */
|
---|
| 120 | sil_wrh_mem((void *)(SIOMOD1(siopcb->port)+2), 0x0800);
|
---|
| 121 |
|
---|
| 122 | /* m3a_za36 10MHzã§57600bps */
|
---|
| 123 | sil_wrh_mem((void *)(SIOBAUR(siopcb->port)+2),SERIAL_CLKDIV);
|
---|
| 124 | sil_wrb_mem((void *)(SIORBAUR(siopcb->port)+3), SERIAL_CLKCMP);
|
---|
| 125 |
|
---|
| 126 | /* éåä¿¡å²è¾¼ã¿çºçè¨±å¯ */
|
---|
| 127 | sil_wrh_mem((void *)(SIOTRCR(siopcb->port)+2), 0x0006);
|
---|
| 128 |
|
---|
| 129 | /* ã¹ãã¼ã¿ã¹ã¯ãªã¢, éåä¿¡åä½éå§ */
|
---|
| 130 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+2), 0x3);
|
---|
| 131 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0x3);
|
---|
| 132 |
|
---|
| 133 | /* éåä¿¡å²è¾¼ã¿è¦æ±åä»è¨±å¯ */
|
---|
| 134 | sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+2), 0x1000); /* åä¿¡å²è¾¼ã¿è¦æ±è¨±å¯ */
|
---|
| 135 | sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+6), 0x1000); /* éä¿¡å²è¾¼ã¿è¦æ±è¨±å¯ */
|
---|
| 136 |
|
---|
| 137 | /* TxD,RxDãã³æå¹(UART0) */
|
---|
| 138 | sil_wrh_mem((void *)PMOD(5), 0x5500);
|
---|
| 139 |
|
---|
| 140 | break;
|
---|
| 141 | }
|
---|
| 142 | return siopcb;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | /*
|
---|
| 146 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
| 147 | */
|
---|
| 148 | void
|
---|
| 149 | sio_cls_por(SIOPCB *siopcb)
|
---|
| 150 | {
|
---|
| 151 | switch(SIO_TYP(siopcb->flags))
|
---|
| 152 | {
|
---|
| 153 | case SIO_TYP_M32RUART:
|
---|
| 154 | /* éåä¿¡åä½ãç¦æ¢ãã */
|
---|
| 155 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
|
---|
| 156 | break;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
| 162 | */
|
---|
| 163 | INT sio_rcv_chr(SIOPCB * siopcb)
|
---|
| 164 | {
|
---|
| 165 | switch(SIO_TYP(siopcb->flags))
|
---|
| 166 | {
|
---|
| 167 | case SIO_TYP_M32RUART:
|
---|
| 168 | return sil_reb_mem((void *)(SIORXB(siopcb->port)+3));
|
---|
| 169 | }
|
---|
| 170 | return -1;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | /*
|
---|
| 175 | * æåãåä¿¡ãããï¼
|
---|
| 176 | */
|
---|
| 177 |
|
---|
| 178 | inline BOOL
|
---|
| 179 | hw_port_getready(SIOPCB *p)
|
---|
| 180 | {
|
---|
| 181 | switch(SIO_TYP(p->flags))
|
---|
| 182 | {
|
---|
| 183 | case SIO_TYP_M32RUART:
|
---|
| 184 | return (sil_reb_mem((void *)(SIOSTS(p->port)+3)) & 0x4) != 0 ? TRUE : FALSE;
|
---|
| 185 | }
|
---|
| 186 | return FALSE;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /*
|
---|
| 190 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯è¨±å¯
|
---|
| 191 | */
|
---|
| 192 | void sio_ena_cbr(SIOPCB * siopcb, UINT cbrtn)
|
---|
| 193 | {}
|
---|
| 194 |
|
---|
| 195 | /*
|
---|
| 196 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ç¦æ¢
|
---|
| 197 | */
|
---|
| 198 | void sio_dis_cbr(SIOPCB * siopcb, UINT cbrtn)
|
---|
| 199 | {}
|
---|
| 200 |
|
---|
| 201 | /*
|
---|
| 202 | * ã·ãªã¢ã«ãã¼ãã®åä¿¡å²è¾¼ã¿ãã³ãã©
|
---|
| 203 | */
|
---|
| 204 | void sio_handler_in(void)
|
---|
| 205 | {
|
---|
| 206 | int port;
|
---|
| 207 |
|
---|
| 208 | for(port = 0; port < TNUM_PORT; ++ port){
|
---|
| 209 | if( hw_port_getready(&siopcb_table[port]) == TRUE )
|
---|
| 210 | {
|
---|
| 211 | sio_ierdy_rcv(GET_SIOPCB(ID_PORT(port))->exinf);
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | /*
|
---|
| 217 | * ã·ãªã¢ã«ãã¼ãã®éä¿¡å²è¾¼ã¿ãã³ãã©
|
---|
| 218 | */
|
---|
| 219 | void sio_handler_out(void)
|
---|
| 220 | {
|
---|
| 221 | int port;
|
---|
| 222 |
|
---|
| 223 | for(port = 0; port < TNUM_PORT; ++ port) {
|
---|
| 224 | if((siopcb_table[port].flags & SIO_STS_SENDING) != 0) {
|
---|
| 225 | //éä¿¡ã¹ãã¼ã¿ã¹åæå
|
---|
| 226 | sil_wrb_mem((void *)(SIOCR(port)+2), 0x1);
|
---|
| 227 | siopcb_table[port].flags &= ~SIO_STS_SENDING;
|
---|
| 228 |
|
---|
| 229 | sio_ierdy_snd(GET_SIOPCB(ID_PORT(port))->exinf);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|