From 5644e95fb6b261a7cdcb792e67e239918d35666c Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 1 May 2015 16:15:33 +0100 Subject: [PATCH] Fix global interrupt manipulation --- cpu/cc26xx/dev/cc26xx-rf.c | 61 ++++++++++++++++++------- cpu/cc26xx/dev/cc26xx-rtc.c | 11 ++++- platform/srf06-cc26xx/sensortag/board.c | 3 +- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/cpu/cc26xx/dev/cc26xx-rf.c b/cpu/cc26xx/dev/cc26xx-rf.c index 97b1aafc4..e034cc830 100644 --- a/cpu/cc26xx/dev/cc26xx-rf.c +++ b/cpu/cc26xx/dev/cc26xx-rf.c @@ -69,6 +69,7 @@ #include #include #include +#include /*---------------------------------------------------------------------------*/ #define BUSYWAIT_UNTIL(cond, max_time) \ do { \ @@ -431,16 +432,19 @@ static uint_fast8_t rf_send_cmd(uint32_t cmd, uint32_t *status) { uint32_t timeout_count = 0; + bool interrupts_disabled; /* * Make sure ContikiMAC doesn't turn us off from within an interrupt while * we are accessing RF Core registers */ - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); if(!rf_is_accessible()) { PRINTF("rf_send_cmd: RF was off\n"); - ti_lib_int_master_enable(); + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } return RF_CMD_ERROR; } @@ -449,12 +453,16 @@ rf_send_cmd(uint32_t cmd, uint32_t *status) *status = HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA); if(++timeout_count > 50000) { PRINTF("rf_send_cmd: Timeout\n"); - ti_lib_int_master_enable(); + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } return RF_CMD_ERROR; } } while(*status == RF_CMD_STATUS_PENDING); - ti_lib_int_master_enable(); + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } /* * If we reach here the command is no longer pending. It is either completed @@ -911,8 +919,8 @@ static int power_up(void) { uint32_t cmd_status; + bool interrupts_disabled = ti_lib_int_master_disable(); - ti_lib_int_master_disable(); ti_lib_int_pend_clear(INT_RF_CPE0); ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_disable(INT_RF_CPE0); @@ -935,7 +943,10 @@ power_up(void) HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = 0x0; ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE1); - ti_lib_int_master_enable(); + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } /* Let CPE boot */ HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = RF_CORE_CLOCKS_MASK; @@ -955,7 +966,7 @@ power_up(void) static void power_down(void) { - ti_lib_int_master_disable(); + bool interrupts_disabled = ti_lib_int_master_disable(); ti_lib_int_disable(INT_RF_CPE0); ti_lib_int_disable(INT_RF_CPE1); @@ -978,7 +989,9 @@ power_down(void) ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE1); - ti_lib_int_master_enable(); + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } } /*---------------------------------------------------------------------------*/ static int @@ -1093,6 +1106,8 @@ cc26xx_rf_cpe0_isr(void) static void setup_interrupts(void) { + bool interrupts_disabled; + /* We are already turned on by the caller, so this should not happen */ if(!rf_is_accessible()) { PRINTF("setup_interrupts: No access\n"); @@ -1100,7 +1115,7 @@ setup_interrupts(void) } /* Disable interrupts */ - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); /* Set all interrupt channels to CPE0 channel, error to CPE1 */ HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEISL) = ERROR_IRQ; @@ -1115,7 +1130,10 @@ setup_interrupts(void) ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE1); - ti_lib_int_master_enable(); + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } } /*---------------------------------------------------------------------------*/ static uint8_t @@ -1926,6 +1944,7 @@ PROCESS_THREAD(cc26xx_rf_ble_beacon_process, ev, data) uint8_t was_on; int j; uint32_t cmd_status; + bool interrupts_disabled; PROCESS_BEGIN(); @@ -1956,9 +1975,11 @@ PROCESS_THREAD(cc26xx_rf_ble_beacon_process, ev, data) * Under ContikiMAC, some IEEE-related operations will be called from an * interrupt context. We need those to see that we are in BLE mode. */ - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); ble_mode_on = 1; - ti_lib_int_master_enable(); + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } /* * Send BLE_ADV_MESSAGES beacon bursts. Each burst on all three @@ -2055,9 +2076,13 @@ PROCESS_THREAD(cc26xx_rf_ble_beacon_process, ev, data) } etimer_set(&ble_adv_et, BLE_ADV_DUTY_CYCLE); - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); + ble_mode_on = 0; - ti_lib_int_master_enable(); + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } /* Wait unless this is the last burst */ if(i < BLE_ADV_MESSAGES - 1) { @@ -2065,9 +2090,13 @@ PROCESS_THREAD(cc26xx_rf_ble_beacon_process, ev, data) } } - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); + ble_mode_on = 0; - ti_lib_int_master_enable(); + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } } PROCESS_END(); } diff --git a/cpu/cc26xx/dev/cc26xx-rtc.c b/cpu/cc26xx/dev/cc26xx-rtc.c index b1b01ea6e..9c3d58756 100644 --- a/cpu/cc26xx/dev/cc26xx-rtc.c +++ b/cpu/cc26xx/dev/cc26xx-rtc.c @@ -44,6 +44,7 @@ #include "ti-lib.h" #include +#include /*---------------------------------------------------------------------------*/ #define cc26xx_rtc_isr(...) AONRTCIntHandler(__VA_ARGS__) /*---------------------------------------------------------------------------*/ @@ -54,9 +55,11 @@ void cc26xx_rtc_init(void) { uint32_t compare_value; + bool interrupts_disabled; /* Disable and clear interrupts */ - ti_lib_int_master_disable(); + interrupts_disabled = ti_lib_int_master_disable(); + ti_lib_aon_rtc_disable(); ti_lib_aon_rtc_event_clear(AON_RTC_CH0); @@ -80,7 +83,11 @@ cc26xx_rtc_init(void) ti_lib_aon_rtc_enable(); ti_lib_int_enable(INT_AON_RTC); - ti_lib_int_master_enable(); + + /* Re-enable interrupts */ + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } } /*---------------------------------------------------------------------------*/ rtimer_clock_t diff --git a/platform/srf06-cc26xx/sensortag/board.c b/platform/srf06-cc26xx/sensortag/board.c index e397f1266..f2322082a 100644 --- a/platform/srf06-cc26xx/sensortag/board.c +++ b/platform/srf06-cc26xx/sensortag/board.c @@ -48,6 +48,7 @@ #include /*---------------------------------------------------------------------------*/ #define PRCM_DOMAINS (PRCM_DOMAIN_SERIAL | PRCM_DOMAIN_PERIPH) +#include /*---------------------------------------------------------------------------*/ static void power_domains_on(void) @@ -94,7 +95,7 @@ void board_init() { /* Disable global interrupts */ - uint8_t int_disabled = ti_lib_int_master_disable(); + bool int_disabled = ti_lib_int_master_disable(); power_domains_on();