创建MTK task的demo
MTK的拓展进程基本都是在custom_config.c文件中的const comptask_info_struct custom_comp_config_tbl[ MAX_CUSTOM_TASKS]进行定义的,默认最多拓展16个。我们可以参照MTK中自带的两个task demo来创建我们自己的task,其相关步骤如下:
1 对custom_config.h文件的修改
在RPS_CUSTOM_TASKS_END之前添加需要创建的task索引
typedef enum
{
INDX_CUSTOM1 = RPS_CUSTOM_TASKS_BEGIN,
INDX_CUSTOM2,
#ifdef __JY_DEBUG_TASK_TEST__
INDX_JY_TASK_TEST,// added by chenwenbin
#endif
RPS_CUSTOM_TASKS_END
} custom_task_indx_type;
在MOD_CUSTOM_END之前添加需要创建的task的功能模块ID,task之间的消息传递就是用这个ID。
typedef enum
{
MOD_CUSTOM1 = MOD_CUSTOM_BEGIN,
MOD_CUSTOM2,
#ifdef __JY_DEBUG_TASK_TEST__
MOD_JY_TASK_TEST, // added by chenwenbin
#endif
MOD_CUSTOM_END
} custom_module_type;
2 对custom_config.c文件的修改
在该文件的适当位置添加一个create函数声明
extern kal_bool custom1_create(comptask_handler_struct **handle);
extern kal_bool custom2_create(comptask_handler_struct **handle);
#ifdef __JY_DEBUG_TASK_TEST__
extern kal_bool jy_task_test_create(comptask_handler_struct **handle);
#endif
在数组custom_mod_task_g[ MAX_CUSTOM_MODS ]中添加INDX_JY_TASK_TEST
custom_task_indx_type custom_mod_task_g[ MAX_CUSTOM_MODS ] =
{
INDX_CUSTOM1, /* MOD_CUSTOM1 */
INDX_CUSTOM2, /* MOD_CUSTOM2 */
#ifdef __JY_DEBUG_TASK_TEST__
INDX_JY_TASK_TEST, // added by chenwenbin
#endif
INDX_NIL /* Please end with INDX_NIL element */
};
对数组custom_comp_config_tbl [ MAX_CUSTOM_TASKS ]的修改
const comptask_info_struct custom_comp_config_tbl[ MAX_CUSTOM_TASKS ] =
{
/* INDX_CUSTOM1 */
{"CUST1", "CUST1 Q", 210, 1024, 10, 0,
#ifdef CUSTOM1_EXIST
custom1_create, KAL_FALSE
#else
NULL, KAL_FALSE
#endif
},
/* INDX_CUSTOM2 */
{"CUST2", "CUST2 Q", 211, 1024, 10, 0,
#ifdef CUSTOM2_EXIST
custom2_create, KAL_FALSE
#else
NULL, KAL_FALSE
#endif
},
#ifdef __JY_DEBUG_TASK_TEST__
/* INDX_JY_TEST */
{"JY_TASK_TEST", "JY_TASK_TEST Q", 212, 1024, 10, 0,
jy_task_test_create, KAL_FALSE
},
#endif
};
typedef struct {
kal_char *comp_name_ptr; //task的名字
kal_char *comp_qname_ptr; //外部队列的名字
kal_uint32 comp_priority; //优先级
kal_uint16 comp_stack_size; //栈大小
kal_uint8 comp_ext_qsize; //外部队列大小
kal_uint8 comp_int_qsize; //内部队列大小
kal_create_func_ptr comp_create_func; //task创建函数
kal_bool comp_internal_ram_stack; //是否是internal_ram_stack
} comptask_info_struct;
3 在custom_sap.h文件末尾定义我们的消息ID
#ifdef __JY_DEBUG_TASK_TEST__
MSG_ID_JY_TASK_TEST, // added by chenwenbin
#endif
4 对custom1_create.c文件的修改
在该文件的适当位置添加一个task_main函数声明
static void custom1_main(task_entry_struct * task_entry_ptr);
static void custom2_main(task_entry_struct * task_entry_ptr);
#ifdef __JY_DEBUG_TASK_TEST__
static void jy_task_test_main(task_entry_struct * task_entry_ptr);
#endif
在该文件末尾添加create和task_main函数的实现
#ifdef __JY_DEBUG_TASK_TEST__
kal_bool jy_task_test_create(comptask_handler_struct **handle)
{
static const comptask_handler_struct jy_task_test_info =
{
jy_task_test_main, /* task entry function */
NULL, /* task initialization function */
NULL, /* task configuration function */
NULL, /* task reset handler */
NULL, /* task termination handler */
};
*handle = (comptask_handler_struct *)&jy_task_test_info;
return KAL_TRUE;
}
static void jy_task_test_main(task_entry_struct * task_entry_ptr)
{
/*-------------------------------------------------------------------------*/
/* Local Variables */
/*-------------------------------------------------------------------------*/
ilm_struct current_ilm;
kal_uint32 my_index;
/*-------------------------------------------------------------------------*/
/* Code Body */
/*-------------------------------------------------------------------------*/
kal_get_my_task_index(&my_index);
while(1)
{
receive_msg_ext_q(task_info_g[task_entry_ptr->task_indx].task_ext_qid, ¤t_ilm);
stack_set_active_module_id(my_index, current_ilm.dest_mod_id);
if(MSG_ID_JY_TASK_TEST == current_ilm.msg_id)
{
jy_trace_log("/n[%d]MOD_MMI --> MOD_JY_TASK_TEST/n", __LINE__);
}
free_ilm( ¤t_ilm);
}
}
#endif
注:以上的修改必须在sysGen1.pl中找到对应的位置进行相应的修改,否则无法创建一个task,因为mtk的编译系统在new操作时是根据sysGen1.pl来生成其他配置文件的。