From d4c980ca86e49c1dd00e991935d7f6dccb695584 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 4 Aug 2016 17:44:34 +0100 Subject: [PATCH] unsuccessful tweaks to use IRQs for BLE TX --- libs/bluetooth/jswrap_bluetooth.c | 38 ++++++++++++++++++++++++++++--- targets/nrf5x/jshardware.c | 9 -------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 2a56f638c..c0af7f98f 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -134,7 +134,7 @@ bool jswrap_nrf_transmit_string(); "generate" : "jswrap_nrf_idle" }*/ bool jswrap_nrf_idle() { - return jswrap_nrf_transmit_string()>0; // return true if we sent anything + return false; } /*JSON{ @@ -439,7 +439,36 @@ bool jswrap_nrf_transmit_string() { } return idx>0; } -/**@snippet [Handling the data received over BLE] */ + +uint32_t radio_notification_init(uint32_t irq_priority, uint8_t notification_type, uint8_t notification_distance) +{ + uint32_t err_code; + + err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = sd_nvic_EnableIRQ(SWI1_IRQn); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Configure the event + return sd_radio_notification_cfg_set(notification_type, notification_distance); +} + +void SWI1_IRQHandler(bool radio_evt) { + jswrap_nrf_transmit_string(); +} /**@brief Function for initializing services that will be used by the application. @@ -693,7 +722,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) case BLE_EVT_TX_COMPLETE: // UART Transmit finished - we can try and send more data bleStatus &= ~BLE_IS_SENDING; - jswrap_nrf_transmit_string(); break; case BLE_GAP_EVT_ADV_REPORT: { @@ -1047,6 +1075,10 @@ void jswrap_nrf_bluetooth_init(void) { conn_params_init(); jswrap_nrf_bluetooth_wake(); + + radio_notification_init(3, + NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, + NRF_RADIO_NOTIFICATION_DISTANCE_5500US); } /*JSON{ diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c index 47b9c6078..070b746de 100644 --- a/targets/nrf5x/jshardware.c +++ b/targets/nrf5x/jshardware.c @@ -680,15 +680,6 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { /** Kick a device into action (if required). For instance we may need to set up interrupts */ void jshUSARTKick(IOEventFlags device) { - - if (device == EV_BLUETOOTH) { - /* For bluetooth, start transmit after one character. - The BLE_EVT_TX_COMPLETE event will get triggered and - will auto-reload whatever needs sending. */ - bool jswrap_nrf_transmit_string(); - jswrap_nrf_transmit_string(); - } - if (device == EV_SERIAL1) { if (uartInitialised) { if (!uartIsSending) {