在MTK中新增TASK與常用函式分析

elemem發表於2010-05-06

宣告TASK的ID和MOD型別
在custom_config.h中custom_task_indx_type新增ID

如:

typedef enum {
   INDX_CUSTOM1 = RPS_CUSTOM_TASKS_BEGIN,
   INDX_CUSTOM2,
   #if defined(__MIIPTS_TASK_SUPPORT__)
   INDX_MIIPTS,
   #endif
#if defined(__ELIVE_SUPPORT__)
   INDX_ELIVE,
#if defined(__ELIVE_IPTV_SUPPORT__) || defined(__ELIVE_RDO_SUPPORT__)       
   INDX_ELIVECORE,
#endif
#endif
#if defined(__MOTION_SENSOR_SUPPORT_MMI_NEW__)
   INDX_GSENSOR,
#endif
#if defined(FLASHLIGHT_LED_SUPPORT)
   INDX_FLASHLIGHT,
#endif
#if defined(BCT3288_SUPPORT)
   INDX_BCT3288LED,
#endif

#if  defined(__OPEN_PLATFORM_SUPPORT__)
    INDX_CUSTOM_OPEN,
  #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
    INDX_MQQ,
  #endif  // #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
#endif  // #if  defined(__OPEN_PLATFORM_SUPPORT__)

   RPS_CUSTOM_TASKS_END
} custom_task_indx_type;

中的

#if defined(FLASHLIGHT_LED_SUPPORT)
   INDX_FLASHLIGHT,
#endif
為 新加ID;

在custom_module_type中新增模組型別

如:

typedef enum {
   MOD_CUSTOM1 = MOD_CUSTOM_BEGIN,
   MOD_CUSTOM2,
   #if defined(__MIIPTS_TASK_SUPPORT__)
   MOD_MIIPTS,
   #endif
#if defined(__ELIVE_SUPPORT__)
   MOD_ELIVE,
#if defined(__ELIVE_IPTV_SUPPORT__) || defined(__ELIVE_RDO_SUPPORT__) 
   MOD_ELIVECORE,
#endif
#endif
#if defined(__MOTION_SENSOR_SUPPORT_MMI_NEW__)
   MOD_SC_GSENSOR,
#endif
#if defined(FLASHLIGHT_LED_SUPPORT)
   MOD_FLASHLIGHT,
#endif
#if defined(BCT3288_SUPPORT)
   MOD_BCT3288LED,
#endif

#if defined(__OPEN_PLATFORM_SUPPORT__)
    MOD_CUSTOM_OPEN,
  #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
    MOD_MQQ,
  #endif  // #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
#endif  // #if defined(__OPEN_PLATFORM_SUPPORT__)

   MOD_CUSTOM_END
} custom_module_type;

#if defined(FLASHLIGHT_LED_SUPPORT)
   MOD_FLASHLIGHT,
#endif
為 新加MOD的型別;

在custom_config.c中的陣列custom_mod_task_g中把宣告的ID加入:

如:

custom_task_indx_type custom_mod_task_g[ MAX_CUSTOM_MODS ] =
{
   INDX_CUSTOM1,        /* MOD_CUSTOM1 */
   INDX_CUSTOM2,        /* MOD_CUSTOM2 */
   #if defined(__MIIPTS_TASK_SUPPORT__)
   INDX_MIIPTS,         // MOD_MIIPTS
   #endif
#if defined(__ELIVE_SUPPORT__)
   INDX_ELIVE,
#if defined(__ELIVE_IPTV_SUPPORT__) || defined(__ELIVE_RDO_SUPPORT__)       
   INDX_ELIVECORE,
#endif
#endif
#if defined(__MOTION_SENSOR_SUPPORT_MMI_NEW__)
   INDX_GSENSOR,
#endif
#if defined(FLASHLIGHT_LED_SUPPORT)
   INDX_FLASHLIGHT,
#endif
#if defined(BCT3288_SUPPORT)
   INDX_BCT3288LED,
#endif

#if  defined(__OPEN_PLATFORM_SUPPORT__)
    INDX_CUSTOM_OPEN,            /* MOD_CUSTOM_OPEN */
  #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
    INDX_MQQ,            /* MOD_QQ */
  #endif  // #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
#endif  // #if  defined(__OPEN_PLATFORM_SUPPORT__)

   INDX_NIL             /* Please end with INDX_NIL element */
};
在 函式custom_comp_config_tbl中新增TASK的實現函式和TASK的資訊宣告

如:

{
   /* 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
   },
   #if defined(__MIIPTS_TASK_SUPPORT__)
   {"MiiPTS", "MiiPTS Q", 212, 1024*4, 10, 0, miipts_task_create, KAL_FALSE},
   #endif
#if defined(__ELIVE_SUPPORT__)
    {"ELIVE", "ELIVE Q", KAL_PRIORITY_CLASS17+2, 1024*3, 80, 0,
    Elive_create, KAL_FALSE} ,
#if defined(__ELIVE_IPTV_SUPPORT__) || defined(__ELIVE_RDO_SUPPORT__) 
    {"ELIVECORE", "ELIVECORE Q", KAL_PRIORITY_CLASS17+4, 1024*3, 20, 10,
    EliveCoreTask, KAL_FALSE} , 
#endif
#endif

#if defined(__MOTION_SENSOR_SUPPORT_MMI_NEW__)
   /* INDX_GSENSOR */
   {"Gsensor", "Gsensor Q", 195, 1024, 20, 10,
   SC_gsensor_create, KAL_FALSE},  
#endif 
#if defined(FLASHLIGHT_LED_SUPPORT)
   /* INDX_FLASHLIGHT */
   {"FLHLT", "FLHLT Q", 200, 1024, 10, 0,
   SC_flashlight_create, KAL_FALSE},
#endif
#if defined(BCT3288_SUPPORT)
   /* INDX_BCT3288LED */
   {"BCT3288", "BCT3288 Q", 200, 1024, 20, 0,
   SC_BCT3288Flashlight_create, KAL_FALSE},
#endif


#if  defined(__OPEN_PLATFORM_SUPPORT__)
    { "CUSTOPEN", "CUSTOPEN Q", 220, 4096, 64, 0, Open_TaskCreate, KAL_FALSE },
  #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
    { "MQQ", "MQQ Q", 212, 4096, 100, 10, mqq_create, KAL_FALSE },
  #endif  // #if  defined(OPEN_CUSTOM_PRODUCT_QQ_DOWN_07A) && !defined(WIN32)
#endif  // #if  defined(__OPEN_PLATFORM_SUPPORT__)

}

中的

#if defined(FLASHLIGHT_LED_SUPPORT)
   /* INDX_FLASHLIGHT */
   {"FLHLT", "FLHLT Q", 200, 1024, 10, 0,
   SC_flashlight_create, KAL_FALSE},
#endif
如果TASK需要與別的TASK互動,要使用訊息,訊息ID在檔案custom_sap.h中定義, 該標頭檔案被包含在檔案stack_msgs.h中,最終合併入msg_type列舉中。

如:

MSG_ID_CUSTOM1_CUSTOM2  =  CUSTOM_MSG_CODE_BEGIN,
MSG_ID_CUSTOM2_CUSTOM1,
#if defined(__MIIPTS_TASK_SUPPORT__)
MSG_ID_MIIPTS_ENCODE_REQ,
MSG_ID_MIIPTS_ENCODE_CNF,
MSG_ID_MIIPTS_DECODE_REQ,
MSG_ID_MIIPTS_DECODE_CNF,
#endif // __MIIPTS_TASK_SUPPORT__
#ifdef __ELIVE_SUPPORT__
MSG_ID_ELIVE_BASE,
MSG_ID_ELIVE_END  = MSG_ID_ELIVE_BASE + 50,
#endif
#if defined(__ALLKEY_EINT_FOR_KEYBOARD__)
MSG_ID_ALLKEYBOARD,
#endif
#if defined(__MOTION_SENSOR_SUPPORT_MMI_NEW__)
MSG_ID_GSENSOR_CHECK_START_REQ,
MSG_ID_GSENSOR_CHECK_STOP_REQ,
MSG_ID_GSENSOR_CHECK_ROTATE_IND,
#endif
#if defined(FLASHLIGHT_LED_SUPPORT)
MSG_ID_FLASHLIGHT_PLAY_REQ,
MSG_ID_FLASHLIGHT_STOP_REQ,
#endif
#ifdef __MMI_IMAP__
MSG_ID_IMAP,
#endif
#if defined(FIVE_CLAM_SUPPORT)
MSG_ID_FIVE_CLAM_SUPPORT,
#endif
#if defined(FOUR_CLAM_SUPPORT)
MSG_ID_FOUR_CLAM_SUPPORT,
#endif
#if defined(E73_TWO_CLAM_SUPPORT)
MSG_ID_TWO_CLAM_SUPPORT,
#endif
#if defined(BCT3288_SUPPORT)
MSG_ID_BCT3288FLASHLIGHT_LEFTKEY_PRESS,
MSG_ID_BCT3288FLASHLIGHT_RIGHTKEY_PRESS,
MSG_ID_BCT3288FLASHLIGHT_UPKEY_PRESS,
MSG_ID_BCT3288FLASHLIGHT_DOWNKEY_PRESS,
MSG_ID_BCT3288FLASHLIGHT_RIGHT_ROTATE,
MSG_ID_BCT3288FLASHLIGHT_LEFT_ROTATE,
MSG_ID_BCT3288FLASHLIGHT_MP3_EFFECT,
MSG_ID_BCT3288FLASHLIGHT_STOP_REQ,
MSG_ID_BCT3288FLASHLIGHT_ROTATE_CNF,
#endif
中 的

#if defined(FLASHLIGHT_LED_SUPPORT)
MSG_ID_FLASHLIGHT_PLAY_REQ,
MSG_ID_FLASHLIGHT_STOP_REQ,
#endif
再 看TASK函式的實現和呼叫:

kal_bool SC_flashlight_create(comptask_handler_struct **handle)
{
 static const comptask_handler_struct custom_handler_info =
 {
  SC_flashlight_task_main, /* task entry function */
  SC_flashlight_init, /* task initialization function */
  NULL,  /* task configuration function */
  NULL,  /* task reset handler */
  NULL,  /* task termination handler */
 };

 *handle = (comptask_handler_struct *)&custom_handler_info;
 return KAL_TRUE;
}

task的處理函式,主要是獲取TASK的ID函式kal_get_my_task_index和獲取訊息內容函式 receive_msg_ext_q:
void SC_flashlight_task_main(task_entry_struct * task_entry_ptr)
{
 ilm_struct current_ilm;
 kal_uint32 my_index;

 kal_get_my_task_index(&my_index);

 while(1)
 {
  receive_msg_ext_q( task_info_g[task_entry_ptr->task_indx].task_ext_qid,
         &current_ilm);
  stack_set_active_module_id( my_index, current_ilm.dest_mod_id);
   if(current_ilm.msg_id==MSG_ID_FLASHLIGHT_PLAY_REQ)
  {
   //ET6204_init();
   SC_et6204_play(&current_ilm);
  }
  else if(current_ilm.msg_id==MSG_ID_FLASHLIGHT_STOP_REQ)
  {
   StopTimer(LED_FLASH_TIMER); 
   ET6204_ALL_OFF();
   Poweroff_ET6204();
  }
  free_ilm( &current_ilm);
 }
}

初始化函式,進入該TASK裡需要初始化的全域性變數等:

kal_bool SC_flashlight_init(task_indx_type indx)
{
 ET6204_init();
 return KAL_TRUE;
}

訊息處理函式,主要是收到訊息的處理函式,掌握 et6204_light_play_ind的定義與使用:

void SC_et6204_play(ilm_struct *ilm_ptr)
{
 kal_uint16 et6204_display[7];
 int i;
 et6204_light_play_ind *play_data = (et6204_light_play_ind *)(ilm_ptr->local_para_ptr);

 ET6204_POWER_HIGH;
 ET6204_ALL_OFF();
 if (get_phnset_led_setting() == 0)
 {
  ET6204_ALL_OFF();
  Poweroff_ET6204();
  return;
 }

 if(play_data->type == 0xf0) 
 {
  et6204_incoming_flag=TRUE;
  flash_count = 0;
  et6204_incoming_number[et6204_incoming_length] = 0x30+10; //jacky added
  et6204_incoming_length ++;  
  mmi_incoming_start_et6204_ind_nubmer();
  return;
 } 
/* else if(play_data->type == 0x02) 
 {
  et6204_audioplayer_flag = TRUE;
  mmi_audioplayer_start_et6204_ind();
  return;
 }*/  
 else
 {
  g_led_count = 0;
  g_ec6204_type = play_data->type;
  g_ec6204_play_num = play_data->play_num;
  mmi_start_et6204();
 }
}
  訊息傳送,主要是如何填充訊息和傳送函式OslMsgSendExtQueue:

void  mmi_et6204_stop_display()
{
 MYQUEUE Message;
 et6204_light_play_ind *et6204_play_req;

 ET6204_POWER_LOW;
 et6204_incoming_flag = FALSE;
 et6204_poweron_flag = FALSE;
 et6204_audioplayer_flag = FALSE; 
 /*----------------------------------------------------------------*/
 /* Code Body                                                      */
 /*----------------------------------------------------------------*/
 Message.oslMsgId = MSG_ID_FLASHLIGHT_STOP_REQ;
 et6204_play_req = OslConstructDataPtr(sizeof(et6204_light_play_ind));
 et6204_play_req->type= 1;

 Message.oslDataPtr = (oslParaType*) et6204_play_req;
 Message.oslPeerBuffPtr = NULL;
 Message.oslSrcId = MOD_MMI;
 Message.oslDestId = MOD_FLASHLIGHT;
 OslMsgSendExtQueue(&Message);
 return;
}
void mmi_et6204_start_display(kal_uint8 type,kal_uint8 play_num)
{
 MYQUEUE Message;
 et6204_light_play_ind *et6204_play_req;
 //kal_prompt_trace(MOD_BMT,"mmi_et6204_start_display::");
 /*----------------------------------------------------------------*/
 /* Code Body                                                      */
 /*----------------------------------------------------------------*/
 StopTimer(LED_FLASH_TIMER); 
 Message.oslMsgId = MSG_ID_FLASHLIGHT_PLAY_REQ;
 et6204_play_req = OslConstructDataPtr(sizeof(et6204_light_play_ind));
 et6204_play_req->type= type;
 et6204_play_req->play_num= play_num;
 
 Message.oslDataPtr = (oslParaType*) et6204_play_req;
 Message.oslPeerBuffPtr = NULL;
 Message.oslSrcId = MOD_MMI;
 Message.oslDestId = MOD_FLASHLIGHT;
 OslMsgSendExtQueue(&Message);
 return;
}

資料結構:

typedef struct  __et6204_light_play_ind
{
 LOCAL_PARA_HDR
 kal_uint8 type;
 kal_uint8 play_num;  
}et6204_light_play_ind;

typedef enum
{
 ET6204_POWER_ON,
 ET6204_INCOMING_IND, 
 ET6204_POWER_OFF,
 ET6204_AUDIOPLAYER, 
 ET6204_NEW_MESSAGE, 
 ET6204_END 
}ET6204_LIGHT_ID;

相關文章