Skip to content

Use critical section helper in HAL #1806

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

Merged
merged 1 commit into from
May 28, 2016
Merged
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
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;
}