📄 em.c
字号:
/*
+-----------------------------------------------------------------------------
| Project : GSM-PS
| Modul : DRV_RX
+-----------------------------------------------------------------------------
| Copyright 2002 Texas Instruments Berlin, AG
| All rights reserved.
|
| This file is confidential and a trade secret of Texas
| Instruments Berlin, AG
| The receipt of or possession of this file does not convey
| any rights to reproduce or disclose its contents or to
| manufacture, use, or sell anything it may describe, in
| whole, or in part, without the specific written consent of
| Texas Instruments Berlin, AG.
+-----------------------------------------------------------------------------
| Purpose : This Module defines the engineering mode
| device driver for the G23 protocol stack.
|
| This driver is used to control all engineering mode related
| functions.
+-----------------------------------------------------------------------------
*/
#ifndef DRV_EM_C
#define DRV_EM_C
#define ENTITY_CST
/*==== INCLUDES ===================================================*/
#if defined (NEW_FRAME)
#include <string.h>
#include "typedefs.h"
#include "vsi.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "gdi.h"
#include "em.h"
#else
#include <string.h>
#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "vsi.h"
#include "gdi.h"
#include "em.h"
#endif
/*==== EXPORT =====================================================*/
/*==== VARIABLES ==================================================*/
#define EV_BUFFER_SIZE 512
#if defined (NEW_FRAME)
EXTERN USHORT cst_handle;
#endif
UBYTE ev_enabled = FALSE;
USHORT ev_first_read;
USHORT ev_first_write;
USHORT ev_size;
UBYTE ev_buffer [EV_BUFFER_SIZE];
/*==== FUNCTIONS ==================================================*/
LOCAL void em_get_size (UBYTE size);
LOCAL UBYTE em_check_em_class_infra_data (UBYTE em_subclass,
UBYTE em_type,
em_data_type * out_em_data);
LOCAL UBYTE em_check_em_subclass_sc_info (UBYTE em_type,
em_data_type * out_em_data);
LOCAL UBYTE em_check_em_subclass_nc_info (UBYTE em_type,
em_data_type * out_em_data);
LOCAL UBYTE em_check_em_subclass_lup_and_pag (UBYTE em_type,
em_data_type * out_em_data);
/*==== CONSTANTS ==================================================*/
#ifndef FF_EM_MODE
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Init |
+--------------------------------------------------------------------+
PURPOSE : The function initializes the driver磗 internal data.
The function returns DRV_OK in case of a successful
completition. The function returns DRV_INITIALIZED if
the driver has already been initialized and is ready to
be used or is already in use. In case of an initialization
failure, which means the that the driver cannot be used,
the function returns DRV_INITFAILURE.
*/
GLOBAL UBYTE em_Init (void)
{
ev_enabled = FALSE;
return DRV_OK;
}
#endif /* FF_EM_MODE */
#ifndef FF_EM_MODE
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Exit |
+--------------------------------------------------------------------+
PURPOSE : The function is used to indicate that the driver
and its functionality isn磘 needed anymore.
*/
GLOBAL void em_Exit (void)
{
}
#endif /* FF_EM_MODE */
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Read_Parameter |
+--------------------------------------------------------------------+
PURPOSE : This function is used to read a parameter of the mobile.
*/
GLOBAL UBYTE em_Read_Parameter (UBYTE em_class,
UBYTE em_subclass,
UBYTE em_type,
em_data_type * out_em_data)
{
switch (em_class)
{
case EM_CLASS_INFRA_DATA:
return (em_check_em_class_infra_data (em_subclass, em_type, out_em_data));
default:
return EM_INVALID_CLASS;
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Enable_Post_Mortem |
+--------------------------------------------------------------------+
PURPOSE : This function enables recording of event data in the
post mortem memory.
*/
GLOBAL UBYTE em_Enable_Post_Mortem ()
{
ev_first_read = 0;
ev_first_write = 0;
ev_size = EV_BUFFER_SIZE;
ev_enabled = TRUE;
return DRV_OK;
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Disable_Post_Mortem |
+--------------------------------------------------------------------+
PURPOSE : This function disables recording of event data in the
post mortem memory and allows reading of the data.
*/
GLOBAL UBYTE em_Disable_Post_Mortem ()
{
ev_enabled = FALSE;
return DRV_OK;
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103) MODULE : DRV_EM |
| STATE : code ROUTINE : em_Read_Post_Mortem |
+--------------------------------------------------------------------+
PURPOSE : This function is used to read a parameter of the
post mortem memory.
*/
GLOBAL UBYTE em_Read_Post_Mortem (em_data_type * out_em_data)
{
UBYTE subclass;
UBYTE i;
#if defined (WIN32)
char buf[60];
sprintf (buf, "before %d %d read", ev_first_read, ev_first_write);
TRACE_EVENT (buf);
#endif
if (ev_enabled EQ FALSE)
{
if (ev_size EQ EV_BUFFER_SIZE)
return EM_NO_MORE_DATA;
out_em_data->em_class = EM_CLASS_EVENT_TRACE;
subclass = ev_buffer [ev_first_read++];
out_em_data->em_subclass = subclass & 0x3F;
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
out_em_data->em_type = ev_buffer [ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
#if defined (WIN32)
sprintf (buf, "subclass %x read", subclass);
TRACE_EVENT (buf);
#endif
switch (subclass & 0xC0)
{
case 0x00:
// single entry
ev_size += 2;
out_em_data->em_length = 0;
break;
case 0x40:
// ubyte entry
ev_size += 3;
out_em_data->em_length = 1;
out_em_data->em_parameter[0] = ev_buffer [ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
break;
case 0x80:
// ushort entry
ev_size += 4;
out_em_data->em_length = 2;
out_em_data->em_parameter[0] = ev_buffer [ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
out_em_data->em_parameter[1] = ev_buffer [ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
break;
case 0xC0:
// array entry
// skip to length
out_em_data->em_length = ev_buffer [ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
for (i=0;i<out_em_data->em_length;i++)
{
out_em_data->em_parameter[i] = ev_buffer[ev_first_read++];
if (ev_first_read >= EV_BUFFER_SIZE)
ev_first_read -= EV_BUFFER_SIZE;
}
ev_size += (out_em_data->em_length+3);
break;
}
#if defined (WIN32)
sprintf (buf, "after %d %d read", ev_first_read, ev_first_write);
TRACE_EVENT (buf);
#endif
return DRV_OK;
}
else
{
return EM_INVALID_ACCESS;
}
}
/*
*************************************************************************************
*
* Internal Functions
*
*************************************************************************************
*/
/*
* the internal event buffer is organised as a ring buffer. Using different
* access functions the data is stored in one of the four following ways:
*
* SINGLE TRACE (no parameter)
*
* Byte 1: 00 xxxxxx subclass
* Byte 2: yyyyyyyyy type
*
* UBYTE TRACE (one byte parameter)
*
* Byte 1: 01 xxxxxx subclass
* Byte 2: yyyyyyyyy type
* Byte 3: zzzzzzzzz parameter
*
* USHORT TRACE (two bytes parameter)
*
* Byte 1: 10 xxxxxx subclass
* Byte 2: yyyyyyyyy type
* Byte 3: zzzzzzzzz parameter
* Byte 4: zzzzzzzzz parameter
*
* ARRAY TRACE (n bytes parameter)
*
* Byte 1: 11 xxxxxx subclass
* Byte 2: yyyyyyyyy type
* Byte 3: aaaaaaaaa len
* Byte 4-n+3: zzzzzzzzz parameter
*
* The parameter ev_enabled defines whether recording is enabled or not.
* after power on it is disabled.
*
* The parameter ev_first_read indicates the first position in the ev_buffer
* which shall be read.
*
* The parameter ev_first_write indicates the first position in the ev_buffer
* which shall be used for the next recorded event.
*
* The parameter ev_size defines the free memory in the ev_buffer. If the next
* write event is greater than the free memory the ev_first_read is changed to
* have enough memory.
*
*/
GLOBAL void em_trace_single (UBYTE class,
UBYTE subclass,
UBYTE type)
{
#if defined (WIN32)
char buf[60];
#endif
TRACE_FUNCTION ("em_trace_single");
#if defined (WIN32)
sprintf (buf, "before %d %d Single", ev_first_read, ev_first_write);
TRACE_EVENT (buf);
#endif
if (ev_enabled)
{
// get memory if needed
em_get_size (2);
// write subclass
ev_buffer[ev_first_write++] = subclass;
if (ev_first_write >= EV_BUFFER_SIZE)
ev_first_write -= EV_BUFFER_SIZE;
// write type
ev_buffer[ev_first_write++] = type;
if (ev_first_write >= EV_BUFFER_SIZE)
ev_first_write -= EV_BUFFER_SIZE;
ev_size -= 2;
}
#if defined (WIN32)
sprintf (buf, "after %d %d Single", ev_first_read, ev_first_write);
TRACE_EVENT (buf);
#endif
}
GLOBAL void em_trace_ubyte (UBYTE class,
UBYTE subclass,
UBYTE type,
UBYTE para_ubyte)
{
#if defined (WIN32)
char buf[60];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -