App_task_config.h (config\include\app) 64687 2018/10/19
在最下面加入;
task_index(INDX_VIB)task_module_map(INDX_VIB, MOD_VIB)task_name("VIB")task_queue_name("VIB 116")task_priority(254) //优先级task_stack_size(1024 * 8)task_create_function(vib_create)//任务函数task_stack_internalRAM(KAL_FALSE)task_external_queue_size(50)task_internal_queue_size(0)task_boot_mode(NORMAL_M)
User_msgid_app.h (config\include\app) 23418 2018/10/19
在最下面加入支持的两个消息:
#ifdef KAL_MSGID_EXPANSIONMSG_ID_VIB_PWM_START,MSG_ID_VIB_PWM_END,MSG_ID_NAME(VIB)#elseMSG_ID_RANGE(VIB, 100)#endif
创建文件:Vib_pwmsrv.c (plutommi\service\vib_pwm) 4759 2018/10/19
在Mmi_service.mak (make\plutommi\mmi_service) 43591 2018/10/18
加入该文件,能编译该文件
Vib_pwmsrv.c文件内容如下;
#include "kal_general_types.h"#include "MMI_features.h"#include "MMIDataType.h"#include "kal_public_api.h"#include "MMI_media_app_trc.h"#include "DebugInitDef_Int.h"#include "kal_trace.h"#include "stack_config.h"#include "stack_ltlcom.h"#include "app_ltlcom.h"#include "stack_common.h"#include "stack_msgs.h"#include "kal_public_defs.h"#include "kal_release.h"#include "task_main_func.h"#include "kal_active_module.h"#include "task_config.h"#include "hisr_config.h"#include "syscomp_config.h"stack_timer_struct VIB_contorl_timer;kal_uint16 mmi_VIB_blink_time = 0;kal_uint8 vib_level =0 ;kal_uint8 VIB_MODE =0 ;kal_uint8 flage =0 ;extern kal_bool PWM_VIB_MODE_SET(kal_uint8 pwm_level) ;extern kal_bool fg_get_adc_channel_voltage(DCL_ADC_CHANNEL_TYPE_ENUM ch, kal_uint32 *voltage);//任务的主要执行函数static void vib_task_main(task_entry_struct * task_entry_ptr){kal_uint32 my_index; ilm_struct current_ilm;mmi_VIB_blink_time = KAL_TICKS_1_SEC/2;stack_init_timer(&VIB_contorl_timer, "message_vib_timer", MOD_VIB);kal_get_my_task_index( &my_index ); stack_start_timer(&VIB_contorl_timer, 0, mmi_VIB_blink_time);vib_level = 17;VIB_MODE=0;while(1){receive_msg_ext_q(task_info_g[task_entry_ptr->task_indx].task_ext_qid,¤t_ilm);//接收向本任务MOD_VIB发送过来的消息stack_set_active_module_id( my_index, MOD_VIB );//如果接收到则启动该任务开始执行,如果没有收到就挂起来,不执行switch (current_ilm.msg_id)//接收到的消息判断{case MSG_ID_VIB_PWM_START:PWM_VIB_MODE_SET(100);break;case MSG_ID_VIB_PWM_END:PWM_VIB_MODE_SET(0);break;case MSG_ID_TIMER_EXPIRY: //定时器超时消息stack_stop_timer(&VIB_contorl_timer);if(VIB_MODE == 0){PWM_VIB_MODE_SET(0);}elseif(VIB_MODE == 1){PWM_VIB_MODE_SET(50);}elseif(VIB_MODE == 2){PWM_VIB_MODE_SET(67);}elseif(VIB_MODE == 3){PWM_VIB_MODE_SET(83);}elseif(VIB_MODE == 4){if(flage==0){PWM_VIB_MODE_SET(vib_level);vib_level = vib_level+3;if(vib_level>83){flage = 1;vib_level=80;}}if(flage==1){PWM_VIB_MODE_SET(vib_level);vib_level = vib_level-3;if(vib_level<17){flage = 0;vib_level=20;}}}elseif(VIB_MODE == 5){if(flage==0){PWM_VIB_MODE_SET(vib_level);vib_level = vib_level+6;if(vib_level>83){flage = 1;vib_level=77;}}if(flage==1){PWM_VIB_MODE_SET(vib_level);vib_level = vib_level-6;if(vib_level<17){flage = 0;vib_level=23;}}}elseif(VIB_MODE == 6){if(flage==0){PWM_VIB_MODE_SET(83);vib_level = vib_level+3;if(vib_level>83){flage = 1;vib_level=80;}}if(flage==1){PWM_VIB_MODE_SET(17);vib_level = vib_level-3;if(vib_level<17){flage = 0;vib_level=20;}}}elseif(VIB_MODE == 7){if(flage==0){PWM_VIB_MODE_SET(83);vib_level = vib_level+6;if(vib_level>83){flage = 1;vib_level=77;}}if(flage==1){PWM_VIB_MODE_SET(17);vib_level = vib_level-6;if(vib_level<17){flage = 0;vib_level=23;}}}elsePWM_VIB_MODE_SET(0);stack_start_timer(&VIB_contorl_timer, 0, KAL_TICKS_1_SEC/50);//20msbreak;default:break;} free_ilm(¤t_ilm);}}kal_bool vib_create(comptask_handler_struct **handle){/*----------------------------------------------------------------*//* Local Variables *//*----------------------------------------------------------------*/static const comptask_handler_struct vib_handler_info ={vib_task_main, /* task entry function */NULL, /* task initialization function */NULL, /* task configuration function */NULL, /* task reset handler */NULL, /* task termination handler */};/*----------------------------------------------------------------*//* Code Body *//*----------------------------------------------------------------*/*handle = (comptask_handler_struct*)&vib_handler_info;return KAL_TRUE;}
下面是一个在其他task发送消息给MOD_VIB的方法:
ilm_ptr1 = allocate_ilm(MOD_MMI);ilm_ptr1->msg_id = (msg_type) MSG_ID_VIB_PWM_START;ilm_ptr1->local_para_ptr = NULL;ilm_ptr1->peer_buff_ptr = NULL;SEND_ILM(MOD_MMI, MOD_VIB, MMI_L4C_SAP, ilm_ptr1);