[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-2004 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | * Copyright (C) 2001-2007 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.7 2007/03/23 07:58:33 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 | #include <h8_sil.h>
|
---|
| 73 |
|
---|
| 74 | #ifndef _MACRO_ONLY
|
---|
| 75 |
|
---|
| 76 | /*
|
---|
| 77 | * ã·ãªã¢ã«ãã¼ãã®åæåãããã¯
|
---|
| 78 | */
|
---|
| 79 | typedef struct sio_port_initialization_block {
|
---|
| 80 | UB *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 | #define INDEX_SIO(sioid) ((UINT)(sioid) - 1u)
|
---|
| 104 |
|
---|
| 105 | Inline SIOPCB*
|
---|
| 106 | get_siopcb(ID sioid)
|
---|
| 107 | {
|
---|
| 108 | UINT index = INDEX_SIO(sioid);
|
---|
| 109 |
|
---|
| 110 | assert(index < TNUM_PORT);
|
---|
| 111 |
|
---|
| 112 | return(&(siopcb_table[index]));
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /*
|
---|
| 116 | * ã³ã¼ã«ããã¯ã«ã¼ãã³ã®èå¥çªå·
|
---|
| 117 | */
|
---|
| 118 | #define SIO_ERDY_SND 1u /* éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 119 | #define SIO_ERDY_RCV 2u /* åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 120 |
|
---|
| 121 | /*
|
---|
| 122 | * SCI é¢æ°ã®åç
|
---|
| 123 | §
|
---|
| 124 | */
|
---|
| 125 | extern void SCI_initialize (ID sioid); /* SCI ã®åæå */
|
---|
| 126 | extern void SCI_cls_por(UB *base); /* SCI ã®ã¯ãã¼ãº */
|
---|
| 127 | extern void SCI_in_handler(ID sioid); /* SCI å
|
---|
| 128 | ¥åå²ãè¾¼ã¿ãã³ãã© */
|
---|
| 129 | extern void SCI_out_handler(ID sioid); /* SCI åºåå²ãè¾¼ã¿ãã³ãã© */
|
---|
| 130 | extern void SCI_err_handler(ID sioid); /* SCI å
|
---|
| 131 | ¥åã¨ã©ã¼å²ãè¾¼ã¿ãã³ãã© */
|
---|
| 132 | extern void SCI_ierdy_snd(VP_INT exinf); /* ã·ãªã¢ã« I/O ããã®éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 133 | extern void SCI_ierdy_rcv(VP_INT exinf); /* ã·ãªã¢ã« I/O ããã®åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * SCI ã¬ãã«ã®é¢æ°
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | /*
|
---|
| 140 | * SCI ã®ãªã¼ãã³
|
---|
| 141 | */
|
---|
| 142 | Inline SIOPCB *
|
---|
| 143 | SCI_opn_por (ID sioid)
|
---|
| 144 | {
|
---|
| 145 | SCI_initialize(sioid);
|
---|
| 146 | return get_siopcb(sioid);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /*
|
---|
| 150 | * SCI_putchar -- éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
| 151 | */
|
---|
| 152 | Inline void
|
---|
| 153 | SCI_putchar(const SIOPCB *p, UB c)
|
---|
| 154 | {
|
---|
| 155 | UB *base_addr = p->inib->base;
|
---|
| 156 |
|
---|
| 157 | sil_wrb_mem((VP)(base_addr + H8TDR), (VB)c);
|
---|
| 158 | bitclr(base_addr + H8SSR, (UB)H8SSR_TDRE_BIT);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | /*
|
---|
| 163 | * ä½ã¬ãã«åºåã«ç¨ããã·ãªã¢ã«ãã¼ãã
|
---|
| 164 | * å¶å¾¡ããã¬ã¸ã¹ã¿ç¾¤ã®å
|
---|
| 165 | é ã¢ãã¬ã¹
|
---|
| 166 | */
|
---|
| 167 | #if SCI_LOW_PORTID == SCI_PORTID1
|
---|
| 168 | #define SCI_LOW_BASE SCI_PORT1_BASE
|
---|
| 169 | #else /* SCI_LOW_PORTID == SCI_PORTID1 */
|
---|
| 170 | #define SCI_LOW_BASE SCI_PORT2_BASE
|
---|
| 171 | #endif
|
---|
| 172 |
|
---|
| 173 | /*
|
---|
| 174 | * SCI_putchar_pol -- ãã¼ãªã³ã°æ¹å¼ã«ããä½ã¬ãã«åºå
|
---|
| 175 | */
|
---|
| 176 | Inline void
|
---|
| 177 | SCI_putchar_pol(UB c)
|
---|
| 178 | {
|
---|
| 179 | UB *base = (UB*)SCI_LOW_BASE;
|
---|
| 180 | UB *addr = base + H8SSR;
|
---|
| 181 | UB tdre = 0;
|
---|
| 182 |
|
---|
| 183 | /* TDREãã»ãããããã¾ã§å¾
|
---|
| 184 | 㤠*/
|
---|
| 185 | while (tdre == 0) {
|
---|
| 186 | /* ã³ã³ãã¤ã©ã®è¦åãæå¶ããããããã£ã¹ããã¦ãã */
|
---|
| 187 | tdre = (UB)((UB)sil_reb_mem((VP)addr) & H8SSR_TDRE);
|
---|
| 188 | }
|
---|
| 189 | sil_wrb_mem((VP)(base + H8TDR), (VB)c);
|
---|
| 190 | bitclr(addr, (UB)H8SSR_TDRE_BIT);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | /*
|
---|
| 194 | * SCI_getchar -- åä¿¡ããæåã®èªã¿åºã
|
---|
| 195 | */
|
---|
| 196 | Inline INT
|
---|
| 197 | SCI_getchar(const SIOPCB *p)
|
---|
| 198 | {
|
---|
| 199 | UB *base_addr = p->inib->base;
|
---|
| 200 | INT ch = (UB)sil_reb_mem((VP)(base_addr + H8RDR));
|
---|
| 201 | /* UB ã®ãã£ã¹ãã¯ã符å·æ¡å¼µãé²æ¢ãããã */
|
---|
| 202 |
|
---|
| 203 | bitclr(base_addr + H8SSR, (UB)H8SSR_RDRF_BIT);
|
---|
| 204 | return ch;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /*
|
---|
| 208 | * SCI_putready -- éä¿¡å¯è½ã
|
---|
| 209 | */
|
---|
| 210 | Inline BOOL
|
---|
| 211 | SCI_putready(const SIOPCB *pcb)
|
---|
| 212 | {
|
---|
| 213 | BOOL ret = TRUE;
|
---|
| 214 | UB ssr = sil_reb_mem((VP)(pcb->inib->base + H8SSR));
|
---|
| 215 |
|
---|
| 216 | ssr &= (UB)H8SSR_TDRE;
|
---|
| 217 | if (ssr == 0) {
|
---|
| 218 | ret = FALSE;
|
---|
| 219 | }
|
---|
| 220 | return(ret);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /*
|
---|
| 224 | * SCI_getready -- åä¿¡å¯è½ã
|
---|
| 225 | */
|
---|
| 226 | Inline BOOL
|
---|
| 227 | SCI_getready(const SIOPCB *pcb)
|
---|
| 228 | {
|
---|
| 229 | BOOL ret = TRUE;
|
---|
| 230 | UB ssr = sil_reb_mem((VP)(pcb->inib->base + H8SSR));
|
---|
| 231 |
|
---|
| 232 | ssr &= (UB)H8SSR_RDRF;
|
---|
| 233 | if (ssr == 0) {
|
---|
| 234 | ret = FALSE;
|
---|
| 235 | }
|
---|
| 236 | return(ret);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | /*
|
---|
| 240 | * éä¿¡å²ãè¾¼ã¿å¶å¾¡é¢æ°
|
---|
| 241 | */
|
---|
| 242 | Inline void
|
---|
| 243 | SCI_enable_send(const SIOPCB *p)
|
---|
| 244 | {
|
---|
| 245 | UB *addr = p->inib->base + H8SCR;
|
---|
| 246 | bitset(addr, (UB)H8SCR_TIE_BIT);
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | Inline void
|
---|
| 250 | SCI_disable_send(const SIOPCB *p)
|
---|
| 251 | {
|
---|
| 252 | UB *addr = p->inib->base + H8SCR;
|
---|
| 253 | bitclr(addr, (UB)H8SCR_TIE_BIT);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /*
|
---|
| 257 | * åä¿¡å²ãè¾¼ã¿å¶å¾¡é¢æ°
|
---|
| 258 | */
|
---|
| 259 | Inline void
|
---|
| 260 | SCI_enable_recv(const SIOPCB *p)
|
---|
| 261 | {
|
---|
| 262 | UB *addr = p->inib->base + H8SCR;
|
---|
| 263 | bitset(addr, (UB)H8SCR_RIE_BIT);
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | Inline void
|
---|
| 267 | SCI_disable_recv(const SIOPCB *p)
|
---|
| 268 | {
|
---|
| 269 | UB *addr = p->inib->base + H8SCR;
|
---|
| 270 | bitclr(addr, (UB)H8SCR_RIE_BIT);
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | /*
|
---|
| 274 | * SIO é¢æ°ã®åç
|
---|
| 275 | §
|
---|
| 276 | */
|
---|
| 277 | /* SCI ã®åæå */
|
---|
| 278 | extern void sio_initialize(void);
|
---|
| 279 | /* ã·ãªã¢ã« I/O ããã®ã³ã¼ã«ããã¯è¨±å¯ */
|
---|
| 280 | extern void sio_ena_cbr(SIOPCB *pcb, UINT cbrtn);
|
---|
| 281 | /* ã·ãªã¢ã« I/O ããã®ã³ã¼ã«ããã¯ç¦æ¢ */
|
---|
| 282 | extern void sio_dis_cbr(SIOPCB *pcb, UINT cbrtn);
|
---|
| 283 |
|
---|
| 284 | /*
|
---|
| 285 | * é¢æ°ã·ãã¥ã¬ã¼ã·ã§ã³ãã¯ã
|
---|
| 286 | */
|
---|
| 287 | /* ã·ãªã¢ã« I/O ããã®éä¿¡å¯è½ã³ã¼ã«ãã㯠*/
|
---|
| 288 | #define sio_ierdy_snd(e) SCI_ierdy_snd(e)
|
---|
| 289 | /* ã·ãªã¢ã« I/O ããã®åä¿¡éç¥ã³ã¼ã«ãã㯠*/
|
---|
| 290 | #define sio_ierdy_rcv(e) SCI_ierdy_rcv(e)
|
---|
| 291 |
|
---|
| 292 | /*
|
---|
| 293 | * SIO ã¬ãã«ã®é¢æ°
|
---|
| 294 | */
|
---|
| 295 |
|
---|
| 296 | extern void sio_in_handler (void);
|
---|
| 297 | extern void sio_out_handler (void);
|
---|
| 298 |
|
---|
| 299 | #ifdef H8_CFG_SCI_ERR_HANDLER
|
---|
| 300 | extern void sio_err_handler (void);
|
---|
| 301 | #endif /* of #ifdef H8_CFG_SCI_ERR_HANDLER */
|
---|
| 302 |
|
---|
| 303 | #if TNUM_PORT >= 2u
|
---|
| 304 | extern void sio_in2_handler (void);
|
---|
| 305 | extern void sio_out2_handler (void);
|
---|
| 306 |
|
---|
| 307 | #ifdef H8_CFG_SCI_ERR_HANDLER
|
---|
| 308 | extern void sio_err2_handler (void);
|
---|
| 309 | #endif /* of #ifdef H8_CFG_SCI_ERR_HANDLER */
|
---|
| 310 |
|
---|
| 311 | #endif /* of #if TNUM_PORT >= 2u */
|
---|
| 312 |
|
---|
| 313 | /*
|
---|
| 314 | * sio_opn_por -- ãã¼ãã®ãªã¼ãã³
|
---|
| 315 | */
|
---|
| 316 | Inline SIOPCB *
|
---|
| 317 | sio_opn_por(ID sioid, VP_INT exinf)
|
---|
| 318 | {
|
---|
| 319 | SIOPCB *pcb = SCI_opn_por(sioid);
|
---|
| 320 |
|
---|
| 321 | pcb->exinf = exinf;
|
---|
| 322 | pcb->openflag = TRUE;
|
---|
| 323 | return pcb;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | /*
|
---|
| 327 | * sio_cls_por -- ãã¼ãã®ã¯ãã¼ãº
|
---|
| 328 | */
|
---|
| 329 | Inline void
|
---|
| 330 | sio_cls_por(SIOPCB *pcb)
|
---|
| 331 | {
|
---|
| 332 | SCI_cls_por(pcb->inib->base);
|
---|
| 333 | pcb->openflag = FALSE;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | /*
|
---|
| 337 | * sio_snd_chr -- æåéä¿¡
|
---|
| 338 | */
|
---|
| 339 | Inline BOOL
|
---|
| 340 | sio_snd_chr(const SIOPCB *pcb, char chr)
|
---|
| 341 | {
|
---|
| 342 | BOOL ret = FALSE;
|
---|
| 343 | if (SCI_putready(pcb) == TRUE) {
|
---|
| 344 | SCI_putchar(pcb, (UB)chr);
|
---|
| 345 | ret = TRUE;
|
---|
| 346 | }
|
---|
| 347 | return ret;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | /*
|
---|
| 351 | * sio_rcv_chr -- æååä¿¡
|
---|
| 352 | */
|
---|
| 353 | Inline INT
|
---|
| 354 | sio_rcv_chr(const SIOPCB *pcb)
|
---|
| 355 | {
|
---|
| 356 | INT ret = 0;
|
---|
| 357 | if (SCI_getready(pcb) == TRUE) {
|
---|
| 358 | ret = SCI_getchar(pcb);
|
---|
| 359 | } else {
|
---|
| 360 | ret = -1;
|
---|
| 361 | }
|
---|
| 362 | return(ret);
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | #endif /* of #ifndef _MACRO_ONLY */
|
---|
| 366 |
|
---|
| 367 | #endif /* _HW_SERIAL_H_ */
|
---|