uint8_t sio2host_getchar(void) { uint8_t c; while (0 == sio2host_rx(&c, 1)) { } return c; }
void serial_data_handler(void) { uint8_t i, j; // for test only data_length = sio2host_rx(data, SERIAL_RX_BUF_SIZE_HOST); // Get input from UART if (data_length != 0) // UART data has been received { for (i = 0; i < data_length; i++) { uart_rx_buf[rx_index++] = data[i]; // Put the received data in the buffer if (uart_rx_buf[rx_index - 1] == '>') // The char '>' is defined as the end of the char sequence { for (j = 0; j < rx_index; j++) { printf("%c", uart_rx_buf[j]); // Print out the buffer content uart_rx_buf[j] = 0x00; //data[j] = 0x00; /* if (j + 1 == rx_index){ printf("%c", uart_rx_buf[j+1]); uart_rx_buf[j+1] = 0x00; //data[j+1] = 0x00; } // Clear the buffer*/ } printf("\n"); rx_index = 0; // Reset the buffer pointer } } } }
/** * @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? */ } } }
int sio2host_getchar_nowait(void) { uint8_t c; int back = sio2host_rx(&c, 1); if (back >= 1) { return c; } else { return (-1); } }
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; } }
/* * @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[0], SIO_RX_BUF_SIZE); /* @ToDo 20 ?, * different * values for * USB and * UART ? */ } else { /* Data has been received, process the data */ /* Process each single byte */ process_incoming_sio_data(); data_length--; rx_index++; } }
void serial_data_handler(void) { if (data_length == 0) { /* No data to process, read the stream IO */ //rx_index = 0; data_length = sio2host_rx(data, 156); /* @ToDo 20 ?, * different * values for * USB and * UART ? */ } else { /* Data has been received, process the data */ printf("Receiving file..\n"); data_length--; rx_index++; if(rx_index ==99) { printf("Received File!!!!!!!!!!\n"); } } #endif void configure_gclock_generator(void) { //! [setup_1] struct system_gclk_gen_config gclock_gen_conf; //! [setup_1] //! [setup_2] system_gclk_gen_get_config_defaults(&gclock_gen_conf); //! [setup_2] //! [setup_3] gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_ULP32K; gclock_gen_conf.division_factor = 128; //! [setup_3] //! [setup_4] system_gclk_gen_set_config(GCLK_GENERATOR_4, &gclock_gen_conf); //! [setup_4] //! [setup_5] system_gclk_gen_enable(GCLK_GENERATOR_4); //! [setup_5] } /*---------------------------------------------------------------------------*/ static void set_link_addr(void) { linkaddr_t addr; unsigned int i; memset(&addr, 0, sizeof(linkaddr_t)); #if UIP_CONF_IPV6 #if SAMR21 memcpy(addr.u8, eui64, sizeof(addr.u8)); #else memcpy(addr.u8, node_mac, sizeof(addr.u8)); #endif #else /* UIP_CONF_IPV6 */ if(node_id == 0) { for(i = 0; i < sizeof(linkaddr_t); ++i) { #if SAMR21 addr.u8[i] = eui64 [7 - i]; #else addr.u8[i] = node_mac [7 - i]; #endif } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; } #endif /* UIP_CONF_IPV6 */ linkaddr_set_node_addr(&addr); printf("Link layer addr "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%u:", addr.u8[i]); } printf("%u, ", addr.u8[i]); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%02x:", addr.u8[i]); } printf("%02x\n", addr.u8[i]); }
/*************************************************************************//** *****************************************************************************/ static void APP_TaskHandler(void) { switch (appState) { case APP_STATE_INITIAL: { appInit(); } break; case APP_STATE_SEND: { appSendData(); } break; case APP_STATE_SENDING_DONE: { #if APP_ENDDEVICE appState = APP_STATE_PREPARE_TO_SLEEP; #else SYS_TimerStart(&appDataSendingTimer); appState = APP_STATE_WAIT_SEND_TIMER; #endif } break; case APP_STATE_PREPARE_TO_SLEEP: { if (!NWK_Busy()) { NWK_SleepReq(); appState = APP_STATE_SLEEP; } } break; case APP_STATE_SLEEP: { sm_sleep(APP_SENDING_INTERVAL/1000); appState = APP_STATE_WAKEUP; } break; case APP_STATE_WAKEUP: { NWK_WakeupReq(); LED_On(LED_NETWORK); appState = APP_STATE_SEND; } break; default: break; } #if APP_COORDINATOR if(sio2host_rx(rx_data,APP_RX_BUF_SIZE) > 0) { LED_Toggle(LED_BLINK); } #endif }
int _read (int *f) { char c; sio2host_rx((uint8_t *)&c,1); return c; }