You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.9 KiB

#include <stdbool.h> //定义布尔
#include "lib_config.h"
#include "system_ES8P5066.h"
uint32_t g_sys_sick = 0;
/***********************************************************************************************************************
* ======================================================ticket======================================================= *
***********************************************************************************************************************/
void SysTick_IRQHandler(void) { g_sys_sick++; }
void systicket_init(void) {
SYSTICK_InitStruType x; //
x.SysTick_Value = SystemCoreClock / 1000; //
x.SysTick_ClkSource = SysTick_ClkS_Cpu; //时钟48M
x.SysTick_ITEnable = Enable; //
SysTick_Init(&x); //现在滴答定时器时钟用的48M,重装载值4800 t=1s/f(f=48M/48000)
SysTick_Disable(); //
SysTick_Enable();
}
/**
* @brief 获得当前时间戳
*/
uint32_t systicket_get_now_ms(void) { return g_sys_sick; }
/**
* @brief 计算距离上一次ticket过去了多久
*
* @param ticket
* @return uint32_t
*/
uint32_t systicket_haspassedms(uint32_t ticket) {
uint32_t nowticket = systicket_get_now_ms();
if (nowticket >= ticket) {
return nowticket - ticket;
}
return UINT32_MAX - ticket + nowticket;
}
/**
* @brief 延时多少ms
*
* @param nTime
*/
void systicket_delay_ms(uint32_t nTime) {
uint32_t TimingDelay = 0;
TimingDelay = systicket_get_now_ms();
// printf("nTime%d\r\n",nTime);
while (systicket_haspassedms(TimingDelay) < nTime)
;
}
// void systicket_do_debug_light_state(void) {
// static uint32_t lastprocess = 0;
// static uint8_t debug_led_state = 1;
// if (systicket_haspassedms(lastprocess) > 1000) {
// lastprocess = systicket_get_now_ms();
// debug_led_state = !debug_led_state;
// systicket_debug_set(debug_led_state);
// }
// }