diff --git a/src/platforms/raw/sys_tick.c b/src/platforms/raw/sys_tick.c new file mode 100644 index 000000000..cf9672b0c --- /dev/null +++ b/src/platforms/raw/sys_tick.c @@ -0,0 +1,50 @@ +/** + * File: sys_tick.c + * Author: AWTK Develop Team + * Brief: use sys tick to implement sleep/get_time_ms. + * + * Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * License file for more details. + * + */ + +/** + * History: + * ================================================================ + * 2018-06-03 Li XianJing created + * + */ + +#include "base/types_def.h" + +static uint32_t g_sys_tick; + +void SysTick_Handler(void) { + g_sys_tick++; +} + +uint32_t get_time_ms() { + return g_sys_tick; +} + +void sleep_ms(uint32_t ms) { + uint32_t count = 0; + uint32_t start = get_time_ms(); + + while (get_time_ms() < (start + ms)) { + count++; + } +} + +void delay_ms(uint32_t ms) { + sleep_ms(ms); +} + +void delay_us(uint32_t us) { + sleep_ms(1); +} +