/*
* File: systmr.c
* Author: merlin66
*
* Created on June 28, 2018, 11:14 AM
*/
#include "xc.h"
#include "systmr.h"
#include "gsm.h"
#ifdef SYSTMR_H
volatile uint32_t delay_final_tick;
volatile uint32_t temp1;
volatile uint32_t temp_=0;
//uint16_t SYSTMR_SaveCountH;
#ifndef System_Tick_Time_In_Interrupt_Routine
#error "Please define the variable mr in the timer file as an extern and increase it by Interrupt Rootin."
#else
volatile uint32_t SYSTMR_CountH;
#if SYSTMRN>0
volatile uint16_t SYSTMR_CountH1;
#define System_Tick_Time1 (((long)SYSTMR_CountH1*(long)SYSTMR_C_Val)+(long)SYSTMR_REG)
#endif
#if SYSTMRN>1
volatile uint16_t SYSTMR_CountH2;
#define System_Tick_Time2 (((long)SYSTMR_CountH2*(long)SYSTMR_C_Val)+(long)SYSTMR_REG)
#endif
#if SYSTMRN>2
volatile uint16_t SYSTMR_CountH3;
#define System_Tick_Time3 (((long)SYSTMR_CountH3*(long)SYSTMR_C_Val)+(long)SYSTMR_REG)
#endif
#endif
#define System_Tick_Time ((SYSTMR_CountH*(long)SYSTMR_C_Val)+(long)SYSTMR_REG)
#if SYSTMRN>0
systimer sys_timer;
bool SYSTMR_Init(uint8_t s_select,void (*call_back_function)(void))
{
switch(s_select)
{
case SYSTMR1:
sys_timer.call_back_sys_1=call_back_function;
sys_timer.s_tick_1_f=_Set;
sys_timer.over_tick_1_f=_Reset;
break;
#if SYSTMRN>1
case SYSTMR2:
sys_timer.call_back_sys_2=call_back_function;
sys_timer.s_tick_2_f=_Set;
sys_timer.over_tick_2_f=_Reset;
break;
#endif
#if SYSTMRN>2
case SYSTMR3:
sys_timer.call_back_sys_3=call_back_function;
sys_timer.s_tick_3_f=_Set;
sys_timer.over_tick_3_f=_Reset;
break;
#endif
default:
return _Error;
};
return _No_Error;
}
bool SYSTMR_DeInit(uint8_t s_select)
{
switch(s_select)
{
case SYSTMR1:
sys_timer.call_back_sys_1=0;
sys_timer.s_tick_1=0;
sys_timer.s_tick_1_f=_Reset;
sys_timer.start_tick_1_f=_Reset;
sys_timer.over_tick_1_f=_Reset;
sys_timer.final_tick_1=_Reset;
break;
#if SYSTMRN>1
case SYSTMR2:
sys_timer.call_back_sys_2=0;
sys_timer.s_tick_2=0;
sys_timer.s_tick_2_f=_Reset;
sys_timer.start_tick_2_f=_Reset;
sys_timer.over_tick_2_f=_Reset;
sys_timer.final_tick_1=_Reset;
break;
#endif
#if SYSTMRN>2
case SYSTMR3:
sys_timer.call_back_sys_3=0;
sys_timer.s_tick_3=0;
sys_timer.s_tick_3_f=_Reset;
sys_timer.start_tick_3_f=_Reset;
sys_timer.over_tick_3_f=_Reset;
sys_timer.final_tick_1=_Reset;
break;
#endif
default:
return _Error;
};
return _No_Error;
}
void SYSTMR_Tasks(void)
{
//temp_=(long)TMR5;
if(sys_timer.start_tick_1_f && (System_Tick_Time1>=sys_timer.final_tick_1))
{
sys_timer.over_tick_1_f=_Set;
sys_timer.start_tick_1_f=_Reset;
if(sys_timer.call_back_sys_1!=0)(*sys_timer.call_back_sys_1)();
}
#if SYSTMRN>1
if(sys_timer.start_tick_2_f && (System_Tick_Time2>=sys_timer.final_tick_2))
{
sys_timer.over_tick_2_f=_Set;
sys_timer.start_tick_2_f=_Reset;
if(sys_timer.call_back_sys_2!=0)(*sys_timer.call_back_sys_2)();
}
#endif
#if SYSTMRN>2
if(sys_timer.start_tick_3_f && (System_Tick_Time3>=sys_timer.final_tick_3))
{
sys_timer.over_tick_3_f=_Set;
sys_timer.start_tick_3_f=_Reset;
if(sys_timer.call_back_sys_3!=0)(*sys_timer.call_back_sys_3)();
}
#endif
}
bool SYSTMR_SetStatus(uint8_t S_Select,uint32_t Sys_input_time,uint8_t t)
{
switch(t)
{
case _Us:
Sys_input_time=Sys_input_time/Time_of_each_Pulse;
break;
case _Ms:
Sys_input_time=(Sys_input_time*1000)/Time_of_each_Pulse;
break;
case _S:
Sys_input_time=(Sys_input_time*1000*1000)/Time_of_each_Pulse;
break;
case _M:
Sys_input_time=(Sys_input_time*1000*1000*60)/Time_of_each_Pulse;
break;
default:
return _Error;
}
switch(S_Select)
{
case SYSTMR1:
if(sys_timer.s_tick_1_f==_Reset)
return _Error;
sys_timer.s_tick_1=Sys_input_time;
break;
#if SYSTMRN>1
case SYSTMR2:
if(sys_timer.s_tick_2_f==_Reset)
return _Error;
sys_timer.s_tick_2=Sys_input_time;
break;
#endif
#if SYSTMRN>2
case SYSTMR3:
if(sys_timer.s_tick_3_f==_Reset)
return _Error;
sys_timer.s_tick_3=Sys_input_time;
break;
#endif
default:
return _Error;
};
return _No_Error;
}
bool SYSTMR_GetStatus(uint8_t S_Select)
{
switch(S_Select)
{
case SYSTMR1:
if(sys_timer.over_tick_1_f==_Set) return _Over;
else if(System_Tick_Time1<sys_timer.s_tick_1) return _Not_Yet;
#if SYSTMRN>1
case SYSTMR2:
if(sys_timer.over_tick_2_f==_Set) return _Over;
else if(System_Tick_Time1<sys_timer.s_tick_2) return _Not_Yet;
#endif
#if SYSTMRN>2
case SYSTMR3:
if(sys_timer.over_tick_3_f==_Set) return _Over;
else if(System_Tick_Time1<sys_timer.s_tick_3) return _Not_Yet;
#endif
};
return _Not_Yet;
}
void SYSTMR_Start(uint8_t S_Select)
{
if(!sys_timer.start_tick_1_f
#if SYSTMRN>1
&& !sys_timer.start_tick_2_f
#endif
#if SYSTMRN>2
&& !sys_timer.start_tick_3_f
#endif
){
start_sys_general_tmr();
}
switch(S_Select)
{
case SYSTMR1:
sys_timer.start_tick_1_f=_Set;
sys_timer.over_tick_1_f=_Reset;
SYSTMR_CountH1=_Reset;
sys_timer.final_tick_1=sys_timer.s_tick_1+(long)System_Tick_Time1;
break;
#if SYSTMRN>1
case SYSTMR2:
sys_timer.start_tick_2_f=_Set;
sys_timer.over_tick_2_f=_Reset;
SYSTMR_CountH2=_Reset;
sys_timer.final_tick_2=sys_timer.s_tick_2+(long)System_Tick_Time2;
break;
#endif
#if SYSTMRN>2
case SYSTMR3:
sys_timer.start_tick_3_f=_Set;
sys_timer.over_tick_3_f=_Reset;
SYSTMR_CountH3=_Reset;
sys_timer.final_tick_3=sys_timer.s_tick_3+(long)System_Tick_Time3;
break;
#endif
};
}
void SYSTMR_Stop(uint8_t S_Select)
{
switch(S_Select)
{
case SYSTMR1:
sys_timer.final_tick_1=0;
sys_timer.start_tick_1_f=_Reset;
sys_timer.over_tick_1_f=_Reset;
break;
#if SYSTMRN>1
case SYSTMR2:
sys_timer.final_tick_2=0;
sys_timer.start_tick_2_f=_Reset;
sys_timer.over_tick_2_f=_Reset;
break;
#endif
#if SYSTMRN
system timer_eyem4v_picsystemtimer_源码
版权申诉
53 浏览量
2021-10-04
00:06:41
上传
评论
收藏 4KB RAR 举报
何欣颜
- 粉丝: 72
- 资源: 4732
最新资源
- (大赛作品)STM32实现的F072RB NUCLEO智能家居控制.zip
- STM32实现的数字示波器源码+数字信号处理教程、配套实例.zip
- 【cookie续续】【cookie续续】【cookie续续】
- 低功耗STM32实现的F411开发板(原理图+PCB源文件+官方例程+驱动等).zip
- 基于stm32实现的 nucleo-L476的智能灯(操作说明+源码).zip
- 基于STM32实现的 NUCLEO板设计彩色LED照明灯(纯cubeMX开发).zip
- 基于STM32实现的 的联合调试侦听设备解决方案(原理图、PCB源文件、调试工具、视频).zip
- 基于STM32实现的 人群定位、调速智能风扇设计(程序、设计报告、视频演示).zip
- 哔哩下载姬(DownKyi)
- 千纬认字app再次更新,增加部首、笔画动画功能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈