diff options
| author | Ha Thach <[email protected]> | 2020-05-12 14:35:45 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-12 14:35:45 +0700 |
| commit | 4e6aa0d81d2dbd23006d5a961938f6478049467a (patch) | |
| tree | 4651ab9772cc3db54be62963f3090c6ae9453efc | |
| parent | 16a3f0a27a8ba9f2eb92ddbea48c05db952bddb4 (diff) | |
| parent | 58b99e59d44197c32cf68e730f67563f28382d2e (diff) | |
Merge pull request #390 from hathach/detect-nrf-softdevice
detect if SD is actually present on the flash using SD magic
| -rw-r--r-- | src/portable/nordic/nrf5x/dcd_nrf5x.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 12435ea23..d788547b8 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -32,13 +32,6 @@ #include "nrf_clock.h" #include "nrf_power.h" #include "nrfx_usbd_errata.h" - -#ifdef SOFTDEVICE_PRESENT -// For enable/disable hfclk with SoftDevice -#include "nrf_sdm.h" -#include "nrf_soc.h" -#endif - #include "device/dcd.h" // TODO remove later @@ -564,9 +557,26 @@ void dcd_int_handler(uint8_t rhport) // HFCLK helper //--------------------------------------------------------------------+ #ifdef SOFTDEVICE_PRESENT -// check if SD is present and enabled -static bool is_sd_enabled(void) + +// For enable/disable hfclk with SoftDevice +#include "nrf_mbr.h" +#include "nrf_sdm.h" +#include "nrf_soc.h" + +#ifndef SD_MAGIC_NUMBER + #define SD_MAGIC_NUMBER 0x51B1E5DB +#endif + +static inline bool is_sd_existed(void) { + return *((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == SD_MAGIC_NUMBER; +} + +// check if SD is existed and enabled +static inline bool is_sd_enabled(void) +{ + if ( !is_sd_existed() ) return false; + uint8_t sd_en = false; (void) sd_softdevice_is_enabled(&sd_en); return sd_en; |
