HAL_GetTick returns elapsed time

pull/7352/head
bcostm 2018-07-03 10:41:54 +02:00
parent 26cb388d14
commit f785c23e89
2 changed files with 20 additions and 3 deletions

View File

@ -19,6 +19,8 @@
#if TIM_MST_16BIT
extern TIM_HandleTypeDef TimMasterHandle;
extern uint32_t prev_time;
extern uint32_t elapsed_time;
volatile uint32_t PreviousVal = 0;
@ -108,6 +110,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
TIM_MST_DBGMCU_FREEZE;
#endif
// Used by HAL_GetTick()
prev_time = 0;
elapsed_time = 0;
return HAL_OK;
}

View File

@ -21,14 +21,25 @@
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
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()
{
// 1 ms tick is required for ST HAL driver
uint32_t new_time;
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 {
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);
}
}