MTK平台学习----消息通讯机制


一、基础知识

        使用消息循环机制之前,我们先来认识几个数据结构

         typedef struct ilm_struct

           {
                    module_type                 src_mod_id;
                    module_type                 dest_mod_id;
                    sap_type                        sap_id;
                    msg_type                       msg_id;
                    local_para_struct *       local_para_ptr;
                    peer_buff_struct  *        peer_buff_ptr;
           } ilm_struct;

         其中各参数的含义如下:

          src_mod_id          ----         请求服务的MOD_ID

          dest_mod_id        ----         接收服务的MOD_ID

          sap_id                    ----         服务请求标示,没有可以填0

          msg_id                   ----         消息的ID号

          local_para_struct  ----        请求需要提供的附加信息,如果有参数需要随MSG一起传入,

                                                         则让这个指针指向相应的数据结构即可

          peer_buff_struct    ----        请求需要提供的附加信息,如果有参数需要随MSG一起传入,

                                                         则让这个指针指向相应的数据结构即可

         系统运行中,会首先调用recive_msg_exq_q从外部消息队列中获取消息,如果消息队列中

         有消息,则立即返回待处理的消息,否则recive_msg_ext_q函数将阻塞Task,直到有消息

          进入消息队列。所以其消息循环机制也就是任务获取其外部队列的消息,然后根据不同的消

          息ID调用不同的处理函数。

二、消息通讯的实例

        任务1接收从键盘输入的字符,然后将输入的字符通过消息队列的形式传送到另外一个任务中。

        函数1:传递消息的函数,此函数对消息结构体进行装填

  1. void SendNoticeMessage( module_type SRCMOD, module_type DESTMOD, kal_uint16 MSGID )  
  2. {  
  3.     ilm_struct *send_ilm;  
  4.     send_ilm = allocate_ilm(SRCMOD);  
  5.     ASSERT(send_ilm);  
  6.     memset( send_ilm, 0, sizeof( ilm_struct ) );  
  7.     send_ilm->src_mod_id = SRCMOD;  
  8.     send_ilm->dest_mod_id = DESTMOD;  
  9.     send_ilm->msg_id = MSGID;  
  10.     msg_send_ext_queue(send_ilm);  
  11. }  

        函数2:消息发送方所属的进程为FD_SHELL,接收方所处的进程为FD_TEST1

      

  1. int sh_input(int argc, char *argv[])  
  2. {  
  3.     char szstr[10];  
  4.     char dat = 0;  
  5.     dat = *argv[1] - '0';  
  6.     sprintf(szstr,"input %c",*argv[1]);  
  7.     SendNoticeMessage(MOD_FD_SHELL,MOD_FD_TEST1,dat);   //  
  1. }  

          函数3:消息接收方的处理

  1. static void fd_test1_fun(task_entry_struct * task_entry_ptr)  
  2. {  
  3. ilm_struct current_ilm;  
  4. Uart_printf("test1 task is run\r\n");  
  5. Uart_printf("Hello world\r\n");  
  6.   
  7. while(1)  
  8.    {  
  9.        receive_msg_ext_q(task_info_g[task_entry_ptr->task_indx].task_ext_qid, ¤t_ilm);  
  10.        switch (current_ilm.msg_id)  
  11.     {  
  12.         case 1:  
  13.                Uart_printf("Test1 task recive msg 1\r\n");  
  14.                break;  
  15.         case 2:  
  16.             Uart_printf("Test1 task recive msg 2\r\n");  
  17.             break;  
  18.         case 3:  
  19.             Uart_printf("Test1 task recive msg 3\r\n");  
  20.             break;  
  21.         case 4:  
  22.             Uart_printf("Test1 task recive msg 4\r\n");  
  23.             break;  
  24.         default:  
  25.             Uart_printf("The argument can not distingishi\r\n");  
  26.             break;  
  27.                   
  28.     }  
  1. free_ilm(¤t_ilm); //释放存储消息的结构体变量  
  1. }  
  1. }  
  1. 以上就是MTK消息通讯以及消息的处理过程,上面的例程虽然简单,但是包含了消息的处理思想,其他的复杂的模块如MMI的消息处理过程跟上面的原理是一样的。  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值