kpd_api.c
来自「是一个手机功能的模拟程序」· C语言 代码 · 共 457 行 · 第 1/2 页
C
457 行
/**
* @file kpd_api.c
*
* Implementation of bridge functions.
*
* @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_virtual_key_table_mgt.h"
#include "kpd_messages_i.h"
#include "kpd_process_internal_msg.h"
#include "kpd_env.h"
#include "rvm_use_id_list.h"
/* Include file to delete when Kp global variable will be useless */
/* Delete variable Kp below */
#include "kpd_power_api.h"
/** External declaration */
extern T_KPD_ENV_CTRL_BLK* kpd_env_ctrl_blk;
extern T_KPD_KEYPAD Kp;
/**
* @name Bridge functions implementation
*
*/
/*@{*/
/**
* function: kpd_subscribe
*/
T_RV_RET kpd_subscribe(T_KPD_SUBSCRIBER* subscriber_p,
T_KPD_MODE mode,
T_KPD_VIRTUAL_KEY_TABLE* notified_keys_p,
T_RV_RETURN return_path)
{
T_RVF_MB_STATUS mb_status;
T_KPD_SUBSCRIBE_MSG* msg_subscribe_p;
T_SUBSCRIBER* subscriber_struct_p;
T_RV_RET ret = RV_OK;
UINT8 i;
/* Initialization of parameter "subscriber" in order to be sure that client will
not use later the parameter with an non initialized value */
*subscriber_p = 0;
/* Check if initialization has been correctly done */
if ( (kpd_env_ctrl_blk == 0) || (kpd_env_ctrl_blk->swe_is_initialized == FALSE) )
{
KPD_SEND_TRACE("KPD: Initialization is not yet done or failed", RV_TRACE_LEVEL_ERROR);
return RV_INTERNAL_ERR;
}
/* Allocate memory to save subscriber Id */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_SUBSCRIBER), (void **) &subscriber_struct_p);
if (mb_status == RVF_RED)
return RV_MEMORY_ERR;
if ( (notified_keys_p != 0)
&& (notified_keys_p->nb_notified_keys > 0)
&& (notified_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) )
{
/* Reserve subscriber Id */
ret = kpd_add_subscriber(&(subscriber_struct_p->subscriber_id));
if (ret != RV_OK)
rvf_free_buf(subscriber_struct_p);
}
else
{
rvf_free_buf(subscriber_struct_p);
ret = RV_INVALID_PARAMETER;
}
if (ret == RV_OK)
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_SUBSCRIBE_MSG), (void **) &msg_subscribe_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Fill the message */
msg_subscribe_p->hdr.msg_id = KPD_SUBSCRIBE_MSG;
msg_subscribe_p->subscription_info.subscriber_id = subscriber_struct_p->subscriber_id;
msg_subscribe_p->subscription_info.mode = mode;
msg_subscribe_p->subscription_info.return_path = return_path;
msg_subscribe_p->subscription_info.notified_keys.nb_notified_keys = notified_keys_p->nb_notified_keys;
for (i = 0; i < notified_keys_p->nb_notified_keys; i++)
msg_subscribe_p->subscription_info.notified_keys.notified_keys[i] = notified_keys_p->notified_keys[i];
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_subscribe_p);
/* Save subscriber id */
*subscriber_p = (void*)subscriber_struct_p;
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
kpd_remove_subscriber(subscriber_struct_p->subscriber_id);
rvf_free_buf(subscriber_struct_p);
ret = RV_MEMORY_ERR;
}
}
return ret;
}
/**
* function: kpd_unsubscribe
*/
T_RV_RET kpd_unsubscribe(T_KPD_SUBSCRIBER* subscriber_p)
{
T_RVF_MB_STATUS mb_status;
T_KPD_UNSUBSCRIBE_MSG* msg_unsubscribe_p;
T_RV_RET ret = RV_INVALID_PARAMETER;
T_SUBSCRIBER_ID subscriber_id;
/* Check if subscriber id is correct */
if ( kpd_subscriber_id_used(*subscriber_p, &subscriber_id) == TRUE)
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_UNSUBSCRIBE_MSG), (void **) &msg_unsubscribe_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Free subscriber Id */
ret = kpd_remove_subscriber(subscriber_id);
if (ret == RV_OK)
{
/* Fill the message */
msg_unsubscribe_p->hdr.msg_id = KPD_UNSUBSCRIBE_MSG;
msg_unsubscribe_p->subscriber_id = subscriber_id;
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_unsubscribe_p);
rvf_free_buf(*subscriber_p);
*subscriber_p = 0;
}
else
{
rvf_free_buf(msg_unsubscribe_p);
}
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
ret = RV_MEMORY_ERR;
}
}
return ret;
}
/**
* function: kpd_define_key_notification
*/
T_RV_RET kpd_define_key_notification(T_KPD_SUBSCRIBER subscriber,
T_KPD_VIRTUAL_KEY_TABLE* notif_key_table_p,
T_KPD_NOTIF_LEVEL notif_level,
UINT16 long_press_time,
UINT16 repeat_time)
{
T_RV_RET ret = RV_INVALID_PARAMETER;
T_RVF_MB_STATUS mb_status;
T_KPD_NOTIF_KEYS_MSG* msg_notif_key_p;
UINT8 i;
T_SUBSCRIBER_ID subscriber_id;
/* Check if subscriber id is correct */
if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE)
{
if ( (notif_key_table_p != 0)
&& (notif_key_table_p->nb_notified_keys > 0)
&& (notif_key_table_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) )
{
if ( (notif_level == KPD_NO_NOTIF )
||(notif_level & KPD_FIRST_PRESS_NOTIF )
||(notif_level & KPD_RELEASE_NOTIF )
||( (notif_level & KPD_LONG_PRESS_NOTIF) && (long_press_time != 0) )
||( (notif_level & KPD_INFINITE_REPEAT_NOTIF) && (long_press_time != 0) && (repeat_time != 0) ) )
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_NOTIF_KEYS_MSG), (void **) &msg_notif_key_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Fill the message */
msg_notif_key_p->hdr.msg_id = KPD_NOTIF_KEYS_MSG;
msg_notif_key_p->subscriber_id = subscriber_id;
msg_notif_key_p->notif_level = notif_level;
msg_notif_key_p->long_press_time = long_press_time;
msg_notif_key_p->repeat_time = repeat_time;
msg_notif_key_p->notif_key_table.nb_notified_keys = notif_key_table_p->nb_notified_keys;
for (i = 0; i < notif_key_table_p->nb_notified_keys; i++)
msg_notif_key_p->notif_key_table.notified_keys[i] = notif_key_table_p->notified_keys[i];
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_notif_key_p);
ret = RV_OK;
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
ret = RV_MEMORY_ERR;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?