Skip to content

Commit

Permalink
Merge pull request #1806 from c1728p9/dev_critical_use
Browse files Browse the repository at this point in the history
Use critical section helper in HAL
  • Loading branch information
sg- committed May 28, 2016
2 parents 3055b28 + 4422884 commit d2fd820
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions hal/common/rtc_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "rtc_api.h"

#include <time.h>
#include "critical.h"
#include "rtc_time.h"
#include "us_ticker_api.h"

Expand Down Expand Up @@ -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)) {
__disable_irq();
core_util_critical_section_enter();
_rtc_read = read_rtc;
_rtc_write = write_rtc;
_rtc_init = init_rtc;
_rtc_isenabled = isenabled_rtc;
__enable_irq();
core_util_critical_section_exit();
}


Expand Down
14 changes: 7 additions & 7 deletions hal/common/ticker_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
#include <stddef.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) {
data->interface->init();
Expand Down Expand Up @@ -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) {
/* disable interrupts for the duration of the function */
__disable_irq();
core_util_critical_section_enter();

// initialise our data
obj->timestamp = timestamp;
Expand Down Expand Up @@ -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 */
obj->next = p;

__enable_irq();
core_util_critical_section_exit();
}

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
if (data->queue->head == obj) {
Expand All @@ -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)
Expand All @@ -124,12 +124,12 @@ int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *time
int ret = 0;

/* if head is NULL, there are no pending events */
__disable_irq();
core_util_critical_section_enter();
if (data->queue->head != NULL) {
*timestamp = data->queue->head->timestamp;
ret = 1;
}
__enable_irq();
core_util_critical_section_exit();

return ret;
}

0 comments on commit d2fd820

Please sign in to comment.