1 /** 2 * @file systick.c 3 * Provide access to the system tick with 1 millisecond resolution 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #ifdef LV_CONF_INCLUDE_SIMPLE 10 #include "lv_conf.h" 11 #else 12 #include "../../lv_conf.h" 13 #endif 14 15 #include "lv_hal_tick.h" 16 #include <stddef.h> 17 18 #if LV_TICK_CUSTOM == 1 19 #include LV_TICK_CUSTOM_INCLUDE 20 #endif 21 22 /********************* 23 * DEFINES 24 *********************/ 25 26 /********************** 27 * TYPEDEFS 28 **********************/ 29 30 /********************** 31 * STATIC PROTOTYPES 32 **********************/ 33 34 /********************** 35 * STATIC VARIABLES 36 **********************/ 37 static uint32_t sys_time = 0; 38 static volatile uint8_t tick_irq_flag; 39 40 /********************** 41 * MACROS 42 **********************/ 43 44 /********************** 45 * GLOBAL FUNCTIONS 46 **********************/ 47 48 /** 49 * You have to call this function periodically 50 * @param tick_period the call period of this function in milliseconds 51 */ lv_tick_inc(uint32_t tick_period)52LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period) 53 { 54 tick_irq_flag = 0; 55 sys_time += tick_period; 56 } 57 58 /** 59 * Get the elapsed milliseconds since start up 60 * @return the elapsed milliseconds 61 */ lv_tick_get(void)62uint32_t lv_tick_get(void) 63 { 64 #if LV_TICK_CUSTOM == 0 65 uint32_t result; 66 do { 67 tick_irq_flag = 1; 68 result = sys_time; 69 } while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. 70 Continue until make a non interrupted cycle */ 71 72 return result; 73 #else 74 return LV_TICK_CUSTOM_SYS_TIME_EXPR; 75 #endif 76 } 77 78 /** 79 * Get the elapsed milliseconds since a previous time stamp 80 * @param prev_tick a previous time stamp (return value of systick_get() ) 81 * @return the elapsed milliseconds since 'prev_tick' 82 */ lv_tick_elaps(uint32_t prev_tick)83uint32_t lv_tick_elaps(uint32_t prev_tick) 84 { 85 uint32_t act_time = lv_tick_get(); 86 87 /*If there is no overflow in sys_time simple subtract*/ 88 if(act_time >= prev_tick) { 89 prev_tick = act_time - prev_tick; 90 } else { 91 prev_tick = UINT32_MAX - prev_tick + 1; 92 prev_tick += act_time; 93 } 94 95 return prev_tick; 96 } 97 98 /********************** 99 * STATIC FUNCTIONS 100 **********************/ 101