[136] | 1 | /*
|
---|
| 2 | * TOPPERS/ASP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Advanced Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2015 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 11 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 12 | * å¤ã»åé
|
---|
| 13 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 14 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 15 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 16 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 17 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 18 | * ç¨ã§ããå½¢ã§åé
|
---|
| 19 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 20 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 21 | * è
|
---|
| 22 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 23 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 24 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 25 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 26 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 27 | * ã¨ï¼
|
---|
| 28 | * (a) åé
|
---|
| 29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 32 | * (b) åé
|
---|
| 33 | å¸ã®å½¢æ
|
---|
| 34 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 35 | * å ±åãããã¨ï¼
|
---|
| 36 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 37 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 38 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 39 | 責ãããã¨ï¼
|
---|
| 40 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 41 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 42 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 43 | * å
|
---|
| 44 | 責ãããã¨ï¼
|
---|
| 45 | *
|
---|
| 46 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 47 | ã
|
---|
| 48 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 49 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 50 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 51 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 52 | *
|
---|
| 53 | * @(#) $Id: target_serial.c 2708 2015-11-22 10:35:09Z ertl-honda $
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | /*
|
---|
| 57 | * ã·ãªã¢ã«I/Oããã¤ã¹ï¼SIOï¼ãã©ã¤ãï¼ARDUINO_M0ç¨ï¼
|
---|
| 58 | */
|
---|
| 59 | #include <kernel.h>
|
---|
| 60 | #include <t_syslog.h>
|
---|
| 61 | #include "arduino_m0.h"
|
---|
| 62 | #include "target_serial.h"
|
---|
| 63 | #include "variant.h"
|
---|
| 64 |
|
---|
| 65 | /*
|
---|
| 66 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯ã®å®ç¾©
|
---|
| 67 | */
|
---|
| 68 | typedef struct sio_port_initialization_block
|
---|
| 69 | {
|
---|
| 70 | Sercom* p_sercom; /* 使ç¨ããSERCOMã¸ã®ãã¤ã³ã¿ */
|
---|
| 71 | uint8_t rx_pin; /* RXç¨PIN */
|
---|
| 72 | uint8_t tx_pin; /* TXç¨PIN */
|
---|
| 73 | uint8_t sample_rate; /* ãµã³ããªã³ã°ã¬ã¼ã */
|
---|
| 74 | uint8_t port; /* ãã¼ã */
|
---|
| 75 | int8_t pio; /* PIO */
|
---|
| 76 | uint8_t gcm; /* GCM */
|
---|
| 77 | uint32_t bps; /* ãã¼ã¬ã¼ã */
|
---|
| 78 | uint32_t pm; /* PowerManagement */
|
---|
| 79 | }
|
---|
| 80 | SIOPINIB;
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®å®ç¾©
|
---|
| 84 | */
|
---|
| 85 | struct sio_port_control_block
|
---|
| 86 | {
|
---|
| 87 | const SIOPINIB* p_siopinib; /* åæåããã㯠*/
|
---|
| 88 | intptr_t exinf; /* æ¡å¼µæ
|
---|
| 89 | å ± */
|
---|
| 90 | bool_t openflag; /* ãªã¼ãã³æ¸ã¿ãã©ã° */
|
---|
| 91 | bool_t devinitd; /* ããã¤ã¹åæåæ¸ã¿ãã©ã° */
|
---|
| 92 | bool_t sendflag; /* éä¿¡å²è¾¼ã¿ã¤ãã¼ãã«ãã©ã° */
|
---|
| 93 | bool_t getready; /* æåãåä¿¡ããç¶æ
|
---|
| 94 | */
|
---|
| 95 | bool_t putready; /* æåãéä¿¡ã§ããç¶æ
|
---|
| 96 | */
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | /*
|
---|
| 100 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
| 101 | */
|
---|
| 102 | const SIOPINIB siopinib_table[TNUM_SIOP] = {
|
---|
| 103 | {SERCOM5, 23u, 22u, 16u, PORTB, PIO_SERCOM_ALT, GCM_SERCOM5_CORE, 115200, PM_APBCMASK_SERCOM5}
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®ã¨ãªã¢
|
---|
| 108 | */
|
---|
| 109 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
| 110 |
|
---|
| 111 | /*
|
---|
| 112 | * ã·ãªã¢ã«I/Oãã¼ãIDãã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
| 113 | */
|
---|
| 114 | #define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1))
|
---|
| 115 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | static void
|
---|
| 119 | sercom_uart_devinit(SIOPCB *p_siopcb){
|
---|
| 120 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 121 |
|
---|
| 122 | /* ããã¤ã¹ãåæåæ¸ã¿ãªããªã¿ã¼ã³ */
|
---|
| 123 | if (p_siopcb->devinitd) {
|
---|
| 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | p_siopcb->devinitd = true;
|
---|
| 128 |
|
---|
| 129 | /* RX Pin Initialize */
|
---|
| 130 | PORT->Group[p_siopcb->p_siopinib->port].PMUX[(p_siopcb->p_siopinib->rx_pin) >> 1].reg =
|
---|
| 131 | ((PORT->Group[p_siopcb->p_siopinib->port].PMUX[(p_siopcb->p_siopinib->rx_pin) >> 1].reg) & PORT_PMUX_PMUXE(0xF))
|
---|
| 132 | |PORT_PMUX_PMUXO(p_siopcb->p_siopinib->pio);
|
---|
| 133 | PORT->Group[p_siopcb->p_siopinib->port].PINCFG[(p_siopcb->p_siopinib->rx_pin)].reg |= PORT_PINCFG_PMUXEN;
|
---|
| 134 |
|
---|
| 135 | /* TX Pin Initialize */
|
---|
| 136 | PORT->Group[p_siopcb->p_siopinib->port].PMUX[(p_siopcb->p_siopinib->tx_pin) >> 1].reg =
|
---|
| 137 | ((PORT->Group[p_siopcb->p_siopinib->port].PMUX[(p_siopcb->p_siopinib->tx_pin) >> 1].reg) & PORT_PMUX_PMUXO(0xF))
|
---|
| 138 | |PORT_PMUX_PMUXE(p_siopcb->p_siopinib->pio);
|
---|
| 139 | PORT->Group[p_siopcb->p_siopinib->port].PINCFG[(p_siopcb->p_siopinib->tx_pin)].reg |= PORT_PINCFG_PMUXEN;
|
---|
| 140 |
|
---|
| 141 | /* é»æºã®æå
|
---|
| 142 | ¥ */
|
---|
| 143 | PM->APBCMASK.reg |= p_siopcb->p_siopinib->pm;
|
---|
| 144 |
|
---|
| 145 | /* Reset Uart */
|
---|
| 146 | p_sercom->USART.CTRLA.bit.SWRST = 1 ;
|
---|
| 147 | while(p_sercom->USART.CTRLA.bit.SWRST || p_sercom->USART.SYNCBUSY.bit.SWRST){};
|
---|
| 148 |
|
---|
| 149 | /* Init Clock */
|
---|
| 150 | GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(p_siopcb->p_siopinib->gcm)
|
---|
| 151 | | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_CLKEN ;
|
---|
| 152 | while(GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {}
|
---|
| 153 |
|
---|
| 154 | /* Set Baund Rate */
|
---|
| 155 | p_sercom->USART.CTRLA.reg = SERCOM_USART_CTRLA_MODE(0x01) | SERCOM_USART_CTRLA_SAMPR(p_siopcb->p_siopinib->sample_rate);
|
---|
| 156 | p_sercom->USART.BAUD.reg = 0xffff - ((0xffff * (((int)p_siopcb->p_siopinib->sample_rate * (int)p_siopcb->p_siopinib->bps)/(CORE_CLOCK_HZ/1000000))) / 1000000u);
|
---|
| 157 |
|
---|
| 158 | /* Disable All Interrupt */
|
---|
| 159 | p_sercom->USART.INTENSET.reg = 0;
|
---|
| 160 |
|
---|
| 161 | /* Set Frame : 8bit, 1Stop, No parity, Lsb first*/
|
---|
| 162 | p_sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_FORM(0) |
|
---|
| 163 | (1 << SERCOM_USART_CTRLA_DORD_Pos);
|
---|
| 164 | p_sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_CHSIZE(0) |
|
---|
| 165 | (0 << SERCOM_USART_CTRLB_SBMODE_Pos) |
|
---|
| 166 | (0 << SERCOM_USART_CTRLB_PMODE_Pos);
|
---|
| 167 |
|
---|
| 168 | /* Set Pad */
|
---|
| 169 | p_sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(0x01) | SERCOM_USART_CTRLA_RXPO(0x03);
|
---|
| 170 |
|
---|
| 171 | /* Tx/Rx Enable */
|
---|
| 172 | p_sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN;
|
---|
| 173 |
|
---|
| 174 | /* Enable Uart */
|
---|
| 175 | p_sercom->USART.CTRLA.bit.ENABLE = 0x01;
|
---|
| 176 | while(p_sercom->USART.SYNCBUSY.bit.ENABLE){};
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /*
|
---|
| 180 | * ã«ã¼ãã«èµ·åæã®ãã°åºåç¨ã®åæå
|
---|
| 181 | */
|
---|
| 182 | void
|
---|
| 183 | arduino_m0_init_uart(uint32_t siopid)
|
---|
| 184 | {
|
---|
| 185 | SIOPCB *p_siopcb;
|
---|
| 186 |
|
---|
| 187 | p_siopcb = get_siopcb(siopid);
|
---|
| 188 | p_siopcb->p_siopinib = &siopinib_table[INDEX_SIOP(siopid)];
|
---|
| 189 | sercom_uart_devinit(p_siopcb);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | * UARTããã®ãã¼ãªã³ã°åºå
|
---|
| 194 | */
|
---|
| 195 | void
|
---|
| 196 | arduino_m0_putc(uint32_t siopid, char c)
|
---|
| 197 | {
|
---|
| 198 | Sercom* p_sercom = (get_siopcb(siopid))->p_siopinib->p_sercom;
|
---|
| 199 | while(p_sercom->USART.INTFLAG.bit.DRE != SERCOM_USART_INTFLAG_DRE);
|
---|
| 200 | p_sercom->USART.DATA.reg = (uint16_t)c;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | /*
|
---|
| 205 | * æåãåä¿¡ããã?
|
---|
| 206 | */
|
---|
| 207 | Inline bool_t
|
---|
| 208 | uart_getready(SIOPCB *p_siopcb)
|
---|
| 209 | {
|
---|
| 210 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 211 | return(p_sercom->USART.INTFLAG.bit.RXC);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /*
|
---|
| 215 | * æåãéä¿¡ã§ããã?
|
---|
| 216 | */
|
---|
| 217 | Inline bool_t
|
---|
| 218 | uart_putready(SIOPCB *p_siopcb)
|
---|
| 219 | {
|
---|
| 220 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 221 | return(p_sercom->USART.INTFLAG.bit.DRE == SERCOM_USART_INTFLAG_DRE);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | /*
|
---|
| 225 | * åä¿¡ããæåã®åãåºã
|
---|
| 226 | */
|
---|
| 227 | Inline uint8_t
|
---|
| 228 | uart_getchar(SIOPCB *p_siopcb)
|
---|
| 229 | {
|
---|
| 230 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 231 | return p_sercom->USART.DATA.bit.DATA;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | /*
|
---|
| 235 | * éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
| 236 | */
|
---|
| 237 | Inline void
|
---|
| 238 | uart_putchar(SIOPCB *p_siopcb, uint8_t c)
|
---|
| 239 | {
|
---|
| 240 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 241 | p_sercom->USART.DATA.reg = (uint16_t)c;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | /*
|
---|
| 245 | * éä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 246 | */
|
---|
| 247 | Inline void
|
---|
| 248 | uart_enable_send(SIOPCB *p_siopcb)
|
---|
| 249 | {
|
---|
| 250 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 251 | p_sercom->USART.INTENSET.reg = SERCOM_USART_INTENSET_TXC;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | /*
|
---|
| 255 | * éä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 256 | */
|
---|
| 257 | Inline void
|
---|
| 258 | uart_disable_send(SIOPCB *p_siopcb)
|
---|
| 259 | {
|
---|
| 260 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 261 | p_sercom->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_TXC;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | /*
|
---|
| 266 | * åä¿¡å²è¾¼ã¿è¨±å¯
|
---|
| 267 | */
|
---|
| 268 | Inline void
|
---|
| 269 | uart_enable_rcv(SIOPCB *p_siopcb)
|
---|
| 270 | {
|
---|
| 271 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 272 | p_sercom->USART.INTENSET.reg = SERCOM_USART_INTENSET_RXC;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | /*
|
---|
| 276 | * åä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
| 277 | */
|
---|
| 278 | Inline void
|
---|
| 279 | uart_disable_rcv(SIOPCB *p_siopcb)
|
---|
| 280 | {
|
---|
| 281 | Sercom* p_sercom = p_siopcb->p_siopinib->p_sercom;
|
---|
| 282 | p_sercom->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_RXC;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 | /*
|
---|
| 287 | * SIOãã©ã¤ãã®åæå
|
---|
| 288 | */
|
---|
| 289 | void
|
---|
| 290 | sio_initialize(intptr_t exinf)
|
---|
| 291 | {
|
---|
| 292 | SIOPCB *p_siopcb;
|
---|
| 293 | uint_t i;
|
---|
| 294 |
|
---|
| 295 | /*
|
---|
| 296 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®åæå
|
---|
| 297 | */
|
---|
| 298 | for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) {
|
---|
| 299 | p_siopcb->p_siopinib = &(siopinib_table[i]);
|
---|
| 300 | p_siopcb->openflag = false;
|
---|
| 301 | p_siopcb->sendflag = false;
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | /*
|
---|
| 306 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 307 | */
|
---|
| 308 | SIOPCB *
|
---|
| 309 | arduino_m0_uart_opn_por(SIOPCB *p_siopcb, intptr_t exinf)
|
---|
| 310 | {
|
---|
| 311 | p_siopcb->exinf = exinf;
|
---|
| 312 | p_siopcb->getready = p_siopcb->putready = false;
|
---|
| 313 | p_siopcb->openflag = true;
|
---|
| 314 |
|
---|
| 315 | sercom_uart_devinit(p_siopcb);
|
---|
| 316 |
|
---|
| 317 | return(p_siopcb);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 |
|
---|
| 321 | /*
|
---|
| 322 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
| 323 | */
|
---|
| 324 | SIOPCB *
|
---|
| 325 | sio_opn_por(ID siopid, intptr_t exinf)
|
---|
| 326 | {
|
---|
| 327 | SIOPCB *p_siopcb = get_siopcb(siopid);
|
---|
| 328 | bool_t opnflg;
|
---|
| 329 | ER ercd;
|
---|
| 330 |
|
---|
| 331 | /*
|
---|
| 332 | * ãªã¼ãã³ãããã¼ããããããopnflgã«èªãã§ããï¼
|
---|
| 333 | */
|
---|
| 334 | opnflg = p_siopcb->openflag;
|
---|
| 335 |
|
---|
| 336 | /*
|
---|
| 337 | * ããã¤ã¹ä¾åã®ãªã¼ãã³å¦çï¼
|
---|
| 338 | */
|
---|
| 339 | arduino_m0_uart_opn_por(p_siopcb, exinf);
|
---|
| 340 |
|
---|
| 341 | /*
|
---|
| 342 | * ã·ãªã¢ã«I/Oå²è¾¼ã¿ã®ãã¹ã¯ã解é¤ããï¼
|
---|
| 343 | */
|
---|
| 344 | if (!opnflg) {
|
---|
| 345 | ercd = ena_int(INTNO_SIO);
|
---|
| 346 | assert(ercd == E_OK);
|
---|
| 347 | }
|
---|
| 348 | return(p_siopcb);
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /*
|
---|
| 352 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
| 353 | */
|
---|
| 354 | void
|
---|
| 355 | sio_cls_por(SIOPCB *p_siopcb)
|
---|
| 356 | {
|
---|
| 357 | /*
|
---|
| 358 | * ããã¤ã¹ä¾åã®ã¯ãã¼ãºå¦çï¼
|
---|
| 359 | */
|
---|
| 360 | p_siopcb->openflag = false;
|
---|
| 361 |
|
---|
| 362 | /*
|
---|
| 363 | * ã·ãªã¢ã«I/Oå²è¾¼ã¿ããã¹ã¯ããï¼
|
---|
| 364 | */
|
---|
| 365 | dis_int(INTNO_SIO);
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /*
|
---|
| 369 | * SIOã®å²è¾¼ã¿ãã³ãã©
|
---|
| 370 | */
|
---|
| 371 | void
|
---|
| 372 | sio_isr(intptr_t exinf)
|
---|
| 373 | {
|
---|
| 374 | SIOPCB *p_siopcb = get_siopcb(exinf);
|
---|
| 375 |
|
---|
| 376 | if (uart_getready(p_siopcb)) {
|
---|
| 377 | /*
|
---|
| 378 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 379 | */
|
---|
| 380 | sio_irdy_rcv(p_siopcb->exinf);
|
---|
| 381 | }
|
---|
| 382 | if (uart_putready(p_siopcb)) {
|
---|
| 383 | /*
|
---|
| 384 | * éä¿¡å¯è½ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
| 385 | */
|
---|
| 386 | sio_irdy_snd(p_siopcb->exinf);
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 |
|
---|
| 391 | /*
|
---|
| 392 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®æåéä¿¡
|
---|
| 393 | */
|
---|
| 394 | bool_t
|
---|
| 395 | sio_snd_chr(SIOPCB *siopcb, char c)
|
---|
| 396 | {
|
---|
| 397 | if (uart_putready(siopcb)){
|
---|
| 398 | uart_putchar(siopcb, c);
|
---|
| 399 | return(true);
|
---|
| 400 | }
|
---|
| 401 | return(false);
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | /*
|
---|
| 405 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
| 406 | */
|
---|
| 407 | int_t
|
---|
| 408 | sio_rcv_chr(SIOPCB *siopcb)
|
---|
| 409 | {
|
---|
| 410 | if (uart_getready(siopcb)) {
|
---|
| 411 | return((int_t)(uint8_t) uart_getchar(siopcb));
|
---|
| 412 | }
|
---|
| 413 | return(-1);
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | /*
|
---|
| 417 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®è¨±å¯
|
---|
| 418 | */
|
---|
| 419 | void
|
---|
| 420 | sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn)
|
---|
| 421 | {
|
---|
| 422 | switch (cbrtn) {
|
---|
| 423 | case SIO_RDY_SND:
|
---|
| 424 | uart_enable_send(siopcb);
|
---|
| 425 | break;
|
---|
| 426 | case SIO_RDY_RCV:
|
---|
| 427 | uart_enable_rcv(siopcb);
|
---|
| 428 | break;
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | /*
|
---|
| 433 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®ç¦æ¢
|
---|
| 434 | */
|
---|
| 435 | void
|
---|
| 436 | sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
|
---|
| 437 | {
|
---|
| 438 | switch (cbrtn) {
|
---|
| 439 | case SIO_RDY_SND:
|
---|
| 440 | uart_disable_send(siopcb);
|
---|
| 441 | break;
|
---|
| 442 | case SIO_RDY_RCV:
|
---|
| 443 | uart_disable_rcv(siopcb);
|
---|
| 444 | break;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | #define UART_SERCOM SERCOM5
|
---|
| 449 |
|
---|
| 450 | void
|
---|
| 451 | serial_ena(void){
|
---|
| 452 | UART_SERCOM->USART.INTENSET.reg |= SERCOM_USART_INTENSET_RXC;
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | void
|
---|
| 456 | serial_putc(char c){
|
---|
| 457 | while(UART_SERCOM->USART.INTFLAG.bit.DRE != SERCOM_USART_INTFLAG_DRE);
|
---|
| 458 | UART_SERCOM->USART.DATA.reg = (uint16_t)c;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | char
|
---|
| 462 | serial_getc(void){
|
---|
| 463 | while(!UART_SERCOM->USART.INTFLAG.bit.RXC);
|
---|
| 464 | return UART_SERCOM->USART.DATA.bit.DATA;
|
---|
| 465 | }
|
---|