implement waitForEvent() and systemOff()

This commit is contained in:
hathach committed 2017-08-31 15:14:37 +07:00
1 parent 51d8f082e9
commit a8d83b6c0d
3 files changed
+57 -22

No files matched your search

+1
View File
@@ -22,6 +22,7 @@
#include <stdbool.h>
#include "nrf.h"
#include "nrf_soc.h"
#include "nrf_sdm.h"
#ifdef __cplusplus
extern "C" {
+51
View File
@@ -20,6 +20,7 @@
#include <nrf.h>
#include "Arduino.h"
#include "nrf.h"
#ifdef __cplusplus
extern "C" {
@@ -69,6 +70,56 @@ void enterOTADfu(void)
NVIC_SystemReset();
}
void waitForEvent(void)
{
#if 0
// Set bit 7 and bits 4..0 in the mask to one (0x ...00 1001 1111)
enum { FPU_EXCEPTION_MASK = 0x0000009F };
/* Clear exceptions and PendingIRQ from the FPU unit */
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
(void) __get_FPSCR();
NVIC_ClearPendingIRQ(FPU_IRQn);
#endif
uint8_t sd_en;
(void) sd_softdevice_is_enabled(&sd_en);
if ( sd_en )
{
(void) sd_app_evt_wait();
}else
{
// SoftDevice is not enabled.
__WFE();
__SEV(); // Clear Event Register.
__WFE();
}
}
void systemOff(uint32_t pin, uint8_t wake_logic)
{
// for(int i=0; i<8; i++)
// {
// NRF_POWER->RAM[i].POWERCLR = 0x03UL;
// }
pinMode(pin, wake_logic ? INPUT_PULLDOWN : INPUT_PULLUP);
NRF_GPIO->PIN_CNF[pin] |= ((uint32_t) (wake_logic ? GPIO_PIN_CNF_SENSE_High : GPIO_PIN_CNF_SENSE_Low) << GPIO_PIN_CNF_SENSE_Pos);
uint8_t sd_en;
(void) sd_softdevice_is_enabled(&sd_en);
// Enter System OFF state
if ( sd_en )
{
sd_power_system_off();
}else
{
NRF_POWER->SYSTEMOFF = 1;
}
}
#ifdef __cplusplus
}
+5 -22
View File
@@ -22,34 +22,17 @@
extern "C" {
#endif
extern void init(void);
extern void enterSerialDfu(void);
extern void enterOTADfu(void);
/* Bootloader version. Assigned by init().
* - value of 0x000500 is version 0.5.0
*/
extern uint32_t bootloaderVersion;
// Hint instruction to tell CPU go to low power mode
#if 0
#define waitForEvent() __WFE()
#else
ATTR_ALWAYS_INLINE static inline void waitForEvent(void)
{
// Set bit 7 and bits 4..0 in the mask to one (0x ...00 1001 1111)
enum { FPU_EXCEPTION_MASK = 0x0000009F };
extern void init(void);
/* Clear exceptions and PendingIRQ from the FPU unit */
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
(void) __get_FPSCR();
NVIC_ClearPendingIRQ(FPU_IRQn);
/* Call SoftDevice Wait For event */
(void) sd_app_evt_wait();
}
#endif
void enterSerialDfu(void);
void enterOTADfu(void);
void waitForEvent(void);
void systemOff(uint32_t pin, uint8_t wake_logic);
#ifdef __cplusplus
}