VIA Selle 新建Task方法

 尝试了在Selle 平台上建立一个新的Task来执行一些操作.Selle 0.17以后的版本可以试用,之前的没有试过.

具体的步骤如下:
1.在exeapi.h中新建一个定义,并指定其优先级 如:EXE_ZJJ_ID=36
,
2. 在exepowr.c中声明一个Task
/*——————————————————
* ZJJ Task
Declarations
*——————————————————-
*/
#define
ZJJ_TASK_CB_P
&Exe
ZjjTaskCb
extern void
ZjjTask(uint32 argc, void
*argv);
ExeTaskCbT ExeZjjTaskCb;
extern uint8
ZjjTaskStack[];
static const
MailQueueT
ZjjMailQueueTable[] = {ZJJ_TASK_MAIL_QUEUE_1,
EXE_MAILBOX_1_ID,
ZJJ_TASK_MAIL_QUEUE_2,
EXE_MAILBOX_2_ID};
/*——————————————————
在以下函数中添加一CB的定义:
const ExeTaskCbT *ExeTaskCb[] ={
 ZJJ_TASK_CB_P,
}
在TaskInitTableT中添加此Task的初始化表:
static const TaskInitTableT
TaskInitTable[] = {
,
 "ZjjTask", "ZjjEvGrp", "ZjjQue",
&Exe
ZjjTaskCb, ZjjTask,
ZJJ_TASK_STACK, ZJJ_TASK_PRI, EXE_ZJJ_ID,
  
sizeof(
ZjjMailQueueTable)/sizeof(MailQueueT), ZjjMailQueueTable,
   TaskCreateOptions,
TaskQueueCreateOptions, TaskMemoryAllocateOptions,
   (void
*)
ZjjTaskStack
}
3.
ZJJ_TASK_PRI的定义在exepowr.h 中                  #define ZJJ_TASK_PRI                36
并在此定义ZJJ_TASK_MAIL_QUEUE的大小:
 #defineZJJ_TASK_MAIL_QUEUE_1          20 *
EXE_MAIL_QUEUE_REC_SIZE
 #defineZJJ_TASK_MAIL_QUEUE_2          20 *
EXE_MAIL_QUEUE_REC_SIZE
 定义EXE_ZJJ_ID 与 ZJJ_TASK_PRI 的优先级应该是一致的
4.在exetaskstack.c中添加定义:
            uint8 ZjjTaskStack[ZJJ_TASK_STACK];
5.在其它文件中实现ZjjTask的功能,接收到的消息,针对不同消息的分别处理:
我添加了一个示例如下:
/*zjj add for a task*/
typedef enum
{
/*tts msgs*/
ZJJ_NEW_TASK_FIRST_MONPRINTF_MSG
= 0,
ZJJ_NEW_TASK_SECOND_MSG
}ZjjMsgIdT;
/* TTS_SYNTH_START_MSG msg data
structure */
typedef PACKED
struct
{
   int age;
}ZjjTaskMsgT;
ZjjTaskMsgT *msgp; //发送消息的格式很关键,我只试成功了typedef PACKED struct多消息结构,直接传送Int型的好像不行
msgp = (ZjjTaskMsgT *) ExeMsgBufferGet
(sizeof (ZjjTaskMsgT));
msgp->age=26;
//往这个Task发送消息的格式如下:
ExeMsgSend(EXE_ZJJ_ID, EXE_MAILBOX_1_ID,
ZJJ_NEW_TASK_FIRST_MONPRINTF_MSG, (void*)
msgp,sizeof(ZjjTaskMsgT));
extern "C" void ZjjTask(uint32
/*argc*/, void * /*argv*/)
{
ExeEventWaitT EvtStatus;
bool          
MsgStatus;
uint32        
MsgId;
uint32        
MsgSize;
void*         
MsgDataPtr = NULL;
while (ValStatusGet()
== FALSE)
{
ExeEventWait(
EXE_ZJJ_ID, EXE_SIGNAL_FALSE, EXE_MESSAGE_FALSE, ExeCalMsec(100) );
}
/* Initialize task
*/
/*MonPrintf("TtsTask
begin");*/
/*———————–*
* Event processing
loop *
*————————*/
while(TRUE)
{
/* Wait on mail
*/
EvtStatus =
ExeEventWait(EXE_ZJJ_ID, EXE_SIGNAL_TRUE, EXE_MESSAGE_TRUE, EXE_TIMEOUT_FALSE);
/* Check all signal
flags */
if (EvtStatus &
EXE_SIGNAL_TYPE)
{
;
}
/* Check for message in
mailbox */
if (EvtStatus &
EXE_MESSAGE_TYPE)
{
/* tts Message Handler
for TTS_API_MAILBOX*/
if (EvtStatus &
EXE_MAILBOX_1)
{
/* Read message */
MsgStatus =
ExeMsgRead(EXE_ZJJ_ID, EXE_MAILBOX_1_ID, &MsgId, &MsgDataPtr,
&MsgSize);
/* If message received
process it */
if (MsgStatus)
{
/* Process normal
operation messages */
                  switch(MsgId)
                  {
                      case
ZJJ_NEW_TASK_FIRST_MONPRINTF_MSG:
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS RUNNING");
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS RUNNING");
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS RUNNING");
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS
RUNNING:%d",((ZjjTaskMsgT*)MsgDataPtr)->age);                        
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS RUNNING");
                        
MonPrintf("***********Debug By ZJJ***** ZJJ TASK IS
RUNNING");                        
                     
        break;
                      default:
                     
        break;
                  }
/*MonFault(MON_MMDL_FAULT_UNIT,
TTS_ERR_UNKNOWN_CMD, MsgId, MON_CONTINUE);*/
}         
}
/* tts Message Handler
for EXE_MAILBOX_2*/                        
if (EvtStatus &
EXE_MAILBOX_2)
{
;
}
/* Free message data
buffer */
if (MsgDataPtr)
{
ExeMsgBufferFree(
(void*)MsgDataPtr);
MsgDataPtr = NULL;
}
}
} /* End While(TRUE)
*/
}
有些声名在这里可能没有列出,参照别的Task请自行添加即可,我本地己编译通过,可以正常执行.
希望本文对你有所帮助.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.