Skip to content

Commit fba7162

Browse files
authored
Merge pull request #5 from soburi/zephyr_timer_modification
Adapting the hardware_timer API to Zephyr
2 parents b7801e4 + 852bc44 commit fba7162

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

ChangeLog.zephyr.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Need to take care to not break these changes when updating pico-sdk.
44

55
## Patch List:
6+
- [#7] pico-sdk: hardware_timer: Don't add irq handler to interrupt vector
7+
- src/rp2_common/hardware_timer/timer.c
8+
- [#6] pico-sdk: hardware_timer: Add argument to irq handler to handle userdata
9+
- src/rp2_common/hardware_timer/include/hardware/timer.h
10+
- src/rp2_common/hardware_timer/timer.c
611
- [#5] pico-sdk: Rename is_irq_enabled() to pico_is_irq_enabled()
712
- src/rp2_common/hardware_irq/include/hardware/irq.h
813
- src/rp2_common/hardware_irq/irq.c

src/rp2_common/hardware_timer/include/hardware/timer.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ static inline bool time_reached(absolute_time_t t) {
121121
/*! Callback function type for hardware alarms
122122
* \ingroup hardware_timer
123123
*
124+
* Modification on the porting to Zephyr:
125+
* Add parameter argument to enable referencing user data
126+
*
124127
* \param alarm_num the hardware alarm number
125128
* \sa hardware_alarm_set_callback()
126129
*/
127-
typedef void (*hardware_alarm_callback_t)(uint alarm_num);
130+
typedef void (*hardware_alarm_callback_t)(uint alarm_num, void *data);
128131

129132
/*! \brief cooperatively claim the use of this hardware alarm_num
130133
* \ingroup hardware_timer
@@ -214,6 +217,13 @@ void hardware_alarm_cancel(uint alarm_num);
214217
* @param alarm_num the hardware alarm number
215218
*/
216219
void hardware_alarm_force_irq(uint alarm_num);
220+
221+
/**
222+
* Modification on the porting to Zephyr:
223+
* Publish as API.
224+
* Add parameter argument to enable referencing user data
225+
*/
226+
void hardware_alarm_irq_handler(void *dev);
217227
#ifdef __cplusplus
218228
}
219229
#endif

src/rp2_common/hardware_timer/timer.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ static inline uint harware_alarm_irq_number(uint alarm_num) {
110110
return TIMER_IRQ_0 + alarm_num;
111111
}
112112

113-
static void hardware_alarm_irq_handler(void) {
113+
/**
114+
* Modification on the porting to Zephyr:
115+
* Add parameter argument to enable referencing user data
116+
* Publish as API.
117+
*/
118+
void hardware_alarm_irq_handler(void* data) {
114119
// Determine which timer this IRQ is for
115120
uint alarm_num = __get_current_exception() - VTABLE_FIRST_IRQ - TIMER_IRQ_0;
116121
check_hardware_alarm_num_param(alarm_num);
@@ -141,33 +146,27 @@ static void hardware_alarm_irq_handler(void) {
141146
spin_unlock(lock, save);
142147

143148
if (callback) {
144-
callback(alarm_num);
149+
callback(alarm_num, data);
145150
}
146151
}
147152

153+
/**
154+
* Modification on the porting to Zephyr:
155+
* Don't add irq handler to interrupt vector in this function.
156+
*/
148157
void hardware_alarm_set_callback(uint alarm_num, hardware_alarm_callback_t callback) {
149158
// todo check current core owner
150159
// note this should probably be subsumed by irq_set_exclusive_handler anyway, since that
151160
// should disallow IRQ handlers on both cores
152161
check_hardware_alarm_num_param(alarm_num);
153-
uint irq_num = harware_alarm_irq_number(alarm_num);
154162
spin_lock_t *lock = spin_lock_instance(PICO_SPINLOCK_ID_TIMER);
155163
uint32_t save = spin_lock_blocking(lock);
156164
if (callback) {
157-
if (hardware_alarm_irq_handler != irq_get_vtable_handler(irq_num)) {
158-
// note that set_exclusive will silently allow you to set the handler to the same thing
159-
// since it is idempotent, which means we don't need to worry about locking ourselves
160-
irq_set_exclusive_handler(irq_num, hardware_alarm_irq_handler);
161-
irq_set_enabled(irq_num, true);
162-
// Enable interrupt in block and at processor
163-
hw_set_bits(&timer_hw->inte, 1u << alarm_num);
164-
}
165+
hw_set_bits(&timer_hw->inte, 1u << alarm_num);
165166
alarm_callbacks[alarm_num] = callback;
166167
} else {
167168
alarm_callbacks[alarm_num] = NULL;
168169
timer_callbacks_pending &= (uint8_t)~(1u << alarm_num);
169-
irq_remove_handler(irq_num, hardware_alarm_irq_handler);
170-
irq_set_enabled(irq_num, false);
171170
}
172171
spin_unlock(lock, save);
173172
}

0 commit comments

Comments
 (0)