本帖最后由 damiaa 于 2017-7-24 11:52 编辑
l
描述抽象层的文件fs_os_abstraction_free_rtos.c文件中:
说明:操作系统抽象
使用RTOS服务的框架和其他连接软件模块从不直接使用RTOS API。
相反,它们使用操作系统抽象暴露的API,
确保跨多个操作系统的可移植性。OS抽象层为RTOS服务和裸机环境提供了共同的任务创建和控制服务方法。!!!!套一层啊。!!!
In the OS Abstraction layer, the task named main_task() is used as the starting point.
The user must implement a function with the prototype extern void main_task(void *) and treat it like a task. The OS Abstraction implementation declares this function external.
在操作系统抽象层、任务main_task()作为出发点。用户必须与原型extern void main_task实现一个函数(void *),把它当作一个任务。操作系统抽象实现对外声明这个函数。
OSA_TASK_DEFINE(startup_task, gMainThreadPriority_c, 1, gMainThreadStackSize_c, 0) ;
nt main (void)
{
/* Initialize MCU clock */
hardware_init();
OSA_TaskCreate(OSA_TASK(startup_task), NULL);
vTaskStartScheduler();
return 0;
}
OSA_TASK_DEFINE 宏(第一个参数是任务名)和函数 OSA_TaskCreate()申明并创建任务
程序开始初始化硬件,然后就转入freertos的启动任务去了。
hardware_init();初始化硬件在board.c中 关于硬件的时钟,DCDC等问题初始化。
fsl_os_abstraction_free_rtos.c文件中:启动任务
fsl_os_abstraction_free_rtos.c FREERTOS抽象 与 fsl_os_abstraction_bm.c裸机抽象 fsl_os_abstraction_ucosii.c USOSII抽象
void startup_task(void* argument)
{
main_task(argument);
while(1);
}
启动任务中调用app_init.c(这个在nwk==>app==>common)中 main_task函数:初始化,然后调用WHILE循环处理所有事物。
void main_task(uint32_t param)
{
static uint8_t mainInitialized = FALSE;
if (!mainInitialized)
{
mainInitialized = TRUE;
#if WDOG_ENABLE
/* Init watchdog module */
APP_WDOG_Init();
#endif
/* Init memory blocks manager */
MEM_Init();
SecLib_Init();
/* Init timers module */
TMR_Init();
TMR_TimeStampInit();
/* Init Led module */
LED_Init();
/* Non volatile memory module init */
if (gNVM_OK_c != NvModuleInit())
{
panic(0, (uint32_t) NvModuleInit, 0, 0);
}
/* Init phy module */
Phy_Init();
/* RNG must be initialized after the PHY is Initialized */
RNG_Init();
/* Init mac module */
MAC_Init();
/* Initialize Thread Module */
THR_Init();
#if gLpmIncluded_d
PWR_Init();
#endif
/* Initialize Keyboard (Switches) Module */
KBD_Init(KBD_Callback);
SerialManager_Init();
#if THREAD_USE_SHELL
SHELLComm_Init(&appThreadMsgQueue);
#endif
#if THREAD_USE_THCI
FSCI_Init((void*)&mFsciSerials);
#endif
#if THREAD_USE_THCI
APP_FsciInterface(&appThreadMsgQueue);
#endif
#if gHybridApp_d
/* Initialize ble and peripheral drivers specific to the ble application */
BleApp_Init();
#endif
/* Init demo application */
APP_Init();
}
/* Main Application Loop (idle state) */
while (1)
{
#if WDOG_ENABLE
/* Restart the watchdog so it doesn't reset */
APP_WDOG_Refresh();
#endif
#if NVM_NG_ENABLED
/* Process NV Storage save-on-idle, save-on-count and save-on-interval requests */
NvIdle();
#endif
/* Debug Checks, Leader LED restore check */
DBG_Check();
#if gHybridApp_d
/* Ble app */
BleApp_Thread(0);
#endif
/* Application handler */
APP_Handler();//看看这个函数,原来在route_eligible_device_app.c中!!!
/* Treat low power */
#if gLpmIncluded_d
APP_HandleLowPowerOnIdle();
#endif
/* Reset MCU */
APP_HandleMcuResetOnIdle();
/* For BareMetal break the while(1) after 1 run */
if (gUseRtos_c == 0)
{
break;
}
也就是说程序先调用启动任务,初始化一些东西,然后就调用while 循环,里面最主要APP_Handler()。开始thread事件处理。
route_eligible_device_app.c: void APP_Handler ( void ) { bool_t handleMsg = TRUE; while(handleMsg == TRUE) { handleMsg =NWKU_MsgHandler(&appThreadMsgQueue); // Network Utils module function used to dequeueand handle a task message. //pMsgQueue Pointer to structure holding message queueand task id to receive message /* For BareMetal break the while(1)after 1 run */ if(!gUseRtos_c &&MSG_Pending(&appThreadMsgQueue.msgQueue))// MSG_Pending检查thread消息对列 { (void)OSA_EventSet(appThreadMsgQueue.taskEventId,NWKU_GENERIC_MSG_EVENT); //设置事件的标志Sets the specified signal flags of an event object. break; } } }
|