/** * @brief Function to handle the state machine serial data exchange. */ void serial_data_handler(void) { /* Rx processing */ if (data_length == 0) { /* No data to process, read the stream IO */ rx_index = 0; data_length = sio2host_rx(data, SIO_RX_BUF_SIZE); } else { /* Data has been received, process the data */ /* Process each single byte */ process_incoming_sio_data(); data_length--; rx_index++; } /* Tx processing */ if (buf_count != 0) { if (sio2host_tx(sio_tx_buf[head], (sio_tx_buf[head][1] + 3)) != 0) { head++; head %= SIO_BUF_COUNT; buf_count--; } else { /* @ToDo what happens if none or only a part of the * bytes could be transmitted? */ } } }
_write (int file, const char *ptr, int len) { if ((file != 1) && (file != 2) && (file!=3)) { return -1; } sio2host_tx((uint8_t*)buffer,(uint8_t)size); return size; }
void send_server_data(ota_domain_t domain_id, addr_mode_t addr_mode, uint8_t *addr, uint8_t msg_id, uint8_t *msg, uint16_t len) { uint8_t fcs = 0; uint8_t total_len; uint8_t addr_size; if(NATIVE_ADDR_MODE == addr_mode) { addr_size = NATIVE_ADDR_SIZE; } else { addr_size = EXTENDED_ADDR_SIZE; } total_len = len + 5 + 1 + addr_size; //Seq no + stack id + Domain + command id + msg_id sio2host_putchar(SOF); sio2host_putchar(0x80); //AREQ/ARSP sio2host_putchar((uint8_t)total_len); sio2host_putchar((uint8_t)total_len >> 8); sio2host_putchar(tx_seq_no); sio2host_putchar(STACK_ID); sio2host_putchar(domain_id); sio2host_putchar(0x00); sio2host_putchar(msg_id); sio2host_putchar(addr_mode); sio2host_tx(addr, addr_size); fcs = tx_seq_no ^ STACK_ID ^ domain_id ^ 0x00 ^ msg_id ^ addr_mode; for(uint8_t index = 0; index < addr_size; index++) { fcs ^= *(addr + index); } if(len) { sio2host_tx(msg, len); for(uint8_t index = 0; index < len; index++) { fcs ^= *(msg + index); } } sio2host_putchar(fcs); tx_seq_no++; }
void serial_bridge_handler() { length_received_host = sio2host_rx(temp, SIO_RX_BUF_SIZE); if (length_received_host != 0) { sio2ncp_tx(temp, length_received_host); length_received_host = 0; } length_received_ncp = sio2ncp_rx(temp, SIO_RX_BUF_SIZE); if (length_received_ncp != 0) { sio2host_tx(temp, length_received_ncp); length_received_ncp = 0; } }
_STD_BEGIN #pragma module_name = "?__write" size_t __write(int handle, const unsigned char *buffer, size_t size) { if (buffer == 0) { return 0; } // This implementation only writes to stdout and stderr. // For all other file handles, it returns failure. if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) { return _LLIO_ERROR; } sio2host_tx((uint8_t*)buffer,(uint8_t)size); return size; }
void send_pc_data(ota_domain_t domain_id, uint8_t msg_id, uint8_t *msg, uint16_t len) { uint8_t fcs = 0; uint8_t total_len = len + 5; //Seq no + stack id + Domain + command id + msg_id sio2host_putchar(SOF); sio2host_putchar(0x80); //AREQ/ARSP sio2host_putchar((uint8_t)total_len); sio2host_putchar((uint8_t)total_len >> 8); sio2host_putchar(tx_seq_no); //constant sequence number as of now... sio2host_putchar(STACK_ID); sio2host_putchar(domain_id); sio2host_putchar(COMMON); sio2host_putchar(msg_id); fcs = tx_seq_no ^ STACK_ID ^ domain_id ^ COMMON ^ msg_id; sio2host_tx(msg, len); for(uint8_t index = 0; index < len; index++) { fcs ^= *(msg + index); } sio2host_putchar(fcs); tx_seq_no++; }
void sio2host_putchar(uint8_t ch) { sio2host_tx(&ch, 1); }
int _write (char c, int *f) { sio2host_tx((uint8_t *)&c,1); return 1; }