mirror of https://github.com/ARMmbed/mbed-os.git
HAL_GetTick returns elapsed time
parent
26cb388d14
commit
f785c23e89
|
@ -19,6 +19,8 @@
|
||||||
#if TIM_MST_16BIT
|
#if TIM_MST_16BIT
|
||||||
|
|
||||||
extern TIM_HandleTypeDef TimMasterHandle;
|
extern TIM_HandleTypeDef TimMasterHandle;
|
||||||
|
extern uint32_t prev_time;
|
||||||
|
extern uint32_t elapsed_time;
|
||||||
|
|
||||||
volatile uint32_t PreviousVal = 0;
|
volatile uint32_t PreviousVal = 0;
|
||||||
|
|
||||||
|
@ -108,6 +110,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
TIM_MST_DBGMCU_FREEZE;
|
TIM_MST_DBGMCU_FREEZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Used by HAL_GetTick()
|
||||||
|
prev_time = 0;
|
||||||
|
elapsed_time = 0;
|
||||||
|
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,25 @@
|
||||||
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
|
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
|
||||||
extern int mbed_sdk_inited;
|
extern int mbed_sdk_inited;
|
||||||
|
|
||||||
|
// Variables also reset in HAL_InitTick()
|
||||||
|
uint32_t prev_time = 0;
|
||||||
|
uint32_t elapsed_time = 0;
|
||||||
|
|
||||||
|
// 1 ms tick is required for ST HAL driver
|
||||||
uint32_t HAL_GetTick()
|
uint32_t HAL_GetTick()
|
||||||
{
|
{
|
||||||
// 1 ms tick is required for ST HAL driver
|
uint32_t new_time;
|
||||||
if (mbed_sdk_inited) {
|
if (mbed_sdk_inited) {
|
||||||
return (ticker_read_us(get_us_ticker_data()) / 1000);
|
// Apply the latest time recorded just before the sdk is inited
|
||||||
|
new_time = ticker_read_us(get_us_ticker_data()) + prev_time;
|
||||||
|
prev_time = 0; // Use this time only once
|
||||||
|
return (new_time / 1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return (us_ticker_read() / 1000);
|
new_time = us_ticker_read();
|
||||||
|
elapsed_time += (new_time - prev_time) & 0xFFFF; // Only use the lower 16 bits
|
||||||
|
prev_time = new_time;
|
||||||
|
return (elapsed_time / 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue