Skip to content

Commit e4b4a2f

Browse files
committed
CM3DS: switch us_ticker HAL to the tick domain
This commit changes the conversion function to do all the calculation inside the HAL in ticks instead of microseconds. The conversion will be done in Mbed OS side. As SystemCoreClock is not a constant, it can not be used to initialise the ticker_info_t structure. Change-Id: I8fd4bf20dc5be8b965aca45f800a631275ccc724 Signed-off-by: Hugues de Valon <[email protected]>
1 parent 17b3cb1 commit e4b4a2f

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/us_ticker.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,37 @@
2323
#include "us_ticker_api.h"
2424
#include "platform_devices.h"
2525

26+
/*
27+
* The CMSDK Ticker counts on 32 bits.
28+
*/
29+
#define CMSDK_TICKER_COUNTER_BITS 32U
30+
2631
/**
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.
2834
*
29-
* \param[in] tick Number of clocks
35+
* \param[in] tick Number of clock ticks
3036
*
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.
3338
*/
3439
static uint32_t convert_tick_to_us(uint32_t tick)
3540
{
36-
return (tick / (SystemCoreClock / SEC_TO_USEC_MULTIPLIER));
41+
/* Work only in the tick domain. */
42+
return tick;
3743
}
3844

3945
/**
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.
4148
*
42-
* \param[in] us Time to convert to clock ticks
49+
* \param[in] us Number of us
4350
*
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.
4652
*/
4753
static uint32_t convert_us_to_tick(uint32_t us)
4854
{
49-
return (us * (SystemCoreClock / SEC_TO_USEC_MULTIPLIER));
55+
/* Work only in the tick domain. */
56+
return us;
5057
}
5158

5259
static const struct tick_cfg_t cfg =
@@ -109,3 +116,18 @@ void TIMER0_IRQHandler(void)
109116
{
110117
cmsdk_ticker_irq_handler(&timer_data);
111118
}
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

Comments
 (0)