首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 单片机 >

关于函数参数void* argv的使用有关问题

2012-10-31 
关于函数参数void* argv的使用问题函数CoCreate函数原型:OS_TID CoCreateTask (FUNCPtr task,void* argv,U

关于函数参数void* argv的使用问题
函数CoCreate
函数原型:
OS_TID CoCreateTask (
FUNCPtr task,
void* argv,
U8 prio,
OS_STK* stk,
U16 stkSz,
)
功能描述:
创建一个任务并返回任务ID。
函数参数:
[IN] task
创建任务的函数体
[IN] argv
任务函数体的传入参数列表
[IN] prio
任务优先级
[IN] stk
任务堆栈起始地址
[IN] stkSz
任务堆栈大小(单位为字)
返回值:
任务ID, 创建任务成功
-1, 创建任务失败

这是CoOS操作系统中的一个函数,下面一个例子中用到它,但参数写的有些问题

C/C++ code
/*---------------------------- Inlcude ---------------------------------------*/#include                  /*!< CoOS header file          *//*---------------------------- Symbol Define -------------------------------*/#define STACK_SIZE_TASKA 128              /*!< Define "taskA" task size */#define STACK_SIZE_TASKB 128              /*!< Define "taskA" task size */#define STACK_SIZE_TASKC 128              /*!< Define "taskA" task size *//*---------------------------- Variable Define -------------------------------*/OS_STK     taskA_stk[STACK_SIZE_TASKA];   /*!< Define "taskA" task stack */OS_STK     taskB_stk[STACK_SIZE_TASKB];   /*!< Define "taskB" task stack */OS_STK     taskC_stk[STACK_SIZE_TASKC];   /*!< Define "led" task stack   */typedef struct  { long m1; unsigned long m2; long m3;  }test_t;const test_t par={345,20,130};/** ******************************************************************************* * @brief       "taskA" task code * @param[in]   None  * @param[out]  None * @retval      None   * @par Description * @details    This task use to crate mutex and flags,print message "taskA running".  *             Indicate "taskA" had been executed.   ******************************************************************************* */void taskA (unsigned int st){  unsigned int led_num;  led_num=st;  for (;;) { led_num++;        CoTickDelay (50);  }}/** ******************************************************************************* * @brief       "taskB" task code * @param[in]   None  * @param[out]  None * @retval      None   * @par Description * @details    This task use to print message "taskB running". Indicate "taskB" *             had been executed.   ******************************************************************************* */void taskB (test_t* p){  unsigned int led_num;  led_num=p->m3;  for (;;) { led_num++;        CoTickDelay (50);  }}/** ******************************************************************************* * @brief       "led" task code * @param[in]   None  * @param[out]  None * @retval      None   * @par Description * @details    This function use to blink led,and set flag for "taskA" and "taskB". ******************************************************************************* */void taskC (void* pdata){  unsigned int led_num;  for (;;) { led_num++;        CoTickDelay (50);  }}/** ******************************************************************************* * @brief  main function     * @param[in]  None   * @param[out]  None   * @retval  None   ******************************************************************************* */int main (){  CoInitOS ();     /*!< Initial CooCox CoOS          */  /*!< Create three tasks */  CoCreateTask (taskA,123,0,&taskA_stk[STACK_SIZE_TASKA-1],STACK_SIZE_TASKA);  CoCreateTask (taskB,&par,1,&taskB_stk[STACK_SIZE_TASKB-1],STACK_SIZE_TASKB);  CoCreateTask (taskC,0,2,&taskC_stk[STACK_SIZE_TASKC-1],STACK_SIZE_TASKC);  CoStartOS ();       /*!< Start multitask            */   while (1);                /*!< The code don''t reach here    */}


编译时会给出CoCreateTask参数二类型不匹配的警告,请教下这个参数(分别为123,&par,0)该怎么进行类型转换才能不出警告?


[cc] E:\WorkProject\CooCox\OSTest\example\CoOS_App_Framework.c: In function 'main':



  [cc] E:\WorkProject\CooCox\OSTest\example\CoOS_App_Framework.c:98:3: warning: passing argument 1 of 'CreateTask' from incompatible pointer type
   

[cc] E:\WorkProject\CooCox\OSTest\CoOS\kernel/CoOS.h:136:20: note: expected 'FUNCPtr' but argument is of type 'void (*)(unsigned int)'
   

[cc] E:\WorkProject\CooCox\OSTest\example\CoOS_App_Framework.c:98:3: warning: passing argument 2 of 'CreateTask' makes pointer from integer without a cast
   

  [cc] E:\WorkProject\CooCox\OSTest\CoOS\kernel/CoOS.h:136:20: note: expected 'void *' but argument is of type 'int'
   

[cc] E:\WorkProject\CooCox\OSTest\example\CoOS_App_Framework.c:99:3: warning: passing argument 1 of 'CreateTask' from incompatible pointer type
   

[cc] E:\WorkProject\CooCox\OSTest\CoOS\kernel/CoOS.h:136:20: note: expected 'FUNCPtr' but argument is of type 'void (*)(struct test_t *)'
   

[cc] E:\WorkProject\CooCox\OSTest\example\CoOS_App_Framework.c:99:3: warning: passing argument 2 of 'CreateTask' discards qualifiers from pointer target type
   

  [cc] E:\WorkProject\CooCox\OSTest\CoOS\kernel/CoOS.h:136:20: note: expected 'void *' but argument is of type 'const struct test_t *'




[解决办法]
加“”,变成字符串试试,本来我想先试试再给你说的,可是我没有你这个系统环境。是UCOS吧
[解决办法]
void* 的意思是你可以传进入任何类型的指针。
[解决办法]
是任何的指针类型。不是任意类型。
[解决办法]
unsigned int param1 = 123;
void * param3 = 0;

CoCreateTask (taskA,(void*)&param1,0,&taskA_stk[STACK_SIZE_TASKA-1],STACK_SIZE_TASKA);
CoCreateTask (taskB,(void*)&par,1,&taskB_stk[STACK_SIZE_TASKB-1],STACK_SIZE_TASKB);
CoCreateTask (taskC,param3,2,&taskC_stk[STACK_SIZE_TASKC-1],STACK_SIZE_TASKC);
[解决办法]

探讨
CoCreateTask ((FUNCPtr)taskA,(void *)123,0,&taskA_stk[STACK_SIZE_TASKA-1],STACK_SIZE_TASKA);

[解决办法]
lz,解决问题要记得结贴哦,:-)

热点排行