summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-01-29 18:02:25 +0700
committerhathach <[email protected]>2019-01-29 18:02:25 +0700
commit6752a7126477b21c542b2f19b4ddeaa7584b0f0b (patch)
treef73741564afd5f534b4d0812efb70a41965f445f
parentae560bd8250d351fbe456daaffbf749682630c24 (diff)
usb work when sd is init first
-rw-r--r--hw/bsp/pca10056/board_pca10056.c57
1 files changed, 54 insertions, 3 deletions
diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c
index 16dce465e..7144d8d5b 100644
--- a/hw/bsp/pca10056/board_pca10056.c
+++ b/hw/bsp/pca10056/board_pca10056.c
@@ -188,8 +188,25 @@ void board_init(void)
uint32_t usb_reg;
#ifdef SOFTDEVICE_PRESENT
+
+// Enable to test enable SD before USB scenario
+#if 1
+ extern void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info);
+ nrf_clock_lf_cfg_t clock_cfg =
+ {
+ // LFXO
+ .source = NRF_CLOCK_LF_SRC_XTAL,
+ .rc_ctiv = 0,
+ .rc_temp_ctiv = 0,
+ .accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
+ };
+
+ sd_softdevice_enable(&clock_cfg, nrf_error_cb);
+ NVIC_EnableIRQ(SD_EVT_IRQn);
+#endif
+
uint8_t sd_en = false;
- (void) sd_softdevice_is_enabled(&sd_en);
+ sd_softdevice_is_enabled(&sd_en);
if ( sd_en ) {
sd_power_usbdetected_enable(true);
@@ -240,7 +257,7 @@ uint32_t board_buttons(void)
return ret;
}
-uint8_t board_uart_getchar(void)
+uint8_t board_uart_getchar(void)
{
return 0;
}
@@ -251,12 +268,46 @@ void board_uart_putchar(uint8_t c)
}
#ifdef SOFTDEVICE_PRESENT
+
+// process SOC event from SD
+uint32_t proc_soc(void)
+{
+ uint32_t soc_evt;
+ uint32_t err = sd_evt_get(&soc_evt);
+
+ if (NRF_SUCCESS == err)
+ {
+ /*------------- usb power event handler -------------*/
+ int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED:
+ (soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
+ (soc_evt == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1;
+
+ if ( usbevt >= 0) tusb_hal_nrf_power_event(usbevt);
+ }
+
+ return err;
+}
+
+uint32_t proc_ble(void)
+{
+ // do nothing with ble
+ return NRF_ERROR_NOT_FOUND;
+}
+
void SD_EVT_IRQHandler(void)
{
+ // process BLE and SOC until there is no more events
+ while( (NRF_ERROR_NOT_FOUND != proc_ble()) || (NRF_ERROR_NOT_FOUND != proc_soc()) )
+ {
+
+ }
}
-void SVC_Handler( void )
+void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
{
+ (void) id;
+ (void) pc;
+ (void) info;
}
#endif