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

📄 rvt_api.c

📁 是一个手机功能的模拟程序
💻 C
字号:
/**************************************************************************
 *			
 * rvt_api.c
 *
 * This module defines the interface of Trace Module
 *
 * (C) Texas Instruments, all rights reserved
 *
 * Version number	: 0.1
 *
 * History			: 0.1 (7/5/2000) - Created
 *
 * Date             : 7/5/2000
 *
 * Author           : Guido Pagana    g-pagana@ti.com															  *
***************************************************************************/



#include "general.h"
#include "rv_general.h"
#include "rvf_api.h"
#include "rvm_use_id_list.h"

#include "rvt_gen.h"
#include "rvt_def_i.h"
#include "rvt_env.h"
#include "rvt_env_i.h"

#include <string.h>


extern UINT32 rvf_lost_msg_cpt;

/*
** Trace User data base global variable
*/
T_RVT_USER_DB rvt_user_db [] = RVT_USER_ID_MAPPING;

extern T_RVT_TRACE_RQST * rvt_lost_msg_ptr;

extern UINT8 rvf_trace_level;

extern UINT32 rvf_layer_mask;

/* External functions declaration */
extern char Num2Char(UINT8 value);


/********************************************************************************/
/*                                                                              */
/*    Function Name:   rvt_set_trace_level                                      */
/*                                                                              */
/*    Purpose:         Updating the level of filtering, as well as the 32-bit   */
/*                     mask related to the software entities to be monitored,   */
/*                     according to the PC.                                     */
/*                                                                              */
/*    Note:            None.                                                    */
/*                                                                              */
/********************************************************************************/
void rvt_set_trace_level (T_RVT_BUFFER p_msg, UINT16 msg_length)
{

	/* Checking for an invalid PDU. */
	if ((p_msg == NULL) || \
		(msg_length != (sizeof (UINT8) + sizeof (UINT32))))
	{
		return;
	}

	/* Update the level of filtering. */
	if (*p_msg <= RV_TRACE_LEVEL_DEBUG_LOW)
	{
		rvf_trace_level = *p_msg;
	}

	/* Update the 32-bit mask related to the software entities to be monitored.
	Note that the 32-bit mask is transmitted LSB first. */
	rvf_layer_mask = *(++p_msg);
	rvf_layer_mask |= *(++p_msg) << 8;
	rvf_layer_mask |= *(++p_msg) << 16;
	rvf_layer_mask |= *(++p_msg) << 24;
}


/********************************************************************************/
/*                                                                              */
/*    Function Name:   rvt_send_trace_no_copy									*/
/*                                                                              */
/*    Purpose:         This function is used send trace messages without        */
/*                     copying.                                                 */
/*                                                                              */
/*    Note:                                                                     */
/*        WARNING!!!! The buffer containing the message has been allocated      */
/*        by the trace module!!!                                                */
/*                                                                              */
/********************************************************************************/

T_RVT_RET
rvt_send_trace_no_cpy(	T_RVT_BUFFER msg, 
						T_RVT_USER_ID user_id, 
						T_RVT_MSG_LG msg_length, 
						T_RVT_FORMAT msg_format)
{
	/* Shift the pointer back to write control values */
	T_RVT_TRACE_RQST * req_msg = (T_RVT_TRACE_RQST * )((UINT8*)msg - RVT_HEADER_SIZE);

	/* Check is Trace Module is running	*/
	if (rvt_module_state != RVT_STARTED)
	{
		return RVT_NOT_READY;
	}

    
	/* Add the id, size and format of the msg at the beginning */	
	
	req_msg->header.msg_id		= RVT_TRACE_RQST_ID;
	req_msg->format				= msg_format;
	req_msg->user_id			= user_id;
	req_msg->msg_length			= msg_length;
	req_msg->do_not_free		= 0;
    
	
	rvf_send_msg (rvt_addr_id, (void *) req_msg);
	
	return RVT_OK;
}		


/********************************************************************************/
/*                                                                              */
/*    Function Name:   send trace copy											*/
/*                                                                              */
/*    Purpose:         this function sends traces with copy						*/
/*																				*/
/*    Note:                                                                     */
/*        No check on id parameter !!!! Must be done in PC.                     */
/*                                                                              */
/********************************************************************************/
T_RVT_RET rvt_send_trace_cpy (T_RVT_BUFFER msg, 
						T_RVT_USER_ID user_id, 
						T_RVT_MSG_LG msg_length, 
						T_RVT_FORMAT msg_format)

		

{
	T_RVT_TRACE_RQST * req ;
	T_RVT_MSG_LG i;

	/* Check is Trace Module is running	*/
	if (rvt_module_state != RVT_STARTED)
	{
		return RVT_NOT_READY;
	}
	
	/* Allocate memory (msg_length + necessary room for the header)	*/
	if ((rvf_get_buf (rvt_mb_id, (UINT32) msg_length + RVT_HEADER_SIZE,	(T_RVF_BUFFER**) &req)) == RVF_RED)
	{
		rvf_lost_msg_cpt ++;

		/* try to send a message if necessary to inform that we are losing traces */
		if( (rvf_lost_msg_cpt > RVT_MAX_LOST_TRACE_MSG)&&
			(rvt_lost_msg_ptr != NULL) )
		{	UINT8 j;
			T_RVT_TRACE_RQST * temp_lost_msg = rvt_lost_msg_ptr;
			UINT32 temp_lost_cpt = rvf_lost_msg_cpt;
			rvt_lost_msg_ptr = NULL;
			rvf_lost_msg_cpt = 0;
			/* add the number of lost msg */
			for (j=0; j<8; j++)
			{
				((UINT8*)temp_lost_msg)[sizeof(T_RVT_TRACE_RQST)+ 24 + j] = Num2Char((UINT8)((temp_lost_cpt<<(j*4))>>28)); 
			}
			temp_lost_msg->msg_length = 24 + 8;
			rvf_send_msg(rvt_addr_id, (void *) temp_lost_msg);
		}

		return RVT_MEMORY_ERR;
	}

 	/* Add the id, size and format of the msg at the beginning */	
	req->header.msg_id		= RVT_TRACE_RQST_ID;
	req->format				= msg_format;
	req->user_id			= user_id;
	req->msg_length			= msg_length;
	req->do_not_free		= 0;

	/* Copy the message	*/
	memcpy( (UINT8*)req + RVT_HEADER_SIZE, msg, msg_length);  

	/*
	** Send it as a message to Trace Task
	*/
	rvf_send_msg(rvt_addr_id, (void *) req);

	return RVT_OK;
}



/********************************************************************************/
/*                                                                              */
/*    Function Name:   rvt_register_id											*/
/*                                                                              */
/*    Purpose:         function rvt_register id									*/
/*					   returns 0 if string not found, else the number			*/
/*					   stocked in the array										*/
/*                                                                              */
/*    Note:                                                                     */
/*        uses two arrays, one that stockes the messages,and another for the	*/
/*        correspondent values.                                                 */
/*                                                                              */
/********************************************************************************/

T_RVT_RET rvt_register_id(T_RVT_NAME name[], T_RVT_USER_ID *rvt_id, RVT_CALLBACK_FUNC callback)
{
	UINT8 i;

	/*looks in the array if the message is stocked */
	for (i=0;rvt_user_db[i].user_id!=RVT_INVALID_HEADER;i++)
	{
	 if (rvt_name_cmp(rvt_user_db[i].user_name,name))
	 {
	 	*rvt_id = rvt_user_db[i].user_id;
	 	rvt_user_db[i].rx_callback_func = callback;
	 	return(RVT_OK);
	 }			
	}
	
	/*else returns zero */
	return (RVT_INVALID_PARAMETER);

}




/********************************************************************************/
/*                                                                              */
/*    Function Name:   rvt_mem_alloc											*/
/*                                                                              */
/*    Purpose:         this function allocates a buffer for tracing.			*/
/*																				*/
/*    Note:                                                                     */
/*        None.                                                                 */
/*                                                                              */
/********************************************************************************/
T_RVT_RET rvt_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_length, T_RVT_BUFFER * buff)
{
	T_RVF_MB_STATUS return_value;

	if (rvt_module_state != RVT_STARTED)
	{
		*buff = NULL;
		return RVT_NOT_READY;
	}
	

	return_value = rvf_get_buf (rvt_mb_id, (UINT32) buffer_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff);

	if (return_value == RVF_RED)
	{
		*buff = NULL;
		rvf_lost_msg_cpt ++;
		
		/* try to send a message if necessary to inform that we are losing traces */
		if( (rvf_lost_msg_cpt > RVT_MAX_LOST_TRACE_MSG)&&
			(rvt_lost_msg_ptr != NULL) )
		{	UINT8 j;
			T_RVT_TRACE_RQST * temp_lost_msg = rvt_lost_msg_ptr;
			UINT32 temp_lost_cpt = rvf_lost_msg_cpt;
			rvt_lost_msg_ptr = NULL;
			rvf_lost_msg_cpt = 0;
			/* add the number of lost msg */
			for (j=0; j<8; j++)
			{
				((UINT8*)temp_lost_msg)[sizeof(T_RVT_TRACE_RQST)+ 24 + j] = Num2Char((UINT8)((temp_lost_cpt<<(j*4))>>28)); 
			}
			temp_lost_msg->msg_length = 24 + 8;
			rvf_send_msg(rvt_addr_id, (void *) temp_lost_msg);
		}

		return RVT_MEMORY_ERR;
	}
	else
	{
		*buff = *buff + RVT_HEADER_SIZE;
		return RVT_OK;
	}
}


/********************************************************************************/
/*                                                                              */
/*    Function Name:   rvt_mem_free												*/
/*                                                                              */
/*    Purpose:      this function frees an allocated buffer for the trace task	*/
/*																				*/
/*    Note:                                                                     */
/*        None.                                                                 */
/*                                                                              */
/********************************************************************************/
T_RVT_RET rvt_mem_free(T_RVT_BUFFER msg)
{
	T_RVF_RET return_value;

	/*
	** Shift the pointer back to write control values
	*/
	char *buff = (char*) msg - RVT_HEADER_SIZE;

    // Deallocates the buffer
    return_value = rvf_free_buf((T_RVF_BUFFER*) buff);

	if (return_value == RVF_MEMORY_ERR)
	{
		return RVT_MEMORY_ERR;
	}
	else
	{
		return RVT_OK;
	}
}


/*
** User function used to compare name
*/
BOOLEAN rvt_name_cmp( char * str1, char * str2)
{	UINT8 i;
	for ( i = 0; (str1[i] == str2[i]) && (str1[i] != 0) && (str2[i] != 0) && (i < RVT_NAME_MAX_LEN); i++ );
	if ( i == RVT_NAME_MAX_LEN)
	{	return TRUE;
	}
	if ( (str1[i] == 0) && (str2[i] == 0) )
	{	return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

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