CELIS/HARDWARE/EVENT/Single_event_receiver.c

119 lines
2.2 KiB
C
Raw Normal View History

/*
* @Description:
* @Version:
* @Author: Arnold
* @Date: 2023-12-31 14:36:59
* @LastEditTime: 2023-12-31 16:10:41
*/
#include "Single_event_receiver.h"
#include "Err_code.h"
#include "kC_Features.h"
#include <stdint.h>
static int32_t front =0;
static int32_t rear = 0;
SingleEvent_FOREACH(GetSingleEventFunction);
static SingleEvent_t event_queue[MAX_EVENTS];
static bool is_queue_empty(void) {
return front == rear;
}
static bool is_queue_full() {
return front == (rear + 1) % MAX_EVENTS;
}
void add_event(SingleEvent_t event) {
if (is_queue_full()) {
printf("Event queue is full\n");
return;
}
event_queue[rear] = event;
rear = (rear + 1) % MAX_EVENTS;
}
static SingleEvent_t get_event() {
if (is_queue_empty()) {
return EVENT_NONE;
}
SingleEvent_t event = event_queue[front];
front = (front + 1) % MAX_EVENTS;
return event;
}
static void process_event(SingleEvent_t event)
{
switch (event) {
SingleEvent_FOREACH(GetSwitchSingleCase)
default:
printf("Unknown event is ignored\n");
break;
}
}
void GetSingleEventFunction_NAME(EVENT_AA)
{
printf("EVENT_A\r\n");
}
void GetSingleEventFunction_NAME(EVENT_BB)
{
printf("EVENT_B\r\n");
}
void GetSingleEventFunction_NAME(EVENT_CC)
{
printf("EVENT_C\r\n");
}
void GetSingleEventFunction_NAME(EVENT_AC)
{
printf("EVENT_AC\r\n");
for(uint8_t i=0;i<5;i++)
{
DCU_SendState.AC_Relay_State == false?CLOSE_AC_RELAY():OPEN_AC_RELAY();
Delay_MS(500);
DCU_SendState.AC_Relay_State == false?CLOSE_AC_RELAY():OPEN_AC_RELAY();
Delay_MS(500);
if(DCU_SendState.AC_Relay_State == READ_AC_YX1())return;
}
Err_Set(4);
}
void GetSingleEventFunction_NAME(EVENT_DC)
{
printf("EVENT_DC\r\n");
for(uint8_t i=0;i<5;i++)
{
DCU_SendState.DC_Relay_State == true?CLOSE_DC_RELAY():OPEN_DC_RELAY();
Delay_MS(500);
DCU_SendState.DC_Relay_State == true?CLOSE_DC_RELAY():OPEN_DC_RELAY();
Delay_MS(500);
if(DCU_SendState.DC_Relay_State == READ_DC_YX2())return;
}
Err_Set(3);
}
void eventDosomething()
{
while (!is_queue_empty())
{
SingleEvent_t event = get_event();
process_event(event);
}
}