Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bsp/board/openmote-%: add DEEP_SLEEP configuration #542

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions bsp/boards/openmote-b-24ghz/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,31 @@ void antenna_init(void) {

void antenna_cc2538(void) {
GPIOPinWrite(BSP_ANTENNA_BASE, BSP_ANTENNA_CC2538_24GHZ, 0);
GPIOPinWrite(BSP_ANTENNA_BASE, BSP_ANTENNA_AT215_24GHZ, BSP_ANTENNA_AT215_24GHZ);
GPIOPinWrite(BSP_ANTENNA_BASE, BSP_ANTENNA_AT215_24GHZ, BSP_ANTENNA_AT215_24GHZ);
}

void antenna_at86rf215(void) {
GPIOPinWrite(BSP_ANTENNA_BASE, BSP_ANTENNA_AT215_24GHZ, 0);
GPIOPinWrite(BSP_ANTENNA_BASE, BSP_ANTENNA_CC2538_24GHZ, BSP_ANTENNA_CC2538_24GHZ);
}
}

/**
* Puts the board to sleep
*/
void board_sleep(void) {
#if BOARD_DEEP_SLEEP
if(radio_is_enabled()) {
SysCtrlPowerModeSet(SYS_CTRL_PM_NOACTION);
SysCtrlSleep();
}
else {
SysCtrlPowerModeSet(SYS_CTRL_PM_1);
SysCtrlDeepSleep();
}
#else
SysCtrlPowerModeSet(SYS_CTRL_PM_NOACTION);
SysCtrlSleep();
#endif
}

/**
Expand Down
9 changes: 8 additions & 1 deletion bsp/boards/openmote-b-24ghz/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
radio_capture_cbt startFrame_cb;
radio_capture_cbt endFrame_cb;
radio_state_t state;
bool radio_txrx_enabled;
} radio_vars_t;

radio_vars_t radio_vars;
Expand Down Expand Up @@ -259,6 +260,7 @@ void radio_loadPacket(uint8_t* packet, uint16_t len) {
}

void radio_txEnable(void) {
radio_vars.radio_txrx_enabled = true;

// change state
radio_vars.state = RADIOSTATE_ENABLING_TX;
Expand Down Expand Up @@ -299,7 +301,7 @@ void radio_txNow(void) {
//===== RX

void radio_rxEnable(void) {

radio_vars.radio_txrx_enabled = true;
// change state
radio_vars.state = RADIOSTATE_ENABLING_RX;

Expand Down Expand Up @@ -404,6 +406,7 @@ void radio_on(void){
}

void radio_off(void){
radio_vars.radio_txrx_enabled = false;
/* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */
while(HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
//CC2538_RF_CSP_ISFLUSHRX();
Expand Down Expand Up @@ -538,3 +541,7 @@ void radio_error_isr(void){
//poipoi -- todo handle error
}
}

bool radio_is_enabled(void) {
return radio_vars.radio_txrx_enabled;
}
23 changes: 17 additions & 6 deletions bsp/boards/openmote-b/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(void) {

void board_init(void) {
user_button_initialized = FALSE;

gpio_init();
clock_init();
antenna_init();
Expand Down Expand Up @@ -104,8 +104,19 @@ void antenna_init(void) {
* Puts the board to sleep
*/
void board_sleep(void) {
#if BOARD_DEEP_SLEEP
if(radio_is_enabled()) {
SysCtrlPowerModeSet(SYS_CTRL_PM_NOACTION);
SysCtrlSleep();
}
else {
SysCtrlPowerModeSet(SYS_CTRL_PM_1);
SysCtrlDeepSleep();
}
#else
SysCtrlPowerModeSet(SYS_CTRL_PM_NOACTION);
SysCtrlSleep();
#endif
}

/**
Expand All @@ -115,7 +126,7 @@ void board_sleep(void) {
void board_timer_init(void) {
// Configure the timer
TimerConfigure(GPTIMER2_BASE, GPTIMER_CFG_PERIODIC_UP);

// Enable the timer
TimerEnable(GPTIMER2_BASE, GPTIMER_BOTH);
}
Expand All @@ -126,9 +137,9 @@ void board_timer_init(void) {
*/
uint32_t board_timer_get(void) {
uint32_t current;

current = TimerValueGet(GPTIMER2_BASE, GPTIMER_A) >> 5;

return current;
}

Expand All @@ -143,7 +154,7 @@ bool board_timer_expired(uint32_t future) {
current = TimerValueGet(GPTIMER2_BASE, GPTIMER_A) >> 5;

remaining = (int32_t) (future - current);

if (remaining > 0) {
return false;
} else {
Expand Down Expand Up @@ -325,7 +336,7 @@ static void GPIO_C_Handler(void) {
FlashMainPageErase(CC2538_FLASH_ADDRESS);

leds_circular_shift();

/* Reset the board */
SysCtrlReset();
}
Loading