update sd handler
This commit is contained in:
parent
c7ec0755ad
commit
dae80c7d61
@ -65,7 +65,7 @@ typedef struct
|
||||
} rx_buffer_queue_t;
|
||||
|
||||
static bool m_is_tx_allocated; /**< Boolean value to determine if the TX buffer is allocated. */
|
||||
static rx_buffer_elem_t m_rx_buffer_elem_queue[HCI_RX_BUF_QUEUE_SIZE]; /**< RX buffer element instances. */
|
||||
static rx_buffer_elem_t m_rx_buffer_elem_queue[HCI_RX_BUF_QUEUE_SIZE] __ALIGN(4); /**< RX buffer element instances. */
|
||||
static rx_buffer_queue_t m_rx_buffer_queue; /**< RX buffer queue element instance. */
|
||||
|
||||
|
||||
|
79
src/main.c
79
src/main.c
@ -83,7 +83,7 @@
|
||||
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
|
||||
|
||||
#define SCHED_MAX_EVENT_DATA_SIZE sizeof(app_timer_event_t) /**< Maximum size of scheduler events. */
|
||||
#define SCHED_QUEUE_SIZE 20 /**< Maximum number of events in the scheduler queue. */
|
||||
#define SCHED_QUEUE_SIZE 30 /**< Maximum number of events in the scheduler queue. */
|
||||
|
||||
// Helper function
|
||||
#define memclr(buffer, size) memset(buffer, 0, size)
|
||||
@ -492,18 +492,9 @@ void adafruit_factory_reset(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// Error Handler
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void halt_breakpoint(void)
|
||||
{
|
||||
// Cortex M CoreDebug->DHCSR
|
||||
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL);
|
||||
|
||||
// Only halt mcu if debugger is attached
|
||||
if ( (*ARM_CM_DHCSR) & 1UL ) __asm("BKPT #0\n");
|
||||
}
|
||||
|
||||
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
halt_breakpoint();
|
||||
verify_breakpoint();
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
@ -529,19 +520,6 @@ uint32_t tusb_hal_millis(void)
|
||||
return ( ( ((uint64_t)app_timer_cnt_get())*1000*(APP_TIMER_CONFIG_RTC_FREQUENCY+1)) / APP_TIMER_CLOCK_FREQ );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* SoftDevice Event handler
|
||||
*------------------------------------------------------------------*/
|
||||
void ada_ble_task(void* evt_data, uint16_t evt_size);
|
||||
void ada_soc_task(void* evt_data, uint16_t evt_size);
|
||||
|
||||
void SD_EVT_IRQHandler(void)
|
||||
{
|
||||
// Use App Scheduler to defer handling code in non-isr context
|
||||
app_sched_event_put(NULL, 0, ada_ble_task);
|
||||
app_sched_event_put(NULL, 0, ada_soc_task);
|
||||
}
|
||||
|
||||
void ada_ble_hanlder(ble_evt_t* evt)
|
||||
{
|
||||
// from dfu_transport_ble
|
||||
@ -550,44 +528,30 @@ void ada_ble_hanlder(ble_evt_t* evt)
|
||||
ble_evt_dispatch(evt);
|
||||
}
|
||||
|
||||
void ada_ble_task(void* evt_data, uint16_t evt_size)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* SoftDevice Event handler
|
||||
*------------------------------------------------------------------*/
|
||||
uint32_t proc_ble(void)
|
||||
{
|
||||
(void) evt_data;
|
||||
(void) evt_size;
|
||||
|
||||
// TODO Should check alignment 4
|
||||
__ALIGN(4) uint8_t ev_buf[ BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX) ];
|
||||
|
||||
uint32_t err = NRF_SUCCESS;
|
||||
|
||||
// Until no pending events
|
||||
while( NRF_ERROR_NOT_FOUND != err )
|
||||
{
|
||||
uint16_t ev_len = BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX);
|
||||
|
||||
// Get BLE Event
|
||||
err = sd_ble_evt_get(ev_buf, &ev_len);
|
||||
uint32_t err = sd_ble_evt_get(ev_buf, &ev_len);
|
||||
|
||||
// Handle valid event, ignore error
|
||||
if( NRF_SUCCESS == err)
|
||||
{
|
||||
ada_ble_hanlder( (ble_evt_t*) ev_buf );
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void ada_soc_task(void* evt_data, uint16_t evt_size)
|
||||
uint32_t proc_soc(void)
|
||||
{
|
||||
(void) evt_data;
|
||||
(void) evt_size;
|
||||
|
||||
uint32_t soc_evt;
|
||||
uint32_t err = NRF_SUCCESS;
|
||||
|
||||
// until no more pending events
|
||||
while ( NRF_ERROR_NOT_FOUND != err )
|
||||
{
|
||||
err = sd_evt_get(&soc_evt);
|
||||
uint32_t err = sd_evt_get(&soc_evt);
|
||||
|
||||
if (NRF_SUCCESS == err)
|
||||
{
|
||||
@ -597,5 +561,26 @@ void ada_soc_task(void* evt_data, uint16_t evt_size)
|
||||
pstorage_sys_event_handler(soc_evt);
|
||||
power_usb_event_handler(soc_evt);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void ada_sd_task(void* evt_data, uint16_t evt_size)
|
||||
{
|
||||
(void) evt_data;
|
||||
(void) evt_size;
|
||||
|
||||
// process BLE and SOC until there is no more events
|
||||
while( (NRF_ERROR_NOT_FOUND != proc_ble()) || (NRF_ERROR_NOT_FOUND != proc_soc()) )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SD_EVT_IRQHandler(void)
|
||||
{
|
||||
// Use App Scheduler to defer handling code in non-isr context
|
||||
app_sched_event_put(NULL, 0, ada_sd_task);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user