mirror of https://github.com/ARMmbed/mbed-os.git
Add initialization of timer instance in all functions
parent
6baec10d29
commit
cc24e5b7f9
|
@ -44,6 +44,7 @@ volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_h
|
|||
|
||||
void set_compare(uint16_t count)
|
||||
{
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
|
||||
// Enable IT
|
||||
|
@ -64,6 +65,8 @@ uint32_t us_ticker_read()
|
|||
{
|
||||
uint32_t counter;
|
||||
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
|
||||
if (!us_ticker_inited) us_ticker_init();
|
||||
|
||||
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
|
||||
|
@ -106,6 +109,7 @@ uint32_t us_ticker_read()
|
|||
void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||
{
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
@ -125,11 +129,13 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
{
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
||||
void us_ticker_clear_interrupt(void)
|
||||
{
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
|
||||
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
|
||||
}
|
||||
|
|
|
@ -51,22 +51,20 @@ uint32_t us_ticker_read() {
|
|||
}
|
||||
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
// Set new output compare value
|
||||
// TODO: Check if still true
|
||||
#if defined(TARGET_L4)
|
||||
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
#else
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
#endif
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void) {
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
||||
void us_ticker_clear_interrupt(void) {
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue