EdgeGateway_FSU/DevicePortGet/Public_Src/SystemTimeFunc.c

136 lines
5.0 KiB
C
Raw Normal View History

2024-03-15 17:25:04 +08:00
/***************************************************************
Copyright © huijue Network Co., Ltd. 1998-2129. All rights reserved.
Copyright © 1998-2129. All rights reserved.
: SystemTimeFunc.c
: kooloo
: V1.0
: /FSU kooloo add 202310
: iMX6ULL
: linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7
gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
: V1.0 2023/7/15 kooloo
***************************************************************/
#define _GNU_SOURCE //在源文件开头定义_GNU_SOURCE宏 加此宏则不会有错误 kooloo add 202401
#include <stdio.h>
#include <stdlib.h>
#include <signal.h> //signal()
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h> //struct itimerval, setitimer()
#include "public.h" //公共函数头文件
#include "mslog.h"
#include "SystemTimeFunc.h"
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : TimerTicks_sig_handler
** : SIGALRM
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
static void TimerTicks_sig_handler(int sig)
{
SystemTicktimer_isr();
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : Systemtimer_Iint
** :
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Systemtimer_Iint(void)
{
struct sigaction sig = { 0 };
struct itimerval tick;
pSysPara->g_SystemTicksCounter = 0; //起始设置为0不需要回滚时间所以设置为0 kooloo add 202311
/* 为 SIGALRM 信号绑定处理函数 */
sig.sa_handler = TimerTicks_sig_handler;
sig.sa_flags = 0;
if (-1 == sigaction(SIGALRM, &sig, NULL))
{
ms_error1("sigaction error!\n");
exit(-1);
}
//间隔定时器
//Timeout to run first time
tick.it_value.tv_sec = C_SYSTEMTIME_COUNTER_BASE;
tick.it_value.tv_usec = 0;
//After first, the Interval time for clock
tick.it_interval.tv_sec = C_SYSTEMTIME_COUNTER_BASE;
tick.it_interval.tv_usec = 0;
if (setitimer(ITIMER_REAL, &tick, NULL) < 0)
{
ms_error1("Set timer failed!\n");
exit(-1);
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : SystemTicktimer_isr
** :
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void SystemTicktimer_isr(void)
{
if (pSysPara->g_SystemTicksCounter < C_SYSTEMTIME_COUNTER_MAX)
{
pSysPara->g_SystemTicksCounter++;
}
else //时间值超出 这里直接将其初始化为 0 并没有做对齐处理 一般不会连续使用不会超过20天另外 直接清0 并没有过多问题 kooloo add 20190411
{
pSysPara->g_SystemTicksCounter = 0;
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : Timer_getNowTicks
** :
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
int Timer_getNowTicks(void)
{
return pSysPara->g_SystemTicksCounter;
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : Timer_getDiffValueTicks
** : Ticks kooloo add 20190114
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
int Timer_getDiffValueTicks(int StartTimeTicks)
{
int Tempi = Timer_getNowTicks();
if (Tempi < StartTimeTicks) //如果小于 实际不会有小于此种情况,但考虑程序的健壮性 增加此处代码 kooloo add 20190114
{
return 0; //直接返回0 kooloo add 20190114
}
else
{
return (Tempi - StartTimeTicks); //返回差值 kooloo add 20190114
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** : SystemInterval_Iint
** :
** :
**   : 2023902
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void SystemInterval_Iint(void)
{
pSysPara->SystemUpTime = Timer_getNowTicks(); //时间更新判断计时变量 kooloo add 202311
pSysPara->g_TimeUpdateCounter = Timer_getNowTicks(); //时间更新判断计时变量 kooloo add 202311
pSysPara->g_ExeIsRunningCounter = Timer_getNowTicks(); //时间更新判断计时变量 kooloo add 202311
pSysPara->g_ExeIndex = C_SUBPRCESS_DevicePortGetApp;
//Device 数据采集相关变量
pSysPara->g_GetApp_TimeCounter = Timer_getNowTicks(); //DevicePortGetApp 时间计数 kooloo add 202312
pSysPara->g_SendSubDevData_TimeCnt = Timer_getNowTicks(); //DevicePortGetApp 数据发送时间计数 kooloo add 202312
}