/** * COPYRIGHT NOTICE *Copyright(c) 2014,YICHIP * * @file yc_timer.c * @brief ... * * @version 1.0 * @author jingzou * @data Jan 23, 2018 **/ #include "yc_timer.h" #include "yc11xx.h" #include "core_cm0.h" #include "LH_TaskManager.h" uint32_t sys_tick_count; uint8_t sys_Timer_Check_Flag; uint32_t gSystemTimerAdjustClknbt; static unsigned int sys_run_tickms=0; //从定时器初始化运行到当前的毫秒 static unsigned int sys_run_ticks=0; //从定时器初始化运行到当前的秒 void SYS_TimerExpireDefaultHandle(int params) { // YC_LOG_ERROR("default timer expire !\r\n"); while(0); } void SYS_TimerInit() { SysTick_Config(SYSTEM_CLOCK/CLOCK_DIVISOR); //each systick interrupt is 1ms } static unsigned int system_time_get_run_tickms(void) { return sys_run_tickms; } static unsigned int system_time_get_run_ticks(void) { return sys_run_ticks; } static unsigned short MsCnt = 0; void SYStick_handle() //1ms中断一次 { //SYS_ClkTicks(); //sys_Timer_Check_Flag = true; // SYS_timerPolling(); if(++MsCnt>999) { MsCnt=0; sys_run_ticks++; } sys_run_tickms++; TaskManager_Scheduling(); } void SYS_delay_ms(uint32_t nms) { SYS_delay_us(nms*1000); } void SYS_delay_us(uint32_t nus){ uint32_t ticks; uint32_t told,tnow,tcnt=0; uint32_t reload=SysTick->LOAD; ticks=nus*(SYSTEM_CLOCK/1000000); tcnt=0; told=SysTick->VAL; while(1){ tnow=SysTick->VAL; if(tnow!=told){ if(tnow=ticks) break; } }; } sys_time_handle_t sys_time_handle={ .init= SYS_TimerInit, .get_run_ticks=system_time_get_run_ticks, .get_run_tickms=system_time_get_run_tickms } ;