Skip to content

Commit 4596e15

Browse files
mtpr-otaescolar
authored andcommitted
bluetooth: controller: Minor refactoring in ticker.c
Moved duplicate code to function. Removed superfluous include. Signed-off-by: Morten Priess <[email protected]>
1 parent 21ae705 commit 4596e15

File tree

1 file changed

+20
-17
lines changed
  • subsys/bluetooth/controller/ticker

1 file changed

+20
-17
lines changed

subsys/bluetooth/controller/ticker/ticker.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <stdbool.h>
99
#include <zephyr/types.h>
10-
#include <stdbool.h>
1110
#include <soc.h>
1211

1312
#include "hal/cntr.h"
@@ -110,7 +109,7 @@ struct ticker_user_op_update {
110109
};
111110

112111
/* 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
114113
*/
115114
struct ticker_user_op_slot_get {
116115
u8_t *ticker_id;
@@ -210,6 +209,23 @@ static struct ticker_instance _instance[TICKER_INSTANCE_MAX];
210209
* Static Functions
211210
****************************************************************************/
212211

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+
213229
/**
214230
* @brief Get ticker expiring in a specific slot
215231
*
@@ -568,13 +584,7 @@ void ticker_worker(void *param)
568584

569585
/* Queue the elapsed ticks */
570586
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);
578588
}
579589
instance->ticks_elapsed[instance->ticks_elapsed_last] = ticks_expired;
580590

@@ -1311,7 +1321,6 @@ static inline void ticker_job_op_inquire(struct ticker_instance *instance,
13111321
uop->params.slot_get.ticks_current,
13121322
uop->params.slot_get.ticks_to_expire);
13131323
/* Fall-through */
1314-
13151324
case TICKER_USER_OP_TYPE_IDLE_GET:
13161325
uop->status = TICKER_STATUS_SUCCESS;
13171326
fp_op_func = uop->fp_op_func;
@@ -1478,13 +1487,7 @@ void ticker_job(void *param)
14781487

14791488
/* Update current tick with the elapsed value from queue, and dequeue */
14801489
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);
14881491

14891492
ticks_elapsed =
14901493
instance->ticks_elapsed[instance->ticks_elapsed_first];

0 commit comments

Comments
 (0)