俺的“嵌入式裸奔”一个程序
#include "libRain_M128.h"
#include "MyLib.h"
#include "Driver\UmIo.h"
#include "Protocol\Protocol.h"
#include "Task\Task.h"
#include "Task\ImportKey.h"
#include "Task\PWM_Wkv.h"
#include "Triggle\Triggle.h"
#include "Task\XPower.h"
#include "Task\WaterLoop.h"
#include "WorkLed\WorkLed.h"
//--------------------------------------------------------
//5ms中断回调函数
//--------------------------------------------------------
void CallBack_5msInterrupt( void )
{
}
//--------------------------------------------------------
//20ms中断回调函数
//--------------------------------------------------------
void CallBack_20msInterrupt( void )
{
}
//--------------------------------------------------------
//析构
//--------------------------------------------------------
void Main_Destory( void )
{
WatchDog_Destory();
//--------------------------user---------------------
Triggle_Destory();
PWM_Wkv_Destory();
ImportKey_Destory();
Task_Destory();
Protocol_Destory();
UmIo_Destory();
//--------------------------System---------------------
WorkLed_Destory();
Package_Destory();
VirtualUart80_Destory();
Uart80_Destory();
Uart81_Destory();
EDataBase_Destory();
CPU_Eeprom_Destory();
MyLib_Destory();
}
//--------------------------------------------------------
//初始化
//--------------------------------------------------------
void Main_Init( void )
{
//--------------------------System---------------------
MyLib_Init();
CPU_Eeprom_Init();
EDataBase_Init( 4, 1, 500, CPU_Eeprom_Cmd );
Uart80_Setup( OSC_7p3728MHz_4800, (eUart80_NoneChk | eUart80_Stop1Bit), 250, 250 );
Uart81_Setup( OSC_7p3728MHz_4800, (eUart80_NoneChk | eUart80_Stop1Bit), 250, 250 );
VirtualUart80_Setup( 200, 200 ); //配置信息在VirtualUart80_IO.c中
Package_Init( 3 ); //三个协议转换任务
//--------------------------user---------------------
UmIo_Init();
Protocol_Init();
Task_Init();
ImportKey_Init();
PWM_Wkv_Init();
Triggle_Init();
XPower_Init();
WaterLoop_Init();
WorkLed_Init();
}
//--------------------------------------------------------
//主程序
//--------------------------------------------------------
int main( void )
{
Main_Init();
Msg_RunInit(); //执行完全部初始化消息
WatchDog_Init(); //看门狗初始化
sei();
Package_Send( psUart_Import, eProto_RequAllState );
//开始主循环
while(1){
//--------------------------System---------------------
MyLib_MainLoop();
CPU_Eeprom_MainLoop();
EDataBase_MainLoop();
VirtualUart80_MainLoop();
Uart80_MainLoop();
Uart81_MainLoop();
Package_MainLoop();
//--------------------------user---------------------
UmIo_MainLoop();
Protocol_MainLoop();
PWM_Wkv_MainLoop();
Task_MainLoop();
ImportKey_MainLoop();
Triggle_MainLoop();
XPower_MainLoop();
WaterLoop_MainLoop();
WatchDog_MainLoop();
WorkLed_MainLoop();
}
}
只要任意再添加一百个任务,即使TCP/IP也可以(当然要改造下),只要MCU能处理过来,同样也可以user下面任何一个任务去掉,而其它任务工作正常。这就是规则和约束的好处。 |