[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 | *
|
---|
| 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: hw_serial.c,v 1.1 2007/05/30 08:38:51 honda Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | /*
|
---|
| 54 | * ã·ãªã¢ã«I/Oããã¤ã¹ï¼SIOï¼ãã©ã¤ãï¼M32102å
|
---|
| 55 | èµéåæã·ãªã¢ã«ç¨ï¼
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | #include <sil.h>
|
---|
| 59 | #include <hw_serial.h>
|
---|
| 60 |
|
---|
| 61 | #include <cpu_rename.h>
|
---|
| 62 | #include <sys_rename.h>
|
---|
| 63 |
|
---|
| 64 | SIOPCB siopcb_table[TNUM_PORT];
|
---|
| 65 |
|
---|
| 66 | extern FP InterruptHandlerEntry[];
|
---|
| 67 |
|
---|
| 68 | /*
|
---|
| 69 | * ä½æ¥ç¨é¢æ°
|
---|
| 70 | */
|
---|
| 71 | #define ID_PORT(x) ((x) + 1)
|
---|
| 72 | #define INDEX_PORT(x) ((x) - 1)
|
---|
| 73 | #define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | * ã·ãªã¢ã«ãã¼ãã®åæå
|
---|
| 77 | */
|
---|
| 78 | void
|
---|
| 79 | sio_initialize(void)
|
---|
| 80 | {
|
---|
| 81 | int i;
|
---|
| 82 |
|
---|
| 83 | for(i=0;i<TNUM_PORT;i++)
|
---|
| 84 | {
|
---|
| 85 | siopcb_table[i].flags = SIO_TYP_M32RUART;
|
---|
| 86 | siopcb_table[i].port = i;
|
---|
| 87 | siopcb_table[i].exinf = 0;
|
---|
| 88 |
|
---|
| 89 | InterruptHandlerEntry[INT_SIO0RCV + (siopcb_table[i].port * 2) - 1] = sio_handler_in;
|
---|
| 90 | InterruptHandlerEntry[INT_SIO0XMT + (siopcb_table[i].port * 2) - 1] = sio_handler_out;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /*
|
---|
| 95 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 96 | */
|
---|
| 97 | SIOPCB *
|
---|
| 98 | sio_opn_por(ID siopid, VP_INT exinf)
|
---|
| 99 | {
|
---|
| 100 | SIOPCB * siopcb = GET_SIOPCB(siopid);
|
---|
| 101 |
|
---|
| 102 | siopcb->exinf = exinf;
|
---|
| 103 |
|
---|
| 104 | switch(SIO_TYP(siopcb->flags)) {
|
---|
| 105 | case SIO_TYP_M32RUART:
|
---|
| 106 |
|
---|
| 107 | /* UARTåæå */
|
---|
| 108 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
|
---|
| 109 |
|
---|
| 110 | /* ãã¼ããéã(UART0) */
|
---|
| 111 | sil_wrb_mem((void *)PDATA(5), 0);
|
---|
| 112 | sil_wrb_mem((void *)PDIR(5), 0x80);
|
---|
| 113 |
|
---|
| 114 | /* UART, Non-parity, 1 stop-bit */
|
---|
| 115 | sil_wrb_mem((void *)(SIOMOD0(siopcb->port)+3), 0);
|
---|
| 116 |
|
---|
| 117 | /* 8bit, internal clock */
|
---|
| 118 | sil_wrh_mem((void *)(SIOMOD1(siopcb->port)+2), 0x0800);
|
---|
| 119 |
|
---|
| 120 | /* M32R(32102) - f(BLK)=16MHzã§115200bps */
|
---|
| 121 | sil_wrh_mem((void *)(SIOBAUR(siopcb->port)+2), SERIAL_CLKDIV);
|
---|
| 122 | sil_wrb_mem((void *)(SIORBAUR(siopcb->port)+3), SERIAL_CLKCMP);
|
---|
| 123 |
|
---|
| 124 | /* éåä¿¡å²è¾¼ã¿çºçè¨±å¯ */
|
---|
| 125 | sil_wrh_mem((void *)(SIOTRCR(siopcb->port)+2), 0x0006);
|
---|
| 126 |
|
---|
| 127 | /* ã¹ãã¼ã¿ã¹ã¯ãªã¢, éåä¿¡åä½éå§ */
|
---|
| 128 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+2), 0x3);
|
---|
| 129 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0x3);
|
---|
| 130 |
|
---|
| 131 | /* åä¿¡å²è¾¼ã¿åä»è¨±å¯ */
|
---|
| 132 | sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+2), 0x1000);
|
---|
| 133 | sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+6), 0x1000);
|
---|
| 134 |
|
---|
| 135 | /* TxD,RxDãã³æå¹(UART0) */
|
---|
| 136 | sil_wrh_mem((void *)PMOD(5), 0x5500);
|
---|
| 137 |
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | return siopcb;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
| 146 | */
|
---|
| 147 | void
|
---|
| 148 | sio_cls_por(SIOPCB *siopcb)
|
---|
| 149 | {
|
---|
| 150 | switch(SIO_TYP(siopcb->flags))
|
---|
| 151 | {
|
---|
| 152 | case SIO_TYP_M32RUART:
|
---|
| 153 | /* éåä¿¡åä½ãç¦æ¢ãã */
|
---|
| 154 | sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
|
---|
| 155 | break;
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /*
|
---|
| 160 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
| 161 | */
|
---|
| 162 | INT sio_rcv_chr(SIOPCB * siopcb)
|
---|
| 163 | {
|
---|
| 164 | switch(SIO_TYP(siopcb->flags))
|
---|
| 165 | {
|
---|
| 166 | case SIO_TYP_M32RUART:
|
---|
| 167 | return sil_reb_mem((void *)(SIORXB(siopcb->port)+3));
|
---|
| 168 | }
|
---|
| 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 | void sio_handler_in(void)
|
---|
| 202 | {
|
---|
| 203 | int port;
|
---|
| 204 |
|
---|
| 205 | for(port = 0; port < TNUM_PORT; ++ port)
|
---|
| 206 | {
|
---|
| 207 | if( hw_port_getready(&siopcb_table[port]) == TRUE )
|
---|
| 208 | sio_ierdy_rcv(GET_SIOPCB(ID_PORT(port))->exinf);
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | void sio_handler_out(void)
|
---|
| 213 | {
|
---|
| 214 | int port;
|
---|
| 215 |
|
---|
| 216 | for(port = 0; port < TNUM_PORT; ++ port)
|
---|
| 217 | {
|
---|
| 218 | if((siopcb_table[port].flags & SIO_STS_SENDING) != 0)
|
---|
| 219 | {
|
---|
| 220 | /* éä¿¡ã¹ãã¼ã¿ã¹åæå */
|
---|
| 221 | sil_wrb_mem((void *)(SIOCR(port)+2), 0x1);
|
---|
| 222 | siopcb_table[port].flags &= ~SIO_STS_SENDING;
|
---|
| 223 |
|
---|
| 224 | sio_ierdy_snd(GET_SIOPCB(ID_PORT(port))->exinf);
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|