1.引言
本文依然来讲HelloWorld_demo。本文旨在说明pal.c中的代码逻辑。
2.全局变量PAL_Context
本文件中定义了一个很重要的全局变量PAL_Context
/*-------------------------------------------------------------------------
* Type Declarations
*-----------------------------------------------------------------------*/
typedef struct PAL_Context_s
{
qbool_t Initialized; //初始化标志
qapi_UART_Handle_t Console_UART; //串口handle
qbool_t Uart_Enabled; //串口使能标志
char Rx_Buffer[PAL_RECIEVE_BUFFER_COUNT][PAL_RECIEVE_BUFFER_SIZE]; //buffer
char Rx_Buffer_Length[PAL_RECIEVE_BUFFER_COUNT]; //每个buffer的长度
uint8_t Rx_In_Index;
uint8_t Rx_Out_Index;
volatile uint32_t Rx_Buffers_Free;
volatile uint32_t BytesToTx;
qurt_signal_t Event; //事件
} PAL_Context_t;/*-------------------------------------------------------------------------
* Static & global Variable Declarations
*-----------------------------------------------------------------------*/
static PAL_Context_t PAL_Context;
3.平台初始化函数app_init
/**
@brief Function call to initialize the application.
*/
void app_init(qbool_t ColdBoot)
{
#ifdef ENABLE_DBGCALL
dbgcall_setup();
#endif/* Initialize the platform. */
if(PAL_Initialize())
{
/* Create a receive event. */
qurt_signal_init(&(PAL_Context.Event));/* Initialize the samples. */
Initialize_Samples();PAL_Context.Initialized = true;
}
}
这里包含了两个部分:
(1)平台初始化、
在本demo中,平台的初始化主要包括:memset全局变量PAL_Context、串口的初始化(包括打开、创建接收事件)
(2)sample初始化
在这里主要是调用hello_work的初始化代码
4.主体函数app_start
只是调用了hello_world中的主体代码
/**
@brief Main entry point of the application.
*/
void app_start(qbool_t ColdBoot)
{
if(PAL_Context.Initialized)
{
/* Start the main demo app. */
App_Start(ColdBoot);
}
}