- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/asp3_dcre/target/gr_sakura_gcc/target_serial.c
r337 r374 3 3 * Toyohashi Open Platform for Embedded Real-Time Systems/ 4 4 * Advanced Standard Profile Kernel 5 * 5 * 6 6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory 7 7 * Toyohashi Univ. of Technology, JAPAN … … 12 12 * Copyright (C) 2008-2010 by Witz Corporation, JAPAN 13 13 * Copyright (C) 2013 by Mitsuhiro Matsuura 14 * 14 * 15 15 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ 16 16 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 … … 35 35 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを 36 36 * 免責すること. 37 * 37 * 38 38 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お 39 39 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 … … 41 41 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ 42 42 * の責任を負わない. 43 * 43 * 44 44 * @(#) $Id$ 45 45 */ … … 51 51 #include <sil.h> 52 52 #include "target_serial.h" 53 #include "hal/serial_api.h" 54 #include "target_syssvc.h" 55 #include "syssvc/serial.h" 56 57 /* 58 * シリアルI/Oポート初期化ブロックの定義 59 */ 60 typedef struct sio_port_initialization_block { 61 PinName tx; 62 PinName rx; 63 } SIOPINIB; 64 65 /* 66 * シリアルI/Oポート管理ブロックの定義 67 */ 68 struct sio_port_control_block { 69 const SIOPINIB *p_siopinib; 70 intptr_t exinf; 71 bool_t openflag; 72 serial_t serial; 73 }; 74 75 /* 76 * シリアルI/Oポート管理ブロックのエリア 77 */ 78 SIOPCB siopcb_table[TNUM_PORT]; 79 80 static const SIOPINIB siopinib_table[TNUM_SIOP] = 81 { 82 { P20, P21 }, 83 #if TNUM_SIOP > 1 84 { P32, P33 }, 85 #endif 86 #if TNUM_SIOP > 2 87 { P50, P52 }, 88 #endif 89 #if TNUM_SIOP > 3 90 { P23, P25 }, 91 #endif 92 #if TNUM_SIOP > 4 93 { PC3, PC2 }, 94 #endif 95 #if TNUM_SIOP > 5 96 { PC7, PC6 }, 97 #endif 98 #if TNUM_SIOP > 6 99 { P26, P30 }, 100 #endif 101 }; 102 103 /* 104 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ 105 */ 106 #define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1)) 107 #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)])) 108 #define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOP(siopid)])) 109 110 static void mbed_serial_irq_handler(uint32_t id, SerialIrq event); 53 111 54 112 /* … … 58 116 sio_initialize(intptr_t exinf) 59 117 { 60 rx630_uart_initialize(); 118 SIOPCB *p_siopcb; 119 uint_t i; 120 121 /* 122 * シリアルI/Oポート管理ブロックの初期化 123 */ 124 for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) { 125 p_siopcb->p_siopinib = &(siopinib_table[i]); 126 p_siopcb->openflag = false; 127 } 61 128 } 62 129 … … 69 136 SIOPCB *p_siopcb = NULL; 70 137 ER ercd; 71 INTNO intno_sio_tx, intno_sio_rx; 72 73 /* 74 * シリアルI/O割込みをマスクする. 75 * (dis_int関数は、"\kernel\interrupt.c"に記述) 76 */ 77 p_siopcb = rx630_uart_get_siopcb(siopid); 78 intno_sio_tx = rx630_uart_intno_tx(p_siopcb); 79 intno_sio_rx = rx630_uart_intno_rx(p_siopcb); 80 ercd = dis_int(intno_sio_tx); 81 assert(ercd == E_OK); 82 ercd = dis_int(intno_sio_rx); 83 assert(ercd == E_OK); 84 85 p_siopcb = 86 rx630_uart_opn_por(siopid , exinf , UART_BAUDRATE , UART_CLKSRC); 87 88 /* 89 * シリアルI/O割込みをマスク解除する. 90 * (ena_int関数は、"\kernel\interrupt.c"に記述) 91 */ 92 ercd = ena_int(intno_sio_tx); 93 assert(ercd == E_OK); 94 ercd = ena_int(intno_sio_rx); 95 assert(ercd == E_OK); 96 97 return(p_siopcb); 138 serial_t *serial; 139 140 if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0])))) 141 return NULL; 142 p_siopcb = get_siopcb(siopid); 143 144 if (p_siopcb->openflag) 145 return NULL; 146 p_siopcb->openflag = true; 147 p_siopcb->exinf = exinf; 148 149 serial = &p_siopcb->serial; 150 serial_init(serial, p_siopcb->p_siopinib->tx, p_siopcb->p_siopinib->rx); 151 serial_baud(serial, UART_BAUDRATE); 152 serial_format(serial, 8, ParityNone, 1); 153 154 serial_irq_handler(serial, mbed_serial_irq_handler, siopid); 155 156 return p_siopcb; 98 157 } 99 158 … … 105 164 { 106 165 ER ercd; 107 INTNO intno_sio_tx, intno_sio_rx;166 serial_t *serial = &p_siopcb->serial; 108 167 109 168 /* 110 169 * デバイス依存のクローズ処理. 111 170 */ 112 rx630_uart_cls_por(p_siopcb); 113 114 /* 115 * シリアルI/O割込みをマスクする. 116 */ 117 intno_sio_tx = rx630_uart_intno_tx(p_siopcb); 118 intno_sio_rx = rx630_uart_intno_rx(p_siopcb); 119 ercd = dis_int(intno_sio_tx); 120 assert(ercd == E_OK); 121 ercd = dis_int(intno_sio_rx); 122 assert(ercd == E_OK); 171 serial_free(serial); 172 p_siopcb->openflag = false; 173 } 174 175 /* 176 * シリアルI/Oポートへの文字送信 177 */ 178 bool_t 179 sio_snd_chr(SIOPCB *p_siopcb, char c) 180 { 181 serial_t *serial = &p_siopcb->serial; 182 if (!serial_writable(serial)) 183 return false; 184 serial_putc(serial, c); 185 return true; 186 } 187 188 /* 189 * シリアルI/Oポートからの文字受信 190 */ 191 int_t 192 sio_rcv_chr(SIOPCB *p_siopcb) 193 { 194 serial_t *serial = &p_siopcb->serial; 195 if (!serial_readable(serial)) 196 return -1; 197 return serial_getc(serial); 198 } 199 200 /* 201 * シリアルI/Oポートからのコールバックの許可 202 */ 203 void 204 sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn) 205 { 206 serial_t *serial = &p_siopcb->serial; 207 switch (cbrtn) { 208 case SIO_RDY_SND: 209 serial_irq_set(serial, TxIrq, true); 210 break; 211 case SIO_RDY_RCV: 212 serial_irq_set(serial, RxIrq, true); 213 break; 214 } 215 } 216 217 /* 218 * シリアルI/Oポートからのコールバックの禁止 219 */ 220 void 221 sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn) 222 { 223 serial_t *serial = &p_siopcb->serial; 224 switch (cbrtn) { 225 case SIO_RDY_SND: 226 serial_irq_set(serial, TxIrq, false); 227 break; 228 case SIO_RDY_RCV: 229 serial_irq_set(serial, RxIrq, false); 230 break; 231 } 232 } 233 234 /* 235 * シリアルI/Oポートからの送信可能コールバック 236 */ 237 void 238 serial_irdy_snd(SIOPCB *p_siopcb) 239 { 240 /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/ 241 sio_irdy_snd(p_siopcb->exinf); 242 } 243 244 /* 245 * シリアルI/Oポートからの受信通知コールバック 246 */ 247 void 248 serial_irdy_rcv(SIOPCB *p_siopcb) 249 { 250 /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/ 251 sio_irdy_rcv(p_siopcb->exinf); 123 252 } 124 253 … … 126 255 * SIOの割込みハンドラ 127 256 */ 128 void sio_tx_isr(intptr_t exinf) 129 { 130 rx630_uart_tx_isr(exinf); 131 } 132 133 /* 134 * SIOの割込みハンドラ 135 */ 136 void sio_rx_isr(intptr_t exinf) 137 { 138 rx630_uart_rx_isr(exinf); 139 } 140 141 /* 142 * シリアルI/Oポートへの文字送信 143 */ 144 bool_t 145 sio_snd_chr(SIOPCB *siopcb, char c) 146 { 147 return(rx630_uart_snd_chr(siopcb, c)); 148 } 149 150 /* 151 * シリアルI/Oポートからの文字受信 152 */ 153 int_t 154 sio_rcv_chr(SIOPCB *siopcb) 155 { 156 return(rx630_uart_rcv_chr(siopcb)); 157 } 158 159 /* 160 * シリアルI/Oポートからのコールバックの許可 161 */ 162 void 163 sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn) 164 { 165 rx630_uart_ena_cbr(siopcb, cbrtn); 166 } 167 168 /* 169 * シリアルI/Oポートからのコールバックの禁止 170 */ 171 void 172 sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn) 173 { 174 rx630_uart_dis_cbr(siopcb, cbrtn); 175 } 176 177 /* 178 * シリアルI/Oポートからの送信可能コールバック 179 */ 180 void 181 rx630_uart_irdy_snd(intptr_t exinf) 182 { 183 /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/ 184 sio_irdy_snd(exinf); 185 } 186 187 /* 188 * シリアルI/Oポートからの受信通知コールバック 189 */ 190 void 191 rx630_uart_irdy_rcv(intptr_t exinf) 192 { 193 /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/ 194 sio_irdy_rcv(exinf); 195 } 196 257 void 258 mbed_serial_irq_handler(uint32_t siopid, SerialIrq event) 259 { 260 SIOPCB *p_siopcb; 261 262 if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0])))) 263 return; 264 p_siopcb = get_siopcb(siopid); 265 266 if (!p_siopcb->openflag) 267 return; 268 269 switch (event) { 270 case TxIrq: 271 serial_irdy_snd(p_siopcb); 272 break; 273 case RxIrq: 274 serial_irdy_rcv(p_siopcb); 275 break; 276 } 277 }
Note:
See TracChangeset
for help on using the changeset viewer.