|
23 | 23 | #include "us_ticker_api.h"
|
24 | 24 | #include "platform_devices.h"
|
25 | 25 |
|
| 26 | +/* |
| 27 | + * The CMSDK Ticker counts on 32 bits. |
| 28 | + */ |
| 29 | +#define CMSDK_TICKER_COUNTER_BITS 32U |
| 30 | + |
26 | 31 | /**
|
27 |
| - * \brief Convert clocks to us |
| 32 | + * \brief Pass-through function to make the US ticker HAL only work in the tick |
| 33 | + * domain. This function is needed by the CMSDK Ticker layer. |
28 | 34 | *
|
29 |
| - * \param[in] tick Number of clocks |
| 35 | + * \param[in] tick Number of clock ticks |
30 | 36 | *
|
31 |
| - * \return Number of usec, relative to the timer frequency, |
32 |
| - * that a given ammount of ticks equates to. |
| 37 | + * \return The number of ticks given. |
33 | 38 | */
|
34 | 39 | static uint32_t convert_tick_to_us(uint32_t tick)
|
35 | 40 | {
|
36 |
| - return (tick / (SystemCoreClock / SEC_TO_USEC_MULTIPLIER)); |
| 41 | + /* Work only in the tick domain. */ |
| 42 | + return tick; |
37 | 43 | }
|
38 | 44 |
|
39 | 45 | /**
|
40 |
| - * \brief Convert us to clock ticks |
| 46 | + * \brief Pass-through function to make the US ticker HAL only work in the tick |
| 47 | + * domain. This function is needed by the CMSDK Ticker layer. |
41 | 48 | *
|
42 |
| - * \param[in] us Time to convert to clock ticks |
| 49 | + * \param[in] us Number of us |
43 | 50 | *
|
44 |
| - * \return Number of clock ticks relative to the timer frequency, |
45 |
| - * that a given period of usec equates to. |
| 51 | + * \return The number of us given. |
46 | 52 | */
|
47 | 53 | static uint32_t convert_us_to_tick(uint32_t us)
|
48 | 54 | {
|
49 |
| - return (us * (SystemCoreClock / SEC_TO_USEC_MULTIPLIER)); |
| 55 | + /* Work only in the tick domain. */ |
| 56 | + return us; |
50 | 57 | }
|
51 | 58 |
|
52 | 59 | static const struct tick_cfg_t cfg =
|
@@ -109,3 +116,18 @@ void TIMER0_IRQHandler(void)
|
109 | 116 | {
|
110 | 117 | cmsdk_ticker_irq_handler(&timer_data);
|
111 | 118 | }
|
| 119 | + |
| 120 | +const ticker_info_t* us_ticker_get_info(void) |
| 121 | +{ |
| 122 | + static ticker_info_t us_ticker_info = { |
| 123 | + .bits = CMSDK_TICKER_COUNTER_BITS |
| 124 | + }; |
| 125 | + |
| 126 | + /* |
| 127 | + * SystemCoreClock is not a constant so it cannot be used to initialize the |
| 128 | + * ticker_info_t structure. |
| 129 | + */ |
| 130 | + us_ticker_info.frequency = SystemCoreClock; |
| 131 | + |
| 132 | + return &us_ticker_info; |
| 133 | +} |
0 commit comments