Use critical section helper in HAL

Routines using __disable_irq and __enable_irq had the effect of
enabling interrupts if called with interrupts disabled.

Some versions of __disable_irq do not return old status to restore it.

Change to use the critical section helper functions instead.
pull/1806/head
Kevin Bracey 2016-05-18 14:50:31 +03:00 committed by Russ Butler
parent a7ff058fb2
commit 4422884c16
2 changed files with 10 additions and 9 deletions

View File

@ -16,6 +16,7 @@
#include "rtc_api.h" #include "rtc_api.h"
#include <time.h> #include <time.h>
#include "critical.h"
#include "rtc_time.h" #include "rtc_time.h"
#include "us_ticker_api.h" #include "us_ticker_api.h"
@ -74,12 +75,12 @@ clock_t clock() {
} }
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) { void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
__disable_irq(); core_util_critical_section_enter();
_rtc_read = read_rtc; _rtc_read = read_rtc;
_rtc_write = write_rtc; _rtc_write = write_rtc;
_rtc_init = init_rtc; _rtc_init = init_rtc;
_rtc_isenabled = isenabled_rtc; _rtc_isenabled = isenabled_rtc;
__enable_irq(); core_util_critical_section_exit();
} }

View File

@ -15,7 +15,7 @@
*/ */
#include <stddef.h> #include <stddef.h>
#include "ticker_api.h" #include "ticker_api.h"
#include "cmsis.h" #include "critical.h"
void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) { void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) {
data->interface->init(); data->interface->init();
@ -55,7 +55,7 @@ void ticker_irq_handler(const ticker_data_t *const data) {
void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id) { void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
/* disable interrupts for the duration of the function */ /* disable interrupts for the duration of the function */
__disable_irq(); core_util_critical_section_enter();
// initialise our data // initialise our data
obj->timestamp = timestamp; obj->timestamp = timestamp;
@ -84,11 +84,11 @@ void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, t
/* if we're at the end p will be NULL, which is correct */ /* if we're at the end p will be NULL, which is correct */
obj->next = p; obj->next = p;
__enable_irq(); core_util_critical_section_exit();
} }
void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) { void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) {
__disable_irq(); core_util_critical_section_enter();
// remove this object from the list // remove this object from the list
if (data->queue->head == obj) { if (data->queue->head == obj) {
@ -111,7 +111,7 @@ void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) {
} }
} }
__enable_irq(); core_util_critical_section_exit();
} }
timestamp_t ticker_read(const ticker_data_t *const data) timestamp_t ticker_read(const ticker_data_t *const data)
@ -124,12 +124,12 @@ int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *time
int ret = 0; int ret = 0;
/* if head is NULL, there are no pending events */ /* if head is NULL, there are no pending events */
__disable_irq(); core_util_critical_section_enter();
if (data->queue->head != NULL) { if (data->queue->head != NULL) {
*timestamp = data->queue->head->timestamp; *timestamp = data->queue->head->timestamp;
ret = 1; ret = 1;
} }
__enable_irq(); core_util_critical_section_exit();
return ret; return ret;
} }