| 1 | /* |
|---|
| 2 | * TOPPERS/ASP Kernel |
|---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/ |
|---|
| 4 | * Advanced Standard Profile Kernel |
|---|
| 5 | * |
|---|
| 6 | * Copyright (C) 2013-2014 by Embedded and Real-Time Systems Laboratory |
|---|
| 7 | * Graduate School of Information Science, Nagoya Univ., JAPAN |
|---|
| 8 | * |
|---|
| 9 | * ŸåµÃøºîž¢ŒÔ€Ï¡€°Ê²Œ€Î(1)¡Á(4)€ÎŸò·ï€òËþ€¿€¹Ÿì¹ç€ËžÂ€ê¡€ËÜ¥œ¥Õ¥È¥Š¥§ |
|---|
| 10 | * ¥¢¡ÊËÜ¥œ¥Õ¥È¥Š¥§¥¢€ò²þÊÑ€·€¿€â€Î€òŽÞ€à¡¥°Ê²ŒÆ±€ž¡Ë€ò»ÈÍÑ¡ŠÊ£Àœ¡Š²þ |
|---|
| 11 | * ÊÑ¡ŠºÆÇÛÉۡʰʲŒ¡€ÍøÍрȞƀ֡ˀ¹€ë€³€È€ò̵œþ€ÇµöÂú€¹€ë¡¥ |
|---|
| 12 | * (1) ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ò¥œ¡Œ¥¹¥³¡Œ¥É€Î·Á€ÇÍøÍÑ€¹€ëŸì¹ç€Ë€Ï¡€Ÿåµ€ÎÃøºî |
|---|
| 13 | * ž¢ÉœŒš¡€€³€ÎÍøÍÑŸò·ï€ª€è€Ó²Œµ€Î̵ÊÝŸÚµ¬Äꀬ¡€€œ€Î€Þ€Þ€Î·Á€Ç¥œ¡Œ |
|---|
| 14 | * ¥¹¥³¡Œ¥ÉÃæ€ËŽÞ€Þ€ì€Æ€€€ë€³€È¡¥ |
|---|
| 15 | * (2) ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ò¡€¥é¥€¥Ö¥é¥ê·ÁŒ°€Ê€É¡€ÂŸ€Î¥œ¥Õ¥È¥Š¥§¥¢³«È¯€Ë»È |
|---|
| 16 | * Íрǀ€ë·Á€ÇºÆÇÛÉÛ€¹€ëŸì¹ç€Ë€Ï¡€ºÆÇÛÉÛ€ËÈŒ€Š¥É¥¥å¥á¥ó¥È¡ÊÍøÍÑ |
|---|
| 17 | * ŒÔ¥Þ¥Ë¥å¥¢¥ë€Ê€É¡Ë€Ë¡€Ÿåµ€ÎÃøºîž¢ÉœŒš¡€€³€ÎÍøÍÑŸò·ï€ª€è€Ó²Œµ |
|---|
| 18 | * €Î̵ÊÝŸÚµ¬Äê€ò·ÇºÜ€¹€ë€³€È¡¥ |
|---|
| 19 | * (3) ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ò¡€µ¡Žï€ËÁȀ߹þ€à€Ê€É¡€ÂŸ€Î¥œ¥Õ¥È¥Š¥§¥¢³«È¯€Ë»È |
|---|
| 20 | * Íрǀ€Ê€€·Á€ÇºÆÇÛÉÛ€¹€ëŸì¹ç€Ë€Ï¡€Œ¡€Î€€€º€ì€«€ÎŸò·ï€òËþ€¿€¹€³ |
|---|
| 21 | * €È¡¥ |
|---|
| 22 | * (a) ºÆÇÛÉÛ€ËÈŒ€Š¥É¥¥å¥á¥ó¥È¡ÊÍøÍьԥޥ˥奢¥ë€Ê€É¡Ë€Ë¡€Ÿåµ€ÎÃø |
|---|
| 23 | * ºîž¢ÉœŒš¡€€³€ÎÍøÍÑŸò·ï€ª€è€Ó²Œµ€Î̵ÊÝŸÚµ¬Äê€ò·ÇºÜ€¹€ë€³€È¡¥ |
|---|
| 24 | * (b) ºÆÇÛÉۀηÁÂÖ€ò¡€ÊÌ€ËÄê€á€ëÊýË¡€Ë€è€Ã€Æ¡€TOPPERS¥×¥í¥ž¥§¥¯¥È€Ë |
|---|
| 25 | * Êó¹ð€¹€ë€³€È¡¥ |
|---|
| 26 | * (4) ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ÎÍøÍрˀè€êÄŸÀÜŪ€Þ€¿€ÏŽÖÀÜŪ€ËÀž€ž€ë€€€«€Ê€ë» |
|---|
| 27 | * ³²€«€é€â¡€ŸåµÃøºîž¢ŒÔ€ª€è€ÓTOPPERS¥×¥í¥ž¥§¥¯¥È€òÌÈÀÕ€¹€ë€³€È¡¥ |
|---|
| 28 | * €Þ€¿¡€ËÜ¥œ¥Õ¥È¥Š¥§¥¢€Î¥æ¡Œ¥¶€Þ€¿€Ï¥š¥ó¥É¥æ¡Œ¥¶€«€é€Î€€€«€Ê€ëÍý |
|---|
| 29 | * ͳ€ËŽð€Å€¯ÀÁµá€«€é€â¡€ŸåµÃøºîž¢ŒÔ€ª€è€ÓTOPPERS¥×¥í¥ž¥§¥¯¥È€ò |
|---|
| 30 | * ÌÈÀÕ€¹€ë€³€È¡¥ |
|---|
| 31 | * |
|---|
| 32 | * ËÜ¥œ¥Õ¥È¥Š¥§¥¢€Ï¡€ÌµÊÝŸÚ€ÇÄó¶¡€µ€ì€Æ€€€ë€â€Î€Ç€¢€ë¡¥ŸåµÃøºîž¢ŒÔ€ª |
|---|
| 33 | * €è€ÓTOPPERS¥×¥í¥ž¥§¥¯¥È€Ï¡€ËÜ¥œ¥Õ¥È¥Š¥§¥¢€ËŽØ€·€Æ¡€ÆÃÄê€Î»ÈÍÑÌÜŪ |
|---|
| 34 | * €ËÂЀ¹€ëŬ¹çÀ€âŽÞ€á€Æ¡€€€€«€Ê€ëÊÝŸÚ€â¹Ô€ï€Ê€€¡¥€Þ€¿¡€ËÜ¥œ¥Õ¥È¥Š¥§ |
|---|
| 35 | * ¥¢€ÎÍøÍрˀè€êÄŸÀÜŪ€Þ€¿€ÏŽÖÀÜŪ€ËÀž€ž€¿€€€«€Ê€ë»³²€ËŽØ€·€Æ€â¡€€œ |
|---|
| 36 | * €ÎÀÕÇ€€òÉé€ï€Ê€€¡¥ |
|---|
| 37 | * |
|---|
| 38 | * $Id$ |
|---|
| 39 | */ |
|---|
| 40 | |
|---|
| 41 | /* |
|---|
| 42 | * ¥·¥ê¥¢¥ëI/O¥Ç¥Ð¥€¥¹¡ÊSIO¡Ë¥É¥é¥€¥Ð¡Ê¥À¥ß¡Œ¥¿¡Œ¥²¥Ã¥ÈÍÑ¡Ë |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | #include "target_serial.h" |
|---|
| 46 | |
|---|
| 47 | /* |
|---|
| 48 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈœéŽü²œ¥Ö¥í¥Ã¥¯€ÎÄêµÁ |
|---|
| 49 | */ |
|---|
| 50 | typedef struct sio_port_initialization_block { |
|---|
| 51 | int_t dummy; /* ¥À¥ß¡Œ¥Õ¥£¡Œ¥ë¥É */ |
|---|
| 52 | /* SIO€Î¥ì¥ž¥¹¥¿€ÎÈÖÃÏ€Ê€É */ |
|---|
| 53 | } SIOPINIB; |
|---|
| 54 | |
|---|
| 55 | /* |
|---|
| 56 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈŽÉÍý¥Ö¥í¥Ã¥¯€ÎÄêµÁ |
|---|
| 57 | */ |
|---|
| 58 | struct sio_port_control_block { |
|---|
| 59 | const SIOPINIB *p_siopinib; /* ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈœéŽü²œ¥Ö¥í¥Ã¥¯ */ |
|---|
| 60 | intptr_t exinf; /* ³ÈÄ¥ŸðÊó */ |
|---|
| 61 | bool_t openflag; /* ¥ª¡Œ¥×¥óºÑ€ß¥Õ¥é¥° */ |
|---|
| 62 | /* SIO€ÎŸõÂÖ€Ê€É */ |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | /* |
|---|
| 66 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈœéŽü²œ¥Ö¥í¥Ã¥¯ |
|---|
| 67 | */ |
|---|
| 68 | const SIOPINIB siopinib_table[TNUM_SIOP] = { |
|---|
| 69 | { 0 } |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈŽÉÍý¥Ö¥í¥Ã¥¯€Î¥š¥ê¥¢ |
|---|
| 74 | */ |
|---|
| 75 | SIOPCB siopcb_table[TNUM_SIOP]; |
|---|
| 76 | |
|---|
| 77 | /* |
|---|
| 78 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈID€«€éŽÉÍý¥Ö¥í¥Ã¥¯€òŒè€êœÐ€¹€¿€á€Î¥Þ¥¯¥í |
|---|
| 79 | */ |
|---|
| 80 | #define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1)) |
|---|
| 81 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)])) |
|---|
| 82 | |
|---|
| 83 | /* |
|---|
| 84 | * SIO¥É¥é¥€¥Ð€ÎœéŽü²œ |
|---|
| 85 | */ |
|---|
| 86 | void |
|---|
| 87 | sio_initialize(intptr_t exinf) |
|---|
| 88 | { |
|---|
| 89 | SIOPCB *p_siopcb; |
|---|
| 90 | uint_t i; |
|---|
| 91 | |
|---|
| 92 | /* |
|---|
| 93 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥ÈŽÉÍý¥Ö¥í¥Ã¥¯€ÎœéŽü²œ |
|---|
| 94 | */ |
|---|
| 95 | for (i = 0; i < TNUM_SIOP; i++) { |
|---|
| 96 | p_siopcb = &(siopcb_table[i]); |
|---|
| 97 | p_siopcb->p_siopinib = &(siopinib_table[i]); |
|---|
| 98 | p_siopcb->openflag = false; |
|---|
| 99 | /* €œ€ÎŸ€Î¥Õ¥£¡Œ¥ë¥É€ÎœéŽü²œ */ |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | * SIO¥É¥é¥€¥Ð€ÎœªÎ»œèÍý |
|---|
| 105 | */ |
|---|
| 106 | void |
|---|
| 107 | sio_terminate(intptr_t exinf) |
|---|
| 108 | { |
|---|
| 109 | SIOPCB *p_siopcb; |
|---|
| 110 | uint_t i; |
|---|
| 111 | |
|---|
| 112 | /* |
|---|
| 113 | * ¥ª¡Œ¥×¥ó€µ€ì€Æ€€€ë¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€Î¥¯¥í¡Œ¥º |
|---|
| 114 | */ |
|---|
| 115 | for (i = 0; i < TNUM_SIOP; i++) { |
|---|
| 116 | p_siopcb = &(siopcb_table[i]); |
|---|
| 117 | if (p_siopcb->openflag) { |
|---|
| 118 | /* SIO€Î¥¯¥í¡Œ¥ºœèÍý */ |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /* |
|---|
| 124 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€Î¥ª¡Œ¥×¥ó |
|---|
| 125 | */ |
|---|
| 126 | SIOPCB * |
|---|
| 127 | sio_opn_por(ID siopid, intptr_t exinf) |
|---|
| 128 | { |
|---|
| 129 | SIOPCB *p_siopcb; |
|---|
| 130 | const SIOPINIB *p_siopinib; |
|---|
| 131 | |
|---|
| 132 | p_siopcb = get_siopcb(siopid); |
|---|
| 133 | p_siopinib = p_siopcb->p_siopinib; |
|---|
| 134 | |
|---|
| 135 | /* SIO€Î¥ª¡Œ¥×¥óœèÍý */ |
|---|
| 136 | |
|---|
| 137 | p_siopcb->exinf = exinf; |
|---|
| 138 | p_siopcb->openflag = true; |
|---|
| 139 | return(p_siopcb); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /* |
|---|
| 143 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€Î¥¯¥í¡Œ¥º |
|---|
| 144 | */ |
|---|
| 145 | void |
|---|
| 146 | sio_cls_por(SIOPCB *p_siopcb) |
|---|
| 147 | { |
|---|
| 148 | /* SIO€Î¥¯¥í¡Œ¥ºœèÍý */ |
|---|
| 149 | |
|---|
| 150 | p_siopcb->openflag = false; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | /* |
|---|
| 154 | * SIO€Î³ä¹þ€ß¥µ¡Œ¥Ó¥¹¥ë¡Œ¥Á¥ó |
|---|
| 155 | */ |
|---|
| 156 | void |
|---|
| 157 | sio_isr(intptr_t exinf) |
|---|
| 158 | { |
|---|
| 159 | SIOPCB *p_siopcb = &(siopcb_table[(int_t) exinf]); |
|---|
| 160 | |
|---|
| 161 | if (1/* Á÷¿®Ž°Î»³ä¹þ€ß€ÎŸì¹ç */) { |
|---|
| 162 | sio_irdy_snd(p_siopcb->exinf); |
|---|
| 163 | } |
|---|
| 164 | if (1/* Œõ¿®Ž°Î»³ä¹þ€ß€ÎŸì¹ç */) { |
|---|
| 165 | sio_irdy_rcv(p_siopcb->exinf); |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /* |
|---|
| 170 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€Ø€ÎÊž»úÁ÷¿® |
|---|
| 171 | */ |
|---|
| 172 | bool_t |
|---|
| 173 | sio_snd_chr(SIOPCB *p_siopcb, char c) |
|---|
| 174 | { |
|---|
| 175 | if (1/* Á÷¿®¥ì¥ž¥¹¥¿€Ë¶õ€€¬€¢€ëŸì¹ç */) { |
|---|
| 176 | /* Á÷¿®¥ì¥ž¥¹¥¿€ËÊž»úc€òÆþ€ì€ë */ |
|---|
| 177 | return(true); |
|---|
| 178 | } |
|---|
| 179 | else { |
|---|
| 180 | return(false); |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | /* |
|---|
| 185 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€«€é€ÎÊž»úŒõ¿® |
|---|
| 186 | */ |
|---|
| 187 | int_t |
|---|
| 188 | sio_rcv_chr(SIOPCB *p_siopcb) |
|---|
| 189 | { |
|---|
| 190 | char c; |
|---|
| 191 | |
|---|
| 192 | if (1/* Œõ¿®¥ì¥ž¥¹¥¿€ËÊž»ú€¬€¢€ëŸì¹ç */) { |
|---|
| 193 | /* Œõ¿®¥ì¥ž¥¹¥¿€ÎÊž»ú€òc€ËÆþ€ì€ë */ |
|---|
| 194 | return((int_t) c); |
|---|
| 195 | } |
|---|
| 196 | else { |
|---|
| 197 | return(-1); |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | /* |
|---|
| 202 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€«€é€Î¥³¡Œ¥ë¥Ð¥Ã¥¯€Îµö²Ä |
|---|
| 203 | */ |
|---|
| 204 | void |
|---|
| 205 | sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn) |
|---|
| 206 | { |
|---|
| 207 | switch (cbrtn) { |
|---|
| 208 | case SIO_RDY_SND: |
|---|
| 209 | /* Á÷¿®Ž°Î»³ä¹þ€ß€òµö²Ä */ |
|---|
| 210 | break; |
|---|
| 211 | case SIO_RDY_RCV: |
|---|
| 212 | /* Œõ¿®Ž°Î»³ä¹þ€ß€òµö²Ä */ |
|---|
| 213 | break; |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | /* |
|---|
| 218 | * ¥·¥ê¥¢¥ëI/O¥Ý¡Œ¥È€«€é€Î¥³¡Œ¥ë¥Ð¥Ã¥¯€Î¶Ø»ß |
|---|
| 219 | */ |
|---|
| 220 | void |
|---|
| 221 | sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn) |
|---|
| 222 | { |
|---|
| 223 | switch (cbrtn) { |
|---|
| 224 | case SIO_RDY_SND: |
|---|
| 225 | /* Á÷¿®Ž°Î»³ä¹þ€ß€ò¶Ø»ß */ |
|---|
| 226 | break; |
|---|
| 227 | case SIO_RDY_RCV: |
|---|
| 228 | /* Œõ¿®Ž°Î»³ä¹þ€ß€ò¶Ø»ß */ |
|---|
| 229 | break; |
|---|
| 230 | } |
|---|
| 231 | } |
|---|