Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | /* * Copyright (c) 2016 Nordic Semiconductor ASA * Copyright (c) 2016 Vinayak Kariappa Chettimada * * SPDX-License-Identifier: Apache-2.0 */ #ifndef _TICKER_H_ #define _TICKER_H_ /** \brief Macro to translate microseconds to tick units. * * \note This returns the floor value. */ #define TICKER_US_TO_TICKS(x) \ ( \ ((u32_t)(((u64_t) (x) * 1000000000UL) / 30517578125UL)) \ & 0x00FFFFFF \ ) /** \brief Macro returning remainder in nanoseconds over-and-above a tick unit. */ #define TICKER_REMAINDER(x) \ ( \ ( \ ((u64_t) (x) * 1000000000UL) \ - ((u64_t) TICKER_US_TO_TICKS(x) * 30517578125UL) \ ) \ / 1000UL \ ) /** \brief Macro to translate tick units to microseconds. */ #define TICKER_TICKS_TO_US(x) \ ((u32_t)(((u64_t) (x) * 30517578125UL) / 1000000000UL)) /** \defgroup Timer API return codes. * * @{ */ #define TICKER_STATUS_SUCCESS 0 /**< Success. */ #define TICKER_STATUS_FAILURE 1 /**< Failure. */ #define TICKER_STATUS_BUSY 2 /**< Busy, requested feature will * complete later in time as job is * disabled or at lower execution * priority than the caller. */ /** * @} */ /** \defgroup Timer API common defaults parameter values. * * @{ */ #define TICKER_NULL ((u8_t)((u8_t)0 - 1)) #define TICKER_NULL_REMAINDER 0 #define TICKER_NULL_PERIOD 0 #define TICKER_NULL_SLOT 0 #define TICKER_NULL_LAZY 0 /** * @} */ /** \brief Timer node type size. */ #define TICKER_NODE_T_SIZE 36 /** \brief Timer user type size. */ #define TICKER_USER_T_SIZE 8 /** \brief Timer user operation type size. */ #define TICKER_USER_OP_T_SIZE 44 /** \brief Timer timeout function type. */ typedef void (*ticker_timeout_func) (u32_t ticks_at_expire, u32_t remainder, u16_t lazy, void *context); /** \brief Timer operation complete function type. */ typedef void (*ticker_op_func) (u32_t status, void *op_context); /** \brief Timer module initialization. * * \param[in] instance_index Timer mode instance 0 or 1 (uses RTC0 CMP0 or * CMP1 respectively). * \param[in] count_node Max. no. of ticker nodes to initialize. * \param[in] node * \param[in] count_user * \param[in] user * \param[in] count_op * \param[in] user_op */ u32_t ticker_init(u8_t instance_index, u8_t count_node, void *node, u8_t count_user, void *user, u8_t count_op, void *user_op); bool ticker_is_initialized(u8_t instance_index); void ticker_trigger(u8_t instance_index); u32_t ticker_start(u8_t instance_index, u8_t user_id, u8_t ticker_id, u32_t ticks_anchor, u32_t ticks_first, u32_t ticks_periodic, u32_t remainder_periodic, u16_t lazy, u16_t ticks_slot, ticker_timeout_func ticker_timeout_func, void *context, ticker_op_func fp_op_func, void *op_context); u32_t ticker_update(u8_t instance_index, u8_t user_id, u8_t ticker_id, u16_t ticks_drift_plus, u16_t ticks_drift_minus, u16_t ticks_slot_plus, u16_t ticks_slot_minus, u16_t lazy, u8_t force, ticker_op_func fp_op_func, void *op_context); u32_t ticker_stop(u8_t instance_index, u8_t user_id, u8_t ticker_id, ticker_op_func fp_op_func, void *op_context); u32_t ticker_next_slot_get(u8_t instance_index, u8_t user_id, u8_t *ticker_id_head, u32_t *ticks_current, u32_t *ticks_to_expire, ticker_op_func fp_op_func, void *op_context); u32_t ticker_job_idle_get(u8_t instance_index, u8_t user_id, ticker_op_func fp_op_func, void *op_context); void ticker_job_sched(u8_t instance_index, u8_t user_id); u32_t ticker_ticks_now_get(void); u32_t ticker_ticks_diff_get(u32_t ticks_now, u32_t ticks_old); #endif |