当前位置:网站首页>Embedded software architecture Division
Embedded software architecture Division
2022-07-20 15:54:00 【WangLanguager】
1、 Module partition
(1) It's modular “ draw ” It means planning , It means how to reasonably divide a large software into a series of functionally independent parts , Cooperate to complete the requirements of the system .
(2)C Language as a structured programming language , The division of modules is mainly based on functions .
2、 Method of module division
(1) A module is a .C file , Or a .h Joining of documents , The header file (.h) Is the declaration of the module interface .
(2) The external functions and data provided by a module to other modules need to be called in .h The document is preceded by extern Keyword declaration .
(3) Functions and local variables used only inside the module need to be in .C The document is preceded by static Statement .
(4) Never be in .h Variables defined in file : The difference between defining variables and declaring variables is that defining variables will produce memory allocation operations .
stay .h The variable... Is defined in the file , other .C The file refers to the header file , Will make each .C The file defaults this variable to a local variable , This makes this variable unable to play the role of global sharing .
A bad example :
/*module1.h*/
int a = 5 ; // In the module 1 The file of .h It's defined in the file int a
/*module1.c*/
#include "module1.h" // In the module 1 The file of .c The file contains modules 1 Of .h file
/*module2.c*/
#include "module1.h" // In the module 2 The file of .c The file contains modules 1 Of .h file
/*module3.c*/
#include "module1.h" // In the module 3 The file of .c The file contains modules 1 Of .h file
A good example :
/*module1.h*/
extern int a; // In the module 1 The file of .h The document only states int a
/*module1.c*/
#include "module1.h" // In the module 1 The file of .c The file contains modules 1 Of .h file
int a = 5; // In the module 1 The file of .c It's defined in the file int a
/*module2.c*/
#include "module1.h" // In the module 2 The file of .c The file contains modules 1 Of .h file
/*module3.c*/
#include "module1.h" // In the module 3 The file of .c The file contains modules 1 Of .h file
3、 The type of module
(1) Hardware driver module : A specific hardware corresponds to a module
(2) Software function module : The division of its modules should meet the requirements of low coupling 、 High cohesion requirements , A function corresponds to a module .
4、 Task mode :
(1) A single task : Micro serial 、 Macro serial
(2) multitasking : Micro serial 、 Macro parallel
Serial : Only one task runs at a time .
parallel : You run multiple tasks in one time period .
5、 Typical single task architecture
(1) from CPU Start execution at the specified address during reset
(2) Jump to assembly code startup Start execution 、 Partial initialization .
(3) Jump to the user main program main To execute , stay main Done in the function :
① Initialize some hardware devices
② Initialize each software module
③ Into the dead cycle ( Infinite loop ), Call the processing function of each module .
The programming method of dead cycle :
while(1)
{
//null
}
Or written :
for(;;)
{
//null
}
6、 Interrupt service routine
(1) Interrupt is an important part of embedded system , But in standard C The language does not contain interrupts , Many compiler developers are working on Standards C Added support for interrupts , Provide a new keyword to identify the interrupt service program (ISR),
for example :_ _interrupt
(2) When a function is defined as an interrupt function (ISR) When , The compiler will automatically add the interrupt field stack and stack code required by the interrupt service program for this function .
7、 Characteristics of interrupt service program :
The interrupt service program needs to meet the following requirements :
(1) Cannot return value
(2) Cannot interrupt function (ISR) Pass parameters
(3)ISR The program should be as short and concise as possible ; Otherwise, the performance of the program will be affected
(4)printf(char *IpFormatString, ...) Functions cause performance problems , Can't be in ISR Use in a function , Because the execution time of variable parameter functions is relatively long .
8、 Interrupt service program model
In project development , Design a queue , In the interrupt service program , Just add the interrupt type to the queue , Constantly scan the interrupt queue for interrupts in the infinite loop of the main program , If yes, take out the first interrupt type in the queue , Deal with it accordingly .
typedef struct tagIntQueue // Queue for storing interrupts
{
int intType; // Interrupt type
struct tagIntQueue *next; // Queue pointer
} IntQueue;
IntQueue* IpIntQueueHead;
_ _interrupt ISRexample()
{
int intType; // Interrupt type
intType = GetSystemType(); // Get interrupt type
QueueAddTail(IpIntQueueHead, intType), // Add a new interrupt to the end of the queue
}
9、 Main program model
while(1)
{
if(!IsIntQueueEmpty())
{
intType = GetFirstInt();
switch(intType)
{
case xxx: // Interrupt handling function
....
break;
case xxx:
....
break;
}
}
}
边栏推荐
猜你喜欢
In depth explanation of the development function of Multi Chain Wallet system and analysis of the development principle of multi currency wallet system
使用八叉树结构来管理场景
【大型电商项目开发】缓存-分布式锁-缓存一致性解决-45
uniapp通过addInterceptor拦截路由跳转,控制页面是否需要登录
[development of large e-commerce projects] cache - distributed lock - cache consistency solution -45
[matlab project practice] invoice recognition based on MATLAB (including GUI interface)
ZFS - 01 - 创建与扩容zpool基本操作
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
Iterm2 installation and use
无心剑英译吴飞《经纬之歌》
随机推荐
原来何恺明提出的MAE还是一种数据增强!上交&华为基于MAE提出掩蔽重建数据增强,优于CutMix、Cutout和Mixup!...
实验二 货物进销管理系统
经济学十大原理
MySQL将查询的结果作为update更新的数据,且在原字段数据后 CONCAT拼接(lej)
CS615 System Administration, Week 02, Segment 5 - Partitions
使用八叉树结构来管理场景
LIO-SAM:带平滑和建图的紧耦合激光惯性里程计
【MATLAB项目实战】基于感兴趣区域的无人机图像压缩技术研究
golang 接口变量的赋值和方法的调用
关于不同版本的SQLSERVER数据库性能问题
uniapp通过addInterceptor拦截路由跳转,控制页面是否需要登录
pytorch,筛选出一定范围的值
Interviewer: what are the three cache update strategies?
参与开源社区还有证书拿?
Interviewer: are you sure redis is a single threaded process?
PLC-LiSLAM线-面-圆柱体-激光SLAM
Super detailed basic MySQL operations
【WSN通信】基于matlab生物地理学优化HWSN节能聚类协议【含Matlab源码 1989期】
ZFS - 01 - 创建与扩容zpool基本操作
[LSTM regression prediction] Based on MATLAB attention mechanism, LSTM time series regression prediction [including Matlab source code, 1992]