/**1* @file systick.c2* Provide access to the system tick with 1 millisecond resolution3*/45/*********************6* INCLUDES7*********************/8#ifdef LV_CONF_INCLUDE_SIMPLE9#include "lv_conf.h"10#else11#include "../../lv_conf.h"12#endif1314#include "lv_hal_tick.h"15#include <stddef.h>1617#if LV_TICK_CUSTOM == 118#include LV_TICK_CUSTOM_INCLUDE19#endif2021/*********************22* DEFINES23*********************/2425/**********************26* TYPEDEFS27**********************/2829/**********************30* STATIC PROTOTYPES31**********************/3233/**********************34* STATIC VARIABLES35**********************/36static uint32_t sys_time = 0;37static volatile uint8_t tick_irq_flag;3839/**********************40* MACROS41**********************/4243/**********************44* GLOBAL FUNCTIONS45**********************/4647/**48* You have to call this function periodically49* @param tick_period the call period of this function in milliseconds50*/51LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)52{53tick_irq_flag = 0;54sys_time += tick_period;55}5657/**58* Get the elapsed milliseconds since start up59* @return the elapsed milliseconds60*/61uint32_t lv_tick_get(void)62{63#if LV_TICK_CUSTOM == 064uint32_t result;65do {66tick_irq_flag = 1;67result = sys_time;68} while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */6970return result;71#else72return LV_TICK_CUSTOM_SYS_TIME_EXPR;73#endif74}7576/**77* Get the elapsed milliseconds since a previous time stamp78* @param prev_tick a previous time stamp (return value of systick_get() )79* @return the elapsed milliseconds since 'prev_tick'80*/81uint32_t lv_tick_elaps(uint32_t prev_tick)82{83uint32_t act_time = lv_tick_get();8485/*If there is no overflow in sys_time simple subtract*/86if(act_time >= prev_tick) {87prev_tick = act_time - prev_tick;88} else {89prev_tick = UINT32_MAX - prev_tick + 1;90prev_tick += act_time;91}9293return prev_tick;94}9596/**********************97* STATIC FUNCTIONS98**********************/99100101102