mirror of https://github.com/ARMmbed/mbed-os.git
Align HAL & US tickers
parent
953b9250f1
commit
4fe8e8ca44
|
|
@ -161,15 +161,15 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void HAL_SuspendTick(void)
|
void HAL_SuspendTick(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void HAL_ResumeTick(void)
|
void HAL_ResumeTick(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,15 +131,15 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void HAL_SuspendTick(void)
|
void HAL_SuspendTick(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void HAL_ResumeTick(void)
|
void HAL_ResumeTick(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,22 +26,13 @@ TIM_HandleTypeDef TimMasterHandle;
|
||||||
volatile uint32_t SlaveCounter = 0;
|
volatile uint32_t SlaveCounter = 0;
|
||||||
volatile uint32_t oc_int_part = 0;
|
volatile uint32_t oc_int_part = 0;
|
||||||
|
|
||||||
static int us_ticker_inited = 0;
|
|
||||||
|
|
||||||
void us_ticker_init(void)
|
void us_ticker_init(void)
|
||||||
{
|
{
|
||||||
if (us_ticker_inited) return;
|
/* NOTE: assuming that HAL tick has already been initialized! */
|
||||||
us_ticker_inited = 1;
|
|
||||||
|
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
|
|
||||||
HAL_InitTick(0); // The passed value is not used
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t us_ticker_read()
|
uint32_t us_ticker_read()
|
||||||
{
|
{
|
||||||
if (!us_ticker_inited) us_ticker_init();
|
|
||||||
|
|
||||||
uint16_t cntH_old, cntH, cntL;
|
uint16_t cntH_old, cntH, cntL;
|
||||||
do {
|
do {
|
||||||
cntH_old = SlaveCounter;
|
cntH_old = SlaveCounter;
|
||||||
|
|
@ -73,7 +64,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||||
{
|
{
|
||||||
// NOTE: This function must be called with interrupts disabled to keep our
|
// NOTE: This function must be called with interrupts disabled to keep our
|
||||||
// timer interrupt setup atomic
|
// timer interrupt setup atomic
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
// Set new output compare value
|
// Set new output compare value
|
||||||
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, timestamp & 0xFFFF);
|
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, timestamp & 0xFFFF);
|
||||||
// Ensure the compare event starts clear
|
// Ensure the compare event starts clear
|
||||||
|
|
@ -178,19 +169,18 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||||
|
|
||||||
void us_ticker_fire_interrupt(void)
|
void us_ticker_fire_interrupt(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
HAL_TIM_GenerateEvent(&TimMasterHandle, TIM_EVENTSOURCE_CC1);
|
HAL_TIM_GenerateEvent(&TimMasterHandle, TIM_EVENTSOURCE_CC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void us_ticker_disable_interrupt(void)
|
void us_ticker_disable_interrupt(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void us_ticker_clear_interrupt(void)
|
void us_ticker_clear_interrupt(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
|
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,27 +23,21 @@
|
||||||
|
|
||||||
TIM_HandleTypeDef TimMasterHandle;
|
TIM_HandleTypeDef TimMasterHandle;
|
||||||
|
|
||||||
static int us_ticker_inited = 0;
|
|
||||||
|
|
||||||
void us_ticker_init(void)
|
void us_ticker_init(void)
|
||||||
{
|
{
|
||||||
if (us_ticker_inited) return;
|
/* NOTE: assuming that HAL tick has already been initialized! */
|
||||||
us_ticker_inited = 1;
|
|
||||||
|
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
|
|
||||||
HAL_InitTick(0); // The passed value is not used
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t us_ticker_read()
|
uint32_t us_ticker_read()
|
||||||
{
|
{
|
||||||
if (!us_ticker_inited) us_ticker_init();
|
|
||||||
return TIM_MST->CNT;
|
return TIM_MST->CNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void us_ticker_set_interrupt(timestamp_t timestamp)
|
void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
// NOTE: This function must be called with interrupts disabled to keep our
|
||||||
|
// timer interrupt setup atomic
|
||||||
|
|
||||||
// disable IT while we are handling the correct timestamp
|
// disable IT while we are handling the correct timestamp
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||||
// Set new output compare value
|
// Set new output compare value
|
||||||
|
|
@ -57,16 +51,16 @@ void us_ticker_fire_interrupt(void)
|
||||||
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
|
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void us_ticker_disable_interrupt(void)
|
void us_ticker_disable_interrupt(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: must be called with interrupts disabled! */
|
||||||
void us_ticker_clear_interrupt(void)
|
void us_ticker_clear_interrupt(void)
|
||||||
{
|
{
|
||||||
TimMasterHandle.Instance = TIM_MST;
|
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
|
||||||
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !TIM_MST_16BIT
|
#endif // !TIM_MST_16BIT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue