|
7 | 7 |
|
8 | 8 | #include <stdbool.h> |
9 | 9 | #include <zephyr/types.h> |
10 | | -#include <stdbool.h> |
11 | 10 | #include <soc.h> |
12 | 11 |
|
13 | 12 | #include "hal/cntr.h" |
@@ -110,7 +109,7 @@ struct ticker_user_op_update { |
110 | 109 | }; |
111 | 110 |
|
112 | 111 | /* User operation data structure for slot_get opcode. Used for passing request |
113 | | - * to get next ticker with slot ticks via ticker_job. Only used by legacy stack |
| 112 | + * to get next ticker with slot ticks via ticker_job |
114 | 113 | */ |
115 | 114 | struct ticker_user_op_slot_get { |
116 | 115 | u8_t *ticker_id; |
@@ -210,6 +209,23 @@ static struct ticker_instance _instance[TICKER_INSTANCE_MAX]; |
210 | 209 | * Static Functions |
211 | 210 | ****************************************************************************/ |
212 | 211 |
|
| 212 | +/** |
| 213 | + * @brief Update elapsed index |
| 214 | + * |
| 215 | + * @param ticks_elapsed_index Pointer to current index |
| 216 | + * |
| 217 | + * @internal |
| 218 | + */ |
| 219 | +static inline void ticker_next_elapsed(u8_t *ticks_elapsed_index) |
| 220 | +{ |
| 221 | + u8_t idx = *ticks_elapsed_index + 1; |
| 222 | + |
| 223 | + if (idx == DOUBLE_BUFFER_SIZE) { |
| 224 | + idx = 0U; |
| 225 | + } |
| 226 | + *ticks_elapsed_index = idx; |
| 227 | +} |
| 228 | + |
213 | 229 | /** |
214 | 230 | * @brief Get ticker expiring in a specific slot |
215 | 231 | * |
@@ -568,13 +584,7 @@ void ticker_worker(void *param) |
568 | 584 |
|
569 | 585 | /* Queue the elapsed ticks */ |
570 | 586 | if (instance->ticks_elapsed_first == instance->ticks_elapsed_last) { |
571 | | - u8_t last; |
572 | | - |
573 | | - last = instance->ticks_elapsed_last + 1; |
574 | | - if (last == DOUBLE_BUFFER_SIZE) { |
575 | | - last = 0U; |
576 | | - } |
577 | | - instance->ticks_elapsed_last = last; |
| 587 | + ticker_next_elapsed(&instance->ticks_elapsed_last); |
578 | 588 | } |
579 | 589 | instance->ticks_elapsed[instance->ticks_elapsed_last] = ticks_expired; |
580 | 590 |
|
@@ -1311,7 +1321,6 @@ static inline void ticker_job_op_inquire(struct ticker_instance *instance, |
1311 | 1321 | uop->params.slot_get.ticks_current, |
1312 | 1322 | uop->params.slot_get.ticks_to_expire); |
1313 | 1323 | /* Fall-through */ |
1314 | | - |
1315 | 1324 | case TICKER_USER_OP_TYPE_IDLE_GET: |
1316 | 1325 | uop->status = TICKER_STATUS_SUCCESS; |
1317 | 1326 | fp_op_func = uop->fp_op_func; |
@@ -1478,13 +1487,7 @@ void ticker_job(void *param) |
1478 | 1487 |
|
1479 | 1488 | /* Update current tick with the elapsed value from queue, and dequeue */ |
1480 | 1489 | if (instance->ticks_elapsed_first != instance->ticks_elapsed_last) { |
1481 | | - u8_t first; |
1482 | | - |
1483 | | - first = instance->ticks_elapsed_first + 1; |
1484 | | - if (first == DOUBLE_BUFFER_SIZE) { |
1485 | | - first = 0U; |
1486 | | - } |
1487 | | - instance->ticks_elapsed_first = first; |
| 1490 | + ticker_next_elapsed(&instance->ticks_elapsed_first); |
1488 | 1491 |
|
1489 | 1492 | ticks_elapsed = |
1490 | 1493 | instance->ticks_elapsed[instance->ticks_elapsed_first]; |
|
0 commit comments