|
|
@ -32,14 +32,43 @@ uint32_t zchip_clock_hasspassed(uint32_t ticket) { |
|
|
|
return UINT32_MAX - ticket + nowticket; |
|
|
|
} |
|
|
|
|
|
|
|
static HAL_StatusTypeDef _HAL_TIM_Base_Start(TIM_HandleTypeDef* htim) __attribute__((optimize("O2"))); |
|
|
|
static HAL_StatusTypeDef _HAL_TIM_Base_Stop(TIM_HandleTypeDef* htim) __attribute__((optimize("O2"))); |
|
|
|
|
|
|
|
static HAL_StatusTypeDef _HAL_TIM_Base_Start(TIM_HandleTypeDef* htim) { |
|
|
|
uint32_t tmpsmcr; |
|
|
|
/* Check the TIM state */ |
|
|
|
if (htim->State != HAL_TIM_STATE_READY) { |
|
|
|
return HAL_ERROR; |
|
|
|
} |
|
|
|
htim->State = HAL_TIM_STATE_BUSY; |
|
|
|
if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) { |
|
|
|
tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
|
|
if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) { |
|
|
|
__HAL_TIM_ENABLE(htim); |
|
|
|
} |
|
|
|
} else { |
|
|
|
__HAL_TIM_ENABLE(htim); |
|
|
|
} |
|
|
|
return HAL_OK; |
|
|
|
} |
|
|
|
static HAL_StatusTypeDef _HAL_TIM_Base_Stop(TIM_HandleTypeDef* htim) { |
|
|
|
/* Disable the Peripheral */ |
|
|
|
__HAL_TIM_DISABLE(htim); |
|
|
|
/* Set the TIM state */ |
|
|
|
htim->State = HAL_TIM_STATE_READY; |
|
|
|
/* Return function status */ |
|
|
|
return HAL_OK; |
|
|
|
} |
|
|
|
|
|
|
|
void __zchip_clock_early_delayus(uint32_t n) { |
|
|
|
volatile uint32_t counter = 0; |
|
|
|
__HAL_TIM_SET_COUNTER(m_usdleaytim, 0); |
|
|
|
HAL_TIM_Base_Start(m_usdleaytim); |
|
|
|
_HAL_TIM_Base_Start(m_usdleaytim); |
|
|
|
while (counter < n) { |
|
|
|
counter = __HAL_TIM_GET_COUNTER(m_usdleaytim); |
|
|
|
} |
|
|
|
HAL_TIM_Base_Stop(m_usdleaytim); |
|
|
|
_HAL_TIM_Base_Stop(m_usdleaytim); |
|
|
|
} |
|
|
|
void zchip_clock_early_delayus(uint32_t n) { |
|
|
|
uint32_t us = n % 1000; |
|
|
@ -56,12 +85,10 @@ void zchip_clock_early_delayus(uint32_t n) { |
|
|
|
void zchip_clock_early_delayus2(uint32_t us) { __zchip_clock_early_delayus(us); } |
|
|
|
void zchip_clock_early_delayus_timer_start() { |
|
|
|
__HAL_TIM_SET_COUNTER(m_usdleaytim, 0); |
|
|
|
HAL_TIM_Base_Start(m_usdleaytim); |
|
|
|
_HAL_TIM_Base_Start(m_usdleaytim); |
|
|
|
} |
|
|
|
uint32_t zchip_clock_early_delayus_timer_haspassed() { |
|
|
|
uint32_t counter = __HAL_TIM_GET_COUNTER(m_usdleaytim); |
|
|
|
return counter; |
|
|
|
} |
|
|
|
void zchip_clock_early_delayus_timer_stop(){ |
|
|
|
HAL_TIM_Base_Stop(m_usdleaytim); |
|
|
|
} |
|
|
|
void zchip_clock_early_delayus_timer_stop() { _HAL_TIM_Base_Stop(m_usdleaytim); } |