Fix global interrupt manipulation

This commit is contained in:
George Oikonomou 2015-05-01 16:15:33 +01:00
parent bd79e18e1e
commit 5644e95fb6
3 changed files with 56 additions and 19 deletions

View file

@ -69,6 +69,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define BUSYWAIT_UNTIL(cond, max_time) \ #define BUSYWAIT_UNTIL(cond, max_time) \
do { \ do { \
@ -431,16 +432,19 @@ static uint_fast8_t
rf_send_cmd(uint32_t cmd, uint32_t *status) rf_send_cmd(uint32_t cmd, uint32_t *status)
{ {
uint32_t timeout_count = 0; uint32_t timeout_count = 0;
bool interrupts_disabled;
/* /*
* Make sure ContikiMAC doesn't turn us off from within an interrupt while * Make sure ContikiMAC doesn't turn us off from within an interrupt while
* we are accessing RF Core registers * we are accessing RF Core registers
*/ */
ti_lib_int_master_disable(); interrupts_disabled = ti_lib_int_master_disable();
if(!rf_is_accessible()) { if(!rf_is_accessible()) {
PRINTF("rf_send_cmd: RF was off\n"); 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; 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); *status = HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA);
if(++timeout_count > 50000) { if(++timeout_count > 50000) {
PRINTF("rf_send_cmd: Timeout\n"); PRINTF("rf_send_cmd: Timeout\n");
ti_lib_int_master_enable(); if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
return RF_CMD_ERROR; return RF_CMD_ERROR;
} }
} while(*status == RF_CMD_STATUS_PENDING); } 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 * If we reach here the command is no longer pending. It is either completed
@ -911,8 +919,8 @@ static int
power_up(void) power_up(void)
{ {
uint32_t cmd_status; 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_CPE0);
ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_pend_clear(INT_RF_CPE1);
ti_lib_int_disable(INT_RF_CPE0); ti_lib_int_disable(INT_RF_CPE0);
@ -935,7 +943,10 @@ power_up(void)
HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = 0x0; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = 0x0;
ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE0);
ti_lib_int_enable(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE1);
ti_lib_int_master_enable();
if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
/* Let CPE boot */ /* Let CPE boot */
HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = RF_CORE_CLOCKS_MASK; HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = RF_CORE_CLOCKS_MASK;
@ -955,7 +966,7 @@ power_up(void)
static void static void
power_down(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_CPE0);
ti_lib_int_disable(INT_RF_CPE1); 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_pend_clear(INT_RF_CPE1);
ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE0);
ti_lib_int_enable(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE1);
ti_lib_int_master_enable(); if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
@ -1093,6 +1106,8 @@ cc26xx_rf_cpe0_isr(void)
static void static void
setup_interrupts(void) setup_interrupts(void)
{ {
bool interrupts_disabled;
/* We are already turned on by the caller, so this should not happen */ /* We are already turned on by the caller, so this should not happen */
if(!rf_is_accessible()) { if(!rf_is_accessible()) {
PRINTF("setup_interrupts: No access\n"); PRINTF("setup_interrupts: No access\n");
@ -1100,7 +1115,7 @@ setup_interrupts(void)
} }
/* Disable interrupts */ /* Disable interrupts */
ti_lib_int_master_disable(); interrupts_disabled = ti_lib_int_master_disable();
/* Set all interrupt channels to CPE0 channel, error to CPE1 */ /* Set all interrupt channels to CPE0 channel, error to CPE1 */
HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEISL) = ERROR_IRQ; 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_pend_clear(INT_RF_CPE1);
ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE0);
ti_lib_int_enable(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE1);
ti_lib_int_master_enable();
if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static uint8_t static uint8_t
@ -1926,6 +1944,7 @@ PROCESS_THREAD(cc26xx_rf_ble_beacon_process, ev, data)
uint8_t was_on; uint8_t was_on;
int j; int j;
uint32_t cmd_status; uint32_t cmd_status;
bool interrupts_disabled;
PROCESS_BEGIN(); 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 * Under ContikiMAC, some IEEE-related operations will be called from an
* interrupt context. We need those to see that we are in BLE mode. * 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; 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 * 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); 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; ble_mode_on = 0;
ti_lib_int_master_enable();
if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
/* Wait unless this is the last burst */ /* Wait unless this is the last burst */
if(i < BLE_ADV_MESSAGES - 1) { 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; ble_mode_on = 0;
ti_lib_int_master_enable();
if(!interrupts_disabled) {
ti_lib_int_master_enable();
}
} }
PROCESS_END(); PROCESS_END();
} }

View file

@ -44,6 +44,7 @@
#include "ti-lib.h" #include "ti-lib.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define cc26xx_rtc_isr(...) AONRTCIntHandler(__VA_ARGS__) #define cc26xx_rtc_isr(...) AONRTCIntHandler(__VA_ARGS__)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -54,9 +55,11 @@ void
cc26xx_rtc_init(void) cc26xx_rtc_init(void)
{ {
uint32_t compare_value; uint32_t compare_value;
bool interrupts_disabled;
/* Disable and clear interrupts */ /* 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_disable();
ti_lib_aon_rtc_event_clear(AON_RTC_CH0); ti_lib_aon_rtc_event_clear(AON_RTC_CH0);
@ -80,7 +83,11 @@ cc26xx_rtc_init(void)
ti_lib_aon_rtc_enable(); ti_lib_aon_rtc_enable();
ti_lib_int_enable(INT_AON_RTC); 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 rtimer_clock_t

View file

@ -48,6 +48,7 @@
#include <string.h> #include <string.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PRCM_DOMAINS (PRCM_DOMAIN_SERIAL | PRCM_DOMAIN_PERIPH) #define PRCM_DOMAINS (PRCM_DOMAIN_SERIAL | PRCM_DOMAIN_PERIPH)
#include <stdbool.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
power_domains_on(void) power_domains_on(void)
@ -94,7 +95,7 @@ void
board_init() board_init()
{ {
/* Disable global interrupts */ /* Disable global interrupts */
uint8_t int_disabled = ti_lib_int_master_disable(); bool int_disabled = ti_lib_int_master_disable();
power_domains_on(); power_domains_on();