[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-2004 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | * Copyright (C) 2001-2010 by Industrial Technology Institute,
|
---|
| 9 | * Miyagi Prefectural Government, JAPAN
|
---|
| 10 | * Copyright (C) 2001-2004 by Dep. of Computer Science and Engineering
|
---|
| 11 | * Tomakomai National College of Technology, JAPAN
|
---|
| 12 | *
|
---|
| 13 | * ä¸è¨èä½æ¨©è
|
---|
| 14 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 15 | * ã«ãã£ã¦å
|
---|
| 16 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 17 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 18 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 19 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 20 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 21 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 22 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 23 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 24 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 25 | * ç¨ã§ããå½¢ã§åé
|
---|
| 26 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 27 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 28 | * è
|
---|
| 29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 30 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 31 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 32 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 33 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 34 | * ã¨ï¼
|
---|
| 35 | * (a) åé
|
---|
| 36 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 37 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 38 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 39 | * (b) åé
|
---|
| 40 | å¸ã®å½¢æ
|
---|
| 41 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 42 | * å ±åãããã¨ï¼
|
---|
| 43 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 44 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 46 | 責ãããã¨ï¼
|
---|
| 47 | *
|
---|
| 48 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 49 | ã
|
---|
| 50 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 51 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 52 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 53 | *
|
---|
| 54 | * @(#) $Id: hw_serial.h,v 1.17 2007/03/23 07:22:15 honda Exp $
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | #ifndef _HW_SERIAL_H_
|
---|
| 58 | #define _HW_SERIAL_H_
|
---|
| 59 |
|
---|
| 60 | /*
|
---|
| 61 | * ã¿ã¼ã²ããä¾åã·ãªã¢ã«I/Oã¢ã¸ã¥ã¼ã«ï¼H8ç¨ï¼
|
---|
| 62 | * ã»ãã¼ãã 1æ¬ã®å ´å㯠HWPORT1_ADDRã«æå®ããããã¼ãã使ç¨ãã
|
---|
| 63 | * 2æ¬ã®å ´åã¯ãHWPORT1_ADDRãã¦ã¼ã¶ç¨ãHWPORT2_ADDRãã³ã³ã½ã¼ã«
|
---|
| 64 | * åºåã¨ãã¦ä½¿ç¨ããã
|
---|
| 65 | * HWPORTx_ADDR㯠ã¿ã¼ã²ããä¾åã® sys_config.hä¸ã§æå®ããã
|
---|
| 66 | * ã»å
|
---|
| 67 | ±éé¨ã®ã¢ã¸ã¥ã¼ã«ã«ãã£ã¦ãXON/XOFFããã¼å¶å¾¡ãè¡ã
|
---|
| 68 | * ãã¦ããã®ã§ãä¿¡å·ç·ã¯TxDã¨RxDã®2æ¬ã§ãã
|
---|
| 69 | */
|
---|
| 70 |
|
---|
| 71 | #include <s_services.h>
|
---|
| 72 |
|
---|
| 73 | #ifndef _MACRO_ONLY
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | * ã·ãªã¢ã«ãã¼ãã®åæåãããã¯
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | typedef struct sio_port_initialization_block {
|
---|
| 80 | UW base; /* SCI ã®ãã¼ã¹ã¢ãã¬ã¹ */
|
---|
| 81 | UW baudrate; /* ãã¼ã¬ã¼ã */
|
---|
| 82 | IRC irc; /* å²è¾¼ã¿ã¬ãã«è¨å®æ
|
---|
| 83 | å ± */
|
---|
| 84 | UB smr_init; /* SMR ã®è¨å®å¤ */
|
---|
| 85 | } SIOPINIB;
|
---|
| 86 |
|
---|
| 87 | /*
|
---|
| 88 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡ãããã¯
|
---|
| 89 | */
|
---|
| 90 |
|
---|
| 91 | typedef struct sio_port_control_block {
|
---|
| 92 | const SIOPINIB *inib; /* åæåããã㯠*/
|
---|
| 93 | VP_INT exinf; /* æ¡å¼µæ
|
---|
| 94 | å ± */
|
---|
| 95 | BOOL openflag; /* ãªã¼ãã³æ¸ã¿ãã©ã° */
|
---|
| 96 | } SIOPCB;
|
---|
| 97 |
|
---|
| 98 | extern SIOPCB siopcb_table[TNUM_PORT];
|
---|
| 99 |
|
---|
| 100 | /*
|
---|
| 101 | * SIO ID ãã管çãããã¯ã¸ã®å¤æãã¯ã
|
---|
| 102 | */
|
---|
| 103 |
|
---|
| 104 | #define INDEX_SIO(sioid) ((UINT)((sioid) - 1))
|
---|
| 105 | #define get_siopcb(sioid) (&(siopcb_table[INDEX_SIO(sioid)]))
|
---|
| 106 |
|
---|
| 107 | /*
|
---|
| 108 | * ã³ã¼ã«ããã¯ã«ã¼ãã³ã®èå¥çªå·
|
---|
| 109 | */
|
---|
| 110 |
|
---|
| 111 | #define SIO_ERDY_SND 1u /* éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 112 | #define SIO_ERDY_RCV 2u /* åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 113 |
|
---|
| 114 | /*
|
---|
| 115 | * SCI é¢æ°ã®åç
|
---|
| 116 | §
|
---|
| 117 | */
|
---|
| 118 |
|
---|
| 119 | extern void SCI_initialize (ID sioid); /* SCI ã®åæå */
|
---|
| 120 | extern void SCI_cls_por(UW base); /* SCI ã®ã¯ãã¼ãº */
|
---|
| 121 | extern void SCI_in_handler(ID sioid); /* SCI å
|
---|
| 122 | ¥åå²ãè¾¼ã¿ãã³ãã© */
|
---|
| 123 | extern void SCI_out_handler(ID sioid); /* SCI åºåå²ãè¾¼ã¿ãã³ãã© */
|
---|
| 124 | extern void SCI_err_handler(ID sioid); /* SCI å
|
---|
| 125 | ¥åã¨ã©ã¼å²ãè¾¼ã¿ãã³ãã© */
|
---|
| 126 | extern void SCI_ierdy_snd(VP_INT exinf); /* ã·ãªã¢ã« I/O ããã®éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 127 | extern void SCI_ierdy_rcv(VP_INT exinf); /* ã·ãªã¢ã« I/O ããã®åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 128 |
|
---|
| 129 | /*
|
---|
| 130 | * SCI ã¬ãã«ã®é¢æ°
|
---|
| 131 | */
|
---|
| 132 |
|
---|
| 133 | /*
|
---|
| 134 | * SCI ã®ãªã¼ãã³
|
---|
| 135 | */
|
---|
| 136 |
|
---|
| 137 | Inline SIOPCB *
|
---|
| 138 | SCI_opn_por (ID sioid)
|
---|
| 139 | {
|
---|
| 140 | SCI_initialize(sioid);
|
---|
| 141 | return get_siopcb(sioid);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * SCI_putchar -- éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
| 146 | */
|
---|
| 147 |
|
---|
| 148 | Inline void
|
---|
| 149 | SCI_putchar(SIOPCB *p, UB c)
|
---|
| 150 | {
|
---|
| 151 | UW addr = p->inib->base + H8SSR;
|
---|
| 152 |
|
---|
| 153 | sil_wrb_mem((VP)(p->inib->base + H8TDR), c);
|
---|
| 154 | bitclr((UB *)addr, H8SSR_TDRE_BIT);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | /*
|
---|
| 158 | * SCI_wait_putchar -- ç´æ¥åºå (å¾
|
---|
| 159 | ã¡ãã)
|
---|
| 160 | */
|
---|
| 161 |
|
---|
| 162 | Inline void
|
---|
| 163 | SCI_wait_putchar (int base, char c)
|
---|
| 164 | {
|
---|
| 165 | UW addr = base + H8SSR;
|
---|
| 166 |
|
---|
| 167 | /* TDRE ã 1 ã«ãªãã¾ã§å¾
|
---|
| 168 | 㤠*/
|
---|
| 169 | while ((sil_reb_mem((VP)addr) & H8SSR_TDRE) == 0)
|
---|
| 170 | ;
|
---|
| 171 | sil_wrb_mem((VP)(base + H8TDR), c);
|
---|
| 172 | bitclr((UB *)addr, H8SSR_TDRE_BIT);
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /*
|
---|
| 176 | * SCI_getchar -- åä¿¡ããæåã®èªã¿åºã
|
---|
| 177 | */
|
---|
| 178 |
|
---|
| 179 | Inline INT
|
---|
| 180 | SCI_getchar(SIOPCB *p)
|
---|
| 181 | {
|
---|
| 182 | INT ch;
|
---|
| 183 | UW addr = p->inib->base + H8SSR;
|
---|
| 184 |
|
---|
| 185 | ch = (INT)(UB)sil_reb_mem((VP)(p->inib->base + H8RDR));
|
---|
| 186 | /* UBåã¸ã®ãã£ã¹ãã¯ã符å·æ¡å¼µãé²ããã */
|
---|
| 187 |
|
---|
| 188 | bitclr((UB *)addr, H8SSR_RDRF_BIT);
|
---|
| 189 | return ch;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | * SCI_putready -- éä¿¡å¯è½ã
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | Inline BOOL
|
---|
| 197 | SCI_putready(SIOPCB *pcb)
|
---|
| 198 | {
|
---|
| 199 | UB ssr = sil_reb_mem((VP)(pcb->inib->base + H8SSR));
|
---|
| 200 | return ((ssr & H8SSR_TDRE) != 0);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | * SCI_getready -- åä¿¡å¯è½ã
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 | Inline BOOL
|
---|
| 208 | SCI_getready(SIOPCB *pcb)
|
---|
| 209 | {
|
---|
| 210 | #ifndef HEW_SIMULATOR
|
---|
| 211 | UB ssr = sil_reb_mem((VP)(pcb->inib->base + H8SSR));
|
---|
| 212 | return ((ssr & H8SSR_RDRF) != 0);
|
---|
| 213 | #else /* HEW_SIMULATOR */
|
---|
| 214 | return TRUE;
|
---|
| 215 | #endif /* HEW_SIMULATOR */
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | /*
|
---|
| 219 | * éä¿¡å²ãè¾¼ã¿å¶å¾¡é¢æ°
|
---|
| 220 | */
|
---|
| 221 |
|
---|
| 222 | Inline void
|
---|
| 223 | SCI_enable_send(SIOPCB *p)
|
---|
| 224 | {
|
---|
| 225 | UW addr = p->inib->base + H8SCR;
|
---|
| 226 |
|
---|
| 227 | bitset((UB *)addr, H8SCR_TIE_BIT);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | Inline void
|
---|
| 231 | SCI_disable_send(SIOPCB *p)
|
---|
| 232 | {
|
---|
| 233 | UW addr = p->inib->base + H8SCR;
|
---|
| 234 |
|
---|
| 235 | bitclr((UB *)addr, H8SCR_TIE_BIT);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | /*
|
---|
| 239 | * åä¿¡å²ãè¾¼ã¿å¶å¾¡é¢æ°
|
---|
| 240 | */
|
---|
| 241 |
|
---|
| 242 | Inline void
|
---|
| 243 | SCI_enable_recv(SIOPCB *p)
|
---|
| 244 | {
|
---|
| 245 | UW addr = p->inib->base + H8SCR;
|
---|
| 246 |
|
---|
| 247 | bitset((UB *)addr, H8SCR_RIE_BIT);
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | Inline void
|
---|
| 251 | SCI_disable_recv(SIOPCB *p)
|
---|
| 252 | {
|
---|
| 253 | UW addr = p->inib->base + H8SCR;
|
---|
| 254 |
|
---|
| 255 | bitclr((UB *)addr, H8SCR_RIE_BIT);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /*
|
---|
| 259 | * SIO é¢æ°ã®åç
|
---|
| 260 | §
|
---|
| 261 | */
|
---|
| 262 |
|
---|
| 263 | extern void sio_initialize(void); /* SCI ã®åæå */
|
---|
| 264 | extern void sio_ena_cbr(SIOPCB *pcb, UINT cbrtn); /* ã·ãªã¢ã« I/O ããã®ã³ã¼ã«ããã¯è¨±å¯ */
|
---|
| 265 | extern void sio_dis_cbr(SIOPCB *pcb, UINT cbrtn); /* ã·ãªã¢ã« I/O ããã®ã³ã¼ã«ããã¯ç¦æ¢ */
|
---|
| 266 |
|
---|
| 267 | /*
|
---|
| 268 | * é¢æ°ã·ãã¥ã¬ã¼ã·ã§ã³ãã¯ã
|
---|
| 269 | */
|
---|
| 270 | /* SCI ããã®æååä¿¡ */
|
---|
| 271 | #ifdef HEW_SIMULATOR
|
---|
| 272 | extern BOOL hew_io_sim_snd_chr(char c);
|
---|
| 273 | #define sio_snd_chr(siopcb, c) hew_io_sim_snd_chr(c)
|
---|
| 274 |
|
---|
| 275 | #else /* HEW_SIMULATOR */
|
---|
| 276 | #define sio_snd_chr(p,c) SCI_snd_chr(p,c)
|
---|
| 277 | #endif /* HEW_SIMULATOR */
|
---|
| 278 | /* SCI ããã®æååä¿¡ */
|
---|
| 279 | #ifdef HEW_SIMULATOR
|
---|
| 280 | extern INT hew_io_sim_rcv_chr(void);
|
---|
| 281 | #define sio_rcv_chr(siopcb) hew_io_sim_rcv_chr( )
|
---|
| 282 |
|
---|
| 283 | #else /* HEW_SIMULATOR */
|
---|
| 284 | #define sio_rcv_chr(p) SCI_rcv_chr(p)
|
---|
| 285 | #endif /* HEW_SIMULATOR */
|
---|
| 286 |
|
---|
| 287 | #define sio_ierdy_snd(e) SCI_ierdy_snd(e) /* ã·ãªã¢ã« I/O ããã®éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 288 | #define sio_ierdy_rcv(e) SCI_ierdy_rcv(e) /* ã·ãªã¢ã« I/O ããã®åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 289 |
|
---|
| 290 | /*
|
---|
| 291 | * SIO ã¬ãã«ã®é¢æ°
|
---|
| 292 | */
|
---|
| 293 |
|
---|
| 294 | /*
|
---|
| 295 | * sio_opn_por -- ãã¼ãã®ãªã¼ãã³
|
---|
| 296 | */
|
---|
| 297 |
|
---|
| 298 | Inline SIOPCB *
|
---|
| 299 | sio_opn_por(ID sioid, VP_INT exinf)
|
---|
| 300 | {
|
---|
| 301 | SIOPCB *pcb;
|
---|
| 302 |
|
---|
| 303 | pcb = SCI_opn_por(sioid);
|
---|
| 304 | pcb->exinf = exinf;
|
---|
| 305 | pcb->openflag = TRUE;
|
---|
| 306 | return pcb;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | /*
|
---|
| 310 | * sio_cls_por -- ãã¼ãã®ã¯ãã¼ãº
|
---|
| 311 | */
|
---|
| 312 |
|
---|
| 313 | Inline void
|
---|
| 314 | sio_cls_por(SIOPCB *pcb)
|
---|
| 315 | {
|
---|
| 316 | SCI_cls_por(pcb->inib->base);
|
---|
| 317 | pcb->openflag = FALSE;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | /*
|
---|
| 321 | * sio_snd_chr -- æåéä¿¡
|
---|
| 322 | */
|
---|
| 323 |
|
---|
| 324 | #ifndef HEW_SIMULATOR
|
---|
| 325 | Inline BOOL
|
---|
| 326 | sio_snd_chr(SIOPCB *pcb, INT chr)
|
---|
| 327 | {
|
---|
| 328 | if (SCI_putready(pcb)) {
|
---|
| 329 | SCI_putchar(pcb, (UB)chr);
|
---|
| 330 | return TRUE;
|
---|
| 331 | } else {
|
---|
| 332 | return FALSE;
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 | #endif /* HEW_SIMULATOR */
|
---|
| 336 |
|
---|
| 337 | /*
|
---|
| 338 | * sio_rcv_chr -- æååä¿¡
|
---|
| 339 | */
|
---|
| 340 |
|
---|
| 341 | #ifndef HEW_SIMULATOR
|
---|
| 342 | Inline INT
|
---|
| 343 | sio_rcv_chr(SIOPCB *pcb)
|
---|
| 344 | {
|
---|
| 345 | if (SCI_getready(pcb)) {
|
---|
| 346 | return SCI_getchar(pcb);
|
---|
| 347 | } else {
|
---|
| 348 | return -1;
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | #endif /* HEW_SIMULATOR */
|
---|
| 352 |
|
---|
| 353 | #endif /* of #ifndef _MACRO_ONLY */
|
---|
| 354 |
|
---|
| 355 | #endif /* _HW_SERIAL_H_ */
|
---|