Skip to content

Commit

Permalink
bluetooth: controller: Minor refactoring in ticker.c
Browse files Browse the repository at this point in the history
Moved duplicate code to function. Removed superfluous include.

Signed-off-by: Morten Priess <mtpr@oticon.com>
  • Loading branch information
mtpr-ot authored and aescolar committed Apr 30, 2019
1 parent 21ae705 commit 4596e15
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions subsys/bluetooth/controller/ticker/ticker.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


#include <stdbool.h> #include <stdbool.h>
#include <zephyr/types.h> #include <zephyr/types.h>
#include <stdbool.h>
#include <soc.h> #include <soc.h>


#include "hal/cntr.h" #include "hal/cntr.h"
Expand Down Expand Up @@ -110,7 +109,7 @@ struct ticker_user_op_update {
}; };


/* User operation data structure for slot_get opcode. Used for passing request /* User operation data structure for slot_get opcode. Used for passing request
* to get next ticker with slot ticks via ticker_job. Only used by legacy stack * to get next ticker with slot ticks via ticker_job
*/ */
struct ticker_user_op_slot_get { struct ticker_user_op_slot_get {
u8_t *ticker_id; u8_t *ticker_id;
Expand Down Expand Up @@ -210,6 +209,23 @@ static struct ticker_instance _instance[TICKER_INSTANCE_MAX];
* Static Functions * Static Functions
****************************************************************************/ ****************************************************************************/


/**
* @brief Update elapsed index
*
* @param ticks_elapsed_index Pointer to current index
*
* @internal
*/
static inline void ticker_next_elapsed(u8_t *ticks_elapsed_index)
{
u8_t idx = *ticks_elapsed_index + 1;

if (idx == DOUBLE_BUFFER_SIZE) {
idx = 0U;
}
*ticks_elapsed_index = idx;
}

/** /**
* @brief Get ticker expiring in a specific slot * @brief Get ticker expiring in a specific slot
* *
Expand Down Expand Up @@ -568,13 +584,7 @@ void ticker_worker(void *param)


/* Queue the elapsed ticks */ /* Queue the elapsed ticks */
if (instance->ticks_elapsed_first == instance->ticks_elapsed_last) { if (instance->ticks_elapsed_first == instance->ticks_elapsed_last) {
u8_t last; ticker_next_elapsed(&instance->ticks_elapsed_last);

last = instance->ticks_elapsed_last + 1;
if (last == DOUBLE_BUFFER_SIZE) {
last = 0U;
}
instance->ticks_elapsed_last = last;
} }
instance->ticks_elapsed[instance->ticks_elapsed_last] = ticks_expired; instance->ticks_elapsed[instance->ticks_elapsed_last] = ticks_expired;


Expand Down Expand Up @@ -1311,7 +1321,6 @@ static inline void ticker_job_op_inquire(struct ticker_instance *instance,
uop->params.slot_get.ticks_current, uop->params.slot_get.ticks_current,
uop->params.slot_get.ticks_to_expire); uop->params.slot_get.ticks_to_expire);
/* Fall-through */ /* Fall-through */

case TICKER_USER_OP_TYPE_IDLE_GET: case TICKER_USER_OP_TYPE_IDLE_GET:
uop->status = TICKER_STATUS_SUCCESS; uop->status = TICKER_STATUS_SUCCESS;
fp_op_func = uop->fp_op_func; fp_op_func = uop->fp_op_func;
Expand Down Expand Up @@ -1478,13 +1487,7 @@ void ticker_job(void *param)


/* Update current tick with the elapsed value from queue, and dequeue */ /* Update current tick with the elapsed value from queue, and dequeue */
if (instance->ticks_elapsed_first != instance->ticks_elapsed_last) { if (instance->ticks_elapsed_first != instance->ticks_elapsed_last) {
u8_t first; ticker_next_elapsed(&instance->ticks_elapsed_first);

first = instance->ticks_elapsed_first + 1;
if (first == DOUBLE_BUFFER_SIZE) {
first = 0U;
}
instance->ticks_elapsed_first = first;


ticks_elapsed = ticks_elapsed =
instance->ticks_elapsed[instance->ticks_elapsed_first]; instance->ticks_elapsed[instance->ticks_elapsed_first];
Expand Down

0 comments on commit 4596e15

Please sign in to comment.