当前位置:网站首页>A MCU event driven C framework
A MCU event driven C framework
2022-07-26 01:59:00 【Passing bears~】
brief introduction
This paper is mainly to solve the coupling degree of code function modules , An expression of event driven display .
Current code contains 3 Events , And one of the events contains a sub event .
The code example is as follows
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <windows.h>
#define MAX_HANDLE_QUEUE 10
typedef enum status
{
EVENT_KEY1_PRESS=0,
EVENT_KEY2_PRESS=1,
}tEvent;
typedef struct
{
uint16_t event; // Event number
void (*handle)(uint16_t event); // Save only the total scatter function of the module
}handleType;
handleType _handle[MAX_HANDLE_QUEUE];
int _eventHead = 0;
int _eventTail = 0;
bool _eventFull = false;
void test1(uint16_t data1)
{
printf("data1 =%d\n", data1);
}
void test2(uint16_t data2)
{
printf("data2 =%d\n", data2);
}
void keyEventHandle(uint16_t tEvent)
{
switch (tEvent)
{
case EVENT_KEY1_PRESS:
printf("EVENT_KEY1_PRESS\n");
break;
case EVENT_KEY2_PRESS:
printf("EVENT_KEY2_PRESS\n");
break;
default:
printf("OTHER KEY EVENT PRESS\n");
break;
}
}
void eventProc(void)
{
// uint16_t event;
uint8_t i;
if((_eventHead!=_eventTail) || _eventFull) // Only when there are events in the event queue
{
for(i=0; i<_eventTail; i++)
{
(*_handle[i].handle)(_handle[i].event); // Pass the event number to the module scatter function
}
}
}
void addEventListener(void (*pFunc)(uint16_t event), uint16_t event)
{
if(!_eventFull)
{
_handle[_eventTail].handle = pFunc;
_handle[_eventTail].event = event;
_eventTail++;
if(_eventTail>= MAX_HANDLE_QUEUE)
{
_eventFull= true;
}
}
}
// This function is called during system initialization
void eventInit(void)
{
addEventListener(test1, 1);
addEventListener(test2, 2);
addEventListener(keyEventHandle, 2);
}
int main()
{
eventInit();
while(1)
{
eventProc();
}
return 0;
}
边栏推荐
- 网络之二三层转发
- 餐饮连锁门店重塑增长背后的数字化转型
- Detailed explanation of redis6.x configuration parameters
- 推荐系统-协同过滤在Spark中的实现
- AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
- Implementation of C iterator
- npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
- What is a test case? How to design?
- SVN版本控制分支、合并功能使用
- Redis集群搭建(基于6.x)
猜你喜欢

Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington

Worthington核酸酶、微球菌相关研究及测定方案

CPU的三种模式

The SQL script generated by powerdispatcher model runs incorrectly

Worthington木瓜蛋白酶丨从纯化的蛋白聚糖生产糖肽(附文献)

Analysis of zeromq

How to use the pagoda panel to deploy the full stack project of node to the server

3、 Pinda general permission system__ pd-tools-swagger2

CD from grabbing the track to building a streaming media server -- a case study of "moon in the hometown of sleep"
SQL injection tutorial: learn through examples
随机推荐
Dest0g3 520 orientation (under update)
网络之IP地址
vite 本地运行首次进入页面加载慢问题
Create a future and enjoy extraordinary | gbase Nantah General Motors unveiled opengauss Developer Day 2022
Redis集群搭建(基于6.x)
G. Count the trains (thought set + two points)
Typora expiration solution, what if typora can't open
D - Dire Wolf (interval DP)
Proto conversion dart | project uses protobuf | fluent uses grpc
Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
pt-onnx-ncnn转换的问题记录(接yolov5训练)
mysql 事务隔离级别
我mysql to mysql数据表同步,代码上只有写在第一个顺序上的生效 其余的不生效,这个可能是
How idea can quickly delete recently opened projects
How does Flink SQL configure to print the insert parameter log
How to display numbers / English time in Excel
Remember a laravel problem script @php artist package:discover handling the post autoload dump event returned with
Zhinai buys melons (DP backpack)
FFT is used to estimate the image resampling factor after interpolation
Image batch processing Gaussian filter noise reduction + peak signal-to-noise ratio calculation