Skip to content

Commit 0facec2

Browse files
committed
Refactor get_reset_reason/rename to readResetReason.
Former-commit-id: 311e940
1 parent ad3405b commit 0facec2

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

cores/nRF5/wiring.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,37 @@
5151
extern "C" {
5252
#endif
5353

54-
static const char * _resetReason;
54+
static uint32_t _resetReason;
5555

5656
void init( void )
5757
{
58-
#if defined(USE_LFXO)
58+
59+
_resetReason = NRF_POWER->RESETREAS;
60+
NRF_POWER->RESETREAS |= NRF_POWER->RESETREAS;
61+
62+
#if defined(USE_LFXO)
5963
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
60-
#elif defined(USE_LFSYNT)
64+
#elif defined(USE_LFSYNT)
6165
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Synth << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
62-
#else //USE_LFRC
66+
#else //USE_LFRC
6367
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
64-
#endif
65-
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
66-
67-
#if defined(RESET_PIN)
68-
if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
69-
((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
70-
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
71-
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
72-
NRF_UICR->PSELRESET[0] = RESET_PIN;
73-
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
74-
NRF_UICR->PSELRESET[1] = RESET_PIN;
75-
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
76-
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
77-
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
78-
NVIC_SystemReset();
79-
}
80-
#endif
81-
82-
if(NRF_POWER->RESETREAS & (POWER_RESETREAS_DOG_Detected << POWER_RESETREAS_DOG_Pos))
83-
{
84-
_resetReason = "Watchdog timeout";
85-
NRF_POWER->RESETREAS = 0xffffffff;
86-
} else {
87-
_resetReason = "Device power on";
68+
#endif
69+
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
70+
71+
#if defined(RESET_PIN)
72+
if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
73+
((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
74+
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
75+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
76+
NRF_UICR->PSELRESET[0] = RESET_PIN;
77+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
78+
NRF_UICR->PSELRESET[1] = RESET_PIN;
79+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
80+
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
81+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
82+
NVIC_SystemReset();
8883
}
84+
#endif
8985

9086
// Set vendor IRQ's to default priority level
9187
for (unsigned i = 0; i < NUM_IRQS; i++) {
@@ -99,7 +95,7 @@ void init( void )
9995
NRF_WDT->TASKS_START = 1; //Start the Watchdog timer
10096
}
10197

102-
const char * get_reset_reason(void) {
98+
uint32_t readResetReason(void) {
10399
return _resetReason;
104100
}
105101

@@ -109,8 +105,8 @@ void systemPowerOff(void) {
109105

110106
__attribute__ ((__weak__))
111107
void enterSerialDfu(void) {
112-
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET;
113-
NVIC_SystemReset();
108+
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET;
109+
NVIC_SystemReset();
114110
}
115111

116112
#ifdef __cplusplus

cores/nRF5/wiring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525
extern void init(void);
2626
void enterSerialDfu(void);
2727
void systemPowerOff(void);
28-
const char * get_reset_reason(void);
28+
uint32_t readResetReason(void);
2929

3030
#ifdef __cplusplus
3131
}

0 commit comments

Comments
 (0)