Skip to content

Commit 3c08e7b

Browse files
committed
Merge pull request #72 from ARMmbed/enable_irq
Restore IRQ status on exit; don't always enable
2 parents c24e3e4 + 6401161 commit 3c08e7b

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

hal/common/rtc_time.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "rtc_api.h"
1717

1818
#include <time.h>
19+
#include "critical.h"
1920
#include "rtc_time.h"
2021
#include "us_ticker_api.h"
2122

@@ -74,12 +75,12 @@ clock_t clock() {
7475
}
7576

7677
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
77-
__disable_irq();
78+
core_util_critical_section_enter();
7879
_rtc_read = read_rtc;
7980
_rtc_write = write_rtc;
8081
_rtc_init = init_rtc;
8182
_rtc_isenabled = isenabled_rtc;
82-
__enable_irq();
83+
core_util_critical_section_exit();
8384
}
8485

8586

hal/common/ticker_api.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
#include <stddef.h>
1717
#include "ticker_api.h"
18-
#include "cmsis.h"
18+
#include "critical.h"
1919

2020
void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) {
2121
data->interface->init();
@@ -55,7 +55,7 @@ void ticker_irq_handler(const ticker_data_t *const data) {
5555

5656
void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
5757
/* disable interrupts for the duration of the function */
58-
__disable_irq();
58+
core_util_critical_section_enter();
5959

6060
// initialise our data
6161
obj->timestamp = timestamp;
@@ -84,11 +84,11 @@ void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, t
8484
/* if we're at the end p will be NULL, which is correct */
8585
obj->next = p;
8686

87-
__enable_irq();
87+
core_util_critical_section_exit();
8888
}
8989

9090
void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) {
91-
__disable_irq();
91+
core_util_critical_section_enter();
9292

9393
// remove this object from the list
9494
if (data->queue->head == obj) {
@@ -111,7 +111,7 @@ void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) {
111111
}
112112
}
113113

114-
__enable_irq();
114+
core_util_critical_section_exit();
115115
}
116116

117117
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
124124
int ret = 0;
125125

126126
/* if head is NULL, there are no pending events */
127-
__disable_irq();
127+
core_util_critical_section_enter();
128128
if (data->queue->head != NULL) {
129129
*timestamp = data->queue->head->timestamp;
130130
ret = 1;
131131
}
132-
__enable_irq();
132+
core_util_critical_section_exit();
133133

134134
return ret;
135135
}

0 commit comments

Comments
 (0)