add sys_tick.c

This commit is contained in:
xianjimli 2018-06-03 10:42:47 +08:00
parent 6d249e62b0
commit 548b856862

View File

@ -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 <xianjimli@hotmail.com> 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);
}