/* send a found device info according to passed index */ void conn_send_found_device(uint8_t found_dev_index) { char ascii_address[12]; uart_send_string((uint8_t *)"OK-", 3); /* check required device index */ if(found_dev_index < devices_list_index) { /* connvert and send the device address */ util_address_to_string(found_devices[found_dev_index].gap_addr.addr, ascii_address); uart_send_string((uint8_t *)ascii_address, 12); app_uart_put('-'); /* send device name */ if(found_devices[found_dev_index].name_length > 0) { uart_send_string(found_devices[found_dev_index].name, found_devices[found_dev_index].name_length-1); } else { uart_send_string((uint8_t *)"Unknown", 7); } } else { uart_send_string((uint8_t *)"ERROR", 5); } app_uart_put('.'); }
/**@snippet [Handling the data received over BLE] */ static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { uint32_t err_code; NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.\r\n"); NRF_LOG_HEXDUMP_DEBUG(p_data, length); for (uint32_t i = 0; i < length; i++) { do { err_code = app_uart_put(p_data[i]); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. \r\n", err_code); APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_BUSY); } if (p_data[length-1] == '\r') { while (app_uart_put('\n') == NRF_ERROR_BUSY); } }
void uart_print_string(void) { app_uart_put('h'); app_uart_put('e'); app_uart_put('\n'); }
int _write(int fd, char * str, int len) { for (int ii = 0; ii < len; ii++) { // We could try to do something clever here like // decide if the buffer is almost full and put // ... instead of running out of space and then // break out of the loop. #if 1 // TODO: // The example app uart code in SDK 8 does this // in a while loop like this. Not totally clear // why or what error they are expecting. Should // figure this out. unsigned count = 1000; while(app_uart_put(str[ii]) != NRF_SUCCESS) { if(!count--) { break; } } #else // If no room in the buffer, just move on. app_uart_put(str[ii]); #endif } return len; }
static uint32_t send_tx_byte_encoded(void) { uint32_t err_code; switch(mp_tx_buffer[m_tx_buffer_index]) { case APP_SLIP_END: err_code = app_uart_put(APP_SLIP_ESC_END); break; case APP_SLIP_ESC: err_code = app_uart_put(APP_SLIP_ESC_ESC); break; default: err_code = NRF_ERROR_NO_MEM; break; } if (err_code == NRF_SUCCESS) { m_tx_buffer_index++; send_tx_byte = send_tx_byte_default; } return err_code; }
/** @brief Function for main application entry. */ int main(void) { // Setup bsp module. bsp_configuration(); //uart initialization uint32_t err_code; const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud115200 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); while(app_uart_put(86) != NRF_SUCCESS); intan_setup(); while(app_uart_put(87) != NRF_SUCCESS); // initialize the buffer buffer_init(&db, DATA_BUF_SIZE, sizeof(uint8_t)); while(app_uart_put(88) != NRF_SUCCESS); for (;;) { // printf("ldsakjf;ljdsaflkjlljlk\n"); while(app_uart_put(89) != NRF_SUCCESS); if (m_transfer_completed) { m_transfer_completed = false; intan_convert(m_tx_data_spi, m_rx_data_spi,intan_convert_channel); //print m_rx_data_spi results switch_state(); for (int i; i< RX_MSG_LENGTH; i++){ while(app_uart_put(m_rx_data_spi[i]) != NRF_SUCCESS); } nrf_delay_ms(DELAY_MS); //printf("Hi\n"); } //printf("Yo\n"); } }
/**@snippet [Handling the data received over BLE] */ void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { for (int i = 0; i < length; i++) { app_uart_put(p_data[i]); } app_uart_put('\n'); }
/**@snippet [Handling the data received over BLE] */ static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { for (uint32_t i = 0; i < length; i++) { while(app_uart_put(p_data[i]) != NRF_SUCCESS); } while(app_uart_put('\n') != NRF_SUCCESS); }
void _ttywrch(int ch) { if (CFG_PRINTF_NEWLINE[0] == '\r' && ch == '\n') { (void) app_uart_put('\r'); } (void) app_uart_put(ch); }
int fputc(int ch, FILE *f) { if (CFG_PRINTF_NEWLINE[0] == '\r' && ch == '\n') { (void) app_uart_put('\r'); } (void) app_uart_put(ch); return ch; }
static void uarts_write_handler(ble_uarts_t * p_uarts, uint8_t *data, int len) { uint32_t err; for (int i = 0; i < len; i++) { err = app_uart_put(data[i]); APP_ERROR_CHECK(err); } app_uart_put('\n'); //app_uart_flush(); }
int fputc(int ch, FILE * p_file) { uint32_t err_code = app_uart_put((uint8_t)ch); if (err_code == NRF_ERROR_NO_MEM) { UNUSED_PARAMETER(app_uart_flush()); for (uint32_t i = 0; i < sizeof(overflow_message); i++) { UNUSED_VARIABLE(app_uart_put(overflow_message[i])); } } return ch; }
int puts(const char * str) { while(*str) { if (CFG_PRINTF_NEWLINE[0] == '\r' && (*str) == '\n') { (void) app_uart_put('\r'); } (void) app_uart_put(*str++); } return 0; }
static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { SEGGER_RTT_WriteString(0, "received data \n"); newData = true; memset(txt_data,0,sizeof(txt_data)); for (uint32_t i = 0; i < length; i++) { //m_tx_data[i] = p_data[i]; txt_data[i] = p_data[i]; SEGGER_RTT_printf(0,"%c", p_data[i]); while(app_uart_put(p_data[i]) != NRF_SUCCESS); } SEGGER_RTT_printf(0, "to send: %s\n", txt_data); SEGGER_RTT_WriteString(0, "\n"); while(app_uart_put('\n') != NRF_SUCCESS); }
int fputc(int ch, FILE * p_file) { UNUSED_PARAMETER(p_file); UNUSED_VARIABLE(app_uart_put((uint8_t)ch)); return ch; }
/**@brief Nordic UART Service (NUS) Client Event Handler. */ static void uart_c_evt_handler(ble_uart_c_t * p_uart_c, ble_uart_c_evt_t * p_uart_c_evt) { uint32_t err_code; switch (p_uart_c_evt->evt_type) { case BLE_UART_C_EVT_DISCOVERY_COMPLETE: // Initiate bonding. err_code = dm_security_setup_req(&m_dm_device_handle); APP_ERROR_CHECK(err_code); // Nordic UART service discovered. Enable notification of RX data channel. err_code = ble_uart_c_rx_notif_enable(p_uart_c); APP_ERROR_CHECK(err_code); break; case BLE_UART_C_EVT_RX_DATA_NOTIFICATION: { for (uint32_t i = 0; i < p_uart_c_evt->params.uart.len; i++) { while(app_uart_put(p_uart_c_evt->params.uart.rx_data[i]) != NRF_SUCCESS); } break; } default: break; } }
/* CENTRAL: Callback handling NUS Client events. Handling events from the ble_nus_c module. This function is called to notify the application of NUS client events. Parameters: p_ble_nus_c NUS Client Handle. This identifies the NUS client p_ble_nus_evt Pointer to the NUS Client event. */ static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt) { uint32_t err_code; switch (p_ble_nus_evt->evt_type) { case BLE_NUS_C_EVT_FOUND_NUS_TX_CHARACTERISTIC: { /* TX characteristic found */ break; } case BLE_NUS_C_EVT_FOUND_NUS_RX_CHARACTERISTIC: { /* RX characteristic found: enable notification on that */ err_code = ble_nus_c_rx_notif_enable(p_ble_nus_c); APP_ERROR_CHECK(err_code); break; } case BLE_NUS_C_EVT_NUS_RX_EVT: { /* send received data from NUS to uart interface */ for (uint32_t i = 0; i < p_ble_nus_evt->data_len; i++) { while(app_uart_put( p_ble_nus_evt->p_data[i]) != NRF_SUCCESS); } app_uart_put('.'); break; } case BLE_NUS_C_EVT_DISCONNECTED: { /* clear related connection handle */ active_conn_handles[pending_nus_conn_index] = BLE_CONN_HANDLE_INVALID; /* reset pending NUS connection index */ pending_nus_conn_index = 0xFF; /* reset uart */ uart_reset(); /* set "connection" pin as disconnected */ nrf_gpio_pin_write(CONN_PIN_NUMBER, DISCONNECTED_PIN_STATE); /* send confirmation string */ uart_send_string((uint8_t *)"OK.", 3); break; } } }
int fputc(int ch, FILE * p_file) { #if defined(TRACE_UART) const uint32_t err_code = app_uart_put((uint8_t)ch); UNUSED_VARIABLE(err_code); #endif // TRACE_UART return ch; }
static __inline void tx_next_byte(void) { if (BUFFER_USED_SPACE() == 0) { state = READY; return; } app_uart_put(buffer[RP]); rp++; }
int _write(int fd, char * str, int len) { uint32_t err_code; for (int i = 0; i < len; i++) { do { err_code = app_uart_put(str[i]); } while (err_code == NRF_ERROR_NO_MEM); } return len; }
void hif_send(uint8_t* data, uint32_t size) { int i; uint32_t err_code; uint8_t hdr[SERIAL_HEADER_LENGTH]; hdr[0] = SERIAL_SYNC_BYTE; hdr[1] = size; for (i=0; i<SERIAL_HEADER_LENGTH; i++) { err_code = app_uart_put(hdr[i]); APP_ERROR_CHECK(err_code); } for (i=0; i<size; i++) { err_code = app_uart_put(data[i]); APP_ERROR_CHECK(err_code); } }
bool bridge_send_packet(void) { uint8_t cnt; uint8_t * ptr; app_uart_put(bridge.tx.packet.command); app_uart_put(bridge.tx.packet.payload_length); ptr = (uint8_t *)&bridge.tx.packet.payload; for(cnt = 0; cnt < bridge.tx.packet.payload_length; cnt++) { if(app_uart_put(ptr[cnt]) != NRF_SUCCESS) { return false; } } app_uart_put((uint8_t)bridge.tx.packet.crc16); app_uart_put((uint8_t)(bridge.tx.packet.crc16 >> 8)); return true; }
static uint32_t send_tx_byte_default(void) { uint32_t err_code = app_uart_put(mp_tx_buffer[m_tx_buffer_index]); if (err_code == NRF_SUCCESS) { m_tx_buffer_index++; } return err_code; }
__STATIC_INLINE void slip_encode(void) { switch (mp_data->p_buffer[m_tx_index]) { case APP_SLIP_END: m_tx_escape = true; (void)app_uart_put(APP_SLIP_ESC); break; case APP_SLIP_ESC: m_tx_escape = true; (void)app_uart_put(APP_SLIP_ESC); break; default: (void)app_uart_put(mp_data->p_buffer[m_tx_index]); m_tx_index++; break; } }
static uint32_t send_tx_byte_esc(void) { uint32_t err_code = app_uart_put(APP_SLIP_ESC); if (err_code == NRF_SUCCESS) { send_tx_byte = send_tx_byte_encoded; } return err_code; }
static uint32_t send_tx_byte_end(void) { uint32_t err_code = app_uart_put(APP_SLIP_END); if ((err_code == NRF_SUCCESS) && (m_tx_buffer_index == 0)) { // Packet transmission started. send_tx_byte = send_tx_byte_default; } return err_code; }
void uart_putstring(const uint8_t * str) { uint32_t err_code; uint8_t len = strlen((char *) str); for (uint8_t i = 0; i < len; i++) { err_code = app_uart_put(str[i]); APP_ERROR_CHECK(err_code); } }
/** * @brief Function for main application entry. */ int main(void) { LEDS_CONFIGURE(LEDS_MASK); LEDS_OFF(LEDS_MASK); uint32_t err_code; const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud115200 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); #ifndef ENABLE_LOOPBACK_TEST printf("\n\rStart: \n\r"); while (true) { uint8_t cr; while(app_uart_get(&cr) != NRF_SUCCESS); while(app_uart_put(cr) != NRF_SUCCESS); if (cr == 'q' || cr == 'Q') { printf(" \n\rExit!\n\r"); while (true) { // Do nothing. } } } #else // This part of the example is just for testing the loopback . while (true) { uart_loopback_test(); } #endif }
/* send a number of found devices */ void conn_send_num_found_devices(void) { char string[4]; /* build the string */ string[0] = 'O'; string[1] = 'K'; string[2] = '-'; string[3] = (char)(0x30 | devices_list_index); /* ascii conversion */ /* send the string */ uart_send_string((uint8_t *)string, 4); app_uart_put('.'); }
/** *@brief Function for handling Tx procedure. */ static void ser_phy_uart_tx(void) { if (mp_tx_stream != NULL) { bool tx_done_flag = false; /**< Local flag for indicating that TX is completed */ uint32_t err_code = NRF_SUCCESS; /**< Error code for storing result of app_uart_put */ //Blocking TXRDY interrupt is done to avoid interrupting when this procedure is //triggered from main context NRF_UART0->INTENCLR = (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos); //Notify upper layer if whole packet has been transmitted if (m_tx_stream_index == m_tx_stream_length) { callback_packet_sent(); tx_done_flag = true; } //First transmit 2 bytes of packet length else if (m_tx_stream_index < SER_PHY_HEADER_SIZE) { err_code = app_uart_put(m_tx_length_buf[m_tx_stream_index]); } //Then transmit payload else if (m_tx_stream_index < m_tx_stream_length) { err_code = app_uart_put(mp_tx_stream[m_tx_stream_index - SER_PHY_HEADER_SIZE]); } //Increment index only if byte was sent without errors if ((err_code == NRF_SUCCESS) && !tx_done_flag) { m_tx_stream_index++; } //Unblock TXRDY interrupts NRF_UART0->INTENSET = (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos); } }