⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kpd_process_internal_msg.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
 * @file   kpd_process_internal_msg.c
 *
 * Implementation of Keypad functions.
 * These functions implement the keypad processing for all the messages the
 * keypad task can receive.
 *
 * @author   Laurent Sollier (l-sollier@ti.com)
 * @version 0.1
 */

/*
 * History:
 *
 *   Date          Author       Modification
 *  ----------------------------------------
 *  10/10/2001     L Sollier    Create
 *
 *
 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
 */

#include "kpd_api.h"
#include "kpd_env.h"
#include "kpd_i.h"
#include "kpd_virtual_key_table_mgt.h"
#include "kpd_physical_key_def.h"

#include "rvf_api.h"
#include "rvm_use_id_list.h"

#include <string.h>

/* External declaration */
extern T_KPD_ENV_CTRL_BLK* kpd_env_ctrl_blk;


/* Definition of the wait time in the loop */
#ifdef _WINDOWS
   #define WAIT_TIME_LOOP (50)
#else
   #define WAIT_TIME_LOOP (10)
#endif


/* This structure gathers informations about one physical key Id.
   It define if subscriber is notified for this physical key */
typedef struct {  UINT32   subscriber_mask;
               }  T_PHYSICAL_KEY_MASK;


/** Definition of a set of keys with repeat keys parameters. */
typedef struct {  UINT8                nb_notified_keys;
                  UINT16               long_press_time; /* in ms */
                  UINT16               repeat_time; /* in ms */
                  T_KPD_NOTIF_LEVEL    notif_level[KPD_NB_PHYSICAL_KEYS];
               } T_PHYSICAL_KEY_PARAM_TABLE;


/* This structure gather general informations about subscriber id */
typedef struct {  T_RV_RETURN return_path;
                  T_KPD_MODE mode;
                  T_PHYSICAL_KEY_PARAM_TABLE notified_keys;
               } T_SUBSCRIBER_INFOS;


/* Informations for all the physical keys Id.
   This variable is updated each time a client subscribe to the keypad driver,
   unsubscribe, or change notification key level.
   Warn that position of the physical key Id is implicit cause of the rule
   used to define the vpm table */
static T_PHYSICAL_KEY_MASK physical_key_mask[KPD_NB_PHYSICAL_KEYS] = {0};

/* Informations for all the subscribers */
static T_SUBSCRIBER_INFOS* subscriber_infos[KPD_MAX_SUBSCRIBER] = {0};



/**
 * @name Functions implementation
 *
 */
/*@{*/

/**
 * function: kpd_return_path_already_defined
 */
static BOOL kpd_return_path_already_defined(T_RV_RETURN return_path)
{
   UINT8 i;
   BOOL ret = FALSE;

   for (i = 0; i < KPD_MAX_SUBSCRIBER; i++)
      if ( subscriber_infos[i] != 0 )
         if (subscriber_infos[i]->return_path.callback_func != 0)
         {
            if (subscriber_infos[i]->return_path.callback_func == return_path.callback_func)
            {
               ret = TRUE;
               break;
            }
         }
         else
         {
            if (subscriber_infos[i]->return_path.addr_id == return_path.addr_id)
            {
               ret = TRUE;
               break;
            }
         }

   return ret;
}

/**
 * function: kpd_subscribe_i
 */
T_RV_RET kpd_subscribe_i(T_SUBSCRIBER_ID subscriber_id,
                         T_KPD_MODE mode,
                         T_KPD_VIRTUAL_KEY_TABLE* notified_keys,
                         T_RV_RETURN return_path)
{
   INT8 i, position;
   T_RVF_MB_STATUS mb_status;
   T_RV_RET ret;

   /* Check the validity of the key table */
   ret = kpd_check_key_table(notified_keys, mode);

   if (ret != RV_OK)
   {
      /* Remove subscriber id because id was reserved */
      kpd_remove_subscriber(subscriber_id);

      /* Send error message */
      kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_KEYS_TABLE, return_path);
   }
   else
   {
      if (kpd_return_path_already_defined(return_path) == TRUE)
      {
         /* Remove subscriber id because id was reserved */
         kpd_remove_subscriber(subscriber_id);

         /* Send error message */
         kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_RETURN_PATH_EXISTING, return_path);

         ret = RV_INVALID_PARAMETER;
      }
      else
      {      
         /* Update subscriber informations */
         /* ------------------------------ */

         /* Reserve memory for subscriber informations */
         mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id,
                                  sizeof(T_SUBSCRIBER_INFOS),
                                  (void **) &subscriber_infos[subscriber_id]);

         if (mb_status != RVF_RED) /* Memory allocation success */
         {
            /* Initialize structure */
            memset(subscriber_infos[subscriber_id], 0, sizeof(T_SUBSCRIBER_INFOS));

            /* Fill the subscriber structure */
            subscriber_infos[subscriber_id]->mode = mode;
            subscriber_infos[subscriber_id]->return_path = return_path;
            subscriber_infos[subscriber_id]->notified_keys.nb_notified_keys = notified_keys->nb_notified_keys;
            subscriber_infos[subscriber_id]->notified_keys.long_press_time = 0;
            subscriber_infos[subscriber_id]->notified_keys.repeat_time = 0;
            for (i = 0; i < notified_keys->nb_notified_keys; i++)
            {
               /* Retrieve physical key Id from virtual key_id */
               kpd_retrieve_virtual_key_position(  notified_keys->notified_keys[i],
                                                   mode,
                                                   &position);

               subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = KPD_RELEASE_NOTIF;
            }

            /* Update link (ID <-> key) */
            /* ------------------------ */
            for (i = 0; i < notified_keys->nb_notified_keys; i++)
            {
               /* Retrieve position in vpm table */
               kpd_retrieve_virtual_key_position(notified_keys->notified_keys[i],
                                                 mode,
                                                 &position);

               /* Update subscriber mask for the physical key */
               physical_key_mask[position].subscriber_mask |= (1<<subscriber_id);

            }

            /* Send success message to suscriber */
            kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_PROCESS_OK, return_path);
         }
         else
         {
            KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);

            /* Remove subscriber id because id was reserved */
            kpd_remove_subscriber(subscriber_id);

            /* Send error message to suscriber */
            kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_INTERNAL, return_path);
         }
      }
   }

   return RV_OK;
}


/**
 * function: kpd_unsubscribe_i
 */
T_RV_RET kpd_unsubscribe_i(T_SUBSCRIBER_ID subscriber_id)
{
   UINT8 i;

   /* Delete subscriber informations */
   rvf_free_buf(subscriber_infos[subscriber_id]);
   subscriber_infos[subscriber_id] = 0;

   /* Delete link (ID <-> key) */
   for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++)
   {
      physical_key_mask[i].subscriber_mask &= ~(1<<subscriber_id);
   }

   /* If the subscriber is the keypad owner, this privilege is unset */
   if (kpd_is_owner_keypad(subscriber_id) == TRUE)
      kpd_set_keypad_mode(MN_MODE);

   return RV_OK;
}


/**
 * function: kpd_define_key_notification_i
 */
T_RV_RET kpd_define_key_notification_i(T_SUBSCRIBER_ID subscriber_id,
                                       T_KPD_VIRTUAL_KEY_TABLE* notif_key_table,
                                       T_KPD_NOTIF_LEVEL notif_level,
                                       UINT16 long_press_time,
                                       UINT16 repeat_time)
{
   T_RV_RET ret = RV_OK;
   UINT8 i;
   INT8 position;

   /* Check the validity of the key table */
   ret = kpd_check_key_table(notif_key_table, subscriber_infos[subscriber_id]->mode);

   if (ret != RV_OK)
   {
      /* Send error message */
      kpd_send_status_message(KPD_REPEAT_KEYS_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path);

   }
   else
   {
      /* Update subscriber informations */
      /* ------------------------------ */
      subscriber_infos[subscriber_id]->notified_keys.long_press_time = long_press_time*100;
      subscriber_infos[subscriber_id]->notified_keys.repeat_time = repeat_time*100;

      for (i = 0; i < notif_key_table->nb_notified_keys; i++)
      {
         /* Retrieve physical key Id from virtual key_id */
         kpd_retrieve_virtual_key_position(  notif_key_table->notified_keys[i],
                                             subscriber_infos[subscriber_id]->mode,
                                             &position);

         /* Check if subscriber have asked notification for this key at subscription */
         if ( physical_key_mask[position].subscriber_mask & (1<<subscriber_id) )
            subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = notif_level;
      }

      /* Send success message to suscriber */
      kpd_send_status_message(KPD_REPEAT_KEYS_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path);
   }

   return ret;
}


/**
 * function: kpd_change_mode_i
 */
T_RV_RET kpd_change_mode_i(T_SUBSCRIBER_ID subscriber_id,
                           T_KPD_VIRTUAL_KEY_TABLE* notified_keys,
                           T_KPD_MODE new_mode)
{
   UINT8 i;
   INT8 position;
   T_RV_RET ret;

   /* Check the validity of the key table */
   ret = kpd_check_key_table(notified_keys, new_mode);

   if (ret != RV_OK)
   {
      /* Send error message */
      kpd_send_status_message(KPD_CHANGE_MODE_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path);
   }
   else
   {
      /* Delete link (ID <-> key) for old mode*/
      for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++)
      {
         physical_key_mask[i].subscriber_mask &= ~(1<<subscriber_id);
         subscriber_infos[subscriber_id]->notified_keys.notif_level[i] = KPD_NO_NOTIF;
      }

      /* Update subscriber structure */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -