1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

clraify the tricky loop in lv_tick_get

This commit is contained in:
Gabor Kiss-Vamosi 2020-06-26 14:35:30 +02:00
parent 274d0b522d
commit 6056bc3b95

View File

@ -29,7 +29,7 @@
* STATIC VARIABLES
**********************/
static uint32_t sys_time = 0;
static volatile uint8_t tick_irq_flag;
static volatile uint32_t tick_irq_flag;
/**********************
* MACROS
@ -56,12 +56,17 @@ LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)
uint32_t lv_tick_get(void)
{
#if LV_TICK_CUSTOM == 0
/* If `lv_tick_inc` is called from an interrupt while `sys_time` is read
* the result might be corrupted.
* This loop detects if `lv_tick_inc` was called while reading `sys_time`.
* If `tick_irq_flag` was cleared in `lv_tick_inc` try to read again
* until `tick_irq_flag` remains `1`. */
uint32_t result;
do {
tick_irq_flag = 1;
result = sys_time;
} while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt.
Continue until make a non interrupted cycle */
} while(!tick_irq_flag); /*Continue until see a non interrupted cycle */
return result;
#else