changeset 164:d78219c43fbf

gsm-fw/services/etm: initial import from the Leonardo semi-src
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 18 Nov 2013 06:39:44 +0000
parents 5e0e41cd7c9f
children 9dbf3248a197
files gsm-fw/services/etm/etm.h gsm-fw/services/etm/etm_api.c gsm-fw/services/etm/etm_api.h gsm-fw/services/etm/etm_at.c gsm-fw/services/etm/etm_at.h gsm-fw/services/etm/etm_audio.c gsm-fw/services/etm/etm_audio_err.h gsm-fw/services/etm/etm_env.c gsm-fw/services/etm/etm_env.h gsm-fw/services/etm/etm_messages_i.h gsm-fw/services/etm/etm_misc.h gsm-fw/services/etm/etm_pool_size.h gsm-fw/services/etm/etm_task.c gsm-fw/services/etm/etm_tests.c gsm-fw/services/etm/etm_tmcore.c gsm-fw/services/etm/etm_tmpwr.c gsm-fw/services/etm/etm_trace.c gsm-fw/services/etm/etm_trace.h gsm-fw/services/etm/etm_version.h
diffstat 19 files changed, 3913 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,257 @@
+/******************************************************************************
+ * Enhanced TestMode  (ETM) 
+ * @file              etm.h
+ *
+ * Design and coding  Mads Meisner-Jensen, (mmj@ti.com)
+ *                    Kim T. Petersn,      (ktp@ti.com)
+ *
+ *
+ ******************************************************************************/
+
+
+#ifndef _ETM_H_
+#define _ETM_H_
+
+
+/******************************************************************************
+ * Prototypes and Globals
+ ******************************************************************************/
+
+// Max size of downlink packet payload
+#define ETM_PAYLOAD_MAX 256
+// End Terminator for Tables
+#define TABLE_END -1
+
+struct ioformat_s {
+    const short index;  // index for identifier
+    const char *name;   // parameter
+    const char *format; // parameter data format
+};
+
+
+/******************************************************************************
+ * Global Definitions
+ ******************************************************************************/
+
+// Enhanced TestMode Module IDentifiers
+enum {
+    ETM_TM3        = 0x00, // Use of old TM3 protocol
+    ETM_CORE       = 0x01,
+    ETM_TMT        = 0x02, // Pseudo module
+    ETM_SH         = 0x03, // Pseudo module
+    ETM_TM3_MISC   = 0x04, // Pseudo module - Target side
+    ETM_RF         = 0x05, 
+    ETM_IMEI       = 0x06,
+    ETM_FFS2       = 0x07,
+    ETM_AUDIO      = 0x08,
+    ETM_TPU        = 0x09, // Not official part ETM
+    ETM_PWR        = 0x0A,
+    ETM_BT         = 0x0B,
+    ETM_L23        = 0x0C,
+    ETM_RESERVED10 = 0x0D,
+    ETM_RESERVED11 = 0x0E,
+    ETM_RESERVED12 = 0x0F,
+
+ ETM_CUST      = 0xC0, // Customize id
+    ETM_CUST1      = 0xC1, // Customize id
+    ETM_CUST2      = 0xC2, // Customize id
+    ETM_CUST3      = 0xC3, // Customize id
+    ETM_CUST4      = 0xC4, // Customize id
+    ETM_CUST5      = 0xC5, // Customize id
+    ETM_CUST6      = 0xC6, // Customize id
+    ETM_CUST7      = 0xC7, // Customize id
+    ETM_CUST8      = 0xC8, // Customize id
+
+    ETM_TEST       = 0xAA, // used for test of dll's
+    ETM_TASK       = 0xEE, // ETM TASK in Target
+
+    ETM_FFS1       = 0x70
+};
+
+enum {
+//    ETM_ERROR_MUL  = 100,
+    ETM_CORE_ERROR   = -100 * ETM_CORE,
+    ETM_TMT_ERROR    = -100 * ETM_TMT,
+    ETM_SH_ERROR     = -100 * ETM_SH,
+    ETM_RF_ERROR     = -100 * ETM_RF,
+    ETM_FFS2_ERROR   = -100 * ETM_FFS2,
+    ETM_AUDIO_ERROR  = -100 * ETM_AUDIO,
+    ETM_TPU_ERROR    = -100 * ETM_TPU,
+    ETM_IMEI_ERROR   = -100 * ETM_IMEI,
+    ETM_PWR_ERROR    = -100 * ETM_PWR,
+    ETM_BT_ERROR     = -100 * ETM_BT,
+	ETM_FFS_ERROR    = -100 * ETM_FFS2, 
+
+    ETM_TEST_ERROR   = -100 * ETM_TEST, // used for test of dll's
+
+    ETM_OS_ERROR     = -100 * 1000 // OS Error (specially handled!)
+};
+
+// Module private (normally target-side) errors are in the range: [ -2..-47]
+// Common (normally target-side) errors are in the range:         [-48..-63]
+// Common (normally PC-side) errors are in the range:             [-64..-89]
+// Module private (normally PC-side) errors are in the range:     [-90..-99]
+
+enum ETMCommonTargetErrors {
+    ETM_OK               =   0,   // Ok
+    ETM_FINISHED         =  -1,   // Previously started operation has finished.
+
+    // Errors that are related to the Riv env.
+    ETM_RV_FATAL         = -48,   // Fatal error in RIV environment eg. memory error 
+    ETM_RV_NOT_SUPPORTED = -49,   // Funtionality not supported by RIV
+
+    // Error codes related to L1 Test mode
+    ETM_L1TESTMODE       = -50,   // Layer 1 is not in test mode
+
+    ETM_NOT_USED1        = -51,   //
+    ETM_NOT_USED2        = -52,   //
+    ETM_NOT_USED3        = -53,   //
+    ETM_NOT_USED4        = -54,   //
+
+    // ETM Common Target Errors
+    ETM_MESSAGE          = -55,   // Received unknown message
+    ETM_NOMEM            = -56,   // Out of memory
+    ETM_AGAIN            = -57,   // Not ready, try again later
+    ETM_BADOP            = -58,   // Operation not possible in current context
+    ETM_INVAL            = -59,   // Invalid parameter/argument
+    ETM_NOSYS            = -60,   // Module or function not present
+    ETM_FATAL            = -61,   // System fatal error
+    ETM_PACKET           = -62,   // Packet error (checksum or other)
+    ETM_OK_MORE          = -63    // Ok, more data coming
+};
+
+
+// ETM Common PC-side Errors. The error codes from this section are not to
+// be used directly but should be used like 'ETM_XXX_ERROR + ETM_INVALID',
+// where XXX is the module's name
+enum ETMCommonPCErrors {
+    ETM_INTERNAL    = -64, // Fatal (internal) unrecoverable error
+    ETM_TOOFEWARGS  = -65, // Too few arguments
+
+    ETM_USE         = -67, // Failed to load module
+    ETM_USEAGAIN    = -68, // Module already loaded
+    ETM_USEVERSION  = -69, // Module version incompatible
+
+    ETM_INVALID     = -70, // Invalid parameter/argument
+    ETM_MEMORY      = -71, // Out of memory
+    ETM_BUFFER      = -72, // Buffer too small (maybe internal buffer)
+    ETM_BADDATA     = -73, // Bad/unexpected data in uplink packet
+    ETM_NOSUPPORT   = -74, // Not supported 
+    ETM_BADVALUE    = -75, // Bad argument/parameter value
+
+    ETM_FILE_IO     = -76, // File I/O error (file not found?)
+    ETM_HOST_FIO    = -78  // Host system file I/O error
+};
+
+enum ETMTgTraceMask {
+    TgTrTest      = 0x00000001,
+    TgTrEtmLow    = 0x00000002,
+    TgTrEtmMed    = 0x00000004,
+    TgTrEtmHigh   = 0x00000008,
+    TgTrCore      = 0x00000100,
+    TgTrAudio     = 0x00000200,
+    TgTrFfs       = 0x00000400, 
+    TgTrRf        = 0x00000800,
+    TgTrFatal     = 0x80000000,
+    TgTrAll       = 0xFFFFFFFF
+};
+
+
+/******************************************************************************
+ * Macros
+ ******************************************************************************/
+
+#define if_error_return(myerror) if (myerror < 0) return myerror
+
+// Keyword to use for exporting a DLL function
+#define FEXPORT __stdcall
+
+// Keyword to use for defining a DLL variable as private
+#define PRIVATE
+
+// Keyword to use for defining a DLL variable as private
+#define PUBLIC
+
+
+/******************************************************************************
+ * Tracing
+ ******************************************************************************/
+
+// Trace module IDs
+enum {
+    TrSH          =  1 << 24,
+    TrTMT         =  2 << 24,
+    TrCore        =  3 << 24,
+    TrAUDIO       =  4 << 24,
+    TrFFS         =  5 << 24,
+    TrPWR         =  6 << 24,
+    TrCust        =  9 << 24,
+    TrRF          = 10 << 24,
+    TrIMEI        = 11 << 24,
+    TrBT          = 12 << 24,
+    TrETM         = 14 << 24,
+    TrTPU         = 15 << 24,
+    TrTEST        = 19 << 24
+};
+
+/******************************************************************************
+ * Supported hardware and software version - read out from Target
+ *****************************************************************************/
+
+enum HW_SW_revisions_fids
+{
+    SW_REV_ETM_TASK            = 0x01,
+    SW_REV_ETM_API             = 0x02,
+    SW_REV_ETM_CORE            = 0x10, 
+    SW_REV_ETM_AUDIO           = 0x11,
+    SW_REV_ETM_RF              = 0x12,
+    SW_REV_ETM_FFS             = 0x13,
+    SW_REV_ETM_PWR             = 0x14,
+    SW_REV_ETM_BT              = 0x15,
+    SW_REV_xx1                 = 0x16, // Not in use
+    SW_REV_xx2                 = 0x18, // Not in use
+    SW_REV_xx3                 = 0x19, // Not in use
+    SW_MCU_TCS_PROGRAM_RELEASE = 0xC0,
+    SW_MCU_TCS_OFFICIAL        = 0xC1,
+    SW_MCU_TCS_INTERNAL        = 0xC2,
+    SW_MCU_TM_VERSION          = 0xC3,
+    SW_DSP_CODE_VERSION        = 0xD0,
+    SW_DSP_PATCH_VERSION       = 0xD1,
+    HW_REV_1,
+    HW_REV_2,
+    HW_REV_3,
+    HW_REV_4,
+    HW_REV_5,
+    HW_REV_6,
+    HW_REV_7,
+    HW_REV_8
+};
+
+
+/******************************************************************************
+ * Types
+ ******************************************************************************/
+
+#ifndef BASIC_TYPES
+#define BASIC_TYPES
+typedef signed   char  int8_t;
+typedef unsigned char  uint8_t;
+typedef signed   short int16_t;
+typedef unsigned short uint16_t;
+typedef signed   int   int32_t;
+typedef unsigned int   uint32_t;
+
+typedef signed   char  int8;
+typedef unsigned char  uint8;
+typedef signed   short int16;
+typedef unsigned short uint16;
+typedef signed   int   int32;
+typedef unsigned int   uint32;
+#endif
+
+
+/******************************************************************************
+ * Trash/Hacks
+ ******************************************************************************/
+
+#endif // _ETM_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_api.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,280 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_api.c
+ *
+ * API for ETM SWE.
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  11/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#include "etm/etm.h"
+#include "etm/etm_env.h"
+#include "etm/etm_messages_i.h"
+#include "etm/etm_trace.h"
+
+#include "etm/etm_misc.h"
+
+#include "rvf/rvf_api.h"
+
+#include <string.h> 
+
+extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+
+
+/********************************************************************************
+ * Registers the SWE to the ETM instance.
+ *
+ * This is a bridge function. It sends the T_ETM_REGISTRATION_REQ
+ * message to the ETM SWE.
+ * It is the first function that should be called.
+ *
+ * @return	ETM_NOMEM in case of a memory error,
+ *			the return value of rvf_send_msg otherwise.
+ *********************************************************************************/
+
+int etm_register(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback)
+{
+	/* Type for a registration event. */
+	T_ETM_REGISTER_REQ *etm_registration_p;
+
+	tr_etm(TgTrEtmLow, "ETM API: _register bridge function(%s)", name);
+
+    /* Allocate the memory for the message to send */
+    if ((etm_registration_p = (T_ETM_REGISTER_REQ*) etm_malloc(sizeof(T_ETM_REGISTER_REQ))) == NULL)
+            return ETM_NOMEM; 
+
+    /* Fill the message id */
+    etm_registration_p->header.msg_id        = ETM_REGISTER_REQ;
+ 
+    /* Fill the address source id */
+    etm_registration_p->header.src_addr_id   = rvf_get_taskid(); 
+    etm_registration_p->header.dest_addr_id  = etm_env_ctrl_blk->addr_id;
+    etm_registration_p->header.callback_func = NULL;
+
+    /* Fill the message parameters */
+    memcpy(etm_registration_p->name, name, strlen(name));
+	etm_registration_p->mid              = mid;
+	etm_registration_p->task_id          = task_id;
+	etm_registration_p->addr_id          = addr_id;
+	etm_registration_p->rx_callback_func = callback; 
+
+	/* Send the message using mailbox. */
+	return rvf_send_msg(etm_env_ctrl_blk->addr_id,
+						(void*) etm_registration_p);
+}
+
+
+/********************************************************************************
+ * Cleans ETM register tables, i.e. set/clean the variable at their initialization
+ * state for a specific entity.
+ * This function can be used to reinitialize ETM register database without having to
+ * start/stop it.
+ *
+ * This is a bridge function. It sends ETM_UNREGISTER message to ETM.
+ *
+ * @return	ETM_NOMEM in case of a memory error,
+ *			the return value of rvf_send_msg otherwise.
+ *********************************************************************************/
+
+int etm_unregister(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback)
+{
+	/* Type for a start input event. */
+	T_ETM_UNREGISTER *etm_unregister_p;
+    
+	tr_etm(TgTrEtmLow, "ETM API: _unregister bridge function");
+    
+    /* Allocate the memory for the message to send */
+    if ((etm_unregister_p = (T_ETM_UNREGISTER*) etm_malloc(sizeof(T_ETM_UNREGISTER))) == NULL)
+            return ETM_NOMEM; 
+
+    /* Fill the message id */
+    etm_unregister_p->header.msg_id        = ETM_UNREGISTER;
+ 
+    /* Fill the address source id */
+    etm_unregister_p->header.src_addr_id   = rvf_get_taskid(); 
+    etm_unregister_p->header.dest_addr_id  = etm_env_ctrl_blk->addr_id;
+    etm_unregister_p->header.callback_func = NULL;
+
+    /* Fill the message parameters */
+    memcpy(etm_unregister_p->name, name, strlen(name));
+	etm_unregister_p->mid              = mid;
+	etm_unregister_p->task_id          = task_id;
+	etm_unregister_p->addr_id          = addr_id;
+	etm_unregister_p->rx_callback_func = callback;
+
+	/* Send the message using mailbox. */
+	return rvf_send_msg(etm_env_ctrl_blk->addr_id,
+						(void*) etm_unregister_p);
+}
+
+
+/********************************************************************************
+ * Get data from a ETM packet structur. Get either 8, 16 or 32 value
+ * Used to unpack data 
+ * 
+ * This is helpers
+ *
+ * @return	the return value of the point of the ETM packet.
+ *********************************************************************************/
+
+int etm_get8(void *buf)
+{
+    unsigned char *p = buf;
+
+    int value = *p;
+
+    tr_etm(TgTrEtmLow, "ETM API: _get8(%d)", value);
+
+    return value;
+}
+
+int etm_get16(void *buf)
+{
+   unsigned char *p = buf;
+
+    int value =
+        (*p++ | (*p << 8));
+
+    tr_etm(TgTrEtmLow, "ETM API: _get16(%d)", value);
+
+    return value;
+}
+
+int etm_get32(void *buf)
+{
+    unsigned char *p = buf;
+    int value = 0;
+   
+    value = *p;
+    p++;
+    value |= (*p << 8);
+    p++;
+    value |= (*p << 16);
+    p++;
+    value |= (*p << 24);
+
+    tr_etm(TgTrEtmLow, "ETM API: _get32(%d)", value);
+
+    return value;
+}
+
+
+/********************************************************************************
+ * Put data into a ETM packet structur. Put either 8, 16 or 32 value
+ * Used to pack data 
+ * 
+ * This is helpers
+ *
+ * @return	Return ETM_PACKET of ETM_OK.
+ *********************************************************************************/
+
+#define max_ul_data_size 240
+
+int etm_pkt_put8(T_ETM_PKT *pkt, int value)
+{
+    tr_etm(TgTrEtmLow, "ETM API: _pkt_put8(*, %d)", value);
+
+    if (pkt->index + 1 > max_ul_data_size) 
+        return ETM_PACKET;
+    
+    pkt->data[pkt->index] = value;
+    pkt->index += 1;
+
+    pkt->size += 1;
+
+    return ETM_OK;
+}
+
+int etm_pkt_put16(T_ETM_PKT *pkt, int value)
+{
+    tr_etm(TgTrEtmLow, "ETM API: _pkt_put16(*, %d)", value);
+
+    if (pkt->index + 2 > max_ul_data_size) 
+        return ETM_PACKET;
+
+    memcpy(&pkt->data[pkt->index], &value, 2);
+    pkt->index += 2;
+
+    pkt->size += 2;
+
+    return ETM_OK;
+}
+
+int etm_pkt_put32(T_ETM_PKT *pkt, int value)
+{
+    tr_etm(TgTrEtmLow, "ETM API: _pkt_put32(*, %d)", value);
+
+    if (pkt->index + 4 > max_ul_data_size) 
+        return ETM_PACKET;
+
+    memcpy(&pkt->data[pkt->index], &value, 4);
+    pkt->index += 4;
+
+    pkt->size += 4;
+
+    return ETM_OK;
+}
+
+int  etm_pkt_putdata(T_ETM_PKT *pkt, const void *buf, int size)
+{
+    tr_etm(TgTrEtmLow, "ETM API: _pkt_putdata(*, %d)", size);
+
+    if (pkt->index + size > max_ul_data_size)
+        return ETM_PACKET;
+    memcpy(&pkt->data[pkt->index], buf, size);
+    pkt->index += size;
+
+    pkt->size += size;
+  
+    return ETM_OK;
+}
+
+
+/********************************************************************************
+ * This function is used to send an ETM Packet to the PC
+ *
+ * This is helpers
+ *
+ * @return	Return value of rvf_send_trace_cpy.
+ *********************************************************************************/
+
+int etm_pkt_send(T_ETM_PKT *pkt)
+{
+    extern unsigned char etm_trace_user_id; 
+    uint8 *buf, cksum = 0, sendsize, size;
+    int error = ETM_OK;
+
+    buf = (uint8 *) &pkt->mid;
+    sendsize = size = pkt->size + 2; //one for mid, one for status  
+
+    tr_etm(TgTrEtmLow, "ETM API: _pkt_send: size(%d)", sendsize);
+
+    while (size-- ) {
+        cksum ^= *buf++;
+    }
+    *buf = cksum;
+
+    sendsize += 1; // one for checksum
+
+    tr_etm_hexdump(TgTrEtmLow, &pkt->mid, sendsize);
+   
+    error = rvt_send_trace_cpy((uint8 *) &pkt->mid, etm_trace_user_id, 
+                               sendsize, RVT_BINARY_FORMAT);
+    if(error < 0)
+        tr_etm(TgTrFatal, "ETM API: _pkt_send: ERROR(%d)", error);
+
+    return error;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_api.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,72 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_api.c
+ *
+ * API for ETM SWE.
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  11/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#ifndef __ETM_API_H_
+#define __ETM_API_H_
+
+#include "etm/etm_misc.h"
+#include "etm/etm_messages_i.h"
+
+/******************************************************************************
+ * ETM Packet
+ *****************************************************************************/
+
+typedef struct {	
+    T_RV_HDR  header;
+    char      size;
+    uint8     data[255];
+    
+} T_ETM_MAIL;
+
+
+/******************************************************************************
+ * Messages
+ *****************************************************************************/
+
+/* Event return to entity */
+#define ETM_DATA_READY              (ETM_MESSAGES_OFFSET | 0x010)
+typedef struct
+{
+    T_RV_HDR  header;
+    char      data[255];
+    
+} T_ETM_DATA_READY;
+
+
+/******************************************************************************
+ * Prototypes
+ *****************************************************************************/
+
+int etm_register(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback);
+int etm_unregister(char name[], int mid, int task_id, T_RVF_ADDR_ID addr_id, ETM_CALLBACK_FUNC callback);
+
+int etm_pkt_send(T_ETM_PKT *pkt);
+int etm_pkt_putdata(T_ETM_PKT *pkt, const void *buf, int size);
+
+int etm_get8(void *buf);
+int etm_get16(void *buf);
+int etm_get32(void *buf);
+
+int etm_pkt_put8(T_ETM_PKT *p, int value);
+int etm_pkt_put16(T_ETM_PKT *p, int value);
+int etm_pkt_put32(T_ETM_PKT *p, int value);
+
+#endif /* __ETM_API_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_at.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,464 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_at.c (Support for AT-commands)
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.2
+ *
+
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *  06/11/2003  Small updates 
+ *  18/02/2004  Major updating, the event handling has been updated
+ *
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+//#include "aci_msg.h"
+
+#include "etm/etm.h"          
+#include "etm/etm_api.h"
+#include "etm/etm_at.h"
+#include "etm/etm_trace.h"
+
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+
+#include "atp/atp_env.h"  // FixMe
+#include "atp/atp_i.h"    // FixMe    
+//#include "atp/atp_general.h"  // FixMe
+
+#include "atp/atp_api.h"
+#include "atp/atp_messages.h" 
+
+#include <string.h>
+
+// Defined in aci_msg.h
+extern T_XAT_SYNC_MESSAGE;
+extern SYNC_PORT_NUM;
+extern ASYNC_PORT_NUM;
+extern T_RAT_CALLBACK_MESSAGE;
+
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+
+static T_ATP_SW_ENTITY_NAME  ETM_AT_ADAPTER      = "ETMATA"; // max 5 caracter
+static T_ATP_SW_ENTITY_ID    etm_at_id;     
+static T_ATP_PORT_NB         etm_at_to_aaa_port  = 0x01;     // equal to SYNC_PORT_NUM
+
+static T_ATP_SW_ENTITY_NAME  aaa_name            = "AAA";     // ACIA ADAPTER
+//static T_ATP_SW_ENTITY_NAME  aaa_name            = "GSM";     // GSM ADAPTER
+static T_ATP_SW_ENTITY_ID    aaa_entity_id;
+static T_ATP_ENTITY_MODE     aaa_mode;       
+
+static T_ATP_CALLBACK etm_at_return_path;
+static T_ATP_ENTITY_MODE etm_at_mode;
+
+//extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+
+static int etm_at_initialized  = 0;
+static int etm_at_event_status = 0;
+
+static char etm_at_latest_cmd[9] = { 0 };
+
+
+/******************************************************************************
+ * Internal prototypes 
+ *****************************************************************************/
+
+int  etm_at_init(void);
+int  etm_at_reg_req(void);
+int  etm_at_open_port_req(void);
+//T_RV_HDR *etm_at_wait_for_atp_event (UINT16 event_code);
+int etm_at_atp_txt_cmd_rdy( T_ATP_TXT_CMD_RDY *msg);
+void etm_at_callback_for_ATP(void *event_from_atp_p);
+
+
+/******************************************************************************
+ * AT commands List 
+ *****************************************************************************/
+
+struct at_async_trans_s {
+//    const short index;  // index for ...
+    const char *name;   // parameter
+};
+
+static struct at_async_trans_s at_cmd[] =
+{
+    {  "TEST"  },
+    {  "atd"   },
+    {  NULL    }
+};
+
+
+int at_cmd_search(char *at_string)
+{
+    struct at_async_trans_s *at_p = at_cmd;
+    int size, error;
+
+    size = strlen(at_string);
+    tr_etm(TgTrCore, "ETM CORE: _cmd_search: at_string size(%d)", size);
+
+    if (size > 8)
+        strncpy(&etm_at_latest_cmd[0], at_string, 8);
+    else
+        strncpy(&etm_at_latest_cmd[0], at_string, size);
+
+//    if ((etm_at_latest_cmd[2]== '+') || (etm_at_latest_cmd[2] == '%'))
+//        return ETM_OK;
+    
+    while (at_p->name) {
+        error = strncmp(&etm_at_latest_cmd[0], at_p->name, strlen(at_p->name));
+        if (error == 0)
+            strcpy(&etm_at_latest_cmd[0], at_p->name);
+        tr_etm(TgTrCore, "ETM CORE: _cmd_search: AT list(%s)", at_p->name);
+        at_p++;
+    }
+
+    tr_etm(TgTrCore, "ETM CORE: _cmd_search: text(%s)", &etm_at_latest_cmd[0]);
+
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * AT command to ACI
+ *****************************************************************************/
+
+int etm_at_adapter(char *command)
+{
+    int error;
+    T_ATP_TXT_CMD txt_cmd_p = NULL;
+       
+    if (!etm_at_initialized){
+        if ((etm_at_init() == ETM_OK) && (etm_at_event_status == ETM_OK)) {
+            // read etm_at_event_status
+            tr_etm(TgTrCore, "ETM CORE: _at_adapter: initialization - OK");
+            etm_at_initialized = 1;
+        }
+        else {
+            tr_etm(TgTrCore, "ETM CORE: _at_adapter: initialization - FAILED");
+            return ETM_FATAL;
+        }
+    }
+
+    // Creating ETM_AT data buffer, will be fread by atp_send_txt_cmd()
+    if ((txt_cmd_p = etm_malloc(strlen(command)+1)) == NULL)
+        return ETM_NOMEM;
+
+    strcpy(txt_cmd_p, command);
+
+    // Find AT command
+    //at_cmd_search(command);
+
+    // Send AT command to AAA
+    if ((error = atp_send_txt_cmd(etm_at_id, etm_at_to_aaa_port, AT_CMD, txt_cmd_p)) != RV_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_adapter: send_txt_cmd - FAILED");
+        return ETM_FATAL;
+    }
+
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * ETM AT Adapter Initialization
+ *****************************************************************************/
+
+int etm_at_init(void)
+{
+    int error;
+
+    // Check if ATP has been started if NOT 
+    // Turn ATP module ON - necessary for RVM 
+    if (atp_swe_state != ATP_STARTED)
+        if (atp_start() != RV_OK)
+            return ETM_FATAL;
+   
+ 
+    // Registration of ETM_AT to ATP  
+    if ((error = etm_at_reg_req()) != ETM_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_init: Registration ERROR(%d)", error); 
+       return error;    
+    }    
+
+    // Open a port to ACI adapter
+    if ((error = etm_at_open_port_req()) != ETM_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_init: Open port ERROR(%d)", error);
+        return error;
+    }
+
+    return ETM_OK;
+}
+
+
+// Register of ETM AT adapter with ATP.
+
+int etm_at_reg_req(void)
+{
+    int result;
+
+     // Registration of ETM_AT in ATP
+    etm_at_return_path.addr_id        = NULL; // mailbox identifier - unused when callback mechanism in use
+    etm_at_return_path.callback_func  = etm_at_callback_for_ATP;  // Pointer to callback fn ...
+
+    // Set modes supported by SWE 
+    etm_at_mode.cmd_mode         = TXT_MODE;  // INTERPRETED_MODE/TXT_MODE
+    etm_at_mode.cp_mode          = COPY_OFF;
+    etm_at_mode.cmd_support_mode = CMD_SUPPORT_ON;
+
+    // Registration of ETM_AT to ATP
+    if ((result = (atp_reg(ETM_AT_ADAPTER, etm_at_return_path, etm_at_mode, &etm_at_id)))
+        != RV_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_reg_req: ERROR(%d)", result);
+        return ETM_RV_FATAL;    
+    }
+
+    // Check ETM_AT Registration
+    if ((result = (atp_reg_info(ETM_AT_ADAPTER, &etm_at_id, &etm_at_mode)))
+        != RV_OK){
+        tr_etm(TgTrCore, "ETM CORE: _at_reg_req: FAILED");
+        return ETM_RV_NOT_SUPPORTED;
+    }
+
+    return ETM_OK;
+}
+
+
+// Open a port with ATP.
+
+int etm_at_open_port_req(void)
+{
+    int result;
+    T_ATP_NO_COPY_INFO etm_no_copy_info;
+    T_ATP_PORT_INFO etm_port_info;
+    T_ATP_CUSTOM_INFO *cust_info_p = NULL;
+//    T_RV_HDR *message_p;
+    T_RVF_MB_ID etm_mb_id;
+
+    if (rvf_get_mb_id("ETM_PRIM", &etm_mb_id) != RVF_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_open_port_req: Memory bank ETM does not exist!");
+        return ETM_RV_FATAL;
+    }
+         
+	/* Test header and trailer removal from ATP so: trailers and headers equal 0 */
+	etm_no_copy_info.tx_mb		    = etm_mb_id;   /* MB used by ATP is from ETM */ 
+	etm_no_copy_info.rx_mb		    = etm_mb_id;   /* MB used by ATP is from ETM */
+	etm_no_copy_info.rx_head_mode   = RX_HEADER_OFF;
+    etm_no_copy_info.rx_head_size   = 0x00;
+    etm_no_copy_info.rx_trail_size  = 0x00;
+	etm_no_copy_info.tx_head_mode   = TX_HEADER_OFF;
+    etm_no_copy_info.tx_head_size   = 0x00;
+    etm_no_copy_info.tx_trail_size  = 0x00;
+	etm_no_copy_info.packet_mode    = NORMAL_PACKET;     /* No L2CAP packet... */
+
+    //  Port info 
+    etm_port_info.port_config = NOT_DEFINED_CONFIG;
+    etm_port_info.ring_type   = ATP_NO_RING_TYPE;
+    etm_port_info.signal_mask = (T_ATP_SIGNAL_MASK) ATP_ALL_THE_SIGNAL_UNMASK; /* Get all signal changed event */
+    etm_port_info.dce_mask[0] = 0x0000; /* No requirement in term of DCE */ 
+
+    // Test AA Adapter Registration
+    if (atp_reg_info(aaa_name, &aaa_entity_id, &aaa_mode) != RV_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_open_port_req: AAA is not registered to ATP");
+        return ETM_RV_NOT_SUPPORTED;
+    }
+
+    // Open a virtual port between ETM AT adapter and ACI adapter 
+    if ((result = atp_open_port_rqst(etm_at_id, aaa_entity_id, etm_at_to_aaa_port, 
+                                     etm_port_info, etm_no_copy_info, cust_info_p)) != RV_OK) {
+        tr_etm(TgTrCore, "ETM CORE: _at_open_port_req: FAILED");
+        return ETM_RV_FATAL;
+    }
+
+    // etm_at_callback_for_ATP should receive event: ATP_OPEN_PORT_CFM 
+    rvf_wait(0xffff, 100); // Timeout 100 ticks
+    tr_etm(TgTrCore, "ETM CORE: _at_open_port_req: STATUS(%d)", etm_at_event_status);
+
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * Close Port
+ *****************************************************************************/
+
+int etm_at_port_close_req(void)
+{ 
+    int error;
+
+    error = atp_close_port(etm_at_id, etm_at_to_aaa_port);
+    if (error != RV_OK) {
+    tr_etm(TgTrCore, "ETM CORE: _at_port_close_req: FAILED");
+        return ETM_FATAL;
+    }        
+    
+    // etm_at_callback_for_ATP should receive event: ATP_PORT_CLOSED 
+    rvf_wait(0xffff, 100); // Timeout 100 ticks
+    tr_etm(TgTrCore, "ETM CORE: _at_open_port_req: STATUS(%d)", etm_at_event_status);
+
+    etm_at_initialized = 0;
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * Callback function for ATP
+ *****************************************************************************/
+
+//   PURPOSE : Decipher and route incoming messages from ATP.
+
+void etm_at_callback_for_ATP(void *event_from_atp_p)
+{
+	// This function is ATP context.
+	
+//    tr_etm(TgTrEtmLow,"ETM: CORE: etm_at_callback_for_ATP: recv. event (0x%x)", ((T_RV_HDR *) event_from_atp_p)->msg_id);
+
+    // What type of event?
+    switch (((T_RV_HDR *) event_from_atp_p)->msg_id)
+    {
+    case ATP_CMD_RDY:
+        tr_etm(TgTrCore,"ETM CORE: _at_callback_for_AT: UNSUPPORTED"); 
+        break;
+    case ATP_OPEN_PORT_CFM:
+        if (((T_ATP_OPEN_PORT_CFM *) event_from_atp_p)->result == OPEN_PORT_OK) {
+            tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_OPEN_PORT_CFM - OPEN_PORT_OK");
+//            tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_OPEN_PORT_CFM - Port Number (%d)",
+//                   ((T_ATP_OPEN_PORT_CFM *) event_from_atp_p)->initiator_port_nb);
+        }
+        else {
+            tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_OPEN_PORT_CFM - OPEN_PORT_NOK");
+            etm_at_event_status = ETM_FATAL;
+        }
+//            tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_OPEN_PORT_CFM - Port Number (%d)",
+//                   ((T_ATP_OPEN_PORT_CFM *) event_from_atp_p)->initiator_port_nb);
+        break;
+    case ATP_TXT_CMD_RDY:
+        etm_at_atp_txt_cmd_rdy((T_ATP_TXT_CMD_RDY *) event_from_atp_p);
+        break;
+    case ATP_PORT_CLOSED:
+        tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_PORT_CLOSED");
+        break;
+    case ATP_OPEN_PORT_IND:
+        tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. event ATP_OPEN_PORT_IND");
+        break;
+    default:
+        tr_etm(TgTrCore, "ETM CORE: _at_callback_for_ATP: rev. unknown event(0x%x)- UNSUPPORTED", 
+               ((T_RV_HDR *) event_from_atp_p)->msg_id);
+    }
+    
+    /* Free memmory that is allocated within ATP */
+    etm_free(event_from_atp_p);
+}      
+
+
+// This is called when the result of the AT cmd is received 
+// (in a primetive) from the ATP entity.
+int etm_at_atp_txt_cmd_rdy(T_ATP_TXT_CMD_RDY *msg)
+{
+/* Send reply to PC
+   The status type depend of the event from ATP module: 
+       last_result = 0, means more data is sent to HOST (PC)
+       last_result = 1, means last data is sent to HOST (PC)
+       last_result = 2, means data is not sent to HOST (PC)  */
+
+    T_ETM_PKT  *pkt;
+    char *text, last_result = 1;
+    int error = 0, length;
+
+    if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
+        rvf_dump_mem();
+        return ETM_NOMEM;
+    }
+    
+    // Init. of return packet
+    pkt->mid    = ETM_CORE;
+    pkt->status = ETM_OK;
+    pkt->size   = 0;
+    pkt->index  = 0;
+    etm_pkt_put8(pkt, 'G'); // 'G' is indcator for AT command respons
+
+
+    tr_etm(TgTrCore, "ETM CORE: _at_atp_txt_cmd_rdy: ATP_TXT_CMD_RDY with cmd_type(%d)",
+           msg->cmd_type);
+ 
+    switch (msg->cmd_type){
+    case AT_CMD:                                                   // Type: 0
+    case CUSTOM_CMD:                                               // Type: 4
+    case CMD_ABORT:                                                // Type: 5
+    case UNKNOWN:                  error = ETM_MESSAGE; break;     // Type: 6
+    case PRELIMINARY_RESULT_CODE:  last_result = 0;     break;     // Type: 7
+//    case INFORMATION_TXT:          last_result = 0;     break;     // Type: 3
+    case RESULT_CODE:              last_result = 1;     break;     // Type: 1
+    case UNSOLICITED_RESULT:       last_result = 2;     break;     // Type: 2
+    default:
+        tr_etm(TgTrCore,"ETM CORE: _at_atp_txt_cmd_rdy: cmd_tpye(%d) - FAILED", msg->cmd_type); 
+        error = ETM_NOSYS;
+    }
+
+    if (last_result == 2) 
+        goto etm_at_atp_txt_cmd_rdy_end;
+    
+    text = ((char *) msg->txt_cmd_p);
+    length = strlen(text);
+    etm_pkt_putdata(pkt, text, length);
+    tr_etm(TgTrCore, "ETM CORE: _at_atp_txt_cmd_rdy: text(%s) length(%d)", text, length);
+
+    // Status will be set to ETM_OK_MORE when more data is send.
+    // Add one because of string length is also returned as part of the result
+    pkt->status = (last_result ? ETM_OK : -ETM_OK_MORE);
+
+    if (error < 0) {
+//        tr_etm(TgTrCore,"ETM CORE: _at_atp_txt_cmd_rdy: ERROR(%d)", error); 
+        pkt->status = -error;
+    }
+
+    etm_pkt_send(pkt);
+
+etm_at_atp_txt_cmd_rdy_end:
+    etm_free(pkt);
+
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * ETM AT - Main Task 
+ *****************************************************************************/
+
+// Structur of protocol data dl-link: |target|at_cmd|
+int etm_at(T_ETM_PKT *pkt, char *buf)
+{
+    int error = ETM_NOSYS;
+    int sw_entity;
+
+//    sw_entity = *buf++;
+
+    // FIXME pkt should be use in etm_at_adapter()
+    error = etm_at_adapter((char *) buf);
+
+#if 0 
+    switch (sw_entity) {
+    case GSM: 
+  
+        break;
+    case BLUE: 
+        //error = etm_at_blue(*buf++); 
+        break;
+    default:
+        tr_etm(TgTrCore,"ETM CORE: _at: ERROR(%d)", error); 
+        error = ETM_NOSYS; 
+    }
+#endif
+
+    return error;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_at.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,30 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_at.c (Support for AT-commands)
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *  06/11/2003  Small updates  
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+#ifndef __ETM_AT_H_
+#define __ETM_AT_H_
+
+#include "etm/etm_env.h" // Need because use of T_ETM_ENV_CTRL_BLK 
+
+
+/** External ref "global variables" structure. */
+extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+
+
+#endif //__ETM_AT_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_audio.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,401 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_audio.c (Support for AUDIO commands)
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.8
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *  30/06/2003  Small cleanup in func. etm_audio_write, etm_audio_saveload and
+ *              etm_aud_wait_for_aud_event is updated and renamed
+ *  12/08/2003  The func. etm_audio_write has been updated regarding the AEC struct.
+ *  14/08/2003  The func. etm_audio_read has been updated regarding the AEC struct.
+ *  17/03/2004  Modified the event handling, events revceived from the Audio SWE. 
+ *              Integrated event callback function, etm_audio_callback().
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#include "etm/etm.h"
+#include "etm/etm_api.h"
+#include "etm/etm_trace.h"
+#include "etm/etm_env.h" // Need because use of T_ETM_ENV_CTRL_BLK 
+#include "etm/etm_audio_err.h" // Privat Audio error codes for PC and Target 
+
+#include "etm/etm_trace.h"
+#include "audio/audio_api.h"
+
+#include "rv/rv_general.h"
+#include "spi/spi_drv.h" // used for codec read/write
+
+#include "memif/mem.h"
+#include <string.h>
+
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+
+// Version of the ETM AUDIO module
+//const uint16 etm_audio_revision = (1<<12) | (0x1);
+
+extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+
+static int etm_audio_event_status = 0;
+
+
+/******************************************************************************
+ * Internal prototypes 
+ *****************************************************************************/
+
+int etm_audio(uint8 *indata, int insize);
+T_RV_HDR *etm_audio_wait_for_event(UINT16 msg_id_expected);
+T_ETM_PKT *etm_audio_setup(uint8 fid, uint8 cfg_data);
+void etm_audio_callback(void *event_from_audio);
+
+
+/******************************************************************************
+ * Register the Audio Module to the ETM database 
+ *****************************************************************************/
+
+int etm_audio_init(void)
+{
+    int result; 
+
+    result = etm_register("AUDIO", ETM_AUDIO, 0, 0, etm_audio);
+    return result;    
+}
+
+
+/******************************************************************************
+ * Audio Full Access Read Function
+ *****************************************************************************/
+
+int etm_audio_read(T_ETM_PKT *pkt, uint8 *buf)
+{
+    int result, size = 0, size_tmp, i;
+    uint8 param;
+    T_AUDIO_FULL_ACCESS_READ audio;
+    T_AUDIO_AEC_CFG *aec_parameter = NULL;
+    void *parameter = NULL;
+    
+    param = *buf;
+    if ((result = etm_pkt_put8(pkt, param)) < 0) 
+        return result;
+
+    tr_etm(TgTrAudio, "ETM AUDIO: _audio_read: param(%d)", param);
+   
+    audio.variable_indentifier = param;
+    audio.data = (T_AUDIO_FULL_ACCESS_READ *) &pkt->data[2]; //data[0] = fid
+                                                             //data[1] = parameter/identifier
+    
+    if ((result = audio_full_access_read(&audio)) != AUDIO_OK){
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_read: ERROR(%d)", result);
+        if (result == AUDIO_ERROR) 
+            return ETM_INVAL;         // Invalid audio parameter
+        else
+            return ETM_AUDIO_FATAL;
+    }
+
+    switch (param) {
+    case AUDIO_PATH_USED:
+        size = sizeof(T_AUDIO_VOICE_PATH_SETTING);
+        break;
+    case AUDIO_MICROPHONE_MODE:
+    case AUDIO_MICROPHONE_GAIN:
+    case AUDIO_MICROPHONE_EXTRA_GAIN:
+    case AUDIO_MICROPHONE_OUTPUT_BIAS:
+    case AUDIO_MICROPHONE_SPEAKER_LOOP_SIDETONE:
+        size = sizeof(INT8);                         
+        break;
+    case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC:
+        size = sizeof(T_AUDIO_AEC_CFG);              
+      
+        aec_parameter = (T_AUDIO_AEC_CFG *) &pkt->data[2];
+
+        etm_pkt_put16(pkt, aec_parameter->aec_enable);                  // 1
+#if (L1_NEW_AEC)
+        etm_pkt_put16(pkt, aec_parameter->continuous_filtering);        // 2
+        etm_pkt_put16(pkt, aec_parameter->granularity_attenuation);     // 3
+        etm_pkt_put16(pkt, aec_parameter->smoothing_coefficient);       // 4
+        etm_pkt_put16(pkt, aec_parameter->max_echo_suppression_level);  // 5
+        etm_pkt_put16(pkt, aec_parameter->vad_factor);                  // 6
+        etm_pkt_put16(pkt, aec_parameter->absolute_threshold);          // 7
+        etm_pkt_put16(pkt, aec_parameter->factor_asd_filtering);        // 8
+        etm_pkt_put16(pkt, aec_parameter->factor_asd_muting);           // 9
+        etm_pkt_put16(pkt, aec_parameter->aec_visibility);              //10
+#else
+        etm_pkt_put16(pkt, aec_parameter->aec_mode);                    // 2
+        etm_pkt_put16(pkt, aec_parameter->echo_suppression_level);      // 3
+#endif // end of (L1_NEW_AEC)
+        etm_pkt_put16(pkt, aec_parameter->noise_suppression_enable);    // 4 or 11
+        etm_pkt_put16(pkt, aec_parameter->noise_suppression_level);     // 5 or 12
+        break;
+    case AUDIO_MICROPHONE_FIR:
+    case AUDIO_SPEAKER_FIR:
+        size = sizeof(T_AUDIO_FIR_COEF);             
+        break;
+    case AUDIO_SPEAKER_MODE:
+    case AUDIO_SPEAKER_GAIN:
+    case AUDIO_SPEAKER_FILTER:
+    case AUDIO_SPEAKER_BUZZER_STATE:
+        size = sizeof(INT8);                         
+        break;
+    case AUDIO_SPEAKER_VOLUME_LEVEL:
+        size = sizeof(T_AUDIO_SPEAKER_LEVEL);        
+        break;
+    default:
+        size = ETM_INVAL;                            
+    }
+
+    pkt->size += size;
+    return ETM_OK;
+}
+
+ 
+/******************************************************************************
+ * Audio Full Access Write Function
+ *****************************************************************************/
+
+int etm_audio_write(T_ETM_PKT *pkt, uint8 *buf)
+{
+    T_RV_HDR *msg = NULL;
+    T_RV_RETURN return_path;
+    T_AUDIO_FULL_ACCESS_WRITE audio;
+    T_AUDIO_AEC_CFG *aec_parameter = NULL;
+    void *parameter = NULL;
+    int result = ETM_OK, i;
+    uint8 param;
+
+    param = *buf++;
+    if ((result = etm_pkt_put8(pkt, param)) < ETM_OK) {
+        return result;
+    } 
+
+    tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: param(%d)", param);
+
+    return_path.addr_id        = NULL; //etm_env_ctrl_blk->addr_id;
+    return_path.callback_func  = etm_audio_callback;
+
+    audio.variable_indentifier = param;
+    audio.data = buf;
+
+    switch (param) {
+    case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: AUDIO_MICROPHONE_SPEAKER_LOOP_AEC"); // RemoveMe
+        aec_parameter = etm_malloc (sizeof(T_AUDIO_AEC_CFG));
+        
+        aec_parameter->aec_enable =                 etm_get16(buf); buf += 2;// 1
+#if (L1_NEW_AEC)
+        if (etm_get16(buf))  // 2
+            aec_parameter->continuous_filtering = TRUE;
+         else
+            aec_parameter->continuous_filtering = FALSE;
+        buf += 2;
+        aec_parameter->granularity_attenuation =    etm_get16(buf); buf += 2;// 3
+        aec_parameter->smoothing_coefficient =      etm_get16(buf); buf += 2;// 4
+        aec_parameter->max_echo_suppression_level = etm_get16(buf); buf += 2;// 5
+        aec_parameter->vad_factor =                 etm_get16(buf); buf += 2;// 6
+        aec_parameter->absolute_threshold =         etm_get16(buf); buf += 2;// 7
+        aec_parameter->factor_asd_filtering =       etm_get16(buf); buf += 2;// 8
+        aec_parameter->factor_asd_muting =          etm_get16(buf); buf += 2;// 9
+        aec_parameter->aec_visibility =             etm_get16(buf); buf += 2;// 10
+#else
+        aec_parameter->aec_mode =                   etm_get16(buf); buf += 2;// 2
+        aec_parameter->echo_suppression_level =     etm_get16(buf); buf += 2;// 3
+#endif // end of (L1_NEW_AEC)
+#if (L1_ANR == 0)
+        aec_parameter->noise_suppression_enable =   etm_get16(buf); buf += 2;// 4 or 11
+        aec_parameter->noise_suppression_level =    etm_get16(buf); // 5 or 12
+#endif // end of (L1_ANR)
+        audio.data = aec_parameter;
+        break;
+    case AUDIO_MICROPHONE_FIR:
+    case AUDIO_SPEAKER_FIR:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: AUDIO_MICROPHONE/SPEAKER_FIR [%d]", 
+               sizeof(T_AUDIO_FIR_COEF)/2); // RemoveMe
+
+        parameter = etm_malloc (sizeof(T_AUDIO_FIR_COEF));
+        // Write coeffient values
+        for (i=0; i <= (sizeof(T_AUDIO_FIR_COEF)/2); i++) {
+            ((T_AUDIO_FIR_COEF *) parameter)->coefficient[i]  = etm_get16(buf);  buf += 2;
+        }
+        audio.data = parameter;
+        break;
+    }
+
+    if ((result = audio_full_access_write(&audio, return_path)) != AUDIO_OK) {
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: ERROR(%d)", result);
+        if (result == AUDIO_ERROR) 
+            result = ETM_INVAL;         // Invalid audio parameter
+        else
+            result = ETM_AUDIO_FATAL;
+    }
+
+    // Wait for recv. of event: AUDIO_FULL_ACCESS_WRITE_DONE
+    rvf_wait(0xffff, 100); // Timeout 100 ticks
+    tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: STATUS(%d)", etm_audio_event_status);
+
+    if (parameter != NULL) {
+        etm_free(parameter);
+        parameter = NULL;
+    }
+
+    if (aec_parameter != NULL) {
+        etm_free(aec_parameter);    
+        aec_parameter = NULL;
+    }
+
+    if (etm_audio_event_status != 0) {
+        etm_audio_event_status = 0;
+        result = ETM_AUDIO_FATAL;
+    }
+
+    return result;
+}
+
+/******************************************************************************
+ * Audio Save and Load cfg file Function
+ *****************************************************************************/
+
+int etm_audio_saveload(T_ETM_PKT *pkt, uint8 saveload, void *buf, int size)
+{
+    T_RV_HDR *msg;
+    T_AUDIO_MODE_SAVE audio_s;
+    T_AUDIO_MODE_LOAD audio_l;
+    T_RV_RETURN return_path;
+    int result = ETM_OK; 
+    int error, event;
+    
+    return_path.addr_id        = etm_env_ctrl_blk->addr_id;
+    return_path.callback_func  = NULL;
+
+    switch(saveload) {
+    case 'S':
+        memcpy(audio_s.audio_mode_filename, buf, size);
+        result = audio_mode_save(&audio_s, return_path); 
+        break;
+    case 'L':
+        memcpy(audio_l.audio_mode_filename, buf, size);
+        result = audio_mode_load(&audio_l, return_path); 
+        break;
+    default:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_saveload: FAILED"); 
+        break;
+    }
+    
+    rvf_wait(0xffff, 100); // Timeout 100 ticks
+    tr_etm(TgTrAudio, "ETM AUDIO: _audio_saveload: STATUS(%d)", etm_audio_event_status);
+
+    if (etm_audio_event_status != 0) {
+        etm_audio_event_status = 0;
+        return ETM_AUDIO_FATAL;
+    }
+
+    if (result != AUDIO_OK)
+        return ETM_AUDIO_FATAL;
+
+    return result;
+}
+
+
+/******************************************************************************
+ * ETM AUDIO callback functio
+ *****************************************************************************/
+
+void etm_audio_callback(void *event_from_audio)
+{
+    tr_etm(TgTrEtmLow,"ETM: AUDIO: _audio_callback: recv. event (0x%x)", 
+           ((T_RV_HDR *) event_from_audio)->msg_id);
+    
+    switch (((T_RV_HDR *) event_from_audio)->msg_id)
+    {
+    case AUDIO_FULL_ACCESS_WRITE_DONE:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_FULL_ACCESS_WRITE_DONE");
+        etm_audio_event_status = ((T_AUDIO_FULL_ACCESS_WRITE_DONE *) event_from_audio)->status;
+        break;
+    case AUDIO_MODE_SAVE_DONE:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_MODE_SAVE_DONE");
+        etm_audio_event_status = ((T_AUDIO_SAVE_DONE *) event_from_audio)->status;
+        break;
+    case AUDIO_MODE_LOAD_DONE:
+        tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_MODE_LOAD_DONE");
+        etm_audio_event_status = ((T_AUDIO_LOAD_DONE *) event_from_audio)->status;
+        break;
+    }
+    
+    if (event_from_audio != NULL) {
+//        etm_free(event_from_audio); 
+        event_from_audio = NULL;
+    }
+}
+
+
+/******************************************************************************
+ * ETM AUDIO Moudle - Main Task
+ *****************************************************************************/
+
+// AUDIO packet structure for audio read/write and codec read/write: 
+// |fid(8)|param(8)|--data(W)--| and for audio save/load |fid|--data(W)--|
+
+int etm_audio(uint8 *indata, int insize)
+{
+    int error = ETM_OK;
+    uint8 fid;
+    T_ETM_PKT *pkt = NULL;  
+
+    fid = *indata++;   
+       
+    tr_etm(TgTrAudio, "ETM AUDIO: _audio: fid(%c) param(%d) recv. size(%d)", 
+           fid, *indata, insize); 
+
+    /* Create TestMode return Packet */
+    if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
+        return ETM_NOMEM;
+    }
+    
+    // Init. of return packet
+    pkt->mid     = ETM_AUDIO;
+    pkt->status  = ETM_OK;
+    pkt->size    = 0;
+    pkt->index   = 0;
+    etm_pkt_put8(pkt, fid);
+    
+    if (error == ETM_OK) {
+        switch (fid) {
+        case 'R':
+            error = etm_audio_read(pkt, indata);                  
+            break;
+        case 'W':
+            error = etm_audio_write(pkt, indata); 
+            break;
+        case 'S':
+        case 'L': 
+            error = etm_audio_saveload(pkt, fid, indata, insize);  
+            break;
+        default:
+            tr_etm(TgTrAudio, "ETM AUDIO: _audio: fid(%c) - ERROR ", fid);
+            error = ETM_NOSYS;                                
+            break;
+        }
+    }
+    
+    if (error < 0) {
+        tr_etm(TgTrAudio,"ETM AUDIO: _audio: ERROR(%d)", error); 
+        pkt->status = -error;
+
+    }
+
+    etm_pkt_send(pkt);
+    etm_free(pkt);
+
+    return ETM_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_audio_err.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,36 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_audio_err.h (Support for AUDIO commands)
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  30/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+#ifndef _ETM_AUDIO_ERR_H_
+#define _ETM_AUDIO_ERR_H_
+
+/******************************************************************************
+ * ERRORS
+ *****************************************************************************/
+
+// Module private (normally target-side) errors are in the range: [ -2..-47]
+enum ETM_AUDIO_ERRORS_TG {
+    ETM_AUDIO_FATAL = -3   // Fatal error
+};
+
+// Module private (normally PC-side) errors are in the range:     [-90..-99]
+//enum ETM_AUDIO_ERRORS_PC {
+ 
+//};
+
+#endif // end of _ETM_AUDIO_ERR_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_env.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,232 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_env.c 
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#include "etm/etm_env.h"
+
+#include "rvm/rvm_priorities.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rv/rv_defined_swe.h"
+
+#include <string.h>
+/******************************************************************************
+ * 
+ *****************************************************************************/
+
+/* External declaration */
+extern T_RV_RET etm_task(void);
+
+
+/**
+ * Pointer on the structure gathering all the global variables
+ * used by ETM instance.
+ */
+T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk = NULL;
+
+
+/******************************************************************************
+* Function	  : etm_get_info
+*
+* Description : This function is called by the RV manager to learn 
+*				driver requirements in terms of memory, SWEs...
+*
+* Parameters  : T_RVM_INFO_SWE  * swe_info: pointer to the structure to fill
+*				containing infos related to the driver SWE.
+*
+* Return      :  T_RVM_RETURN
+* 
+* History	  : 0.1 
+*									
+*
+******************************************************************************/
+T_RVM_RETURN etm_get_info(T_RVM_INFO_SWE *swe_info)
+{
+    /* SWE info */
+	swe_info->swe_type = RVM_SWE_TYPE_4;
+    swe_info->type_info.type4.swe_use_id = ETM_USE_ID;
+
+    memcpy(swe_info->type_info.type4.swe_name, "ETM", sizeof("ETM"));
+	swe_info->type_info.type4.stack_size = ETM_STACK_SIZE;
+	swe_info->type_info.type4.priority   = RVM_ETM_TASK_PRIORITY;
+
+	/* Set the return path */
+	swe_info->type_info.type4.return_path.callback_func	= NULL;
+	swe_info->type_info.type4.return_path.addr_id	    = 0;
+
+	/* memory bank info */
+	swe_info->type_info.type4.nb_mem_bank = 1;
+	
+	memcpy (swe_info->type_info.type4.mem_bank[0].bank_name, "ETM_PRIM", 9);
+	swe_info->type_info.type4.mem_bank[0].initial_params.size          = ETM_MB_PRIM_SIZE;
+	swe_info->type_info.type4.mem_bank[0].initial_params.watermark     = ETM_MB_PRIM_WATERMARK;
+
+	/* linked SWE info */
+    /* this SWE requires the ATP SWE to run */
+#ifdef RVM_ATP_SWE
+    swe_info->type_info.type4.nb_linked_swe = 1;
+    swe_info->type_info.type4.linked_swe_id[0] = ATP_USE_ID;
+#else
+	 swe_info->type_info.type4.nb_linked_swe = 0;
+#endif
+
+	/* generic functions */
+	swe_info->type_info.type4.set_info = etm_set_info;
+	swe_info->type_info.type4.init     = etm_init;
+	swe_info->type_info.type4.core     = etm_start;
+	swe_info->type_info.type4.stop     = etm_stop;
+	swe_info->type_info.type4.kill     = etm_kill;
+
+	return RVM_OK;
+}
+
+
+/******************************************************************************
+* Function	  : etm_set_info
+*
+* Description : This function is called by the RV manager to inform  
+*				the driver SWE about task_id, mb_id and error function.
+*
+* Parameters  : - T_RVF_ADDR_ID  addr_id: unique path to the SWE.
+*					 - T_RV_RETURN ReturnPath[], array of return path for linked SWE
+*					 - T_RVF_MB_ID mbId[]: array of memory bank ids.
+*					 - callback function to call in case of unrecoverable error.
+*
+* Return      : T_RVM_RETURN
+* 
+* History	  : 0.1
+*									
+*
+******************************************************************************/
+
+T_RVM_RETURN etm_set_info (T_RVF_ADDR_ID	addr_id, 
+                           T_RV_RETURN		return_path[], 
+                           T_RVF_MB_ID		bk_id[],
+                           T_RVM_RETURN	(*rvm_error_ft)(T_RVM_NAME			swe_name, 
+                                                        T_RVM_RETURN		error_cause, 
+                                                        T_RVM_ERROR_TYPE	error_type, 
+                                                        T_RVM_STRING		error_msg))
+{
+	/* Create instance gathering all the variable used by EXPL instance */
+	if (rvf_get_buf(bk_id[0], 
+					sizeof(T_ETM_ENV_CTRL_BLK),
+					(T_RVF_BUFFER**)&etm_env_ctrl_blk) != RVF_GREEN)
+	{
+		/* The environemnt will cancel the ETM instance creation. */
+		return RVM_MEMORY_ERR;
+	}
+
+
+	/* Store the pointer to the error function */
+	etm_env_ctrl_blk->error_ft = rvm_error_ft ;
+	/* Store the mem bank id. */
+	etm_env_ctrl_blk->prim_id = bk_id[0];
+   /* Store the addr id */
+	etm_env_ctrl_blk->addr_id = addr_id;
+
+	/*
+	 * Task ID (task_id) and Memory bank ID (mb_id) can be retrieved later 
+	 * using rvf_get_taskid and rvf_get_mb_id functions.
+	 */
+
+	/* return_path of linked SWE -> not used */
+
+	return RVM_OK;
+}
+
+
+/******************************************************************************
+* Function	  : etm_init
+*
+* Description : This function is called by the RV manager to initialize the 
+*				etm SWE before creating the task and calling etm_start. 
+*
+* Parameters  : None
+*
+* Return      : T_RVM_RETURN
+* 
+* History	  : 0.1 (20-August-2000)
+*									
+*
+******************************************************************************/
+
+T_RVM_RETURN etm_init(void)
+{
+    return RVM_OK;
+}
+
+
+/******************************************************************************
+* Function	  : etm_start
+*
+* Description : This function is called by the RV manager to start the etm
+*				SWE, it is the body of the task.
+*
+* Parameters  : None
+*
+* Return      : T_RVM_RETURN
+* 
+* History	  : 0.1 
+*									
+*
+******************************************************************************/
+
+T_RVM_RETURN etm_start(void)
+{
+    etm_task();
+	return RV_OK;
+}
+
+
+/******************************************************************************
+* Function	  : etm_stop
+*
+* Description : This function is called by the RV manager to stop the etm SWE.
+*
+* Parameters  : None
+*
+* Return      : T_RVM_RETURN
+* 
+* History	  : 0.1 								
+*
+******************************************************************************/
+
+T_RVM_RETURN etm_stop(void)
+{
+	return RVM_OK;
+}
+
+/******************************************************************************
+* Function	  : etm_kill
+*
+* Description : This function is called by the RV manager to kill the etm 
+*				SWE, after the etm_stop function has been called.
+*
+* Parameters  : None
+*
+* Return      : T_RVM_RETURN
+* 
+* History	  : 0.1 
+*									
+*
+******************************************************************************/
+
+T_RVM_RETURN etm_kill (void)
+{
+	rvf_free_buf(etm_env_ctrl_blk);
+	return RVM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_env.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,82 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_env.h 
+ *
+ * Declarations of the Riviera Generic Functions 
+ * (except handle message and handle timer).
+ *
+ * @author	aurent Sollier (l-sollier@ti.com) and Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  10/24/2001	Creation
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#ifndef _ETM_ENV_H_
+#define _ETM_ENV_H_
+
+#include "rvm/rvm_gen.h"
+#include "etm/etm_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+
+/**
+ * Mailbox ID used by the SWE.
+ */
+#define ETM_MAILBOX    RVF_TASK_MBOX_0
+
+/**
+ * @name Mem bank
+ * Memory bank size and watermark.
+ */
+/*@{*/
+#define ETM_MB_PRIM_SIZE	        ETM_MB1_SIZE
+#define ETM_MB_PRIM_WATERMARK       ETM_MB_PRIM_SIZE
+/*@}*/
+
+
+/** Define a structure used to store all the informations related to KPD's task
+ *	& MBs identifiers.
+ */
+typedef struct ctrl_blk
+{
+    T_RVF_MB_ID		prim_id;
+    T_RVF_ADDR_ID	addr_id;
+    T_RVM_RETURN	(*error_ft)(T_RVM_NAME        swe_name, 
+                                T_RVM_RETURN      error_cause,
+                                T_RVM_ERROR_TYPE  error_type,
+                                T_RVM_STRING      error_msg);
+} T_ETM_ENV_CTRL_BLK;
+
+
+/**
+ * @name Generic functions
+ * Generic functions declarations.
+ */
+/*@{*/
+
+T_RVM_RETURN etm_get_info(T_RVM_INFO_SWE *infoSWE);
+
+T_RVM_RETURN etm_set_info( T_RVF_ADDR_ID  addr_id,
+                           T_RV_RETURN    return_path[],
+                           T_RVF_MB_ID    bk_id[],
+                           T_RVM_RETURN   (*rvm_error_ft)(T_RVM_NAME swe_name, 
+                                                          T_RVM_RETURN error_cause, 
+                                                          T_RVM_ERROR_TYPE error_type, 
+                                                          T_RVM_STRING error_msg));
+
+T_RVM_RETURN etm_init(void);
+T_RVM_RETURN etm_start(void);
+T_RVM_RETURN etm_stop(void);
+T_RVM_RETURN etm_kill(void);
+
+/*@}*/
+
+
+#endif /* #ifndef _ETM_ENV_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_messages_i.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,160 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_message_i.h 
+ *
+ * Data structures that ETM SWE can receive.
+ *
+ * These messages are send by the bridge function. There are not available
+ * out of the SWE - Internaly messages.
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#ifndef _ETM_MESSAGES_I_H_
+#define _ETM_MESSAGES_I_H_
+
+#include "rv/rv_general.h"
+#include "rvm/rvm_use_id_list.h"
+
+
+typedef int (*ETM_CALLBACK_FUNC)(uint8*, int);
+
+
+/******************************************************************************
+ * Constants
+ *****************************************************************************/
+
+#define ETM_NAME_MAX_LEN 10
+
+#define ETM_MESSAGES_OFFSET BUILD_MESSAGE_OFFSET(ETM_USE_ID)
+
+
+/******************************************************************************
+ * Internal messages
+ *****************************************************************************/
+
+/**
+ * @name ETM_REGISTER_REQ
+ *
+ * Internal message.
+ *
+ * Message issued by TMETM to ETM task.
+ * This message is used to ...
+ */
+/*@{*/
+/** Message ID. */
+#define ETM_REGISTER_REQ (ETM_MESSAGES_OFFSET | 0x001)
+
+/** Message structure. */
+typedef struct 
+{
+    /** Message header. */
+    T_RV_HDR  header;
+
+    /** Magic key sequence informations. */
+    char                name[ETM_NAME_MAX_LEN];
+    int                 mid;
+	int                 task_id;
+    T_RVF_ADDR_ID       addr_id;
+	ETM_CALLBACK_FUNC	rx_callback_func;
+
+}  T_ETM_REGISTER_REQ;
+/*@}*/
+
+
+/**
+ * @name ETM_UNREGISTER
+ *
+ * Internal message.
+ *
+ * Message issued by TMETM to ETM task.
+ * This message is used to ...
+ */
+/*@{*/
+/** Message ID. */
+#define ETM_UNREGISTER (ETM_MESSAGES_OFFSET | 0x002)
+
+/** Message structure. */
+typedef struct 
+{
+    /** Message header. */
+    T_RV_HDR  header;
+    /** Magic key sequence informations. */
+    char                name[ETM_NAME_MAX_LEN];
+    int                 mid;
+	int                 task_id;
+    T_RVF_ADDR_ID       addr_id;      
+	ETM_CALLBACK_FUNC	rx_callback_func;
+    
+}  T_ETM_UNREGISTER;
+/*@}*/
+
+
+/**
+ * @name ETM_DATA_FWR
+ *
+ * Internal message.
+ *
+ * Message issued by TMETM to ETM task.
+ * This message is used to ...
+ */
+/*@{*/
+/** Message ID. */
+#define ETM_DATA_FWR (ETM_MESSAGES_OFFSET | 0x003)
+
+/** Message structure. */
+typedef struct 
+{
+    /** Message header. */
+    T_RV_HDR  header;
+
+    /** Magic key sequence informations. */
+    int          size;
+    char         mid;
+    uint8        data[255];
+    T_RV_RETURN  return_path;
+
+}  T_ETM_DATA_FWR;
+/*@}*/
+
+/**
+ * @name TM3_DATA_FWR
+ *
+ * Internal message.
+ *
+ * Message issued by TMETM to ETM task.
+ * This message is used to ...
+ */
+/*@{*/
+/** Message ID. */
+#define ETM_TM3_DATA_FWR (ETM_MESSAGES_OFFSET | 0x004)
+
+/** Message structure. */
+typedef struct 
+{
+    /** Message header. */
+    T_RV_HDR  header;
+    /** Magic key sequence informations. */
+    int          size;
+    char         cid;
+    uint8        data[255];
+    T_RV_RETURN  return_path;
+
+}  T_ETM_TM3_DATA_FWR;
+/*@}*/
+
+
+
+#endif /* _ETM_MESSAGES_I_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_misc.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,139 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_misc.h 
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#ifndef _ETM_MISC_H_
+#define _ETM_MISC_H_
+
+
+/******************************************************************************
+ * Usefull Header 
+ *****************************************************************************/
+
+#ifndef _WINDOWS
+#include "swconfig.cfg"
+#include "sys.cfg"
+#include "chipset.cfg"
+//#include "testmode.cfg"
+#endif
+
+#include "l1_confg.h"
+
+/* Riviera useful header */
+#include "rv/rv_general.h"
+#include "rvm/rvm_gen.h"
+#include "rvf/rvf_target.h"
+#include "rvf/rvf_api.h"
+#include "rvt/rvt_gen.h"
+
+
+/* include the usefull L1 header */
+#ifdef _WINDOWS
+#define BOOL_FLAG
+#define CHAR_FLAG
+#endif
+
+#include "l1_types.h"
+#include "l1audio_const.h"
+#include "l1audio_cust.h"
+#include "l1audio_defty.h"
+#include "l1audio_msgty.h"
+#include "l1audio_signa.h"
+
+#if TESTMODE
+#include "l1tm_defty.h"
+#endif      
+
+#if (L1_GTT == 1)
+#include "l1gtt_defty.h"
+#endif      
+
+#include "l1_const.h"
+#include "l1_defty.h"
+#include "l1_msgty.h"
+#include "l1_signa.h"
+
+#ifdef _WINDOWS
+#define L1_ASYNC_C
+#endif
+
+#include "l1_varex.h"
+
+
+/******************************************************************************
+ * Defines 
+ *****************************************************************************/
+
+#define TM3_PACKET_SIZE 128
+#define ETM_PACEKT_SIZE 256
+
+// This is the return TM3 packet structure
+// HACK! - taken from l1tm_msgty.h
+typedef struct 
+{
+    unsigned char cid;
+    unsigned char index;
+    unsigned char status;
+    unsigned char size; // size of result[] array
+    unsigned char result[TM3_PACKET_SIZE];
+} T_TM3_PKT; 
+
+
+// This is the new TM packet structure
+typedef struct
+{
+    unsigned short size; // size of data[]
+    int index;           // index into data[] - for put()/get() functions
+    unsigned char  mid;
+    unsigned char  status;
+    unsigned char  data[ETM_PACEKT_SIZE]; // include cksum
+} T_ETM_PKT;
+
+
+#ifndef BASIC_TYPES
+#define BASIC_TYPES
+typedef signed   char  int8;
+typedef unsigned char  uint8;
+typedef signed   short int16;
+typedef unsigned short uint16;
+typedef signed   int   int32;
+typedef unsigned int   uint32;
+#endif
+
+/******************************************************************************
+ * Prototypes 
+ *****************************************************************************/
+
+void *etm_malloc(int size);
+int etm_free(void *addr);
+
+int etm_at(T_ETM_PKT *pkt, char *buf);
+
+/******************************************************************************
+ * Internal Error codes 
+ *****************************************************************************/
+
+enum {
+
+    ETM_TASK_REGISTERED = -100,
+    ETM_DB_LIMIT        = -101
+
+};
+
+
+#endif // _ETM_MISC_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_pool_size.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,35 @@
+/**
+ * @file	etm_pool_size.h
+ *
+ * Declarations of:
+ * - the memory bank sizes and their watermark
+ * - the SWE stack size
+ * - the pool size needed (generally the sum of memory bank and stack sizes)
+ *
+ * @author	Vincent Oberle
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	07/08/2003	Vincent Oberle			Extracted from rvf_pool_size.h
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __ETM_POOL_SIZE_H_
+#define __ETM_POOL_SIZE_H_
+
+
+/*
+ * Values used in etm_env.h
+ */
+#define ETM_STACK_SIZE (1024)
+#define ETM_MB1_SIZE   (1024)
+#define ETM_POOL_SIZE  (ETM_STACK_SIZE + ETM_MB1_SIZE)
+
+
+#endif /*__ETM_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_task.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,543 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm.c
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *  03/03/2004  Upadted regarding the ATP + minor ETM DB handling updates
+ *  28/07/2004  Fixed ETM database issue
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#include "etm/etm.h"
+#include "etm/etm_api.h"
+#include "etm/etm_messages_i.h"
+#include "etm/etm_trace.h"
+#include "etm/etm_env.h"
+
+#include "audio/audio_api.h"
+
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvt/rvt_gen.h"
+#include "rvf/rvf_target.h" 
+#include "rv/rv_defined_swe.h"
+
+#include <string.h>
+
+#ifdef RVM_LCC_SWE
+    #include "lcc/lcc_api.h"
+    #include "lcc/lcc_cfg_i.h"
+    #include "lcc/lcc.h"
+    #include "lcc/lcc_env.h"
+    #include "lcc/lcc_trace.h"
+#endif
+
+// Version of the ETM TASK moved to etm_version.h
+//const uint16 etm_task_revision = (1<<12) | (0x1);
+
+/******************************************************************************
+ * Globals 
+ *****************************************************************************/
+
+#define ETM_DB_MAX     16  // Limited of registered SWEntities into ETM DB
+#define ETM_DB_NO_USE  0xFFFFFFFF  //
+
+typedef struct
+{	
+    char                swe_name[ETM_NAME_MAX_LEN];
+    int                 mid;
+	int                 task_id;
+    T_RVF_ADDR_ID       addr_id;    // Unique mailbox (ID) of the SWE which will
+                                    //receive the message
+    ETM_CALLBACK_FUNC	rx_callback_func;
+} T_ETM_USER_DB;
+
+
+static T_ETM_USER_DB etm_user_db[ETM_DB_MAX];
+
+static int etm_db_counter = 0;
+
+
+/******************************************************************************
+ * Prototypes 
+ *****************************************************************************/
+
+extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+#ifdef RVM_LCC_SWE
+extern T_PWR_CTRL_BLOCK *pwr_ctrl;
+#endif
+
+int etm_database_manager(T_RV_HDR *msg_p);
+int etm_forward_packet(int mid, T_RV_HDR *msg);
+void etm_error_packet_send(int mid, int error);
+void etm_receive(unsigned char *inbuf, unsigned short size);
+int etm_ffs_pkt_receive(uint8 *data, int size);
+
+extern int etm_at_atp_message(void *msg);
+#ifdef RVM_LCC_SWE
+extern int etm_pwr_ul(void *msg);
+extern int etm_pwr_dl(T_ETM_PKT *pkt, uint8 *buf, int insize);
+#endif
+
+/******************************************************************************
+ * Main Testmode Task Loop
+ *****************************************************************************/
+
+T_RV_RET etm_task(void)
+{  
+    extern int etm_core_init(void);
+    extern int etm_audio_init(void);
+#ifdef RVM_LCC_SWE
+    extern int etm_pwr_init(void);
+#endif
+
+    T_RV_HDR  *msg = NULL;
+    T_ETM_PKT *pkt = NULL; 
+    UINT32 start_time = 0;
+    UINT32 end_time   = 0;
+    UINT16 recv_event, i;  
+
+    int status = RV_OK, buf_size;
+    
+    /* Entity registration to ETM */
+    /* This should be in the individual SWE init. function*/
+    status = etm_core_init();
+    status = etm_audio_init();
+#ifdef RVM_LCC_SWE
+    status = etm_pwr_init();
+#endif
+
+    while (1)
+    {
+        recv_event = rvf_wait(0xffff,0); /* Wait (infinite) for all events. */
+
+        start_time = rvf_get_tick_count();
+        tr_etm(TgTrEtmLow,"ETM: _task: Time Waiting (%d) tick", start_time - end_time);
+        tr_etm(TgTrEtmLow,"ETM: _task: Time Start(%d)", start_time);
+
+        tr_etm(TgTrEtmLow,"ETM: _task: Got message passing to bit filter (0x%x)", recv_event);
+
+
+        if (!(recv_event & RVF_TASK_MBOX_0_EVT_MASK))
+            continue;
+        
+        /* Read the message in the ETM mailbox */
+        if ((msg = rvf_read_mbox(ETM_MAILBOX)) == NULL)
+            continue;
+        
+        tr_etm(TgTrEtmLow,"ETM: _task: msg_id(0x%x)", msg->msg_id);
+        
+            switch (msg->msg_id) {
+                /* Entity registration request or unregistration */
+            case ETM_REGISTER_REQ:
+            case ETM_UNREGISTER:
+                status = etm_database_manager(msg);
+                break;
+                /* ETM packet received */
+            case ETM_DATA_FWR:
+                if ((status = etm_forward_packet(((T_ETM_DATA_FWR *) msg)->mid, msg))
+                    != ETM_OK)
+                    etm_error_packet_send(((T_ETM_DATA_FWR *) msg)->mid, status);
+                break;
+                /* TM3 packet received */
+            case ETM_TM3_DATA_FWR:
+                if ((status = etm_forward_packet(ETM_TM3, msg)) != ETM_OK)
+                    etm_error_packet_send(ETM_TM3, status);
+                break;
+            default:
+                tr_etm(TgTrEtmLow,"ETM: _task: msg_id '0x%x' NOT supported",
+                       msg->msg_id);
+            }
+
+        if (status != ETM_OK) {
+            tr_etm(TgTrFatal,"ETM: _task: mid(0x%x) ERROR(%d)", 
+                   ((T_ETM_DATA_FWR *) msg)->mid, status);
+            etm_free(msg); // Free the message
+        }
+        
+        end_time = rvf_get_tick_count();
+        tr_etm(TgTrEtmLow,"ETM: _task: Time End (%d)", end_time);
+        tr_etm(TgTrEtmLow,"ETM: _task: Time Total (%d) tick", end_time - start_time);
+    }
+    
+    return RV_OK;
+}
+
+
+void etm_error_packet_send(int mid, int error)
+{
+    T_ETM_PKT *pkt;
+
+    tr_etm(TgTrFatal,"ETM: _error_packet_send: Module(0x%x) ERROR(%d)", mid, error); 
+
+    if (error == ETM_NOMEM) {
+        rvf_dump_mem();  
+    }
+    
+    if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
+        rvf_dump_mem();  
+        return;
+    }
+    
+    // Init. of return packet
+    pkt->mid    = mid;
+    pkt->status = -error;
+    pkt->size   = 0;
+    pkt->index  = 0;
+
+    etm_pkt_send(pkt);
+    etm_free(pkt); // Free return packet
+}
+
+
+/* Forwarding of DATA to the SWE can either be done by message/primitive or callback */
+int etm_forward_packet(int mid, T_RV_HDR* msg)
+{
+    ETM_CALLBACK_FUNC rx_callback_func = NULL;
+    int i, cid, status = ETM_OK;
+    T_ETM_DATA_READY* message_p;
+    T_RVF_ADDR_ID swe_addr_id = 0;
+
+    // Search for supported MID in the table
+    for (i = 0; etm_user_db[i].mid != TABLE_END; i++)
+    {
+        tr_etm(TgTrEtmLow,"ETM: _forward_packet: Lookup in db for mid(0x%x)", mid);
+    
+        if (etm_user_db[i].mid == mid) {
+            rx_callback_func = etm_user_db[i].rx_callback_func;
+            swe_addr_id = etm_user_db[i].addr_id;
+            break;
+        }
+    }
+
+    tr_etm(TgTrEtmLow,"ETM: _forward_packet: rx_callback_func(%d) swe_addr_id(%d)", 
+           *rx_callback_func, swe_addr_id);
+
+    // Invoke the SWE mailbox
+    if (swe_addr_id) {
+        /* Allocate the memory for the message to send */
+        if ((message_p = (T_ETM_DATA_READY*) etm_malloc(sizeof(T_ETM_DATA_READY))) == NULL)
+            return ETM_NOMEM; 
+
+        /* Fill the header of the message */
+        message_p->header.msg_id = ETM_DATA_READY;
+        
+        /* Fill the address source id */
+        message_p->header.src_addr_id   = rvf_get_taskid(); 
+        message_p->header.dest_addr_id  = etm_env_ctrl_blk->addr_id;
+        message_p->header.callback_func = NULL;
+        
+        /* Fill the data in the message */
+        memcpy(((T_ETM_DATA_READY*) message_p)->data, ((T_ETM_DATA_FWR*) msg)->data,
+               ((T_ETM_DATA_FWR*) msg)->size);
+        
+        /* Send the message to the entity */
+        if ((status = rvf_send_msg(swe_addr_id, message_p)) != RV_OK) {
+            tr_etm(TgTrFatal,"ETM: _forward_packet: Failed to sent message - ERROR(%d)", 
+                   status);
+            return ETM_RV_FATAL;
+        }
+        etm_free(msg); // Free the message
+    }
+    // Invoke the SWE callback function
+    else if (rx_callback_func) {
+        tr_etm(TgTrEtmLow,"ETM: _forward_packet: to mid(0x%x)", mid);
+        status = rx_callback_func (((T_ETM_DATA_FWR*) msg)->data, ((T_ETM_DATA_FWR*) msg)->size);
+        rx_callback_func = NULL;
+        if (status != ETM_OK)
+            return status;        
+        etm_free(msg); // Free the message
+    }
+    else {
+        return ETM_NOSYS;
+    }
+    
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * Get and Free buffer (Internal Functions)
+ *****************************************************************************/
+
+void *etm_malloc(int size)
+{
+    /* Memory bank status (red, yellow, green) */
+    T_RVF_MB_STATUS mb_status;
+    void *addr;
+
+    mb_status = rvf_get_buf(etm_env_ctrl_blk->prim_id, size, &addr);
+
+    /* The flag returned by rvf_get_buf is red, there is not enough
+     * memory to allocate the buffer. */
+    if (mb_status == RVF_RED) {
+		tr_etm(TgTrFatal, "ETM: _malloc: Error to get memory");
+        return NULL;
+	}
+    /* The flag is yellow, there will soon be not enough memory anymore. */
+	else if (mb_status == RVF_YELLOW) {
+		tr_etm(TgTrFatal, "ETM: _malloc: Getting short on memory");
+	}
+
+    tr_etm(TgTrEtmLow,"ETM: _malloc: size(%d) at addr(0x%x)", size, addr);
+    return addr;
+}
+
+int etm_free(void *addr)
+{
+    int status;
+
+    tr_etm(TgTrEtmLow,"ETM: _free: addr(0x%x)", addr);
+
+    if ((status = rvf_free_buf(addr)) != RV_OK) {
+        tr_etm(TgTrFatal, "ETM: _free: ERROR(%d)", status);
+    }
+    
+    return ETM_RV_FATAL;
+}
+
+
+/******************************************************************************
+ * ETM receive Functions API (Internal Functions)
+ ******************************************************************************/
+
+/* The input pointer buf point at a complete TM3 packet. */
+int etm_tm3_data_forward(uint8 *buf, int size)
+{
+    /* Type for a registration event. */
+    T_ETM_TM3_DATA_FWR *msg;
+
+    tr_etm(TgTrEtmLow, "ETM: _tm3_data_forward: cid(0x%x) size(%d)", *buf, size);
+
+    /* Allocate the memory for the message to send */
+    if ((msg = (T_ETM_TM3_DATA_FWR*) etm_malloc(sizeof(T_ETM_TM3_DATA_FWR))) == NULL)
+            return ETM_NOMEM; 
+
+    /* Fill the message id */
+    msg->header.msg_id        = ETM_TM3_DATA_FWR;
+
+    /* Fill the address source id */
+    msg->header.src_addr_id   = rvf_get_taskid();
+    msg->header.dest_addr_id  = etm_env_ctrl_blk->addr_id;
+    msg->header.callback_func = NULL;
+
+    /* Fill the message parameters */
+    msg->size = size;
+    msg->cid  = *buf;
+    memcpy(&msg->data, buf, size);
+
+// At this point, all the data have been parsed and copied into
+// the ETM primitive.  Now we send the primitive to the ETM task.
+    if (rvf_send_msg(etm_env_ctrl_blk->addr_id, msg) != RV_OK) {
+        tr_etm(TgTrFatal, "ETM: _tm3_data_forward: FAILED");
+        return ETM_RV_FATAL;  // msg is auto freed by rvf_send_msg() if error
+    }
+
+    return ETM_OK;
+}
+
+
+/* The input pointer buf point at payload of the TM packet, minus mid and cksum. */
+int etm_data_forward(char mid, uint8 *inbuf, int size)
+{
+    /* Type for a registration event. */
+    T_ETM_DATA_FWR *msg;
+
+    tr_etm(TgTrEtmLow, "ETM: _data_forward: mid(0x%x) size(%d)", mid, size);
+
+    /* Allocate the memory for the message to send */
+    if ((msg = (T_ETM_DATA_FWR*) etm_malloc(sizeof(T_ETM_DATA_FWR))) == NULL)
+            return ETM_NOMEM; 
+
+    /* Fill the message id */
+    msg->header.msg_id        = ETM_DATA_FWR;
+
+    /* Fill the address source id */
+    msg->header.src_addr_id   = rvf_get_taskid(); 
+    msg->header.dest_addr_id  = etm_env_ctrl_blk->addr_id;
+    msg->header.callback_func = NULL;
+
+    /* Fill the message parameters */
+    msg->size = size;
+    msg->mid  = mid;
+    memcpy(&msg->data, inbuf, size);
+
+// At this point, all the data have been parsed and copied into
+// the ETM primitive.  Now we send the primitive to the ETM task.
+    if (rvf_send_msg(etm_env_ctrl_blk->addr_id, msg) != RV_OK) {
+        tr_etm(TgTrFatal, "ETM: _data_forward: FAILED");
+        return ETM_RV_FATAL;  // msg is auto freed by rvf_send_msg() if error
+    }
+
+    return ETM_OK;
+}
+
+
+/* This function is registred in the RVT module as the TestMode receive function */
+/* It's called every time a TestMode packet is received on the UART and the */
+/* data is forwarded to the ETM Entity via a message/primitiv */
+/* The function is a callback func. used by the RVT TASK -> UART RX. */
+
+void etm_receive(uint8 *inbuf, unsigned short size)
+{
+    int error = ETM_NOSYS, i, index;
+    char mid;
+    unsigned char cksum;
+    T_ETM_PKT *pkt;
+
+    tr_etm(TgTrEtmLow, "ETM: _receive: inbuf size(%d)", size);
+
+    // Copy data payload size (size minus MID/CID byte and checksum byte)
+    mid = *inbuf++;
+
+    cksum = mid;
+    for (i = 0; i < size - 1; i++) {
+        cksum ^= inbuf[i];
+    }
+    
+    if (cksum != 0) {
+        error = ETM_PACKET;
+        goto ETM_RECEIVE_END;
+    }
+    
+    // Check it's a TM3 packet
+    if ((0x20 <= mid && mid < 0x27) ||
+        (0x30 <= mid && mid < 0x3A) ||
+        (0x40 <= mid && mid < 0x49) ||
+        (0x50 <= mid && mid < 0x57)) {
+        // Forward complete TM3 packet
+        error = etm_tm3_data_forward(--inbuf, size);
+    }
+    else {
+        /* Controlling of receptor for regisration */
+        for (index=0; index < etm_db_counter; index++)
+        {
+            if (etm_user_db[index].mid == mid) {
+                // Forward ETM packet without <mid> and <cksum>, -2 in size
+                error = etm_data_forward(mid, inbuf, size - 2);
+                break;
+            }
+            else if ((index == etm_db_counter) && (etm_user_db[index].mid != mid)) {
+                tr_etm(TgTrFatal, "ETM: _receive: mid(0x%x) not supported", mid);
+            }
+        }
+    }
+
+ETM_RECEIVE_END:
+    /* Fill in Error status in ETM packet and send */
+    if (error) {
+        if (error == ETM_NOMEM) {
+            rvf_dump_mem();
+            return;
+        }
+
+        if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL)
+            return; 
+        pkt->size   = 0;
+        pkt->mid    = mid;
+        pkt->status = -error;
+        
+        etm_pkt_send(pkt);
+        etm_free(pkt); // Free return Packet
+    }
+}
+
+
+/******************************************************************************
+ * Registration manager Functions API (Internal function)
+ ******************************************************************************/
+
+int etm_database_add(T_ETM_REGISTER_REQ *msg_p, int index)
+{
+
+    memcpy(etm_user_db[index].swe_name, msg_p->name, strlen(msg_p->name));
+    etm_user_db[index].mid              =  msg_p->mid;
+    etm_user_db[index].task_id          =  msg_p->task_id;
+    etm_user_db[index].addr_id          =  msg_p->addr_id;
+    etm_user_db[index].rx_callback_func =  msg_p->rx_callback_func;
+
+    etm_user_db[index+1].mid            =  TABLE_END;
+
+    return ETM_OK;
+}
+
+
+int etm_database_manager(T_RV_HDR *msg_p)
+{
+    int index, mid, status;
+
+    if (msg_p->msg_id == ETM_REGISTER_REQ) {
+        mid = ((T_ETM_REGISTER_REQ *) msg_p)->mid;
+        
+        tr_etm(TgTrEtmLow,"ETM: _database_manager: _REGISTER_REQ reguest is received from (%s)", 
+               ((T_ETM_REGISTER_REQ *) msg_p)->name); 
+        
+        /* Lookup in the ETM DB array */
+        for (index=0; index < ETM_DB_MAX; index++)
+        {
+            /* Use unregistrered space */
+            if ((etm_user_db[index].mid == ETM_DB_NO_USE) && (etm_user_db[index].addr_id == 0) && 
+                (etm_user_db[index].rx_callback_func == NULL)) {
+                status = etm_database_add((T_ETM_REGISTER_REQ*) msg_p, index);
+                etm_db_counter++;
+                etm_free(msg_p); // Free Message
+                return ETM_OK;
+            }
+            /* Reject double registration */
+            else if ((etm_user_db[index].mid == mid) &&
+                     ((etm_user_db[index].addr_id != 0) || (etm_user_db[index].rx_callback_func != NULL))) {
+                tr_etm(TgTrFatal,"ETM: _database_manager: The Module(0x%x) is registrered", mid);
+                etm_free(msg_p); // Free Message
+                return ETM_OK;
+            }
+        }
+                    
+        /* Add the entity to the etm database */
+        if (etm_db_counter < ETM_DB_MAX) {
+            status = etm_database_add((T_ETM_REGISTER_REQ*) msg_p, etm_db_counter);
+            etm_db_counter++;
+            etm_free(msg_p); // Free Message
+            return ETM_OK;
+        }
+        
+        etm_free(msg_p); // Free Message
+        return ETM_DB_LIMIT;
+    }
+    
+    
+    if (msg_p->msg_id == ETM_UNREGISTER) {
+        mid = ((T_ETM_UNREGISTER *) msg_p)->mid;
+        tr_etm(TgTrEtmLow,"ETM: _database_manager: _UNREGISTER reguest is received from (%s)",
+               ((T_ETM_REGISTER_REQ *) msg_p)->name);
+        
+        /* Lookup in the array, if the SWE is stocked then clean it*/
+        for (index=0; index < ETM_DB_MAX; index++) {
+            if (etm_user_db[index].mid == mid) {
+                etm_user_db[index].mid              = ETM_DB_NO_USE;
+                etm_user_db[index].addr_id          = 0;
+                etm_user_db[index].rx_callback_func = NULL;
+                etm_db_counter--;
+                etm_free(msg_p); // Free Message
+                return ETM_OK;
+            }			
+        }
+
+        etm_free(msg_p); // Free Message
+        return ETM_INVAL;
+    }
+    
+    etm_free(msg_p); // Free Message
+    return ETM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_tests.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,24 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_tests.c
+ *
+ * Test Suite for SWE ETM
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  23/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+int etm_test_suite(void)
+{
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_tmcore.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,538 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	tmcore.c 
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *  02/07/2003  Removed l1_config.TestMode check from CODEC Write
+ *  17/03/2004  Updated etm_version
+ *  30/03/2004  Updated etm_dieID_read() func. regarding get die id for 16 bits
+ *              instead of 8 bits.
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+#include "rv/rv_defined_swe.h"
+#include "rv/rv_general.h"
+
+#include "etm/etm.h"
+#include "etm/etm_api.h"
+#include "etm/etm_trace.h"
+#include "etm/etm_version.h"
+
+#include "abb/abb.h"
+
+#include "spi/spi_drv.h"
+extern void tr_etm_init(unsigned int mask);
+
+// Version of the ETM CORE module
+// See the file etm_version.h
+
+/******************************************************************************
+ * DIE ID settings 
+ *****************************************************************************/
+
+#define BE_STREAM_TO_ARRAY(a, p, l) {register INT32 i; for (i = 0; i < l; i++) a[i] = *(UINT8*)(p)++;}
+
+/* DIE ID register */
+#if ((CHIPSET == 8) || (CHIPSET == 10) || (CHIPSET == 11))      //For D-Sample: $CHIPSET  =  8 (=10 for D-sample AMR, 11 for GSMLITE).
+#define DIE_ID_REG    (MEM_DEV_ID0 | 0xF010) //+ 0xFFFEF010 for Calypso
+#else
+#if (CHIPSET == 12)                         //For E-Sample: $CHIPSET   =  12.
+#define DIE_ID_REG    (0xFFFE0000 | 0xF004)	//+ 0xFFFEF004 for Calypso Plus
+#endif
+#endif
+
+/* DIE ID SIZE is 4 words (16 bits)long */
+#define DIE_ID_SIZE        4
+
+//Copied from rv_general.h:
+//#define BE_STREAM_TO_ARRAY(a, p, l) {register INT32 i; for (i = 0; i < l; i++) a[i] = *(UINT16*)(p)++;}
+
+
+/******************************************************************************
+ * Internal prototypes 
+ *****************************************************************************/
+
+T_ETM_PKT *etm_core_setup(uint8 fid);
+int etm_core(uint8 *buf, int size);
+
+/******************************************************************************
+ * Register the Core Module to the ETM database 
+ *****************************************************************************/
+
+int etm_core_init(void)
+{
+    int result; 
+
+    result = etm_register("CORE", ETM_CORE, 0, 0, etm_core);
+    return result;    
+}
+
+
+/******************************************************************************
+ * Memory read/write Functions
+ *****************************************************************************/
+
+// Describe the payload of the mem protocol !!!!!!
+// |--type(1)-|--partnum(1)-|--addr(4)-|--data(?)-|
+
+int etm_mem(T_ETM_PKT *pkt, uint8 *buf)
+{
+   int num, unitsize, error;
+   uint8 type, param;
+   uint8  *mem8;
+   uint16 *mem16;
+   uint32 *mem32;
+   uint32 addr, tmp;
+   static unsigned char test_buf[64];
+
+   param = unitsize = *buf & 0x3;
+   if (unitsize == 0)
+       unitsize = 4;
+
+   type = *buf & 0x10;
+   buf++;
+
+   num = *buf++;
+   addr = etm_get32(buf);
+   buf += 4;
+
+   tr_etm(TgTrCore, "ETM CORE: _mem: type(0x%x) addr(0x%x) partnum(%d)", type, addr, num);
+
+   // Put 'parameter' in return packet
+   if ((error = etm_pkt_put8(pkt, param)) < 0) {
+       return error;
+   }
+      
+   switch (type) {
+   case 0: // READ(0x00)
+       switch (unitsize) {
+       case 1:
+           mem8 = (uint8 *) addr;
+           while (num--) {
+               if ((error = etm_pkt_put8(pkt, *mem8++)) < 0)
+                   break;
+           }
+           break;
+       case 2:
+           mem16 = (uint16 *) addr;
+           while (num--) {
+               if ((error = etm_pkt_put16(pkt, *mem16++)) < 0)
+                   break;
+           }
+           break;
+       case 4:
+           mem32 = (uint32 *) addr;
+           while (num--) {
+               if ((error = etm_pkt_put32(pkt, *mem32++)) < 0)
+                   break;
+           }
+           break;
+       } 
+       break;
+
+   case 16: // WRITE(0x10)  
+       switch (unitsize) {
+       case 1:
+           mem8 = (uint8 *) addr;
+           while (num--) {
+               *mem8++ = etm_get8(buf);
+               buf += 1;
+           }
+           break;
+       case 2:
+           mem16 = (uint16 *) addr;
+           while (num--) {
+               *mem16++ = tmp = etm_get16(buf); 
+               buf += 2;
+           }
+           break;
+       case 4:
+           mem32 = (uint32 *) addr;
+           while (num--) {
+               *mem32++ = etm_get32(buf); 
+               buf += 4;
+           }
+           break;
+       }
+       break;
+   default:
+       return ETM_NOSYS;
+   }
+   
+   if (error < 0)
+       return error;
+   
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * CODEC Functions
+ *****************************************************************************/
+
+// ETM sends both page value and register address in one byte.
+// Bit field is:  PPPR RRRR
+// where P = page bit, R = register address bits and X = don't care bits.  
+
+int etm_codec_write(T_ETM_PKT *pkt, uint8 *buf)
+{
+    extern void ABB_Write_Register_on_page(SYS_UWORD16 page, SYS_UWORD16 reg_id, SYS_UWORD16 value);
+    uint16  page, reg, data;
+    int result, reg_data;
+
+    reg_data = *buf++;
+    if ((result = etm_pkt_put8(pkt, reg_data)) < 0)
+        return result;
+
+    page = (reg_data  >> 5) & 0x3;
+    reg  =  reg_data        & 0x1F;
+    data = etm_get16(buf);
+   
+    tr_etm(TgTrCore, "ETM CORE: _codec_write: page(%d) reg(%d) data(0x%x)",
+           page, reg, (data & 0x3ff));
+
+    if (page > 7 && reg > 32)
+        return ETM_INVAL;
+    else {
+        // The function below expects a 1 for page 0 and a 2 for page 1.
+        // The register address value is left-shifted by 1 since LSB is read/write command bit.
+        // The value is written in the 10 MSB's of register.
+        ABB_Write_Register_on_page(page + 1, reg << 1, (data & 0x3ff));
+    }    
+
+    return ETM_OK;
+}
+
+
+int etm_codec_read(T_ETM_PKT *pkt, uint8 *buf)
+{
+    extern SYS_UWORD16 ABB_Read_Register_on_page(SYS_UWORD16 page, SYS_UWORD16 reg_id);
+    volatile uint16 value;
+    uint16 page, reg;
+    int result, reg_data;
+  
+    reg_data = *buf;
+    if ((result = etm_pkt_put8(pkt, reg_data)) < 0)
+        return result;
+
+    page = (reg_data  >> 5) & 0x3;
+    reg  =  reg_data        & 0x1F;
+    
+    if (page > 7 && reg > 32)
+        return ETM_INVAL;
+
+    // The function below expects a 1 for page 0 and a 2 for page 1.
+    // The register value is left-shifted by 1 since LSB is read/write command bit.
+    value = ABB_Read_Register_on_page(page + 1, (reg << 1));
+    
+    tr_etm(TgTrCore, "ETM CORE: _codec_read: page(%d) reg(%d) value(0x%x)", page, reg, value);
+    
+    result = etm_pkt_put16(pkt, value);
+    return result;
+}
+
+
+/******************************************************************************
+ * Echo and Reset Functions
+ *****************************************************************************/
+
+//structur of data dl: |delay|recvsize|num| = 3x2 bytes
+int etm_echo(T_ETM_PKT *pkt, uint8 *data)
+{
+    int delay, sendsize, i, num, count;
+
+    tr_etm(TgTrCore, "etm_echo:");
+
+    delay = etm_get16(data);
+    data += 2;
+
+    sendsize = etm_get16(data);
+    if (sendsize > 240)
+        return ETM_INVAL;
+
+    data += 2;
+    num = etm_get16(data);
+
+    tr_etm(TgTrCore, "ETM CORE: _echo: delay(%d) sendsize(%d) num(%d)", 
+           delay, sendsize, num);
+
+    if (delay > 0) {
+        rvf_delay((delay + 32) * 14 / 64);
+    }
+    
+    for (i = 0; i < sendsize; i++) {
+        pkt->data[i+1] = i;        // data[0] = fid
+    }
+
+    pkt->size = sendsize; 
+
+    return ETM_OK;
+}
+
+
+int etm_reset(void)
+{
+// The reset code is taken form Fluid->cmd.c
+    int i;
+
+    tr_etm(TgTrCore, "ETM CORE: _reset: Target is Reset");
+    
+    // Setup watchdog timer and let it timeout to make a reset
+    *(volatile uint16*) 0xfffff804 = 0xFFFF;  // Timer to watchdog
+    *(volatile uint16*) 0xfffff800 = 0x0080;  // Start timer
+		// Apparently works it only if we read this register?
+    i = *(volatile uint16*) 0xfffff802;
+    *(volatile uint16*) 0xfffff802 = 0x0001;  // Load timer
+    
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ * Set Test Controls
+ *****************************************************************************/
+
+int etm_debug(T_ETM_PKT *pkt, uint8 *buf)
+{
+   int type, error, data;
+   
+   static char *p;
+
+   type = *buf & 0x0F;   
+   buf++; 
+
+   data = etm_get32(buf);
+
+   tr_etm(TgTrCore, "ETM CORE: _debug: type(%d) data(0x%x)", type, data);
+
+   switch (type) {
+   case 0: // (0x00) Allocate Test Buffer
+       if ((p = etm_malloc(data)) == NULL)
+           error = ETM_NOMEM;
+       error = etm_pkt_put32(pkt, (int) p); 
+       break;
+   case 1: // (0x01) Free Test Buffer.
+       p = (char *) data;
+       etm_free(p);                         
+       break;
+   case 2: // (0x02) Set ETM Trace mask
+       tr_etm_init(data);                   
+       break;
+   case 3: // (0x03) Set read all mem banks stat
+       rvf_dump_mem();
+       rvf_dump_pool();
+       rvf_dump_tasks();
+       break;
+   default:
+       error = ETM_NOSYS;                  
+   }
+
+   if (error < 0)
+       return error;
+
+    return ETM_OK;
+}
+
+/******************************************************************************
+ * Get Version of ...
+ *****************************************************************************/
+// This is in development ...
+
+int etm_version(T_ETM_PKT *pkt, uint8 *buf)
+{
+    extern uint16 etm_audio_revision;
+    extern uint16 etm_task_revision;
+    int error, fid, ffs_tm_version;
+    volatile int revision = 0;
+    T_VERSION *l1s_version;
+
+    fid = etm_get32(buf);
+
+    tr_etm(TgTrCore, "ETM CORE: _version: fid(0x%x)", fid);
+
+    l1s_version = (T_VERSION*) l1s_get_version(); 
+
+    switch (fid) {
+// Code Versions related to ETM modules 
+    case SW_REV_ETM_CORE:
+        error = etm_pkt_put32(pkt, ETM_CORE_VERSION);
+        break;
+    case SW_REV_ETM_AUDIO:
+        error = etm_pkt_put32(pkt, ETM_AUDIO_VERSION);
+        break;
+//    case SW_REV_ETM_FFS:
+//        ffs_query(Q_FFS_TM_VERSION, &ffs_tm_version);
+//        error = etm_pkt_put32(pkt, ffs_tm_version);
+        break;
+//    case SW_REV_ETM_RF: // Layer1 Testmode Version
+//        error = etm_pkt_put32(pkt, TESTMODEVERSION);
+//        break;
+    case SW_REV_ETM_PWR:
+        error = etm_pkt_put32(pkt, ETM_PWR_VERSION);
+        break;
+    case SW_REV_ETM_BT:
+        error = ETM_NOSYS;
+        break;
+    case SW_REV_ETM_TASK:
+        error = etm_pkt_put32(pkt, ETM_VERSION);
+        break;
+    case SW_REV_ETM_API:
+        error = etm_pkt_put32(pkt, ETM_API_VERSION); 
+        break;
+// Code Versions related to L1, see in l1_defty.h 
+// Get the version on this way "revision = l1s.version.dsp_code_version;" 
+// doesn't work because of struct aligment -> compile flag -mw !!!!
+    case SW_DSP_CODE_VERSION:
+        revision = ((T_VERSION*) l1s_version)->dsp_code_version;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    case SW_DSP_PATCH_VERSION:
+        revision = ((T_VERSION*) l1s_version)->dsp_patch_version;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    case SW_MCU_TCS_PROGRAM_RELEASE:
+        revision = ((T_VERSION*) l1s_version)->mcu_tcs_program_release;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    case SW_MCU_TCS_OFFICIAL: // This version allso identify version of Layer1 
+        revision = ((T_VERSION*) l1s_version)->mcu_tcs_official;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    case SW_MCU_TCS_INTERNAL:
+        revision = ((T_VERSION*) l1s_version)->mcu_tcs_internal;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    case SW_MCU_TM_VERSION:
+        revision = ((T_VERSION*) l1s_version)->mcu_tm_version;
+        error = etm_pkt_put32(pkt, revision);
+        break;
+    default:
+        error = ETM_NOSYS;
+    }
+    
+    tr_etm(TgTrCore, "ETM CORE: _version: version(%d)", revision);
+
+    if (error < 0)
+        return error;
+    
+    return ETM_OK;
+}
+
+
+/******************************************************************************
+ *  Function for reading the Die-ID from base band processor.
+ *****************************************************************************/
+
+int etm_dieID_read(T_ETM_PKT *pkt, uint8 *inbuf) 
+{
+	T_RV_RET result;
+	int8 byteCount;
+	UINT16 dieID[DIE_ID_SIZE];
+	int16 index;
+	volatile UINT16 *reg_p = (UINT16 *) DIE_ID_REG;
+    
+	tr_etm(TgTrCore, "ETM CORE: _dieID_read: started - Die-ID address(0x%x)", DIE_ID_REG);
+    
+	BE_STREAM_TO_ARRAY(dieID, reg_p, DIE_ID_SIZE);
+    
+	for (byteCount = 0; byteCount < DIE_ID_SIZE; byteCount++) {
+
+		tr_etm(TgTrCore, "ETM CORE: Die-ID[%i] Byte Read(0x%x)", byteCount, (UINT16)dieID[byteCount]);
+        result = etm_pkt_put16(pkt, (UINT8)(((dieID[byteCount]) & 0xFFFF)));
+		if (result < 0)
+			return result;
+	}
+
+
+	return ETM_OK;
+}
+
+
+/******************************************************************************
+ * ETM CORE Main Function - Module
+ *****************************************************************************/
+
+int etm_core(uint8 *buf, int size)
+{
+// Structur of protocol data dl-link: |fid|index|data|
+
+    uint8 mid;
+    uint8 fid;
+    int error = 0;
+    T_ETM_PKT *pkt = NULL;  
+
+    fid = *buf++;
+
+    tr_etm(TgTrCore, "ETM CORE: _core: fid(%c):", fid); 
+
+    /* Create TestMode return Packet */
+    if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
+        return ETM_NOMEM;
+    }
+        
+    // Init. of return packet
+    pkt->mid    = ETM_CORE;
+    pkt->status = ETM_OK;
+    pkt->size   = 0;
+    pkt->index  = 0;
+    etm_pkt_put8(pkt, fid);
+   
+    switch (fid) {
+#ifdef RVM_ATP_SWE
+    case 0x60: // old 'G'
+        error = etm_at(pkt, (char *) buf);
+        break;
+#endif
+    case 0x61: // old 'M'
+        error = etm_mem(pkt, buf);
+        break;
+    case 0x62: // old 'E'
+        error = etm_echo(pkt, buf);
+        break;
+    case 0x63: // old 'R'
+        error = etm_reset();
+        break;
+    case 0x64: // old 'T' 
+        error = etm_debug(pkt, buf);
+        break;
+    case 0x65: // old 'V' 
+        error = etm_version(pkt, buf);
+        break;
+    case 0x66: // old 'C'
+        error = etm_codec_read(pkt, buf);
+        break;
+    case 0x67: // old 'D' 
+        error = etm_codec_write(pkt, buf);            
+        break;
+    case 0x68: // old 'd'
+        error = etm_dieID_read(pkt, buf);
+        break;	
+    default:
+        tr_etm(TgTrCore,"ETM CORE: _core: fid ERROR"); 
+        error = ETM_NOSYS;
+        break;
+    }
+    
+    if (error < 0) {
+        tr_etm(TgTrCore,"ETM CORE: _core: FAILED"); 
+        pkt->status = -error;
+    }
+   
+    // etm_at(): send func. is controlled by primitive 
+    if (fid == 'G' && error >= RV_OK) {}
+    else 
+        etm_pkt_send(pkt);
+
+    etm_free(pkt); 
+    return ETM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_tmpwr.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,338 @@
+/******************************************************************************
+ * Enhanced TestMode (PWR)
+ * Copyright Texas Instruments, 2003
+ * Svend Kristian Lindholm, skl@ti.com
+ *
+ * $Id: tmpwr.c 1.1 Wed, 20 Aug 2003 10:22:37 +0200 skl $
+ *
+ ******************************************************************************/
+
+#include "etm/etm.h"
+#include "etm/etm_trace.h"
+#include "etm/etm.h"
+#include "etm/etm_env.h"
+#include "etm/etm_api.h"
+#include "etm/etm_misc.h"
+
+#include "rv/rv_general.h"
+#include "rv/rv_defined_swe.h"
+
+#include "memif/mem.h"
+#include <string.h>
+
+
+#include "rv/rv_defined_swe.h"
+#define TRACE_WANTED 1
+#include "lcc/lcc_api.h"
+#include "lcc/lcc_cfg_i.h"
+#include "lcc/lcc.h"
+#include "lcc/lcc_trace.h"
+#include "lcc/lcc_tm_i.h"
+#include "lcc/lcc_task.h"
+#include "lcc/lcc_modulate.h"
+#include "ffs/ffs.h"
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+
+extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
+extern T_PWR_CTRL_BLOCK *pwr_ctrl;
+extern T_PWR_CFG_BLOCK *pwr_cfg;
+
+
+/******************************************************************************
+ * EMT PWR Version
+ *****************************************************************************/
+/* 
+The version of the etm pwr module can be found in the file etm_version.h
+*/
+
+/******************************************************************************
+ * ETM PWR Module
+ *****************************************************************************/
+// pwr uplink packet structure for pwr read/write : 
+// |fid|index|--data(W)--|
+
+int etm_pwr(uint8 *indata, int insize);
+
+/******************************************************************************
+ * Register the PWR Module to the ETM database 
+ *****************************************************************************/
+
+int etm_pwr_init(void)
+{
+    return etm_register("PWR", ETM_PWR, 0, 0, etm_pwr);
+}
+
+
+int etm_pwr(uint8 *buf, int insize)
+{
+    int error = ETM_OK;
+    uint8 fid, size, index,i;
+    T_ETM_PKT *pkt = NULL;  
+    T_FFS_STAT stat;
+    char name[20], id;
+
+    ttw(pwr_ttr(TTrInit, "etm_pwr(%d)" NL, 0));
+
+    fid = *buf;
+
+    ttw(pwr_ttr(TTrInit, "insize = %d " NL, insize));
+       
+    /* Create TestMode return Packet */
+    if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
+        return ETM_NOMEM;
+    }
+    
+    // Init. of return packet
+    pkt->mid     = ETM_PWR;
+    pkt->status  = ETM_OK;
+    pkt->size    = 0;
+    pkt->index   = 0;
+    etm_pkt_put8(pkt, fid);
+
+    index = *(buf+1);
+    etm_pkt_put8(pkt, index);
+    
+    name[0] = 0; // FIXME: Really needed?
+
+    for (i=0; i<insize; i++) {
+        ttw(ttr(TTrTmpwr, "buf[%d]=%d" NL,i, (*(buf+i))));
+    }
+
+    switch (fid) {
+    case 'R':
+	ttw(ttr(TTrTmpwr,"pwr (%d)" NL, 0));
+
+	// All reads start from index 2 since the fid + index is kept
+	switch (index) {
+	case PWR_CFG_ID :
+	    // We can read different configurations swiching between them using pwtw
+	    size = PWR_CFG_ID_SIZE;
+	    *(buf+2) = pwr_ctrl->cfg_id;
+	    *(buf+3) = pwr_ctrl->chg_cfg_id;
+	    ttw(ttr(TTrTmpwr,"Using cfg_id %d" NL, *(buf+2)));
+	    ttw(ttr(TTrTmpwr,"Using chg_cfg_id %d" NL, *(buf+3)));
+
+	    // If either the bat.cfg or the chg.cfg lacks object not found is returned
+
+	    // If (battery) file can't be stat'ed then the configuration doesn't exist
+	    id = *(buf+2) + '0';
+	    build_name("/pwr/bat/bat", &id, 12, ".cfg", name);
+	    error = ffs_stat(name, &stat);
+
+	    // If charger file can't be stat'ed then the configuration doesn't exist
+	    id = *(buf+3) + '0';
+	    build_name("/pwr/chg/chg", &id, 12, ".cfg", name);
+	    error = ffs_stat(name, &stat);
+	    break;
+	case PWR_COMMON :
+	    // Read the /pwr/common.cfg file
+	    // NOTE: sizeof(pwr_cfg->common) = 16 <>  (14 byte alignment)
+	    size = PWR_COMMON_CFG_SIZE;
+	    error = ffs_fread("/pwr/common.cfg", buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_CHG :
+	    // Read the /pwr/chg/chg<cfgid>.cfg file
+	    size = PWR_CHG_CFG_SIZE;
+	    id = pwr_ctrl->chg_cfg_id + '0';
+	    build_name("/pwr/chg/chg", &id, 12, ".cfg", name);
+	    error = ffs_fread(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr, "Read %d bytes " NL, error));
+	    break;
+	case PWR_BAT :
+	    // Read the /pwr/bat/bat<cfgid>.cfg file
+	    size = PWR_BAT_CFG_SIZE;
+	    id = pwr_ctrl->cfg_id + '0';
+	    build_name("/pwr/bat/bat", &id, 12, ".cfg", name);
+	    error = ffs_fread(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_TEMP :
+	    // Read the /pwr/bat/temp<cfgid>.cfg file
+	    size = PWR_TEMP_CFG_SIZE;
+	    id = pwr_ctrl->cfg_id + '0';
+	    build_name("/pwr/bat/temp", &id, 13, ".cfg", name);
+	    error = ffs_fread(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_MMI:
+	    // Read the /mmi/pwr/bsie.cfg file
+	    size = PWR_MMI_CFG_SIZE;
+	    error = ffs_fread("/mmi/pwr/bsie.cfg", buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_I2V_CAL :
+	    // Read the /pwr/i2v.cal file
+	    size = PWR_I2V_CAL_SIZE;
+	    error = ffs_fread("/pwr/i2v.cal", buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_VBAT_CAL :
+	    // Read the /pwr/vbat.cal file
+	    size = PWR_VBAT_CAL_SIZE;
+	    error = ffs_fread("/pwr/vbat.cal", buf+2, size);
+	    ttw(ttr(TTrTmpwr,"Read %d bytes" NL, error));
+	    break;
+	case PWR_MMI_TEST :
+#if (TEST_PWR_MMI_INTERFACE == 1)
+	    // Trigger MMI registration 
+	    return_path.callback_func = mmi_test_cb_function;
+	    ttw(ttr(TTrInit,"before: &mmi_test_cb_function=(0x%x)" NL, return_path.callback_func));
+	    return_path.addr_id = NULL; // FIXME??
+	    ttw(ttr(TTrTmpwr,"MMI testing callback: %d" NL, 0x0));
+	    size = 1;
+	    *(buf+2) = 0xBA;
+	    pwr_register(&return_path, &mmi_data);
+	    ttw(ttr(TTrInit,"after: &mmi_test_cb_function=(0x%x)" NL, pwr_ctrl->rpath.callback_func));
+	    ttw(ttr(TTrTmpwr,"MMI testing callback: %d" NL, 0xFF));
+#endif
+	    break;
+	case PWR_DYNAMIC :
+	    // Dump 'dynamic' configuration data to trace
+	    size = PWR_DYNAMIC_SIZE;
+	    *(buf+2) = 0xBA;
+	    ttr(TTrAll,"*PWR Module Version = 0x%x" NL, PWRVERSION );
+	    ttr(TTrAll,"*bat_id = %d" NL,               pwr_cfg->data.bat_id );
+	    ttr(TTrAll,"*state = %d" NL,                pwr_ctrl->state);
+	    ttr(TTrAll,"*chg_id = %d" NL,               pwr_cfg->data.chg_id );
+	    ttr(TTrAll,"*Vbat = %d" NL,                 pwr_cfg->data.Vbat);
+	    ttr(TTrAll,"*Vbat_avg = %d" NL,             pwr_cfg->data.Vbat_avg);
+	    ttr(TTrAll,"*Vbat_avg_mV = %d" NL,          pwr_cfg->data.Vbat_avg_mV);
+	    ttr(TTrAll,"*Tbat = %d" NL,                 pwr_cfg->data.Tbat);
+	    ttr(TTrAll,"*Tbat_avg = %d" NL,             pwr_cfg->data.Tbat_avg);
+	    ttr(TTrAll,"*Vchg = %d" NL,                 pwr_cfg->data.Vchg);
+	    ttr(TTrAll,"*Ichg = %d" NL,                 pwr_cfg->data.Ichg);
+	    ttr(TTrAll,"*Cbat = %d" NL,                 pwr_cfg->data.Cbat);
+	    ttr(TTrAll,"*cfg_id = %d" NL,               pwr_cfg->data.cfg_id);
+	    ttr(TTrAll,"*chg_cfg_id = %d" NL,           pwr_cfg->data.chg_cfg_id);
+	    ttr(TTrAll,"*bforce = %d" NL,               pwr_cfg->data.bforce);
+	    ttr(TTrAll,"*cforce = %d" NL,               pwr_cfg->data.cforce);
+	    ttr(TTrAll,"*k = %d" NL,                    pwr_cfg->data.k);
+	    ttr(TTrAll,"*T4 = %d" NL,                   pwr_cfg->data.T4);
+	    ttr(TTrAll,"*T1 elapsed = %d" NL,           pwr_ctrl->time_elapsed_T1);
+	    ttr(TTrAll,"*T2 elapsed = %d" NL,           pwr_ctrl->time_elapsed_T2);
+	    ttr(TTrAll,"*T3 elapsed = %d" NL,           pwr_ctrl->time_elapsed_T3);
+	    ttr(TTrAll,"*MMI timer elapsed = %d" NL,    pwr_ctrl->time_elapsed_mmi_rep);
+	    error = PWR_OK;
+	    break;
+	case PWR_TRACE_MASK:
+	    // Read the trace mask of the PWR module 
+	    size = PWR_TMASK_SIZE;
+	    memcpy(buf+2, &pwr_ctrl->tmask, size);
+	    ttw(ttr(TTrTmpwr,"tmask: 0x%x" NL, pwr_ctrl->tmask));
+	    break;
+	default :
+	    {
+	     // Unknown index
+	    error = PWR_INDEX;
+	    ttr(TTrWarning, "Unknown index! %d" NL, index);
+	    }
+	}
+
+	etm_pkt_putdata(pkt, buf+2 , size);
+        break;
+    case 'W':
+
+	ttw(ttr(TTrTmpwr,"pww (%d)" NL, 0));
+	switch (index) {
+	case PWR_CFG_ID :
+	    // Write the configuration id to be used
+	    pwr_ctrl->cfg_id = *(buf+2);
+	    pwr_ctrl->chg_cfg_id = *(buf+3);
+	    pwr_cfg->data.cfg_id = pwr_ctrl->cfg_id + '0';
+	    pwr_cfg->data.chg_cfg_id = pwr_ctrl->chg_cfg_id + '0';
+	    ttw(ttr(TTrTmpwr,"Switched to bat id=%d" NL, pwr_ctrl->cfg_id));
+	    ttw(ttr(TTrTmpwr,"Switched to chg id=%d" NL, pwr_ctrl->chg_cfg_id));
+	    break;
+	case PWR_COMMON :
+	    // Write the /pwr/common.cfg file
+	    // Blocking version of ffs_fwrite is used since this is a test mode command
+	    error = ffs_fwrite("/pwr/common.cfg", buf+2, PWR_COMMON_CFG_SIZE);
+	    ttw(ttr(TTrTmpwr,"Wrote %d bytes" NL, error));
+	    break;
+	case PWR_CHG :
+	    // Write the /pwr/chg/chg<cfgid>.cfg file
+	    size = PWR_CHG_CFG_SIZE;
+	    id = pwr_ctrl->chg_cfg_id + '0';
+	    build_name("/pwr/chg/chg", &id, 12, ".cfg", name);
+	    error = ffs_fwrite(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr, "Wrote %d bytes = %d" NL, error));
+	    break;
+	case PWR_BAT :
+	    // Write the /pwr/bat/bat<cfgid>.cfg file
+	    size = PWR_BAT_CFG_SIZE;
+	    id = pwr_ctrl->cfg_id + '0';
+	    build_name("/pwr/bat/bat", &id, 12, ".cfg", name);
+	    error = ffs_fwrite(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr, "Wrote %d bytes = %d" NL, error));
+	    break;
+	case PWR_TEMP :
+	    // Write the /pwr/bat/temp<cfgid>.cfg file
+	    size = PWR_TEMP_CFG_SIZE;
+	    id = pwr_ctrl->cfg_id + '0';
+	    build_name("/pwr/bat/temp", &id, 13, ".cfg", name);
+	    error = ffs_fwrite(name, buf+2, size);
+	    ttw(ttr(TTrTmpwr, "Wrote %d bytes = %d" NL, error));
+	    break;
+	case PWR_MMI:
+	    // Write the /mmi/pwr/bsie.cfg file
+	    size = PWR_MMI_CFG_SIZE;
+	    error = ffs_fwrite("/mmi/pwr/bsie.cfg", buf+2, size);
+	    ttw(ttr(TTrTmpwr, "Wrote %d bytes = %d" NL, error));
+	    break;
+	case PWR_I2V_CAL :
+	    // Write the /pwr/i2v.cal file
+	    error = ffs_fwrite("/pwr/i2v.cal", buf+2, PWR_I2V_CAL_SIZE);
+	    ttw(ttr(TTrTmpwr,"Wrote %d bytes" NL, PWR_I2V_CAL_SIZE));
+	    break;
+	case PWR_VBAT_CAL:
+	    // Write the /pwr/vbat.cal file
+	    error = ffs_fwrite("/pwr/vbat.cal", buf+2, PWR_VBAT_CAL_SIZE);
+	    ttw(ttr(TTrTmpwr,"Wrote %d bytes" NL, PWR_VBAT_CAL_SIZE));
+	    break;
+	case PWR_MMI_TEST :
+	    break;
+	case PWR_TRACE_MASK:
+	    // Write the trace mask of the PWR module 
+	    memcpy(&pwr_ctrl->tmask, buf+2, sizeof(pwr_ctrl->tmask));
+	    ttw(ttr(TTrTmpwr,"Wrote tmask 0x%x" NL, pwr_ctrl->tmask));
+	    pwr_ttr_init(pwr_ctrl->tmask);
+	    break;
+	default :
+	    {
+	     // Unknown index
+	    error = PWR_INDEX;
+	    ttr(TTrWarning, "Unknown index! %d" NL, index);
+	    }
+	}
+
+	size = 0; // Size of write message reply is always 0
+
+        break;
+    default:
+        pwr_ttr(TTrWarning, "etm_pwr: fid unknown (%d)" NL, fid);
+        error = ETM_NOSYS;
+        break;
+    }
+    
+    for (i=0; i<size+2; i++) {
+        ttw(ttr(TTrTmpwr, "buf[%d]=0x%x" NL, i, (*(buf+i))));
+    }
+
+    if (error < 0) {
+        pwr_ttr(TTrWarning, "etm_pwr: error %d" NL, error);
+        pkt->status = -error;
+
+    }
+
+    pkt->size += size;
+
+    etm_pkt_send(pkt);
+    etm_free(pkt);
+
+    ttw(pwr_ttr(TTrInit, "etm_pwr(%d)" NL, 0xFF));
+    return ETM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_trace.c	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,193 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_trace.c
+ *
+ * @author	Kim T. Peteren (ktp@ti.com) and Mads Meisner-Jensen, mmj@ti.com
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#include "etm/etm_trace.h"
+#include "etm/etm_env.h"
+
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+
+/******************************************************************************
+ * Prototypes
+ *****************************************************************************/
+
+void trstr(unsigned int mask, char *string);
+
+
+/******************************************************************************
+ * Target Tracing
+ *****************************************************************************/
+
+static unsigned int ttr_mask = TgTrFatal; //TgTrFatal; //TgTrAll;
+
+void tr_etm_init(unsigned int mask)
+{
+    ttr_mask = mask;
+}
+
+
+void tr_etm(unsigned int mask, char *format, ...)
+{
+    va_list args;
+    static char buf[256];
+
+    if (ttr_mask & mask) {
+        // build string ala tr() then call str()
+        va_start(args, format);
+        vsprintf(buf, format, args);
+        trstr(mask, buf);
+        va_end(args);
+    }
+}
+
+
+void trstr(unsigned int mask, char *string)
+{
+    if (ttr_mask & mask) {
+        rvf_send_trace(string, strlen(string), NULL_PARAM,
+                       RV_TRACE_LEVEL_WARNING, ETM_USE_ID);
+        rvf_delay(10);
+    }
+}
+
+
+void tr_etm_hexdump(unsigned int mask, const void *p, int size)
+{
+    unsigned int type, module;
+  
+    if (!(ttr_mask & mask))
+        return;
+    
+    hexdump_buf((char*) p, size);
+}
+
+
+/******************************************************************************
+ * Hexdumping Functions
+ *****************************************************************************/
+
+void etm_trace(char *string, int level)
+{
+    rvf_send_trace(string, strlen(string), NULL_PARAM, level, ETM_USE_ID);
+    rvf_delay(20);
+}
+
+
+int sprint_int_as_hex(char *buf, unsigned int n, int width, char padding)
+{
+    unsigned int m = n; // MUST be unsigned because it will be right shifted
+    int size = 0;
+    int i;
+    char digit;
+    char *buf_start = buf;
+
+    // Count number of digits in <n>
+    do {
+        size++;
+    } while (m >>= 4);
+
+    // Shift significant part of <n> into the top-most bits
+    n <<= 4 * (8 - size);
+
+    // Pad output buffer with <padding>
+    if (0 < width && width <= 8) {
+        width = (width > size ? width - size : 0);
+        while (width--)
+            *buf++ = padding;
+    }
+
+    // Convert <n>, outputting the hex digits
+    for (i = 0; i < size; i++) {
+        digit  = (n >> 28) & 0xF;
+        digit += (digit < 10 ? '0' : 'A' - 10);
+        *buf++ = digit;
+        n <<= 4;
+    }
+
+    // Null terminate
+    *buf = 0;
+
+    return buf - buf_start;
+}
+
+int printf_int_as_hex(unsigned int n, int width, char padding)
+{
+    char string[8+1];
+    int length;
+
+    length = sprint_int_as_hex(string, n, width, padding);
+    etm_trace(string, RV_TRACE_LEVEL_DEBUG_LOW);
+
+    return length;
+}
+
+
+int print_int_as_hex(unsigned int n)
+{
+    return printf_int_as_hex(n, 0, 0);
+}
+
+
+void hexdump_buf(char *buf, int size)
+{
+    int n, i, multiline;
+    char string[(8+1) + (16+1) + (3*16) + 1];
+    char *s;
+    
+    multiline = (size > 16);
+
+    while (size > 0)
+    {
+        s = string;
+        n = (size > 16 ? 16 : size);
+
+        // Print address
+        if (multiline) {
+            s += sprint_int_as_hex(s, (unsigned int) buf, 8, ' ');
+            *s++ = ' ';
+        }
+
+        // Print the textual representation
+        for (i = 0; i < n; i++)
+            *s++ = (buf[i] >= ' ' && buf[i] < 127 ? buf[i] : '.');
+
+        // Pad textual representation with spaces
+        if (multiline)
+            for (i = 0; i < 16 - n; i++)
+                *s++ = ' ';
+
+        // Print hexedecimal bytes
+        for (i = 0; i < n; i++) {
+            *s++ = ' ';
+            s += sprint_int_as_hex(s, (unsigned int) buf[i] & 0xFF, 2, '0');
+        }
+
+        *s = 0;
+
+        etm_trace(string, RV_TRACE_LEVEL_DEBUG_LOW);
+
+        buf  += 16;
+        size -= 16;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_trace.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,30 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM)
+ * @file	etm_trace.h
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  16/06/2003	Creation
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+
+#ifndef _ETM_TRACE_H_
+#define _ETM_TRACE_H_
+
+#include "etm/etm.h"
+
+void tr_etm(unsigned trmask, char *format, ...);
+void tr_etm_hexdump(unsigned int mask, const void *p, int size);
+void hexdump_buf(char *buf, int size);
+int  print_int_as_hex(unsigned int n);
+
+#endif // End of ETM_TRACE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/etm/etm_version.h	Mon Nov 18 06:39:44 2013 +0000
@@ -0,0 +1,59 @@
+/********************************************************************************
+ * Enhanced TestMode (ETM) - Revision Controle System Header
+ * @file	etm_version.h 
+ *
+ * @author	Kim T. Peteren (ktp@ti.com)
+ * @version 0.1
+ *
+
+ *
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *  21/10/2003	Creation
+ * 
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ *********************************************************************************/
+
+#ifndef _ETM_VERSION_H_
+#define _ETM_VERSION_H_
+
+
+/******************************************************************************
+ * Enhanced TestMode version numbers 
+ *****************************************************************************/
+
+//#define ETM_VERSION      0x0100L // First Version
+//#define ETM_VERSION      0x0102L // Updated ETM task state machine, removed recption of ATP events.
+#define ETM_VERSION      0x0103L // Fixed issue regarding interaction with the ETM registration database 
+
+
+#define ETM_API_VERSION  0x0100L // First Version
+
+
+/******************************************************************************
+ * Version of ETM CORE  
+ *****************************************************************************/
+
+//#define ETM_CORE_VERSION 0x0101L // First Version
+//#define ETM_CORE_VERSION 0x0102L // 
+#define ETM_CORE_VERSION 0x0103L // Updated core FIDs with new values and added 
+                                 // support for Die-ID read.
+
+/******************************************************************************
+ * Version of ETM AUDIO  
+ *****************************************************************************/
+
+//#define ETM_AUDIO_VERSION 0x0100L // First Version
+//#define ETM_AUDIO_VERSION 0x0101L // Version updated with support of new AUDIO parameters - not yet fully tested
+#define ETM_AUDIO_VERSION 0x0102L // Implemented callback function instead of msg handling.
+#endif // End of ETM_VERSION
+
+
+/******************************************************************************
+ * Version of ETM PWR  
+ *****************************************************************************/
+
+#define ETM_PWR_VERSION 0x0100L // First Version