1.定义任务间传递数据的结构体
typedef struct
{
osal_event_hdr_t hdr;
uint8 mydata;
}temp_collect_task_msg;
typedef struct
{
osal_event_hdr_t hdr;
uint8 mydata;
}voltage_scan_task_msg;
typedef struct
{
osal_event_hdr_t hdr;
uint8 mydata;
}remote_ctl_temp_task_msg;
typedef struct
{
osal_event_hdr_t hdr;
uint8 * mydata;
}light_control_task_msg;
2.在需要执行任务间数据发送的时候执行如下语句
temp_collect_task_msg * Temp_Msg = (temp_collect_task_msg *)osal_msg_allocate(sizeof(temp_collect_task_msg));
remote_ctl_temp_task_msg * Remote_Temp_Msg = (remote_ctl_temp_task_msg *)osal_msg_allocate(sizeof(remote_ctl_temp_task_msg));
light_control_task_msg * light_Msg =(light_control_task_msg*)osal_msg_allocate(sizeof(light_control_task_msg));
Temp_Msg ->hdr.event = ----;
Temp_Msg->mydata = ----;
Remote_Temp_Msg->hdr.event = ----;
Remote_Temp_Msg->mydata = ----;
light_Msg ->hdr.event = ----;
light_Msg ->mydata = ----;
osal_msg_send(Light_Control_TaskID,(uint8 *)Temp_Msg);
osal_msg_send(Light_Control_TaskID,(uint8 *)Remote_Temp_Msg);
osal_msg_send(Light_Control_TaskID,(uint8 *)light_Msg);
3.在任务循环里执行如下语句:
afIncomingMSGPacket_t *MSGpkt;
temp_collect_task_msg * TEMP_Msg;
remote_ctl_temp_task_msg * REMOTE_Temp_Msg;
light_control_task_msg * LIGHT_MSG;
if(events & SYS_EVENT_MSG)
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Light_Control_TaskID );
TEMP_Msg = (temp_collect_task_msg *)MSGpkt;
REMOTE_Temp_Msg = (remote_ctl_temp_task_msg * )MSGpkt;
Light_MSG = (light_control_task_msg *)MSGpkt;
while ( MSGpkt )
{
switch(MSGpkt->hdr.event )
{
case AF_INCOMING_MSG_CMD:
Light_App_ProcessMSGCmd( MSGpkt );
break;
case ----:
TEMP_Msg->mydata----
break;
case ----:
REMOTE_Temp_Msg->mydata----
break;
case ----:
Light_MSG->mdata----
break;
osal_msg_deallocate( (uint8 *)MSGpkt );// Release the memory
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Light_Control_TaskID );
}
return (events ^ SYS_EVENT_MSG); // return unprocessed events
}