CELIS/APPLICATION/SecTimer/SecTimer.c
lidun 7a7daad23a
完成UDS升级
Signed-off-by: lidun <1084178170@qq.com>
2024-01-30 11:31:27 +08:00

129 lines
2.6 KiB
C

#include "SecTimer.h"
#include "timer.h"
#include "stm32f10x_rtc.h"
#include "mm_config.h"
#include "SEN_DCUMessage.h"
struct SecTimer SecTimer[SecTimerNUM] = {0};
static uint32_t GetThisTime()
{
return RTC_GetCounter();
}
bool SecStar(struct SecTimer* obj,uint32_t longTime)
{
uint32_t ThisSecTime = RTC_GetCounter();
if(obj->Star_time == 0)
{
obj->Star_time = ThisSecTime;
obj->Endtime = longTime + obj->Star_time;
}
if(ThisSecTime>=obj->Endtime)
{
return true;
}
return false;
}
bool SecStop(struct SecTimer* obj)
{
obj->Star_time = 0;
obj->Endtime = 0;
return true;
}
struct CAN_SendMaster CanMasterOBJ = {
.obj = NULL,
.Master_len = 0,
};
void AddItemCAN_SendMaster(struct CAN_SendMaster* head,struct CAN_SendTimer* Item)
{
struct CAN_SendTimer* prtItem = (struct CAN_SendTimer*)MM_Malloc(sizeof(struct CAN_SendTimer));
prtItem->Arrcount = Item->Arrcount;
prtItem->can_send = Item->can_send;
if(head->obj==NULL)
{
head->Master_len = 1;
head->headH = prtItem;
prtItem->next=prtItem;
head->obj = prtItem;
return;
}
struct CAN_SendTimer* temp = head->obj;
while(temp->next != head->headH)
{
temp = temp->next;
}
temp->next = prtItem;
prtItem->next = head->obj;
return;
}
void CAN_TowSend()
{
ParseDCU_State_314();
ParseDCU_State_3E8();
}
#define offset_3E8 2500
void InitCAN_SendMaster(void)
{
struct CAN_SendTimer ResterItem;
ResterItem.Arrcount = 10000-1;
ResterItem.can_send = ParseDCU_State_314;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
ResterItem.Arrcount = 5000-1-offset_3E8;
ResterItem.can_send = ParseDCU_State_314;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
//
ResterItem.Arrcount = 5000-1+offset_3E8;
ResterItem.can_send = ParseDCU_State_3E8;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
//
ResterItem.Arrcount = 10000-1;
ResterItem.can_send = ParseDCU_State_314;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
//
ResterItem.Arrcount = 10000-1-offset_3E8;
ResterItem.can_send = ParseDCU_State_314;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
//
ResterItem.Arrcount =0+offset_3E8-1;
ResterItem.can_send = ParseDCU_State_3E8;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
ResterItem.Arrcount = 10000-1;
ResterItem.can_send = ParseDCU_State_314;
AddItemCAN_SendMaster(&CanMasterOBJ,&ResterItem);
}
void TimSend(void)
{
TIM_SetAutoreload(TIM3,CanMasterOBJ.obj->Arrcount);
CanMasterOBJ.obj->can_send();
CanMasterOBJ.obj = CanMasterOBJ.obj->next;
}