update sd handler

This commit is contained in:
hathach 2018-04-14 12:15:50 +07:00
parent c7ec0755ad
commit dae80c7d61
2 changed files with 43 additions and 58 deletions

View File

@ -65,7 +65,7 @@ typedef struct
} rx_buffer_queue_t; } rx_buffer_queue_t;
static bool m_is_tx_allocated; /**< Boolean value to determine if the TX buffer is allocated. */ 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. */ static rx_buffer_queue_t m_rx_buffer_queue; /**< RX buffer queue element instance. */

View File

@ -83,7 +83,7 @@
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */ #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_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 // Helper function
#define memclr(buffer, size) memset(buffer, 0, size) #define memclr(buffer, size) memset(buffer, 0, size)
@ -492,18 +492,9 @@ void adafruit_factory_reset(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Error Handler // 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) void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{ {
halt_breakpoint(); verify_breakpoint();
NVIC_SystemReset(); 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 ); 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) void ada_ble_hanlder(ble_evt_t* evt)
{ {
// from dfu_transport_ble // from dfu_transport_ble
@ -550,52 +528,59 @@ void ada_ble_hanlder(ble_evt_t* evt)
ble_evt_dispatch(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) ]; __ALIGN(4) uint8_t ev_buf[ BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX) ];
uint16_t ev_len = BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX);
uint32_t err = NRF_SUCCESS; // Get BLE Event
uint32_t err = sd_ble_evt_get(ev_buf, &ev_len);
// Until no pending events // Handle valid event, ignore error
while( NRF_ERROR_NOT_FOUND != err ) if( NRF_SUCCESS == err)
{ {
uint16_t ev_len = BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX); ada_ble_hanlder( (ble_evt_t*) ev_buf );
// Get BLE Event
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)
{
uint32_t soc_evt;
uint32_t err = sd_evt_get(&soc_evt);
if (NRF_SUCCESS == err)
{
// from hal_nrf5x.c
extern void power_usb_event_handler(uint32_t evt);
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_data;
(void) evt_size; (void) evt_size;
uint32_t soc_evt; // process BLE and SOC until there is no more events
uint32_t err = NRF_SUCCESS; while( (NRF_ERROR_NOT_FOUND != proc_ble()) || (NRF_ERROR_NOT_FOUND != proc_soc()) )
// until no more pending events
while ( NRF_ERROR_NOT_FOUND != err )
{ {
err = sd_evt_get(&soc_evt);
if (NRF_SUCCESS == err)
{
// from hal_nrf5x.c
extern void power_usb_event_handler(uint32_t evt);
pstorage_sys_event_handler(soc_evt);
power_usb_event_handler(soc_evt);
}
} }
} }
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);
}