changeset 118:21de8d8e6ea7

checking in Riviera code from the Sotomodem version
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 29 Oct 2013 07:03:45 +0000
parents e40d8661ecab
children dd56546ad9e0
files nuc-fw/riviera/rv/general.h nuc-fw/riviera/rv/rv.h nuc-fw/riviera/rv/rv_defined_swe.h nuc-fw/riviera/rv/rv_general.h nuc-fw/riviera/rv/rv_general_config.h nuc-fw/riviera/rv/rv_trace.h nuc-fw/riviera/rv_template/xxx_api.h nuc-fw/riviera/rv_template/xxx_cfg.h nuc-fw/riviera/rv_template/xxx_env.h nuc-fw/riviera/rv_template/xxx_i.h nuc-fw/riviera/rv_template/xxx_message.h nuc-fw/riviera/rv_template/xxx_pool_size.h nuc-fw/riviera/rv_template/xxx_state_i.h nuc-fw/riviera/rvf/rvf_api.h nuc-fw/riviera/rvf/rvf_buffer.c nuc-fw/riviera/rvf/rvf_cust.h nuc-fw/riviera/rvf/rvf_env.h nuc-fw/riviera/rvf/rvf_i.h nuc-fw/riviera/rvf/rvf_mem_pool.c nuc-fw/riviera/rvf/rvf_msg.c nuc-fw/riviera/rvf/rvf_pool_size.h nuc-fw/riviera/rvf/rvf_target.h nuc-fw/riviera/rvf/rvf_task.c nuc-fw/riviera/rvf/rvf_time.c nuc-fw/riviera/rvf/rvf_trace_adapt.c nuc-fw/riviera/rvm/rvm_api.c nuc-fw/riviera/rvm/rvm_api.h nuc-fw/riviera/rvm/rvm_ext_priorities.h nuc-fw/riviera/rvm/rvm_ext_use_id_list.h nuc-fw/riviera/rvm/rvm_gen.h nuc-fw/riviera/rvm/rvm_group_swe.c nuc-fw/riviera/rvm/rvm_i.h nuc-fw/riviera/rvm/rvm_mem.c nuc-fw/riviera/rvm/rvm_pool_size.h nuc-fw/riviera/rvm/rvm_priorities.h nuc-fw/riviera/rvm/rvm_swe.c nuc-fw/riviera/rvm/rvm_swe_db.c nuc-fw/riviera/rvm/rvm_swe_hdlr.c nuc-fw/riviera/rvm/rvm_task.c nuc-fw/riviera/rvm/rvm_use_id_list.h nuc-fw/riviera/rvt/rvt_api.c nuc-fw/riviera/rvt/rvt_def_i.h nuc-fw/riviera/rvt/rvt_env.c nuc-fw/riviera/rvt/rvt_env.h nuc-fw/riviera/rvt/rvt_env_i.h nuc-fw/riviera/rvt/rvt_gen.h nuc-fw/riviera/rvt/rvt_pool_size.h nuc-fw/riviera/rvt/rvt_task.c nuc-fw/riviera/rvt/ti_profiler/ti_prf_pool_size.h nuc-fw/riviera/rvt/ti_profiler/ti_profiler.c nuc-fw/riviera/rvt/ti_profiler/ti_profiler.h nuc-fw/riviera/rvt/ti_profiler/ti_profiler_env.c nuc-fw/riviera/rvt/ti_profiler/ti_profiler_env.h nuc-fw/riviera/support/exception.c nuc-fw/riviera/support/exception.h nuc-fw/riviera/tests/rtest/rtest_api.h nuc-fw/riviera/tests/rtest/rtest_env.h nuc-fw/riviera/tests/rtest/rtest_msg_i.h nuc-fw/riviera/tests/rtest/rtest_pool_size.h nuc-fw/riviera/tests/rv/rv_test.h nuc-fw/riviera/tests/rv/rv_test_certif.h nuc-fw/riviera/tests/rv/rv_test_cfg.h nuc-fw/riviera/tests/rv/rv_test_demo.h nuc-fw/riviera/tests/rv/rv_test_exec_def.h nuc-fw/riviera/tests/rv/rv_test_filter.h nuc-fw/riviera/tests/rv/rv_test_filter_redirect.h nuc-fw/riviera/tests/rv/rv_test_misc.h nuc-fw/riviera/tests/rv/rv_test_regr.h nuc-fw/riviera/tests/rv/rv_test_upf.h
diffstat 69 files changed, 17825 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/general.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,87 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        general.h                                                   */
+/*                                                                          */
+/*  Function    this file contains common data type definitions used        */
+/*              throughout the SWE                                          */
+/*                                                                          */
+/*  Date       Modification                                                 */
+/*  -----------------------                                                 */
+/*  3/12/99    Create                                                       */
+/* **************************************************************************/
+/*  10/27/1999 David Lamy-Charrier: remove declaration of ntohs, htons,     */
+/*                                  ntohl, htonl in order to avoid conflict */
+/*                                  with winsock.h                          */
+/*                                                                          */
+/*  11/30/1999 Pascal Pompei: 'string.h' included in order to define memcmp,*/
+/*                            memset and memcpy functions.                  */
+/*                                                                          */
+/*                                                                          */
+/****************************************************************************/
+
+#ifndef GENERAL_H
+#define GENERAL_H
+
+#ifdef _WINDOWS
+   #include <string.h>
+#endif
+
+/* WINDOWS */
+#ifdef _WINDOWS
+   typedef unsigned short  UINT16;
+   typedef unsigned int    UINT32;
+   typedef unsigned char   UBYTE;
+   typedef short           SHORT;
+   typedef int             BOOL;
+
+/* BOARD */
+#else
+   #ifndef __TYPEDEFS_H__ /* This #define allows to Condat to use general.h without conflict */
+      typedef unsigned short  UINT16;
+      typedef unsigned char   UBYTE;
+      typedef short           SHORT;
+      typedef signed char     BYTE;
+      #if !defined (BOOL_FLAG)
+         #define BOOL_FLAG
+         typedef unsigned char BOOL;
+      #endif
+      typedef unsigned short  USHORT;
+      typedef unsigned int    ULONG;
+   #endif
+   typedef unsigned long    UINT32;
+#endif
+
+typedef unsigned char   UINT8;
+typedef signed char     INT8;
+typedef short           INT16; 
+typedef int             INT32;
+typedef unsigned char   BOOLEAN;
+
+typedef void (*FUNC)(void);      /* pointer to a function */
+
+#define OK        1
+
+#ifndef NULL
+   #define NULL   0
+#endif
+
+#ifndef TRUE
+   #define TRUE   1
+#endif
+
+#ifndef FALSE
+   #define FALSE  0
+#endif
+
+
+#define htons  ntohs
+#define htonl  ntohl
+
+
+#if !defined(_WIN32) 
+   #define ntohs(n) (n)
+   #define ntohl(n) (n)
+   #define ntoh6(n) (n)
+#endif
+
+#endif /* #ifndef GENERAL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/rv.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,21 @@
+
+/************************************************************************************																				    
+*                                                                             	    *
+*   rv.h : Include file for rv.c and other C-files in the project 					*
+*          Contains priority setting for the different tasks, ...					*
+*		                                            					    		*
+*   Author         	: Frederic Bossy (f-bossy@ti.com)				    		    *
+*   Version number	: 1.0														    *
+*   Date        	: 23 Nov 1999 													*		
+*																				    *
+*   Copyright (c) Texas Instruments 1999							                *		
+**********************************************************************************/
+
+#ifndef __RV_INCLUDE_H__
+#define __RV_INCLUDE_H__
+
+
+/* Stack and memory size definitions */
+#define STACK_SIZE 2000
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/rv_defined_swe.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,211 @@
+/**
+ *
+ * @file	rv_defined_swe.h
+ *
+ * Definition of the SWE that will be compiled.
+ *
+ * To include a SWE in the build, the System/env.mak file is used.
+ * Before the build, a rv_swe.h file is generated from env.mak.
+ * This file includes rv_swe.h and makes some adjustement if necessary
+ * (e.g. mandatory SWE to include if some other is included, include
+ * of group of SWE, etc).
+ *
+ * @author	Cristian Livadiotti
+ * @version	0.4
+ *
+ */
+
+/*
+ * Revision History:
+ *
+ * 10/10/2000	Cristian Livadiotti		Create.
+ * 10/18/2001   Christophe Favergeon	Updated for R2D.
+ * 10/15/2002   Laurent Sollier			Updated for automatic definition from env.mak file.
+ * 11/19/2002	Vincent Oberle			Added RivieraTool support to automatic definition.
+ *
+ * (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_DEFINED_SWE_H_
+#define _RV_DEFINED_SWE_H_
+
+#ifndef _WINDOWS
+   #include "config/l1sw.cfg"
+   #include "config/rv.cfg"
+   #include "config/swconfig.cfg"
+   #include "config/debug.cfg"
+#endif
+
+/*
+ * rv_swe.h is generated before build from System/env.mak
+ * It is used both for RivieraTool and Target.
+ */
+#include "rv_swe.h"
+
+
+/* ------------------------------------------------------------------
+ * Grouped SWEs
+ * Some define in rv_swe.h might not represent one SWE, but a group
+ * of SWEs, this is decoded here.
+ * ------------------------------------------------------------------ */
+
+
+/*
+ * J2ME SW entities
+ * If RVM_J2ME_K_SWE is defined, the SWE's for the Java KVM are defined.
+ */
+#ifdef RVM_JAVA_K_SWE
+   #define RVM_KGC_SWE
+   #define RVM_KIL_SWE
+   #define RVM_KCL_SWE
+   #define RVM_KMM_SWE
+   #define RVM_KNM_SWE
+   #define RVM_UVM_SWE
+   #define RVM_KZP_SWE
+   #define RVM_KPG_SWE
+   #define RVM_JTM_SWE
+#endif
+
+/*
+ * AUDIO_FRAMEWORK SW entities
+ * If it is defined, AUDIO SWE is defined and AUDIO BACKGROUND may be defined
+ * depending on available audio features
+ */
+
+#ifdef RVM_AUDIO_SWE
+  #define RVM_AUDIO_MAIN_SWE
+  #if ((MELODY_E2) || (L1_GTT == 1))
+    #define RVM_AUDIO_BGD_SWE
+  #endif
+#endif
+
+
+/*
+ * Obigo SWEs.
+ */
+#if ((defined RVM_OBIGO_WAP_FULL_SWE) || (defined RVM_OBIGO_MMS_FULL_SWE) || (defined RVM_OBIGO_FULL_SWE))
+   #define RVM_MSFE_SWE
+   #define RVM_MSME_SWE
+   #define RVM_STKE_SWE
+   #define RVM_PHSE_SWE
+   #define RVM_PRSE_SWE
+   #define RVM_IBSE_SWE
+   #define RVM_SELE_SWE
+   #define RVM_SECE_SWE
+   #if ((defined RVM_OBIGO_WAP_FULL_SWE) || (defined RVM_OBIGO_FULL_SWE))
+      #define RVM_BRSE_SWE
+      #define RVM_BRAE_SWE
+   #endif
+   #if ((defined RVM_OBIGO_MMS_FULL_SWE) || (defined RVM_OBIGO_FULL_SWE))
+      #define RVM_MMSE_SWE
+      #define RVM_SLSE_SWE
+      #define RVM_MEAE_SWE
+      #define RVM_SLAE_SWE
+   #endif
+#endif
+
+
+/* ----------------------------------------
+ * WIDCOMM SWEs.
+ * ---------------------------------------- */
+#ifdef BLUETOOTH_INCLUDED
+    #ifdef _WINDOWS
+        #define RVM_BTH_SWE
+    #else
+        #define RVM_HCI_SWE
+    #endif
+    #define RVM_GKI_SWE
+    #define RVM_BTU_SWE
+#endif
+
+/* ----------------------------------------
+ * Specifics for a RivieraTool build.
+ * ---------------------------------------- */
+#ifdef _WINDOWS
+
+   #ifndef RVM_ATP_UART_SWE
+      #define RVM_ATP_UART_SWE
+   #endif
+
+   /* If a TCP/IP Winsocket implementation is defined */
+   #ifdef RVM_RNET_WS_SWE
+      #define RVM_RNET_SWE          /* Define the generic API. */
+      #ifdef RVM_RNET_RT_SWE
+         #undef RVM_RNET_RT_SWE     /* Undef Bridge implemetation. */
+      #endif
+      #ifdef RVM_RNET_BR_SWE
+         #undef RVM_RNET_BR_SWE     /* Undef Real implemetation. */
+      #endif
+   #endif
+   /* If TCP/IP Bridge implementation is defined */
+   #ifdef RVM_RNET_BR_SWE
+      #define RVM_RNET_SWE          /* Define the generic API. */
+      #ifdef RVM_RNET_RT_SWE
+         #undef RVM_RNET_RT_SWE     /* Undef Real implemetation. */
+      #endif
+   #endif
+   /* If TCP/IP Real implementation is defined */
+   #ifdef RVM_RNET_RT_SWE
+      #define RVM_RNET_SWE          /* Define the generic API. */
+      #ifdef RVM_RNET_BR_SWE
+         #undef RVM_RNET_BR_SWE     /* Undef Bridge implemetation. */
+      #endif
+   #endif
+
+   // TEMPORARY: THESE SWEs MUST BE FIXED FOR RIVIERATOOL
+   #ifdef RVM_DAR_SWE
+      #undef RVM_DAR_SWE
+   #endif
+   #ifdef RVM_ETM_SWE
+      #undef RVM_ETM_SWE
+   #endif
+   #ifdef RVM_TTY_SWE
+      #undef RVM_TTY_SWE
+   #endif
+   #ifdef RVM_MFW_SWE
+      #undef RVM_MFW_SWE
+   #endif
+   #ifdef RVM_SMBS_SWE
+      #undef RVM_SMBS_SWE
+   #endif
+
+/* ----------------------------------------
+ * Specifics for target build.
+ * ---------------------------------------- */
+#else
+   #if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+      #define RVM_TI_PRF_SWE
+   #endif
+
+   #ifndef RVM_RVT_SWE
+      #define RVM_RVT_SWE
+   #endif
+
+   /* If TCP/IP Bridge AND Real implementation are defined, error */
+   #if ((defined RVM_TTY_SWE) && (L1_GTT == 0))
+     #error "TTY entity cannot be enabled if L1_GTT is disabled (= 0)"
+   #endif
+
+   #if ((!defined RVM_TTY_SWE) && (L1_GTT == 1))
+     #error "L1_GTT cannot be enabled (= 1) if TTY entity is disabled"
+   #endif
+
+   /* If TCP/IP Bridge AND Real implementation are defined, error */
+   #if (defined RVM_RNET_RT_SWE) && (defined RVM_RNET_BR_SWE)
+     #error "RNET RT and BR cannot be compiled together on target"
+   #endif
+   /* If TCP/IP Bridge OR Real implementation are defined */
+   #if (defined RVM_RNET_RT_SWE) || (defined RVM_RNET_BR_SWE)
+      #define RVM_RNET_SWE          /* Define the generic API. */
+      #ifdef RVM_RNET_WS_SWE
+         #undef RVM_RNET_WS_SWE     /* Undef Winsocket implemetation. */
+      #endif
+   #endif
+
+#endif
+
+#if (TEST==1) && (defined RVM_R2D_SWE) && (defined RVM_RGUI_SWE)
+   #define RVM_RTEST_SWE
+#endif
+
+#endif /* _RV_DEFINED_SWE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/rv_general.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,124 @@
+/**
+ * @file	rv_general.h
+ * 
+ * Definitions that are shared between S/W entities 
+ * in the Riviera Environment.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)
+ * @version	0.1
+ */
+
+/*
+ * Revision History:																			
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	03/12/1999							Create.
+ *	12/03/1999	Christian Livadiotti	Replaced:
+ *										#define ARRAY_TO_STREAM(p, a, l) {register int i; for
+ *										(i = 0; i < l; i++) *p++ = (UINT8) a[i];}
+ *										by the following to change convention of array writing.
+ *	12/08/1999	Pascal Pompei			Add STREAM_TO_ARRAY
+ *	11/20/2001	Vincent Oberle			- Changed T_RV_RETURN to T_RV_RETURN_PATH
+ *										  Keep compatibility with a define
+ *										- Documentation cleaning
+ *	06/03/2002	Vincent Oberle			Added __RV_CRITICAL
+ *																			
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+#ifndef _RV_GENERAL_H_
+#define _RV_GENERAL_H_
+
+#include "rv/general.h"
+#include "rv/rv_trace.h"
+
+/**
+ * Task IDentifiers: A-M-E-N-D-E-D!
+ *    0:                   Reserved for RVM,
+ *    RVTEST_MENU_TASK_ID: 'Test Selection Menu',
+ *    DUMMY_TASK_ID:       'Dummy' task.
+ *    MAX - 1:             Trace task (refer to rvf_target.h).
+ */
+#define RVTEST_MENU_TASK_ID			(0x0A)
+#define DUMMY_TASK_ID               (0x0B)
+
+
+
+/**
+ * Returned parameter values.  [Perhaps, a memory level WARNING could be added]  */
+typedef enum {
+	RV_OK						= 0,
+	RV_NOT_SUPPORTED				= -2,
+	RV_NOT_READY					= -3,
+	RV_MEMORY_WARNING				= -4,
+	RV_MEMORY_ERR					= -5,
+	RV_MEMORY_REMAINING				= -6,
+	RV_INTERNAL_ERR					= -9,
+	RV_INVALID_PARAMETER			        = -10
+} T_RV_RET;
+
+
+/**
+ * Unique ADDRess IDentifier of any SWE. (T_RVF_ADDR_ID is deprecated)
+ */
+typedef UINT8 T_RVF_G_ADDR_ID;
+#define T_RVF_ADDR_ID T_RVF_G_ADDR_ID
+
+
+/**
+ * Return path type.
+ *
+ * T_RV_RETURN_PATH is the new name for the return path type.
+ * It is introduced to avoid the confusion with the return value
+ * type. Use this one.
+ */
+typedef struct
+{
+	T_RVF_ADDR_ID	addr_id;
+	void			(*callback_func)(void *);
+} T_RV_RETURN_PATH;
+
+// Deprecated. For backward compatibility only.
+#define T_RV_RETURN		T_RV_RETURN_PATH
+
+
+/**
+ * Mark used to indicate that a function should be loadable.
+ * For instance:
+ *    char __RV_CRITICAL xxx_do_something (char toto, int bill) {
+ *        ..
+ */
+#ifndef __RV_CRITICAL
+#define __RV_CRITICAL
+#endif
+
+
+/**
+ * Generic header of messages used in Riviera.
+ */
+typedef struct {
+    UINT32			msg_id;
+	void			(*callback_func)(void *);
+    T_RVF_ADDR_ID	src_addr_id;
+	T_RVF_ADDR_ID	dest_addr_id;
+} T_RV_HDR;
+
+#define RV_HDR_SIZE (sizeof (T_RV_HDR))
+
+/**
+ * Macros to get minimum and maximum between 2 numbers.
+ */
+#define Min(a,b) ((a)<(b)?(a):(b))
+#define Max(a,b) ((a)<(b)?(b):(a))
+
+
+/**
+ * Macro to get minimum between 3 numbers.
+ */
+#define Min3(a,b,c) (Min(Min(a,b),c))
+
+// Pointer type used to handle received data that L2CAP set in a chained buffer list.
+typedef UINT8 T_RV_BUFFER;
+
+#endif /* _RV_GENERAL_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/rv_general_config.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,20 @@
+/****************************************************************************
+*                                                                           *
+*  Name        rv_general_config.h                                          *
+*                                                                           *
+*  Function    this file contains main configuration						*
+*                                                                           *
+*  Date        Modification                                                 *
+*  ------------------------                                                 *
+*  06/12/2000	 - Create													*
+*																			*
+* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved *
+****************************************************************************/
+
+#ifndef _RV_GENERAL_CONFIG_H_
+#define _RV_GENERAL_CONFIG_H_
+
+#define _SDP_CLIENT_
+#define _SDP_SERVER_
+
+#endif /* _RV_GENERAL_CONFIG_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv/rv_trace.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,41 @@
+/************************************************************************************* 
+ *																			         * 
+ *  Name        rv_trace.h													         * 
+ *																			         * 
+ *  Function    this file contains trace definitions for basic layers		         * 
+ *																			         * 
+ *  Date        Modification                                                         * 
+ *  ------------------------												         * 
+ *  10/12/00	 - Create Cristian Livadiotti - c-livadiotti@ti.com			         * 
+ *																			         * 
+ *																			         * 
+ * (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved         * 
+ *                                                                                   *
+ * --------------------------------------------------------------------------------- *
+ *                                                                                   *
+ *   History:                                                                        *
+ *                                                                                   *
+ *   10/18/2001 - Updated for R2D by Christophe Favergeon		                     * 
+ *                                                                                   *
+ *************************************************************************************/
+
+#ifndef _RV_TRACE_H_
+#define _RV_TRACE_H_
+
+
+
+/* Define trace levels.                                                          */
+#define RV_TRACE_LEVEL_ERROR		(1)		/* Error condition trace messages.   */
+											/* Used when an unrecoverable error is found */
+#define RV_TRACE_LEVEL_WARNING		(2)		/* Warning condition trace messages. */
+											/* Used when an error is found but is handled properly by the code*/
+#define RV_TRACE_LEVEL_DEBUG_HIGH	(3)		/* Debug messages (high debugging).  */
+                                            /* high = important debug message */
+#define RV_TRACE_LEVEL_DEBUG_MEDIUM	(4)		/* Debug messages.                   */
+#define RV_TRACE_LEVEL_DEBUG_LOW	(5)		/* Debug messages (low debugging).   */
+                                            /* low = not important debug message */
+
+/* temporary definition of this old flag for backward compatibility */
+#define TRACE_RVTEST				(0x001E0004)
+
+#endif /* _RV_GENERAL_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_api.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,67 @@
+/**
+ * @file	xxx_api.h
+ *
+ * API Definition for XXX SWE.
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_API_H_
+#define __XXX_API_H_
+
+
+#include "rvm/rvm_gen.h"		/* Generic RVM types and functions. */
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/**
+ * @name XXX Return type and return values.
+ *
+ * Currently they are the standard RV return types, but they may
+ * be customized in the future.
+ */
+/*@{*/
+typedef T_RV_RET T_XXX_RETURN;
+
+#define	XXX_OK					RV_OK				
+#define	XXX_NOT_SUPPORTED		RV_NOT_SUPPORTED		
+#define	XXX_MEMORY_ERR			RV_MEMORY_ERR			
+#define	XXX_INTERNAL_ERR		RV_INTERNAL_ERR		
+/*@}*/
+
+
+/**
+ * @name API functions
+ *
+ * API functions declarations (bridge functions).
+ */
+/*@{*/
+
+T_XXX_RETURN xxx_send_sample ();
+
+/*@}*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /*__XXX_API_H_*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_cfg.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,31 @@
+/**
+ * @file	xxx_cfg.h
+ *
+ * Configuration definitions for the XXX instance.
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_CFG_H_
+#define __XXX_CFG_H_
+
+
+#include "rv/rv_general.h"		/* General Riviera definitions. */
+/**
+ * Sample value.
+ */
+#define XXX_SAMPLE_VALUE	            10
+
+
+#endif /* __XXX_CFG_H_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_env.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,80 @@
+/**
+ * @file	xxx_env.h
+ *
+ * Declarations of the Riviera Generic Functions 
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_ENV_H_
+#define __XXX_ENV_H_
+
+
+#include "rvm/rvm_gen.h"		/* Generic RVM types and functions. */
+#include "rvf/rvf_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+#include "xxx/xxx_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+
+/** 
+ * Wished priority of the host task for the SWE.
+ *
+ * During development, put the hardcoded value here.
+ * After integration, the value should be in rvm_priorities.h
+ */
+#ifdef RVM_XXX_TASK_PRIORITY
+#define XXX_TASK_PRIORITY               RVM_XXX_TASK_PRIORITY	
+#else
+#define XXX_TASK_PRIORITY               80	
+#endif
+
+
+/**
+ * @name Generic functions
+ *
+ * Generic functions declarations needed for a Type 2 SWE
+ * (Group Member SWE).
+ */
+/*@{*/
+T_RVM_RETURN xxx_get_info (T_RVM_INFO_SWE  *info_swe);
+
+T_RVM_RETURN xxx_set_info ( T_RVF_ADDR_ID	addr_id,
+							T_RV_RETURN_PATH return_path[],
+							T_RVF_MB_ID		bk_id_table[],
+							T_RVM_CB_FUNC	call_back_error_ft);
+
+T_RVM_RETURN xxx_init (void);
+
+T_RVM_RETURN xxx_kill (void);
+
+/* Type 1 specific generic functions */
+T_RVM_RETURN xxx_start (void);
+/* End of specific */
+/* Type 2 specific generic functions */
+T_RVM_RETURN xxx_start (void);
+T_RVM_RETURN xxx_stop (T_RV_HDR * msg);
+T_RVM_RETURN xxx_handle_message (T_RV_HDR * msg);
+T_RVM_RETURN xxx_handle_timer (T_RV_HDR * msg);
+/* End of specific */
+/* Type 3 specific generic functions */
+T_RVM_RETURN xxx_start (void);
+T_RVM_RETURN xxx_stop (T_RV_HDR * msg);
+T_RVM_RETURN xxx_handle_message (T_RV_HDR * msg);
+T_RVM_RETURN xxx_handle_timer (T_RV_HDR * msg);
+/* End of specific */
+/* Type 4 specific generic functions */
+T_RVM_RETURN xxx_core (void);
+/* End of specific */
+
+/*@}*/
+
+#endif /*__XXX_ENV_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,75 @@
+/**
+ * @file	xxx_i.h
+ *
+ * Internal definitions for XXX.
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_INST_I_H_
+#define __XXX_INST_I_H_
+
+
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rvm/rvm_ext_use_id_list.h"
+
+#include "xxx/xxx_cfg.h"
+#include "xxx/xxx_api.h"
+#include "xxx/xxx_message.h"
+
+#include "xxx/xxx_state_i.h"
+
+
+/** Macro used for tracing XXX messages. */
+#define XXX_SEND_TRACE(string, trace_level) \
+	rvf_send_trace (string, (sizeof(string) - 1), NULL_PARAM, trace_level, XXX_USE_ID)
+
+
+
+/**
+ * The Control Block buffer of XXX, which gathers all 'Global variables'
+ * used by XXX instance.
+ *
+ * A structure should gathers all the 'global variables' of XXX instance.
+ * Indeed, global variable must not be defined in order to avoid using static memory.
+ * A T_XXX_ENV_CTRL_BLK buffer is allocated when creating XXX instance and is 
+ * then always refered by XXX instance when access to 'global variable' 
+ * is necessary.
+ */
+typedef struct
+{
+	/** Store the current state of the XXX instance */
+	T_XXX_INTERNAL_STATE state;
+
+	/** Pointer to the error function */
+	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);
+	/** Mem bank id. */
+	T_RVF_MB_ID prim_mb_id;
+
+	T_RVF_ADDR_ID	addr_id;
+
+} T_XXX_ENV_CTRL_BLK;
+
+
+/** External ref "global variables" structure. */
+extern T_XXX_ENV_CTRL_BLK	*xxx_env_ctrl_blk_p;
+
+
+#endif /* __XXX_INST_I_H_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_message.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,73 @@
+/**
+ * @file	xxx_message.h
+ *
+ * Data structures:
+ * 1) used to send messages to the XXX SWE,
+ * 2) XXX can receive.
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_MESSAGE_H_
+#define __XXX_MESSAGE_H_
+
+
+#include "rv/rv_general.h"
+
+#include "xxx/xxx_cfg.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/** 
+ * The message offset must differ for each SWE in order to have 
+ * unique msg_id in the system.
+ */
+#define XXX_MESSAGE_OFFSET	 BUILD_MESSAGE_OFFSET(XXX_USE_ID)
+
+
+
+/**
+ * @name XXX_SAMPLE_MESSAGE
+ *
+ * Short description.
+ *
+ * Detailled description
+ */
+/*@{*/
+/** Message ID. */
+#define XXX_SAMPLE_MESSAGE (XXX_MESSAGE_OFFSET | 0x001)
+
+/** Message structure. */
+typedef struct 
+{
+	/** Message header. */
+	T_RV_HDR			hdr;
+
+	/** Some parameters. */
+	/* ... */
+
+} T_XXX_SAMPLE_MESSAGE;
+/*@}*/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __XXX_MESSAGE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,35 @@
+/**
+ * @file	xxx_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	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_POOL_SIZE_H_
+#define __XXX_POOL_SIZE_H_
+
+
+/*
+ * Values used in xxx_env.h
+ */
+#define XXX_STACK_SIZE  (1024)
+#define XXX_MB1_SIZE    (2048)
+#define XXX_POOL_SIZE  (XXX_STACK_SIZE + XXX_MB1_SIZE)
+
+
+#endif /*__XXX_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rv_template/xxx_state_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,54 @@
+/**
+ * @file	xxx_state_i.h
+ * 
+ * Internal definitions for XXX state machine, 
+ * i.e. the states and the functions corresponding to the states.
+ *
+ * The messages are declared in xxx_message.h, since they can 
+ * be seen from outside.
+ *
+ * @author	Your name here (your_email_here)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	//							Create.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __XXX_STATE_I_H_
+#define __XXX_STATE_I_H_
+
+
+#include "rv/rv_general.h"
+
+
+/**
+ * XXX states.
+ *
+ * XXX instance is a state machine with several possible states.
+ * Based on the current state, XXX handle different kind of messages/events.
+ * States are listed in the order they should normally be sequenced.
+ *
+ * See the Readme file for a description of the state machine.
+ */
+typedef enum
+{
+	XXX_STATE_1,
+	XXX_STATE_2
+} T_XXX_INTERNAL_STATE;
+
+
+/*
+ * Optional but	recommanded, define a function for the processing
+ * in each state, like:
+ *   T_XXX_RETURN xxx_state_1					(T_RV_HDR * message_p);
+ *   T_XXX_RETURN xxx_state_2					(T_RV_HDR * message_p);
+ */
+
+#endif /* __XXX_STATE_I_H_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_api.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,356 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_api.h                                                       */
+/*                                                                          */
+/*  Function    this file contains rvf public definitions.                  */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  3/12/99		Create														*/
+/*	11/15/99	remove useless functions,									*/
+/*				change tasks priority and time_slicing						*/
+/*	11/15/1999	compliant to RV coding guidelines							*/
+/*  12/23/1999	change buffer management, add memory bank handling			*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef _RVF_API_H
+#define _RVF_API_H
+
+#include "rv/general.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_target.h"
+
+#ifndef _WINDOWS
+  #include "config/swconfig.cfg"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* macros used to trace messages */
+
+// WCP patch: default config is no RV trace for WCP
+#if (OP_WCP == 0)
+  #define DEBUG_ENABLE 1
+#endif
+
+
+#ifndef DEBUG_ENABLE 
+#define rvf_send_trace 
+#else 
+void rvf_send_trace1(char * msg, UINT8 msg_length, UINT32 val, UINT8 trace_level, UINT32 swe_use_id);
+#define rvf_send_trace rvf_send_trace1
+#endif 	
+
+#define T_RVF_GD_ID UINT8
+
+/* return parameters definition */
+typedef T_RV_RET T_RVF_RET;
+
+#define	RVF_OK					RV_OK				
+#define	RVF_NOT_SUPPORTED		RV_NOT_SUPPORTED		
+#define	RVF_NOT_READY			RV_NOT_READY			
+#define	RVF_MEMORY_ERR			RV_MEMORY_ERR			
+#define	RVF_INTERNAL_ERR		RV_INTERNAL_ERR		
+#define	RVF_INVALID_PARAMETER	RV_INVALID_PARAMETER	
+
+/* memeory bank state definition */
+typedef enum{
+	RVF_GREEN,
+	RVF_YELLOW,
+	RVF_RED
+}T_RVF_MB_STATUS;
+
+/* task state */
+typedef enum { SUSPEND, RUNNING} T_RVF_TASK_STATE;
+
+/************************************************************************
+** Mailbox definitions. Each task has 4 mailboxes that are used to
+** send buffers to the task.
+*/
+#define RVF_TASK_MBOX_0    0
+#define RVF_TASK_MBOX_1    1
+#define RVF_TASK_MBOX_2    2
+#define RVF_TASK_MBOX_3    3
+
+#define RVF_NUM_TASK_MBOX  4
+
+#define RVF_TASK_MBOX_0_EVT_MASK   0x0001
+#define RVF_TASK_MBOX_1_EVT_MASK   0x0002
+#define RVF_TASK_MBOX_2_EVT_MASK   0x0004
+#define RVF_TASK_MBOX_3_EVT_MASK   0x0008
+
+/************************************************************************
+** Event definitions.
+**
+** There are 4 reserved events used to signal messages rcvd in task mailboxes.
+** There are 4 reserved events used to signal timeout events.
+** There are 8 general purpose events available for applications.
+*/
+#define RVF_MAX_EVENTS	          16
+
+#define RVF_NUM_TASK_TIMERS     4
+
+#define RVF_TIMER_0             0
+#define RVF_TIMER_1             1
+#define RVF_TIMER_2             2
+#define RVF_TIMER_3             3
+
+#define RVF_TIMER_0_EVT_MASK    0x0010
+#define RVF_TIMER_1_EVT_MASK    0x0020
+#define RVF_TIMER_2_EVT_MASK    0x0040
+#define RVF_TIMER_3_EVT_MASK    0x0080
+
+#define RVF_APPL_EVT_0          8
+#define RVF_APPL_EVT_1          9
+#define RVF_APPL_EVT_2          10
+#define RVF_APPL_EVT_3          11
+#define RVF_APPL_EVT_4          12
+#define RVF_APPL_EVT_5          13
+#define RVF_APPL_EVT_6          14
+#define RVF_APPL_EVT_7          15
+
+#define EVENT_MASK(evt)	   ((UINT16)0x0001 << evt)
+
+#define MAX_HOSTING_TASKS	10
+#define MAX_PARASITES		10
+
+
+/* define memory bank related types */
+typedef UINT16 T_RVF_MB_ID;
+//typedef UINT8 T_RVF_MB_NAME[RVF_MAX_MB_LEN];
+typedef char T_RVF_MB_NAME[RVF_MAX_MB_LEN];
+#define T_RVF_BUFFER void 
+typedef void (*CALLBACK_FUNC)(void *);
+typedef void (*MB_CALLBACK_FUNC)(T_RVF_MB_ID);
+
+typedef struct{
+	UINT32 size;
+	UINT32 watermark;
+} T_RVF_MB_PARAM;
+
+
+
+/* Define a timer list entry
+*/
+typedef struct _tle
+{
+	T_RV_HDR	  hdr;
+	struct _tle  *p_next;
+	struct _tle  *p_prev;
+	UINT32        ticks;
+	UINT16        event;			/* event & param must be revised possibily       */
+	UINT32        param;			/* sub struct pointed to by p_data if required   */
+	UINT32		  t_init;
+	void*		  p_data;
+} T_RVF_TIMER_LIST_ENT;
+
+typedef T_RVF_TIMER_LIST_ENT*	P_NODE;
+
+/* Define a timer list queue          ?? QUEUE or LIST ??
+*/
+typedef struct 
+{
+    T_RVF_TIMER_LIST_ENT   *p_first;
+    T_RVF_TIMER_LIST_ENT   *p_last;
+    UINT32           last_ticks;
+	UINT16			 timerCnt;
+} T_RVF_TIMER_LIST_Q;
+
+
+/***********************************************************************
+** This queue is a general purpose buffer queue, for application use.
+*/
+typedef struct 
+{   void    *p_first;
+    void    *p_last;
+    UINT16  count;
+} T_RVF_BUFFER_Q;
+
+#define RVF_IS_QUEUE_EMPTY(p_q) (p_q.count == 0)
+
+/*******************************************************
+* Message parameter of "handle_timer()"  
+********************************************************/
+#define T_RVF_TIMER_ID		UINT32 
+
+typedef struct {
+	T_RV_HDR				hdr;
+	T_RVF_TIMER_ID			tm_id;
+	UINT8					cont;
+	void*					action;
+} T_RVF_TMS_MSG;
+
+/* define a mutex structure */
+typedef struct
+{	UINT32	words[11];
+}T_RVF_MUTEX;
+
+/***********************************************************************
+** Define the basic message header that RVF expects on all inter-computer
+** communications. Applications should use this in their own definitions
+** and add on their own message contents.
+*/
+/*typedef struct {
+	UINT16  prim;  // Message Type 
+	UINT16  len;   // Message Length (including header) 
+} msg_hdr_t;
+
+typedef struct {
+	msg_hdr_t  hdr;
+	UINT8      data[1];
+} msg_type1;
+*/
+
+/* Task constants
+*/
+#ifndef TASKPTR
+typedef void (*TASKPTR)(UINT32);
+#endif
+
+
+#define RVF_INVALID_TASK (0xFF)
+#define RVF_INVALID_MB_ID		(0xFFFF)
+#define RVF_INVALID_MAILBOX (0xFF)
+#define RVF_INVALID_ADDR_ID	(0xFF)
+
+/* Define the value that create pool will return if it fails
+*/
+
+
+/************************************************************************/
+/* Function prototypes													*/
+
+
+/* Task management*/
+void			rvf_init(void);
+T_RVF_RET		rvf_create_legacy_task (TASKPTR task_entry, UINT8 task_id, char *taskname, UINT8 *stack, UINT16 stacksize, UINT8 priority, UINT8 time_slicing, T_RVF_TASK_STATE is_suspend) ;
+T_RVF_RET		rvf_create_task (TASKPTR task_entry, T_RVF_G_ADDR_ID task_id, char *taskname, UINT8 *stack, UINT16 stacksize, UINT8 priority, UINT8 tcode, UINT8 time_slicing, T_RVF_TASK_STATE is_suspend);
+T_RVF_RET		rvf_resume_task( T_RVF_G_ADDR_ID taskid);
+void			rvf_exit_task(T_RVF_G_ADDR_ID vtask);
+T_RVF_RET		rvf_suspend_task(T_RVF_G_ADDR_ID vtask);
+T_RVF_G_ADDR_ID	rvf_get_taskid(void);
+char *			rvf_get_taskname(void);
+T_RVF_G_ADDR_ID rvf_get_context();
+
+/* Message Handling */
+typedef T_RV_HDR T_RVF_MSG ;
+typedef UINT32	  T_RVF_MSG_ID;
+
+T_RVF_RET		rvf_send_msg			(T_RVF_G_ADDR_ID addr_id, void * p_msg);
+T_RVF_MB_STATUS rvf_get_msg_buf			(T_RVF_MB_ID mb_id,
+											UINT32 message_size,
+											T_RVF_MSG_ID msg_id,
+											T_RVF_MSG ** pp_msg);
+T_RVF_RET		rvf_free_msg			(T_RVF_MSG * p_msg);
+T_RVF_RET		rvf_free_timer_msg		(T_RVF_MSG *p_msg);
+
+
+
+/* To send buffers and events between tasks*/
+void *			rvf_read_mbox  (UINT8 mbox);
+void *			rvf_read_addr_mbox (T_RVF_G_ADDR_ID  task_id, UINT8 mbox);
+UINT8			rvf_send_event (T_RVF_G_ADDR_ID task_id, UINT16 event);
+
+/* task synchronization */
+T_RVF_RET		rvf_initialize_mutex( T_RVF_MUTEX * mutex);
+T_RVF_RET		rvf_lock_mutex( T_RVF_MUTEX * mutex);
+T_RVF_RET		rvf_unlock_mutex( T_RVF_MUTEX * mutex);
+T_RVF_RET		rvf_delete_mutex( T_RVF_MUTEX * mutex);
+
+
+/* To manage memory */
+T_RVF_RET		rvf_create_mb(T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM mb_param, T_RVF_MB_ID *mb_id);
+T_RVF_RET		rvf_delete_mb(T_RVF_MB_NAME mb_name);
+T_RVF_RET		rvf_get_mb_id(T_RVF_MB_NAME mb_name, T_RVF_MB_ID *mb_id);
+T_RVF_MB_STATUS	rvf_get_mb_status(T_RVF_MB_ID mb_id);
+T_RVF_RET		rvf_mb_is_used(T_RVF_MB_NAME mb_name, UINT8* isUsed) ;
+
+T_RVF_MB_STATUS	rvf_get_buf(T_RVF_MB_ID mb_id, UINT32 buffer_size, T_RVF_BUFFER** p_buffer);
+T_RVF_MB_STATUS	rvf_count_buf(T_RVF_MB_ID mb_id, T_RVF_BUFFER * p_buffer);
+T_RVF_RET		rvf_free_buf( T_RVF_BUFFER * p_buffer);
+T_RVF_RET		rvf_set_callback_func(T_RVF_MB_ID mb_id, MB_CALLBACK_FUNC func);
+T_RVF_RET		rvf_change_callback_func(T_RVF_MB_ID mb_id, MB_CALLBACK_FUNC func);
+
+void rvf_get_protected_buf(T_RVF_MB_ID mb_id, UINT32 buffer_size, T_RVF_BUFFER** p_buffer);
+  
+
+UINT32			rvf_get_buf_size (void *bptr);
+				/* get the parameters of a specific memory bank */
+T_RVF_RET		rvf_get_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param);
+				/* change the parameters of a specific memory bank */
+T_RVF_RET		rvf_set_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param);
+
+
+/* User buffer queue management*/
+T_RVF_RET		rvf_enqueue (T_RVF_BUFFER_Q *p_q, void *p_buf);
+T_RVF_RET		rvf_enqueue_head (T_RVF_BUFFER_Q *p_q, void *p_buf);
+void *			rvf_dequeue  (T_RVF_BUFFER_Q *p_q);
+T_RVF_BUFFER *	rvf_scan_next (T_RVF_BUFFER_Q * p_q, T_RVF_BUFFER * p_buf);
+T_RVF_RET		rvf_remove_from_queue (T_RVF_BUFFER_Q * p_q, T_RVF_BUFFER * p_buf);
+
+/* Timer management*/
+
+UINT16			rvf_wait(UINT16 flag, UINT32 ticks);
+UINT16			rvf_evt_wait(T_RVF_G_ADDR_ID rtask, UINT16 flag, UINT32 timeout) ;
+void			rvf_delay(UINT32 ticks);
+
+void			rvf_start_timer(UINT8 tnum, UINT32 ticks, BOOLEAN is_continuous);
+void			rvf_stop_timer (UINT8 tnum);
+char *			rvf_get_time_stamp(char *tbuf);
+UINT32			rvf_get_tick_count(void);
+void			rvf_init_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq);
+void			rvf_init_timer_list_entry (T_RVF_TIMER_LIST_ENT  *p_tle);
+UINT16			rvf_update_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq);
+void			rvf_add_to_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq, T_RVF_TIMER_LIST_ENT  *p_tle);
+void			rvf_remove_from_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq, T_RVF_TIMER_LIST_ENT  *p_tle);
+T_RVF_TIMER_LIST_ENT*	rvf_get_expired_entry (T_RVF_TIMER_LIST_Q *p_timer_listq);
+
+
+#define T_RV_TM_ID	UINT32
+
+/*************************************************************************/
+/* :)  USER FRIENDLY TIMER MANAGEMENT API consisting of add, delete and modify timer */
+/*************************************************************************/
+/* Returns 0 on failure */
+T_RVF_TIMER_ID	rvf_create_timer(	T_RVF_G_ADDR_ID			g_addrId,
+									UINT32					timerDuration,
+									BOOLEAN					isContinuous,
+									void*					p_action);
+
+void			rvf_del_timer	(	T_RV_TM_ID tm_id) ;
+
+void			rvf_reset_timer	(	T_RV_TM_ID tm_id, UINT32 new_duration,
+									BOOLEAN isContinuous);
+
+
+/* Disable Interrupts, Enable Interrupts*/
+void			rvf_enable(void);
+void			rvf_disable(UINT8 who);
+
+/* Trace for debug purposes*/
+void rvf_dump_mem();
+void rvf_dump_tasks();
+void rvf_dump_pool();
+
+/* specific function */
+T_RVF_BUFFER * rvf_wait_for_specific_msg(UINT16 msg_code, UINT8 mbox, UINT32 timeout);
+
+/* Trace definitions */
+#define NULL_PARAM 4294967295 /* this value will not be displayed in rvf_send_trace function */
+#define TRACE_MB_ID		(RVF_MAX_REAL_MB -1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif	/* _RVF_API_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_buffer.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,2128 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_buffer.c                                                */
+/*                                                                          */
+/*  Function    this file contains rvf buffer handling functions            */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  3/12/99		Create														*/
+/*  10/27/1999	remove all non-nucleus sections (#ifdef)					*/
+/*	30/11/1999	compliant to RV coding guidelines							*/
+/*  12/23/1999	change buffer management, add memory bank handling and		*/
+/*				remove useless functions									*/
+/*  07/12/2000	implement dynamic memory allocation.						*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef _WINDOWS
+#include "config/board.cfg"
+#endif
+
+#include "nucleus.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rvf/rvf_api.h"
+#include "rvf/rvf_i.h"
+#include "support/exception.h"
+#include "rvf/rvf_pool_size.h"
+
+#include <string.h>
+#include <stdio.h>
+
+
+#if RVF_ENABLE_STATS	/* conditional inclusion of stdio.h for sprintf() function */
+#ifdef _WINDOWS
+#include <stdio.h>
+#endif
+#endif
+
+#include "rv/rv_defined_swe.h"
+
+#ifdef RVM_DAR_SWE
+	#include "dar/dar_api.h"
+#endif
+#define RVF_INVALID_MD_ID_ERRROR  ("RVF: Invalid MB ID")
+
+#define INC_END_INITIALIZE		2
+#define RVF_INVALID_INDEX		0xFFFF
+
+/************* TASK MAILBOXES *******************/
+/* chained lists for task mailboxes			*/
+T_RVF_INTERNAL_BUF *OSTaskQFirst[1][1]; //[MAX_RVF_TASKS][RVF_NUM_TASK_MBOX]; 
+T_RVF_INTERNAL_BUF *OSTaskQLast [1][1]; //[MAX_RVF_TASKS][RVF_NUM_TASK_MBOX];
+
+extern INC_Initialize_State;
+
+T_RVF_RT_ADDR_ID_DATA*	pRtAddrIdTable[MAX_RVF_G_ADDR_ID]; 
+
+
+/******** MEMORY POOLS ******************/
+/* Define the buffer pools */
+extern T_RVF_POOL		_rvf_pools[];
+
+/*********** MEMORY BANKS ***********/
+/* array of memory bank				*/
+static T_RVF_MB			rvf_banks[RVF_MAX_REAL_MB];
+
+/* array of waiting buffers */
+static T_RVF_BUFFER *	waiting_buffers[RVF_MAX_WAITING_BUF];
+static UINT16			next_buffer[RVF_MAX_WAITING_BUF];
+static UINT16			first_free_element;
+
+/* array of memory bank name and id*/
+static T_RVF_MB_NAME_ID rvf_name_id[RVF_MAX_TOTAL_MB] = RVF_MB_MAPPING;
+
+
+/* variable for statistics */
+#if RVF_ENABLE_STATS
+static UINT32 required_size = 0;
+static UINT32 obtained_size = 0;
+static UINT32 used_size		= 0;
+static UINT32 mem_in_use	= 0;
+#endif
+
+/* lists of free buffers */
+static T_RVF_INTERNAL_BUF * lists[RVF_NB_FREE_LISTS];
+
+/* last split-off buffer */
+T_RVF_INTERNAL_BUF * last_remainder = NULL;
+
+/* allocated static buffer pools */
+extern UINT8 Buf0[];
+extern UINT8 Buf1[];
+
+/********Internal windows function used to display memory status *******/
+#ifdef _WINDOWS
+extern void AddNewState(void *s,char *name,
+				unsigned long  current,unsigned long  peak,
+				unsigned long  water,unsigned long  bank);
+#endif
+
+
+/*******************************************************************************
+**
+** Function         _rvf_init_free_queue
+**
+** Description      Function called at startup to initialize a free
+**                  pool (statically or dynamically allocated). 
+**					It is called once for each free pool.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_init_free_queue (UINT8 id, UINT32 size, void *p_mem)
+{
+   T_RVF_INTERNAL_BUF	*hdr;
+	UINT8 list_idx;
+
+    /* round to up size to a multiple of 4 */
+    size = (size + 3) & ~0x0003;
+
+    /* store pool start address and size */
+	_rvf_pools[id].start_address	= p_mem;
+
+    _rvf_pools[id].pool_size		= size;
+   
+	/* Initialize the pool as a big free buffer */
+	hdr = (T_RVF_INTERNAL_BUF *) p_mem;
+	hdr->buf_size = size - sizeof(T_RVF_INTERNAL_BUF) - sizeof(UINT32); /* last 4 bytes of the pool losts*/ 
+	hdr->header.p_prev = NULL;
+	RVF_SET_PREV_IN_USE(hdr);
+
+	NEXTCHUNK(hdr)->buf_size = 0;
+	
+	ENDSIZE(hdr) = hdr->buf_size;
+
+	
+	/* get the corresponding list and insert the buffer */
+	list_idx		= RVF_BUF_LIST_INDEX( hdr->buf_size);
+	hdr->p_next		= lists[list_idx];
+	lists[list_idx] = hdr;
+
+	last_remainder	= hdr;
+
+}
+
+void rvf_mbox_buffer_init(T_RVF_RT_ADDR_ID_DATA* pRtAddrIdElement) {
+   UINT8   task_num, mbox_num;
+    /* Initialize all mailboxes queues of all tasks*/
+    for (task_num = 0; task_num < MAX_RVF_TASKS; task_num++) {
+        for (mbox_num = 0; mbox_num < RVF_NUM_TASK_MBOX; mbox_num++) {
+			pRtAddrIdElement->OSTaskQFirst[mbox_num] = NULL;
+			pRtAddrIdElement->OSTaskQLast[mbox_num] = NULL;
+        }
+    }
+}
+/*******************************************************************************
+**
+** Function         _rvf_buffer_init
+**
+** Description      Called once internally by rvf at startup to initialize all
+**                  buffers and free buffer pools.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_buffer_init(void)
+{
+    UINT8   list_num;
+	UINT16	memory_bank_num;
+
+    /* Initialize all mailboxes queues of all tasks*/
+    /*  for (task_num = 0; task_num < MAX_RVF_TASKS; task_num++)
+    {
+        for (mbox_num = 0; mbox_num < RVF_NUM_TASK_MBOX; mbox_num++)
+        {
+            OSTaskQFirst[task_num][mbox_num] = NULL;
+            OSTaskQLast [task_num][mbox_num] = NULL;
+			//pRtAddrIdTable[task_num]->OSTaskQFirst[mbox_num] = NULL; // only if static
+			//pRtAddrIdTable[task_num]->OSTaskQLast[mbox_num] = NULL; // only if static
+        }
+    } */
+
+   /* initialize free lists */
+   for (list_num = 0; list_num < RVF_NB_FREE_LISTS; list_num++)
+   {
+      lists[list_num] = NULL;
+   }
+
+
+   /* initialize buffer pools */
+   _rvf_init_mem_pool();
+
+	/* Initialize real memory banks */
+	for (memory_bank_num = 0; memory_bank_num < RVF_MAX_REAL_MB; memory_bank_num++)
+	{	
+		rvf_banks[memory_bank_num].cur_memory_used		= 0;
+		rvf_banks[memory_bank_num].watermark			= 0;
+		rvf_banks[memory_bank_num].max					= 0;
+		rvf_banks[memory_bank_num].first_buffer_index	= RVF_INVALID_INDEX;
+		rvf_banks[memory_bank_num].last_buffer_index	= RVF_INVALID_INDEX;
+		rvf_banks[memory_bank_num].func					= 0;
+		rvf_banks[memory_bank_num].returned_red			= FALSE;
+#if RVF_ENABLE_STATS
+		rvf_banks[memory_bank_num].max_reached			= 0;
+		rvf_banks[memory_bank_num].required_size		= 0;
+		rvf_banks[memory_bank_num].num_buf				= 0;
+#endif
+	}
+
+	/* Initialize total memory banks */
+	for (memory_bank_num = 0; memory_bank_num < RVF_MAX_TOTAL_MB; memory_bank_num++)
+	{	
+		rvf_name_id[memory_bank_num].mb_params.size			= 0;
+		rvf_name_id[memory_bank_num].mb_params.watermark	= 0;
+	}
+
+
+	/* initialize array of waiting buffers */
+	first_free_element = 0;
+	for( memory_bank_num = 0; memory_bank_num < RVF_MAX_WAITING_BUF; memory_bank_num++)
+	{	waiting_buffers[memory_bank_num] = NULL;
+		next_buffer[memory_bank_num] = memory_bank_num + 1;
+	}
+	next_buffer[RVF_MAX_WAITING_BUF-1] = RVF_INVALID_INDEX;
+}
+
+/*******************************************************************************
+**
+** Function         _rvf_send_msg_to_mbox
+**
+** Description      Called by applications to send a buffer to a SWE.
+**                  (Temporary internal use - DO NOT USE IT !)
+**					(Presently, only for Christophe          )
+** Returns			RVF_OK if successful, else an error code.
+**
+*******************************************************************************/
+T_RVF_RET _rvf_send_msg_to_mbox (T_RVF_G_ADDR_ID addr_id, UINT8 mbox,void *msg){
+	return rvf_adapt_send_msg(addr_id, msg, mbox);
+}
+
+/*T_RVF_RET _rvf_send_msg_to_mbox (T_RVF_ADDR_ID addr_id, UINT8 mbox,void *msg)
+{
+    T_RVF_INTERNAL_BUF    *p_hdr;
+	UINT8 task_id = (UINT8)addr_id;
+
+    
+    if ((task_id >= MAX_RVF_TASKS) )
+    {
+        rvf_send_trace( "RVF: rvf_send_msg(): invalid taskid", 35, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        rvf_free_buf (msg);
+        return RVF_INVALID_PARAMETER;
+    }
+
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK	
+
+	if (_rvf_chk_buf_damage(msg) == TRUE)
+    {	rvf_send_trace( "RVF: rvf_send_msg(): buffer corrupted", 37, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+	}
+#endif
+
+	
+	((T_RV_HDR *)msg)->dest_addr_id = addr_id;
+	p_hdr = USER2MEM(msg);
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+  
+	if ( RVF_BUF_IS_LINKED( p_hdr) )
+	{
+		rvf_send_trace( "RVF: rvf_send_msg(): buffer already enqueued", 44, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return RVF_MEMORY_ERR;
+    }
+#endif
+
+    rvf_disable(8);		
+
+	
+    if (OSTaskQFirst[task_id][mbox])	
+	{	OSTaskQLast[task_id][mbox]->p_next = p_hdr;
+	}
+    else
+	{	OSTaskQFirst[task_id][mbox] = p_hdr;
+	}
+    OSTaskQLast[task_id][mbox] = p_hdr;
+
+	p_hdr->p_next = NULL;
+
+	if (pRtAddrIdTable[task_id]->OSTaskQFirst[mbox]) {
+		pRtAddrIdTable[task_id]->OSTaskQLast[mbox]->p_next = p_hdr;
+	} else {
+		pRtAddrIdTable[task_id]->OSTaskQFirst[mbox] = p_hdr;
+	}
+    pRtAddrIdTable[task_id]->OSTaskQLast[mbox] = p_hdr;
+
+	p_hdr->p_next = NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	RVF_SET_BUF_LINKED(p_hdr);	
+#endif
+
+    rvf_enable();		
+
+    rvf_send_event(task_id, (UINT16) (EVENT_MASK(mbox)) );
+	return RVF_OK;
+}*/
+
+/*******************************************************************************
+**
+** Function         rvf_read_mbox
+**
+** Description      Called by applications to read a buffer from one of
+**                  the task mailboxes.
+**
+** Returns          NULL if the mailbox was empty, else the address of a buffer
+**
+*******************************************************************************/
+void * rvf_read_mbox (UINT8 mbox) {   
+	T_RVF_G_ADDR_ID  task_id	= rvf_get_taskid();
+
+	return rvf_read_addr_mbox (task_id, mbox) ;   
+}
+void * rvf_read_addr_mbox (T_RVF_G_ADDR_ID  task_id, UINT8 mbox) {   
+    void * p_buf	= NULL;
+    T_RVF_INTERNAL_BUF * p_hdr;
+
+	mbox=resolveHostAddrId(mbox);
+
+    if ((task_id >= MAX_RVF_TASKS) || (mbox >= RVF_NUM_TASK_MBOX))
+    {   rvf_send_trace( "RVF: rvf_read_mbox(): invalid taskid or mbox", 44, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return NULL;
+    } 
+
+    rvf_disable(9);		/* enter critical section */
+
+	/* if the chained list is not empty */
+    /*if ( OSTaskQFirst[task_id][mbox] )	
+    {   p_hdr = OSTaskQFirst[task_id][mbox];
+        OSTaskQFirst[task_id][mbox] = p_hdr->p_next;
+
+        p_hdr->p_next = NULL;*/
+	if ( pRtAddrIdTable[task_id]->OSTaskQFirst[mbox] )	{
+        p_hdr = pRtAddrIdTable[task_id]->OSTaskQFirst[mbox];
+        pRtAddrIdTable[task_id]->OSTaskQFirst[mbox] = p_hdr->p_next;
+
+        p_hdr->p_next = NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	RVF_SET_BUF_UNLINKED(p_hdr);	/* change buffer status */
+#endif
+        p_buf = (UINT8 *)p_hdr + sizeof(T_RVF_INTERNAL_BUF);
+    }
+ 
+	rvf_enable();		/* exit critical section */
+
+    return (p_buf);
+}
+
+/*******************************************************************************
+**
+** Function         rvf_enqueue
+**
+** Description      Enqueue a buffer at the tail of the queue
+**
+** Returns          RVF_OK if successful, else an error code.
+**
+*******************************************************************************/
+T_RVF_RET rvf_enqueue (T_RVF_BUFFER_Q *p_q, void *p_buf)
+{
+    T_RVF_INTERNAL_BUF *p_hdr;
+
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK
+    if ( _rvf_chk_buf_damage(p_buf) )
+    {	rvf_send_trace( "RVF: rvf_enqueue(): buffer corrupted", 36, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+    }
+#endif
+
+   	/* check if the buffer has been already enqueued */
+    p_hdr = USER2MEM(p_buf);
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	if( RVF_BUF_IS_LINKED(p_hdr) )
+	{
+		rvf_send_trace( "RVF: rvf_enqueue(): buffer already enqueued", 43, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+        return RVF_MEMORY_ERR;
+    }
+#endif
+
+    rvf_disable(10);	/* enter critical section */
+
+    /* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
+	/* p_q->p_last and p_q->p_first point to the user buffer, since p_hdr->p_next points to the T_RVF_INTERNAL_BUF */
+    if (p_q->p_first)	/* if the queue is not empty */
+    {
+		T_RVF_INTERNAL_BUF * p_last_hdr = (T_RVF_INTERNAL_BUF *) ((UINT8 *)p_q->p_last - sizeof(T_RVF_INTERNAL_BUF) );
+        p_last_hdr->p_next = p_hdr;
+    }
+    else
+        p_q->p_first = p_buf;
+
+    p_q->p_last = p_buf;
+    p_q->count++;
+
+    p_hdr->p_next = NULL;
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+    RVF_SET_BUF_LINKED(p_hdr);	/* change buffer status */
+#endif
+
+    rvf_enable();		/* exit critical section */
+	return RVF_OK;
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_dequeue
+**
+** Description      Dequeue a buffer from the head of a queue
+**
+** Returns          NULL if queue is empty, else buffer
+**
+*******************************************************************************/
+void * rvf_dequeue (T_RVF_BUFFER_Q *p_q)
+{
+    T_RVF_INTERNAL_BUF    *p_hdr;
+
+    if (!p_q->count)	/* if the queue is empty */
+        return (NULL);
+
+    rvf_disable(12);	/* enter critical section */
+
+    p_hdr = USER2MEM(p_q->p_first );
+
+
+    /* Keep buffers such that RVF header is invisible */
+    if (p_hdr->p_next)
+        p_q->p_first = ((UINT8 *)p_hdr->p_next + sizeof(T_RVF_INTERNAL_BUF));
+    else
+    {
+        p_q->p_first = NULL;
+        p_q->p_last  = NULL;
+    }
+
+    p_q->count--;
+
+    p_hdr->p_next = NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+    RVF_SET_BUF_UNLINKED(p_hdr);	/* change buffer status */
+#endif
+
+    rvf_enable();		/* exit critical section */
+
+    return (MEM2USER(p_hdr) );
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_enqueue_head
+**
+** Description      Enqueue a buffer at the head of the queue
+**
+** Returns          RVF_OK if successful, else an error code.
+**
+*******************************************************************************/
+T_RVF_RET rvf_enqueue_head (T_RVF_BUFFER_Q *p_q, void *p_buf)
+{
+    T_RVF_INTERNAL_BUF    *p_hdr;
+
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK
+    if ( _rvf_chk_buf_damage(p_buf) )
+    {	rvf_send_trace( "RVF: rvf_enqueue_head(): buffer corrupted", 41, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+    }
+#endif
+
+    p_hdr = USER2MEM(p_buf);
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	if( RVF_BUF_IS_LINKED(p_hdr) )
+    {	rvf_send_trace( "RVF: rvf_enqueue_head(): buffer already enqueued", 48, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return RVF_MEMORY_ERR;
+    }
+#endif
+
+    rvf_disable(11);		/* enter critical section */
+
+    if (p_q->p_first)		/* if the queue is not empty */
+    {   p_hdr->p_next = (T_RVF_INTERNAL_BUF *)((UINT8 *)p_q->p_first - sizeof(T_RVF_INTERNAL_BUF) );
+        p_q->p_first = p_buf;
+    }
+    else
+    {    p_q->p_first = p_buf;
+        p_q->p_last  = p_buf;
+        p_hdr->p_next = NULL;
+    }
+    p_q->count++;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	RVF_SET_BUF_LINKED(p_hdr);	/* change buffer status */
+#endif
+		
+
+    rvf_enable();		/* exit critical section */
+	
+	return RVF_OK;
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_buf_size
+**
+** Description      Called by an application to get the size of a buffer.
+**
+** Returns          the size of the buffer or 0 if the address is invalid.
+**
+*******************************************************************************/
+INLINE UINT32 rvf_get_buf_size (void *bptr)
+{
+    T_RVF_INTERNAL_BUF *p_hdr;
+
+    p_hdr = (T_RVF_INTERNAL_BUF *)((UINT8 *) bptr - sizeof(T_RVF_INTERNAL_BUF) );
+
+    if ((UINT32)p_hdr & 1) return 0; /* invalid pointer: odd address*/
+
+    return (GETSIZE(p_hdr) - RVF_CORRUPT_OVERHEAD) ;
+}
+
+
+/*******************************************************************************
+**
+** Function         _rvf_chk_buf_damage
+**
+** Description      Called internally by rvf to check for buffer corruption.
+**
+** Returns          TRUE if there is a problem, else FALSE
+**
+*******************************************************************************/
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK
+BOOLEAN _rvf_chk_buf_damage(void *bptr)
+{
+   UINT32 *lg;
+	T_RVF_INTERNAL_BUF * p_hdr;
+	
+	if((UINT32)bptr & 1)	/* odd address */
+	{	return TRUE;
+	}
+
+	p_hdr = USER2MEM(bptr);	/* get the internal header */
+
+    lg = (UINT32*)( (UINT8*)bptr +  GETSIZE(p_hdr) - sizeof(UINT32) );
+
+	 if (lg == 0)
+		 return TRUE;
+
+    if(*lg == GETSIZE(p_hdr) )
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+#endif
+
+
+
+/*******************************************************************************
+**
+** Function         _find_buf
+**
+** Description      Internal function which is in charge of finding a free buffer
+**					of the requested size in one of the lists.
+**
+** Returns          A pointer to the buffer header, or NULL if none available
+**
+*******************************************************************************/
+INLINE void * _find_buf (UINT32 size)
+{    
+	T_RVF_INTERNAL_BUF * p_hdr;
+	UINT8 idx;
+
+    if (size == 0)	/* if user requires a 0 byte buffer !! */
+    {    return (NULL);
+	}
+
+	/* add the overhead for buffer corruption check */
+	size = REQ2SIZE(size);
+
+	/* find the corresponding list */
+	idx = RVF_BUF_LIST_INDEX(size);
+
+	/* 1. try in the bin corresponding to the requested size. */
+	/* 2. try to use the last_remainder chunk. */
+	/* 3. try in the others bins of greater size. */
+
+	if( (lists[idx] == NULL) || ( GETSIZE(lists[idx]) < size) )  
+	/* if the first buffer in the appropriate bin is not big enough. */
+	{
+		rvf_disable(4);		/* enter critical section */
+
+		if( last_remainder != NULL)
+		{
+			p_hdr = last_remainder;
+
+			/* if the last remainder is big enough */
+			if( GETSIZE(p_hdr) >= size )
+			{
+
+				if( GETSIZE(p_hdr) >= (size + RVF_MIN_USABLE_SIZE ) ) /* if the free part may be used */
+				{	/* create a new free buffer and link it in the appropriate list*/
+
+					T_RVF_INTERNAL_BUF * new_buf;
+					UINT8 new_idx;
+					
+					new_buf = (T_RVF_INTERNAL_BUF *) ((UINT8*)p_hdr + size + sizeof(T_RVF_INTERNAL_BUF));
+					new_buf->buf_size =  GETSIZE(p_hdr) - size - sizeof(T_RVF_INTERNAL_BUF);
+					ENDSIZE(new_buf) = new_buf->buf_size;
+
+					/* remove the used buffer from the list */
+					if( p_hdr->header.p_prev != NULL)
+					{	(p_hdr->header.p_prev)->p_next = p_hdr->p_next;
+					}
+					else
+					{	lists[ RVF_BUF_LIST_INDEX( GETSIZE(p_hdr) )] = p_hdr->p_next;
+					}
+					if( p_hdr->p_next != NULL)
+					{	(p_hdr->p_next)->header.p_prev = p_hdr->header.p_prev;
+					}
+					p_hdr->p_next = NULL;
+
+					SETSIZE(p_hdr, size);
+					ENDSIZE(p_hdr) = size;  /* to CHANGE */
+
+					/* insert the new buffer in the appropriate list */
+					new_idx = RVF_BUF_LIST_INDEX(new_buf->buf_size);
+					new_buf->p_next = lists[new_idx];
+					lists[new_idx] = new_buf;
+					new_buf->header.p_prev = NULL;
+					if( new_buf->p_next != NULL)
+					{	(new_buf->p_next)->header.p_prev = new_buf;
+					}
+					RVF_SET_PREV_IN_USE(new_buf);
+						
+					last_remainder = new_buf;
+
+					rvf_enable();		/* exit critical section */
+					return p_hdr;				
+
+				}
+				else	/* return the entire buffer */
+				{
+					/* remove the used buffer from the list */
+					if( p_hdr->header.p_prev != NULL)
+					{	(p_hdr->header.p_prev)->p_next = p_hdr->p_next;
+					}
+					else
+					{	lists[ RVF_BUF_LIST_INDEX( GETSIZE(p_hdr) )] = p_hdr->p_next;
+					}
+					if( p_hdr->p_next != NULL)
+					{	(p_hdr->p_next)->header.p_prev = p_hdr->header.p_prev;
+					}
+					p_hdr->p_next = NULL;
+
+					RVF_SET_PREV_IN_USE( NEXTCHUNK(p_hdr) );
+
+					last_remainder = NULL;
+				
+					rvf_enable();		/* exit critical section */
+					return p_hdr;
+				}
+			}
+			else /* the last remainder is too small */
+			{
+				/* clear the last remainder */
+				last_remainder = NULL;
+			}
+			
+		}
+		rvf_enable();		/* exit critical section */
+	}
+
+	while( idx < RVF_NB_FREE_LISTS )
+	{
+		rvf_disable(4);		/* enter critical section */
+
+		if( lists[idx] != NULL )  /*if the list is not empty */
+		{	/* remove the first buffer from the list */
+
+			p_hdr = lists[idx];
+			if( GETSIZE(p_hdr) >= size)
+			{
+				if( GETSIZE(p_hdr) >= (size + RVF_MIN_USABLE_SIZE ) ) /* if the free part may be used */
+				{	/* create a new free buffer and link it in the appropriate list*/
+
+					T_RVF_INTERNAL_BUF * new_buf;
+					UINT8 new_idx;
+					
+					new_buf = (T_RVF_INTERNAL_BUF *) ((UINT8*)p_hdr + size + sizeof(T_RVF_INTERNAL_BUF));
+					new_buf->buf_size =  GETSIZE( p_hdr) - size - sizeof(T_RVF_INTERNAL_BUF);
+					ENDSIZE(new_buf) = new_buf->buf_size;
+
+					/* remove the used buffer from the list */
+					lists[idx] = p_hdr->p_next;
+					if( p_hdr->p_next != NULL)
+					{	(p_hdr->p_next)->header.p_prev = NULL;
+					}
+					p_hdr->p_next = NULL;
+
+					SETSIZE(p_hdr, size);
+					ENDSIZE(p_hdr) = size;
+
+					/* insert the new buffer in the appropriate list */
+					new_idx = RVF_BUF_LIST_INDEX(new_buf->buf_size);
+					new_buf->p_next = lists[new_idx];
+					lists[new_idx] = new_buf;
+					new_buf->header.p_prev = NULL;
+					if( new_buf->p_next != NULL)
+					{	(new_buf->p_next)->header.p_prev = new_buf;
+					}
+					RVF_SET_PREV_IN_USE(new_buf);
+
+					last_remainder = new_buf; /* set this new buffer as the last remainder */
+
+					rvf_enable();		/* exit critical section */
+					return p_hdr;				
+
+				}
+				else	/* return the entire buffer */
+				{	lists[idx] = p_hdr->p_next;
+					if( p_hdr->p_next != NULL)
+					{	(p_hdr->p_next)->header.p_prev = NULL;
+					}
+					p_hdr->p_next = NULL;
+					RVF_SET_PREV_IN_USE( NEXTCHUNK(p_hdr) );
+					
+					if( last_remainder == p_hdr) /* if it was the last_remainder, clear it. */
+					{
+						last_remainder = NULL;
+					}
+
+					rvf_enable();		/* exit critical section */
+					return p_hdr;
+				}
+			}
+		}
+
+		rvf_enable();		/* exit critical section */
+
+		idx++;	/* search in the next list */
+	}
+
+    return NULL;
+}
+
+
+/*******************************************************************************
+**
+** Function         _release_buf
+**
+** Description      Internal function called to release a buffer after use.
+**					The parameter points to the beginning of the header.
+**
+** Returns          BOOLEAN: TRUE if successful, else FALSE
+**
+*******************************************************************************/
+INLINE BOOLEAN _release_buf (T_RVF_INTERNAL_BUF *p_hdr)
+{	UINT8 idx;
+
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK		/* check for buffer corruption:i.e. if user wrote data after the end of the buffer */
+    if ( _rvf_chk_buf_damage( MEM2USER(p_hdr) ) )
+    {	rvf_send_trace( "RVF: _release_buf(): buffer corrupted", 37, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+		return FALSE;
+    }
+
+	/* check if the buffer has been already freed */
+	if ( RVF_IS_PREV_FREE( NEXTCHUNK(p_hdr) ) )	/* check buffer status */
+    {	rvf_send_trace( "RVF: _release_buf(): buffer already freed", 41, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return FALSE;
+    }
+
+#endif
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK		/* check for buffer linkage */
+    if ( RVF_BUF_IS_LINKED(p_hdr) )	/* check buffer status */
+    {	rvf_send_trace( "RVF: _release_buf(): free buf buffer linked", 43, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return FALSE;
+    }
+#endif
+
+
+	rvf_disable(6);		/* enter critical section */
+
+	/* try to coalesce the buffer with its neighbors (left and right) */
+
+	if( RVF_IS_PREV_FREE(p_hdr) )
+	{	/* merge the buffer with its left neighbor */
+		UINT32 left_buf_size = *((UINT32*)((UINT8*)p_hdr - sizeof(UINT32) ) );
+		T_RVF_INTERNAL_BUF * left_buf = (T_RVF_INTERNAL_BUF *) ((UINT8 *)p_hdr - left_buf_size - sizeof(T_RVF_INTERNAL_BUF) );
+
+		/* remove the left buffer from its list */
+		if( left_buf->header.p_prev == NULL)
+		{	lists[ RVF_BUF_LIST_INDEX(left_buf_size)] = left_buf->p_next;
+		}
+		else
+		{	(left_buf->header.p_prev)->p_next = left_buf->p_next;
+		}
+		if( left_buf->p_next != NULL)
+		{
+			(left_buf->p_next)->header.p_prev = left_buf->header.p_prev;
+		}
+		/* set the size of the newly created buffer */
+		SETSIZE(left_buf, (left_buf_size + GETSIZE(p_hdr) + sizeof(T_RVF_INTERNAL_BUF) ) );
+		/* set the current buffer as free to allow check for double free */
+		RVF_SET_PREV_FREE( NEXTCHUNK(p_hdr) );
+
+		p_hdr = left_buf;
+	}
+
+	/* check for pool limits */
+	if( GETSIZE( NEXTCHUNK(p_hdr) ) != 0)
+	{	T_RVF_INTERNAL_BUF * right_buf = NEXTCHUNK(p_hdr);
+		/* merge the buffer with its right neighbor */
+		
+		if( RVF_IS_PREV_FREE( NEXTCHUNK(right_buf) ) )
+		{	/* remove the right buffer from its list */
+			UINT32 right_buf_size = GETSIZE( right_buf);
+	
+			if( right_buf->header.p_prev == NULL)
+			{	lists[ RVF_BUF_LIST_INDEX(right_buf_size)] = right_buf->p_next;
+			}
+			else
+			{	(right_buf->header.p_prev)->p_next = right_buf->p_next;
+			}
+			if( right_buf->p_next != NULL)
+			{	(right_buf->p_next)->header.p_prev = right_buf->header.p_prev;
+			}
+			
+			right_buf_size += GETSIZE(p_hdr);
+			SETSIZE(p_hdr, (right_buf_size + sizeof(T_RVF_INTERNAL_BUF) ) );
+
+			if( last_remainder == right_buf) /* keep as last_remainder */
+			{	last_remainder = p_hdr;
+			}
+		}
+	}
+	
+	/* enqueue the free buffer in the appropriate list */
+	idx = RVF_BUF_LIST_INDEX( GETSIZE(p_hdr) );
+	p_hdr->header.p_prev = NULL;
+	p_hdr->p_next = lists[idx];
+	lists[idx] = p_hdr;
+	if( p_hdr->p_next != NULL)
+	{	(p_hdr->p_next)->header.p_prev = p_hdr;
+	}
+
+	ENDSIZE(p_hdr) = GETSIZE(p_hdr);
+	RVF_SET_PREV_FREE( NEXTCHUNK(p_hdr) );
+
+    rvf_enable();		/* exit critical section */
+	return TRUE;
+}
+
+
+/*******************************************************************************
+** Function         _str_cmp
+**
+** Description      Internal function which compares two null-terminated string.
+**					Returns TRUE if they are equal, else FALSE.
+*******************************************************************************/
+BOOLEAN _str_cmp( char *str1, char * str2)
+{	UINT8 i;
+	for ( i = 0; (str1[i] == str2[i]) && (str1[i] != 0) && (str2[i] != 0) && (i < RVF_MAX_MB_LEN); i++ );
+	if ( i == RVF_MAX_MB_LEN)
+	{	return TRUE;
+	}
+	
+	if ( (str1[i] == 0) && (str2[i] == 0) )
+	{	return TRUE;
+	}
+	return FALSE;
+}
+
+/******************************************************************************
+**
+**						MEMORY BANK RELATED FUNCTIONS
+**
+******************************************************************************/
+
+/*******************************************************************************
+**
+** Function         _remove_from_list
+**
+** Description      Internal function called to remove a buffer from the list of
+**					buffer waiting to be counted on the memory bank.
+**					The parameter points to the beginning of the header.
+**
+** Returns          BOOLEAN: TRUE if successful, else FALSE
+**
+*******************************************************************************/
+BOOLEAN _remove_from_list (void *bptr, T_RVF_MB * mb)
+{	UINT16 * index;
+	UINT16 free_elem, prec;
+
+	/* check all elements of the list */	
+	index = &(mb->first_buffer_index);
+	prec = RVF_INVALID_INDEX;
+
+	while ( (*index != RVF_INVALID_INDEX) && (waiting_buffers[*index]!=bptr) )
+	{	prec = *index;
+		index = &(next_buffer[*index]);
+	}
+	
+	if (waiting_buffers[*index] == bptr)
+	{	free_elem = *index;
+		*index = next_buffer[free_elem]; /* link preceding element to the next one */
+		
+		if (next_buffer[free_elem] == RVF_INVALID_INDEX ) /* last element in the list */
+		{	mb->last_buffer_index = prec;
+		}
+
+		waiting_buffers[free_elem] = NULL;
+		next_buffer[free_elem] = first_free_element; /* link free elements */
+		first_free_element = free_elem;
+		return TRUE;
+	}
+	return FALSE; /* buffer not found */
+}
+
+
+/*******************************************************************************
+**
+** Function         _add_to_list
+**
+** Description      Internal function called to add a buffer to the list of
+**					buffer waiting to be counted on the memory bank.
+**					The parameter points to the beginning of the header.
+**
+** Returns          BOOLEAN: TRUE if successful, else FALSE
+**
+*******************************************************************************/
+BOOLEAN _add_to_list (void *bptr, T_RVF_MB * mb)
+{	UINT16 index = first_free_element;
+	
+	first_free_element = next_buffer[index];
+	
+	waiting_buffers[index] = bptr;
+	next_buffer[index] = RVF_INVALID_INDEX;
+
+	if ( mb->last_buffer_index == RVF_INVALID_INDEX) /* empty list */
+	{	mb->first_buffer_index	= index;
+		mb->last_buffer_index	= index;
+	}
+	else
+	{	next_buffer[mb->last_buffer_index] = index;
+		mb->last_buffer_index = index;
+	}
+	
+	return TRUE;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_create_mb
+**
+** Description      Called by an application to create a memory bank
+**
+** Parameters:		memory bank name, memory bank param
+**					(return) memory bank id
+**
+** Returns          T_RVF_RET: RVF_OK if success
+**
+*******************************************************************************/
+T_RVF_RET		rvf_create_mb(T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM mb_param, T_RVF_MB_ID *mb_id)
+{	UINT8 num_mb;
+	T_RVF_MB * mb;
+	UINT32 available_mem = 0;
+	UINT32 required_mem = 0;
+
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+
+	if ( num_mb == RVF_MAX_TOTAL_MB ) /* mb name not found */
+	{	
+		/* DLC added for dynamic memory bank creation*/
+
+		/* search the first available place in the array */
+		T_RVF_MB_ID first_available_mb_id = 0;
+		BOOLEAN mb_id_found = FALSE; 
+
+		for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (rvf_name_id[num_mb].mb_name[0] != 0) ; num_mb++)
+		{	if( rvf_name_id[num_mb].mb_id == first_available_mb_id)
+			{	first_available_mb_id ++;
+			}
+		}
+		
+		while( (first_available_mb_id < RVF_MAX_REAL_MB) &&  (mb_id_found == FALSE) )
+		{	
+			for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (rvf_name_id[num_mb].mb_name[0] != 0) && (rvf_name_id[num_mb].mb_id != first_available_mb_id) ; num_mb++);
+			if ( rvf_name_id[num_mb].mb_id != first_available_mb_id)
+			{	/* available mb id found */
+				mb_id_found = TRUE;
+			}
+			else
+			{	/* try the next one */
+				first_available_mb_id++;
+			}
+		}
+
+		if ( (num_mb == RVF_MAX_TOTAL_MB) || (first_available_mb_id + 1 >= RVF_MAX_REAL_MB ) ) /* no available space in the array */
+
+	{	*mb_id = RVF_INVALID_MB_ID;
+		return RVF_INVALID_PARAMETER;
+	}
+
+	if(INC_Initialize_State==INC_END_INITIALIZE) rvf_disable(20);		/* enter critical section */
+
+		/* create the new mb name and id */
+		strcpy( rvf_name_id[num_mb].mb_name, mb_name);
+		rvf_name_id[num_mb].mb_id = first_available_mb_id;
+		
+		/* initialize the next one */
+		rvf_name_id[num_mb+1].mb_name[0]	= 0;
+		rvf_name_id[num_mb+1].mb_id			= 0;
+
+	if(INC_Initialize_State==INC_END_INITIALIZE) rvf_enable();		/* exit critical section */
+	}
+
+	/* check if the memory bank has been already created */
+	if ( rvf_name_id[ num_mb].mb_params.size != 0) 
+	{	*mb_id = RVF_INVALID_MB_ID;
+		return RVF_INTERNAL_ERR;
+	}
+
+	rvf_get_available_mem( &available_mem, &required_mem);
+
+	if ( ( (required_mem + mb_param.size)*100) > ( available_mem * _rvf_get_mem_usage_ratio()) )	/* if there is not enough available memory to create this mb */
+	{	*mb_id = RVF_INVALID_MB_ID;				/* In a next version: try to create a dynamic pool */
+		return RVF_MEMORY_ERR;
+	}
+
+	rvf_disable(20);		/* enter critical section */
+
+	/* save the mb parameters for deletion */
+	rvf_name_id[num_mb].mb_params.size = mb_param.size;
+	rvf_name_id[num_mb].mb_params.watermark = mb_param.watermark;
+
+	* mb_id = rvf_name_id[num_mb].mb_id;
+	mb = &rvf_banks[ *mb_id ];
+	/* initialize the memory bank structure */
+	mb->watermark				+= mb_param.watermark;
+	mb->max						+= mb_param.size;
+	
+	rvf_enable();		/* exit critical section */
+
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_mb_id
+**
+** Description      Called by an application to get the memory bank id from its name
+**
+** Parameters:		memory bank name
+**					(return) memory bank id
+**
+** Returns          T_RVF_RET: RVF_OK if success
+**
+*******************************************************************************/
+T_RVF_RET		rvf_get_mb_id(T_RVF_MB_NAME mb_name, T_RVF_MB_ID *mb_id)
+{	UINT8 num_mb;
+	
+
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+	if ( num_mb == RVF_MAX_TOTAL_MB ) /* mb name not found */
+	{	*mb_id = RVF_INVALID_MB_ID;
+		return RVF_INVALID_PARAMETER;
+	}
+	if ( rvf_banks[ rvf_name_id[num_mb].mb_id ].max == 0 )
+	{	/* the memory bank has not been created */
+		*mb_id = RVF_INVALID_MB_ID;
+		return 	RVF_NOT_READY;
+	}
+	*mb_id = rvf_name_id[num_mb].mb_id;
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_delete_mb
+**
+** Description      Called by an application to delete a memory bank
+**
+** Parameters:		memory bank name
+**
+** Returns          T_RVF_RET: RVF_OK if success
+**
+*******************************************************************************/
+T_RVF_RET		rvf_delete_mb(T_RVF_MB_NAME mb_name)
+{	UINT8 num_mb;
+	T_RVF_MB * mb;
+
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+	if ( num_mb == RVF_MAX_TOTAL_MB ) /* mb name not found */
+	{	return RVF_INVALID_PARAMETER;
+	}
+	mb = &rvf_banks[ rvf_name_id[num_mb].mb_id ];
+
+	/* check if the mb is used more than once or not */
+	if ( mb->max == rvf_name_id[num_mb].mb_params.size )
+	{	/* mb is used only once, check if cur_memory_used > 0 */
+		if ( mb->cur_memory_used > 0)
+		{	rvf_send_trace( "RVF: rvf_delete_mb(): not all buffers have been freed", 53, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+			return RVF_MEMORY_ERR;
+			/*	free all buffers ????? -> NOT POSSIBLE */
+		}
+		/* initialize mb params */
+		mb->max					= 0;
+		mb->first_buffer_index	= RVF_INVALID_INDEX;
+		mb->last_buffer_index	= RVF_INVALID_INDEX;
+		mb->watermark			= 0;
+		mb->returned_red		= FALSE;
+		mb->func				= 0;
+#if RVF_ENABLE_STATS
+	mb->max_reached				= 0;			
+	mb->required_size			= 0;			
+	mb->num_buf					= 0;				
+#endif
+
+	}
+	else	/* mb is still used by another entity */
+	{	/* change mb params */
+		mb->max			-= rvf_name_id[num_mb].mb_params.size;
+		mb->watermark	-= rvf_name_id[num_mb].mb_params.watermark;
+	}
+	
+	rvf_name_id[num_mb].mb_params.size = 0;
+	rvf_name_id[num_mb].mb_params.watermark = 0;
+
+	return RVF_OK;
+}
+
+T_RVF_RET		rvf_mb_is_used(T_RVF_MB_NAME mb_name, UINT8* isUsed) 	{
+	UINT8 num_mb;
+	T_RVF_MB * mb;
+
+	*isUsed=0;
+
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+	if ( num_mb == RVF_MAX_TOTAL_MB ) {/* mb name not found */
+		return RVF_INVALID_PARAMETER;
+	}
+	mb = &rvf_banks[ rvf_name_id[num_mb].mb_id ];
+
+	/* check if the mb is used more than once or not */
+	if ( mb->max == rvf_name_id[num_mb].mb_params.size ) {
+		/* mb is used only once, check if cur_memory_used > 0 */
+		if ( mb->cur_memory_used > 0) *isUsed=1;
+	}
+	return RVF_OK;
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_mb_status
+**
+** Description      Called by an application to get the status of a memory bank
+**
+** Parameters:		memory bank id
+**
+** Returns          T_RVF_MB_STATUS:	RVF_GREEN if everything is ok,
+**										RVF_YELLOW if watermark limit has been reached,
+**										RVF_RED if max size has been reached
+**
+*******************************************************************************/
+T_RVF_MB_STATUS	rvf_get_mb_status(T_RVF_MB_ID mb_id)
+{	T_RVF_MB * mb;
+
+	/* checking for invalid memory bank IDs */
+	if (mb_id >= RVF_MAX_REAL_MB)
+	{
+#ifdef RVM_DAR_SWE
+		dar_diagnose_generate_emergency (RVF_INVALID_MD_ID_ERRROR,
+										 DAR_ASCII_FORMAT,
+										 RVM_USE_ID);
+#else
+		rvf_send_trace (RVF_INVALID_MD_ID_ERRROR,
+						sizeof (RVF_INVALID_MD_ID_ERRROR) - 1,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_ERROR,
+						RVM_USE_ID);
+#endif
+		return RVF_RED;
+	}
+	mb = &rvf_banks[mb_id];
+	
+	if ( mb->returned_red == TRUE) /* if a previous count buf or get buf has failed */
+	{	return RVF_RED;
+	}
+
+	if ( mb->cur_memory_used < mb->watermark )
+	{	return RVF_GREEN;
+	}
+	else
+	{	if ( mb->cur_memory_used < mb->max )
+		{	return RVF_YELLOW;
+		}
+		else
+		{	return RVF_RED; /* since max and cur_memory_used are set to 0 for not-created mb, it will return RED*/ 
+		}
+	}
+}
+
+/*******************************************************************************
+**
+** Function         rvf_get_mb_unused_mem
+**
+** Description      Called by an application to get the number of bytes available
+**					until the memory bank size.
+**
+** Parameters:		memory bank id
+**
+** Returns          UINT32:	number of bytes available
+**					returns 0 if the memory bank has not been created.
+**
+*******************************************************************************/
+UINT32	rvf_get_mb_unused_mem(T_RVF_MB_ID mb_id)
+{	T_RVF_MB * mb;
+	mb = &rvf_banks[mb_id];
+	
+	if ( mb->returned_red == TRUE) /* if a previous count buf or get buf has failed */
+	{	return 0;
+	}
+
+	return( mb->max - mb->cur_memory_used);
+}
+
+/*******************************************************************************
+**
+** Function         rvf_get_mb_unused_green_mem
+**
+** Description      Called by an application to get the number of bytes available
+**					until the memory bank watermark.
+**
+** Parameters:		memory bank id
+**
+** Returns          UINT32:	number of bytes available
+**					returns 0 if the memory bank has not been created.
+**
+*******************************************************************************/
+UINT32	rvf_get_mb_unused_green_mem(T_RVF_MB_ID mb_id)
+{	T_RVF_MB * mb;
+	mb = &rvf_banks[mb_id];
+	
+	if ( mb->returned_red == TRUE) /* if a previous count buf or get buf has failed */
+	{	return 0;
+	}
+
+	if( mb->cur_memory_used > mb->watermark)
+	{	return 0;
+	}
+
+	return( mb->watermark - mb->cur_memory_used);
+}
+
+/*******************************************************************************
+**
+** Function         rvf_get_buf
+**
+** Description      Called by an application to get a buffer from a memory bank
+**
+** Parameters:		memory bank id, buffer size
+**					(return) buffer pointer to the allocated buffer or null if 
+**					mb status is RVF_RED
+**
+** Returns          T_RVF_MB_STATUS:	RVF_GREEN if everything is ok,
+**										RVF_YELLOW if watermark limit has been reached,
+**										RVF_RED if max size has been reached (does not return a buffer)
+**
+*******************************************************************************/
+T_RVF_MB_STATUS rvf_get_buf(T_RVF_MB_ID mb_id, UINT32 buffer_size, T_RVF_BUFFER** p_buffer)
+{	T_RVF_MB * mb;
+
+	/* checking for invalid memory bank IDs */
+	if (mb_id >= RVF_MAX_REAL_MB)
+	{
+#ifdef RVM_DAR_SWE
+		dar_diagnose_generate_emergency (RVF_INVALID_MD_ID_ERRROR,
+										 DAR_ASCII_FORMAT,
+										 RVM_USE_ID);
+#else
+		rvf_send_trace (RVF_INVALID_MD_ID_ERRROR,
+						sizeof (RVF_INVALID_MD_ID_ERRROR) - 1,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_ERROR,
+						RVM_USE_ID);
+#endif
+		return RVF_RED;
+	}
+	mb = &rvf_banks[ mb_id ];
+	
+	/* check memory usage */
+	if ( ( mb->cur_memory_used + buffer_size) >  mb->max )
+	{	/* over the limits, return RED and do not allocate a buffer */
+		mb->returned_red = TRUE;
+		*p_buffer = NULL;
+		return RVF_RED;
+	}
+	
+	/* find a buffer of the requested size */
+	*p_buffer = _find_buf( buffer_size );
+	if ( *p_buffer == NULL ) /* error during allocation, not enough memory */
+	{	//rvf_send_trace( "RVF: rvf_get_buf(): not enough available physical memory", 56, NULL_PARAM, RV_TRACE_LEVEL_ERROR, TRACE_RVF_BUFFER );
+		mb->returned_red = TRUE;
+		return RVF_RED;
+	}
+
+#if RVF_ENABLE_STATS
+	required_size	+= buffer_size;
+	obtained_size	+= rvf_get_buf_size((UINT8*)(*p_buffer) + sizeof(T_RVF_INTERNAL_BUF));
+	used_size		+= rvf_get_buf_size((UINT8*)(*p_buffer) + sizeof(T_RVF_INTERNAL_BUF)) + sizeof(T_RVF_INTERNAL_BUF) + RVF_CORRUPT_OVERHEAD;
+	mem_in_use		+= rvf_get_buf_size((UINT8*)(*p_buffer) + sizeof(T_RVF_INTERNAL_BUF)) + sizeof(T_RVF_INTERNAL_BUF) + RVF_CORRUPT_OVERHEAD;
+#endif
+
+	if(INC_Initialize_State==INC_END_INITIALIZE) rvf_disable(20);		/* enter critical section */
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	/* set as unlinked */
+	RVF_SET_BUF_UNLINKED((T_RVF_INTERNAL_BUF*)(*p_buffer));
+#endif
+
+	/* increase memory use counter */
+	mb->cur_memory_used += rvf_get_buf_size( (UINT8*)(*p_buffer) + sizeof(T_RVF_INTERNAL_BUF) );
+	( (T_RVF_INTERNAL_BUF *) (*p_buffer))->header.external.mb_id = mb_id;
+	( (T_RVF_INTERNAL_BUF *) (*p_buffer))->header.external.mb_expected = RVF_INVALID_MB_ID;
+	
+	*p_buffer = (UINT8*)(*p_buffer) + sizeof(T_RVF_INTERNAL_BUF);
+
+#if RVF_ENABLE_STATS
+	if ( mb->cur_memory_used > mb->max_reached )
+	{	mb->max_reached = mb->cur_memory_used;
+	}
+	mb->required_size += buffer_size;
+	mb->num_buf++;
+#endif
+
+	if(INC_Initialize_State==INC_END_INITIALIZE) rvf_enable();			/* exit critical section */
+
+	/* return the correct flag */
+	if ( mb->cur_memory_used > mb->watermark )
+	{	return RVF_YELLOW;
+	}
+	else
+	{	return RVF_GREEN;
+	}
+}
+
+/*******************************************************************************
+**
+** Function         rvf_count_buf
+**
+** Description      Called by an application to change the memory bank on which a buffer is counted
+**
+** Parameters:		new memory bank id,
+**					pointer to the buffer.
+**
+** Returns          T_RVF_MB_STATUS:	RVF_GREEN if everything is ok,
+**										RVF_YELLOW if watermark limit has been reached,
+**										RVF_RED if max size has been reached
+**
+*******************************************************************************/
+T_RVF_MB_STATUS rvf_count_buf(T_RVF_MB_ID mb_id, T_RVF_BUFFER * p_buffer)
+{	T_RVF_INTERNAL_BUF * buf;
+	UINT32 buf_size;
+	T_RVF_MB * new_mb;
+	T_RVF_MB * old_mb;
+
+	/* checking for invalid memory bank IDs */
+	if (mb_id >= RVF_MAX_REAL_MB)
+	{
+#ifdef RVM_DAR_SWE
+		dar_diagnose_generate_emergency (RVF_INVALID_MD_ID_ERRROR,
+										 DAR_ASCII_FORMAT,
+										 RVM_USE_ID);
+#else
+		rvf_send_trace (RVF_INVALID_MD_ID_ERRROR,
+						sizeof (RVF_INVALID_MD_ID_ERRROR) - 1,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_ERROR,
+						RVM_USE_ID);
+#endif
+		return RVF_RED;
+	}
+	buf = (T_RVF_INTERNAL_BUF *) ( (UINT8 *) p_buffer - sizeof(T_RVF_INTERNAL_BUF) );
+	new_mb = &rvf_banks[mb_id];
+	old_mb = &rvf_banks[buf->header.external.mb_id];
+		
+	/* get the size of the buffer and try to count it on the new mb */
+	buf_size = rvf_get_buf_size( p_buffer );
+	
+	if ( ( new_mb->cur_memory_used + buf_size ) < new_mb->max )
+	{	/* there is enough memory in the new mb */
+		
+		if ( buf->header.external.mb_expected != RVF_INVALID_MB_ID )
+		{	/* remove the buffer from the list of waiting buffers in mb expected */
+			_remove_from_list( buf, &rvf_banks[buf->header.external.mb_expected] );
+			buf->header.external.mb_expected = RVF_INVALID_MB_ID;
+		}
+		
+		rvf_disable(20);		/* enter critical section */
+
+		/* decrease the memory used in the old mb */
+		old_mb->cur_memory_used -= buf_size;
+	
+		/* increase memory used in the new mb */
+		new_mb->cur_memory_used += buf_size;
+
+		rvf_enable();			/* exit critical section */
+
+		/* call the callback function if state of the old mb switches to RVF_GREEN and there is no buffer waiting */
+		if ( (old_mb->cur_memory_used < old_mb->watermark) && (old_mb->first_buffer_index == RVF_INVALID_INDEX) && (old_mb->returned_red == TRUE) && ( old_mb->func != NULL) )
+		{	old_mb->returned_red = FALSE;
+			old_mb->func( buf->header.external.mb_id);
+		}
+		else
+		{	/* count as many waiting buffers as possible on the old mb */
+			while( (old_mb->first_buffer_index != RVF_INVALID_INDEX) && (rvf_count_buf( buf->header.external.mb_id, (UINT8 *) (waiting_buffers[old_mb->first_buffer_index]) + sizeof(T_RVF_INTERNAL_BUF)) != RVF_RED) );
+			if ( (old_mb->cur_memory_used < old_mb->watermark) && (old_mb->first_buffer_index == RVF_INVALID_INDEX) && (old_mb->returned_red == TRUE) && ( old_mb->func != NULL) )
+			{	old_mb->returned_red = FALSE;
+				old_mb->func( buf->header.external.mb_id);
+			}
+		}
+		/* change mb_id of the buffer */
+		buf->header.external.mb_id = mb_id;
+
+
+
+#if RVF_ENABLE_STATS
+	if ( new_mb->cur_memory_used > new_mb->max_reached )
+	{	new_mb->max_reached = new_mb->cur_memory_used;
+	}
+#endif
+
+		if ( new_mb->cur_memory_used > new_mb->watermark )
+		{	return RVF_YELLOW;
+		}
+		else
+		{	return RVF_GREEN;
+		}
+	}
+	else
+	{	/* there is not enough memory in the new mb_id */
+		if ( buf->header.external.mb_expected != RVF_INVALID_MB_ID)	/* remove the buffer from old expected mb */
+		{	_remove_from_list( buf, &rvf_banks[ buf->header.external.mb_expected] );
+		}
+		/* enqueue the buffer in the list of waiting buffer */
+		buf->header.external.mb_expected = mb_id;
+		_add_to_list( buf, new_mb );
+		new_mb->returned_red = TRUE;
+		return RVF_RED;
+	}
+}
+
+/*******************************************************************************
+**
+** Function         rvf_free_buf
+**
+** Description      Called by an application to free a buffer
+**
+** Parameters:		buffer pointer
+**
+** Returns          T_RVF_RET:	T_RVF_OK if succesful,
+**
+*******************************************************************************/
+T_RVF_RET rvf_free_buf( T_RVF_BUFFER * p_buffer)
+{	T_RVF_INTERNAL_BUF * buf;
+	T_RVF_MB * mb;
+	T_RVF_MB_ID mb_id;
+	UINT32 buf_size;
+	
+	
+	buf = USER2MEM(p_buffer);
+
+	mb_id = buf->header.external.mb_id;
+	mb = &rvf_banks[mb_id];
+	buf_size = rvf_get_buf_size(p_buffer);
+
+	/* do not need to change the mb id of the buffer, since it will be overwritten by p_prev */
+
+	/* free the buffer */
+	if ( !_release_buf(buf) )
+	{	return RVF_MEMORY_ERR;
+	}
+
+#if RVF_ENABLE_STATS
+	mem_in_use		-= buf_size + sizeof(T_RVF_INTERNAL_BUF) + RVF_CORRUPT_OVERHEAD;
+#endif
+
+	rvf_disable(20);		/* enter critical section */
+
+	/* decrease mb memory use */
+	mb->cur_memory_used -= buf_size;
+
+	rvf_enable();			/* exit critical section */
+
+
+	/* call the callback function if state of the mb switches to RVF_GREEN and there is no buffer waiting */
+	if ( (mb->returned_red == TRUE) && (mb->cur_memory_used < mb->watermark) && ( mb->first_buffer_index == RVF_INVALID_INDEX) && ( mb->func != NULL) )
+		{	mb->returned_red = FALSE;
+			mb->func( mb_id);
+		}
+		else
+		{	/* count as many waiting buffers as possible on the mb */
+			while( (mb->first_buffer_index != RVF_INVALID_INDEX) && (rvf_count_buf( mb_id, (UINT8 *) (waiting_buffers[mb->first_buffer_index]) + sizeof(T_RVF_INTERNAL_BUF)) != RVF_RED) );
+			if ( (mb->cur_memory_used < mb->watermark) && ( mb->first_buffer_index == RVF_INVALID_INDEX) && (mb->returned_red == TRUE) && ( mb->func != NULL) )
+			{	mb->returned_red = FALSE;
+				mb->func( mb_id);
+			}
+		}
+
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_set_callback_func
+**
+** Description      Called the first time an application wants to set the callback
+**					function associated to a memory bank.
+**
+** Parameters:		memory bank id, pointer to the callback function.
+**
+** Returns          T_RVF_RET:	T_RVF_OK if succesful,
+**
+*******************************************************************************/
+T_RVF_RET		rvf_set_callback_func(T_RVF_MB_ID mb_id, MB_CALLBACK_FUNC func)
+{	T_RVF_MB * mb;
+
+	/* checking for invalid memory bank IDs */
+	if (mb_id >= RVF_MAX_REAL_MB)
+		return RVF_INVALID_PARAMETER;
+	mb = &rvf_banks[mb_id];
+	if ( (mb->max != 0) && (mb->func == NULL) )	/* if the mb has been created and the callback func has never been set */
+	{	mb->func = func;
+		return RVF_OK;
+	}
+	return RVF_INVALID_PARAMETER;	
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_change_callback_func
+**
+** Description      Called by an application to change the callback
+**					function associated to a memory bank.
+**					It means the callback function has to be set before.
+**
+** Parameters:		memory bank id, pointer to the callback function.
+**
+** Returns          T_RVF_RET:	T_RVF_OK if succesful,
+**
+*******************************************************************************/
+T_RVF_RET		rvf_change_callback_func(T_RVF_MB_ID mb_id, MB_CALLBACK_FUNC func)
+{	T_RVF_MB * mb;
+
+	/* checking for invalid memory bank IDs */
+	if (mb_id >= RVF_MAX_REAL_MB)
+		return RVF_INVALID_PARAMETER;
+	mb = &rvf_banks[mb_id];
+	if ( (mb->max != 0) && (mb->func != NULL) )	/* if the mb has been created and the callback func has already been set */
+	{	mb->func = func;
+		return RVF_OK;
+	}
+	return RVF_INVALID_PARAMETER;	
+}
+
+#ifdef _WINDOWS_
+/*******************************************************************************
+**
+** Function         _rvf_window_dump_mem
+**
+** Description      Called by a C++ object to update the graphical display of
+**                  memory
+**
+** Parameters:		Opaque pointer to C++ object
+**
+** Returns          void
+**
+** WARNING          DON'T CHANGE THE SYNTAX OF DISPLAYED DATAS SINCE
+**                  THEY ARE PARSED TO DISPLAY GRAPHICALLY THE MEMORY
+**                  STATUS
+**
+*******************************************************************************/
+void _rvf_window_dump_mem(void *m)
+{
+
+	
+#if RVF_ENABLE_STATS	/* conditional compilation if stats are enabled */
+	char mb_info[100];
+	UINT16 num_mb, num_buf, index;
+	UINT32 total_mem_size = 0;
+	UINT32 total_max_used = 0;
+	UINT32 total_cur_used = 0;
+	T_RVF_MB * mb;
+
+
+	for ( num_mb = 0; num_mb < RVF_MAX_TOTAL_MB; num_mb++ )
+	{	
+		/* trace the mb if it has been created*/
+		if ( rvf_name_id[num_mb].mb_params.size > 0 )
+		{	mb = &rvf_banks[ rvf_name_id[num_mb].mb_id ]; 
+			num_buf = 0;
+			index = mb->first_buffer_index;
+			while ( index != RVF_INVALID_INDEX)
+			{	num_buf++;
+				index = next_buffer[index];
+			}
+			strcpy(mb_info,rvf_name_id[num_mb].mb_name);
+			mb_info[10]='\0';
+			AddNewState(m,mb_info,
+				mb->cur_memory_used,mb->max_reached,mb->watermark,mb->max);
+			
+			
+			total_mem_size += mb->max;
+			total_max_used += mb->max_reached;
+			total_cur_used += mb->cur_memory_used;
+		}
+	}
+	
+#endif /* RVF_ENABLE_STATS */
+}
+
+#endif
+
+/*******************************************************************************
+**
+** Function         rvf_dump_mem
+**
+** Description      Called by an application to dump mb state and display statistics
+**
+** Parameters:		None
+**
+** Returns          void
+**
+** WARNING          DON'T CHANGE THE SYNTAX OF DISPLAYED DATAS SINCE
+**                  THEY ARE PARSED TO DISPLAY GRAPHICALLY THE MEMORY
+**                  STATUS
+**
+*******************************************************************************/
+void rvf_dump_mem()
+{
+#if RVF_ENABLE_STATS	/* conditional compilation if stats are enabled */
+	char mb_info[100];
+	UINT16 num_mb, num_buf, index;
+	UINT32 total_mem_size = 0;
+	UINT32 total_max_used = 0;
+	UINT32 total_cur_used = 0;
+	T_RVF_MB * mb;
+
+
+	/* display memory required, obtained and ratio */
+	rvf_send_trace("MEM STAT: Total memory required", 31, required_size, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+	rvf_send_trace("MEM STAT: Total memory obtained", 31, obtained_size, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+	rvf_send_trace("MEM STAT: Total memory used    ", 31, used_size, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+	sprintf( mb_info,"MEM STAT: Mem usage ratio      : %010f%%",  ( (double)(required_size) / (double)(obtained_size) ) *100 );
+	rvf_send_trace(mb_info, 44, NULL_PARAM , RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+
+	rvf_send_trace("*** START DUMPING MEMORY BANK ***", 33, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+	/* for each mb, display its name, its id, its cur_size, its watermark, its limit, its max reached, the number of callback functions enqueued,
+	(the requested size, the number of allocated buffer), the average buffer size for this mb */
+	rvf_send_trace("**MB_NAME* Id Used_mem Watermark  Limit   Peak Nb_buff Avg_buf_size", 67, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+
+	for ( num_mb = 0; num_mb < RVF_MAX_TOTAL_MB; num_mb++ )
+	{	
+		/* trace the mb if it has been created*/
+		if ( rvf_name_id[num_mb].mb_params.size > 0 )
+		{	mb = &rvf_banks[ rvf_name_id[num_mb].mb_id ]; 
+			num_buf = 0;
+			index = mb->first_buffer_index;
+			while ( index != RVF_INVALID_INDEX)
+			{	num_buf++;
+				index = next_buffer[index];
+			}
+			sprintf( mb_info, "%10.10s %2d   %6d    %6d %6d %6d      %2d       %6d",
+				rvf_name_id[num_mb].mb_name, rvf_name_id[num_mb].mb_id, 
+				mb->cur_memory_used, mb->watermark, mb->max, mb->max_reached, num_buf,
+				mb->num_buf == 0? 0:mb->required_size / mb->num_buf);
+
+			rvf_send_trace( mb_info, 67, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);		
+
+			total_mem_size += mb->max;
+			total_max_used += mb->max_reached;
+			total_cur_used += mb->cur_memory_used;
+		}
+	}
+	sprintf(	mb_info, "TOTAL: ******** %6d********** %6d %6d",
+				total_cur_used, total_mem_size, total_max_used );
+
+	rvf_send_trace( mb_info, 46, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);		
+
+#endif /* RVF_ENABLE_STATS */
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_available_mem
+**
+** Description      Called to get the total size of the memory and the used size.
+**
+** Parameters:		(return) UINT32 * total_size: contains the number of bytes in the memory.
+**					(return) UINT32 * used_size:  contains the number of used bytes in the memory.
+**
+** Returns          T_RVF_RET: RVF_OK if successful, else a negative value.
+**
+*******************************************************************************/
+T_RVF_RET rvf_get_available_mem( UINT32 * total_size, UINT32 * used_size )
+{
+	UINT16 count;
+	*total_size = 0;
+	*used_size	= 0;
+
+	/* check if there is enough available physical memory (static or dynamic): if Sum(mb size) <= Sum(pool size)*/
+	for ( count = 0; count < _rvf_get_number_of_pool(); count ++ )		/* sum the memory in pools */
+	{	*total_size += _rvf_pools[count].pool_size;
+	}
+	/* sum the memory required by existing mb */
+	for ( count = 0; count < RVF_MAX_REAL_MB; count ++ )
+	{	*used_size	+= rvf_banks[count].max;
+	}
+
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_mb_param
+**
+** Description      return the parameters of a specific memory bank 
+**
+** Parameters:		T_RVF_MB_NAME: name of the memory bank
+**					(return) T_RVF_MB_PARAM*: parameter of the memory bank.
+**
+** Returns          T_RVF_RET: RVF_OK if successful, else a negative value.
+**
+*******************************************************************************/
+T_RVF_RET rvf_get_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param)
+{	UINT8 num_mb;
+	
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+	if ( num_mb == RVF_MAX_TOTAL_MB ) /* mb name not found */
+	{	return RVF_INVALID_PARAMETER;
+	}
+	
+	/* copy the parameters of the memory bank */
+	*param = rvf_name_id[num_mb].mb_params;
+
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_set_mb_param
+**
+** Description      change the parameters of a specific memory bank 
+**
+** Parameters:		T_RVF_MB_NAME: name of the memory bank
+**					T_RVF_MB_PARAM*: parameter of the memory bank.
+**
+** Returns          T_RVF_RET: RVF_OK if successful, else a negative value.
+**
+*******************************************************************************/
+T_RVF_RET rvf_set_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param)
+{	UINT8 num_mb;
+	T_RVF_MB_ID mb_id;
+	T_RVF_MB * mb;
+
+	/* find the mb name in the array */
+	for ( num_mb = 0; (num_mb < RVF_MAX_TOTAL_MB) && (!_str_cmp(mb_name, rvf_name_id[num_mb].mb_name) ); num_mb++);
+	if ( num_mb == RVF_MAX_TOTAL_MB ) /* mb name not found */
+	{	return RVF_INVALID_PARAMETER;
+	}
+
+	mb_id = rvf_name_id[num_mb].mb_id;
+	mb = &rvf_banks[ mb_id ];
+	
+	rvf_disable(20);		/* enter critical section */
+	
+	/* decrease the mb param by the old parameters */
+	mb->watermark				-= rvf_name_id[num_mb].mb_params.watermark;
+	mb->max						-= rvf_name_id[num_mb].mb_params.size;
+
+	/* save the mb parameters */
+	rvf_name_id[num_mb].mb_params.size = param->size;
+	rvf_name_id[num_mb].mb_params.watermark = param->watermark;
+
+	/* increase the mb param by the new parameters */
+	mb->watermark				+= param->watermark;
+	mb->max						+= param->size;
+	
+	rvf_enable();		/* exit critical section */
+
+	/* dequeue callback functions if state switches to RVF_GREEN */
+
+	return RVF_OK;
+}
+
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_empty_mailboxes
+**
+** Description      Called by rvf_exit_task to empty a task's mailboxes before
+**					killing it
+**
+** Parameters:		task_id: task of wich the mailboxes have to be emptied
+**
+** Returns          RV_OK
+**
+*******************************************************************************/
+T_RV_RET _rvf_empty_mailboxes (T_RVF_G_ADDR_ID task_id)
+{
+    void * p_buf	= NULL;
+    T_RVF_INTERNAL_BUF * p_hdr;
+	UINT8 mbox_id = 0;
+
+    if (task_id >= MAX_RVF_TASKS)
+    {
+		rvf_send_trace( "RVF: rvf_empty_mbox(): invalid taskid: ", 39, task_id, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return RVF_INVALID_PARAMETER;
+    } 
+
+	for (mbox_id = 0; mbox_id< RVF_NUM_TASK_MBOX; mbox_id++)
+	{   /* while the chained list is not empty */
+		/*while ( OSTaskQFirst[task_id][mbox_id] )
+		{
+		    rvf_disable(9);		
+
+			p_hdr = OSTaskQFirst[task_id][mbox_id];
+			OSTaskQFirst[task_id][mbox_id] = p_hdr->p_next;
+		*/
+		while ( pRtAddrIdTable[task_id]->OSTaskQFirst[mbox_id]  )
+		{
+		    rvf_disable(9);		
+
+			p_hdr = pRtAddrIdTable[task_id]->OSTaskQFirst[mbox_id];
+			pRtAddrIdTable[task_id]->OSTaskQFirst[mbox_id] = p_hdr->p_next;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+			/* set as unlinked */
+			RVF_SET_BUF_UNLINKED(p_hdr);
+#endif
+
+			p_buf = (UINT8 *)p_hdr + sizeof(T_RVF_INTERNAL_BUF);
+
+			rvf_enable();		/* exit critical section */
+
+			rvf_free_buf(p_buf);
+		}
+	}
+
+
+    return (RV_OK);
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_scan_next
+**
+** Description      return the next item in the queue if any.
+**					If the end of the queue is reached, returns NULL.
+**					If current item is NULL, returns the first item in the queue.
+**
+** Returns          NULL if the end of the queue is reached, else a pointer to the buffer.
+**
+*******************************************************************************/
+T_RVF_BUFFER *	rvf_scan_next (T_RVF_BUFFER_Q * p_q, T_RVF_BUFFER * p_buf)
+{
+    T_RVF_INTERNAL_BUF    *p_hdr;
+
+    if (!p_q->count)	/* if the queue is empty */
+        return (NULL);
+
+	if (p_buf == NULL)  /* if current item == NULL, returns the first one */
+	{
+		return (T_RVF_BUFFER*)p_q->p_first;
+	}
+
+    rvf_disable(12);	/* enter critical section */
+
+    p_hdr = (T_RVF_INTERNAL_BUF *)((UINT8 *)p_buf - sizeof(T_RVF_INTERNAL_BUF));
+	p_hdr = p_hdr->p_next;
+	if (p_hdr != NULL)
+	{	p_hdr = (T_RVF_INTERNAL_BUF*) ((UINT8 *)p_hdr + sizeof(T_RVF_INTERNAL_BUF));
+	}
+	
+	rvf_enable();
+
+	return (T_RVF_BUFFER*)p_hdr;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_remove_from_queue
+**
+** Description      remove a specific item from a queue
+**
+** Returns          RVF_OK if the item is removed, RVF_INTERNAL_ERR else.
+**
+*******************************************************************************/
+T_RVF_RET		rvf_remove_from_queue (T_RVF_BUFFER_Q * p_q, T_RVF_BUFFER * p_buf)
+{
+    T_RVF_INTERNAL_BUF    *p_hdr;
+	T_RVF_INTERNAL_BUF    *p_target;
+
+	
+    if (!p_q->count)	/* if the queue is empty */
+        return (RVF_INTERNAL_ERR);
+
+    rvf_disable(12);	/* enter critical section */
+
+	/* find the specific item in the queue */
+	p_target = USER2MEM((UINT8*)p_buf);
+	p_hdr = USER2MEM( (UINT8 *)p_q->p_first);
+	
+	if( p_hdr == p_target )
+	{	/* the specific item is the first one */
+		rvf_dequeue( p_q);
+		rvf_enable();
+		return (RVF_OK);
+	}
+	
+	while( (p_hdr->p_next != p_target) && (p_hdr->p_next != NULL) )
+	{	p_hdr = p_hdr->p_next;
+	}
+	
+	if( p_hdr->p_next == NULL) /* item not found */
+	{	rvf_enable();
+		return (RVF_INTERNAL_ERR);
+	}
+
+
+	p_hdr->p_next = p_target->p_next;
+	p_q->count--;
+    
+    /* if we removed the last buffer */
+    if (p_q->p_last == p_buf)
+	{	p_q->p_last = p_hdr + sizeof(T_RVF_INTERNAL_BUF);
+	}   
+
+    p_target->p_next = NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	/* set as unlinked */
+	RVF_SET_BUF_UNLINKED(p_target);
+#endif
+
+    rvf_enable();		/* exit critical section */
+
+    return (RVF_OK);
+}
+
+/*******************************************************************************
+**
+** Function         rvf_dump_pool
+**
+** Description      Called by an application to dump memory pool usage
+**
+** Parameters:		None
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_dump_pool()
+{
+#if RVF_ENABLE_STATS	/* conditional compilation if stats are enabled */
+	
+	UINT16 num_pool;
+	UINT32 total_mem = 0;
+
+	/* display memory stats */
+	rvf_send_trace("*** START DUMPING MEMORY ***", 28, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+
+	/* display the total amount of memory available in the system */
+	/* and the total amount of memory currently in use */
+	for( num_pool = 0; num_pool < _rvf_get_number_of_pool(); num_pool++)
+	{	total_mem	+= _rvf_pools[num_pool].pool_size;
+	}
+		
+	rvf_send_trace( "Total memory available ", 23, total_mem, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);		
+	rvf_send_trace( "Memory currently in use", 23, mem_in_use, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);		
+
+#endif /* RVF_ENABLE_STATS */
+}
+
+static void rvf_free_protected_buf(void *buf)
+{
+	rvf_free_buf(buf);
+}
+
+void rvf_get_protected_buf(T_RVF_MB_ID mb_id, UINT32 buffer_size, T_RVF_BUFFER** p_buffer)
+{
+   T_RVF_MB_STATUS err;
+   err=rvf_get_buf(mb_id,buffer_size,p_buffer);
+   if (err==RVF_GREEN)
+   {
+	   struct _protectedPtr_ *ptr;
+	   struct _exceptionContext_ *context;
+
+	   context=_currentExceptionContext_[rvf_get_taskid()];
+	   err=rvf_get_buf(mb_id,sizeof(struct _protectedPtr_),(void*)&ptr);
+	   ptr->next=NULL;
+	   ptr->previous=NULL;
+	   ptr->ptr=*p_buffer;
+	   ptr->func=rvf_free_protected_buf;
+
+	   if (err==RVF_GREEN)
+	   {
+          if (context->stack==NULL)
+		  {
+			  context->stack=ptr;
+		  }
+		  else
+		  {
+			  ptr->previous=context->stack;
+			  context->stack->next=ptr;
+			  context->stack=ptr;
+		  }
+	   }
+	   else
+	   {
+		   rvf_free_buf(*p_buffer);
+	   }
+   }
+   if (err!=RVF_GREEN)
+	   throw(E_not_enough_memory);
+}
+
+//TISHMMS Project
+/* add by xmzhou_trace_string to trace debug trace message */
+void xmzhou_trace_string(char * string2trace)
+{
+rvf_send_trace(string2trace,strlen(string2trace),NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+}
+
+void xmzhou_trace_string_value(char * string2trace,UINT32 value)
+{
+rvf_send_trace(string2trace,strlen(string2trace),value, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+}
+
+static void mychar2hex(char ch, char *str)
+{
+    unsigned char   h_nibble = (ch >> 4) & 0x0F;
+    unsigned char   l_nibble = ch & 0x0F;
+
+    if (h_nibble < 10)
+        str[0] = 48 + h_nibble;
+    else
+        str[0] = 55 + h_nibble;
+
+    if (l_nibble < 10)
+        str[1] = 48 + l_nibble;
+    else
+        str[1] = 55 + l_nibble;
+}
+
+void xmzhou_trace_n_bytes(char * buffer0, UINT32 len)
+{
+int i;
+int traced_len=0;
+char mybuffer[40];
+char *tracebuffer;
+
+if(buffer0==NULL) return;
+
+xmzhou_trace_string_value("xmzhou dumping data length=",len);
+xmzhou_trace_string("-------");
+	
+
+while(traced_len<len){
+
+	if((len-traced_len)>=16){
+	  tracebuffer=mybuffer;
+	  for (i = 0; i < 16; i++) {
+    	mychar2hex (buffer0[traced_len+i], tracebuffer);
+	    tracebuffer += 2;
+  	  }
+	  traced_len+=16;
+	  *tracebuffer = '\0';
+  	  rvf_send_trace(mybuffer,strlen(mybuffer),NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+  	  rvf_delay(20);
+	}else{
+      tracebuffer=mybuffer;
+	  for(i=0;i<(len-traced_len);i++)
+	  	{
+	    	mychar2hex (buffer0[traced_len+i], tracebuffer);
+		    tracebuffer += 2;
+	  	}
+	  *tracebuffer = '\0';
+  	  rvf_send_trace(mybuffer,strlen(mybuffer),NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+      rvf_delay(20);
+	  break;
+	}
+
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_cust.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,39 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_cust.h                                                  */
+/*                                                                          */
+/*  Function    this file contains rvf cust definitions                     */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  29/11/2002	Create														*/
+/*																			*/
+/*	Author		Stephanie Gerthoux(s-gerthoux@ti.com)						*/
+/*																			*/
+/* (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+
+#ifndef _RVF_CUST_H
+#define _RVF_CUST_H
+
+
+#include "rv/general.h"
+
+
+/* RVF will managed at most 2 pools of memory for dynamic allocation */
+/* buffer pool structure*/
+typedef struct _t_rvf_pool
+{
+	void * start_address;			/* address of the beginnig of the pool */
+	UINT32 pool_size;				/* total size of the pool */
+} T_RVF_POOL;
+
+
+/* RVF function prototypes */
+
+void _rvf_init_free_queue (UINT8 id, UINT32 size, void *p_mem);
+
+#endif /* _RVF_I_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_env.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,46 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_env.h                                                   */
+/*                                                                          */
+/*  Function    this file contains rvf definitions specific for the RVM.	*/
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  28/01/2000	Create														*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef _RVF_ENV_H
+#define _RVF_ENV_H
+
+#include "rvf/rvf_api.h"
+
+
+
+
+/* return the size of the available memory in bytes */
+T_RVF_RET rvf_get_available_mem( UINT32 * total_size, UINT32 * used_size );
+
+/* get the parameters of a specific memory bank */
+T_RVF_RET rvf_get_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param);
+
+/* change the parameters of a specific memory bank */
+T_RVF_RET rvf_set_mb_param( T_RVF_MB_NAME mb_name, T_RVF_MB_PARAM * param);
+
+/* retrieve the amount of memory available before the memory bank size */
+UINT32	rvf_get_mb_unused_mem(T_RVF_MB_ID mb_id);
+
+/* retrieve the amount of memory available before the memory bank watermark */
+UINT32	rvf_get_mb_unused_green_mem(T_RVF_MB_ID mb_id);
+
+
+
+
+
+#endif	/* _RVF_ENV_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,262 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_i.h                                                     */
+/*                                                                          */
+/*  Function    this file contains rvf private definitions                  */
+/*                                                                          */
+/*  Version		0.4															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  3/12/99		Create														*/
+/*	30/11/99	compliant to RV coding guidelines							*/
+/*  12/23/1999	change buffer structures, add memory bank related structures*/
+/*  02/21/2000	change memory bank implementation.							*/
+/*  12/07/2000	implement dynamic memory allocation.						*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+
+#ifndef _RVF_I_H
+#define _RVF_I_H
+
+
+#include "rv/general.h"
+#include "rvf/rvf_api.h"
+#include "nucleus.h" 	/* A-M-E-N-D-E-D! */
+#include "rvm/rvm_i.h"
+
+/********************************************************************/
+/**  Buffer Management Data Structures                             **/
+/********************************************************************/
+#define MAX_RVF_G_ADDR_ID	200
+
+
+/* define the OVERHEAD per buffer */
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK
+	#define RVF_CORRUPT_OVERHEAD (sizeof(UINT32))
+	BOOLEAN _rvf_chk_buf_damage(void *bptr);
+#else
+	#define RVF_CORRUPT_OVERHEAD 0
+#endif
+/* calculate the size required in bytes, add the overhead for buffer corruption and round up to a multiple of 4 */
+#define REQ2SIZE(size) ( ((size) + 3 + RVF_CORRUPT_OVERHEAD) & ~0x00000003)
+
+
+#define RVF_MIN_USABLE_SIZE	( sizeof(T_RVF_INTERNAL_BUF) + sizeof(UINT32) )
+
+/* macros to get the internal header from the user pointer and vice-versa */
+#define USER2MEM(buf)  ( (T_RVF_INTERNAL_BUF*)(((UINT8*)(buf)) - sizeof(T_RVF_INTERNAL_BUF) ) )
+#define MEM2USER(buf)  ( ((UINT8*)(buf)) + sizeof(T_RVF_INTERNAL_BUF) )
+
+
+/* NOTE: since buffer size is always a multiple of 4, the last 2 bits may be used for flags */
+
+#define GETSIZE(hdr)	((UINT32)(hdr->buf_size & ~0x03) )
+
+/* macros to manage if buffers are linked or not */
+#define RVF_BUF_IS_LINKED(hdr) 		(0x00000001 & hdr->buf_size)
+#define RVF_SET_BUF_LINKED(hdr)		( (hdr)->buf_size |= 0x00000001)
+
+#define RVF_BUF_IS_UNLINKED(hdr)	(!(RVF_BUF_IS_LINKED(hdr)) )
+#define RVF_SET_BUF_UNLINKED(hdr)	( (hdr)->buf_size &= ~0x00000001)
+
+
+/* macros to set and check the usage of the previous buffer */
+#define RVF_IS_PREV_IN_USE(hdr) 	(0x00000002 & hdr->buf_size)
+#define RVF_SET_PREV_IN_USE(hdr)	( (hdr)->buf_size |= 0x00000002)
+
+#define RVF_IS_PREV_FREE(hdr)		(!(RVF_IS_PREV_IN_USE(hdr)) )
+#define RVF_SET_PREV_FREE(hdr)		( (hdr)->buf_size &= ~0x00000002)
+
+
+#define SETSIZE(hdr, size)			{	(hdr)->buf_size &= 0x03;\
+										(hdr)->buf_size |= (size); }
+									
+
+
+#define NEXTCHUNK(hdr)	( (T_RVF_INTERNAL_BUF *)( (UINT8*)hdr + GETSIZE(hdr) + sizeof(T_RVF_INTERNAL_BUF) ) )
+
+#define ENDSIZE(hdr)	( ((T_RVF_INTERNAL_BUF*)( (UINT8*)hdr + GETSIZE(hdr) + sizeof(T_RVF_INTERNAL_BUF) - sizeof(UINT32) ))->buf_size )
+
+
+#define RVF_NB_FREE_LISTS	32
+/* macro used to get the list index from the buffer size */
+/* 32 lists :	8  lists for buffer < 256  all spaced 32 bytes apart,
+				8  lists for buffer < 1280 all spaced 128 bytes apart,
+				8  lists for buffer < 5376 all spaced 512 bytes apart, 
+				8  lists for buffer > 5376 all spaced 16384 bytes apart.*/
+
+#define RVF_BUF_LIST_INDEX(size)	( ((size) < 256 ) ? ( (UINT8)((size)>>5) ) :\
+									( ((size) < 1280 ) ? ((UINT8)(8 + ((size-256)>>7) ) ) :\
+									( ((size) < 5376) ? ((UINT8)(16 + ((size-1280)>>9) ) ) :\
+									( ((size) < 136448)? ((UINT8)(24 + ((size-5376)>>14) ) ): (UINT8)(31) ) ) ) )
+
+/* internal buffer structure */
+typedef struct _t_internal_buf
+{	UINT32	buf_size;					/* size of the user buffer */
+	struct	_t_internal_buf * p_next;	/* pointer to the next buffer in the queue */ 
+	
+	union header
+	{	struct external
+		{	UINT16	mb_id;						/* id of the memory bank which owns the buffer */
+			UINT16	mb_expected;				/* id of the memory bank on which the buffer want to be counted */
+		}external;
+		
+		struct	_t_internal_buf * p_prev;		/* pointer to the previous buffer in the queue */ 
+	}header;
+	
+	
+} T_RVF_INTERNAL_BUF;
+
+
+
+
+
+/* RVF will managed at most 2 pools of memory for dynamic allocation */
+/* buffer pool structure*/
+typedef struct _t_rvf_pool
+{
+	void * start_address;			/* address of the beginnig of the pool */
+	UINT32 pool_size;				/* total size of the pool */
+} T_RVF_POOL;
+
+
+
+
+/* memory bank structure */
+typedef struct _t_rvf_mb
+{	UINT32	cur_memory_used;		/* size of current memory usage */
+	UINT32	watermark;				/* watermark */
+	UINT32	max;					/* max size */
+	MB_CALLBACK_FUNC func;			/* function to call when mb_state switch to GREEN */
+	BOOLEAN	returned_red;			/* flag indicating that this memory bank returned a RED value, */
+									/* its callback function has to be called and/or buffer are waiting */	
+	UINT16	first_buffer_index;		/* index of the first waiting buffer in the array */
+	UINT16	last_buffer_index;		/* index of the last waiting buffer in the array */
+#if RVF_ENABLE_STATS
+	UINT32	max_reached;			/* maximum memory usage reached */
+	UINT32	required_size;			/* total size in byte required by the rvf_get_buf function */
+	UINT32	num_buf;				/* total number of buffer allocated by rvf_get_buf function */
+#endif
+
+} T_RVF_MB;
+
+
+/* structure which associates mb name and mb id */
+typedef struct _t_rvf_mb_name_id
+{	char mb_name[RVF_MAX_MB_LEN];	/* name of the memory bank */
+	UINT16 mb_id;					/* id of the memory bank */
+	T_RVF_MB_PARAM mb_params;		/* parameters of the memory bank */
+} T_RVF_MB_NAME_ID;
+
+
+/* note:
+ * - hosting_list overhead is reduced with an 8 bit addr id
+ * - is hosting_list needed? would known_swe struct be enough to derive all info?  */
+typedef struct _rvf_rt_addr_id_data {					/* A-M-E-N-D-E-D!  */
+	UINT8				type_code;						/* poss. derived?  */
+	UINT8				priority;
+	T_RVF_G_ADDR_ID		host_addr_id;					/* Poss. union: JavaRef-32b or addrId-16 */
+	UINT8				hosting_count;
+	T_RVF_G_ADDR_ID		parasites[MAX_PARASITES];
+	UINT8				swe_db_index;
+	char*				symbolic_name;
+	NU_TASK*			pOSTCB;
+	NU_EVENT_GROUP*		pOSEvtGrp;
+	UINT8*				p_os_stack;
+	UINT16				os_stack_size;
+	T_RVF_G_ADDR_ID		virtualContext;
+	UINT8				gdHost;
+	T_RVF_INTERNAL_BUF* OSTaskQFirst[RVF_NUM_TASK_MBOX]; 
+	T_RVF_INTERNAL_BUF*	OSTaskQLast [RVF_NUM_TASK_MBOX];
+	T_RV_RET			(* handle_message)	(T_RV_HDR * msg);  // note: T_RV_RETURN and not T_RVM...
+	T_RV_RET			(* handle_timer)	(T_RV_HDR * msg);
+} T_RVF_RT_ADDR_ID_DATA;
+
+typedef struct _rvf_tm_attrib {					
+	T_RVF_G_ADDR_ID		host_addr_id;		
+	UINT8				legacyFlag;
+	void*				action;
+} T_RVF_TM_ATTRIB;
+
+typedef NU_TIMER T_RV_TM;
+
+typedef union _rvf_tm_ublk {					
+	T_RV_TM*		ptr;		
+	UINT32			id;
+	
+} T_RVF_TM_UBLK;
+
+typedef union _rvf_tm_attib {
+	char				str[8];
+	T_RVF_TM_ATTRIB		attrib;
+} T_RVF_TM_ATTRIB_UBLK;
+
+typedef union _rvf_tm_action {
+	UINT32				action_id;
+	void*				p_action;
+} T_RVF_TM_ACTION_UBLK;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+T_RVF_RET	rvf_send_priority_msg	(T_RVF_G_ADDR_ID addr_id, void *msg) ;
+T_RVF_RET	rvf_adapt_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox) ;
+
+void		rvf_yield();
+
+void		rvf_mbox_buffer_init(T_RVF_RT_ADDR_ID_DATA* pRtAddrIdElement);
+void		_rvf_buffer_init (void);
+void		_rvf_timers_init(void);
+T_RVF_RET	rvf_get_available_mem( UINT32 * total_size, UINT32 * used_size );
+T_RV_RET	_rvf_empty_mailboxes (T_RVF_G_ADDR_ID task_id);
+
+void		_rvf_init_mem_pool(void);
+void		_rvf_init_free_queue (UINT8 id, UINT32 size, void *p_mem);
+UINT16		_rvf_get_mem_usage_ratio(void);
+UINT16		_rvf_get_number_of_pool(void);
+#ifdef		_WINDOWS
+  void		_rvf_window_dump_mem(void *m);
+#endif
+
+
+T_RVF_RET		rvf_free_sys_resources(T_RVF_G_ADDR_ID gid, UINT8 rm);
+T_RVF_G_ADDR_ID	rvf_allocate_task_id(UINT8 isRealTask) ;   /* return should be changed to 16 or 32 bit val */
+T_RVF_RET		rvf_setRtAddrSweIndex(T_RVF_G_ADDR_ID id, UINT8 sweIndex);
+T_RVF_G_ADDR_ID	resolveHostAddrId(T_RVF_G_ADDR_ID id) ;
+T_RVF_RET		rvf_create_virtual_task(T_RV_RET (* handle_message)(T_RV_HDR * msg),
+										T_RV_RET (* handle_timer)(T_RV_HDR * msg),
+										T_RVF_G_ADDR_ID task_id, T_RVF_G_ADDR_ID host_task_id, char *taskname, UINT8 priority, UINT8 tcode) ;
+T_RVF_RET		rvf_register_t3_handlers (T_RVF_G_ADDR_ID task_id,
+								   T_RV_RET (* handle_message)(T_RV_HDR * msg),
+								   T_RV_RET (* handle_timer)(T_RV_HDR * msg) ) ;
+T_RVF_RET		rvf_create_host_task (T_RV_RET (* proxy)(void), T_RVF_G_ADDR_ID task_id, char *taskname, UINT8 *stack, UINT16 stacksize,\
+										 UINT8 priority, UINT8 tcode, UINT8 time_slicing, T_RVF_TASK_STATE suspend);
+T_RVF_RET		rvf_registerToHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID eid) ;
+T_RVF_RET		rvf_unregisterFromHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID pid) ;
+T_RVF_RET		rvf_setHostTaskStackPtr(T_RVF_G_ADDR_ID id, UINT8* pStack) ;
+
+T_RVF_G_ADDR_ID rvf_resolveHostingAddrId(T_RVM_GROUP_DIRECTIVE gd);
+T_RVF_RET		rvf_associateGrpToHost(T_RVF_G_ADDR_ID host_id, T_RVF_GD_ID gd_id);
+T_RVF_RET		rvf_isHostingTaskIdle(T_RVF_G_ADDR_ID id, UINT8* status);
+void			rvf_setRDV(T_RVF_G_ADDR_ID tid,T_RVF_G_ADDR_ID vid);
+
+/* Internal RVF data structures*/
+
+extern T_RVF_INTERNAL_BUF *OSTaskQFirst[1][1]; //MAX_RVF_TASKS][RVF_NUM_TASK_MBOX];
+extern T_RVF_INTERNAL_BUF *OSTaskQLast[1][1]; //[MAX_RVF_TASKS][RVF_NUM_TASK_MBOX];
+
+extern T_RVF_RT_ADDR_ID_DATA* pRtAddrIdTable[MAX_RVF_G_ADDR_ID];
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RVF_I_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_mem_pool.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,81 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_mem_pool.c                                              */
+/*                                                                          */
+/*  Function    this file contains the definition of main memory pool       */
+/*                                                                          */
+/*  Version		0.1															             */
+/*																			                   */
+/* 	Date       	Modification												          */
+/*  ------------------------------------									          */
+/*  06/08/02		Create														          */
+/*																			                   */
+/*	Author		Laurent Sollier (l-sollier@ti.com)						          */
+/*																			                   */
+/* (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#include "rvf/rvf_pool_size.h"
+#include "rvf/rvf_cust.h"
+
+/******** MEMORY POOLS ******************/
+/* Define the buffer pools */
+T_RVF_POOL _rvf_pools[RVF_NB_POOLS];
+
+
+/* allocated static buffer pools */
+UINT8 Buf0[RVF_POOL_0_SIZE];
+
+#if (RVF_NB_POOLS > 1)
+UINT8 Buf1[RVF_POOL_1_SIZE];
+#endif
+
+/*******************************************************************************
+**
+** Function         _rvf_init_mem_pool
+**
+** Description      This function is called to initialize the different memory
+**                  pool.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_init_mem_pool(void)
+{
+	/* initialize buffer pools */
+   _rvf_init_free_queue(0, RVF_POOL_0_SIZE, (UINT8 *)Buf0);
+
+#if (RVF_NB_POOLS > 1)
+   _rvf_init_free_queue(1, RVF_POOL_1_SIZE, (UINT8 *)Buf1);
+#endif
+}
+
+/*******************************************************************************
+**
+** Function         _rvf_get_mem_usage_ratio
+**
+** Description      This function is called to have the value of
+**                  RVF_MEM_USAGE_RATIO.
+**
+** Returns          The value of RVF_MEM_USAGE_RATIO (see details of this value
+**                  in rvf_pool_size.h)
+**
+*******************************************************************************/
+UINT16 _rvf_get_mem_usage_ratio(void)
+{
+   return RVF_MEM_USAGE_RATIO;
+}
+
+/*******************************************************************************
+**
+** Function         _rvf_get_number_of_pool
+**
+** Description      This function is called to have the number of memory pool.
+**
+** Returns          The number of available different pool
+**
+*******************************************************************************/
+UINT16 _rvf_get_number_of_pool(void)
+{
+   return RVF_NB_POOLS;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_msg.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,194 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_msg.c                                                */
+/*                                                                          */
+/*  Function    this file contains rvf message handling functions            */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  18-March-2002															*/
+/*																			*/
+/* (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#include "rvf/rvf_api.h"
+#include "rvf/rvf_i.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rvm/rvm_api.h"	// RVM_TMS_MSG & RVM_MSG_OFFSET
+
+// PRIVATE
+static const UINT8	BOUNDBUFVAL=20; 
+T_RVF_RET _send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox, UINT8 bindbuf);
+
+/*******************************************************************************
+**
+** Function         rvf_get_msg_buf
+**
+** Description      Request for a message buffer.  
+**					Automatically update the message id of the buffer
+**
+**
+** Returns          T_RVF_MB_STATUS:	RVF_GREEN if everything is ok,
+**										RVF_YELLOW if watermark limit has been reached,
+**										RVF_RED if max size has been reached (does not return a buffer)
+**
+*******************************************************************************/
+T_RVF_MB_STATUS rvf_get_msg_buf(T_RVF_MB_ID mb_id,
+								UINT32 message_size,
+								T_RVF_MSG_ID msg_id,
+								T_RVF_MSG ** pp_msg)
+{
+
+	T_RVF_MB_STATUS mb_status;
+
+
+	mb_status = rvf_get_buf(mb_id,message_size,(T_RVF_BUFFER**) pp_msg);
+
+	if (mb_status != RVF_RED)
+	{
+		(*pp_msg)->msg_id = msg_id;
+	}
+
+	return mb_status;
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_fre_msg
+**
+** Description      Deallocate a message buffer
+**
+**
+** Returns          T_RVF_RET:	T_RVF_OK if succesful,...
+**
+*******************************************************************************/
+T_RVF_RET rvf_free_msg(T_RVF_MSG *p_msg)
+{
+	return rvf_free_buf( (T_RVF_BUFFER *)  p_msg);
+}
+
+T_RVF_RET rvf_free_timer_msg(T_RVF_MSG *p_msg)
+{
+	return rvf_free_buf( (T_RVF_BUFFER *)  p_msg);
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_send_msg
+**
+** Description      Called by applications to send a buffer to a SWE.
+**
+** Returns			RVF_OK if successful, else an error code.
+**
+** Comments			Priority is defined the inverse of NU. for legacy reasons
+*******************************************************************************/
+T_RVF_RET rvf_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg) {
+	return _send_msg ( addr_id, msg, 0, FALSE);
+}
+
+T_RVF_RET rvf_send_priority_msg (T_RVF_G_ADDR_ID addr_id, void *msg) {
+	return _send_msg ( addr_id, msg, 1, TRUE);
+}
+
+T_RVF_RET _send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox, UINT8 bindbuf) {
+    T_RVF_INTERNAL_BUF    *p_hdr;
+	T_RVF_INTERNAL_BUF*	cur=NULL;
+	UINT8 i=0;   
+	T_RVF_G_ADDR_ID tid=RVF_INVALID_ADDR_ID;
+
+    /* If task non-existant or not started, drop buffer */
+    if ((addr_id >= MAX_RVF_G_ADDR_ID)) {
+        rvf_send_trace( "RVF: rvf_send_msg(): invalid taskid", 35, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        rvf_free_buf (msg);
+        return RVF_INVALID_PARAMETER;
+    }
+	if((tid=resolveHostAddrId(addr_id))==RVF_INVALID_ADDR_ID) {
+		rvf_free_buf (msg);
+		return RVF_INTERNAL_ERR;
+	}
+	if(!pRtAddrIdTable[tid]) {
+		rvf_free_buf (msg);
+		return RVF_INTERNAL_ERR;
+	}
+
+	// Reject all msg or only continuous tm msg if bound buf limit
+	if(bindbuf) {
+		for(i=0, cur=pRtAddrIdTable[tid]->OSTaskQFirst[mbox];
+				 cur && cur->p_next; cur=cur->p_next, i++) ;
+		if(((T_RV_HDR*)msg)->msg_id==RVM_TMS_MSG) {
+			if(i>=BOUNDBUFVAL && ((T_RVF_TMS_MSG*)msg)->cont) {
+				rvf_free_buf(msg);
+				return RVF_MEMORY_ERR;
+			}
+		} else {
+			if(i>=BOUNDBUFVAL) {
+				rvf_free_buf(msg);
+				return RVF_MEMORY_ERR;
+			}
+		}
+	}
+
+#if RVF_ENABLE_BUF_CORRUPTION_CHECK	
+	/* check for buffer corruption */
+	if (_rvf_chk_buf_damage(msg) == TRUE)
+    {	rvf_send_trace( "RVF: rvf_send_msg(): buffer corrupted", 37, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+	}
+#endif
+
+	/* update the addr_id field of the message */
+	((T_RV_HDR *)msg)->dest_addr_id = addr_id;
+	p_hdr = USER2MEM(msg);
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+    /* check if the buffer has been already enqueued */
+	if ( RVF_BUF_IS_LINKED( p_hdr) )
+	{
+		rvf_send_trace( "RVF: rvf_send_msg(): buffer already enqueued", 44, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+        return RVF_MEMORY_ERR;
+    }
+#endif
+
+    rvf_disable(8);		/* enter critical section */
+
+	/* chained the buffer in the mailbox list */
+    /*if (OSTaskQFirst[task_id][mbox])	{
+		OSTaskQLast[task_id][mbox]->p_next = p_hdr;
+	} else {
+		OSTaskQFirst[task_id][mbox] = p_hdr;
+	}
+    OSTaskQLast[task_id][mbox] = p_hdr;
+	p_hdr->p_next = NULL;*/
+
+	if (pRtAddrIdTable[tid]->OSTaskQFirst[mbox]) {
+		pRtAddrIdTable[tid]->OSTaskQLast[mbox]->p_next = p_hdr;
+	} else	{	
+		pRtAddrIdTable[tid]->OSTaskQFirst[mbox] = p_hdr;
+	}
+    pRtAddrIdTable[tid]->OSTaskQLast[mbox] = p_hdr;
+
+	p_hdr->p_next = NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+	RVF_SET_BUF_LINKED(p_hdr);	/* change buffer status */
+#endif
+
+    rvf_enable(); 
+
+	/* send a rvf event  */
+    rvf_send_event(tid, (UINT16) (EVENT_MASK(mbox)) );
+
+	return RVF_OK;
+}
+
+// Poss. Deprecate ! [Only used by: rvf.Buffer::_rvf_send_msg_to_mbox() ]
+// May conflict with "msg::rvf_send_priority_msg()"
+T_RVF_RET rvf_adapt_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox) {
+	return _send_msg ( addr_id, msg, mbox, FALSE); 
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,761 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_pool_size.h                                             */
+/*                                                                          */
+/*  Function    this file contains definitions for buffer pool sizes        */
+/*                                                                          */
+/*                                                                          */
+/*                                                                          */
+/*                                                                          */
+/*  Version     0.3                                                         */
+/*                                                                          */
+/*  Date        Modification                                                */
+/*  ------------------------------------                                    */
+/*  4/19/1999   Create                                                      */
+/*  10/27/1999  Remove declaration of ntohs, htons, ntohl, htonl            */
+/*              in order to avoid conflict with winsock.h                   */
+/*  12/23/1999  Add buffer and memory bank related definition               */
+/*  07/12/2000  Implement dynamic memory allocation.                        */
+/*  01/13/2002  Extracted buffer pool size info from rvf_target.h           */
+/*              to prevent useless full recompilation when those datas      */
+/*              are changed                                                 */
+/*  10/01/2002  Completely reworked in order to be modular                  */
+/*  07/08/2003  Rework                                                      */
+/*                                                                          */
+/*  Author      David Lamy-Charrier (dlamy@tif.ti.com)                      */
+/*                                                                          */
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef _RVF_POOL_SIZE_H
+#define _RVF_POOL_SIZE_H
+
+#ifndef _WINDOWS
+  #include "config/r2d.cfg"
+  #include "config/rv.cfg"
+  #include "config/debug.cfg"
+  #include "config/board.cfg"
+  #include "config/l1sw.cfg"
+  #include "config/swconfig.cfg"
+#endif
+
+#include "rv/rv_defined_swe.h"
+#include "config/mdc.cfg"
+
+
+/* 
+ * RPC SWE 
+ */
+#ifdef RVM_RPC_SWE
+  #include "widcomm/rpc/rpc_pool_size.h"
+  #define RVF_RPC_POOL_SIZE  (RPC_POOL_SIZE)
+#else
+  #define RVF_RPC_POOL_SIZE  (0)
+#endif
+
+/* 
+ * BTA SWE 
+ */
+#ifdef RVM_BTA_SWE
+  #include "widcomm/bta/bta_pool_size.h"
+  #define RVF_BTA_POOL_SIZE  (BTA_POOL_SIZE)
+#else
+  #define RVF_BTA_POOL_SIZE  (0)
+#endif
+
+/* 
+ * BTU SWE 
+ */
+#ifdef RVM_BTU_SWE
+  #include "widcomm/btu/btu_pool_size.h"
+  #define RVF_BTU_POOL_SIZE  (BTU_POOL_SIZE)
+#else
+  #define RVF_BTU_POOL_SIZE  (0)
+#endif
+
+/* 
+ * BTUI SWE
+ */
+#ifdef RVM_BTUI_SWE
+  #include "widcomm/btui/btui_pool_size.h"
+  #define RVF_BTUI_POOL_SIZE  (BTUI_POOL_SIZE)
+#else
+  #define RVF_BTUI_POOL_SIZE  (0)
+#endif
+
+/* 
+ * BTH SWE  
+ */
+#ifdef RVM_BTH_SWE
+  #include "widcomm/hci/pc/bth/bth_pool_size.h"
+  #define RVF_BTH_POOL_SIZE  (BTU_POOL_SIZE)
+#else
+  #define RVF_BTH_POOL_SIZE  (0)
+#endif
+
+/* 
+ * GKI SWE 
+ */
+#ifdef RVM_GKI_SWE
+  #include "widcomm/gki/gki_pool_size.h"
+  #define RVF_GKI_POOL_SIZE  (GKI_POOL_SIZE)
+#else
+  #define RVF_GKI_POOL_SIZE  (0)
+#endif
+
+/*
+ * HCI SWE
+ */
+#ifdef RVM_HCI_SWE
+  #include "widcomm/hci/hci_pool_size.h"
+  #define RVF_HCI_POOL_SIZE  (HCI_POOL_SIZE)
+#else
+  #define RVF_HCI_POOL_SIZE  (0)
+#endif
+
+
+
+/*
+ * ATP SWE
+ */
+#ifdef RVM_ATP_SWE
+  #include "atp/atp_pool_size.h"
+  #define RVF_ATP_POOL_SIZE (ATP_POOL_SIZE)
+#else
+  #define RVF_ATP_POOL_SIZE (0)
+#endif
+
+/*
+ * ATP_UART SWE
+ */
+#ifdef RVM_ATP_UART_SWE
+  #include "atp/atp_pool_size.h"
+  #define RVF_ATP_UART_POOL_SIZE  (ATP_UART_POOL_SIZE)
+#else
+  #define RVF_ATP_UART_POOL_SIZE  (0)
+#endif
+
+/*
+ * AUDIO SWE and background
+ */
+#ifdef RVM_AUDIO_MAIN_SWE
+  #include "audio/audio_pool_size.h"
+  #define RVF_AUDIO_POOL_SIZE  (AUDIO_POOL_SIZE)
+#else
+  #define RVF_AUDIO_POOL_SIZE  (0)
+#endif
+
+#ifdef RVM_AUDIO_BGD_SWE
+  #include "audio/audio_pool_size.h"
+  #define RVF_AUDIO_BGD_POOL_SIZE  (AUDIO_BGD_POOL_SIZE)
+#else
+  #define RVF_AUDIO_BGD_POOL_SIZE  (0)
+#endif
+
+/*
+ * DAR SWE
+ */
+#ifdef RVM_DAR_SWE
+  #include "dar/dar_pool_size.h"
+  #define RVF_DAR_POOL_SIZE  (DAR_POOL_SIZE)
+#else
+  #define RVF_DAR_POOL_SIZE  (0)
+#endif
+
+/*
+ * ETM SWE
+ */
+#ifdef RVM_ETM_SWE
+  #include "etm/etm_pool_size.h"
+  #define RVF_ETM_POOL_SIZE  (ETM_POOL_SIZE)
+#else
+  #define RVF_ETM_POOL_SIZE  (0)
+#endif
+
+/*
+ * FFS SWE
+ */
+#ifdef RVM_FFS_SWE
+  #include "ffs/ffs_pool_size.h"
+  #define RVF_FFS_POOL_SIZE  (FFS_POOL_SIZE)
+#else
+  #define RVF_FFS_POOL_SIZE  (0)
+#endif
+
+
+/*
+ * KCL SWE
+ */
+#ifdef RVM_KCL_SWE
+  #include "j2me_k/kcl/kcl_pool_size.h"
+  #define RVF_KCL_POOL_SIZE (KCL_POOL_SIZE)
+#else
+  #define RVF_KCL_POOL_SIZE (0)
+#endif
+
+/*
+ * KGC SWE
+ */
+#ifdef RVM_KGC_SWE
+  #include "j2me_k/kgc/kgc_pool_size.h"
+  #define RVF_KGC_POOL_SIZE (KGC_POOL_SIZE)
+#else
+  #define RVF_KGC_POOL_SIZE (0)
+#endif
+
+/*
+ * KIL SWE
+ */
+#ifdef RVM_KIL_SWE
+  #include "j2me_k/kil/kil_pool_size.h"
+  #define RVF_KIL_POOL_SIZE (KIL_POOL_SIZE)
+#else
+  #define RVF_KIL_POOL_SIZE (0)
+#endif
+
+/*
+ * KMM SWE
+ */
+#ifdef RVM_KMM_SWE
+  #include "j2me_k/kmm/kmm_pool_size.h"
+  #define RVF_KMM_POOL_SIZE (KMM_POOL_SIZE)
+#else
+  #define RVF_KMM_POOL_SIZE (0)
+#endif
+
+/*
+ * KNM SWE
+ */
+#ifdef RVM_KNM_SWE
+  #include "j2me_k/knm/knm_pool_size.h"
+  #define RVF_KNM_POOL_SIZE (KNM_POOL_SIZE)
+#else
+  #define RVF_KNM_POOL_SIZE (0)
+#endif
+
+/*
+ * KPG SWE
+ */
+#ifdef RVM_KPG_SWE
+  #include "j2me_k/kpg/kpg_pool_size.h"
+  #define RVF_KPG_POOL_SIZE (KPG_POOL_SIZE)
+#else
+  #define RVF_KPG_POOL_SIZE (0)
+#endif
+
+/*
+ * KZP SWE
+ */
+#ifdef RVM_KZP_SWE
+  #include "j2me_k/kzp/kzp_pool_size.h"
+  #define RVF_KZP_POOL_SIZE (KZP_POOL_SIZE)
+#else
+  #define RVF_KZP_POOL_SIZE (0)
+#endif
+
+
+/*
+ * KPD SWE
+ */
+#ifdef RVM_KPD_SWE
+  #include "kpd/kpd_pool_size.h"
+  #define RVF_KPD_POOL_SIZE  (KPD_POOL_SIZE)
+#else
+  #define RVF_KPD_POOL_SIZE  (0)
+#endif
+
+   
+/*
+ * LLS SWE
+ */
+#ifdef RVM_LLS_SWE
+  #include "lls/lls_pool_size.h"
+  #define RVF_LLS_POOL_SIZE (LLS_POOL_SIZE)
+#else
+  #define RVF_LLS_POOL_SIZE (0)
+#endif
+
+/*
+ * MKS SWE
+ */
+#ifdef RVM_MKS_SWE
+  #include "mks/mks_pool_size.h"
+  #define RVF_MKS_POOL_SIZE  (MKS_POOL_SIZE)
+#else
+  #define RVF_MKS_POOL_SIZE  (0)
+#endif
+
+/*
+ * MPM SWE
+ */
+#ifdef RVM_MPM_SWE
+  #include "mpm/mpm_pool_size.h"
+  #define RVF_MPM_POOL_SIZE  (MPM_POOL_SIZE)
+#else
+  #define RVF_MPM_POOL_SIZE  (0)
+#endif
+
+/*
+ * PWR SWE
+ */
+#ifdef RVM_PWR_SWE
+  #include "pwr/pwr_pool_size.h"
+  #define RVF_PWR_POOL_SIZE (PWR_POOL_SIZE)
+#else
+  #define RVF_PWR_POOL_SIZE (0)
+#endif
+
+/*
+ * LCC (PWR) SWE
+ */
+
+#ifdef RVM_LCC_SWE
+  #include "lcc/lcc_pool_size.h"
+  #define RVF_LCC_POOL_SIZE (LCC_POOL_SIZE)
+#else
+  #define RVF_LCC_POOL_SIZE (0)
+#endif
+
+/*
+ * R2D SWE
+ */
+#ifdef RVM_R2D_SWE
+  #include "r2d/r2d_pool_size.h"
+  #define RVF_R2D_POOL_SIZE    (R2D_POOL_SIZE)
+#else
+  #define RVF_R2D_POOL_SIZE    (0)
+#endif
+
+/*
+ * RGUI SWE
+ */
+#ifdef RVM_RGUI_SWE
+  #include "rgui/rgui_pool_size.h"
+  #define RVF_RGUI_POOL_SIZE  (RGUI_POOL_SIZE)
+#else
+  #define RVF_RGUI_POOL_SIZE  (0)
+#endif
+
+
+/*
+ * RNET SWE
+ */
+#ifdef RVM_RNET_SWE
+  #include "rnet/rnet_pool_size.h"
+  #define RVF_RNET_POOL_SIZE (RNET_POOL_SIZE)
+#else
+  #define RVF_RNET_POOL_SIZE (0)
+#endif
+
+/*
+ * RNET_BR SWE
+ */
+#ifdef RVM_RNET_BR_SWE
+  #include "rnet/rnet_br/rnet_br_pool_size.h"
+  #define RVF_RNET_BR_POOL_SIZE (RNET_BR_POOL_SIZE)
+#else
+  #define RVF_RNET_BR_POOL_SIZE (0)
+#endif
+
+/*
+ * RNET_RT SWE
+ */
+#ifdef RVM_RNET_RT_SWE
+  #include "rnet/rnet_rt/rnet_rt_pool_size.h"
+  #define RVF_RNET_RT_POOL_SIZE  (RNET_RT_POOL_SIZE)
+#else
+  #define RVF_RNET_RT_POOL_SIZE  (0)
+#endif
+
+/*
+ * RNET_WS SWE
+ */
+#ifdef RVM_RNET_WS_SWE
+  #include "rnet/rnet_ws/rnet_ws_pool_size.h"
+  #define RVF_RNET_WS_POOL_SIZE  (RNET_WS_POOL_SIZE)
+#else
+  #define RVF_RNET_WS_POOL_SIZE  (0)
+#endif
+
+
+/*
+ * DCM SWE
+ */
+#ifdef RVM_DCM_SWE
+  #include "dcm/dcm_pool_size.h"
+  #define RVF_DCM_POOL_SIZE  (DCM_POOL_SIZE)
+#else
+  #define RVF_DCM_POOL_SIZE  (0)
+#endif
+
+/*
+ * DCFG SWE
+ */
+
+#ifdef RVM_DCFG_SWE
+  #include "dcfg/dcfg_pool_size.h"
+  #define RVF_DCFG_POOL_SIZE  (DCFG_POOL_SIZE)
+#else
+  #define RVF_DCFG_POOL_SIZE  (0)
+#endif
+
+/*
+ * RTC SWE
+ */
+#ifdef RVM_RTC_SWE
+  #include "rtc/rtc_pool_size.h"
+  #define RVF_RTC_POOL_SIZE  (RTC_POOL_SIZE)
+#else
+  #define RVF_RTC_POOL_SIZE  (0)
+#endif
+
+/*
+ * RTEST SWE
+ */
+#ifdef RVM_RTEST_SWE
+  #include "tests/rtest/rtest_pool_size.h"
+  #define RVF_RTEST_POOL_SIZE  (RTEST_POOL_SIZE)
+#else
+  #define RVF_RTEST_POOL_SIZE  (0)
+#endif
+
+/*
+ * RVM SWE; This SWE is of course always enabled.
+ * TO CLEAN??
+ */
+#include "rvm/rvm_pool_size.h"
+
+
+/*
+ * SPI SWE
+ */
+#ifdef RVM_SPI_SWE
+  #include "spi/spi_pool_size.h"
+  #define RVF_SPI_POOL_SIZE  (SPI_POOL_SIZE)
+#else
+  #define RVF_SPI_POOL_SIZE  (0)
+#endif
+
+
+
+/*
+ * TI_PRF SWE
+ */
+#ifdef RVM_TI_PRF_SWE
+  #include "rvt/ti_profiler/ti_prf_pool_size.h"
+  #define RVF_TI_PRF_POOL_SIZE  (TI_PRF_POOL_SIZE)
+#else
+  #define RVF_TI_PRF_POOL_SIZE  (0)
+#endif
+
+/*
+ * TRACE SWE
+ */
+#ifdef RVM_RVT_SWE
+  #include "rvt/rvt_pool_size.h"
+  #define RVF_TRACE_POOL_SIZE  (TRACE_POOL_SIZE)
+#else
+  #define RVF_TRACE_POOL_SIZE  (0)
+#endif
+
+/*
+ * TUT SWE
+ */
+#ifdef RVM_TUT_SWE
+  #include "tut/tut_pool_size.h"
+  #define RVF_TUT_POOL_SIZE  (TUT_POOL_SIZE)
+#else
+  #define RVF_TUT_POOL_SIZE  (0)
+#endif
+
+/*
+ * UVM SWE
+ */
+#ifdef RVM_UVM_SWE
+  #include "j2me_k/uvm/uvm_pool_size.h"
+  #define RVF_UVM_POOL_SIZE  (UVM_POOL_SIZE)
+#else
+  #define RVF_UVM_POOL_SIZE  (0)
+#endif
+
+/*
+ * JTM SWE
+ */
+#ifdef RVM_JTM_SWE
+  #include "j2me_k/jtm/jtm_pool_size.h"
+  #define RVF_JTM_POOL_SIZE  (JTM_POOL_SIZE)
+#else
+  #define RVF_JTM_POOL_SIZE  (0)
+#endif
+
+/*
+ * MDC SWE
+ */
+#ifdef RVM_MDC_SWE
+  #include "mdc/mdc_pool_size.h"
+  #define RVF_MDC_POOL_SIZE  (MDC_POOL_SIZE)
+#else
+  #define RVF_MDC_POOL_SIZE  (0)
+#endif
+
+/*
+ * TTY SWE
+ */
+#ifdef RVM_TTY_SWE
+  #include "tty/tty_pool_size.h"
+  #define RVF_TTY_POOL_SIZE  (TTY_POOL_SIZE)
+#else
+  #define RVF_TTY_POOL_SIZE  (0)
+#endif
+
+
+/*
+ * Obigo SWEs
+ */
+/* BRAE SWE */
+#ifdef RVM_BRAE_SWE
+  #include "obigo/brae/brae_pool_size.h"
+  #define RVF_BRAE_POOL_SIZE  BRAE_POOL_SIZE
+#else
+  #define RVF_BRAE_POOL_SIZE  (0)
+#endif
+/* BRSE SWE */
+#ifdef RVM_BRSE_SWE
+  #include "obigo/brse/brse_pool_size.h"
+  #define RVF_BRSE_POOL_SIZE  BRSE_POOL_SIZE
+#else
+  #define RVF_BRSE_POOL_SIZE  (0)
+#endif
+
+/* UISE SWE */
+#ifdef RVM_UISE_SWE
+  #include "obigo/uise/uise_pool_size.h"
+  #define RVF_UISE_POOL_SIZE  UISE_POOL_SIZE
+#else
+  #define RVF_UISE_POOL_SIZE  (0)
+#endif
+
+/* UIAE SWE */
+#ifdef RVM_UIAE_SWE
+  #include "obigo/uiae/uiae_pool_size.h"
+  #define RVF_UIAE_POOL_SIZE  UIAE_POOL_SIZE
+#else
+  #define RVF_UIAE_POOL_SIZE  (0)
+#endif
+
+/* MEAE SWE */
+#ifdef RVM_MEAE_SWE
+  #include "obigo/meae/meae_pool_size.h"
+  #define RVF_MEAE_POOL_SIZE  MEAE_POOL_SIZE
+#else
+  #define RVF_MEAE_POOL_SIZE  (0)
+#endif
+/* MMSE SWE */
+#ifdef RVM_MMSE_SWE
+  #include "obigo/mmse/mmse_pool_size.h"
+  #define RVF_MMSE_POOL_SIZE  MMSE_POOL_SIZE
+#else
+  #define RVF_MMSE_POOL_SIZE  (0)
+#endif
+/* MSFE SWE */
+#ifdef RVM_MSFE_SWE
+  #include "obigo/msfe/msfe_pool_size.h"
+  #define RVF_MSFE_POOL_SIZE  MSFE_POOL_SIZE
+#else
+  #define RVF_MSFE_POOL_SIZE  (0)
+#endif
+/* MSME SWE */
+#ifdef RVM_MSME_SWE
+  #include "obigo/msme/msme_pool_size.h"
+  #define RVF_MSME_POOL_SIZE  MSME_POOL_SIZE
+#else
+  #define RVF_MSME_POOL_SIZE  (0)
+#endif
+/* PHSE SWE */
+#ifdef RVM_PHSE_SWE
+  #include "obigo/phse/phse_pool_size.h"
+  #define RVF_PHSE_POOL_SIZE  PHSE_POOL_SIZE
+#else
+  #define RVF_PHSE_POOL_SIZE  (0)
+#endif
+/* PRSE SWE */
+#ifdef RVM_PRSE_SWE
+  #include "obigo/prse/prse_pool_size.h"
+  #define RVF_PRSE_POOL_SIZE  PRSE_POOL_SIZE
+#else
+  #define RVF_PRSE_POOL_SIZE  (0)
+#endif
+/* SECE SWE */
+#ifdef RVM_SECE_SWE
+  #include "obigo/sece/sece_pool_size.h"
+  #define RVF_SECE_POOL_SIZE  SECE_POOL_SIZE
+#else
+  #define RVF_SECE_POOL_SIZE  (0)
+#endif
+/* SELE SWE */
+#ifdef RVM_SELE_SWE
+  #include "obigo/sele/sele_pool_size.h"
+  #define RVF_SELE_POOL_SIZE  SELE_POOL_SIZE
+#else
+  #define RVF_SELE_POOL_SIZE  (0)
+#endif
+/* SLSE SWE */
+#ifdef RVM_SLSE_SWE
+  #include "obigo/slse/slse_pool_size.h"
+  #define RVF_SLSE_POOL_SIZE  SLSE_POOL_SIZE
+#else
+  #define RVF_SLSE_POOL_SIZE  (0)
+#endif
+/* SMAE SWE */
+#ifdef RVM_SMAE_SWE
+  #include "obigo/smae/smae_pool_size.h"
+  #define RVF_SMAE_POOL_SIZE  SMAE_POOL_SIZE
+#else
+  #define RVF_SMAE_POOL_SIZE  (0)
+#endif
+/* STKE SWE */
+#ifdef RVM_STKE_SWE
+  #include "obigo/stke/stke_pool_size.h"
+  #define RVF_STKE_POOL_SIZE  STKE_POOL_SIZE
+#else
+  #define RVF_STKE_POOL_SIZE  (0)
+#endif
+/* EMAE SWE */
+#ifdef RVM_EMAE_SWE
+  #include "obigo/emae/emae_pool_size.h"
+  #define RVF_EMAE_POOL_SIZE  EMAE_POOL_SIZE
+#else
+  #define RVF_EMAE_POOL_SIZE  (0)
+#endif
+/* EMSE SWE */
+#ifdef RVM_EMSE_SWE
+  #include "obigo/emse/emse_pool_size.h"
+  #define RVF_EMSE_POOL_SIZE  EMSE_POOL_SIZE
+#else
+  #define RVF_EMSE_POOL_SIZE  (0)
+#endif
+
+/* IT0E SWE */
+#ifdef RVM_IT0E_SWE
+  #include "obigo/tests/it0e/it0e_pool_size.h"
+  #define RVF_IT0E_POOL_SIZE  IT0E_POOL_SIZE
+#else
+  #define RVF_IT0E_POOL_SIZE  (0)
+#endif
+/* IT1E SWE */
+#ifdef RVM_IT1E_SWE
+  #include "obigo/tests/it1e/it1e_pool_size.h"
+  #define RVF_IT1E_POOL_SIZE  IT1E_POOL_SIZE
+#else
+  #define RVF_IT1E_POOL_SIZE  (0)
+#endif
+/* IT2E SWE */
+#ifdef RVM_IT2E_SWE
+  #include "obigo/tests/it2e/it2e_pool_size.h"
+  #define RVF_IT2E_POOL_SIZE  IT2E_POOL_SIZE
+#else
+  #define RVF_IT2E_POOL_SIZE  (0)
+#endif
+
+
+/* 
+ * MFW SWE
+ */
+#ifdef RVM_MFW_SWE
+  #include "mfw/mfw_pool_size.h"
+  #define RVF_MFW_POOL_SIZE  (MFW_POOL_SIZE)
+#else
+  #define RVF_MFW_POOL_SIZE  (0)
+#endif
+
+/*
+ * IMG SWE
+ */
+#ifdef RVM_IMG_SWE
+  #include "img/img_pool_size.h"
+  #define RVF_IMG_POOL_SIZE  IMG_POOL_SIZE
+#else
+  #define RVF_IMG_POOL_SIZE  (0)
+#endif
+
+/*
+MMS
+//TISHMMS Project add 10K for buffer mms message 
+*/
+#ifdef RVM_MMS_SWE
+  /*
+   * Values used in mms_env.h
+   */
+   #include "mms/mms_pool_size.h"
+
+  #define RVF_MMS_POOL_SIZE  MMS_POOL_SIZE
+#else
+  #define RVF_MMS_POOL_SIZE  (0)
+#endif
+
+/* 
+ * SMBS SWE
+ */
+#ifdef RVM_SMBS_SWE
+  #include "smbs/smbs_pool_size.h"
+  #define RVF_SMBS_POOL_SIZE  (SMBS_POOL_SIZE)
+#else
+  #define RVF_SMBS_POOL_SIZE  (0)
+#endif
+
+/* 
+ * MDL SWE
+ */
+#ifdef RVM_MDL_SWE
+  #include "mdl/mdl_pool_size.h"
+  #define RVF_MDL_POOL_SIZE  (MDL_POOL_SIZE)
+#else
+  #define RVF_MDL_POOL_SIZE  (0)
+#endif
+
+
+
+/* define the memory pools used by the RVF */
+
+/* define RVF_NB_POOLS to 1 or 2 if you want to use 2 buffers in RAM,
+for example 1 in internal RAM, 1 in external RAM */
+#define RVF_NB_POOLS            1
+/* 500 corresponds to a "hard-coded" value for RVM_STACKS Memory Bank defined in rvm_i.h */
+#define RVF_POOL_0_SIZE (RVF_ATP_POOL_SIZE     + RVF_ATP_UART_POOL_SIZE + RVF_AUDIO_POOL_SIZE     + \
+                         RVF_DAR_POOL_SIZE     + RVF_HCI_POOL_SIZE      + RVF_ETM_POOL_SIZE       + \
+                         RVF_FFS_POOL_SIZE     + RVF_KCL_POOL_SIZE      + RVF_KGC_POOL_SIZE       + \
+                         RVF_KIL_POOL_SIZE     + RVF_KMM_POOL_SIZE      + RVF_KNM_POOL_SIZE       + \
+                         RVF_KPD_POOL_SIZE     + RVF_KPG_POOL_SIZE      + RVF_KZP_POOL_SIZE       + \
+                         RVF_LLS_POOL_SIZE     + RVF_MKS_POOL_SIZE      + RVF_TTY_POOL_SIZE       + \
+                         RVF_MPM_POOL_SIZE     + RVF_PWR_POOL_SIZE      + RVF_LCC_POOL_SIZE       + \
+                         RVF_R2D_POOL_SIZE + RVF_MMS_POOL_SIZE +\
+                         RVF_RGUI_POOL_SIZE    + RVF_RNET_POOL_SIZE     + RVF_RNET_BR_POOL_SIZE   + \
+                         RVF_MDC_POOL_SIZE     + RVF_RNET_RT_POOL_SIZE  + RVF_RNET_WS_POOL_SIZE   + \
+                         RVF_RTC_POOL_SIZE     + RVF_RTEST_POOL_SIZE    + RVF_RVM_POOL_SIZE       + \
+                         RVF_SPI_POOL_SIZE     + RVF_TI_PRF_POOL_SIZE   + RVF_TRACE_POOL_SIZE     + \
+                         RVF_TUT_POOL_SIZE     + RVF_UVM_POOL_SIZE      + RVF_JTM_POOL_SIZE       + \
+                         RVF_DCM_POOL_SIZE     + RVF_BRAE_POOL_SIZE     + RVF_BRSE_POOL_SIZE      + \
+                         RVF_UISE_POOL_SIZE    + RVF_UIAE_POOL_SIZE     + RVF_MEAE_POOL_SIZE      + \
+                         RVF_MMSE_POOL_SIZE                                                       + \
+                         RVF_MSFE_POOL_SIZE    + RVF_MSME_POOL_SIZE     + RVF_PHSE_POOL_SIZE      + \
+                         RVF_PRSE_POOL_SIZE    + RVF_SECE_POOL_SIZE     + RVF_SELE_POOL_SIZE      + \
+                         RVF_SLSE_POOL_SIZE    + RVF_SMAE_POOL_SIZE     + RVF_STKE_POOL_SIZE      + \
+                         RVF_IT0E_POOL_SIZE    + RVF_EMAE_POOL_SIZE     + RVF_EMSE_POOL_SIZE      + \
+                         RVF_IT1E_POOL_SIZE    + RVF_IT2E_POOL_SIZE     + RVF_IMG_POOL_SIZE       + \
+                         RVF_SMBS_POOL_SIZE    + RVF_MFW_POOL_SIZE      + RVF_AUDIO_BGD_POOL_SIZE + \
+                         RVF_BTA_POOL_SIZE     + RVF_BTU_POOL_SIZE      + RVF_GKI_POOL_SIZE       + \
+                         RVF_BTUI_POOL_SIZE    + RVF_BTH_POOL_SIZE      + RVF_RPC_POOL_SIZE       + \
+                         RVF_DCFG_POOL_SIZE    + RVF_MDL_POOL_SIZE)
+
+#if (RVF_NB_POOLS > 1 )
+    #define RVF_POOL_1_SIZE     0
+#endif
+
+/* define the memory usage ratio */
+/* e.g. the ratio between the sum of the memory banks sizes and the memory available in the system */
+/* for example: 90 for 90 % to be sure to always satisfy memory requests*/
+/*              120 for 120 % to optimize memory usage */
+#define RVF_MEM_USAGE_RATIO     100
+
+#endif /* _RVF_POOL_SIZE_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_target.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,143 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_target.h                                                */
+/*                                                                          */
+/*  Function    this file contains definitions that will probably			*/
+/*              change for each target system. This includes				*/
+/*              such things number of tasks,			                    */
+/*              little endian/big endian conversions, etc...				*/
+/*																			*/
+/*                                                                          */
+/*	NOTE        This file should always be included first.					*/
+/*																			*/
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  4/19/1999	Create														*/
+/*  10/27/1999  remove declaration of ntohs, htons, ntohl, htonl			*/
+/*				in order to avoid conflict with winsock.h					*/
+/*  12/23/1999	add buffer and memory bank related definition				*/
+/*  07/12/2000	implement dynamic memory allocation.						*/
+/*  01/16/2004  Corrected conversion from seconds/milliseconds to ticks.    */
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+#ifndef _RVF_TARGET_H
+#define _RVF_TARGET_H
+
+#ifndef _WINDOWS
+	#include "config/rv.cfg"
+	#include "config/swconfig.cfg"
+#endif
+
+
+/* optimizations */
+#ifdef _WINDOWS
+	#define INLINE __inline
+#else
+	#define INLINE inline
+#endif
+
+
+/*----------------------------------------------------------------------*/
+/*                      RVF Definitions                                 */
+/*----------------------------------------------------------------------*/
+
+
+/* the maximum number of memory bank created by users */
+#if (!GSMLITE)
+#define RVF_MAX_TOTAL_MB			70
+#else // GSMLITE
+  #define RVF_MAX_TOTAL_MB			20
+#endif // GSMLITE
+
+/* the maximum number of real memory bank managed */
+#if (!GSMLITE)
+#define RVF_MAX_REAL_MB				60
+#else // GSMLITE
+  #define RVF_MAX_REAL_MB			20
+#endif // GSMLITE
+
+/* max length of memory bank name */
+#define RVF_MAX_MB_LEN				10
+
+/* max length of task name */
+#define RVF_MAX_TASK_LEN			10
+
+
+/* RVF_MB_MAPPING defines the correspondance between mb_name and mb_id */
+/* WARNING!!!! When adding new memory banks in this default list, take care */
+/* to always finish with the {0,0} !!! */
+#if (!GSMLITE)
+#define RVF_MB_MAPPING {{ "RVM_PRIM", 0},{ "TEST1", 1}, { "TEST2", 2},\
+	{ "TEST3", 3}, { "TEST4", 3},\
+	{"HCI_RX", 4},{"HCI_TX", 5},\
+	{"ATP_PRIM",27},{"ATP_UART",27},\
+	{"RV_TRACE", TRACE_MB_ID},\
+	{"UWIRE_PRIM",37},{0,0}}
+#else // GSMLITE
+  #define RVF_MB_MAPPING {{ "RVM_PRIM", 0},{ "TEST1", 1}, { "TEST2", 2},\
+						  { "TEST3", 3}, { "TEST4", 3}, {0,0}}
+#endif // GSMLITE
+
+/* set the following variable to 1 to check for buffer corruption*/
+#define RVF_ENABLE_BUF_CORRUPTION_CHECK	1
+
+/* set the following variable to 1 to check for buffer linkage*/
+#define RVF_ENABLE_BUF_LINKAGE_CHECK	1
+
+/* enable or disable memory statistics functions */
+#define RVF_ENABLE_STATS				1	
+
+
+/* The maximum number of RVF tasks allowed in the system*/
+#if (!GSMLITE)
+#define MAX_RVF_TASKS	            30
+#else // GSMLITE
+  #define MAX_RVF_TASKS	            11
+#endif // GSMLITE
+
+/* max number of callback functions for buffers waiting to be counted on another memory bank */
+#if (!GSMLITE)
+#define RVF_MAX_WAITING_BUF		300 
+#else // GSMLITE
+  #define RVF_MAX_WAITING_BUF		 20 
+#endif // GSMLITE
+/* sum of RVF_BUFi_MAX */
+
+
+
+
+
+
+
+/***********************************************************************
+** Timer related definitions. These should be edited per system. The
+** macros should convert milliseconds and seconds to system ticks.
+** Applications should use these to calculate the number of ticks to
+** sleep for.
+*/
+
+#ifdef _WINDOWS
+#define RVF_MS_TO_TICKS(_x)   ((_x) / 50)
+#define RVF_SECS_TO_TICKS(_x) (((_x) * 1000) / 50)
+#define RVF_TICKS_TO_MS(_x)   ((_x) * 50)
+#else
+/*
+ * To avoid floating point computation, the tick duration 4.615 ms can be
+ * resolved to the fraction : 923/200.
+ *
+ * Due to the multiplication with 200, the maximum usable value for
+ * milliseconds is 2^32 / 200 = 21,474,836. The maximum usable value
+ * for seconds is 2^32 / (200 * 1000) = 21,474.
+ * Both values correspond approximately to 5h 57m 54s.
+ */
+#define RVF_MS_TO_TICKS(_x)   ((((_x) * 200) + 462) / 923) 
+#define RVF_SECS_TO_TICKS(_x) ((((_x) * 1000 * 200) + 462) / 923)
+#define RVF_TICKS_TO_MS(_x)   ((((_x) * 923) + 100) / 200)
+#endif
+
+#endif /* _RVF_TARGET_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_task.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,1174 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_task.c                                                  */
+/*                                                                          */
+/*  Function    this file contains \rvf task related functions               */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  3/12/99		Create														*/
+/*	10/27/99	remove all non-nucleus sections (#ifdef)					*/
+/*				change tasks priority and time_slicing						*/	
+/*  11/17/1999	change RVF_create_task and RVF_get_taskid functions         */
+/*	30/11/99	compliant to RV coding guidelines							*/
+/*  28/08/2000	add mutex related functions.								*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef _WINDOWS
+	#include "config/rv.cfg"
+#endif
+
+#include "nucleus.h" 
+
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvf/rvf_i.h"			
+#include "rvm/rvm_i.h"	 /* ONLY for Task Codes */
+#include "rvm/rvm_use_id_list.h"
+#include <stdio.h>
+#include <string.h>
+
+/* include the rvtool_trace.h file only in the RivieraTool */
+#ifdef	_WINDOWS
+#ifndef	_CONSOLE
+//		#include "rvtool_trace.h"
+	#endif
+	#include <windows.h>
+#endif
+
+#define RVF_STATIC_ALLOC_NB	1
+
+/**********************************************************************
+** Nucleus specific definitions
+*/
+
+typedef void (*NU_TASK_ENTRY)(UNSIGNED, VOID *);  //
+
+/* array of tasks */
+/**********************************************************************
+* Note: if dynamic mem alloc of "pOSTCB" creates too much fragentation
+* The origianl way me be utilised and pointed to by a addr_id table 
+* structure, which is proposed for type 2 support.
+***********************************************************************/
+
+#define _RALLOC_TASK_CNTRL_BLK(tb)		rvf_get_buf(rvm_sys_mem_bank, sizeof(NU_TASK), tb)
+#define	_RALLOC_TASK_EVT_GRP(tb)		rvf_get_buf(rvm_sys_mem_bank, sizeof(NU_EVENT_GROUP), tb)
+#define _RALLOC_TASK_RT_ADDR_DATA(tb)	rvf_get_buf(rvm_sys_mem_bank, sizeof(T_RVF_RT_ADDR_ID_DATA), tb)
+//#define _RALLOC_TASK_RT_TM(tb)			rvf_get_buf(rvm_sys_mem_bank, sizeof(T_RVF_TIMER_LIST_Q), tb)
+
+/*static NU_TASK			bOSTCB[RVF_STATIC_ALLOC_NB];			 
+static NU_EVENT_GROUP	bOSEvtGrp[RVF_STATIC_ALLOC_NB];			 
+static UINT8			*bOSStack;
+static UINT16			bOSStackSize;
+static char				bOSTName[RVF_STATIC_ALLOC_NB][RVF_STATIC_ALLOC_NB];
+*/
+
+static UINT8	task_counter = 0;	
+static INT16	OSDisableNesting = 0;
+static BOOL		OSInterruptAlreadyMasked = FALSE;
+static INT32    OSLastIntLevel;
+static T_RVF_G_ADDR_ID _RDV=RVF_INVALID_ADDR_ID;
+
+T_RVF_RET		_initSysRtData(void);
+
+
+/*******************************************************************************
+**
+** Function         rvf_AllocTaskXyz()
+**
+** Description      
+**                  
+**
+** Returns          T_RVF_MB_STATUS
+**
+*******************************************************************************/
+T_RVF_RET _initSysRtData(void) {    /*A-M-E-N-D-E-D!*/
+	int i=0;
+
+	for (i=0; i < MAX_RVF_G_ADDR_ID; i++) pRtAddrIdTable[i]=NULL;
+
+	//	pOSTCB[0]=&OSTCB[0];
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_init
+**
+** Description      This function is called once at startup to initialize
+**                  all the rvf (timer, buffer...).
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_init(void) {
+	/* UINT8   i;	*/
+
+    /* Initialize RVF variables */
+    /*for (i = 0; i < MAX_RVF_TASKS; i++) {
+        OSStack[i] = 0;
+        OSStackSize[i] = 0;
+        OSTName[i][0] = 0;
+		memset( &OSTCB[i],		0, sizeof(NU_TASK) );
+		memset( &OSEvtGrp[i],	0, sizeof(NU_EVENT_GROUP) );
+    }
+	//	for (i = 0; i < 1; i++) memset( &OSTCB[i], 0, sizeof(NU_TASK) );
+	*/
+	_initSysRtData();
+	_rvf_buffer_init();
+	_rvf_timers_init();
+}
+
+/*******************************************************************************
+**
+** Function         _rvf_name_cpy
+**
+** Description      Internal function which copy a string in a buffer.
+**                  The string may be null-terminated or length bytes long.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_name_cpy(char * dest, char * source, UINT8 length) {	
+	UINT8 cpt;
+	for( cpt = 0; cpt < length ; cpt++) {
+		dest[cpt] = source[cpt];
+		if (source[cpt] == 0) {	return;}
+	}
+}
+
+T_RVF_G_ADDR_ID rvf_get_context() {
+	T_RVF_G_ADDR_ID gid=rvf_get_taskid();
+	if(pRtAddrIdTable[gid]->type_code==ET2_HOST_TASK) {
+		return pRtAddrIdTable[gid]->virtualContext;
+	} else {
+		return pRtAddrIdTable[gid]->host_addr_id;
+	}
+}
+
+void rvf_setRDV(T_RVF_G_ADDR_ID tid,T_RVF_G_ADDR_ID vid) { 	
+	if(pRtAddrIdTable[tid])	pRtAddrIdTable[tid]->virtualContext=vid;
+}
+
+
+/**************************************************************
+*	Function         _rvf_name_cpy
+*
+***************************************************************/
+T_RVF_G_ADDR_ID rvf_allocate_task_id(UINT8 isRealTask) {
+	T_RVF_G_ADDR_ID i=0;
+	UINT8 isTask=1;
+
+	/* Note: differentiation is made between REAL and VIRTUAL IDs
+	 * to provide for backwards compatabible LEGACY timer implementations
+	 * The Real task ids should be in sync with:
+	 * "static rvf_Timer[MAX_RVF_TASKS][RVF_NUM_TASK_TIMERS]",
+	 * defined in "rvf_time.c". In the future, one NU_Timer blk will
+	 * be pointed to in the rt global addr table. Hence, eliminating 
+	 * the large resource of "rvf_Timer[][]"
+	 */
+	if(!pRtAddrIdTable[i]) return RVF_INVALID_ADDR_ID;
+
+	if(isRealTask) {
+		/* REAL TASK									*/
+		for(i=0; pRtAddrIdTable[i]!=NULL && i<MAX_RVF_TASKS; i++);
+
+		if (i < MAX_RVF_TASKS)	{ /* alloc. and init. */ 
+			if(_RALLOC_TASK_RT_ADDR_DATA((T_RVF_BUFFER**)&pRtAddrIdTable[i])) return RVF_INVALID_TASK;
+			memset( pRtAddrIdTable[i], 0, sizeof(T_RVF_RT_ADDR_ID_DATA) );
+			rvf_mbox_buffer_init(pRtAddrIdTable[i]);
+
+		} else	return RVF_INVALID_ADDR_ID;
+	} else {
+		/* VIRTUAL TASK				*/
+		for(i=MAX_RVF_TASKS; pRtAddrIdTable[i]!=NULL && i<MAX_RVF_G_ADDR_ID; i++);
+
+		if (i < MAX_RVF_G_ADDR_ID)	{ /* alloc. and init. */ 
+			if(_RALLOC_TASK_RT_ADDR_DATA((T_RVF_BUFFER**)&pRtAddrIdTable[i])) return RVF_INVALID_TASK;
+			memset( pRtAddrIdTable[i], 0, sizeof(T_RVF_RT_ADDR_ID_DATA) );
+			rvf_mbox_buffer_init(pRtAddrIdTable[i]);
+
+		} else	return RVF_INVALID_ADDR_ID;
+	}
+	
+	return  i;
+}
+
+/* MUST RESOLVE ERROR CODES '1' is just for P of C */
+T_RVF_RET rvf_setRtAddrSweIndex(T_RVF_G_ADDR_ID id, UINT8 sweIndex) {
+	if(id>=MAX_RVF_G_ADDR_ID) return 1;
+	pRtAddrIdTable[id]->swe_db_index=sweIndex;
+//	pRtAddrIdTable[id]->type_code=tcode; /* allows type to be set if not in swe */
+	return RVF_OK;
+}
+
+T_RVF_RET rvf_setHostTaskStackPtr(T_RVF_G_ADDR_ID id, UINT8* pStack) { /* deprecated ! */
+	if(id>=MAX_RVF_TASKS) return 1;
+	pRtAddrIdTable[id]->p_os_stack=pStack;
+
+	return RVF_OK;
+}
+
+T_RVF_RET rvf_isHostingTaskIdle(T_RVF_G_ADDR_ID id, UINT8* status) { /* deprecated ! */
+	if(id>=MAX_RVF_TASKS)	return RVF_INVALID_PARAMETER;
+	if(!pRtAddrIdTable[id])	return RVF_INVALID_PARAMETER;
+	if(pRtAddrIdTable[id]->type_code!=ET2_HOST_TASK) return RVF_INVALID_PARAMETER;
+
+	if(pRtAddrIdTable[id]->hosting_count==0) *status=1;
+	return RVF_OK;
+}
+
+/* convenience/helper fnc. */
+T_RVF_G_ADDR_ID resolveHostAddrId(T_RVF_G_ADDR_ID id) { 
+	if(!pRtAddrIdTable[id]) return RVF_INVALID_ADDR_ID;
+	return pRtAddrIdTable[id]->host_addr_id;
+}
+
+/* HostingCounter enables one to deduce if task can be terminated	*/
+/* ERROR return val must be revised									*/
+T_RVF_RET rvf_registerToHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID eid) {
+	UINT8 i;
+
+	if (host_id >= MAX_RVF_TASKS || eid >= MAX_RVF_G_ADDR_ID )  return RV_INVALID_PARAMETER;; 
+
+	for(i=0;pRtAddrIdTable[host_id]->parasites[i]!=0 && i < MAX_PARASITES; i++);
+
+		pRtAddrIdTable[host_id]->parasites[i]=eid;
+		pRtAddrIdTable[host_id]->hosting_count++;
+
+	return RVF_OK;
+}
+
+T_RVF_RET rvf_unregisterFromHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID pid) {
+	UINT8 i=0;
+	if (pRtAddrIdTable[host_id]->hosting_count !=0) {
+		for(i=0; i<MAX_PARASITES || pRtAddrIdTable[host_id]->parasites[i]==pid; i++);
+			pRtAddrIdTable[host_id]->parasites[i]=0;
+
+		pRtAddrIdTable[host_id]->hosting_count--;
+	} else return RV_INVALID_PARAMETER;
+
+	return RVF_OK;
+}
+
+T_RVF_RET rvf_associateGrpToHost(T_RVF_G_ADDR_ID host_id, T_RVF_GD_ID gd_id) {
+
+	if (host_id >= MAX_RVF_TASKS )  return RV_INVALID_PARAMETER; 
+
+	pRtAddrIdTable[host_id]->gdHost=gd_id;
+		
+	return RVF_OK;
+}
+
+/*T_RVF_RET rvf_unregisterGrpFromHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID pid) {
+	if (pRtAddrIdTable[host_id]->hosting_count !=0) {
+		pRtAddrIdTable[host_id]->parasites[pid]=0;
+		pRtAddrIdTable[host_id]->hosting_count--;
+	} else return RV_INVALID_PARAMETER;
+
+	return RVF_OK;
+}*/
+
+T_RVF_G_ADDR_ID rvf_resolveHostingAddrId(T_RVM_GROUP_DIRECTIVE gd) {
+	int i=0;
+
+	for(i=1; i<MAX_RVF_TASKS; i++) {		// i=1 by-pass RVM task 
+		if(pRtAddrIdTable[i]!=NULL) {
+			if( pRtAddrIdTable[i]->type_code==ET2_HOST_TASK &&
+//				pRtAddrIdTable[i]->priority==priority &&	// to do ...
+//				pRtAddrIdTable[i]->os_stack_size>=stack_size
+				pRtAddrIdTable[i]->gdHost==gd.group_directive &&
+				pRtAddrIdTable[i]->hosting_count<MAX_PARASITES ) return i; // def. 10 A+ .
+		}
+	}
+
+	return RVF_INVALID_ADDR_ID; /* nothing found ret. param must be invalid*/
+}
+
+/*********************************************************************
+ * start() and stop() should be added to params, due to defered calling 
+ * Allow for parasites to be added at RT and their start to be called.
+ *********************************************************************/
+T_RVF_RET rvf_create_virtual_task (T_RV_RET (* handle_message)(T_RV_HDR * msg),
+								   T_RV_RET (* handle_timer)(T_RV_HDR * msg),
+								   T_RVF_G_ADDR_ID task_id, T_RVF_G_ADDR_ID host_task_id, char *taskname,
+								   UINT8 priority, UINT8 tcode) {
+
+	if(!pRtAddrIdTable[task_id]) {  /* allow for static init. or previous dyn init, eg. idle*/	
+		if(_RALLOC_TASK_RT_ADDR_DATA((T_RVF_BUFFER**)&pRtAddrIdTable[task_id])) return RVF_INTERNAL_ERR;
+		memset( pRtAddrIdTable[task_id], 0, sizeof(T_RVF_RT_ADDR_ID_DATA) );
+
+		rvf_mbox_buffer_init(pRtAddrIdTable[task_id]);
+	} /*else printf("RVF: task rt addr %d already alloc'ed\n", task_id); */
+
+	pRtAddrIdTable[task_id]->host_addr_id=host_task_id;
+	pRtAddrIdTable[task_id]->symbolic_name=taskname;
+	pRtAddrIdTable[task_id]->handle_message=handle_message;
+	pRtAddrIdTable[task_id]->handle_timer=handle_timer;
+	pRtAddrIdTable[task_id]->type_code=tcode;
+
+	pRtAddrIdTable[task_id]->pOSTCB=NULL;		/* init to NULL for res.'free' */ 
+	pRtAddrIdTable[task_id]->pOSEvtGrp=NULL;
+	pRtAddrIdTable[task_id]->p_os_stack=NULL;
+//	pRtAddrIdTable[task_id]->p_tm_q=NULL;
+
+//	rvf_registerToHost(host_task_id, task_id);
+	
+	return RVF_OK;
+}
+
+T_RVF_RET rvf_register_t3_handlers (T_RVF_G_ADDR_ID task_id,
+								   T_RV_RET (* handle_message)(T_RV_HDR * msg),
+								   T_RV_RET (* handle_timer)(T_RV_HDR * msg) ) {
+
+	pRtAddrIdTable[task_id]->handle_message=handle_message;
+	pRtAddrIdTable[task_id]->handle_timer=handle_timer;
+
+	return RVF_OK;
+}
+
+/* RVM must create a stack with its MB and pass as params to task create */
+/*T_RVF_RET rvf_create_host_task (T_RV_RET (* proxy)(void), T_RVF_G_ADDR_ID task_id,
+								   char *taskname, UINT8 *stack, UINT16 stacksize, 
+								   UINT8 priority, UINT8 tcode, UINT8 time_slicing, T_RVF_TASK_STATE suspend) {
+
+	return rvf_create_task(	(TASKPTR)proxy, task_id, taskname, stack, stacksize,\
+							priority, tcode, time_slicing,	suspend ) ;
+									
+}*/
+
+/*******************************************************************************
+**
+** Function         rvf_create_task
+**
+** Description      This function is called to create a new rvf task.
+**                  time_slice represents the number of Nucleus ticks before a task is interrupted.
+**					0 for no time-slicing.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET rvf_create_legacy_task (TASKPTR task_entry, UINT8 task_id, char *taskname, UINT8 *stack, UINT16 stacksize, UINT8 priority, UINT8 time_slicing, T_RVF_TASK_STATE is_suspend) {
+
+	return rvf_create_task(task_entry,task_id,taskname,stack,stacksize,priority,ET4_TASK,time_slicing,is_suspend);
+}
+
+T_RVF_RET rvf_create_task (TASKPTR task_entry, T_RVF_G_ADDR_ID task_id, char *taskname, UINT8 *stack, UINT16 stacksize,
+						   UINT8 priority, UINT8 tcode, UINT8 time_slicing, T_RVF_TASK_STATE suspend) {
+
+	/*if (task_id >= MAX_RVF_TASKS) { return 1; } */
+	if (task_counter >= MAX_RVF_TASKS) { return 1; }
+
+	/* fill the task stack with a 0xFE pattern to allow use with stack monitoring tool */
+	memset( stack, 0xFE, stacksize );
+
+	/* allow for immediate task creation, eg. no alloc taskId(), but #defined task No. Dangerous!*/	
+	if(!pRtAddrIdTable[task_id]) {  
+		if(_RALLOC_TASK_RT_ADDR_DATA((T_RVF_BUFFER**)&pRtAddrIdTable[task_id])) return RVF_INTERNAL_ERR;
+		memset( pRtAddrIdTable[task_id], 0, sizeof(T_RVF_RT_ADDR_ID_DATA) );
+
+		rvf_mbox_buffer_init(pRtAddrIdTable[task_id]);
+	} /*else printf("RVF: task rt addr %d already alloc'ed\n", task_id); */
+
+	/*if(_RALLOC_TASK_RT_TM((T_RVF_BUFFER**)&pRtAddrIdTable[task_id]->p_tm_q)) {
+		rvf_free_buf(pRtAddrIdTable[task_id]);
+		pRtAddrIdTable[task_id]=NULL;
+		return RVF_INTERNAL_ERR;
+	} else pRtAddrIdTable[task_id]->p_tm_q->timerCnt=0;*/
+	
+	pRtAddrIdTable[task_id]->hosting_count=0;
+	pRtAddrIdTable[task_id]->host_addr_id=task_id;
+	pRtAddrIdTable[task_id]->symbolic_name=taskname;
+	pRtAddrIdTable[task_id]->priority=priority;
+	pRtAddrIdTable[task_id]->type_code=tcode;
+
+	memset(&pRtAddrIdTable[task_id]->parasites, 0, (sizeof(T_RVF_G_ADDR_ID)*MAX_PARASITES));
+
+	if (stack) {
+	    pRtAddrIdTable[task_id]->p_os_stack     = (UINT8 *)stack;// - stacksize;
+	    pRtAddrIdTable[task_id]->os_stack_size	= stacksize;
+    } else {
+//		rvf_free_buf(pRtAddrIdTable[task_id]->p_tm_q);
+		rvf_free_buf(pRtAddrIdTable[task_id]);
+		pRtAddrIdTable[task_id]=NULL;
+		return RVF_INTERNAL_ERR;
+	}
+
+	if(_RALLOC_TASK_CNTRL_BLK((T_RVF_BUFFER**)&pRtAddrIdTable[task_id]->pOSTCB)) {
+		rvf_free_buf(stack);
+//		rvf_free_buf(pRtAddrIdTable[task_id]->p_tm_q);
+		rvf_free_buf(pRtAddrIdTable[task_id]);
+		pRtAddrIdTable[task_id]=NULL;
+		return RVF_INTERNAL_ERR;
+	}
+	memset( pRtAddrIdTable[task_id]->pOSTCB, 0, sizeof(NU_TASK) );
+
+	if(_RALLOC_TASK_EVT_GRP((T_RVF_BUFFER**)&pRtAddrIdTable[task_id]->pOSEvtGrp)) {
+		rvf_free_buf(pRtAddrIdTable[task_id]->pOSTCB);
+		rvf_free_buf(stack);
+//		rvf_free_buf(pRtAddrIdTable[task_id]->p_tm_q);
+		rvf_free_buf(pRtAddrIdTable[task_id]);
+		pRtAddrIdTable[task_id]=NULL;
+		return RVF_INTERNAL_ERR;
+	}
+	memset( pRtAddrIdTable[task_id]->pOSEvtGrp, 0, sizeof(NU_EVENT_GROUP) );
+
+	/* Create one Event Group for this task */
+	if( NU_SUCCESS != \
+		NU_Create_Event_Group (pRtAddrIdTable[task_id]->pOSEvtGrp,\
+		taskname) ) {
+		return RVF_INTERNAL_ERR;
+	}
+
+	//}
+    /* Create Task */
+	if ( NU_SUCCESS != 
+	NU_Create_Task (pRtAddrIdTable[task_id]->pOSTCB,            /* Task Control Block */
+		            taskname,     /*taskname,*/					/* Task Name */
+		            (NU_TASK_ENTRY )task_entry,					/* Task Entry Function */
+		            0,            /* why prev. task_id ???  */	/* ARGC  A-M-E-N-D-E-D! */
+		            NULL,										/* ARGV */
+		            pRtAddrIdTable[task_id]->p_os_stack,        /* Begining of Stack */
+		            pRtAddrIdTable[task_id]->os_stack_size,		/* Stack size */
+		            priority,									/* Priority */
+		            time_slicing,								/* Time Slicing Period*/
+		            NU_PREEMPT,									/* Preemption allowed */
+					(OPTION)(suspend == RUNNING ? NU_START : NU_NO_START) )/* Start the task or suspend it */
+		)	{	
+		return RVF_INTERNAL_ERR;
+	}
+	task_counter++;   /* MUST 'DEC' ON TASK TERMINATION	*/
+	
+	return RVF_OK;
+}
+
+/* to be called from func. 'create_tasks()' of module "create_RVtasks.c" 
+ * utilises static alloated system variables								*/
+/*T_RVF_RET rvf_create_boot_task (TASKPTR task_entry, UINT8 task_id, char *taskname, UINT8 *stack, UINT16 stacksize, UINT8 priority, UINT8 time_slicing, T_RVF_TASK_STATE suspend) {
+	if (task_id >= MAX_RVF_TASKS)	{		return 1;}
+
+    if (stack)    {
+	    bOSStack     = (UINT8 *)stack;// - stacksize;
+	    bOSStackSize = stacksize;
+    }
+	// copy the task name into an internal buffer 
+	_rvf_name_cpy( &(bOSTName[0][0]), taskname, RVF_MAX_TASK_LEN);
+
+	// fill the task stack with a 0xFE pattern to allow use with stack monitoring tool 
+	memset( stack, 0xFE, stacksize );
+
+	// Create one Event Group for this task 
+	if( NU_SUCCESS != NU_Create_Event_Group (&bOSEvtGrp[0], taskname) ){
+		return RVF_INTERNAL_ERR;
+	}
+
+    // Create Task 
+	if ( NU_SUCCESS != 
+	NU_Create_Task (&bOSTCB[0],                 // (reserved)Task Control Block 
+		            taskname,	                // Task Name 
+		            (NU_TASK_ENTRY )task_entry,	// Task Entry Function 
+		            task_id,		            // ARGC 
+		            NULL,		                // ARGV 
+		            bOSStack,					// Begining of Stack 
+		            stacksize,	                // Stack size 
+		            priority,					// Priority 
+		            time_slicing,			    // Time Slicing Period
+		            NU_PREEMPT,                 // Preemption allowed 
+					(OPTION)(suspend == RUNNING ? NU_START : NU_NO_START) )// Start the task or suspend it 
+		)
+	{	return RVF_INTERNAL_ERR;
+	}
+	task_counter++;
+	return RVF_OK;
+}*/
+
+/* Later timer blk must be added, once made dynamic   */ 
+T_RVF_RET rvf_free_sys_resources(T_RVF_G_ADDR_ID gid, UINT8 rm) {
+
+	if(!pRtAddrIdTable[gid]) return RVF_INTERNAL_ERR;
+
+	if(rm==1 || rm==2) {
+		if(pRtAddrIdTable[gid]->pOSTCB)rvf_free_buf(pRtAddrIdTable[gid]->pOSTCB);
+		if(pRtAddrIdTable[gid]->pOSEvtGrp)rvf_free_buf(pRtAddrIdTable[gid]->pOSEvtGrp);
+		if(pRtAddrIdTable[gid]->p_os_stack)rvf_free_buf(pRtAddrIdTable[gid]->p_os_stack);
+
+		task_counter--;
+	}
+	if(rm==0 || rm==2) {
+		if(pRtAddrIdTable[gid])rvf_free_buf(pRtAddrIdTable[gid]);
+		pRtAddrIdTable[gid]=NULL;
+	}
+
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_exit_task
+**
+** Description      This function is called to stop a rvf task.
+**					A task can kill another task or itself.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_exit_task (T_RVF_G_ADDR_ID task_id)
+{
+	if(!pRtAddrIdTable[task_id]) return;
+	/*
+	** Empty task's mail box
+	*/
+	_rvf_empty_mailboxes(task_id);
+
+	/*
+	** Terminate task
+	*/
+	NU_Terminate_Task(pRtAddrIdTable[task_id]->pOSTCB); /*&OSTCB[task_id]);*/
+	NU_Delete_Task(pRtAddrIdTable[task_id]->pOSTCB);
+
+	/*
+	** Delete related event group
+	*/
+	NU_Delete_Event_Group (pRtAddrIdTable[task_id]->pOSEvtGrp);
+
+	pRtAddrIdTable[task_id]->p_os_stack=0;
+    //OSStack[task_id]     = 0;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_suspend_task
+**
+** Description      This function is called to suspend a rvf task.
+**					A task can suspend another task or itself.
+**
+** Returns          void
+**
+*******************************************************************************/
+T_RVF_RET rvf_suspend_task (T_RVF_G_ADDR_ID task_id)
+{
+	if(!pRtAddrIdTable[task_id]) return RVF_INVALID_PARAMETER;
+	NU_Suspend_Task(pRtAddrIdTable[task_id]->pOSTCB); // A-M-E-N-D-E-D! 
+
+	return RVF_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_wait
+**
+** Description      This function is called by tasks to wait for a specific
+**                  event or set of events. The task may specify the duration
+**                  that it wants to wait for, or 0 if infinite.
+**
+** Returns          the event mask of received events or zero if timeout
+**
+*******************************************************************************/
+UINT16 rvf_wait (UINT16 flag, UINT32 timeout) {
+	T_RVF_G_ADDR_ID     rtask = rvf_get_taskid();
+
+	if (!timeout) timeout = 0xFFFFFFFFL;
+	
+	return rvf_evt_wait(rtask, flag, timeout);
+}
+
+UINT16 rvf_evt_wait(T_RVF_G_ADDR_ID rtask, UINT16 flag, UINT32 timeout) {
+
+#define RVF_RET_TIME_OUT	0
+
+	UINT16		mbxEvt = 0;
+	UNSIGNED    evt   = 0;
+	UNSIGNED	clear = 0;
+	STATUS		status_ret; 
+
+    /* Check if anything in any of the mailboxes. Possible race condition. */
+   
+	if (rtask>=MAX_RVF_TASKS || !pRtAddrIdTable[rtask]) {
+		RVM_TRACE_WARNING_PARAM("RVF: Illegal MBOX or MBOX not ready!", rtask);
+		return (UINT16) RVF_RET_TIME_OUT; 
+	}
+
+	if (pRtAddrIdTable[rtask] && pRtAddrIdTable[rtask]->OSTaskQFirst[0])
+        mbxEvt |= RVF_TASK_MBOX_0_EVT_MASK;
+    if (pRtAddrIdTable[rtask] && pRtAddrIdTable[rtask]->OSTaskQFirst[1])
+        mbxEvt |= RVF_TASK_MBOX_1_EVT_MASK;
+    if (pRtAddrIdTable[rtask] && pRtAddrIdTable[rtask]->OSTaskQFirst[2])
+        mbxEvt |= RVF_TASK_MBOX_2_EVT_MASK;
+    if (pRtAddrIdTable[rtask] && pRtAddrIdTable[rtask]->OSTaskQFirst[3])
+        mbxEvt |= RVF_TASK_MBOX_3_EVT_MASK;
+
+    /* If any valid event if pending, return immediately */
+    if (mbxEvt & flag)
+    {
+       /* Return only those bits which user wants... */
+       evt = (UINT16) (mbxEvt & flag);
+
+	   /* clear the nucleus event(s) for mailboxes */
+	   if ( mbxEvt & 0x000F ) /* a mailbox event is signaled*/
+	   {   NU_Retrieve_Events (pRtAddrIdTable[rtask]->pOSEvtGrp, (UNSIGNED) mbxEvt & 0x000F, NU_AND_CONSUME,
+                        (UNSIGNED *)&clear, NU_NO_SUSPEND);
+	   }
+
+       	   
+        return ((UINT16) evt);
+    }
+
+
+    if(pRtAddrIdTable[rtask]) {
+		status_ret = NU_Retrieve_Events (pRtAddrIdTable[rtask]->pOSEvtGrp,
+										 (UNSIGNED) flag, NU_OR_CONSUME,
+										 (UNSIGNED *)&evt, timeout );
+		if ( status_ret == NU_SUCCESS) {
+			return (UINT16) evt;
+		} else { /* timeout or error case */
+			return (UINT16) RVF_RET_TIME_OUT;
+		}
+	} return (UINT16) RVF_RET_TIME_OUT;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_wait_for_specific_msg
+**
+** Description      This function is called by tasks to wait for a specific
+**                  message in the specified mailbox. The task may specify the duration
+**                  that it wants to wait for, or 0 if infinite.
+**
+** Returns          A pointer to the message, NULL in case of time-out.
+**
+*******************************************************************************/
+T_RVF_BUFFER * rvf_wait_for_specific_msg(UINT16 msg_code, UINT8 mbox, UINT32 timeout)
+{
+	T_RVF_G_ADDR_ID task_id = rvf_get_taskid();
+	T_RVF_BUFFER * p_buf = NULL;
+	T_RVF_INTERNAL_BUF * p_hdr;
+	UNSIGNED clear = 0;
+	STATUS status_ret;
+	UINT32 wait_time;
+	UINT32 init_time = rvf_get_tick_count();
+
+	
+	/* check input parameter */
+	if ( mbox >= RVF_NUM_TASK_MBOX)  /* NOTE: must be def to 2 max */
+	{	rvf_send_trace( "RVF: rvf_wait_for_specific_msg(): invalid mailbox id", 52, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+		return p_buf;
+	}
+
+	if(!timeout)
+		timeout = 0xFFFFFFFFL;
+	wait_time = timeout;
+
+	while( (rvf_get_tick_count() - init_time) < timeout  )
+	{
+		/* test all messages in the mailbox */
+		if( pRtAddrIdTable[task_id]->OSTaskQFirst[mbox] )
+		{
+			rvf_disable(9);
+			p_hdr = pRtAddrIdTable[task_id]->OSTaskQFirst[mbox];
+			p_buf = MEM2USER(p_hdr);
+			/* test the first one */
+			if ( ((T_RV_HDR *)p_buf)->msg_id == msg_code )
+			{	/* message found, return it */
+				pRtAddrIdTable[task_id]->OSTaskQFirst[mbox] = p_hdr->p_next;
+				p_hdr->p_next				= NULL;
+
+#if RVF_ENABLE_BUF_LINKAGE_CHECK
+				RVF_SET_BUF_UNLINKED(p_hdr);
+#endif
+				/* clear the Nucleus Event for this mailbox */
+				NU_Retrieve_Events( pRtAddrIdTable[task_id]->pOSEvtGrp, EVENT_MASK(mbox), NU_AND_CONSUME, 
+								(UNSIGNED *)&clear, NU_NO_SUSPEND);
+				rvf_enable();
+				return p_buf;
+			}
+
+			while(p_hdr->p_next != NULL)
+			{
+				p_buf = MEM2USER(p_hdr->p_next);
+				if ( ((T_RV_HDR *)p_buf)->msg_id == msg_code )
+				{	/* remove it from the list */
+					p_hdr->p_next = ( (T_RVF_INTERNAL_BUF *) USER2MEM(p_buf))->p_next;
+					/* check if it the last one */
+					if ( pRtAddrIdTable[task_id]->OSTaskQLast[mbox]  == USER2MEM(p_buf) )
+					{	pRtAddrIdTable[task_id]->OSTaskQLast[mbox]  = p_hdr;
+					}
+					((T_RVF_INTERNAL_BUF *) USER2MEM(p_buf))->p_next = NULL;
+
+	#if RVF_ENABLE_BUF_LINKAGE_CHECK
+					RVF_SET_BUF_UNLINKED(USER2MEM(p_buf));
+	#endif
+					rvf_enable();
+					return p_buf;
+				}
+				p_hdr = p_hdr->p_next;
+			}
+
+			rvf_enable();
+		}
+		
+		/* here, the message has not been found, so wait for a new message */
+		
+		if ((wait_time != 0xFFFFFFFFL) &&
+			(timeout > rvf_get_tick_count() - init_time))
+		{
+			/* NU_Retrieve_Events bug: cannot call function with a parameter with F in MSB */
+			wait_time = (timeout - (rvf_get_tick_count() - init_time)) & 0x0FFFFFFFL;
+		}
+
+		status_ret = NU_Retrieve_Events( pRtAddrIdTable[task_id]->pOSEvtGrp, EVENT_MASK(mbox), NU_OR_CONSUME,
+										(UNSIGNED *)&clear, wait_time);
+
+		if( status_ret != NU_SUCCESS) /* time out */
+		{	return NULL;
+		}
+		
+	}
+	return NULL;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_delay
+**
+** Description      This function is called by tasks to sleep unconditionally
+**                  for a specified amount of time.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_delay (UINT32 timeout)
+{
+	if (timeout == 0)
+	{	timeout = 1;
+	}
+
+	NU_Sleep(timeout);
+
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_send_event
+**
+** Description      This function is called by tasks to send events to other
+**                  tasks. Tasks can also send events to themselves.
+**
+** Returns          0 if all OK, else 1
+**
+*******************************************************************************/
+UINT8 rvf_send_event (T_RVF_G_ADDR_ID task_id, UINT16 event) {	
+
+	if (task_id >= MAX_RVF_TASKS || !pRtAddrIdTable[task_id] ) return 1;
+
+	NU_Set_Events (pRtAddrIdTable[task_id]->pOSEvtGrp, (UNSIGNED)event, NU_OR);
+
+	return 0;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_get_taskid
+**
+** Description      This function gets the currently running task ID.
+**
+** Returns          task ID
+**
+*******************************************************************************/
+T_RVF_G_ADDR_ID rvf_get_taskid(void) {	/* Retrieve the taskid using index of the task pointer in the OSTCB array */
+	NU_TASK * currTask=0;
+	T_RVF_G_ADDR_ID taskId=RVF_INVALID_ADDR_ID;
+
+	currTask = NU_Current_Task_Pointer();
+
+	if( currTask != NU_NULL) {
+		/* find the task pointer in the OSTCB array */
+		for ( taskId = 0; taskId < MAX_RVF_TASKS; taskId++) {
+			if( (pRtAddrIdTable[taskId]!= NULL) && 
+				((pRtAddrIdTable[taskId]->pOSTCB)) == currTask) return taskId;
+		}
+		return RVF_INVALID_ADDR_ID;
+	} else {
+		return RVF_INVALID_ADDR_ID; /* error case, must return an error code */
+	}
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_taskname
+**
+** Description      This function gets the currently running task name.
+**
+** Returns          pointer to task name or NULL if error
+**
+*******************************************************************************/
+char* rvf_get_taskname(void)
+{	T_RVF_G_ADDR_ID id = rvf_get_taskid();
+	
+	if (id == 0xFF) return NULL; /* return NULL if rvf_get_taskid returns 0xFF */
+
+    return pRtAddrIdTable[id]->symbolic_name; /*(OSTName[ id ]);*/
+}
+
+/*******************************************************************************
+**
+** Function         rvf_enable
+**
+** Description      This function enables interrupts.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_enable(void)
+{
+
+	if( --OSDisableNesting == 0)	/* Control nesting interrupt */
+	{	
+		if( OSInterruptAlreadyMasked == TRUE) /*	check if interrupts have been disabled outside RVF, 
+													in that case, do not enable interrupts */
+		{	OSInterruptAlreadyMasked = FALSE;
+		}
+		else
+		{	NU_Control_Interrupts(OSLastIntLevel);
+		}
+	}
+
+}
+
+#ifdef _WINDOWS
+
+/*******************************************************************************
+**
+** Function         INT_Check_IRQ_Mask()
+**
+** Description      This function checks if the IRQ are disabled (outside RVF).
+**
+** Returns          IRQ mask
+**
+*******************************************************************************/
+UINT32 INT_Check_IRQ_Mask(void)
+{
+	return 0;
+}
+#else
+
+/*-------------------------------------------------------*/ 
+/* INT_Check_IRQ_Mask()                                  */
+/*-------------------------------------------------------*/
+/*                                                       */
+/* Description: check in the CPSR register if the IRQ	 */
+/*              are masked out or not.                   */
+/* ------------                                          */
+/*												         */
+/*-------------------------------------------------------*/
+/* Declaration of ASM INT_Check_IRQ_Mask function */
+UINT32 INT_Check_IRQ_Mask(void);
+
+asm("           .def	$INT_Check_IRQ_Mask");
+asm("$INT_Check_IRQ_Mask  ");			    
+asm("           .ref _INT_32_Check_IRQ_Mask");
+asm(".state16");
+asm("	ADR	r0,_INT_32_Check_IRQ_Mask  ");
+asm("	BX r0  ");
+
+asm("	.align");
+asm("	.state32");
+asm("           .def _INT_32_Check_IRQ_Mask");
+asm("_INT_32_Check_IRQ_Mask  ");
+
+asm("	MRS	r0,CPSR  ");   // pick up CPSR 
+asm("	BX	lr  ");        // return to caller
+
+#endif
+
+
+/*******************************************************************************
+**
+** Function         rvf_disable
+**
+** Description      This function disables interrupts.
+**
+** Returns          void
+**
+*******************************************************************************/
+
+#define RVF_IRQ_DISABLED_MASK 0x00000080
+
+void rvf_disable(UINT8 who)
+{
+
+	/* Control interrupt nesting ourselves */
+	if (OSDisableNesting == 0)
+	{
+		if ( INT_Check_IRQ_Mask() & RVF_IRQ_DISABLED_MASK)	/* if IRQ are disabled (outside RVF) */
+		{	OSInterruptAlreadyMasked = TRUE;
+		}
+		else
+		{	OSLastIntLevel = NU_Control_Interrupts(NU_DISABLE_INTERRUPTS);
+		}
+	}
+	OSDisableNesting++;
+
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_used_stack
+**
+** Description      This function tries to calculate the amount of
+**                  stack used by looking for a zero.
+**
+** Returns          the number of non-zero bytes on the stack
+**
+*******************************************************************************/
+UINT16 rvf_used_stack(T_RVF_G_ADDR_ID task)
+{
+	UINT16 j, stacksize;
+	UINT8 *p;
+
+	if(!pRtAddrIdTable[task]) return 0;
+
+	stacksize = pRtAddrIdTable[task]->os_stack_size; /*OSStackSize[task];*/
+	p = pRtAddrIdTable[task]->p_os_stack; /*OSStack[task];*/
+	for(j = 0; (j < stacksize) && (*p++ == 0xFE); j++);
+
+	return ((UINT16)(stacksize - j));
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_dump_tasks
+**
+** Description      This function dump all the rvf tasks.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_dump_tasks()
+{	UINT8 num_task;
+	char task_info[100];
+
+	rvf_send_trace("*** START DUMPING TASKS ***", 27, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+	
+	/* for each task, display its name, its id, its stack size*/
+	rvf_send_trace("*TASK_NAME Id Stack_size Used_stack", 35, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);
+		
+	for ( num_task = 0; num_task < MAX_RVF_G_ADDR_ID; num_task++ )
+	{	
+		/* trace the task if it has been created*/
+		if (pRtAddrIdTable[num_task] != 0 ) {	
+			sprintf( task_info, "%10.10s %2d      %5d      %5d",
+				pRtAddrIdTable[num_task]->symbolic_name /*OSTName[num_task]*/, 
+				num_task, 
+				pRtAddrIdTable[num_task]->os_stack_size, 
+				rvf_used_stack( num_task) );
+			rvf_send_trace( task_info, 35, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID);		
+		}
+	}
+	/* find a way to track task stack usage and display it */
+	/* using NU_Check_Stack, NU_Task_Information or finding the first non-zero value in the stack */
+}
+
+
+/****************************************************************************/
+/* For Big Endian Processors swap the bytes                                 */
+#if defined(__BIG_ENDIAN)
+UINT16 ntohs(UINT16 n)
+{
+	register UINT8  tmp;
+	register UINT8  *p=(UINT8 *)&n;
+
+	tmp  = p[0];
+	p[0] = p[1];
+	p[1] = tmp;
+
+	return n;
+}
+
+UINT32 ntohl(UINT32 n)
+{
+	register UINT8 tmp;
+	register UINT8 *p=(UINT8 *)&n;
+
+	tmp  = p[0];
+	p[0] = p[3];
+	p[3] = tmp;
+
+	tmp  = p[1];
+	p[1] = p[2];
+	p[2] = tmp;
+
+	return n;
+}
+
+#endif /* __BIG_ENDIAN*/
+
+
+
+
+/******************************************************************************
+**
+** Function			rvf_send_trace
+**
+** Description		This function displays a message essentially for debug purposes.
+**					It displays the msg_length characters of the string pointed by msg
+**					and the value of val.		
+**
+** Returns			void
+**
+******************************************************************************/
+#ifdef  _WINDOWS 
+#ifndef _CONSOLE
+void rvf_send_trace1( INT8 * msg, UINT8 msg_length, UINT32 val, UINT8 TRACE_LEVEL, UINT32 swe_use_id)
+{
+/* Function to display trace message for Tool */
+
+	UINT32 trace_type = swe_use_id;
+	
+	Trace( msg, msg_length, val, TRACE_LEVEL, trace_type);
+}
+#endif	
+#endif	
+
+#ifdef _CONSOLE  /* CONSOLE */
+void rvf_send_trace1( INT8 * msg, UINT8 msg_length, UINT32 val, UINT8 TRACE_LEVEL, UINT32 swe_use_id) {
+	const	int MAX		= 1000; 
+	static	int l		= 0;
+	char	buf[100];
+	HANDLE	out			= 0;
+    int nb;
+
+	if(!out)out=GetStdHandle(STD_OUTPUT_HANDLE); 
+
+	rvf_disable(25);
+	
+	sprintf(buf,"%s %d\n", msg, val);
+	WriteConsole(out, buf, strlen(buf), &nb, NULL);
+	
+	if(l>=MAX) {
+		system("cls");
+		l=0;
+	} else l++;
+
+	rvf_enable();
+}
+#endif			/* CONSOLE */
+
+/*******************************************************************************
+**
+** Function         rvf_resume_task
+**
+** Description      This function is called to resume a rvf task which is in a suspend state.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET rvf_resume_task( T_RVF_G_ADDR_ID taskid)
+{
+	if(!pRtAddrIdTable[taskid]) return RVF_INVALID_PARAMETER;
+	if(!pRtAddrIdTable[taskid]->pOSTCB) return RVF_INVALID_PARAMETER;
+	/* resume the task */
+	if ( NU_INVALID_TASK == NU_Resume_Task( pRtAddrIdTable[taskid]->pOSTCB) ) {// A-M-E-N-D-E-D!
+		return RVF_INTERNAL_ERR; //RVF_INVALID_PARAMETER;
+	}
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_initialize_mutex
+**
+** Description      This function initialize a mutex structure, which will be used 
+**					to protect shared variables against simultaneous access.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET		rvf_initialize_mutex( T_RVF_MUTEX * mutex)
+{
+
+	/* initializes the mutex structure */
+	
+	if( NU_Create_Semaphore( (NU_SEMAPHORE *)mutex, "RVF", 1, NU_PRIORITY ) != NU_SUCCESS)
+	{	return RVF_INTERNAL_ERR;
+	}
+	
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_lock_mutex
+**
+** Description      This function locks a mutex to avoid simultaneous access.
+**					If the mutex is already locked, the task is suspended 
+**					until the mutex is unlocked.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET		rvf_lock_mutex( T_RVF_MUTEX * mutex)
+{
+	if( NU_Obtain_Semaphore( (NU_SEMAPHORE *)mutex, NU_SUSPEND ) != NU_SUCCESS)
+	{	return RVF_INTERNAL_ERR;
+	}
+
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_unlock_mutex
+**
+** Description      This function unlocks a mutex to avoid simultaneous access.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET		rvf_unlock_mutex( T_RVF_MUTEX * mutex)
+{
+	if( NU_Release_Semaphore( (NU_SEMAPHORE *)mutex ) != NU_SUCCESS)
+	{	return RVF_INTERNAL_ERR;
+	}
+
+	return RVF_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_delete_mutex
+**
+** Description      This function deletes a previously created mutex.
+**
+** Returns          RVF_OK if successful, else an error code
+**
+*******************************************************************************/
+T_RVF_RET		rvf_delete_mutex( T_RVF_MUTEX * mutex)
+{
+	if( NU_Delete_Semaphore( (NU_SEMAPHORE *)mutex ) != NU_SUCCESS)
+	{	return RVF_INTERNAL_ERR;
+	}
+
+	return RVF_OK;
+}
+
+void rvf_yield() { NU_Relinquish(); }
+
+/* convenience function    */ 
+UINT8 rvf_isType2() {
+	if(pRtAddrIdTable[rvf_get_taskid()]->type_code==ET2_HOST_TASK) return 1;
+	else return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_time.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,623 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_time.c                                                  */
+/*                                                                          */
+/*  Function    this file contains rvf time related functions               */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  3/12/99		Create														*/
+/*  10/27/1999  remove all non-nucleus sections (#ifdef)					*/
+/*	30/11/99	compliant to RV coding guidelines							*/
+/*  31/01/2003  Timer Redesign/Impl.RV2    Gary TOTNEY						*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#include "nucleus.h" 
+
+#include "rvm/rvm_use_id_list.h"
+#include "rvm/rvm_i.h"	// only for MBs [coupling issue]
+#include "rvm/rvm_api.h"// MSG			[coupling issue]
+#include "rvf/rvf_i.h"
+#include "rvf/rvf_api.h"
+#include <string.h>
+
+
+
+/*
+** Define the time control array
+*/
+static NU_TIMER		rvf_Timer[MAX_RVF_TASKS][RVF_NUM_TASK_TIMERS];
+
+//extern T_RVF_MB_ID rvm_timer_mem_bank;
+
+#define _RALLOC_TIMER_BLK(tb) rvf_get_buf(rvm_timer_mem_bank, sizeof(NU_TIMER), tb)
+#define _RALLOC_TMS_MSG(id, tb) rvf_get_msg_buf(rvm_tm_notify_mem_bank, sizeof(T_RVF_TMS_MSG), id, tb)
+
+
+/* PRIVATE FUNC FWD DECLs   */
+T_RV_TM_ID _invoke_tm(T_RVF_G_ADDR_ID gid, UINT32 t, UINT8 cont, void* action, UINT8 lg);
+
+/*******************************************************************************
+**
+** Function         _rvf_timer_expire
+**
+** Description      This internal function is called by Nucleus OS, when a task
+**					timer expires. It sets the corresponding event.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_timer_expire(UNSIGNED timer_id)
+{ 
+	rvf_disable(14);
+	/* send the corresponding timer event */
+	rvf_send_event((UINT8)(timer_id / RVF_NUM_TASK_TIMERS),(UINT16)(EVENT_MASK(((timer_id % RVF_NUM_TASK_TIMERS)+4)) ) );
+	rvf_enable();
+}
+
+void _rvf_tm_notify(UNSIGNED timer_id) {
+	T_RVF_TM_UBLK			tmr;
+	T_RVF_TM_ATTRIB_UBLK	attr;
+	UINT32 tmid=0, cont=0, d;
+	OPTION	opt;
+	T_RVF_TMS_MSG*		 p_msg=NULL;
+	
+	if(timer_id) tmr.id=timer_id;
+
+	if(NU_Timer_Information(tmr.ptr,attr.str, &opt, (UNSIGNED*)&d, (UNSIGNED*)&tmid, (UNSIGNED*)&d, (UNSIGNED*) &cont) == NU_INVALID_TIMER) { // use to get p_attrib
+		rvf_send_trace ("FATAL: RVF TIMER ATTIRBUTE ERROR!",
+						49,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_WARNING,
+						0);
+
+	}
+/*	printf("%ld %ld %d:",	attr.attrib.host_addr_id,
+							attr.attrib.action,
+							attr.attrib.legacyFlag);
+*/
+	if(!pRtAddrIdTable[attr.attrib.host_addr_id]) return; // Don't waste time in HISR			/* MUST BE REPLACED WITH CACHED MSG'ing  */
+
+	// Will utilise active caching in near future, limiting HISR duration
+	if((_RALLOC_TMS_MSG(RVM_TMS_MSG, (T_RVF_MSG**)&p_msg))==RVF_RED){
+		rvf_send_trace ("FATAL: RVF TIMER HISR: Insufficient resources!",
+						49,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_WARNING,
+						0);
+
+		return; // (RV_MEMORY_ERR);
+	} 
+	p_msg->hdr.msg_id=RVM_TMS_MSG;
+	p_msg->tm_id=tmr.id;
+	p_msg->cont=cont;
+	p_msg->action=attr.attrib.action;
+	rvf_disable(14);
+	rvf_send_priority_msg(attr.attrib.host_addr_id, p_msg); // NOTE: must have id and recognised in FSM core
+	rvf_enable();
+}
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvf_create_timer                                            */
+/*                                                                              */
+/*    Purpose:         This function is reponsible for stopping timers.         */
+/*                                                                              */                      
+/*    Revision History:                                                         */
+/*                                                                              */
+/********************************************************************************/
+T_RVF_TIMER_ID rvf_create_timer(T_RVF_G_ADDR_ID		g_addrId,
+							UINT32					tmDuration,
+							BOOLEAN					isContinuous,
+							void*					p_action) {
+	
+	return _invoke_tm(g_addrId, tmDuration, isContinuous, p_action, 0);
+}
+
+// this exists as part of an on-going initiative to deprecate rvf: start/stop timers
+T_RV_TM_ID _invoke_tm(T_RVF_G_ADDR_ID gid, UINT32 t, UINT8 cont, void* action, UINT8 lg) {
+	T_RVF_TM_UBLK			tmr;
+	T_RVF_TM_ATTRIB_UBLK	tm_attrib;
+	UINT32					re_sched=0;
+	OPTION					opt=NU_DISABLE_TIMER;
+	STATUS					status;
+
+	if(t) opt=NU_ENABLE_TIMER;
+	if(cont) re_sched=t;
+
+	// TO DO... ret. 0 if alloc fails
+	if(_RALLOC_TIMER_BLK((T_RVF_BUFFER**)&tmr.ptr)) return 0;
+	
+	tm_attrib.attrib.host_addr_id	=gid;
+	tm_attrib.attrib.action			=action;
+	tm_attrib.attrib.legacyFlag		=lg;
+
+   	status=NU_Create_Timer( tmr.ptr,			// TIMER CONTROL BLOCK
+							tm_attrib.str,		// timer name (overloaded)
+							_rvf_tm_notify,		// expiration routine to call					
+							tmr.id, 			// unique id which enables to find a specific task and a specific timer
+							t,					// duration				
+							re_sched,			// continuous = 1		
+							opt);
+
+	if(status!=NU_SUCCESS) tmr.id=0;
+	
+	return (UINT32)tmr.id;
+}
+
+/*T_RVF_RET rvf_get_remaining_time(T_RV_TM_ID tid, UINT32* t) {
+	T_RVF_TM_UBLK			tmr;
+
+	tmr.id=tid;
+	if(NU_Get_Remaining_Time(tmr.ptr, (UNSIGNED*)&t)==NU_INVALID_TIMER) return RV_INVALID_PARAMETER;
+
+	return RVF_OK;
+}*/
+
+/*******************************************************************************
+**
+** Function         rvf_del_timer
+**
+** Description      This function is called by an application to delete a timer
+**                  entry from a timer list.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_del_timer(T_RV_TM_ID tm_id) {
+	T_RVF_TM_UBLK			tmr;
+
+	if(tm_id) tmr.id=tm_id;
+
+	NU_Control_Timer(tmr.ptr, NU_DISABLE_TIMER);
+	NU_Delete_Timer(tmr.ptr);
+	rvf_free_buf(tmr.ptr);
+}
+
+void rvf_reset_timer(T_RV_TM_ID tm_id, UINT32 new_duration,
+										BOOLEAN isContinuous) {
+	T_RVF_TM_UBLK			tmr;
+	UINT32					re_sched=0;
+
+	if(isContinuous)re_sched=new_duration;
+	if(tm_id)		tmr.id=tm_id;
+
+	NU_Control_Timer(tmr.ptr, NU_DISABLE_TIMER);
+
+	if(new_duration) {
+		NU_Reset_Timer(	tmr.ptr,
+						_rvf_tm_notify,
+						new_duration,
+						re_sched, 
+						NU_ENABLE_TIMER);
+	}
+
+}
+
+/*******************************************************************************
+**
+** Function         _rvf_timers_init
+**
+** Description      This internal function is called once at startup to initialize
+**                  all the timer structures.
+**
+** Returns          void
+**
+*******************************************************************************/
+void _rvf_timers_init(void)
+{
+    UINT8   task_num, timer_num;
+
+    for (task_num = 0; task_num< MAX_RVF_TASKS; task_num++)
+    {
+		for (timer_num = 0; timer_num < RVF_NUM_TASK_TIMERS; timer_num++)
+		{
+			NU_Create_Timer(	&(rvf_Timer[task_num][timer_num]),/* TIMER CONTROL BLOCK*/
+								"", /* timer name */
+								_rvf_timer_expire, /* expiration routine to call*/					
+								(task_num * RVF_NUM_TASK_TIMERS) +timer_num,
+								/* unique id which enables to find a specific task and a specific timer*/
+								0,
+								0,
+								NU_DISABLE_TIMER);
+		}		
+    }
+}
+
+/*******************************************************************************
+**
+** Function         rvf_get_time_stamp
+**
+** Description      This function formats the time into a user area
+**
+** Returns          the address of the user area containing the formatted time
+**
+*******************************************************************************/
+char *rvf_get_time_stamp(char *tbuf)
+{
+	UINT32 ms_time;
+	UINT32 s_time;
+	UINT32 m_time;
+	UINT32 h_time;
+    char   *p_out = tbuf;
+
+	ms_time = rvf_get_tick_count();
+	s_time  = ms_time/100;   /* 100 Ticks per second */
+	m_time  = s_time/60;
+	h_time  = m_time/60;
+
+	ms_time -= s_time*100;
+	s_time  -= m_time*60;
+	m_time  -= h_time*60;
+
+    *p_out++ = (char)((h_time / 10) + '0');
+    *p_out++ = (char)((h_time % 10) + '0');
+    *p_out++ = ':';
+    *p_out++ = (char)((m_time / 10) + '0');
+    *p_out++ = (char)((m_time % 10) + '0');
+    *p_out++ = ':';
+    *p_out++ = (char)((s_time / 10) + '0');
+    *p_out++ = (char)((s_time % 10) + '0');
+    *p_out++ = ':';
+    *p_out++ = (char)((ms_time / 10) + '0');
+    *p_out++ = (char)((ms_time % 10) + '0');
+    *p_out++ = ':';
+    *p_out   = 0;
+
+	return tbuf;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_tick_count
+**
+** Description      This function returns the current Nucleus system ticks
+**
+** Returns          ticks
+**
+*******************************************************************************/
+UINT32	rvf_get_tick_count(void)
+{
+	return NU_Retrieve_Clock();
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_start_timer
+**
+** Description      An application can call this function to start one of
+**                  it's four general purpose timers. Any of the four timers
+**                  can be 1-shot or continuous. If a timer is already running,
+**                  it will be reset to the new paramaters.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_start_timer (UINT8 tnum, UINT32 ticks, BOOLEAN is_continuous)
+{	T_RVF_G_ADDR_ID     task_id = rvf_get_taskid();
+	
+	if(tnum==RVF_TIMER_3 || tnum==RVF_TIMER_2) { // reserved for rvf timer service 
+		rvf_send_trace ("WARNING: Timers 2 & 3 are deprecated!",
+						37,
+						NULL_PARAM,
+						RV_TRACE_LEVEL_DEBUG_LOW,
+						0); 
+//		return;
+	}
+	if (!ticks) // check if ticks == 0, set it to 1 
+		{	ticks = 1;
+		}
+
+	// disable Nucleus timer 
+	NU_Control_Timer(	&(rvf_Timer[task_id][tnum]),
+						NU_DISABLE_TIMER );
+
+	// reset the timer with the new settings 
+	NU_Reset_Timer(	&(rvf_Timer[task_id][tnum]),
+					_rvf_timer_expire,
+					ticks,
+					is_continuous? ticks:0, // if timer is continuous, reload it 
+					NU_ENABLE_TIMER);
+}
+
+/*******************************************************************************
+**
+** Function         rvf_stop_timer
+**
+** Description      An application can call this function to stop one of
+**                  it's four general purpose timers. There is no harm in
+**                  stopping a timer that is already stopped.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_stop_timer (UINT8 tnum)
+{	T_RVF_G_ADDR_ID  task_id = rvf_get_taskid();
+
+	/* disable Nucleus timer */
+	NU_Control_Timer(	&(rvf_Timer[task_id][tnum]),
+						NU_DISABLE_TIMER );
+}
+
+/*******************************************************************************
+**
+** Function         rvf_init_timer_list
+**
+** Description      This function is called by applications when they
+**                  want to initialize a timer list.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_init_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq)
+{
+    p_timer_listq->p_first    = NULL;
+    p_timer_listq->p_last     = NULL;
+    p_timer_listq->last_ticks = 0;
+}
+
+/*******************************************************************************
+**
+** Function         rvf_init_timer_list_entry
+**
+** Description      This function is called by the applications when they
+**                  want to initialize a timer list entry. This must be
+**                  done prior to first use of the entry.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_init_timer_list_entry (T_RVF_TIMER_LIST_ENT  *p_tle)
+{
+    p_tle->p_next  = NULL;
+    p_tle->p_prev  = NULL;
+    p_tle->ticks   = 0xFFFFFFFFL;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_update_timer_list
+**
+** Description      This function is called by the applications when they
+**                  want to update a timer list. This should be at every
+**                  timer list unit tick, e.g. once per sec, once per minute etc.
+**
+** Returns          the number of timers that have expired
+**
+*******************************************************************************/
+UINT16 rvf_revise_timer_list (T_RVF_G_ADDR_ID gid){
+	if(!pRtAddrIdTable[gid] );
+//	   !pRtAddrIdTable[gid]->p_tm_q ||
+//		pRtAddrIdTable[gid]->p_tm_q->timerCnt==0 ||
+//		pRtAddrIdTable[gid]->polling_tm!=0 ) return 0;			/* rvf abort     */
+//	return rvf_update_timer_list(pRtAddrIdTable[gid]->p_tm_q);	/* tms notify    */
+	return 0;
+}
+UINT16 rvf_update_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq)
+{
+    T_RVF_TIMER_LIST_ENT  *p_tle;
+    UINT16          num_time_out = 0;
+
+    p_tle = p_timer_listq->p_first;
+
+    /* First, get the guys who have previously timed out */
+    while ((p_tle) && (p_tle->ticks == 0))
+    {
+        num_time_out++;
+        p_tle = p_tle->p_next;
+    }
+
+    /* Now, get the guys who have just timed out */
+    if ((p_tle) && (p_tle->ticks))
+    {
+        if (--p_tle->ticks == 0)
+        {
+            while (p_tle != NULL && p_tle->ticks == 0)
+            {
+                num_time_out++;
+                p_tle = p_tle->p_next;
+            }
+        }
+    }
+
+    if (p_timer_listq->last_ticks)
+        p_timer_listq->last_ticks--;
+
+    return (num_time_out);
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvf_add_to_timer_list
+**
+** Description      This function is called by an application to add a timer
+**                  entry to a timer list.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_add_to_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq, T_RVF_TIMER_LIST_ENT  *p_tle)
+{
+    UINT32           nr_ticks_total;
+    T_RVF_TIMER_LIST_ENT  *p_temp;
+
+    if (p_tle->ticks >= p_timer_listq->last_ticks)
+    {
+        if (p_timer_listq->p_first == NULL)
+            p_timer_listq->p_first = p_tle;
+        else
+        {
+            if (p_timer_listq->p_last != NULL)
+                p_timer_listq->p_last->p_next = p_tle;
+
+            p_tle->p_prev = p_timer_listq->p_last;
+        }
+
+        p_tle->p_next = NULL;
+        p_timer_listq->p_last = p_tle;
+        nr_ticks_total = p_tle->ticks;
+        p_tle->ticks = p_tle->ticks - p_timer_listq->last_ticks;
+
+        p_timer_listq->last_ticks = nr_ticks_total;
+    }
+    else
+    {
+        p_temp = p_timer_listq->p_first;
+        while (p_tle->ticks > p_temp->ticks)
+        {
+            p_tle->ticks = p_tle->ticks - p_temp->ticks;
+            p_temp = p_temp->p_next;
+        }
+        if (p_temp == p_timer_listq->p_first)
+        {
+            p_tle->p_next = p_timer_listq->p_first;
+            p_timer_listq->p_first->p_prev = p_tle;
+            p_timer_listq->p_first = p_tle;
+        }
+        else
+        {
+            p_temp->p_prev->p_next = p_tle;
+            p_tle->p_prev = p_temp->p_prev;
+            p_temp->p_prev = p_tle;
+            p_tle->p_next = p_temp;
+        }
+        p_temp->ticks = p_temp->ticks - p_tle->ticks;
+    }
+}
+
+/*******************************************************************************
+**
+** Function         rvf_remove_from_timer_list
+**
+** Description      This function is called by an application to remove a timer
+**                  entry from a timer list.
+**
+** Returns          void
+**
+*******************************************************************************/
+void rvf_remove_from_timer_list (T_RVF_TIMER_LIST_Q *p_timer_listq, T_RVF_TIMER_LIST_ENT  *p_tle)
+{
+    if (p_tle == NULL || p_tle->ticks == 0xFFFFFFFFL || p_timer_listq->p_first == NULL)
+    {
+        return;
+    }
+
+    /* Add the ticks remaining in this timer to the next guy in the list.
+    */
+    if (p_tle->p_next != NULL)
+    {
+        p_tle->p_next->ticks += p_tle->ticks;
+    }
+    else
+    {
+        p_timer_listq->last_ticks -= p_tle->ticks;
+    }
+
+    /* Unlink timer from the list.
+    */
+    if (p_timer_listq->p_first == p_tle)
+    {
+        p_timer_listq->p_first = p_tle->p_next;
+
+        if (p_timer_listq->p_first != NULL)
+            p_timer_listq->p_first->p_prev = NULL;
+
+        if (p_timer_listq->p_last == p_tle)
+            p_timer_listq->p_last = NULL;
+    }
+    else
+    {
+        if (p_timer_listq->p_last == p_tle)
+        {
+            p_timer_listq->p_last = p_tle->p_prev;
+
+            if (p_timer_listq->p_last != NULL)
+                p_timer_listq->p_last->p_next = NULL;
+        }
+        else
+        {
+            if (p_tle->p_next != NULL && p_tle->p_next->p_prev == p_tle)
+                p_tle->p_next->p_prev = p_tle->p_prev;
+            else
+            {
+                /* Error case - chain messed up ?? */
+                return;
+            }
+
+            if (p_tle->p_prev != NULL && p_tle->p_prev->p_next == p_tle)
+                p_tle->p_prev->p_next = p_tle->p_next;
+            else
+            {
+                /* Error case - chain messed up ?? */
+                return;
+            }
+        }
+    }
+
+    p_tle->p_next = p_tle->p_prev = NULL;
+    p_tle->ticks = 0xFFFFFFFFL;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvf_get_expired_entry
+**
+** Description      This function returns a pointer to the first expired entry in
+**					the timer list queue.
+**					If no entry in the queue has expired, it returns NULL.
+**
+** Returns          T_RVF_TIMER_LIST_ENT * : pointer to the expired entry if any.
+**
+*******************************************************************************/
+T_RVF_TIMER_LIST_ENT * rvf_get_expired_entry (T_RVF_TIMER_LIST_Q *p_timer_listq)
+{	
+	T_RVF_TIMER_LIST_ENT * p_tle;
+	/* test if the first entry in the queue has expired */
+	if ( (p_timer_listq->p_first != NULL) && (p_timer_listq->p_first->ticks == 0) )
+	{	
+
+		p_tle = p_timer_listq->p_first;
+		if(p_tle->t_init) {
+			p_tle->ticks=p_tle->t_init;
+		} else {
+			/* unlink entry from the list */
+			p_timer_listq->p_first = p_tle->p_next;
+
+			if (p_timer_listq->p_first != NULL)
+				p_timer_listq->p_first->p_prev = NULL;
+
+			if (p_timer_listq->p_last == p_tle)
+				p_timer_listq->p_last = NULL;
+			
+			p_tle->p_next = NULL;
+			p_tle->p_prev = NULL;
+			p_tle->ticks = 0xFFFFFFFFL;
+			//return p_tle;
+		}
+		return p_tle;
+	}
+	else
+	{	return NULL;
+	}
+}
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvf/rvf_trace_adapt.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,171 @@
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvf_trace_adapt.c                                           */
+/*                                                                          */
+/*  Function    this file is used to trace messages if TRACE module is      */
+/*              activated or not                                            */
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  03/19/2001		Create													*/
+/*																			*/
+/*	Author		Pascal Puel (p-puel@tif.ti.com)								*/
+/*																			*/
+/* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+
+#ifndef _WINDOWS
+	#include "config/rv.cfg"
+	#include "config/trace.cfg"
+#endif
+
+#include "rv/general.h"
+#include "rv/rv.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+
+#include "rvt/rvt_gen.h"
+
+#include "rvm/rvm_use_id_list.h"
+
+#include <string.h>
+
+/* DAR files used to redirect trace to DAR entity */
+//#ifdef RVM_DAR_SWE
+//	#include "dar_api.h"
+//	#include "dar_gen.h"
+//	#include "dar_structs_i.h"
+//	#include "dar_diagnose_i.h"
+
+	/* Define a pointer to the DAR Global Environment Control block   */
+//	extern T_DAR_ENV_CTRL_BLK *dar_gbl_var_p;
+//#endif
+
+UINT8 rvf_trace_level = TRACE_LEVEL_FILTER;
+UINT32 rvf_layer_mask = LAYER_DBG;
+
+/* Decimal to hexadecimal conversion table */
+static const char Num2Char[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+
+extern T_RVT_USER_ID rv_trace_user_id;
+
+#ifndef FRAMING_PROTOCOL
+void rvf_send_trace1 (char * msg, UINT8 msg_length, UINT32 val, UINT8 TRACE_LEVEL, UINT32 swe_use_id)
+{	
+	UINT32 trace_type = swe_use_id;
+
+	/* Apply the appropriate compilation flags to filter trace messages based on
+	their type and level */
+	if ((TRACE_LEVEL < RV_TRACE_LEVEL_WARNING) ||
+		((TRACE_LEVEL <= rvf_trace_level) &&
+		 (((trace_type & rvf_layer_mask & 0x0000FFFF) == (trace_type & 0x0000FFFF)) ||
+		  ((trace_type & rvf_layer_mask & 0xFFFF0000) != (trace_type & 0xFFFF0000)))))
+		{
+			char * buff;
+
+			if (val == NULL_PARAM)
+			{
+				rvt_mem_alloc (rv_trace_user_id, msg_length, (T_RVT_BUFFER *)&buff);
+				if (buff != NULL) /* Check if there is enough memory for the buffer */
+				{
+					/* Copy the body of the message */
+					memcpy( buff, msg, msg_length);
+					rvt_send_trace_no_cpy( buff, rv_trace_user_id, msg_length, RVT_ASCII_FORMAT);
+				}
+			}
+			else
+			{
+				rvt_mem_alloc (rv_trace_user_id, msg_length +11, (T_RVT_BUFFER *)&buff);
+				if (buff != NULL) /* Check if there is enough memory for the buffer */
+				{	
+					UINT8 i;
+				
+					/* Copy the body of the message */
+					memcpy( buff, msg, msg_length);
+
+					((char *)buff)[msg_length]		= ' ';
+					((char *)buff)[msg_length + 1]	= '0'; 
+					((char *)buff)[msg_length + 2]	= 'x';
+					
+					for (i=0; i<8; i++)
+					{
+						((char *)buff)[msg_length+3+i] = Num2Char[(UINT8)((val<<(i<<2))>>28)];
+					}
+					rvt_send_trace_no_cpy(buff, rv_trace_user_id, msg_length + 11, RVT_BINARY_FORMAT);
+				}
+			}
+		}
+}
+#else
+/********************************* VERSION WITH TRACE MUX **************************/
+
+void rvf_send_trace1 (char * msg, UINT8 msg_length, UINT32 val, UINT8 TRACE_LEVEL, UINT32 swe_use_id)
+{	
+	UINT32 trace_type = swe_use_id;
+
+	/* Apply the appropriate compilation flags to filter trace messages based
+	on their type and level */
+	if ((TRACE_LEVEL < RV_TRACE_LEVEL_WARNING) ||
+		((TRACE_LEVEL <= rvf_trace_level) &&
+		 (((trace_type & rvf_layer_mask & 0x0000FFFF) == (trace_type & 0x0000FFFF)) ||
+		  ((trace_type & rvf_layer_mask & 0xFFFF0000) != (trace_type & 0xFFFF0000)))))
+		{
+			char * buff;
+
+			if (val == NULL_PARAM)
+			{
+				rvt_mem_alloc (rv_trace_user_id, msg_length+5, (T_RVT_BUFFER *)&buff);
+
+				if (buff != NULL) /* Check if there is enough memory for the buffer */
+				{
+					/* Add the trace type (MSB and LSB) and Trace level	*/
+					buff [0] = (char) (trace_type >> 24);
+					buff [1] = (char) (trace_type >> 16);
+					buff [2] = (char) (trace_type >> 8);
+					buff [3] = (char) (trace_type & 0xff);
+					buff [4] = (char) TRACE_LEVEL;
+
+					/* Copy the message in the new buffer */
+					memcpy(buff+5, msg, msg_length);
+					
+					/* Send the trace message */
+					rvt_send_trace_no_cpy ((T_RVT_BUFFER) buff, rv_trace_user_id, msg_length+5, RVT_BINARY_FORMAT);
+				}
+			}
+			else
+			{
+				rvt_mem_alloc (rv_trace_user_id, msg_length+16, (T_RVT_BUFFER *)&buff);
+
+				if (buff != NULL) /* Check if there is enough memory for the buffer */
+				{	
+					UINT8 i;
+
+					/* Add the trace type (MSB and LSB) and Trace level	*/
+					buff [0] = (char) (trace_type >> 24);
+					buff [1] = (char) (trace_type >> 16);
+					buff [2] = (char) (trace_type >> 8);
+					buff [3] = (char) (trace_type & 0xff);
+					buff [4] = (char) TRACE_LEVEL;
+
+					/* Copy the message in the new buffer */
+					memcpy( buff + 5, msg, msg_length);
+					
+					buff[5+msg_length]		= ' ';
+					buff[5+msg_length + 1]	= '0'; 
+					buff[5+msg_length + 2]	= 'x';
+					
+					for (i=0; i<8; i++)
+					{
+						((char *)buff)[8+msg_length+i] = Num2Char[(UINT8)((val<<(i<<2))>>28)];
+					}
+
+					/* Send the trace message */
+					rvt_send_trace_no_cpy ((T_RVT_BUFFER) buff, rv_trace_user_id, msg_length+16, RVT_BINARY_FORMAT);
+				}
+			}
+		}
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_api.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,317 @@
+/**
+ *                                                                          
+ *  @file	rvm_api.c                                              
+ *                                                                          
+ *  This file contains interface functions.
+ *
+ * @author	Cristian Livadiotti (c-livadiotti@ti.com)
+ * @version	0.2
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 06/04/2000	Cristian Livadiotti		Create.
+ * 10/22/2001	David Lamy-Charrier		Update for new Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+
+#ifndef _WINDOWS
+	#include "config/rv.cfg"
+#endif
+
+#include "rvf/rvf_env.h"
+
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_i.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include <string.h>
+
+extern T_RVM_KNOWN_SWE * rvm_swe_array;
+
+
+/*******************************************************************************
+** Function         rvm_start_environment
+**
+** Description      Start the RV manager. 
+**					
+*******************************************************************************/
+T_RVM_RETURN	rvm_start_environment()
+{	T_RVF_BUFFER * rvm_stack;
+
+	/* initialize the RVM */
+	if ( rvm_init() == FALSE)
+	{	return RVM_INTERNAL_ERR;
+	}
+
+	/* start the RV manager task */
+
+	if ( rvf_get_buf( rvm_stack_mem_bank, RVM_STACK_SIZE, &rvm_stack) == RVF_RED )
+	{	return RVM_MEMORY_ERR;
+	}
+
+	if ( rvf_create_task( rvm_task, RVM_TASK_ID, "RVM", rvm_stack, RVM_STACK_SIZE, RVM_PRIORITY, RVM_TASK, DEFAULT_TIME_SLICING, RUNNING) 
+		!= RVF_OK )
+	{	return RVM_INTERNAL_ERR;
+	}
+
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_start_swe
+**
+** Description      Called by an application to start the specified SWE
+**
+** Parameters:		USE_ID of the SWE to start.
+**					return path for asynchronous response
+**
+** Returns          T_RVM_RETURN:	RVM_OK if everything is ok,
+**									RVM_INVALID_PARAMETER if the SWE USE_ID is unknown
+**									RVM_NOT_READY if the get_info function has not been specified in the database
+**												  or the SWE has been already started.
+**									RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank.
+**									RVM_INTERNAL_ERR if the RVM task has not been created.
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_start_swe (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path)
+{	
+	T_RVM_MSG		*msg;
+	T_RVM_RETURN	rvm_status;
+	UINT8			num_swe;
+	
+	/* Check Application is "startable"	*/
+	if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_START_APPLI)) != RVM_OK)
+	{
+		rvf_send_trace("RVM_task: rvm_start_swe() this appli cannot be started", 54, (UINT32)rvm_status, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+		return rvm_status;
+	}
+	
+	/* build a msg  */
+	if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_MSG), (void **)&msg) == RVF_RED )
+	{
+		rvf_send_trace("RVM_task: No memory", 19, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+		return RVM_MEMORY_ERR;
+	}
+
+	msg->header.msg_id			= RVM_START_APPLI;
+	msg->header.src_addr_id		= return_path.addr_id; 
+//	msg->header.callback_func	= return_path.callback_func; 
+	msg->rp.callback_func		= return_path.callback_func;
+	msg->swe_num				= num_swe;
+	
+	rvf_send_trace("RVM: SWE START REQUEST", 22, rvm_swe_array[num_swe].swe_use_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID );
+
+	/* and send it to the RVM task to be treated by the RVM task */
+	/* Note: task_id is used as the destination addr_id. This is only */
+	/* true in the case of mailbox zero. Then task_id==addr_id        */
+	if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK)
+	{	rvf_free_buf( msg);
+		return RVM_INTERNAL_ERR;
+	}
+
+	return RVM_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvm_stop_swe
+**
+** Description      Called by an application to stop the specified SWE.
+**
+** Parameters:		USE_ID of the SWE to start.
+**					return path for asynchronous response
+**
+** Returns          T_RVM_RETURN:	RVM_OK if everything is ok,
+**									RVM_INVALID_PARAMETER if the USE_ID is unknown
+**									RVM_NOT_READY if the get_info function has not been specified in the database
+**												  or the SWE is not running.
+**									RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank.
+**									RVM_INTERNAL_ERR if the RVM task has not been created.
+**
+** RV2 ADDITIONAL NOTES: This now creates a RVM_STOP_MSG instead of a RVM_STOP_APPLI message.
+** both are supported in the RVM-FSM, hence the legacy concept may be reverted to easily
+*******************************************************************************/
+T_RVM_RETURN	rvm_stop_swe (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path)
+{	
+	T_RVM_STOP_MSG	*msg;
+	T_RVM_RETURN	rvm_status;
+	UINT8			num_swe;
+
+	/*
+	** Check Application is "stopable"
+	*/
+	if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_STOP_APPLI)) != RVM_OK)
+		return rvm_status;
+	
+	/* build a msg  */
+	if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_STOP_MSG), (void **)&msg) == RVF_RED )
+	{	return RVM_MEMORY_ERR;
+	}
+
+	msg->header.msg_id			= RVM_STOP_MSG;
+	msg->header.src_addr_id		= return_path.addr_id; 
+//	msg->header.callback_func	= return_path.callback_func; 
+	msg->rp.callback_func		= return_path.callback_func; 
+	msg->swe_num				= num_swe;
+	msg->status					= SWE_RUNNING;
+	
+	/* and send it to the rve mailbox to be treated by the RVM task */
+	if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK)
+	{	rvf_free_buf( msg);
+		return RVM_INTERNAL_ERR;
+	}
+
+	return RVM_OK;
+}
+
+// NOTE: this may be used to enable the terminator to uncondionally 
+// kill the Entity. Mainly, spoofing RVM.
+T_RVM_RETURN	rvm_kill_immediate (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path){	
+	T_RVM_STOP_MSG	*msg;
+	T_RVM_RETURN	rvm_status;
+	UINT8			num_swe;
+
+	/*
+	** Check Application is "stopable"
+	*/
+	if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_STOP_APPLI)) != RVM_OK)
+		return rvm_status;
+	
+	/* build a msg  */
+	if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_STOP_MSG), (void **)&msg) == RVF_RED )
+	{	return RVM_MEMORY_ERR;
+	}
+
+	msg->header.msg_id			= RVM_STOP_MSG;
+	msg->header.src_addr_id		= return_path.addr_id; 
+//	msg->header.callback_func	= return_path.callback_func; 
+	msg->rp.callback_func		= return_path.callback_func; 
+	msg->swe_num				= num_swe;
+	msg->status					= SWE_STOPPING;
+	
+	/* and send it to the rve mailbox to be treated by the RVM task */
+	if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK)
+	{	rvf_free_buf( msg);
+		return RVM_INTERNAL_ERR;
+	}
+
+	return RVM_OK;
+}
+
+T_RVM_RETURN rvm_swe_stopped(T_RV_HDR* p_msg) {
+	T_RVM_STOP_MSG	*msg=(T_RVM_STOP_MSG*)p_msg;
+
+	msg->status					= SWE_STOPPING;
+	
+	if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK)	{
+		rvf_free_buf( msg);
+		return RVM_INTERNAL_ERR;
+	}
+	return RVM_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvm_snd_msg_to_upper
+**
+** Description      Called during processing to report to MMI the result of an
+**                  action.
+**
+** Parameters:		name of the application to start.
+**					return path for asynchronous response
+**
+** Returns          T_RVM_RETURN:	RVM_OK if everything is ok,
+**									RVM_INVALID_PARAMETER if the appli name is unknown
+**									RVM_NOT_READY if the get_info function has not been specified in the database
+**												  or the application has been already started.
+**									RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank.
+**									RVM_INTERNAL_ERR if the RVM task has not been created.
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_snd_msg_to_upper	(T_RVM_APPLI_ACTION action,
+										 T_RVM_RETURN result,
+										 UINT8 swe_num,
+										 T_RV_RETURN_PATH return_path)
+{	
+	T_RVM_APPLI_RESULT		*msg;
+
+
+	/* build a msg  */
+	if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_APPLI_RESULT), (void **)&msg) == RVF_RED )
+	{	return RVM_MEMORY_ERR;
+	}
+
+	msg->header.msg_id			= RVM_EVT_TO_APPLI;
+	msg->header.src_addr_id		= RVM_TASK_ID;
+//	msg->header.callback_func	= return_path.callback_func; 
+	msg->rp.callback_func		= return_path.callback_func; 
+	msg->result					= result;
+	msg->action					= action;
+	msg->swe_index				= swe_num;
+
+	memcpy(msg->swe_name, rvm_swe_array[swe_num].swe_name, RVM_NAME_MAX_LEN);
+
+	/* and send it to the rve mailbox to be treated by the RVM task */
+	if (return_path.callback_func)
+	{
+		return_path.callback_func ((void*) msg);
+	}
+	else
+	{
+		if ( rvf_send_msg(return_path.addr_id, (void*)msg) != RVF_OK)
+		{	rvf_free_buf( msg);
+			return RVM_INTERNAL_ERR;
+		}
+	}
+
+	return RVM_OK;
+}
+
+
+
+/*******************************************************************************
+**
+** Function         rvm_get_swe_information
+**
+** Description      Called by a SWE to know information about another SWE.
+**
+** Parameters In:		name of the swe we want to get information about.
+**
+** Parameters Out:		State of the SWE.
+**
+** Returns          T_RVM_RETURN:	RVM_OK if everything is ok,
+**									RVM_INVALID_PARAMETER if the SWE use_id is unknown
+**									RVM_NOT_READY if the 
+**									RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank.
+**									RVM_INTERNAL_ERR if the RVM task has not been created.
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_get_swe_information	(T_RVM_USE_ID swe_id, 
+										 T_RV_RETURN_PATH * return_path)
+{
+	UINT8 swe_index;
+
+	if (rvm_get_swe_index(&swe_index, swe_id) != RVM_OK)
+	{
+
+		RVM_TRACE_WARNING_PARAM("RVM API: Get SWE Information of an unknown SWE, use_id:", swe_id);
+		return RVM_INVALID_PARAMETER;
+	}
+
+	if (return_path != NULL)
+	{
+		(*return_path).callback_func	= rvm_swe_array[swe_index].swe_return_path.callback_func;
+		(*return_path).addr_id			= rvm_swe_array[swe_index].swe_addr_id;
+	}
+
+	return RVM_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_api.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,137 @@
+/**
+ *                                                                          
+ *  @file	rvm_api.h                                              
+ *                                                                          
+ *  Public interface of the Riviera Manager.
+ *
+ * @author	Cristian Livadiotti (c-livadiotti@ti.com)
+ * @version	0.2
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 06/04/2000	Cristian Livadiotti		Create.
+ * 10/18/2001	David Lamy-Charrier		Update for new Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+
+#ifndef __RVM_API_H_
+#define __RVM_API_H_
+
+#include "rv/rv_general.h"
+//#include "rvf_i.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************
+* Message type used by rvf: add, del and  Modify timers
+*******************************************************/
+#define RVM_MSG_OFFSET_PUB		BUILD_MESSAGE_OFFSET(RVM_USE_ID)
+
+#define RVM_TMS_MSG					(RVM_MSG_OFFSET_PUB | 0x004)
+#define RVF_NOTIFY_MSG				(RVM_MSG_OFFSET_PUB | 0x006)
+
+/******************************************************************/
+/* RVM functions return type and values                           */
+/******************************************************************/
+
+/* Return type */
+typedef T_RV_RET T_RVM_RETURN;
+
+
+/* RVM return parameters definition */
+#define	RVM_OK					RV_OK				
+#define	RVM_NOT_SUPPORTED		RV_NOT_SUPPORTED		
+#define	RVM_NOT_READY			RV_NOT_READY			
+#define	RVM_MEMORY_ERR			RV_MEMORY_ERR			
+#define	RVM_INTERNAL_ERR		RV_INTERNAL_ERR		
+#define	RVM_INVALID_PARAMETER	RV_INVALID_PARAMETER	
+
+
+/******************************************************************/
+/* Definition / Types related to both API functions and messages */
+/******************************************************************/
+
+/* RVM USEID definition (Unique Software Entity IDentifier)*/
+typedef UINT32 T_RVM_USE_ID;
+
+#define RVM_INVALID_USE_ID		(0)
+
+/* RVM name prototype */
+#define RVM_NAME_MAX_LEN		(10)
+typedef char T_RVM_NAME[RVM_NAME_MAX_LEN];
+
+typedef UINT32 T_RVM_VERSION;
+
+
+/***********************************************/
+/* Definition / Types related to messages only */
+/***********************************************/
+
+/* Message used as a result from a rvm_start or rv_stop function call */
+/*--------------------------------------------------------------------*/
+#define	RVM_EVT_TO_APPLI (60009) // Value of the event field in the message buffer
+
+
+/* Action field of the results message to application */
+typedef enum {
+    RVM_START_APPLI		= 0,
+    RVM_STOP_APPLI		= 1
+}T_RVM_APPLI_ACTION;
+
+
+/* structure of RVM returned message to appli */
+typedef struct
+{
+	T_RV_HDR			header;		// event field will be RVM_EVT_TO_APPLI
+	T_RV_RETURN_PATH	rp;
+	T_RVM_APPLI_ACTION	action;		// Indicates if the result is coming from a rvm_start or a rvm_stop function call
+	T_RVM_NAME			swe_name;	// Name of the SW entity
+	UINT8				swe_index;	// Number of the SW entity
+	T_RVM_RETURN		result;
+} T_RVM_APPLI_RESULT;
+
+
+
+
+/***************************************/
+/* RVM external functions declarations */
+/***************************************/
+
+/* enable init at boot up   */
+BOOLEAN			rvm_init(void);
+/* launch the creation process to start the specified SWE */
+T_RVM_RETURN	rvm_start_swe( T_RVM_USE_ID swe_id, T_RV_RETURN_PATH return_path);
+
+/* stop the specified SWE */
+T_RVM_RETURN	rvm_stop_swe( T_RVM_USE_ID swe_id, T_RV_RETURN_PATH return_path);
+T_RVM_RETURN	rvm_swe_stopped(T_RV_HDR* p_msg);
+
+/* function called to start the RV Environment */
+T_RVM_RETURN	rvm_start_environment();
+
+/* function called to get the return_path of a SWE  */
+T_RVM_RETURN	rvm_get_swe_information( T_RVM_USE_ID swe_id, 
+										 T_RV_RETURN_PATH * return_path);
+
+/* function called to get the user-friendly name of a SWE  */
+T_RVM_RETURN	rvm_get_swe_name( T_RVM_USE_ID swe_id, 
+								  T_RVM_NAME swe_name);
+
+/* function called to get the version number of a SWE  */
+T_RVM_RETURN	rvm_get_swe_version( T_RVM_USE_ID swe_id, 
+									 T_RVM_VERSION * swe_version);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __RVM_API_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_ext_priorities.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,58 @@
+
+/************************************************************************************* 
+ *                                                                                   * 
+ *  Name        rvm_ext_priorities.h                                                 * 
+ *                                                                                   * 
+ *  Function    this file priorities defintitions for basic SWEs			         * 
+ *				It includes a file                                   *
+ *                                                                                   * 
+ *  Version		0.1															         * 
+ *																			         * 
+ * 	Date       	Modification												         * 
+ *  ------------------------------------									         * 
+ *  10/11/2000	Create														         * 
+ *																			         * 
+ *	Author		Cristian Livadiotti (c-livadiotti@ti.com)					         * 
+ *																			         * 
+ * (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved         * 
+ *                                                                                   *
+ * --------------------------------------------------------------------------------- *
+ *                                                                                   *
+ *   History:                                                                        *
+ *                                                                                   *
+ *   10/18/2001 - Updated for R2D by Christophe Favergeon		                     * 
+ *                                                                                   *
+ *************************************************************************************/
+
+#ifndef __RVM_EXT_PRIORITIES_H_
+#define __RVM_EXT_PRIORITIES_H_
+
+/* PRIORITIES SETTING:                        */
+/* All user priority should be set under 250: */
+/* Higher values are reserved                 */
+
+/*
+** External Priority definitions
+** Note that RVM_EXPL_TASK_PRIORITY is used for testing purpose (refer to RTEST).
+** Hence, users have to make sure that such a priority is lower than the software
+** entity under test, not to starve the system.
+*/
+#define		RVM_EXPL_TASK_PRIORITY	(242)
+
+#define		RVM_RGUI_TASK_PRIORITY	(240)
+#define		RVM_R2D_TASK_PRIORITY	(239)
+
+
+#define		RVM_DEV1_TASK_PRIORITY	(245)
+#define		RVM_DEV2_TASK_PRIORITY	(245)
+#define		RVM_DEV3_TASK_PRIORITY	(245)
+
+#define		RVM_UVM_TASK_PRIORITY	(245)
+
+#define		RVM_BTU_TASK_PRIORITY	(248) /* was 240 */
+#define		RVM_BTUI_TASK_PRIORITY	(240)
+#define		RVM_BTA_TASK_PRIORITY	(248) /* rl: was 200 */
+#define		RVM_BTH_TASK_PRIORITY	(200)
+
+#endif /* __RVM_EXT_PRIORITIES_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_ext_use_id_list.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,55 @@
+/**
+ * @file	rvm_ext_use_id_list.h                                              
+ *                                                                          
+ * List of external SWE USE IDs.
+ *                                                                          
+ * Note on USE ID management:
+ * This file is for development SWE as well as customer SWE only.
+ * USE ID of SWE part of the standard TI releases should be in rvm_use_id_list.h
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)
+ * @version	0.1
+ */
+
+/*
+ * Revision History:																			
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ * 10/25/2001	David Lamy-Charrier		Create.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+
+#ifndef __RVM_EXT_USE_ID_LIST_H_
+#define __RVM_EXT_USE_ID_LIST_H_
+
+
+#include "rvm/rvm_use_id_list.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif  /* __RVM_EXT_USE_ID_LIST_H_ */
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_gen.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,215 @@
+/**
+ * @file	rvm_gen.h
+ * 
+ * Defines the generic types used by the Riviera Environment 
+ * and the exported function of the RVM block.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)
+ * @version	0.1
+ */
+
+/*
+ * Revision History:																			
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	19/01/2000	David Lamy-Charrier		Create.
+ *	11/20/2001	Vincent Oberle			Added BUILD_VERSION_NUMBER.
+ *										Documentation cleaning
+ *																			
+ * (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __RVM_GEN_H_
+#define __RVM_GEN_H_
+
+#ifndef _WINDOWS
+  #include "config/rv.cfg"
+#endif
+
+#include "rvf/rvf_api.h" /* for memory bank related definitions & GD*/
+#include "rvm/rvm_api.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* RVM global definitions */
+#define	T_RVM_STRING			char *
+#define	T_RVM_ERROR_TYPE		UINT32
+
+#define RVM_MAX_NB_MEM_BK		(3)
+
+#define RVM_MAX_NB_LINKED_SWE		(10)
+
+#define RVM_USED_MAILBOX		RVF_TASK_MBOX_0
+
+
+/* define the 4 SWE types */
+typedef enum 
+{	
+	RVM_SWE_TYPE_1,
+	RVM_SWE_TYPE_2,
+	RVM_SWE_TYPE_3,
+	RVM_SWE_TYPE_4
+} T_RVM_SWE_TYPE;
+
+
+/* Memory bank parameters */
+typedef struct 
+{
+	T_RVF_MB_NAME		bank_name;
+	T_RVF_MB_PARAM		initial_params;
+} T_RVM_BK_INFO;
+
+
+/* RVM callback function pointer type */
+typedef  T_RVM_RETURN (*T_RVM_CB_FUNC)(T_RVM_NAME swe_name,
+									T_RVM_RETURN error_cause,
+									T_RVM_ERROR_TYPE error_type,
+									T_RVM_STRING error_msg);
+
+/*
+ * Macro used to build the version number from the
+ * - major version number (8 bits)
+ * - minor version number (8 bits)
+ * - build number (16 bits). A 0 indicates this number is not used.
+ */
+#define BUILD_VERSION_NUMBER(major, minor, build) ( ((major & 0xFF) << 24) | \
+													((minor & 0xFF) << 16) | \
+													 (build & 0xFFFF) )
+
+/* SWE core function prototype */
+typedef  T_RVM_RETURN (*T_RVM_SWE_CORE_FUNC)(void);
+
+/* Type1 SWE info */
+typedef struct
+{
+	T_RVM_NAME				swe_name;
+	T_RVM_USE_ID			swe_use_id;
+	UINT32					version;
+	UINT8					nb_mem_bank;
+	T_RVM_BK_INFO			mem_bank[RVM_MAX_NB_MEM_BK];
+	UINT8					nb_linked_swe;
+	T_RVM_USE_ID			linked_swe_id[RVM_MAX_NB_LINKED_SWE];
+	T_RV_RETURN_PATH		return_path;
+	T_RVM_RETURN  (* set_info) (T_RVF_ADDR_ID	addr_id,
+								T_RV_RETURN_PATH return_path[],
+								T_RVF_MB_ID		bk_id_table[],
+								T_RVM_CB_FUNC	call_back_error_ft);
+	T_RVM_RETURN  (* init)  (void);
+	T_RVM_RETURN  (* start) (void);
+	T_RVM_RETURN  (* stop)	(/*T_RV_HDR* hdr*/void); //???
+	T_RVM_RETURN  (* kill)	(void);
+} T_RVM_SWE_PASSIVE_INFO;
+
+/* Type2 SWE info */
+typedef struct
+{
+	T_RVM_NAME				swe_name;
+	T_RVM_USE_ID			swe_use_id;
+	UINT16					stack_size;
+	UINT8					priority;
+	UINT32					version;
+	UINT8					nb_mem_bank;
+	T_RVM_BK_INFO			mem_bank[RVM_MAX_NB_MEM_BK];
+	UINT8					nb_linked_swe;
+	T_RVM_USE_ID			linked_swe_id[RVM_MAX_NB_LINKED_SWE];
+	T_RV_RETURN_PATH		return_path;
+	T_RVF_GD_ID				swe_group_directive;				/* A-M-E-N-D-E-D! */
+	T_RVM_RETURN  (* set_info) (T_RVF_ADDR_ID	addr_id,
+								T_RV_RETURN_PATH return_path[],
+								T_RVF_MB_ID		bk_id_table[],  /* A-M-E-N-E-D-E-D! is table or list??*/
+								T_RVM_CB_FUNC	call_back_error_ft);
+	T_RVM_RETURN  (* init)  (void);
+	T_RVM_RETURN  (* start) (void);
+	T_RVM_RETURN  (* handle_message)	(T_RV_HDR * msg);
+	T_RVM_RETURN  (* handle_timer)		(T_RV_HDR * msg);
+	T_RVM_RETURN  (* stop)	(T_RV_HDR* hdr);
+	T_RVM_RETURN  (* kill)	(void);
+} T_RVM_SWE_GROUP_MEMBER_INFO;
+
+/* Type3 SWE info */
+typedef struct
+{
+	T_RVM_NAME				swe_name;
+	T_RVM_USE_ID			swe_use_id;
+	UINT16					stack_size;
+	UINT8					priority;
+	UINT32					version;
+	UINT8					nb_mem_bank;
+	T_RVM_BK_INFO			mem_bank[RVM_MAX_NB_MEM_BK];
+	UINT8					nb_linked_swe;
+	T_RVM_USE_ID			linked_swe_id[RVM_MAX_NB_LINKED_SWE];
+	T_RV_RETURN_PATH		return_path;
+	T_RVM_RETURN  (* set_info) (T_RVF_ADDR_ID	addr_id,
+								T_RV_RETURN_PATH return_path[],
+								T_RVF_MB_ID		bk_id_table[],
+								T_RVM_CB_FUNC	call_back_error_ft);
+	T_RVM_RETURN  (* init)  (void);
+	T_RVM_RETURN  (* start) (void);
+	T_RVM_RETURN  (* handle_message)	(T_RV_HDR * msg);
+	T_RVM_RETURN  (* handle_timer)		(T_RV_HDR * msg);
+	T_RVM_RETURN  (* stop)	(T_RV_HDR* hdr);
+	T_RVM_RETURN  (* kill)	(void);
+} T_RVM_SWE_SINGLE_INFO;
+
+/* Type4 SWE info */
+typedef struct
+{
+	T_RVM_NAME				swe_name;
+	T_RVM_USE_ID			swe_use_id;
+	UINT16					stack_size;
+	UINT8					priority;
+	UINT32					version;
+	UINT8					nb_mem_bank;
+	T_RVM_BK_INFO			mem_bank[RVM_MAX_NB_MEM_BK];
+	UINT8					nb_linked_swe;
+	T_RVM_USE_ID			linked_swe_id[RVM_MAX_NB_LINKED_SWE];
+	T_RV_RETURN_PATH		return_path;
+	T_RVM_RETURN  (* set_info) (T_RVF_ADDR_ID	addr_id,
+								T_RV_RETURN_PATH return_path[],
+								T_RVF_MB_ID		bk_id_table[],
+								T_RVM_CB_FUNC	call_back_error_ft);
+	T_RVM_RETURN  (* init)  (void);
+	T_RVM_RETURN  (* core)	(void);
+	T_RVM_RETURN  (* stop)	(/*T_RV_HDR* hdr*/void); // could be removed completely except for legacy code
+	T_RVM_RETURN  (* kill)	(void);
+} T_RVM_SWE_SELF_MADE_INFO;
+
+
+/* SWE information */
+typedef struct 
+{	
+	T_RVM_SWE_TYPE			swe_type;
+
+	union
+	{	T_RVM_SWE_PASSIVE_INFO		type1;
+		T_RVM_SWE_GROUP_MEMBER_INFO type2;
+		T_RVM_SWE_SINGLE_INFO		type3;
+		T_RVM_SWE_SELF_MADE_INFO	type4;
+	} type_info;
+} T_RVM_INFO_SWE;
+
+
+/* get info function pointer type */
+typedef T_RVM_RETURN (*T_RVM_GET_INFO_FUNC) (T_RVM_INFO_SWE * param);
+
+
+/* type used in the const SWEs array */
+typedef struct t_rvm_const_swe_info
+{
+	T_RVM_USE_ID			use_id;
+	T_RVM_GET_INFO_FUNC		get_info_func;
+} T_RVM_CONST_SWE_INFO;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __RVM_GEN_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_group_swe.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,32 @@
+/**
+ *                                                                          
+ * @file	rvm_group_swe.c                                              
+ *                                                                          
+ * Define how to gather GROUP_MEMBER SWEs (type2) by group .
+ *
+ * @author	Vincent Oberle
+ * @version	0.1
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 11/19/2002	Vincent Oberle		Extracted from rvm_swe.c.
+ *																			
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+
+#include "rvm/rvm_gen.h"
+#include "rv/rv_defined_swe.h"
+#include "rvm/rvm_use_id_list.h"
+
+
+const T_RVM_USE_ID group1[] =
+{	RVM_INVALID_USE_ID
+};
+
+const T_RVM_USE_ID * RVM_TYPE2_SWE_GROUPS[] =
+{	NULL
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,351 @@
+
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvm_i.h														*/
+/*                                                                          */
+/*  Function    this file contains the definitions of internal data			*/
+/*				structures for the RVM										*/
+/*																			*/
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  20/01/2000	Create														*/
+/*																			*/
+/*	Author		David Lamy-Charrier (dlamy@tif.ti.com)						*/
+/*																			*/
+/* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef __RVM_I_H_
+#define __RVM_I_H_
+
+#ifndef _WINDOWS
+  #include "config/rv.cfg"
+  #include "config/debug.cfg"
+#endif
+
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_gen.h"
+//#include "rvf/rvf_pool_size.h"
+#include "rvm/rvm_pool_size.h"
+//#include "rv_general.h"  //??
+
+
+/* MSG MUST BE VERIFIED */
+#define RVM_MSG_OFFSET		BUILD_MESSAGE_OFFSET(RVM_USE_ID)
+
+#define RVM_START_T2_MSG			(RVM_MSG_OFFSET	| 0x001)
+#define RVM_RT_MOD_YIELD_T2_MSG		(RVM_MSG_OFFSET	| 0x002)
+#define RVM_STOP_MSG				(RVM_MSG_OFFSET	| 0x003)
+#define RVM_STOP_REQ_MSG			(RVM_MSG_OFFSET	| 0x004)
+		
+
+#define RVM_YIELD_T2_PS_TM			10
+#define RVM_YIELD_T2_PRI_MSG_CNT	10
+#define T_RVM_TASK_ID				T_RVF_G_ADDR_ID  //UINT8
+#define SYSTEM_TASK_MEM				204
+
+#define MAX_GRPS		MAX_HOSTING_TASKS
+#define MAX_COMPOSITES	MAX_PARASITES
+
+/* definitions related to the RVM as a RVF task */
+#define RVM_EXPECTED_EVENT	RVF_TASK_MBOX_0_EVT_MASK
+#define RVM_MAILBOX			RVF_TASK_MBOX_0
+
+#if (defined BLUETOOTH) || (TEST==1)
+	#define RVM_MAX_SWE_USING	(5)		/* max number of SW Entities using another one within a given appli */
+#else
+	#define RVM_MAX_SWE_USING	(3)		/* max number of SW Entities using another one within a given appli */
+#endif
+
+
+#define RVM_INVALID_SWE_INDEX		(0xff)
+
+extern T_RVF_MB_ID rvm_mem_bank;
+extern T_RVF_MB_ID rvm_sys_mem_bank;
+extern T_RVF_MB_ID rvm_timer_mem_bank;
+extern T_RVF_MB_ID rvm_tm_notify_mem_bank;
+extern T_RVF_MB_ID rvm_stack_mem_bank;
+
+/* parameters of mb in use */
+typedef struct
+{	T_RVF_MB_NAME		mb_name;
+	T_RVF_MB_PARAM		mb_initial_param;
+}T_RVM_APPLI_MB_PARAMS;
+
+
+#define RVM_INVALID_GROUP_INDEX	(0xFFFF)
+#define RVM_OWN_GROUP			(0xFFFE)
+
+
+/* list of possible event in the RVM */
+//#define		RVM_START_APPLI	(60000)
+//#define		RVM_STOP_APPLI	(60001)
+//#define		RVM_ERROR		(60002)
+
+
+typedef enum {
+    SWE_NOT_STARTED			= 0,
+    SWE_RUNNING				= 1,
+	SWE_STOPPING			= 2,
+	SWE_KILLED				= 3
+}T_RVM_SWE_STATE;
+
+
+/* structure of message  */
+typedef struct {
+	T_RV_HDR			header;
+	T_RV_RETURN_PATH	rp;
+	UINT8		swe_num;
+}T_RVM_MSG;
+
+
+/* Information about each known SWE
+   This is static information and is built at RVM initialization */
+typedef struct
+{	
+	T_RVM_NAME				swe_name;
+	T_RVM_USE_ID			swe_use_id;
+	T_RVM_GET_INFO_FUNC		swe_get_info;			/* pointer to its get_info function */
+	T_RVM_SWE_TYPE			swe_type;				/* type of the SWE */
+	T_RVF_G_ADDR_ID			swe_addr_id;			/* unique address id of the SWE */
+	UINT16					group_index;			/* for type 2 SWE, index of the hosting group in the group array. */
+	UINT16					swe_stack_size;			/* size of the task stack */
+	UINT8					swe_priority;			/* priority of the SWE */
+	T_RVM_SWE_STATE			swe_state;				/* state of the SWE */
+	T_RVF_BUFFER*			stack_ptr;			/* pointer to the stack of the task */
+	UINT8					nb_using_appli;			/* nb of application which uses this SWE */
+	UINT8					using_appli[RVM_MAX_SWE_USING]; /* pointer to each application which use this SWE */
+	T_RV_RETURN_PATH		swe_return_path;
+	T_RV_RETURN_PATH		mmi_return_path;
+}T_RVM_KNOWN_SWE;
+
+typedef struct
+{	T_RVM_SWE_STATE		host_state;
+	UINT8				task_id;
+	UINT16				nb_hosted_swe;
+	UINT16				stack_size;
+	UINT8				task_priority;
+}	T_RVM_GROUP_INFO; /* DEPRECATED! */
+
+
+/* structure containing the SWE generic functions pointers */
+typedef struct
+{	
+T_RVM_RETURN  (* set_info)	(	T_RVF_ADDR_ID	addr_id,
+								T_RV_RETURN_PATH return_path[],
+								T_RVF_MB_ID		bk_id_table[],
+								T_RVM_CB_FUNC	call_back_error_ft);
+T_RVM_RETURN  (* init)  (void);
+T_RVM_RETURN  (* start) (void);
+T_RVM_RETURN  (* handle_message)	(T_RV_HDR * msg);
+T_RVM_RETURN  (* handle_timer)		(T_RV_HDR * msg);
+T_RVM_RETURN  (* core)	(void);
+T_RVM_RETURN  (* stop)	(T_RV_HDR* hdr);
+T_RVM_RETURN  (* stop1) (void);
+T_RVM_RETURN  (* kill)	(void);
+}	T_RVM_SWE_FUNCTIONS;
+
+/*	Information about each processing SWE
+	This information is dynamic and lives during start or stop process only*/
+typedef struct _t_rvm_processing_swe
+{
+	UINT8							swe_id; // From known SWE array index
+	T_RVM_SWE_TYPE					swe_type;
+	UINT16							stack_size;
+	UINT8							priority;
+	UINT8							nb_requested_mb;
+	UINT8							nb_created_mb;
+	T_RVM_APPLI_MB_PARAMS			swe_mem_bank[RVM_MAX_NB_MEM_BK];
+	T_RVM_SWE_FUNCTIONS				rvm_functions;
+	T_RVF_MB_ID						bk_id_table[RVM_MAX_NB_MEM_BK];
+	struct _t_rvm_processing_swe	*next_swe;
+} T_RVM_PROCESSING_SWE;
+
+typedef struct {
+	T_RV_HDR	hdr;
+	UINT8		grp[MAX_PARASITES];					// to do ..... constant!
+} T_RVM_START_T2_MSG;
+
+typedef struct {
+	T_RV_HDR		header;
+	UINT8			swe_num;
+	T_RV_RETURN_PATH	rp;
+	T_RVM_SWE_STATE status;
+} T_RVM_STOP_MSG;
+
+/*typedef struct {
+	T_RV_HDR		header;
+	UINT8			swe_num;
+//	T_RVF_G_ADDR_ID	target;
+//	UINT8			attempts;
+//	T_RVM_SWE_STATE status;
+} T_RVM_STOP_REQ_MSG; */
+
+typedef struct {
+	T_RV_HDR	hdr;
+	UINT16		val;					
+} T_RVM_RT_MOD_YIELD_T2_MSG;
+
+
+/* information about groups of type2 SWE */
+#define	T_GD_ID	UINT8
+
+typedef struct {
+	T_RVM_SWE_STATE		host_state;
+	T_RVF_GD_ID			group_directive;
+	T_RVF_G_ADDR_ID		host_task_addr;
+//	UINT16				hosted_swe_addr[10];
+	UINT8				hosted_swe_db_index[MAX_PARASITES];  // to do ..... constant!
+	UINT16				stack_size;
+	UINT8				task_priority;
+}	T_RVM_GROUP_DIRECTIVE;
+
+T_RV_RET rvm_t2_proxy(void);
+T_RV_RET rvm_t3_proxy(void);
+//typedef TASKPTR rvm_proxy;
+
+/* definitions related to the RVM as a RVF task */
+#define RVM_TASK_ID			(0)
+#define RVM_PRIORITY		(220)
+
+/* To do ... should correspond to RVF definitions   */
+#define RVM_TASK			0			/* A-M-E-N-D-E-D !	*/
+#define ET2_HOST_TASK		1
+#define ET3_TASK			3
+#define ET4_TASK			4
+#define ET2_VTASK			5
+#define PRE_RV_INIT_TASK	10
+
+
+#define RVM_ERROR_MSG_MAX_LENGTH	(100)
+
+
+#define DEFAULT_TIME_SLICING	0	/* default is no time-slicing */
+
+#define RVM_STACK_SIZE			RVF_RVM_STACK_SIZE
+/*#define RVM_STACK_SIZE			(1500) */
+
+/* memory bank related definitions */
+#define RVM_PRIM_MB				"RVM_PRIM"
+#define RVM_PRIM_MB_SIZE		 RVF_RVM_MB1_SIZE  //A-M-E-N-D-E-D
+#define RVM_SYS_MB				"RVM_SYS"
+#define RVM_SYS_MB_SIZE			 RVF_RVM_MB3_SIZE
+#define RVM_TIMER_MB			"RVM_TIMER"
+#define RVM_TIMER_MB_SIZE		 RVF_RVM_MB4_SIZE
+#define RVM_NOTIFY_MB			"RVM_NOTIFY"
+#define RVM_NOTIFY_MB_SIZE		 RVF_RVM_MB5_SIZE
+
+#define RVM_TIMER_MB_WATERMARK	(RVM_TIMER_MB_SIZE - 500)
+#define RVM_NOTIFY_MB_WATERMARK	(RVM_NOTIFY_MB_SIZE - 500)
+
+#if (defined BLUETOOTH) || (TEST==1) || (TI_PROFILER == 1)	|| (TI_NUC_MONITOR == 1)
+ 		#define RVM_PRIM_MB_WATERMARK	(RVM_PRIM_MB_SIZE - 1000)
+		#define RVM_SYS_MB_WATERMARK	(RVM_SYS_MB_SIZE - 1000)
+#else
+ 		#define RVM_PRIM_MB_WATERMARK	(RVM_PRIM_MB_SIZE - 100)
+		#define RVM_SYS_MB_WATERMARK	(RVM_SYS_MB_SIZE - 100)
+#endif
+  
+#define RVM_STACK_MB			"RVM_STACKS"
+#define RVM_STACK_MB_SIZE		(RVM_STACK_SIZE + RVF_RVM_MB2_SIZE)
+#define RVM_STACK_MB_WATERMARK	RVM_STACK_MB_SIZE
+
+
+
+/***************************************/
+/* RVM Internal functions declarations */
+/***************************************/
+/* function called from rvm_task.c in order to check if an application is startable or stoppable*/
+
+
+/* functions declarations */
+T_RVM_RETURN	rvm_check_application	(T_RVM_USE_ID swe_use_id, UINT8* num_swe, T_RVM_APPLI_ACTION appli_action);
+
+T_RVM_RETURN	rvm_error ( T_RVM_NAME swe_name, T_RVM_RETURN error_cause, 
+							T_RVM_ERROR_TYPE error_type, T_RVM_STRING error_msg);
+
+
+void			rvm_task (UINT32 param);
+
+void			rvm_launch_appli( T_RVM_MSG * msg_Ptr);
+
+void			rvm_stop_appli( T_RVM_STOP_MSG * msg_Ptr);
+
+void			rvm_swe_has_stopped(T_RVM_STOP_MSG* p_msg);
+T_RVM_RETURN	rvm_dup_stop_msg(T_RVM_STOP_MSG* i_msg, T_RVM_STOP_MSG* o_msg) ;
+void			rvm_suspend_swe(UINT8 swe_index);
+T_RVM_RETURN	rvm_kill_swe(UINT8 swe_index);
+UINT8			rvm_get_mb_level(UINT8 swe_index) ;
+
+void			rvm_shut_down_appli( T_RVM_MSG * msg_Ptr);
+void			rvm_shutdown_swe(UINT8 index) ;
+
+T_RVM_TASK_ID rvm_allocate_task_id(UINT8 isRealTask);
+
+T_RVM_RETURN rvm_delete_used_memory ( T_RVM_PROCESSING_SWE * appli);
+
+T_RVM_RETURN rvm_build_swe_list(T_RVM_PROCESSING_SWE ** list, UINT8 swe_num, UINT8 mode);
+
+T_RVM_RETURN rvm_check_memory_requirement( T_RVM_PROCESSING_SWE * appli); // deprected !
+T_RVM_RETURN rvm_verify_memory_requirement( T_RVM_PROCESSING_SWE * appli,\
+										    T_RVM_GROUP_DIRECTIVE* gd, UINT8 cnt);
+
+T_RVM_RETURN rvm_allocate_mb( T_RVM_PROCESSING_SWE * appli);
+
+T_RVM_RETURN rvm_initialize_swe( T_RVM_PROCESSING_SWE * appli,
+										T_RVM_GROUP_DIRECTIVE* gd, 
+										UINT8 cnt);
+
+T_RVM_RETURN rvm_allocate_stack_buffer( UINT32 stack_size, T_RVF_BUFFER** stack_ptr );
+
+T_RVM_RETURN rvm_delete_created_mb (T_RVM_PROCESSING_SWE * appli);
+
+T_RVM_RETURN rvm_clean_env( T_RVM_PROCESSING_SWE * appli);
+
+T_RVM_RETURN rvm_generic_swe_core(void);
+
+T_RVM_RETURN	rvm_init_swe_db (void);
+
+T_RVM_RETURN	rvm_snd_msg_to_upper	(T_RVM_APPLI_ACTION action,
+										 T_RVM_RETURN result,
+										 UINT8 swe_num,
+										 T_RV_RETURN_PATH return_path);
+
+T_RVM_RETURN	rvm_get_swe_index( UINT8 * index, T_RVM_USE_ID swe_use_id);
+
+T_RVM_RETURN	rvm_start_group_req(T_RVF_G_ADDR_ID addrId, UINT8* addrGrp) ;
+
+/*
+** Trace Macros
+*/
+#define RVM_TRACE_ERROR(string)\
+	rvf_send_trace (string,(sizeof(string)-1),NULL_PARAM,RV_TRACE_LEVEL_ERROR,RVM_USE_ID )
+
+#define RVM_TRACE_ERROR_PARAM(string, param)\
+	rvf_send_trace (string,(sizeof(string)-1),(UINT32)param,RV_TRACE_LEVEL_ERROR,RVM_USE_ID )
+
+#define RVM_TRACE_WARNING(string)\
+	rvf_send_trace (string,(sizeof(string)-1),NULL_PARAM,RV_TRACE_LEVEL_WARNING,RVM_USE_ID )
+
+#define RVM_TRACE_WARNING_PARAM(string, param)\
+	rvf_send_trace (string,(sizeof(string)-1),(UINT32)param,RV_TRACE_LEVEL_WARNING,RVM_USE_ID )
+
+#define RVM_TRACE_DEBUG_HIGH(string)\
+	rvf_send_trace (string,(sizeof(string)-1),NULL_PARAM,RV_TRACE_LEVEL_DEBUG_HIGH,RVM_USE_ID )
+
+#define RVM_TRACE_DEBUG_HIGH_PARAM(string, param)\
+	rvf_send_trace (string,(sizeof(string)-1),(UINT32)param,RV_TRACE_LEVEL_DEBUG_HIGH,RVM_USE_ID )
+
+#define RVM_TRACE_DEBUG_LOW(string)\
+	rvf_send_trace (string,(sizeof(string)-1),NULL_PARAM,RV_TRACE_LEVEL_DEBUG_LOW,RVM_USE_ID )
+
+#define RVM_TRACE_DEBUG_LOW_PARAM(string, param)\
+	rvf_send_trace (string,(sizeof(string)-1),(UINT32)param,RV_TRACE_LEVEL_DEBUG_LOW,RVM_USE_ID )
+
+
+#endif /* __RVM_I_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_mem.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,300 @@
+/**
+ *                                                                          
+ *  @file	rvm_mem.c                                              
+ *                                                                          
+ *  This file contains the functions related to memory management within RVM.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)	
+ * @version	0.1
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 10/26/2001	David Lamy-Charrier		Create for Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#include "rvm/rvm_i.h"
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rvf/rvf_env.h"
+
+extern T_RVM_GET_INFO_FUNC RVM_SWE_GET_INFO_ARRAY[];
+
+extern T_RVM_KNOWN_SWE	* rvm_swe_array;
+
+/*******************************************************************************
+** Function         rvm_delete_used_memory
+**
+** Description      Internal function which deletes used local mem if an error
+**                  was received or at the end of the start/stop process.
+**					
+*******************************************************************************/
+T_RVM_RETURN rvm_delete_used_memory ( T_RVM_PROCESSING_SWE * appli)
+{
+	T_RVF_BUFFER_Q			buffer_to_free_q = {0, 0, 0};
+	T_RVM_PROCESSING_SWE		* cur_elem = appli;
+
+	while (cur_elem != NULL)
+	{
+		rvf_enqueue (&buffer_to_free_q, cur_elem);
+		cur_elem = cur_elem->next_swe;
+	}
+
+	while (buffer_to_free_q.p_first)
+	{
+		rvf_free_buf (rvf_dequeue (&buffer_to_free_q));
+	}
+
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+** Function         rvm_delete_created_mb
+**
+** Description      Internal function which deletes all created MB if an error
+**                  was received, or in case application has to be stopped.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_delete_created_mb (T_RVM_PROCESSING_SWE * appli)
+{
+	UINT8 mb_index;
+	T_RVM_PROCESSING_SWE * cur_elem = appli;
+	volatile T_RV_RET ret_value = RV_OK;
+	UINT8 mb_to_delete;
+
+	while (cur_elem != NULL )
+	{
+		UINT8 swe_index = cur_elem->swe_id;
+
+		/*	If more than one appli is using this SWE, cannot delete MB
+			Process to the next SWE. */
+		if (rvm_swe_array[swe_index].nb_using_appli > 1)
+		{	
+			cur_elem = cur_elem->next_swe; /* process the next SWE */ 
+			continue;
+		}
+
+		/*	If the state is running, it means that this SWE has not
+			to be stopped. */
+		if (rvm_swe_array[swe_index].swe_state == SWE_RUNNING)
+		{
+			cur_elem = cur_elem->next_swe; /* process the next SWE */
+			continue;
+		}
+
+		/* We're here:
+			- either because swe_state == SWE_NOT_STARTED => error in starting prcess
+			- either because swe_state == SWE_STOPPING => regular stopping process */
+
+		if (cur_elem->nb_created_mb == 0)
+		{
+			cur_elem = cur_elem->next_swe; /* process the next SWE */
+			continue;
+		}
+
+		mb_to_delete = cur_elem->nb_created_mb;
+
+		for( mb_index = 0; mb_index < mb_to_delete; mb_index++)
+		{
+			ret_value = rvf_delete_mb(cur_elem->swe_mem_bank[mb_index].mb_name);
+			if (ret_value != RV_OK)
+			{
+				rvf_send_trace("RVM: Error in deletion of memory bank: ", 39, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+				rvf_send_trace(cur_elem->swe_mem_bank[mb_index].mb_name, RVF_MAX_MB_LEN, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+			}
+			else
+			{
+				(cur_elem->nb_created_mb)--;
+			}
+
+			ret_value = RVM_OK;
+		}
+
+		cur_elem = cur_elem->next_swe; /* process the next SWE */ 
+	}
+
+	return ret_value;
+}
+
+/*******************************************************************************
+**
+** Function         rvm_check_memory_requirement
+**
+** Description      This function checks if there is enough memory 
+**					to start a SWE(and all the linked SWEs)
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_RETURN: RVM_OK if there is enough memory, else RVM_MEMORY_ERR.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_verify_memory_requirement( T_RVM_PROCESSING_SWE * appli,
+										    T_RVM_GROUP_DIRECTIVE* gd, 
+											UINT8 cnt) {	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	UINT32 required_mem = 0;
+	UINT32 total_mem = 0;
+	UINT32 used_mem = 0;
+	UINT8 mb_index;
+	UINT8 i=0;
+	UINT16 host_task_mem=0;
+
+
+	/* get available memory from the rvf */
+	if ( rvf_get_available_mem( &total_mem, &used_mem) != RVF_OK )
+	{	return RVM_MEMORY_ERR;
+	}
+
+	/* count required memory */
+	while (cur_swe !=NULL ) /* for each SWE */
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		/*
+		** If SWE is already running => MB already created => do nothing
+		*/
+		if (rvm_swe_array[swe_index].swe_state != SWE_RUNNING )
+		{
+			for( mb_index = 0; mb_index < cur_swe->nb_requested_mb; mb_index++) /* for each mb */
+			{	
+				required_mem += cur_swe->swe_mem_bank[mb_index].mb_initial_param.size;
+			}
+
+			/* add the necessary stack sizes */
+			/* TO DO: add the stack size for host groups not yet started */
+			if( (cur_swe->swe_type == RVM_SWE_TYPE_3)
+				|| (cur_swe->swe_type == RVM_SWE_TYPE_4) )
+/*				|| ((cur_swe->swe_type == RVM_SWE_TYPE_2) && (rvm_swe_array[swe_index].group_index == RVM_OWN_GROUP) )) */
+			{	
+				required_mem += rvm_swe_array[swe_index].swe_stack_size;
+				required_mem += SYSTEM_TASK_MEM;  /* only for type 3 & 4. A-M-E-N-D-E-D!    */
+			}
+
+		}
+		cur_swe = cur_swe->next_swe;
+	}
+
+	/* type 2 group host system and stack mem. is catered for here								*/
+	for(i=0; i<cnt; i++) host_task_mem+=gd[i].stack_size;			/* A-M-E-N-D-E-D!  */
+	host_task_mem+=(cnt*SYSTEM_TASK_MEM);
+	
+	/* compare available memory and required memory (eventually, use a percentage to improve performances) */
+	if ((required_mem+host_task_mem) + used_mem > total_mem ) { 	/* A-M-E-N-D-E-D!  */
+		RVM_TRACE_WARNING_PARAM("RVM: Memory required (incl. used): ", (UINT32)(required_mem+host_task_mem+ used_mem) );
+		RVM_TRACE_WARNING_PARAM("RVM: Total Memory available      : ", (UINT32)total_mem);
+		return RVM_MEMORY_ERR;
+	} else{
+		return RVM_OK;
+	}
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_allocate_mem
+**
+** Description      This function creates all the required memory banks or
+**					increases their size if needed, to start a SWE. 
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_RETURN: RVM_OK if all allocations are successful, 
+**					else RVM_MEMORY_ERR and it releases all the allocated memory.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_allocate_mb( T_RVM_PROCESSING_SWE * appli)
+{	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	UINT8 mb_index;
+	volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+	
+	/* for each SWE in the list */
+	while ((cur_swe != NULL ) && (rvm_ret_value == RVM_OK))
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		if (rvm_swe_array[swe_index].swe_state == SWE_NOT_STARTED) 
+			/* If the state is not SWE_RUNNING, then the MBs have to be created	*/
+		{
+			for( mb_index = 0; mb_index < cur_swe->nb_requested_mb; mb_index++) /* for each mb */
+			{	T_RVF_MB_PARAM mb_param;
+				/* add the initial size */
+				mb_param.size = cur_swe->swe_mem_bank[mb_index].mb_initial_param.size;
+				mb_param.watermark = cur_swe->swe_mem_bank[mb_index].mb_initial_param.watermark;
+
+				/* create the mb */
+				if ( mb_param.size != 0)
+				{	
+					/* create the mb */
+					if ( rvf_create_mb( cur_swe->swe_mem_bank[mb_index].mb_name, mb_param, &(cur_swe->bk_id_table[mb_index]) ) != RVF_OK)
+					{
+						/* if an error occurs */
+						rvm_ret_value = RVM_MEMORY_ERR;
+						break;
+					}
+					else
+					{
+						cur_swe->nb_created_mb++;
+					}
+				}
+			}
+		}
+
+		cur_swe = cur_swe->next_swe; /* process the next SWE */ 
+	}
+
+	if (rvm_ret_value != RVM_OK)
+		/* Something went wrong, should release all used memory */
+	{
+		rvf_send_trace("RVM: Problem in memory bank creation !!!", 40, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+		if (rvm_delete_created_mb (appli) != RVM_OK)
+		{
+			rvf_send_trace("RVM: MB deleting error!!!", 25, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+		}
+
+	}
+	return rvm_ret_value;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_allocate_stack_buffer
+**
+** Description      This function allocates a buffer for the stack of a new 
+**					task created by RVM.
+**
+** Parameters:		UINT32 stack_size: size of stack.
+**					T_RVF_BUFFER** stack_ptr: pointer to the allocated buffer.
+**
+** Returns          T_RVM_RETURN: RVM_OK if all allocation is successful, 
+**					else RVM_MEMORY_ERR.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_allocate_stack_buffer( UINT32 stack_size, T_RVF_BUFFER** stack_ptr )
+{	T_RVF_MB_PARAM mb_params;
+
+	/* increase the size of the stack MB before allocating the new buffer */
+	if( rvf_get_mb_param( RVM_STACK_MB, &mb_params) != RV_OK)
+	{	return RVM_MEMORY_ERR;
+	}
+	
+	mb_params.size		+= stack_size;
+	mb_params.watermark	+= stack_size;
+
+	if( rvf_set_mb_param( RVM_STACK_MB, &mb_params) != RV_OK)
+	{	return RVM_MEMORY_ERR;
+	}
+
+	if( rvf_get_buf( rvm_stack_mem_bank, stack_size, stack_ptr) == RVF_RED)
+	{	return RVM_MEMORY_ERR;
+	}
+	return RVM_OK;
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,75 @@
+/**
+ * @file	rvm_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
+ *	17/09/2003	Gary Totney			    Calibrated MB3 for 30 tasks
+ *
+ *
+ * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __RVM_POOL_SIZE_H_
+#define __RVM_POOL_SIZE_H_
+
+
+#ifndef _WINDOWS
+  #include "rv.cfg"	     // TEST
+  #include "debug.cfg" 	 // TI_PROFILER, TI_NUC_MONITOR
+  #include "board.cfg"    // BOARD
+  #include "swconfig.cfg" // GSMLITE
+#endif
+
+/*
+ * RVM SWE; This SWE is of course always enabled.
+ *
+ * Values used in rvm_i.h
+ */
+
+#define RVF_RVM_STACK_SIZE (1500)
+
+#if (defined BLUETOOTH) || (TEST==1) || (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+  #define RVF_RVM_MB1_SIZE (13000)
+#else
+   #if (GSMLITE)
+      #define RVF_RVM_MB1_SIZE  (1200)
+   #else
+      #define RVF_RVM_MB1_SIZE  (6000)
+   #endif
+#endif
+#define RVF_RVM_MB2_SIZE    (700)
+
+#if (GSMLITE)
+   #define RVF_RVM_MB3_SIZE	(3200)
+   #define RVF_RVM_MB4_SIZE	(0)
+   #define RVF_RVM_MB5_SIZE	(0)
+   #define RVF_RVM_COMPENSATOR_POOL_SIZE	(1000)
+#else
+   #define RVF_RVM_MB3_SIZE	(9000)
+   #define RVF_RVM_MB4_SIZE	(3000)
+   #define RVF_RVM_MB5_SIZE	(3000)
+   #define RVF_RVM_COMPENSATOR_POOL_SIZE	(12500+3000)
+#endif
+
+
+#define RVF_RVM_POOL_SIZE  (RVF_RVM_STACK_SIZE + RVF_RVM_MB1_SIZE + \
+                            RVF_RVM_MB2_SIZE + RVF_RVM_MB3_SIZE + \
+                            RVF_RVM_MB4_SIZE + RVF_RVM_MB5_SIZE +\
+                            RVF_RVM_COMPENSATOR_POOL_SIZE )
+
+
+
+#endif /*__RVM_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_priorities.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,94 @@
+
+/****************************************************************************/
+/*                                                                          */
+/*  Name        rvm_priorities.h                                            */
+/*                                                                          */
+/*  Function    this file priorities defintitions for basic SWEs			*/
+/*				It includes a file rvm_ext_priorities.h where are defined   */
+/*				"custom" priorities.
+/*                                                                          */
+/*  Version		0.1															*/
+/*																			*/
+/* 	Date       	Modification												*/
+/*  ------------------------------------									*/
+/*  10/11/2000	Create														*/
+/*																			*/
+/*	Author		Cristian Livadiotti (c-livadiotti@ti.com)					*/
+/*																			*/
+/* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved*/
+/****************************************************************************/
+
+#ifndef __RVM_PRIORITIES_H_
+#define __RVM_PRIORITIES_H_
+
+
+#include "rvm/rvm_ext_priorities.h"
+
+/* PRIORITIES SETTING:                        */
+/* All user priority should be set under 250: */
+/* Higher values are reserved                 */
+
+/*
+** Bluetooth Priorities:
+** All set to same value, except ATP (not a task) and HCI (valid on PC only)
+*/
+#define		RVM_HCI_TASK_PRIORITY			(250)
+#define		RVM_L2CAP_TASK_PRIORITY			(240)
+#define		RVM_BTCTRL_TASK_PRIORITY		(240)
+#define		RVM_RFCOMM_TASK_PRIORITY		(240)
+#define		RVM_SPP_TASK_PRIORITY			(240)
+#define		RVM_SDP_TASK_PRIORITY			(240)
+#define		RVM_HSG_TASK_PRIORITY			(240)
+#define		RVM_DUN_GW_TASK_PRIORITY		(240)
+#define		RVM_FAX_GW_TASK_PRIORITY		(240)
+#define		RVM_ATP_UART_TASK_PRIORITY		(240)
+#define		RVM_ATP_TASK_PRIORITY			(255)
+
+
+/*
+** Drivers and Services Priorities
+** Note: FFS priority should be lower than every user
+*/
+#define		RVM_SPI_TASK_PRIORITY			(39)
+#define		RVM_TTY_TASK_PRIORITY			(238)
+#define		RVM_AUDIO_TASK_PRIORITY			(245)
+#define		RVM_AUDIO_BGD_TASK_PRIORITY		(246)
+#define		RVM_RTC_TASK_PRIORITY			(248)
+#define     RVM_FFS_TASK_PRIORITY			(250)
+#define     RVM_TRACE_TASK_PRIORITY			(251) //(79)
+#define     RVM_DAR_TASK_PRIORITY			(245)
+#define		RVM_ETM_TASK_PRIORITY			(249)
+#define		RVM_LCC_TASK_PRIORITY			(246)
+#define		RVM_MKS_TASK_PRIORITY			(255)
+#define		RVM_KPD_TASK_PRIORITY			(10)
+
+#define		RVM_MPM_TASK_PRIORITY			(242)
+
+#define		RVM_RNET_WS_TASK_PRIORITY		(240)
+#define		RVM_RNET_RT_TASK_PRIORITY		(240)
+#define		RVM_DCM_TASK_PRIORITY			(240)
+#define		RVM_MFW_TASK_PRIORITY			(241)
+#define		RVM_MDL_TASK_PRIORITY           	(241)
+
+
+#define		RVM_OBIGO_TASK_PRIORITY			(242)
+#define		RVM_IMG_TASK_PRIORITY			(241)
+#define		RVM_MMS_TASK_PRIORITY	(247)
+
+/*
+** RV Test Menu and Dummy Tasks Priorities
+*/
+#define		RVM_RVTEST_MENU_TASK_PRIORITY	(240)
+#define		RVM_DUMMY_TASK_PRIORITY			(80)
+//#define		IDLE_TASK_PRIORITY				(80)  /* A-M-E-N-D-E-D! */
+#define		RVM_INVKR_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE1_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE2_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE3_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE4_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE5_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+#define		RVM_TE6_TASK_PRIORITY			(240) /* A-M-E-N-D-E-D! */
+
+#define		RVM_TMS_TASK_PRIORITY			(200) /* A-M-E-N-D-E-D! */
+#endif /* __RVM_PRIORITIES_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_swe.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,459 @@
+/*
+ * AUTOMATICALLY GENERATED FILE - DO NOT EDIT
+ *
+ * This file was generated by ./Scripts/gen_files.pl
+ * See Tools/swe_builder/Readme.txt
+* xrashmic Manually edited to fix the MMS bug 
+ */
+
+#include "rvm/rvm_gen.h"
+#include "rv/rv_defined_swe.h"
+#include "rvm/rvm_use_id_list.h"
+#include "rvm/rvm_ext_use_id_list.h"
+
+
+
+/* Extern definition of all get_info functions. */
+T_RVM_RETURN btu_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN gki_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN bth_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN btui_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rpc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rvm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rvt_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN ti_prf_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN r2d_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rtc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN ffs_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kpd_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN spi_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN lcc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rgui_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN hci_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN l2cap_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN btctrl_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rfc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN spp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN hs_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN hsg_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN sdp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN dun_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN fax_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN obx_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN opp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN ftp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN syn_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN expl_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN audio_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN etm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN dar_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mks_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mpm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN lls_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN atp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN atp_uart_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mdc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN tty_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN dcm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN dcfg_get_info(T_RVM_INFO_SWE *);
+//xrashmic 11 Apr, 2004 MMI-SPR-29099
+//Added mms swe.
+T_RVM_RETURN mms_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mfw_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN smbs_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN audio_bgd_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN img_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mdl_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rtest_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN tut_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kil_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kgc_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kcl_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kmm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN knm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN uvm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kzp_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN kpg_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN jtm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rnet_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rnet_ws_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rnet_rt_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN rnet_br_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN condat_frm_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN msme_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN msfe_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN stke_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN brse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN brae_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN phse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN mmse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN slse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN smae_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN meae_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN sece_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN sele_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN prse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN jaae_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN jase_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN emae_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN emse_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN it1e_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN it2e_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN it0e_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN uise_get_info(T_RVM_INFO_SWE *);
+T_RVM_RETURN uiae_get_info(T_RVM_INFO_SWE *);
+
+
+
+/* RVM_SWE_GET_INFO_ARRAY defines the correspondance between
+ * SWE USE_ID and get_info function.
+ */
+const T_RVM_CONST_SWE_INFO RVM_SWE_GET_INFO_ARRAY[] =
+{
+#ifdef RVM_BTU_SWE
+   { BTU_USE_ID,    btu_get_info},
+#endif
+
+#ifdef RVM_GKI_SWE
+   { GKI_USE_ID,    gki_get_info},
+#endif
+
+#ifdef RVM_BTH_SWE
+   { BTH_USE_ID,    bth_get_info},
+#endif
+
+#ifdef RVM_BTUI_SWE
+   { BTUI_USE_ID,    btui_get_info},
+#endif
+
+#ifdef RVM_RPC_SWE
+   { RPC_USE_ID,    rpc_get_info},
+#endif
+
+#ifdef RVM_RVM_SWE
+   { RVM_USE_ID,    rvm_get_info},
+#endif
+
+#ifdef RVM_RVT_SWE
+   { RVT_USE_ID,    rvt_get_info},
+#endif
+
+#ifdef RVM_TI_PRF_SWE
+   { TI_PRF_USE_ID,    ti_prf_get_info},
+#endif
+
+#ifdef RVM_R2D_SWE
+   { R2D_USE_ID,    r2d_get_info},
+#endif
+
+#ifdef RVM_RTC_SWE
+   { RTC_USE_ID,    rtc_get_info},
+#endif
+
+#ifdef RVM_FFS_SWE
+   { FFS_USE_ID,    ffs_get_info},
+#endif
+
+#ifdef RVM_KPD_SWE
+   { KPD_USE_ID,    kpd_get_info},
+#endif
+
+#ifdef RVM_SPI_SWE
+   { SPI_USE_ID,    spi_get_info},
+#endif
+
+#ifdef RVM_LCC_SWE
+   { LCC_USE_ID,    lcc_get_info},
+#endif
+
+#ifdef RVM_RGUI_SWE
+   { RGUI_USE_ID,    rgui_get_info},
+#endif
+
+#ifdef RVM_HCI_SWE
+   { HCI_USE_ID,    hci_get_info},
+#endif
+
+#ifdef RVM_L2CAP_SWE
+   { L2CAP_USE_ID,    l2cap_get_info},
+#endif
+
+#ifdef RVM_BTCTRL_SWE
+   { BTCTRL_USE_ID,    btctrl_get_info},
+#endif
+
+#ifdef RVM_RFC_SWE
+   { RFC_USE_ID,    rfc_get_info},
+#endif
+
+#ifdef RVM_SPP_SWE
+   { SPP_USE_ID,    spp_get_info},
+#endif
+
+#ifdef RVM_HS_SWE
+   { HS_USE_ID,    hs_get_info},
+#endif
+
+#ifdef RVM_HSG_SWE
+   { HSG_USE_ID,    hsg_get_info},
+#endif
+
+#ifdef RVM_SDP_SWE
+   { SDP_USE_ID,    sdp_get_info},
+#endif
+
+#ifdef RVM_DUN_SWE
+   { DUN_USE_ID,    dun_get_info},
+#endif
+
+#ifdef RVM_FAX_SWE
+   { FAX_USE_ID,    fax_get_info},
+#endif
+
+#ifdef RVM_OBX_SWE
+   { OBX_USE_ID,    obx_get_info},
+#endif
+
+#ifdef RVM_OPP_SWE
+   { OPP_USE_ID,    opp_get_info},
+#endif
+
+#ifdef RVM_FTP_SWE
+   { FTP_USE_ID,    ftp_get_info},
+#endif
+
+#ifdef RVM_SYN_SWE
+   { SYN_USE_ID,    syn_get_info},
+#endif
+
+#ifdef RVM_EXPL_SWE
+   { EXPL_USE_ID,    expl_get_info},
+#endif
+
+#ifdef RVM_AUDIO_SWE
+   { AUDIO_USE_ID,    audio_get_info},
+#endif
+
+#ifdef RVM_ETM_SWE
+   { ETM_USE_ID,    etm_get_info},
+#endif
+
+#ifdef RVM_DAR_SWE
+   { DAR_USE_ID,    dar_get_info},
+#endif
+
+#ifdef RVM_MKS_SWE
+   { MKS_USE_ID,    mks_get_info},
+#endif
+
+#ifdef RVM_MPM_SWE
+   { MPM_USE_ID,    mpm_get_info},
+#endif
+
+#ifdef RVM_LLS_SWE
+   { LLS_USE_ID,    lls_get_info},
+#endif
+
+#ifdef RVM_ATP_SWE
+   { ATP_USE_ID,    atp_get_info},
+#endif
+
+#ifdef RVM_ATP_UART_SWE
+   { ATP_UART_USE_ID,    atp_uart_get_info},
+#endif
+
+#ifdef RVM_MDC_SWE
+   { MDC_USE_ID,    mdc_get_info},
+#endif
+
+#ifdef RVM_TTY_SWE
+   { TTY_USE_ID,    tty_get_info},
+#endif
+
+#ifdef RVM_DCM_SWE
+   { DCM_USE_ID,    dcm_get_info},
+#endif
+
+#ifdef RVM_DCFG_SWE
+   { DCFG_USE_ID,    dcfg_get_info},
+#endif
+//xrashmic 11 Apr, 2004 MMI-SPR-29099
+//Added mms swe.
+#ifdef RVM_MMS_SWE
+   { MMS_USE_ID,    mms_get_info},
+#endif
+
+#ifdef RVM_MFW_SWE
+   { MFW_USE_ID,    mfw_get_info},
+#endif
+
+#ifdef RVM_SMBS_SWE
+   { SMBS_USE_ID,    smbs_get_info},
+#endif
+
+#ifdef RVM_AUDIO_BGD_SWE
+   { AUDIO_BGD_USE_ID,    audio_bgd_get_info},
+#endif
+
+#ifdef RVM_IMG_SWE
+   { IMG_USE_ID,    img_get_info},
+#endif
+
+#ifdef RVM_MDL_SWE
+   { MDL_USE_ID,    mdl_get_info},
+#endif
+
+#ifdef RVM_RTEST_SWE
+   { RTEST_USE_ID,    rtest_get_info},
+#endif
+
+#ifdef RVM_TUT_SWE
+   { TUT_USE_ID,    tut_get_info},
+#endif
+
+#ifdef RVM_KIL_SWE
+   { KIL_USE_ID,    kil_get_info},
+#endif
+
+#ifdef RVM_KGC_SWE
+   { KGC_USE_ID,    kgc_get_info},
+#endif
+
+#ifdef RVM_KCL_SWE
+   { KCL_USE_ID,    kcl_get_info},
+#endif
+
+#ifdef RVM_KMM_SWE
+   { KMM_USE_ID,    kmm_get_info},
+#endif
+
+#ifdef RVM_KNM_SWE
+   { KNM_USE_ID,    knm_get_info},
+#endif
+
+#ifdef RVM_UVM_SWE
+   { UVM_USE_ID,    uvm_get_info},
+#endif
+
+#ifdef RVM_KZP_SWE
+   { KZP_USE_ID,    kzp_get_info},
+#endif
+
+#ifdef RVM_KPG_SWE
+   { KPG_USE_ID,    kpg_get_info},
+#endif
+
+#ifdef RVM_JTM_SWE
+   { JTM_USE_ID,    jtm_get_info},
+#endif
+
+#ifdef RVM_RNET_SWE
+   { RNET_USE_ID,    rnet_get_info},
+#endif
+
+#ifdef RVM_RNET_WS_SWE
+   { RNET_WS_USE_ID,    rnet_ws_get_info},
+#endif
+
+#ifdef RVM_RNET_RT_SWE
+   { RNET_RT_USE_ID,    rnet_rt_get_info},
+#endif
+
+#ifdef RVM_RNET_BR_SWE
+   { RNET_BR_USE_ID,    rnet_br_get_info},
+#endif
+
+#ifdef RVM_CONDAT_FRM_SWE
+   { CONDAT_FRM_USE_ID,    condat_frm_get_info},
+#endif
+
+#ifdef RVM_MSME_SWE
+   { MSME_USE_ID,    msme_get_info},
+#endif
+
+#ifdef RVM_MSFE_SWE
+   { MSFE_USE_ID,    msfe_get_info},
+#endif
+
+#ifdef RVM_STKE_SWE
+   { STKE_USE_ID,    stke_get_info},
+#endif
+
+#ifdef RVM_BRSE_SWE
+   { BRSE_USE_ID,    brse_get_info},
+#endif
+
+#ifdef RVM_BRAE_SWE
+   { BRAE_USE_ID,    brae_get_info},
+#endif
+
+#ifdef RVM_PHSE_SWE
+   { PHSE_USE_ID,    phse_get_info},
+#endif
+
+#ifdef RVM_MMSE_SWE
+   { MMSE_USE_ID,    mmse_get_info},
+#endif
+
+#ifdef RVM_SLSE_SWE
+   { SLSE_USE_ID,    slse_get_info},
+#endif
+
+#ifdef RVM_SMAE_SWE
+   { SMAE_USE_ID,    smae_get_info},
+#endif
+
+#ifdef RVM_MEAE_SWE
+   { MEAE_USE_ID,    meae_get_info},
+#endif
+
+#ifdef RVM_SECE_SWE
+   { SECE_USE_ID,    sece_get_info},
+#endif
+
+#ifdef RVM_SELE_SWE
+   { SELE_USE_ID,    sele_get_info},
+#endif
+
+#ifdef RVM_PRSE_SWE
+   { PRSE_USE_ID,    prse_get_info},
+#endif
+
+#ifdef RVM_JAAE_SWE
+   { JAAE_USE_ID,    jaae_get_info},
+#endif
+
+#ifdef RVM_JASE_SWE
+   { JASE_USE_ID,    jase_get_info},
+#endif
+
+#ifdef RVM_EMAE_SWE
+   { EMAE_USE_ID,    emae_get_info},
+#endif
+
+#ifdef RVM_EMSE_SWE
+   { EMSE_USE_ID,    emse_get_info},
+#endif
+
+#ifdef RVM_IT1E_SWE
+   { IT1E_USE_ID,    it1e_get_info},
+#endif
+
+#ifdef RVM_IT2E_SWE
+   { IT2E_USE_ID,    it2e_get_info},
+#endif
+
+#ifdef RVM_IT0E_SWE
+   { IT0E_USE_ID,    it0e_get_info},
+#endif
+
+#ifdef RVM_UISE_SWE
+   { UISE_USE_ID,    uise_get_info},
+#endif
+
+#ifdef RVM_UIAE_SWE
+   { UIAE_USE_ID,    uiae_get_info},
+#endif
+
+   { RVM_INVALID_USE_ID, NULL}
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_swe_db.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,747 @@
+/**
+ *                                                                          
+ *  @file	rvm_swe_db.c                                              
+ *                                                                          
+ *  This file contains the functions related to the SW Entities
+ *	database management.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)	
+ * @version	0.2
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 01/19/2000	David Lamy-Charrier		Create.
+ * 10/22/2001	David Lamy-Charrier		Update for new Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#include "rvf/rvf_env.h"
+
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_i.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include <string.h>
+
+extern T_RVM_CONST_SWE_INFO RVM_SWE_GET_INFO_ARRAY[];
+
+extern const T_RVM_USE_ID * RVM_TYPE2_SWE_GROUPS[];
+
+
+/* id of the main rvm memory bank */
+T_RVF_MB_ID rvm_mem_bank=RVF_INVALID_MB_ID;
+T_RVF_MB_ID rvm_sys_mem_bank=RVF_INVALID_MB_ID;
+T_RVF_MB_ID rvm_timer_mem_bank=RVF_INVALID_MB_ID;
+T_RVF_MB_ID rvm_tm_notify_mem_bank=RVF_INVALID_MB_ID;
+T_RVF_MB_ID rvm_stack_mem_bank=RVF_INVALID_MB_ID;
+
+
+/* database of all SW Entities, their name, their get_info function and their links */
+T_RVM_KNOWN_SWE	* rvm_swe_array;
+
+T_RVM_GROUP_INFO * rvm_group_array;
+
+/*
+** Used task id array
+** This array allows the RVM to allocate dynamically task ids to SWEs
+** The task ids are allocated during creation.
+*/
+/*BOOLEAN rvm_allocated_task_id [MAX_RVF_TASKS];  */
+
+/*
+** Number of SW Entities known on the system
+*/
+UINT8 rvm_swe_number = 0;
+
+
+/*******************************************************************************
+** Function         rvm_init_swe_db
+**
+** Description      Internal function called once at the beginning which 
+**					initializes the SWE database from information gathered 
+**					in a const array (defined in rvm_swe.c).
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_init_swe_db ()
+{
+	UINT8 swe_cpt=0, i=0, j=0, group_cpt = 0;
+	T_RVM_INFO_SWE swe_info;
+	char rvm_trace_name[RVM_NAME_MAX_LEN+20] = "SWE Name: ";
+	
+	/* Initialize the allocated task id array */
+/*	for (i=0; i<MAX_RVF_TASKS; i++)
+	{
+		rvm_allocated_task_id[i] = FALSE;
+	}
+*/
+	/* None task ID allocated at startup except:
+	 *   - RVM_TASK_ID,
+	 *   - RVTEST_MENU_TASK_ID,
+	 *   - DUMMY_TASK_ID.
+	 *
+	 * Refer to rv_general.h.
+	 *
+	 * TO DO: Remove the last two IDs as soon as managed as SWEs. */
+/*	rvm_allocated_task_id[RVM_TASK_ID] = TRUE;   
+	
+	if ( RVTEST_MENU_TASK_ID < MAX_RVF_TASKS) 
+	{	rvm_allocated_task_id[RVTEST_MENU_TASK_ID] = TRUE;
+	}
+	
+	if ( IDLE_TASK_ID < MAX_RVF_TASKS) 
+	{	rvm_allocated_task_id[IDLE_TASK_ID] = TRUE;
+	}
+*/
+	
+	/* Get the number of known SWEs */
+	while ( ( RVM_SWE_GET_INFO_ARRAY[swe_cpt].get_info_func) != NULL)
+	{
+		swe_cpt++;
+	}
+	rvm_swe_number = swe_cpt;
+	RVM_TRACE_DEBUG_HIGH_PARAM("RVM: number of registered SWE in the system: ", rvm_swe_number);
+
+	/* Get memory for the SWEs array	*/
+	if ( rvf_get_buf( rvm_mem_bank, (swe_cpt+1)*sizeof(T_RVM_KNOWN_SWE), (T_RVF_BUFFER**)&rvm_swe_array ) == RVF_RED )
+	{	
+		RVM_TRACE_WARNING("RVM_init_swe_db: not enough memory in the RVM main memory bank for init of array");
+		return RVM_MEMORY_ERR;
+	}
+	memset(rvm_swe_array, 0, (swe_cpt+1)*sizeof(T_RVM_KNOWN_SWE));
+
+	/* call all get_info functions to gather information about the SWEs */
+	for (i=0; i<swe_cpt; i++)
+	{
+		/* Call get info fct */
+		(RVM_SWE_GET_INFO_ARRAY[i].get_info_func)(&swe_info);
+		
+		/* Init global structure */
+		rvm_swe_array[i].swe_get_info	= RVM_SWE_GET_INFO_ARRAY[i].get_info_func;
+		rvm_swe_array[i].swe_use_id		= RVM_SWE_GET_INFO_ARRAY[i].use_id;
+		rvm_swe_array[i].swe_addr_id	= RVF_INVALID_ADDR_ID;
+		rvm_swe_array[i].group_index	= RVM_OWN_GROUP;
+		rvm_swe_array[i].swe_type		= swe_info.swe_type;
+
+		switch(swe_info.swe_type)
+		{
+		case(RVM_SWE_TYPE_1):
+			{	strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type1.swe_name);
+				rvm_swe_array[i].swe_return_path.callback_func	= swe_info.type_info.type1.return_path.callback_func;
+				rvm_swe_array[i].swe_use_id = swe_info.type_info.type1.swe_use_id;
+				rvm_swe_array[i].swe_stack_size = 0;
+				rvm_swe_array[i].swe_priority = 0;
+				break;
+			}
+
+		case(RVM_SWE_TYPE_2):
+			{	strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type2.swe_name);
+				rvm_swe_array[i].swe_return_path.callback_func	= swe_info.type_info.type2.return_path.callback_func;
+				rvm_swe_array[i].swe_use_id = swe_info.type_info.type2.swe_use_id;
+				rvm_swe_array[i].swe_stack_size = swe_info.type_info.type2.stack_size;
+				rvm_swe_array[i].swe_priority = swe_info.type_info.type2.priority;
+				break;
+			}
+
+		case(RVM_SWE_TYPE_3):
+			{	strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type3.swe_name);
+				rvm_swe_array[i].swe_return_path.callback_func	= swe_info.type_info.type3.return_path.callback_func;
+				rvm_swe_array[i].swe_use_id = swe_info.type_info.type3.swe_use_id;
+				rvm_swe_array[i].swe_stack_size = swe_info.type_info.type3.stack_size;
+				rvm_swe_array[i].swe_priority = swe_info.type_info.type3.priority;
+				break;
+			}
+
+		case(RVM_SWE_TYPE_4):
+			{	strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type4.swe_name);
+				rvm_swe_array[i].swe_return_path.callback_func	= swe_info.type_info.type4.return_path.callback_func;
+				rvm_swe_array[i].swe_use_id = swe_info.type_info.type4.swe_use_id;
+				rvm_swe_array[i].swe_stack_size = swe_info.type_info.type4.stack_size;
+				rvm_swe_array[i].swe_priority = swe_info.type_info.type4.priority;
+				break;
+			}
+		}
+
+		
+		rvm_swe_array[i].swe_state = SWE_NOT_STARTED;
+		rvm_swe_array[i].stack_ptr = NULL;
+		rvm_swe_array[i].nb_using_appli = 0;
+
+		for (j=0; j<RVM_MAX_SWE_USING; j++)
+		{
+			rvm_swe_array[i].using_appli[j] = RVM_INVALID_SWE_INDEX;
+		}
+
+		rvm_swe_array[i].swe_return_path.addr_id		= RVF_INVALID_ADDR_ID;
+
+		rvm_swe_array[i].mmi_return_path.callback_func	= NULL;
+		rvm_swe_array[i].mmi_return_path.addr_id		= RVF_INVALID_ADDR_ID;
+	}
+
+	RVM_TRACE_DEBUG_HIGH("RVM init: Known SWE database built");
+
+	/* display the list of known SWEs with their name, use_id and index in the array. */
+	for (i=0; i<swe_cpt; i++)
+	{
+		strcpy(rvm_trace_name + 10, rvm_swe_array[i].swe_name);
+		rvf_send_trace(rvm_trace_name , (UINT8)strlen(rvm_trace_name), NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID );
+		RVM_TRACE_DEBUG_LOW_PARAM("SWE number:", i);
+		RVM_TRACE_DEBUG_LOW_PARAM("SWE use_id:", rvm_swe_array[i].swe_use_id);
+	}
+
+	/* initialize SWEs group array */
+	
+	/* Get the number of groups 
+	group_cpt = 0;
+	while ( (RVM_TYPE2_SWE_GROUPS[group_cpt]) != NULL)
+	{
+		i++;
+	}
+
+	// Get memory for the groups array	
+	if ( rvf_get_buf( rvm_mem_bank, (group_cpt+1)*sizeof(T_RVM_GROUP_INFO), (T_RVF_BUFFER**)&rvm_group_array ) == RVF_RED )
+	{	
+		RVM_TRACE_WARNING("RVM_build_swe_list: not enough memory in the RVM main memory bank for init of group array");
+		return RVM_MEMORY_ERR;
+	}
+	memset(rvm_group_array, 0, (group_cpt+1)*sizeof(T_RVM_GROUP_INFO));
+
+	// update the group_index of each type 2 SWE. 
+	for( i = 0; i < group_cpt; i++)
+	{	rvm_group_array[i].host_state	= SWE_NOT_STARTED;
+		rvm_group_array[i].task_id		= RVF_INVALID_TASK;	
+		rvm_group_array[i].task_priority= 255;
+		
+		if( RVM_TYPE2_SWE_GROUPS[i] != NULL)
+		{	UINT8 index;
+			j = 0;
+			while( RVM_TYPE2_SWE_GROUPS[i][j] != RVM_INVALID_USE_ID)
+			{	if( rvm_get_swe_index( &index, RVM_TYPE2_SWE_GROUPS[i][j]) == RVM_OK)
+				{	// store the host group in the SWE 
+					rvm_swe_array[index].group_index = i;
+					
+					// computes the highest stack size 
+					if( rvm_swe_array[index].swe_stack_size > rvm_group_array[i].stack_size)
+					{	rvm_group_array[i].stack_size = rvm_swe_array[index].swe_stack_size;
+					}
+
+					// computes the smallest priority 
+					if( rvm_swe_array[index].swe_priority < rvm_group_array[i].task_priority)
+					{	rvm_group_array[i].task_priority = rvm_swe_array[index].swe_priority;
+					}
+				}
+				j++;
+			}
+		}
+	}
+	*/
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+** Function         rvm_get_swe_index
+**
+** Description      Internal function which returns the index of the swe in the
+**					database of known SWEs.
+**					Returns RVM_OK if it exists, else RVM_INVALID_PARAMETER.
+*******************************************************************************/
+T_RVM_RETURN rvm_get_swe_index( UINT8 * index, T_RVM_USE_ID swe_use_id)
+{	for ( (*index) = 0; ( (*index) < rvm_swe_number) && (swe_use_id != rvm_swe_array[*index].swe_use_id) ; (*index)++);
+	if ( *index == rvm_swe_number ) /* swe use id not found */
+	{
+		*index = RVM_INVALID_SWE_INDEX;
+		return RVM_INVALID_PARAMETER;
+	}
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+** Function         rvm_check_application
+**
+** Description      Internal function which checks if a SWE can be started
+**                  or stopped, depending on appli_action parameter.
+**                  If it is the case, it returns the application number.
+*******************************************************************************/
+T_RVM_RETURN	rvm_check_application	(T_RVM_USE_ID swe_use_id, UINT8* num_swe, T_RVM_APPLI_ACTION appli_action)
+{	
+	/* check if the SWE use_id exists */
+	if (rvm_get_swe_index(num_swe, swe_use_id) != RVM_OK)
+	{	
+		return RVM_INVALID_PARAMETER;
+	}
+	
+	/* check if the get_info function is known */
+	if (rvm_swe_array[*num_swe].swe_get_info == NULL )
+	{	
+		*num_swe = 0;
+		return RVM_NOT_READY;
+	}
+
+	/* check if the appli can be started or stopped */	
+/*	if ((appli_action == RVM_START_APPLI) && ( rvm_swe_array[*num_swe].swe_state != SWE_NOT_STARTED))
+	{	
+		*num_swe = 0;
+		return RVM_NOT_READY;
+	}
+*/
+	/* If more than 1 SWE is using the application, we cannot stop it */
+/*	if (appli_action == RVM_STOP_APPLI)
+	{
+		if ( (rvm_swe_array[*num_swe].swe_state != SWE_RUNNING) || \
+			 (rvm_swe_array[*num_swe].nb_using_appli != 1) || \
+			 (rvm_swe_array[rvm_swe_array[*num_swe].using_appli[0]].swe_use_id != rvm_swe_array[*num_swe].swe_use_id) )
+		{
+			*num_swe = 0;
+			return RVM_NOT_READY;
+		}
+	}*/
+
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+** Function         rvm_unlock_swe
+**
+** Description      Internal function that sets back SWE state to NOT_STARTED
+**                  in case an error occurs or the stop process is finished
+*******************************************************************************/
+T_RVM_RETURN	rvm_unlock_swe	( T_RVM_PROCESSING_SWE * appli)
+{
+	T_RVM_PROCESSING_SWE * cur_elem = appli;
+
+	while (cur_elem)
+	{
+		UINT8 swe_index = cur_elem->swe_id;
+
+		if (rvm_swe_array[swe_index].swe_state != SWE_RUNNING)
+		{	
+			cur_elem = cur_elem->next_swe;
+			continue;
+		}
+
+		rvm_swe_array[swe_index].swe_state = SWE_NOT_STARTED;
+
+		cur_elem = cur_elem->next_swe;
+	}
+
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_build_swe_list
+**
+** Description      Build the list of SWEs required to launch the specified SWE.
+**
+** Parameters:		T_RVM_PROCESSING_SWE ** list:	list of required SWE.
+**					UINT8 swe_num:				index of the SWE to start in the array of known SWEs.
+**
+** Returns          T_RVM_RETURN
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_build_swe_list(T_RVM_PROCESSING_SWE ** list, UINT8 swe_num, UINT8 mode)
+{
+	T_RVM_PROCESSING_SWE * cur_elem = *list;
+	T_RVM_USE_ID loc_linked_swe_id[RVM_MAX_NB_LINKED_SWE];
+	UINT8* rvm_swe_to_call;
+	UINT8 rvm_current_swe_to_call = 0, rvm_last_swe_to_call = 1;
+	UINT8	swe_cpt;
+	UINT8	mb_cpt;
+	UINT8	nb_linked_swe = 0;
+	volatile T_RVM_RETURN	rvm_ret_value = RVM_OK;
+	UINT8 isRunning=0;
+
+	/* allocate a matrix to store temporarily the dependencies between SWEs */
+	if (rvf_get_buf( rvm_mem_bank, rvm_swe_number*rvm_swe_number, (void**)&rvm_swe_to_call) == RVF_RED)
+	{	
+		rvf_send_trace("RVM_build_swe_list: not enough memory in the RVM memory bank for build_swe_list process", 87, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+		return RVM_MEMORY_ERR;
+	}
+
+	rvm_swe_to_call[rvm_current_swe_to_call] = swe_num;
+
+	do
+		/* While some get_info functions has to be called. */
+	{
+		T_RVM_INFO_SWE swe_info;
+		UINT8 swe_num_i = rvm_swe_to_call[rvm_current_swe_to_call];
+
+		/* Check if SWE is running or not */
+		if (rvm_swe_array[swe_num_i].swe_state == SWE_RUNNING && mode==0) {
+			rvf_send_trace("RVM_build_swe_list: SWE already running, nb: ", 45, swe_num_i, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID );
+			rvm_current_swe_to_call++;
+			continue;
+		}
+
+		if ( rvm_swe_array[swe_num_i].swe_state == SWE_STOPPING && mode==0) {
+			rvf_send_trace("RVM_build_swe_list: SWE stopped awaiting kill, nb: ", 45, swe_num_i, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID );
+			rvm_current_swe_to_call++;
+			continue;
+		}
+
+
+
+		/* Check if SWE is already queued or not. */
+		cur_elem = *list;
+		while ( (cur_elem != NULL) && ( rvm_swe_array[cur_elem->swe_id].swe_use_id != rvm_swe_array[swe_num_i].swe_use_id) )
+		{	
+			cur_elem = cur_elem->next_swe;
+		}
+
+		if (cur_elem != NULL)
+			/* SWE was found =>	- update SWE variables and pointers
+								- go to next step of the loop. */
+		{
+			rvm_current_swe_to_call++;
+			continue;
+		}
+
+
+		/* cur_elem = NULL => SWE was not found => create its entry in the list.	*/
+
+		/* create it and call its get_info function */
+		if ( rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_PROCESSING_SWE), (void**)&cur_elem ) == RVF_RED )
+		{	
+			rvf_send_trace("RVM_build_swe_list: not enough memory in the RVM main memory bank for the SWE entry", 83, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+			rvm_ret_value = RVM_MEMORY_ERR;
+			break;
+		}
+
+		/*
+		** initialize the new entry
+		*/
+		memset(cur_elem, 0, sizeof(T_RVM_PROCESSING_SWE) );
+
+		/*
+		** Set the SWE id: index in known SWE array
+		*/
+		cur_elem->swe_id = swe_num_i;
+
+		/* call its get_info() function */
+		if ( rvm_swe_array[swe_num_i].swe_get_info(&swe_info) != RVM_OK )
+		{	
+			/*	Here an error occured in its get_info function.
+				free memory allocated for this entry and return an error. */
+			rvf_free_buf( cur_elem );
+			rvf_send_trace("RVM_build_swe_list: get_info function returns an error", 54, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			break;
+		}
+
+		cur_elem->swe_type						= swe_info.swe_type;
+		cur_elem->rvm_functions.core			= rvm_generic_swe_core;
+
+		switch( swe_info.swe_type)
+		{	
+		case ( RVM_SWE_TYPE_1):
+			{	cur_elem->rvm_functions.set_info		= swe_info.type_info.type1.set_info;
+				cur_elem->rvm_functions.init			= swe_info.type_info.type1.init;
+				cur_elem->rvm_functions.start			= swe_info.type_info.type1.start;
+				cur_elem->rvm_functions.stop1			= swe_info.type_info.type1.stop;
+				cur_elem->rvm_functions.kill			= swe_info.type_info.type1.kill;
+		
+				nb_linked_swe							= swe_info.type_info.type1.nb_linked_swe;
+				for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
+				{	loc_linked_swe_id[mb_cpt] = swe_info.type_info.type1.linked_swe_id[mb_cpt];
+				}
+
+				/* memory bank information */
+				cur_elem->nb_requested_mb				= swe_info.type_info.type1.nb_mem_bank;
+				
+				for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
+				{	
+					memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
+							swe_info.type_info.type1.mem_bank[mb_cpt].bank_name, \
+							RVF_MAX_MB_LEN);
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
+								= swe_info.type_info.type1.mem_bank[mb_cpt].initial_params.size;
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
+								= swe_info.type_info.type1.mem_bank[mb_cpt].initial_params.watermark;
+				}
+
+				break;
+			}
+		case ( RVM_SWE_TYPE_2):
+			{	cur_elem->rvm_functions.set_info		= swe_info.type_info.type2.set_info;
+				cur_elem->rvm_functions.init			= swe_info.type_info.type2.init;
+				cur_elem->rvm_functions.start			= swe_info.type_info.type2.start;
+				cur_elem->rvm_functions.stop			= swe_info.type_info.type2.stop;
+				cur_elem->rvm_functions.kill			= swe_info.type_info.type2.kill;
+				cur_elem->rvm_functions.handle_message	= swe_info.type_info.type2.handle_message;
+				cur_elem->rvm_functions.handle_timer	= swe_info.type_info.type2.handle_timer;
+
+				cur_elem->priority						= swe_info.type_info.type2.priority;
+				cur_elem->stack_size					= swe_info.type_info.type2.stack_size;
+				nb_linked_swe							= swe_info.type_info.type2.nb_linked_swe;
+				for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
+				{	loc_linked_swe_id[mb_cpt] = swe_info.type_info.type2.linked_swe_id[mb_cpt];
+				}
+
+				/* memory bank information */
+				cur_elem->nb_requested_mb				= swe_info.type_info.type2.nb_mem_bank;
+				
+				for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
+				{	
+					memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
+							swe_info.type_info.type2.mem_bank[mb_cpt].bank_name, \
+							RVF_MAX_MB_LEN);
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
+								= swe_info.type_info.type2.mem_bank[mb_cpt].initial_params.size;
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
+								= swe_info.type_info.type2.mem_bank[mb_cpt].initial_params.watermark;
+				}
+
+				break;
+			}
+		case ( RVM_SWE_TYPE_3):
+			{	cur_elem->rvm_functions.set_info		= swe_info.type_info.type3.set_info;
+				cur_elem->rvm_functions.init			= swe_info.type_info.type3.init;
+				cur_elem->rvm_functions.start			= swe_info.type_info.type3.start;
+				cur_elem->rvm_functions.stop			= swe_info.type_info.type3.stop;
+				cur_elem->rvm_functions.kill			= swe_info.type_info.type3.kill;
+				cur_elem->rvm_functions.handle_message	= swe_info.type_info.type3.handle_message;
+				cur_elem->rvm_functions.handle_timer	= swe_info.type_info.type3.handle_timer;
+
+				cur_elem->priority						= swe_info.type_info.type3.priority;
+				cur_elem->stack_size					= swe_info.type_info.type3.stack_size;
+				nb_linked_swe							= swe_info.type_info.type3.nb_linked_swe;
+				for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
+				{	loc_linked_swe_id[mb_cpt] = swe_info.type_info.type3.linked_swe_id[mb_cpt];
+				}
+
+				/* memory bank information */
+				cur_elem->nb_requested_mb				= swe_info.type_info.type3.nb_mem_bank;
+				
+				for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
+				{	
+					memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
+							swe_info.type_info.type3.mem_bank[mb_cpt].bank_name, \
+							RVF_MAX_MB_LEN);
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
+								= swe_info.type_info.type3.mem_bank[mb_cpt].initial_params.size;
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
+								= swe_info.type_info.type3.mem_bank[mb_cpt].initial_params.watermark;
+				}
+
+				break;
+			}
+		case ( RVM_SWE_TYPE_4):
+			{	cur_elem->rvm_functions.set_info		= swe_info.type_info.type4.set_info;
+				cur_elem->rvm_functions.init			= swe_info.type_info.type4.init;
+				cur_elem->rvm_functions.stop1			= swe_info.type_info.type4.stop;
+				cur_elem->rvm_functions.kill			= swe_info.type_info.type4.kill;
+				cur_elem->rvm_functions.core			= swe_info.type_info.type4.core;
+
+				cur_elem->priority						= swe_info.type_info.type4.priority;
+				cur_elem->stack_size					= swe_info.type_info.type4.stack_size;
+				nb_linked_swe							= swe_info.type_info.type4.nb_linked_swe;
+				for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
+				{	loc_linked_swe_id[mb_cpt] = swe_info.type_info.type4.linked_swe_id[mb_cpt];
+				}
+
+				/* memory bank information */
+				cur_elem->nb_requested_mb				= swe_info.type_info.type4.nb_mem_bank;
+				
+				for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
+				{	
+					memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
+							swe_info.type_info.type4.mem_bank[mb_cpt].bank_name, \
+							RVF_MAX_MB_LEN);
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
+								= swe_info.type_info.type4.mem_bank[mb_cpt].initial_params.size;
+					cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
+								= swe_info.type_info.type4.mem_bank[mb_cpt].initial_params.watermark;
+				}
+
+				break;
+			}
+		}
+
+		/* allocate a task id, if necessary. */
+/*		if ( (swe_info.swe_type == RVM_SWE_TYPE_3) 
+			||(swe_info.swe_type == RVM_SWE_TYPE_4) 
+			|| ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_swe_array[swe_num_i].group_index == RVM_OWN_GROUP) )
+			|| ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id == RVF_INVALID_TASK) ) )
+		{	
+			T_RVM_TASK_ID loc_task_id;
+			if(swe_info.swe_type==RVM_SWE_TYPE_2) loc_task_id = rvm_allocate_task_id(0);
+			else loc_task_id = rvm_allocate_task_id(1);
+
+			if (loc_task_id == RVF_INVALID_TASK)
+			{
+				rvm_ret_value = RVM_INTERNAL_ERR;
+				break;
+			}
+			if ( (swe_info.swe_type == RVM_SWE_TYPE_3) 
+				||(swe_info.swe_type == RVM_SWE_TYPE_4) 
+				|| ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_swe_array[swe_num_i].group_index == RVM_OWN_GROUP) ) )
+			{	rvm_swe_array[swe_num_i].swe_addr_id = loc_task_id;
+			}
+			else
+			{	if ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id == RVF_INVALID_TASK) )
+				{	rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id = loc_task_id;
+				}
+			}
+
+		}
+*/
+		/* Insert the element in the head of the list. */
+		if (*list == NULL)	/* the list is empty */
+		{
+			/* This element is the first of the list */
+			*list = cur_elem;
+			cur_elem->next_swe = NULL;
+		}
+		else
+		{	cur_elem->next_swe = *list;
+			*list = cur_elem;
+		}
+
+		/* Get the list of linked swe num, and put it in the array */
+		if (nb_linked_swe != 0)	{
+				for (swe_cpt = 0; swe_cpt < nb_linked_swe; swe_cpt++) {
+					if (rvm_get_swe_index(&(rvm_swe_to_call[rvm_last_swe_to_call + swe_cpt]), loc_linked_swe_id[swe_cpt] ) != RVM_OK) {
+					rvm_ret_value = RVM_INVALID_PARAMETER;
+					rvf_send_trace("rvm_swe_db: Task allocation error!",35, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );	
+					break;
+				}
+			}
+				if (rvm_ret_value != RVM_OK) break;
+
+				rvm_last_swe_to_call += nb_linked_swe;
+		}
+		/* Once everything is done for current swe, increment rvm_current_swe_to_call */
+		rvm_current_swe_to_call ++;
+		
+	}
+	while (rvm_current_swe_to_call != rvm_last_swe_to_call);
+
+
+	if (rvm_ret_value != RVM_OK)
+		/* Something went wrong => undo everything	*/
+	{
+		rvm_delete_used_memory (*list);
+	}
+
+	rvf_free_buf (rvm_swe_to_call);
+	return (rvm_ret_value);
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_clean_env
+**
+** Description      This function will clean the environment.
+**                  Its main tasks are:
+**                    - Update the using_appli pointer of the SWE array
+**                    - Update states to NOT_STARTED
+**                    - Release local memory
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_OK if all allocation are successful,
+**                  else T_RVM_INTERNAL_ERR (then some SWE are not killed.)
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_clean_env( T_RVM_PROCESSING_SWE * appli)
+{	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	UINT8 appli_nb1, appli_nb2;
+	volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+	
+	/* for each SWE in the list */
+	while (cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		/* Update using_appli array	*/
+		if (rvm_swe_array[swe_index].nb_using_appli > 1)
+		{
+			for (appli_nb1 = 0; appli_nb1 < (rvm_swe_array[swe_index].nb_using_appli - 1); appli_nb1++)
+			{
+				if (rvm_swe_array[swe_index].using_appli[appli_nb1] == appli->swe_id)
+					/* appli was found in the using_appli array -> remove it and shift down the others */
+				{
+					for (appli_nb2 = appli_nb1; appli_nb2 < rvm_swe_array[swe_index].nb_using_appli; appli_nb2++)
+					{
+						rvm_swe_array[swe_index].using_appli[appli_nb2] = rvm_swe_array[swe_index].using_appli[appli_nb2 + 1];
+					}
+					/* Once using_appli pointer has been eliminated, we can exit the loop */
+					break;
+				}
+
+			}
+		}
+
+		/* Decrement nb of using applications */
+		rvm_swe_array[swe_index].nb_using_appli--;
+
+		/* Force to NULL last appli pointer	*/
+		rvm_swe_array[swe_index].using_appli[rvm_swe_array[swe_index].nb_using_appli] = RVM_INVALID_SWE_INDEX;
+
+		/* If last appli was deleted, put state back to init */
+		if (rvm_swe_array[swe_index].nb_using_appli == 0)
+		{
+			rvm_swe_array[swe_index].swe_state = SWE_NOT_STARTED;
+		}
+
+		/* Proceed to the next SWE	*/
+		cur_swe = cur_swe->next_swe;
+	}
+
+	/* Once Everything is back in stand-by, release used memory	*/
+	rvm_delete_used_memory (appli);
+
+	return rvm_ret_value;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_error
+**
+** Description      Called by a SWE in case of unrecoverable error
+**
+** Parameters:		T_RVM_NAME swe_name:
+**					T_RVM_RETURN error_cause: 
+**					T_RVM_ERROR_TYPE error_type:
+**					T_RVM_STRING error_msg:
+**
+** Returns          T_RVM_RETURN: RVM_OK if successful, else a negative value.
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_error ( T_RVM_NAME swe_name, T_RVM_RETURN error_cause, 
+							T_RVM_ERROR_TYPE error_type, T_RVM_STRING error_msg)
+{	
+	char swe_name_string[40];
+	UINT8 i=0;
+
+	memcpy(swe_name_string,"RVM: coming from: ",18);
+	memcpy((void*)((char*)swe_name_string+18),swe_name,RVM_NAME_MAX_LEN);
+
+	RVM_TRACE_WARNING("RVM: unrecoverable error indication");
+	rvf_send_trace(swe_name_string, 18 + RVM_NAME_MAX_LEN, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+	RVM_TRACE_WARNING_PARAM("RVM: Error Cause: ", error_cause);
+	RVM_TRACE_WARNING_PARAM("RVM: Error Type: ", error_type);
+	/* check the message to limit its length to RVM_ERROR_MSG_MAX_LENGTH characters. */
+	while (error_msg[i])
+	{
+		i++;
+		if (i>RVM_ERROR_MSG_MAX_LENGTH)
+			break;
+	}
+
+	rvf_send_trace(error_msg, i, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
+
+	return RVM_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_swe_hdlr.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,1251 @@
+/**
+ *                                                                          
+ *  @file	rvm_swe_hdlr.c                                              
+ *                                                                          
+ *  This file contains the functions related to SWEs management within RVM.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)	
+ * @version	0.1
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 10/26/2001	David Lamy-Charrier		Create for Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+#include <stdio.h>
+#include "rvf/rvf_env.h"
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_i.h"
+
+#include "rvf/rvf_i.h"			/* ET2 rvf private invocation API */
+#include "rvf/rvf_api.h"		/* A-M-E-N-D-E-D! */
+
+/* temporary inclusion for HCI pb on WINDOWS */
+/* TO DO: remove it. */
+#include "rvm/rvm_use_id_list.h"
+
+#include <string.h>
+
+extern T_RVM_CONST_SWE_INFO RVM_SWE_GET_INFO_ARRAY[];
+
+extern T_RVM_USE_ID * RVM_TYPE2_SWE_GROUPS[];
+
+extern BOOLEAN rvm_allocated_task_id [MAX_RVF_TASKS];
+
+extern T_RVM_KNOWN_SWE	* rvm_swe_array;
+
+
+/* private      */
+T_RVM_RETURN _fatal(T_RVM_PROCESSING_SWE* appli, UINT8 rm);
+
+/***********************************************************************
+* Function         _resolve_t2_grouping   (private)
+*
+* Description      resolves number of group directives & ret. group count
+*************************************************************************/
+UINT8 _resolve_t2_grouping(T_RVM_PROCESSING_SWE* appli, T_RVM_GROUP_DIRECTIVE* gd) {
+	T_RVM_INFO_SWE			swe_info;
+	T_RVM_PROCESSING_SWE*	cur_swe = appli;
+	UINT8 i=0, j=0, k=0;
+
+	for(; cur_swe != NULL;)	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		rvm_swe_array[swe_index].swe_get_info(&swe_info);
+
+		if (rvm_swe_array[swe_index].swe_state !=SWE_RUNNING && //== SWE_NOT_STARTED && 
+			swe_info.swe_type==RVM_SWE_TYPE_2) {
+
+			for(i=0; i<MAX_GRPS; i++) {
+				if(swe_info.type_info.type2.swe_group_directive == gd[i].group_directive) {
+					for(k=0; gd[i].hosted_swe_db_index[k]!=0; k++);
+					if(k<MAX_COMPOSITES) {
+						gd[i].hosted_swe_db_index[k]=swe_index;
+					} else {
+						/* TO DO ... ERROR !!! */
+					}
+//					RVM_TRACE_WARNING_PARAM("rvm.SweHndlr.resolve_t2_grouping(), appended to grp entry , nb=",\
+//											 (UINT32)swe_index);
+//printf("rvm.SweHndlr.resolve_t2_grouping(): appended %d to group: %d\n",gd[i].hosted_swe_db_index[k], gd[i].host_task_addr); 
+
+					break;
+				} else if(	swe_info.type_info.type2.swe_group_directive != gd[i].group_directive &&
+							gd[i].host_task_addr==0 ) {
+
+					/* Constraint! Expects all group priorites and stack sz to be equal 
+					 * Additional method must be used to set highest entity	pri. or resolve			*/
+					gd[i].host_task_addr=RVF_INVALID_ADDR_ID; //rvm_allocate_task_id(1);
+					gd[i].group_directive=swe_info.type_info.type2.swe_group_directive;	
+					gd[i].task_priority=swe_info.type_info.type2.priority;
+					gd[i].stack_size=swe_info.type_info.type2.stack_size;
+
+					gd[i].hosted_swe_db_index[0]=swe_index;
+					j++;
+//					RVM_TRACE_WARNING_PARAM("rvm.SweHndlr.resolve_t2_grouping(), created grp entry , nb=",\
+//											 (UINT32)swe_index);
+//printf("rvm.SweHndlr.resolve_t2_grouping(): created host group: %d AND append %d\n",gd[i].host_task_addr, gd[i].hosted_swe_db_index[0]); 
+					break;	
+				} 			
+			}
+
+		} else RVM_TRACE_WARNING_PARAM("rvm.SweHndlr.resolve_t2_grouping(), SWE Not type 2: ", rvm_swe_array[swe_index].swe_use_id); 
+		cur_swe = cur_swe->next_swe; /* process next SWE */
+	}
+//printf("rvm.SweHndlr.resolve_t2_grouping(): total group count: %d\n", j);
+
+//for(i=0; i<j; i++) /* de'bugger only!! */
+//	for(k=0; k<MAX_COMPOSITES && gd[i].hosted_swe_db_index[k]!=0; k++) 
+//		printf("host addr: %d, T2 swe_db_index %d\n",
+//		gd[i].host_task_addr, gd[i].hosted_swe_db_index[k]);
+
+	return j;
+}
+
+/*******************************************************************************
+** Function         rvm_allocate_task_id
+**
+** Description      Internal function which allocate the first available
+**					task id to a SWE in creation
+*******************************************************************************/
+T_RVM_TASK_ID rvm_allocate_task_id(UINT8 isRealTask) {
+/*	UINT8 i=0;	*/
+
+	/*	Find the 1st free task id
+		If we reach the max: all task ids are allocated => not possible to start SWE.*/
+	/* while (rvm_allocated_task_id[i] == TRUE)
+	{
+		i++;
+		if (i == MAX_RVF_TASKS)
+			return RVF_INVALID_TASK;
+	}*/
+
+	/* Lock task id and return its value. */
+	/* rvm_allocated_task_id[i] = TRUE; */
+	/* return ((T_RVM_TASK_ID) i); */
+	return (T_RVM_TASK_ID) rvf_allocate_task_id(isRealTask); /* A-M-E-N-D-E-D! */
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_set_swe_info
+**
+** Description      This function call the set_info function of each SWEs required 
+**					to start a specified SWE.
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_RETURN: RVM_OK if successful.
+**
+*******************************************************************************/
+T_RVM_RETURN	rvm_set_swe_info(T_RVM_PROCESSING_SWE * appli)
+{	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	UINT8 i;
+	T_RVF_MB_ID	_bk_id_table[RVM_MAX_NB_MEM_BK];
+
+	/* for each SWE in the list */
+	while( cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		if (rvm_swe_array[swe_index].swe_state != SWE_RUNNING)
+			/* Call the set_info function for only those for which MB were just created	*/
+		{
+			/* First build return path	*/
+			T_RVM_INFO_SWE		swe_info;
+			T_RV_RETURN_PATH	return_path[RVM_MAX_NB_LINKED_SWE];
+			T_RVM_USE_ID		linked_swe_use_id[RVM_MAX_NB_LINKED_SWE];
+			UINT8				nb_linked_swe = 0;
+
+			rvm_swe_array[swe_index].swe_get_info(&swe_info);
+
+			switch( swe_info.swe_type)
+			{
+			case(RVM_SWE_TYPE_1):
+				{	nb_linked_swe = swe_info.type_info.type1.nb_linked_swe;
+					memcpy( linked_swe_use_id, swe_info.type_info.type1.linked_swe_id, RVM_MAX_NB_LINKED_SWE * sizeof(T_RVM_USE_ID) );
+					if(rvm_swe_array[swe_index].swe_state != SWE_NOT_STARTED) {
+						for(i=0;i<swe_info.type_info.type1.nb_mem_bank; i++) {
+							rvf_get_mb_id((char*)&swe_info.type_info.type1.mem_bank[i],
+							&_bk_id_table[i]);
+						}
+					}
+					break;
+				}
+			case(RVM_SWE_TYPE_2):
+				{	nb_linked_swe = swe_info.type_info.type2.nb_linked_swe;
+					memcpy( linked_swe_use_id, swe_info.type_info.type2.linked_swe_id, RVM_MAX_NB_LINKED_SWE * sizeof(T_RVM_USE_ID) );
+					if((rvm_swe_array[cur_swe->swe_id].swe_addr_id = rvm_allocate_task_id(0))==RVF_INVALID_ADDR_ID) {
+						return RVM_INTERNAL_ERR;
+					}
+					if(rvm_swe_array[swe_index].swe_state != SWE_NOT_STARTED) {
+						for(i=0;i<swe_info.type_info.type2.nb_mem_bank; i++) {
+							rvf_get_mb_id((char*)&swe_info.type_info.type2.mem_bank[i],
+							&_bk_id_table[i]);
+						}
+					}
+					break;
+				}
+			case(RVM_SWE_TYPE_3):
+				{	nb_linked_swe = swe_info.type_info.type3.nb_linked_swe;
+					memcpy( linked_swe_use_id, swe_info.type_info.type3.linked_swe_id, RVM_MAX_NB_LINKED_SWE * sizeof(T_RVM_USE_ID) );
+					if((rvm_swe_array[cur_swe->swe_id].swe_addr_id = rvm_allocate_task_id(1))==RVF_INVALID_ADDR_ID) {
+						return RVM_INTERNAL_ERR;
+					}
+					if(rvm_swe_array[swe_index].swe_state != SWE_NOT_STARTED) {
+						for(i=0;i<swe_info.type_info.type3.nb_mem_bank; i++) {
+							rvf_get_mb_id((char*)&swe_info.type_info.type3.mem_bank[i],
+							&_bk_id_table[i]);
+						}					
+					}
+					break;
+				}
+			case(RVM_SWE_TYPE_4):
+				{	nb_linked_swe = swe_info.type_info.type4.nb_linked_swe;
+					memcpy( linked_swe_use_id, swe_info.type_info.type4.linked_swe_id, RVM_MAX_NB_LINKED_SWE * sizeof(T_RVM_USE_ID) );
+					if((rvm_swe_array[cur_swe->swe_id].swe_addr_id = rvm_allocate_task_id(1))==RVF_INVALID_ADDR_ID) {
+						return RVM_INTERNAL_ERR;
+					}
+					if(rvm_swe_array[swe_index].swe_state != SWE_NOT_STARTED) {
+						for(i=0;i<swe_info.type_info.type4.nb_mem_bank; i++) {
+							rvf_get_mb_id((char*)&swe_info.type_info.type4.mem_bank[i],
+							&_bk_id_table[i]);
+						}					
+					}
+					break;
+				}
+			}
+			rvm_swe_array[cur_swe->swe_id].swe_return_path.addr_id=rvm_swe_array[cur_swe->swe_id].swe_addr_id;
+
+			for (i=0; i < nb_linked_swe; i++)
+			{
+				UINT8 linked_swe_index;
+				if (rvm_get_swe_index(&linked_swe_index, linked_swe_use_id[i]) != RVM_OK)
+				{
+					return RVM_INTERNAL_ERR;
+				}
+				return_path[i].callback_func	= rvm_swe_array[linked_swe_index].swe_return_path.callback_func;
+				/* TO DO: manage addr_id for GROUP_MEMBER SWEs */
+				return_path[i].addr_id			= rvm_swe_array[linked_swe_index].swe_addr_id;
+			}
+
+
+			if (cur_swe->rvm_functions.set_info != NULL ) {
+				if(rvm_swe_array[swe_index].swe_state == SWE_NOT_STARTED) {
+				cur_swe->rvm_functions.set_info(rvm_swe_array[cur_swe->swe_id].swe_addr_id, \
+												return_path, \
+												cur_swe->bk_id_table, \
+												rvm_error);
+				} else {
+					cur_swe->rvm_functions.set_info(rvm_swe_array[cur_swe->swe_id].swe_addr_id, \
+													return_path, \
+													_bk_id_table, \
+													rvm_error);
+				}
+			}
+		}
+
+		cur_swe = cur_swe->next_swe; /* process next SWE */
+	}
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_initialize_swe
+**
+** Description      This function initialize all the required SWEs which are not running.
+**					It also creates the tasks in a suspend state.
+**					Then it resumes the tasks and call the start function of each SWE.
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_RETURN: RVM_OK if successful.
+**
+*******************************************************************************/
+T_RVM_RETURN		rvm_initialize_swe( T_RVM_PROCESSING_SWE * appli,
+										T_RVM_GROUP_DIRECTIVE* gd, 
+										UINT8 t2cnt) {	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	UINT8 i=0, j=0;
+	UINT16 tuid=0;
+	T_RVF_BUFFER* stack_ptr=NULL;
+	T_RVM_INFO_SWE swe_info;
+
+#ifdef _WINDOWS
+	BOOLEAN hci_started = FALSE;
+#endif
+
+	/* for each SWE in the list, initialize it */
+	while( cur_swe != NULL )
+	{	
+		UINT8 swe_index = cur_swe->swe_id;
+
+		if ( rvm_swe_array[swe_index].swe_state != SWE_RUNNING)
+		{
+			/* call its init function */
+			if (cur_swe->rvm_functions.init)
+			{
+				if (cur_swe->rvm_functions.init() != RVM_OK)
+				{
+					rvf_send_trace("RVM: Error Calling init function of swe nb ", 43, \
+								(UINT32)swe_index, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
+				}
+			}
+		}
+		cur_swe = cur_swe->next_swe;
+	}
+
+
+	/* for each SWE in the list, create the task if necessary. */
+	cur_swe = appli;
+	while( cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		if ( rvm_swe_array[swe_index].swe_state != SWE_RUNNING)		{
+			/* start the task if necessary in SUSPEND mode */
+
+			if ( cur_swe->swe_type == RVM_SWE_TYPE_4) {
+				/* allocate a buffer for the stack */
+				if ( rvm_allocate_stack_buffer( cur_swe->stack_size,
+					 &rvm_swe_array[swe_index].stack_ptr) != RVM_OK) {
+
+					rvf_send_trace("RVM: Error allocating stack nb:", 28, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+
+					/* TO DO: manage the error case */
+					return RVF_MEMORY_ERR;
+				}
+
+				/* start the task in suspend mode */
+				if (rvf_create_task((TASKPTR) cur_swe->rvm_functions.core, \
+									(UINT8)rvm_swe_array[swe_index].swe_addr_id,\
+									rvm_swe_array[swe_index].swe_name, \
+									rvm_swe_array[swe_index].stack_ptr, \
+									cur_swe->stack_size, \
+									cur_swe->priority, \
+									ET4_TASK,\
+									DEFAULT_TIME_SLICING, \
+									SUSPEND ) != RV_OK) {
+
+					rvf_send_trace("RVM: Error Creating Task nb:", 28, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+				}
+
+				rvf_setRtAddrSweIndex(rvm_swe_array[swe_index].swe_addr_id, 
+									  swe_index);
+
+				rvf_send_trace("RVM: Created task nb ", 21, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+
+			} else if (cur_swe->swe_type == RVM_SWE_TYPE_3) {
+				/* allocate a buffer for the stack */
+				if ( rvm_allocate_stack_buffer( cur_swe->stack_size,
+					 &rvm_swe_array[swe_index].stack_ptr) != RVM_OK) {
+
+					rvf_send_trace("RVM: Error allocating stack nb:", 28, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+					/* TO DO: manage the error case */
+					return RVF_MEMORY_ERR;
+				}
+
+				/* start the task in suspend mode */
+				if (rvf_create_task((TASKPTR)rvm_t3_proxy, \
+									(UINT8)rvm_swe_array[swe_index].swe_addr_id,\
+									rvm_swe_array[swe_index].swe_name, \
+									rvm_swe_array[swe_index].stack_ptr, \
+									cur_swe->stack_size, \
+									cur_swe->priority, \
+									ET3_TASK,\
+									DEFAULT_TIME_SLICING, \
+									SUSPEND ) != RV_OK) {
+
+					rvf_send_trace("RVM: Error Creating E3 Task nb:", 28, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+				}
+			
+				rvf_register_t3_handlers(rvm_swe_array[swe_index].swe_addr_id,
+										 cur_swe->rvm_functions.handle_message, /* traverse list hence: cur_swe->rvm_functions */
+										 cur_swe->rvm_functions.handle_timer );
+
+				rvf_setRtAddrSweIndex(rvm_swe_array[swe_index].swe_addr_id, 
+									  swe_index);
+
+				rvf_send_trace("RVM: Created task nb ", 21, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+	
+			
+			}
+		}
+		cur_swe = cur_swe->next_swe; /* process next SWE */
+	} 
+	/* resolve T2 grouping			*/
+	for(i=0; i<t2cnt; i++) {
+		gd[i].host_task_addr=rvf_resolveHostingAddrId(gd[i]);
+		if( gd[i].host_task_addr==RVF_INVALID_ADDR_ID) {
+
+		if ( rvm_allocate_stack_buffer( gd[i].stack_size, &stack_ptr) != RVM_OK){
+			/* TO DO: manage the error case - ABORT & Clean-up if one or more linked Ent. fail */
+			//break;
+			return RVF_MEMORY_ERR;
+		} 
+
+			gd[i].host_task_addr=rvm_allocate_task_id(1);
+		rvf_create_task((TASKPTR)rvm_t2_proxy,
+						gd[i].host_task_addr, //
+						"hosting_task",
+						stack_ptr,
+						gd[i].stack_size,
+						gd[i].task_priority,
+						ET2_HOST_TASK,		
+						DEFAULT_TIME_SLICING,
+						SUSPEND);
+
+			rvf_associateGrpToHost(gd[i].host_task_addr, gd[i].group_directive);
+		}  
+
+		for(j=0; j<MAX_COMPOSITES && gd[i].hosted_swe_db_index[j]!=0; j++) {
+			/* create virtual task for each "hosted_swe_db_index[]" */
+			rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_get_info(&swe_info);
+
+			rvf_create_virtual_task(swe_info.type_info.type2.handle_message,
+									swe_info.type_info.type2.handle_timer,
+									rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_addr_id,
+									gd[i].host_task_addr,
+									rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_name,
+									rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_priority,
+									ET2_VTASK);
+			rvf_setRtAddrSweIndex(rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_addr_id, 
+								  gd[i].hosted_swe_db_index[j]);
+
+			/* register	each with associate host						     */
+			rvf_registerToHost( gd[i].host_task_addr, 
+								rvm_swe_array[gd[i].hosted_swe_db_index[j]].swe_addr_id);
+		}
+	
+	}
+
+	/* resume all hosting tasks...		*/
+	for(i=0; i<t2cnt; i++) rvf_resume_task((UINT8)gd[i].host_task_addr); 
+
+	/* start composites or virtual tasks   */
+	for(i=0; i<t2cnt; i++) {
+		rvm_start_group_req((UINT8)gd[i].host_task_addr, 
+		gd[i].hosted_swe_db_index);
+	}
+
+	/* for each SWE in the list, start it if necessary. */
+	for(cur_swe = appli; cur_swe != NULL; ) {	
+		UINT8 swe_index = cur_swe->swe_id;
+
+		if ( rvm_swe_array[swe_index].swe_state != SWE_RUNNING)	{
+			/* if the SWE is a task, resume it */
+			if ( (cur_swe->swe_type == RVM_SWE_TYPE_3)
+				|| (cur_swe->swe_type == RVM_SWE_TYPE_4) ) {
+
+				/* TO DO: check the return value */
+				if(rvf_resume_task((UINT8)rvm_swe_array[swe_index].swe_addr_id )!=RVF_OK) {
+					RVM_TRACE_WARNING("RVM: ERROR! UNABLE TO RESUME SWE");
+					return RVF_INTERNAL_ERR;
+				}
+				rvf_send_trace("RVM: Resumed task nb ", 21, (UINT32)rvm_swe_array[swe_index].swe_addr_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+				rvf_send_trace("RVM: Resumed SWE ", 17, (UINT32)rvm_swe_array[swe_index].swe_use_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID);
+
+#ifdef _WINDOWS
+				if (rvm_swe_array[swe_index].swe_use_id ==  HCI_USE_ID ) {
+						hci_started = TRUE;
+				}
+#endif
+
+			} else if(cur_swe->swe_type==RVM_SWE_TYPE_1) {	/* A-M-E-N-D-E-D! */
+			
+				/* call its init function */
+				if (cur_swe->rvm_functions.start) {
+					if (cur_swe->rvm_functions.start() != RVM_OK) {
+						rvf_send_trace("RVM: Error Calling start function of swe nb ", 44, \
+									(UINT32)swe_index, RV_TRACE_LEVEL_ERROR, RVM_USE_ID);
+					}
+				}
+			}
+		}
+
+		/* increment the number of using swe and points to the using appli */
+		/* DOES NOT DEPEND ON THE STATE */
+		/*rvm_swe_array[swe_index].swe_get_info(&swe_info);
+		switch( swe_info.swe_type) {
+			case RVM_SWE_TYPE_1: 
+				if(!swe_info.type_info.type1.nb_linked_swe) rvm_swe_array[swe_index].nb_using_appli=0;
+			break;
+			case RVM_SWE_TYPE_2:
+				if(!swe_info.type_info.type2.nb_linked_swe) rvm_swe_array[swe_index].nb_using_appli=0;
+			break;
+			case RVM_SWE_TYPE_3:
+				if(!swe_info.type_info.type3.nb_linked_swe) rvm_swe_array[swe_index].nb_using_appli=0;
+			break;
+			case RVM_SWE_TYPE_4:
+				if(!swe_info.type_info.type4.nb_linked_swe) rvm_swe_array[swe_index].nb_using_appli=0;
+			break;
+			default: rvm_swe_array[swe_index].nb_using_appli=0;
+		}*/
+
+//		if(rvm_swe_array[swe_index].nb_using_appli) {
+//		rvm_swe_array[swe_index].using_appli[rvm_swe_array[swe_index].nb_using_appli++] = appli->swe_id;
+//
+//		}
+
+		if(rvm_swe_array[appli->swe_id].nb_using_appli<RVM_MAX_SWE_USING ) {
+			rvm_swe_array[appli->swe_id].using_appli[rvm_swe_array[appli->swe_id].nb_using_appli++]=swe_index;
+		} else {
+			RVM_TRACE_WARNING_PARAM("RVM: Unable to track 'Using Appli' list is full nb=", appli->swe_id);
+		}
+		
+		cur_swe = cur_swe->next_swe; /* process next SWE */
+	}
+
+	for(cur_swe=appli; cur_swe!=NULL; ) {
+		rvm_swe_array[cur_swe->swe_id].swe_state = SWE_RUNNING;
+		cur_swe = cur_swe->next_swe; 
+	}
+
+#ifdef _WINDOWS
+	if (hci_started == TRUE) {
+		rvf_delay(RVF_MS_TO_TICKS(1000));
+	}
+#endif
+
+	return RVM_OK;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_stop_swe_list
+**
+** Description      This function will call the stop functions when possible.
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_OK if all allocation are successful,
+**                  else T_RVM_INTERNAL_ERR (then some SWE are not stopped.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_stop_swe_list( T_RVM_PROCESSING_SWE * appli, T_RV_HDR* hdr)
+{	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	T_RVM_INFO_SWE swe_info;
+	volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+	T_RVM_STOP_MSG* p_msg=NULL;
+	UINT8 i=0;
+	
+
+	/* for each SWE in the list */
+	while (cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		/* If nb_using_appli > 1, SWE cannot be stopped	*/
+/*		if (rvm_swe_array[swe_index].nb_using_appli > 1) {
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+		// If nb_using_appli == 1 but using_appli != appli, SWE cannot be stopped 
+		if ((rvm_swe_array[swe_index].nb_using_appli == 1) && \
+			(rvm_swe_array[swe_index].using_appli[0] != appli->swe_id))	{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+*/
+		if (cur_swe->swe_type==RVM_SWE_TYPE_1) { //cater for de-init of lib
+			if(cur_swe->rvm_functions.stop1)cur_swe->rvm_functions.stop1();
+			if(cur_swe->rvm_functions.kill)cur_swe->rvm_functions.kill();
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+		if 	(cur_swe->swe_type==RVM_SWE_TYPE_4) { // etype 4 restriction
+			RVM_TRACE_WARNING_PARAM("RVM: Stop & Kill is not applicable to Type 4 entities, nb=", (UINT32)swe_index);
+			for (rvm_swe_array[swe_index].nb_using_appli=0,i=0; i<RVM_MAX_SWE_USING; i++) {  //reset using appli - workaround! 
+				rvm_swe_array[swe_index].using_appli[i] = RVM_INVALID_SWE_INDEX;
+			}
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+		/* Retrieve stop function with a get_info */
+		if (rvm_swe_array[swe_index].swe_get_info == NULL)
+		{
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no get info, cannot be stopped, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			continue;
+		}
+		rvm_swe_array[swe_index].swe_get_info( &swe_info);
+
+		if (cur_swe->rvm_functions.stop == NULL) {
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no stop function, cannot be stopped, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_STOP_MSG), (void **)&p_msg) == RVF_RED ) {
+			RVM_TRACE_WARNING_PARAM("RVM: Unable to create STOP msg, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		p_msg->header.msg_id			= RVM_STOP_MSG;
+		p_msg->header.src_addr_id		= hdr->src_addr_id; 
+		p_msg->header.dest_addr_id		= hdr->dest_addr_id;
+//		p_msg->header.callback_func		= hdr->callback_func; 
+		p_msg->rp.callback_func			= ((T_RVM_STOP_MSG*)hdr)->rp.callback_func;
+		p_msg->status					= SWE_STOPPING;
+		p_msg->swe_num					= swe_index; //((T_RVM_STOP_MSG*)hdr)->swe_num;
+
+		if ( rvf_send_msg( rvm_swe_array[swe_index].swe_addr_id, p_msg) != RVF_OK)	{
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		rvm_swe_array[swe_index].swe_state=SWE_STOPPING;
+
+/*printf("SHUTDOWN: SWE %s nb %d USING APPLI= %d\n",rvm_swe_array[swe_index].swe_name, swe_index, rvm_swe_array[swe_index].nb_using_appli);
+for(i=0; i<rvm_swe_array[swe_index].nb_using_appli; i++)printf(" %d, ", rvm_swe_array[swe_index].using_appli[i]);
+printf("\n");*/
+
+		for (rvm_swe_array[swe_index].nb_using_appli=0,i=0; i<RVM_MAX_SWE_USING; i++) {  //reset using appli - workaround! 
+			rvm_swe_array[swe_index].using_appli[i] = RVM_INVALID_SWE_INDEX;
+		}
+
+/*printf("SHUTDOWN: SWE %s nb %d USING APPLI= %d\n",rvm_swe_array[swe_index].swe_name, swe_index, rvm_swe_array[swe_index].nb_using_appli);
+for(i=0; i<rvm_swe_array[swe_index].nb_using_appli; i++)printf(" %d, ", rvm_swe_array[swe_index].using_appli[i]);
+printf("\n");*/
+
+		/* Stop SWE - amended to ASYNC	*/
+		/* TO DO: for type 2 and 3 SWEs, send a message to the host to call the stop function */
+		//cur_swe->rvm_functions.stop(NULL);
+
+		/* Proceed to the next SWE	*/
+		cur_swe = cur_swe->next_swe;
+	}
+
+	return rvm_ret_value;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_suspend_swe_tasks
+**
+** Description      This function will suspend all SWE that are tasks.
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_OK if all allocation are successful,
+**                  else T_RVM_INTERNAL_ERR (then some SWE are not stopped.
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_suspend_swe_tasks( T_RVM_PROCESSING_SWE * appli)
+{	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	T_RVM_INFO_SWE swe_info;
+	volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+	
+	/* for each SWE in the list */
+	while (cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		/* If nb_using_appli > 1, SWE cannot be stopped	*/
+		if (rvm_swe_array[swe_index].nb_using_appli > 1)
+		{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+		/* If nb_using_appli == 1 but using_appli != appli, SWE cannot be stopped */
+		if ((rvm_swe_array[swe_index].nb_using_appli == 1) && \
+			(rvm_swe_array[swe_index].using_appli[0] != appli->swe_id))
+		{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		/* Retrieve task info with a get_info */
+		if (rvm_swe_array[swe_index].swe_get_info == NULL)
+		{
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no get info, cannot be stopped, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			continue;
+		}
+		rvm_swe_array[swe_index].swe_get_info( &swe_info);
+
+		/* If SWE is not a task, continue */
+		/* TO DO: manage group member SWEs */
+		if ( (swe_info.swe_type == RVM_SWE_TYPE_1) ||
+			 (swe_info.swe_type == RVM_SWE_TYPE_2) )
+		{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		/* Suspend SWE task	*/
+		rvf_suspend_task( (UINT8)rvm_swe_array[swe_index].swe_return_path.addr_id);
+		RVM_TRACE_DEBUG_LOW_PARAM("RVM: Suspended task nb ", (UINT32) (rvm_swe_array[swe_index].swe_return_path.addr_id & 0x000000FF) );
+
+		/* Proceed to the next SWE */
+		cur_swe = cur_swe->next_swe;
+	}
+
+	return rvm_ret_value;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_kill_swe_list
+**
+** Description      This function will call the kill functions when possible.
+**                  It will also delete the task, the stack and the used MBs.
+**
+** Parameters:		T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
+**
+** Returns          T_RVM_OK if everything is successful,
+**                  else T_RVM_INTERNAL_ERR (then some SWE are not killed).
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_kill_swe_list( T_RVM_PROCESSING_SWE * appli)
+{	
+	T_RVM_PROCESSING_SWE * cur_swe = appli;
+	T_RVM_INFO_SWE swe_info;
+	volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+	
+	/* for each SWE in the list */
+	while (cur_swe != NULL )
+	{
+		UINT8 swe_index = cur_swe->swe_id;
+
+		/* If nb_using_appli > 1, SWE cannot be killed */
+		if (rvm_swe_array[swe_index].nb_using_appli > 1)
+		{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		/* If nb_using_appli == 1 but using_appli != appli, SWE cannot be killed */
+		if ((rvm_swe_array[swe_index].nb_using_appli == 1) && \
+			(rvm_swe_array[swe_index].using_appli[0] != appli->swe_id))
+		{
+			cur_swe = cur_swe->next_swe;
+			continue;
+		}
+
+		/* Retrieve kill function with a get_info */
+		if (rvm_swe_array[swe_index].swe_get_info == NULL)
+		{
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no get info, cannot be killed, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			continue;
+		}
+		rvm_swe_array[swe_index].swe_get_info( &swe_info);
+
+		if (cur_swe->rvm_functions.kill == NULL)
+		{
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no kill function, cannot be killed, nb=", (UINT32)swe_index);
+			cur_swe = cur_swe->next_swe;
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			continue;
+		}
+
+		/* Kill SWE	*/
+		cur_swe->rvm_functions.kill();
+		
+		/* TO DO: manage group member SWEs */
+		/* If the SWE is a task, the task should be deleted, as well as its stack */
+		if ( (swe_info.swe_type == RVM_SWE_TYPE_3) ||
+			 (swe_info.swe_type == RVM_SWE_TYPE_4) )
+		{
+			rvf_exit_task((UINT8)(rvm_swe_array[swe_index].swe_return_path.addr_id));
+ 			rvf_free_buf(rvm_swe_array[swe_index].stack_ptr);
+			RVM_TRACE_DEBUG_LOW_PARAM("RVM: Deleted task nb ", (UINT32)(rvm_swe_array[swe_index].swe_return_path.addr_id & 0x000000FF));
+			rvf_free_sys_resources(rvm_swe_array[swe_index].swe_addr_id, 2);
+
+		} else if(swe_info.swe_type == RVM_SWE_TYPE_2) {
+			rvf_free_sys_resources(rvm_swe_array[swe_index].swe_addr_id, 0);
+		}
+
+		/* Proceed to the next SWE	*/
+		cur_swe = cur_swe->next_swe;
+	}
+
+	return rvm_ret_value;
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_launch_appli
+**
+** Description      Called by the main RVM task to start a specified known application
+**
+** Parameters:		T_RVM_MSG msg: containing the return path and the index of the 
+**					application to start in the array of known SWEs.
+**
+** Returns          None
+**
+*******************************************************************************/
+void rvm_launch_appli( T_RVM_MSG * msg_Ptr) {
+	T_RVM_GROUP_DIRECTIVE GroupDirectives[MAX_GRPS]; 
+	UINT8 gdCount=0;
+	T_RVM_PROCESSING_SWE	* appli = NULL; /* pointer to the first element of the list */
+	T_RV_RETURN_PATH		appli_return_path;
+	UINT8	i,j=0;
+
+	for(i=0; i<MAX_GRPS; i++) {
+		GroupDirectives[i].group_directive=0;
+		GroupDirectives[i].host_task_addr=0;
+		GroupDirectives[i].stack_size=0;
+		memset(&GroupDirectives[i].hosted_swe_db_index, 0, (sizeof(UINT8)*MAX_COMPOSITES));
+	}
+
+	/* store the return path of the caller */
+	appli_return_path.callback_func	= msg_Ptr->rp.callback_func;
+	appli_return_path.addr_id		= msg_Ptr->header.src_addr_id;
+	
+	/* recursively call all get_info functions and build the list of running swe */	
+	if ( rvm_build_swe_list( &appli, msg_Ptr->swe_num, 0) != RVM_OK )
+	{	
+		/* Display error message
+		   error case: use the return_path to inform the caller that an error occurs*/
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_INVALID_PARAMETER, msg_Ptr->swe_num, appli_return_path);
+		RVM_TRACE_ERROR("RVM: SWE list built error");
+		return;
+	}
+
+	gdCount=_resolve_t2_grouping(appli, GroupDirectives);
+
+	if(!appli) {
+		// error case: use return_path to inform the caller about memory lack 
+		// Unlock state of SWE and free memory	
+		RVM_TRACE_WARNING_PARAM("RVM: ABORTED, Stand-alone ENTITY start request!", (UINT32)msg_Ptr->swe_num);
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_NOT_READY, msg_Ptr->swe_num, appli_return_path);
+		rvm_delete_used_memory (appli);
+		return;
+	}
+
+	RVM_TRACE_DEBUG_HIGH("RVM: SWE list built success");
+	RVM_TRACE_DEBUG_HIGH_PARAM("RVM: trying to launch SWE", rvm_swe_array[appli->swe_id].swe_use_id);
+	
+	/* check if there is enough available memory */
+	if ( rvm_verify_memory_requirement( appli, GroupDirectives, gdCount) != RVM_OK)
+	{
+		/* error case: use return_path to inform the caller about memory lack */
+		/* Unlock state of SWE and free memory	*/
+		RVM_TRACE_WARNING_PARAM("RVM: SWE not enough memory: unable to launch Appli nb", (UINT32)appli->swe_id);
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_MEMORY_ERR, msg_Ptr->swe_num, appli_return_path);
+		rvm_delete_used_memory (appli);
+		return;
+	}
+
+	/* allocates memory banks */
+	 if ( rvm_allocate_mb( appli) != RVM_OK )
+	 {	/* error case: use return_path to inform the caller about memory lack */
+		rvm_delete_used_memory (appli);
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_MEMORY_ERR, msg_Ptr->swe_num, appli_return_path);
+		RVM_TRACE_WARNING("RVM: SWE memory bank allocation error - launch aborted!");
+		return;
+	 }
+	 RVM_TRACE_DEBUG_LOW("RVM: SWE memory bank allocation success");
+
+	/* call set_info function for each SWE */
+	 if ( rvm_set_swe_info( appli) != RVM_OK)
+	 {	/* error case: use return_path to inform the caller that an error occurs */
+		RVM_TRACE_WARNING("RVM: SWE set info functions error");
+		_fatal(appli, 0);
+		rvm_delete_created_mb(appli);
+		rvm_delete_used_memory (appli);
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_INTERNAL_ERR, msg_Ptr->swe_num, appli_return_path);
+		return;
+	 }
+	 RVM_TRACE_DEBUG_LOW("RVM: SWE set info functions called");
+
+
+	 /* call the init and start functions */
+	 if ( rvm_initialize_swe( appli, GroupDirectives, gdCount) != RVM_OK)
+	 {	/* error case: use return_path to inform the caller that an error occurs */
+		RVM_TRACE_WARNING("RVM: SWE initialization error");
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_INTERNAL_ERR, msg_Ptr->swe_num, appli_return_path);
+		_fatal(appli, 2);
+		rvm_delete_created_mb(appli);
+		rvm_delete_used_memory (appli);
+		return;
+	 }
+	 RVM_TRACE_DEBUG_LOW("RVM: SWE initialization success");
+
+	 /* build a message and send the response to the caller */
+	 /* send a result using the return_path */
+	 rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_OK, msg_Ptr->swe_num, appli_return_path);
+	
+
+	 /* and store the return_path */
+	 rvm_swe_array[ msg_Ptr->swe_num ].mmi_return_path.callback_func = msg_Ptr->rp.callback_func;
+	 rvm_swe_array[ msg_Ptr->swe_num ].mmi_return_path.addr_id = msg_Ptr->header.src_addr_id;
+	 	
+	 /* Once Everything is back in stand-by, release used memory */
+	 rvm_delete_used_memory (appli);
+}
+
+
+/*******************************************************************************
+**
+** Function         rvm_shut_down_appli
+**
+** Description      Called by the main RVM task to stop a specified known application
+**
+** Parameters:		T_RVM_MSG msg: containing the return path and the index of the 
+**					application to stop in the array of known SWEs.
+**
+** Returns          None
+**
+*******************************************************************************/
+void rvm_stop_appli( T_RVM_STOP_MSG* msg_Ptr) {
+	T_RVM_PROCESSING_SWE	* appli = NULL; /* pointer to the first element of the list */
+	T_RVM_RETURN		ret_value;
+	UINT8				swe_idx = 200;
+	T_RV_RETURN_PATH	appli_return_path;
+
+	appli_return_path.callback_func = msg_Ptr->rp.callback_func;
+	appli_return_path.addr_id		= msg_Ptr->header.src_addr_id;
+	
+
+	RVM_TRACE_DEBUG_HIGH_PARAM("RVM: trying to stop Appli nb ", (UINT32)swe_idx);
+	
+	if (rvm_swe_array[msg_Ptr->swe_num].nb_using_appli > 1) {
+		RVM_TRACE_WARNING_PARAM("RVM: SWE has dependencies, nb=", (UINT32)msg_Ptr->swe_num);
+		return;
+	}
+	// ??? If nb_using_appli == 1 but using_appli != appli, SWE cannot be stopped 
+	if ((rvm_swe_array[msg_Ptr->swe_num].nb_using_appli == 1) && \
+		(rvm_swe_array[msg_Ptr->swe_num].using_appli[0] != msg_Ptr->swe_num))	{
+		RVM_TRACE_WARNING_PARAM("RVM: SWE has dependencies, nb=", (UINT32)msg_Ptr->swe_num);
+		return;
+	}
+
+
+	/* TO DO : REBUILD SWE LIST !!!! */
+	if ( rvm_build_swe_list( &appli, msg_Ptr->swe_num, 1) != RVM_OK )
+	{	
+		/* Display error message
+		   error case: use the return_path to inform the caller that an error occurs*/
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_INVALID_PARAMETER, msg_Ptr->swe_num, appli_return_path);
+		RVM_TRACE_ERROR("RVM: SWE list built error");
+		return;
+	}
+
+	/* Stop all swe in the list that are used only once	*/
+	if ((ret_value = rvm_stop_swe_list(appli, (T_RV_HDR*)msg_Ptr)) != RVM_OK )
+	{
+		/* Display error message
+		   TO DO: error case: use the return_path to inform the caller that an error occurs	*/
+		RVM_TRACE_WARNING_PARAM("RVM: Error in SWE stop", (UINT32)ret_value);
+		return;
+	}
+
+	rvm_delete_used_memory (appli);
+
+	RVM_TRACE_DEBUG_LOW("RVM: SWE stop broadcast!");
+
+}
+
+// NOTE: presently no timeout exists, if the ENT. fails to reply 
+// to stop with rvm_swe_stopped() RVM doesn't kill it.
+void rvm_swe_has_stopped(T_RVM_STOP_MSG* msg) {
+	T_RVM_STOP_MSG* p_msg=(T_RVM_STOP_MSG*)msg;
+	T_RV_RETURN_PATH	appli_return_path;
+
+	appli_return_path.callback_func = msg->rp.callback_func;
+	appli_return_path.addr_id		= msg->header.src_addr_id;
+
+	if(msg->status!=SWE_STOPPING) {
+		// inform upper of problem
+		rvm_snd_msg_to_upper(RVM_STOP_APPLI, RVM_INVALID_PARAMETER, msg->swe_num, appli_return_path);
+		RVM_TRACE_ERROR("RVM: Entity declines STOP REQ");
+		rvf_free_msg((T_RV_HDR*)msg);
+		return;
+	}
+
+	// cont. with shutdown - MUST DO ERROR CASE !
+	rvm_shutdown_swe(p_msg->swe_num);
+
+	// set stopped status
+	rvm_swe_array[p_msg->swe_num].swe_state=SWE_KILLED; //SWE_STOPPING;
+
+	/* build a message and send the response to the caller */
+	/* send a result using the return_path */
+	if(rvm_get_mb_level(p_msg->swe_num) ){
+		rvm_snd_msg_to_upper(RVM_STOP_APPLI, RV_MEMORY_REMAINING, msg->swe_num, appli_return_path);
+	} else {
+		rvm_snd_msg_to_upper(RVM_STOP_APPLI, RVM_OK, msg->swe_num, appli_return_path);
+	}
+	
+	/* and store the return_path */
+	rvm_swe_array[ msg->swe_num ].mmi_return_path.callback_func = msg->rp.callback_func;
+	rvm_swe_array[ msg->swe_num ].mmi_return_path.addr_id		= msg->header.src_addr_id;
+
+}
+
+void rvm_shutdown_swe(UINT8 index) { //should ret. ok or fail
+	rvm_suspend_swe(index);
+	rvm_kill_swe(index);
+}
+
+void rvm_suspend_swe(UINT8 swe_index) {
+		volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+		T_RVM_INFO_SWE swe_info;
+
+		/* ??? If nb_using_appli > 1, SWE cannot be stopped	
+		if (rvm_swe_array[swe_index].nb_using_appli > 1) {
+			RVM_TRACE_WARNING_PARAM("RVM-SUSPEND: SWE has dependencies, nb=", (UINT32)swe_index);
+		}
+		// ??? If nb_using_appli == 1 but using_appli != appli, SWE cannot be stopped 
+		if ((rvm_swe_array[swe_index].nb_using_appli == 1) && \
+			(rvm_swe_array[swe_index].using_appli[0] != swe_index))	{
+			RVM_TRACE_WARNING_PARAM("RVM-SUSPEND: SWE has dependencies, nb=", (UINT32)swe_index);
+		}*/
+
+		/* Retrieve task info with a get_info */
+		if (rvm_swe_array[swe_index].swe_get_info == NULL) {
+			RVM_TRACE_WARNING_PARAM("RVM: SWE with no get info, cannot be stopped, nb=", (UINT32)swe_index);
+			rvm_ret_value = RVM_INTERNAL_ERR;
+			return;
+		}
+		rvm_swe_array[swe_index].swe_get_info( &swe_info);
+
+		/* If SWE is not a task, continue */
+		/* TO DO: manage group member SWEs */
+		if ( (swe_info.swe_type == RVM_SWE_TYPE_1) ||
+			 (swe_info.swe_type == RVM_SWE_TYPE_2) ) {
+			return;
+		}
+	
+		/* Suspend SWE task	*/
+		rvf_suspend_task( (UINT8)rvm_swe_array[swe_index].swe_return_path.addr_id);
+		RVM_TRACE_DEBUG_LOW_PARAM("RVM: Suspended task nb ", (UINT32) (rvm_swe_array[swe_index].swe_return_path.addr_id & 0x000000FF) );
+}
+
+T_RVM_RETURN rvm_kill_swe(UINT8 swe_index) {
+		T_RVM_INFO_SWE swe_info;
+		volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
+		UINT8 isVirtual=0;
+		T_RVF_G_ADDR_ID	gid=RVF_INVALID_ADDR_ID;
+		UINT8 isIdle=0;
+		UINT8 i=0;
+
+		/* If nb_using_appli > 1, SWE cannot be killed 
+		if (rvm_swe_array[swe_index].nb_using_appli > 1) return rvm_ret_value;
+
+		// If nb_using_appli == 1 but using_appli != appli, SWE cannot be killed 
+		if ((rvm_swe_array[swe_index].nb_using_appli == 1) && \
+			(rvm_swe_array[swe_index].using_appli[0] != swe_index)) {
+			RVM_TRACE_WARNING_PARAM("RVM-KILL: SWE has dependencies, nb=", (UINT32)swe_index);
+			return rvm_ret_value;
+		}*/
+
+		/* Retrieve kill function with a get_info */
+		if (rvm_swe_array[swe_index].swe_get_info == NULL){
+			RVM_TRACE_WARNING_PARAM("RVM-KILL: SWE has no kill function defined, nb=", (UINT32)swe_index);
+			rvm_ret_value = RVM_INTERNAL_ERR;
+		}
+
+		rvm_swe_array[swe_index].swe_get_info(&swe_info);
+		switch( swe_info.swe_type) {
+			case RVM_SWE_TYPE_1: 
+//				if(swe_info.type_info.type1.kill) swe_info.type_info.type1.kill() ;
+				isVirtual=1;
+			break;
+			case RVM_SWE_TYPE_2:
+				gid=resolveHostAddrId(rvm_swe_array[swe_index].swe_addr_id);
+				rvf_unregisterFromHost(gid, rvm_swe_array[swe_index].swe_addr_id);
+				rvf_isHostingTaskIdle(gid, &isIdle);
+				if(isIdle) { 	// Defered suspend of hosting task: 
+					rvf_suspend_task(gid);
+					rvf_exit_task(gid);
+					rvf_free_sys_resources(gid, 2);
+				}
+				if(swe_info.type_info.type2.kill) swe_info.type_info.type2.kill();
+				isVirtual=1;
+			break;
+			case RVM_SWE_TYPE_3:
+				if(swe_info.type_info.type3.kill) swe_info.type_info.type3.kill();
+			break;
+			case RVM_SWE_TYPE_4:
+				if(swe_info.type_info.type4.kill) swe_info.type_info.type4.kill();
+			break;
+			default: 
+				RVM_TRACE_WARNING_PARAM("RVM: SWE with no kill function, cannot be killed, nb=", (UINT32)swe_index);
+		}
+
+		if(!isVirtual) {
+			rvf_exit_task((UINT8)(rvm_swe_array[swe_index].swe_return_path.addr_id));
+			rvf_free_buf(rvm_swe_array[swe_index].stack_ptr);
+			RVM_TRACE_DEBUG_LOW_PARAM("RVM: Deleted task nb ", (UINT32)(rvm_swe_array[swe_index].swe_return_path.addr_id & 0x000000FF));
+			rvf_free_sys_resources(rvm_swe_array[swe_index].swe_addr_id, 2);
+		} else {
+			rvf_free_sys_resources(rvm_swe_array[swe_index].swe_addr_id, 0);
+		}
+
+	return rvm_ret_value;
+}
+
+UINT8 rvm_get_mb_level(UINT8 swe_index) {
+	T_RVM_INFO_SWE swe_info;
+	INT8 i=0;
+	UINT8 isUsed=0;
+	
+	rvm_swe_array[swe_index].swe_get_info(&swe_info);
+		switch( swe_info.swe_type) {
+			case RVM_SWE_TYPE_1: 
+				if(swe_info.type_info.type1.nb_mem_bank!=0)
+					for(i=0; i<swe_info.type_info.type1.nb_mem_bank; i++) {
+						rvf_mb_is_used(swe_info.type_info.type1.mem_bank[i].bank_name, &isUsed);
+						if(isUsed)	return isUsed;
+					}
+			return isUsed;
+			case RVM_SWE_TYPE_2:
+				if(swe_info.type_info.type2.nb_mem_bank!=0)
+					for(i=0; i<swe_info.type_info.type2.nb_mem_bank; i++) {
+						rvf_mb_is_used(swe_info.type_info.type2.mem_bank[i].bank_name, &isUsed);
+						if(isUsed)	return isUsed;
+					}
+					return isUsed;
+			case RVM_SWE_TYPE_3:
+				if(swe_info.type_info.type3.nb_mem_bank!=0)
+					for(i=0; i<swe_info.type_info.type3.nb_mem_bank; i++) {
+						rvf_mb_is_used(swe_info.type_info.type3.mem_bank[i].bank_name, &isUsed);
+						if(isUsed)	return isUsed;
+					}
+			return isUsed;
+			case RVM_SWE_TYPE_4:
+				if(swe_info.type_info.type4.nb_mem_bank!=0)
+					for(i=0; i<swe_info.type_info.type4.nb_mem_bank; i++) {
+						rvf_mb_is_used(swe_info.type_info.type4.mem_bank[i].bank_name, &isUsed);
+						if(isUsed)	return isUsed;
+					}
+			return isUsed;
+			default: RVM_TRACE_DEBUG_LOW("RVM: Error rvm_get_mb_level()");
+			return isUsed;
+		}
+}
+
+void rvm_shut_down_appli( T_RVM_MSG * msg_Ptr) {
+	T_RVM_PROCESSING_SWE	* appli = NULL; /* pointer to the first element of the list */
+	T_RVM_RETURN		ret_value;
+	UINT8				swe_idx = 200;
+	T_RV_RETURN_PATH	appli_return_path;
+
+	
+	appli_return_path.callback_func = msg_Ptr->rp.callback_func;
+	appli_return_path.addr_id		= msg_Ptr->header.src_addr_id;
+
+
+	RVM_TRACE_DEBUG_HIGH_PARAM("RVM: trying to stop Appli nb ", (UINT32)swe_idx);
+	
+	/* TO DO : REBUILD SWE LIST !!!! */
+	if ( rvm_build_swe_list( &appli, msg_Ptr->swe_num, 1) != RVM_OK )
+	{	
+		/* Display error message
+		   error case: use the return_path to inform the caller that an error occurs*/
+		rvm_snd_msg_to_upper(RVM_START_APPLI, RVM_INVALID_PARAMETER, msg_Ptr->swe_num, appli_return_path);
+		RVM_TRACE_ERROR("RVM: SWE list built error");
+		return;
+	}
+
+	/* Stop all swe in the list that are used only once	*/
+	if ((ret_value = rvm_stop_swe_list(appli, (T_RV_HDR*)msg_Ptr)) != RVM_OK )
+	{
+		/* Display error message
+		   TO DO: error case: use the return_path to inform the caller that an error occurs	*/
+		RVM_TRACE_WARNING_PARAM("RVM: Error in SWE stop", (UINT32)ret_value);
+		return;
+	}
+	RVM_TRACE_DEBUG_LOW("RVM: SWE stop success");
+
+
+	/* Suspend all swe that are tasks */
+	if ((ret_value = rvm_suspend_swe_tasks(appli)) != RVM_OK )
+	{
+		/* Display error message
+		   TO DO: error case: use the return_path to inform the caller that an error occurs	*/
+		RVM_TRACE_WARNING_PARAM("RVM: Error in tasks suspension", (UINT32)ret_value);
+		return;
+	}
+	RVM_TRACE_DEBUG_LOW("RVM: SWE task supsended");
+
+	/* Kill all SWEs */
+	if ((ret_value = rvm_kill_swe_list(appli)) != RVM_OK)
+	{
+		/* Display error message
+		   TO DO: error case: use the return_path to inform the caller that an error occurs	*/
+		RVM_TRACE_WARNING_PARAM("RVM: Error in SWE killing", (UINT32)ret_value);
+		return;
+	}
+	RVM_TRACE_DEBUG_LOW("RVM: SWE kill success");
+
+	
+	/* Delete the swe Memory Banks */
+	rvm_delete_created_mb(appli);
+
+	/* Delete memory used and restore NOT_STARTED states */
+	if ((ret_value = rvm_clean_env(appli)) != RVM_OK)
+	{
+		/* Display error message
+		   TO DO: error case: use the return_path to inform the caller that an error occurs */
+		RVM_TRACE_WARNING_PARAM("RVM: Error in Memory cleaning", (UINT32)ret_value);
+		return;
+	}
+	RVM_TRACE_DEBUG_LOW("RVM: Memory cleaning success");
+
+
+	/* build a message and send the response to the caller */
+	/* send a result using the return_path */
+	rvm_snd_msg_to_upper(RVM_STOP_APPLI, RVM_OK, msg_Ptr->swe_num, appli_return_path);
+
+	
+	/* and store the return_path */
+	rvm_swe_array[ msg_Ptr->swe_num ].mmi_return_path.callback_func = msg_Ptr->rp.callback_func;
+	rvm_swe_array[ msg_Ptr->swe_num ].mmi_return_path.addr_id		= msg_Ptr->header.src_addr_id;
+}
+
+T_RVM_RETURN _fatal( T_RVM_PROCESSING_SWE * appli, UINT8 rm) {
+	T_RVM_PROCESSING_SWE * cur_swe =  NULL;
+//	T_RVM_INFO_SWE swe_info;
+	
+	RVM_TRACE_DEBUG_LOW("RVM: Fatality handler: reclaiming system resources!");
+	/* free all appli's system resources */
+	for (cur_swe = appli; cur_swe!=NULL; ) {
+		if(rvm_swe_array[cur_swe->swe_id].swe_state!=SWE_RUNNING)
+			rvf_free_sys_resources(rvm_swe_array[cur_swe->swe_id].swe_addr_id, rm);
+	}
+	
+
+	return RVM_OK;
+}
+
+/*******************************************************************************
+**
+** Function         rvm_generic_swe_core
+**
+** Description      This is the main task core used for GROUP_MEMBER SWEs hosting
+**					and for SINGLE SWEs.
+**
+** Parameters:		useless, may be for future evolutions if Nucleus really 
+**					supports it.
+**
+** Returns          None
+**
+*******************************************************************************/
+T_RVM_RETURN rvm_generic_swe_core(void)
+{
+   return RVM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_task.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,533 @@
+/**
+ *                                                                          
+ *  @file	rvm_task.c                                              
+ *                                                                          
+ *  This file contains the main RVN function: rvm_task.			
+	It will initialize the RVM and then wait for messages.
+ *
+ * @author	Cristian Livadiotti (c-livadiotti@ti.com)
+ * @version	0.2
+ *
+ */
+
+/*
+ * Revision History:																			
+ *
+ * 06/04/2000	Cristian Livadiotti		Create.
+ * 10/22/2001	David Lamy-Charrier		Update for new Riviera 1.6.
+ *																			
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+# include <stdio.h>
+
+#include "rvf/rvf_api.h"
+
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_api.h"
+#include "rvm/rvm_i.h"
+#include "rvf/rvf_i.h"					/* only for pRtAddrIdTable[] */
+#include "rvm/rvm_use_id_list.h"
+
+
+extern T_RVM_KNOWN_SWE	* rvm_swe_array;  /* for start() */
+
+#ifdef _CONSOLE
+	void	_callerProxy(T_RVM_APPLI_RESULT *p_msg_res) ; //A-M-E-N-D-E-D!
+#endif
+
+T_RVM_RETURN	_start_group(T_RVF_G_ADDR_ID gid, UINT8* grp);
+T_RVM_RETURN	_t3_start(T_RVF_G_ADDR_ID gid);
+T_RVM_RETURN	_stop_t2_swe(T_RVM_STOP_MSG* p_msg);
+T_RVM_RETURN	_stop_t3_swe(T_RVM_STOP_MSG* p_msg);
+
+/*******************************************************************************
+** Function         rvm_init
+**
+** Description      Initialize all the RVM
+**					
+*******************************************************************************/
+BOOLEAN rvm_init()
+{	
+	T_RVF_MB_PARAM mb_params;
+	mb_params.size		=	RVM_PRIM_MB_SIZE;
+	mb_params.watermark =	RVM_PRIM_MB_WATERMARK;
+
+	if(rvm_mem_bank!=RVF_INVALID_MB_ID) return TRUE;
+	/* create rvm main Memory Bank */
+	if ( rvf_create_mb( RVM_PRIM_MB, mb_params, &rvm_mem_bank) != RVF_OK)
+	{	
+		// TO DO: remove this call since the RVT software entity has not been started yet.
+		RVM_TRACE_ERROR( "RVM_init: unable to create the RVM Main mem bank");
+		return FALSE;
+	}
+
+	mb_params.size		= RVM_STACK_MB_SIZE;
+	mb_params.watermark = RVM_STACK_MB_WATERMARK;
+
+	/* create a second Memory Bank used for stack allocation */
+	if ( rvf_create_mb( RVM_STACK_MB, mb_params, &rvm_stack_mem_bank) != RVF_OK)
+	{	
+		// TO DO: remove this call since the RVT software entity has not been started yet.
+		RVM_TRACE_ERROR( "RVM_init: unable to create the RVM stacks mem bank");
+		return FALSE;
+	}
+
+	mb_params.size		=	RVM_SYS_MB_SIZE;
+	mb_params.watermark =	RVM_SYS_MB_WATERMARK;
+
+	if(rvm_sys_mem_bank!=RVF_INVALID_MB_ID) return TRUE;
+	/* create rvm main Memory Bank */
+	if ( rvf_create_mb( RVM_SYS_MB, mb_params, &rvm_sys_mem_bank) != RVF_OK)
+	{	
+		// TO DO: remove this call since the RVT software entity has not been started yet.
+		RVM_TRACE_ERROR( "RVM_init: unable to create the RVM SYSTEM mem bank");
+		return FALSE;
+	}
+
+	mb_params.size		=	RVM_TIMER_MB_SIZE;
+	mb_params.watermark =	RVM_TIMER_MB_WATERMARK;
+
+	if(rvm_timer_mem_bank!=RVF_INVALID_MB_ID) return TRUE;
+	// create rvm main Memory Bank 
+	if ( rvf_create_mb( RVM_TIMER_MB, mb_params, &rvm_timer_mem_bank) != RVF_OK)
+	{	
+		// TO DO: remove this call since the RVT software entity has not been started yet.
+		RVM_TRACE_ERROR( "RVM_init: unable to create the RVM TIMER mem bank");
+		return FALSE;
+	}
+
+	mb_params.size		=	RVM_NOTIFY_MB_SIZE;
+	mb_params.watermark =	RVM_NOTIFY_MB_WATERMARK;
+
+	if(rvm_tm_notify_mem_bank!=RVF_INVALID_MB_ID) return TRUE;
+	// create rvm main Memory Bank 
+	if ( rvf_create_mb( RVM_NOTIFY_MB, mb_params, &rvm_tm_notify_mem_bank) != RVF_OK)
+	{	
+		// TO DO: remove this call since the RVT software entity has not been started yet.
+		RVM_TRACE_ERROR( "RVM_init: unable to create the RVM TIMER NOTIFY MSG mem bank");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+/*******************************************************************************
+** Function         rvm_task
+**
+** Description      Core of the RVM task, which initiliazes the RVM and 
+**					waits for messages.
+**					
+*******************************************************************************/
+void rvm_task (UINT32 param)
+{	BOOLEAN detectedError = FALSE;
+	T_RV_HDR * msgPtr;
+
+	/* init the SWEs database */
+	if ( rvm_init_swe_db() != RVM_OK)
+	{	/* lack of memory */
+		detectedError = TRUE;
+	}
+//printf("RVManager core: %d %s\n", rvf_get_taskid(), rvf_get_taskname());
+
+	/* loop to process messages */
+	while (detectedError == FALSE)
+	{
+		/* Wait for the necessary event (msg in the rve mailbox and no timeout). */
+		UINT16 recEvent = rvf_wait ( RVM_EXPECTED_EVENT, 0);
+					
+		/* If the expected event is received, then */
+		if (recEvent & RVM_EXPECTED_EVENT)	{
+			/* Read the message in the rve mailbox */
+			msgPtr = (T_RV_HDR *) rvf_read_mbox (RVM_MAILBOX);
+			if(msgPtr) {
+			/* Determine the input message type */
+				switch (msgPtr->msg_id)	{
+				case (RVM_START_APPLI): {
+						rvm_launch_appli((T_RVM_MSG*)msgPtr); 
+						rvf_free_buf(msgPtr);
+						break;				
+					}
+					case (RVM_STOP_APPLI): 	{ // still keep original concept
+						rvm_shut_down_appli((T_RVM_MSG*)msgPtr);
+						rvf_free_buf(msgPtr);
+					break;				
+				}
+					case (RVM_STOP_MSG): { // new concept, eg. reverse init/start concept
+						if(((T_RVM_STOP_MSG*)msgPtr)->status==SWE_RUNNING) {
+							rvm_stop_appli((T_RVM_STOP_MSG*) msgPtr);
+							rvf_free_buf(msgPtr);
+						} else {
+							rvm_swe_has_stopped((T_RVM_STOP_MSG*) msgPtr);
+							rvf_free_buf(msgPtr);
+						}
+
+					break;				
+				}
+#ifdef _CONSOLE
+				case (RVM_EVT_TO_APPLI): 	{       /*A-M-E-N-D-E-D! */
+					/* proxy msg's sent by "rvm_snd_to_upper()"      
+					/* There arrival here is evident that no parent or
+					/* calling process, ie. No MMI exists and they were
+					/* started by RVM itself.                          */
+						RVM_TRACE_WARNING_PARAM("RVM: caller response msg", msgPtr->msg_id);
+
+					_callerProxy((T_RVM_APPLI_RESULT*)msgPtr);
+					rvf_free_buf(msgPtr);
+					break;				
+				}
+#endif
+				default:	{	
+						RVM_TRACE_WARNING_PARAM("rvm_Task: [switch()] unrecognized msg", msgPtr->msg_id);
+
+						rvf_free_buf(msgPtr);
+						break;
+				}
+			}
+			}
+			/* free the received msg */
+//			rvf_free_buf(msgPtr);  // may be used when STOP is completed
+		} else {
+			RVM_TRACE_WARNING_PARAM("RVM_task: unrecognized event", recEvent);
+		}
+	}
+	RVM_TRACE_ERROR("RVM_task: unrecoverable error --> stopping RVM");
+}
+
+T_RVM_RETURN rvm_t2_proxy() {
+	T_RVM_RETURN	error_status=RVM_OK;
+	T_RV_HDR*		p_msg = NULL ;
+	UINT16			rec_event;
+	T_RVF_G_ADDR_ID gid=RVF_INVALID_ADDR_ID;
+	UINT16			nbTmExp=0;
+	UINT8			y=0,F_PRI=0, yield;
+
+	RVM_TRACE_WARNING_PARAM("T2PROXY TACHE DE DEV", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+	rvf_start_timer(0, RVM_YIELD_T2_PS_TM, 1);
+	yield=MAX_PARASITES;
+	gid=rvf_get_taskid();
+	
+	while (error_status == RVM_OK) {
+		
+		rec_event = rvf_evt_wait(gid, 0xffff, 0xFFFFFFFFL); /* Wait (infinite) for all events. */
+
+		if (rec_event & RVF_TASK_MBOX_1_EVT_MASK) {
+			F_PRI=1;
+			for(y=0; (p_msg=(T_RV_HDR *)rvf_read_addr_mbox (gid, 1)) && (y<yield); y++) {
+//RVM_TRACE_WARNING_PARAM("T2 PRI MAILBOX !!!\n", RV_TRACE_LEVEL_DEBUG_HIGH);
+				rvf_setRDV(gid, p_msg->dest_addr_id);
+				switch(p_msg->msg_id) { 
+					case RVM_TMS_MSG:
+						if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+						} else rvf_free_timer_msg(p_msg);
+					break;
+					case RVM_START_T2_MSG:
+						yield=MAX_PARASITES;
+						_start_group(gid, ((T_RVM_START_T2_MSG*)p_msg)->grp);
+						rvf_free_buf(p_msg);
+					break;
+					case RVM_STOP_MSG:
+						_stop_t2_swe((T_RVM_STOP_MSG*)p_msg);
+					break;
+					case RVM_RT_MOD_YIELD_T2_MSG:
+						if(((T_RVM_RT_MOD_YIELD_T2_MSG*)p_msg)->val > 1) 
+							rvf_start_timer(0, ((T_RVM_RT_MOD_YIELD_T2_MSG*)p_msg)->val, 1);
+						rvf_free_buf(p_msg);
+					break;
+					default:
+						if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_message) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_message(p_msg);
+						} else rvf_free_msg(p_msg);
+					break;
+				}
+				rvf_setRDV(gid, RVF_INVALID_ADDR_ID);
+			}
+			yield=RVM_YIELD_T2_PRI_MSG_CNT;
+		} 
+		if (rec_event & RVF_TASK_MBOX_0_EVT_MASK ) {
+//RVM_TRACE_WARNING_PARAM("T2 STND MAILBOX !!!\n", RV_TRACE_LEVEL_DEBUG_HIGH);
+			if(p_msg=(T_RV_HDR *) rvf_read_mbox (0)) {
+				rvf_setRDV(gid, p_msg->dest_addr_id);
+				switch(p_msg->msg_id) { 
+					case RVM_TMS_MSG:
+						if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+						} else rvf_free_timer_msg(p_msg);
+							
+						//rvf_free_buf(p_msg);
+					break;
+					case RVM_START_T2_MSG:
+						_start_group(gid, ((T_RVM_START_T2_MSG*)p_msg)->grp);
+						rvf_free_buf(p_msg);
+					break;
+					case RVM_STOP_MSG:
+						_stop_t2_swe((T_RVM_STOP_MSG*)p_msg); // preserve 
+					break;
+					default:
+						if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_message) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_message(p_msg);
+						} else rvf_free_msg(p_msg);
+					break;
+				}
+				rvf_setRDV(gid, RVF_INVALID_ADDR_ID);
+			} 
+		} 
+		if( rec_event & RVF_TIMER_0_EVT_MASK ) {
+//RVM_TRACE_WARNING_PARAM("T2 YIELD !!!\n", RV_TRACE_LEVEL_DEBUG_HIGH);
+			rvf_yield();
+		}
+		if( rec_event & RVF_TIMER_1_EVT_MASK || rec_event & RVF_TIMER_2_EVT_MASK   ) {
+			
+			RVM_TRACE_WARNING_PARAM("RVM: Forbidden timer usage for type 2 entities!\n     Please use rvf_add_timer()", RV_TRACE_LEVEL_DEBUG_HIGH);
+		}
+		if(rec_event & RVF_TIMER_3_EVT_MASK) { 
+
+			/*nbTmExp=0; //rvf_update_timer_list((pRtAddrIdTable[gid]->p_tm_q));
+
+			while(nbTmExp-- > 0) {
+				p_msg=0;//(T_RV_HDR*)rvf_get_expired_entry((pRtAddrIdTable[gid]->p_tm_q));
+				if(p_msg->dest_addr_id)
+				  pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+				else RVM_TRACE_WARNING_PARAM("T3PROXY NO TM DESTINATION", RV_TRACE_LEVEL_DEBUG_HIGH);
+			}*/
+		}
+		F_PRI=0;
+	}
+	
+	/*if (error_status == INVKR_MEMORY_ERR) {
+		invkr_env_ctrl_blk_p->error_ft("INVKR", RVM_MEMORY_ERR, 0,
+						  " Memory Error : the INVKR primitive memory bank is RED ");
+	}*/
+
+	RVM_TRACE_WARNING_PARAM("T2PROXY ERROR: CORE TERMINATION", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+	/* BEFORE returning free resources !!!		*/
+	return RVM_OK;
+}
+
+T_RVM_RETURN rvm_t3_proxy() { 
+	T_RVM_RETURN	error_status=RVM_OK;
+	T_RV_HDR*		p_msg = NULL ;
+	UINT16			rec_event;
+	T_RVF_G_ADDR_ID gid;
+	UINT8			swe_i=0;
+	UINT16			nbTmExp=0;
+	T_RV_HDR*		p_hdr=NULL; 
+	UINT8			yield=250, y=0; /* arguable whether T3 needs Yield. Hence, high nb */
+	UINT8			F_PRI=0;
+
+	RVM_TRACE_WARNING_PARAM("T3PROXY TACHE DE DEV", RV_TRACE_LEVEL_DEBUG_HIGH);
+//printf("t2proxy: %d %s\n", rvf_get_taskid(), rvf_get_taskname());
+	gid=rvf_get_taskid();
+	if(gid) _t3_start(gid);
+
+	RVM_TRACE_WARNING_PARAM("T3PROXY START()", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+	while (error_status == RVM_OK) {
+		
+		rec_event = rvf_evt_wait(gid, 0xffff, 0xFFFFFFFFL); /* Wait (infinite) for all events. */
+
+		if (rec_event & RVF_TASK_MBOX_1_EVT_MASK) { 
+			F_PRI=1;
+			for(y=0; (p_msg=(T_RV_HDR *)rvf_read_addr_mbox (gid, 1)) && (y<yield); y++) {
+				if(p_msg->msg_id==RVM_TMS_MSG) {
+					if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer) {
+					pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+					} else rvf_free_timer_msg(p_msg);
+				} else if(p_msg->msg_id==RVM_STOP_MSG) {
+					_stop_t3_swe((T_RVM_STOP_MSG*)p_msg);
+				} else { 
+					if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_message) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_message(p_msg);
+					} else rvf_free_msg(p_msg);
+				}
+			}
+		} 
+		if (rec_event & RVF_TASK_MBOX_0_EVT_MASK && !F_PRI) {
+			if(p_msg=(T_RV_HDR *) rvf_read_addr_mbox (gid, 0)) {
+				if(p_msg->msg_id==RVM_TMS_MSG) {
+					if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer) {
+					pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+					} else rvf_free_timer_msg(p_msg);
+				} else if(p_msg->msg_id==RVM_STOP_MSG) {
+					_stop_t3_swe((T_RVM_STOP_MSG*)p_msg);
+				} else { 
+					if(pRtAddrIdTable[p_msg->dest_addr_id] && pRtAddrIdTable[p_msg->dest_addr_id]->handle_message) {
+						pRtAddrIdTable[p_msg->dest_addr_id]->handle_message(p_msg);
+					} else rvf_free_msg(p_msg);
+				}
+			} 
+		}
+		if(rec_event & RVF_TIMER_0_EVT_MASK) { 
+			if(rvf_get_buf(rvm_mem_bank,sizeof(T_RV_HDR),(T_RVF_BUFFER**) &p_hdr)!=RVF_RED) {
+				p_hdr->msg_id=RVF_TIMER_0_EVT_MASK;
+				p_hdr->dest_addr_id=0;
+				pRtAddrIdTable[resolveHostAddrId(gid)]->handle_timer(p_hdr);
+			} else RVM_TRACE_WARNING_PARAM("RVM: T3 PROXY TM 0 EVENT DISPATCH MEM ERROR!", RV_TRACE_LEVEL_DEBUG_HIGH);
+		}
+		if(rec_event & RVF_TIMER_1_EVT_MASK) { 
+			if(rvf_get_buf(rvm_mem_bank,sizeof(T_RV_HDR),(T_RVF_BUFFER**) &p_hdr)!=RVF_RED) {
+				p_hdr->msg_id=RVF_TIMER_1_EVT_MASK;
+				p_hdr->dest_addr_id=0;
+				pRtAddrIdTable[resolveHostAddrId(gid)]->handle_timer(p_hdr);
+			} else RVM_TRACE_WARNING_PARAM("RVM: T3 PROXY TM 1 EVENT DISPATCH MEM ERROR!", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+		}
+		if(rec_event & RVF_TIMER_2_EVT_MASK) { 
+			if(rvf_get_buf(rvm_mem_bank,sizeof(T_RV_HDR),(T_RVF_BUFFER**) &p_hdr)!=RVF_RED) {
+				p_hdr->msg_id=RVF_TIMER_2_EVT_MASK;
+				p_hdr->dest_addr_id=0;
+				pRtAddrIdTable[resolveHostAddrId(gid)]->handle_timer(p_hdr);
+			} else RVM_TRACE_WARNING_PARAM("RVM: T3 PROXY TM 2 EVENT DISPATCH MEM ERROR!", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+		}
+		if(rec_event & RVF_TIMER_3_EVT_MASK) {
+
+			nbTmExp=0; //rvf_update_timer_list((pRtAddrIdTable[gid]->p_tm_q));
+//printf("T3 POLL TIMER Id %d ---------------------------------------------> %d!\n",gid, nbTmExp); 
+
+			while(nbTmExp-- > 0) {
+				p_msg=0; //(T_RV_HDR*)rvf_get_expired_entry(pRtAddrIdTable[gid]->p_tm_q);
+				if(p_msg->dest_addr_id)
+				  pRtAddrIdTable[p_msg->dest_addr_id]->handle_timer(p_msg);
+				else RVM_TRACE_WARNING_PARAM("T3PROXY NO TM DESTINATION", RV_TRACE_LEVEL_DEBUG_HIGH);
+			}
+		}
+		F_PRI=0;
+	}
+
+	/*if (error_status == INVKR_MEMORY_ERR) {
+		invkr_env_ctrl_blk_p->error_ft("INVKR", RVM_MEMORY_ERR, 0,
+						  " Memory Error : the INVKR primitive memory bank is RED ");
+	}*/
+
+	RVM_TRACE_WARNING_PARAM("T3PROXY ERROR: CORE TERMINATION", RV_TRACE_LEVEL_DEBUG_HIGH);
+
+	/* BEFORE returning free resources !!!		*/
+	return RVM_OK;
+}
+
+T_RVM_RETURN	rvm_start_group_req(T_RVF_G_ADDR_ID addrId, UINT8* grp) {
+	T_RVM_START_T2_MSG * p_msg;
+	T_RVF_MB_STATUS mb_status;
+	UINT8 i=0;
+
+	mb_status = rvf_get_msg_buf(rvm_mem_bank, 
+							sizeof(T_RVM_START_T2_MSG),
+							RVM_START_T2_MSG,
+							(T_RVF_MSG**) &p_msg);
+
+	if (mb_status == RVF_RED)	{
+		RVM_TRACE_WARNING_PARAM("rvm_start_group(): Error to get memory ",RV_TRACE_LEVEL_ERROR);			
+		return RVM_MEMORY_ERR;
+	} else if (mb_status == RVF_YELLOW) {
+		RVM_TRACE_WARNING_PARAM("rvm_start_group(): Getting short on memory ", RV_TRACE_LEVEL_WARNING);
+	}
+
+	for(i=0;i<10; i++) p_msg->grp[i]=0; // DEFINE MAX !!!
+
+	p_msg->hdr.msg_id			= RVM_START_T2_MSG;   
+	for(i=0; i<10 && grp[i]!=0; i++) p_msg->grp[i]=grp[i];
+
+	return rvf_send_priority_msg(addrId, p_msg); //? cast (void*) i/p
+}
+
+T_RVM_RETURN _start_group(T_RVF_G_ADDR_ID gid, UINT8* grp) {
+	T_RVM_INFO_SWE swe_info;
+	UINT8 i=0;
+	// for each k_swe_entry, IF NOT started get_info and call start() 
+	for(i=0; i<10 && grp[i]!=0; i++ ) {
+//		printf("INDEXES %d\n", grp[i]);
+			rvm_swe_array[grp[i]].swe_get_info(&swe_info);
+			rvf_setRDV(gid, rvm_swe_array[grp[i]].swe_addr_id);
+			if(swe_info.type_info.type2.start) {
+					swe_info.type_info.type2.start();
+					rvm_swe_array[grp[i]].swe_state = SWE_RUNNING;
+			}
+			rvf_setRDV(gid, RVF_INVALID_ADDR_ID);
+	}
+
+	return RVM_OK;   /* ERROR case To do */ 
+}
+
+T_RVM_RETURN _t3_start(T_RVF_G_ADDR_ID gid) {
+	T_RVM_INFO_SWE swe_info;
+
+	rvm_swe_array[pRtAddrIdTable[gid]->swe_db_index].swe_get_info(&swe_info);
+	if(swe_info.type_info.type3.start) {
+					swe_info.type_info.type3.start();
+					rvm_swe_array[pRtAddrIdTable[gid]->\
+						swe_db_index].swe_state = SWE_RUNNING;
+	}
+
+	return RVM_OK;  /* ERROR case To do */ 
+} 
+
+T_RVM_RETURN _stop_t2_swe(T_RVM_STOP_MSG* p_msg) {
+	T_RVM_INFO_SWE swe_info;
+
+	rvm_swe_array[p_msg->swe_num].swe_get_info(&swe_info);
+	if(swe_info.type_info.type2.stop) swe_info.type_info.type2.stop((T_RV_HDR*)p_msg);			
+
+	return RVM_OK;  /* ERROR case To do */ 
+}
+
+T_RVM_RETURN _stop_t3_swe(T_RVM_STOP_MSG* p_msg) {
+	T_RVM_INFO_SWE swe_info;
+
+	rvm_swe_array[p_msg->swe_num].swe_get_info(&swe_info);
+	if(swe_info.type_info.type3.stop) swe_info.type_info.type3.stop((T_RV_HDR*)p_msg);			
+
+	return RVM_OK;  /* ERROR case To do */ 
+}
+
+T_RVM_RETURN rvm_mod_rt_t2_yield(T_RVF_G_ADDR_ID addrId, UINT16 val) {
+	T_RVM_RT_MOD_YIELD_T2_MSG * p_msg;
+	T_RVF_MB_STATUS mb_status;
+
+	mb_status = rvf_get_msg_buf(rvm_sys_mem_bank, 
+							sizeof(T_RVM_RT_MOD_YIELD_T2_MSG),
+							RVM_RT_MOD_YIELD_T2_MSG,
+							(T_RVF_MSG**) &p_msg);
+
+	if (mb_status == RVF_RED)	{
+		RVM_TRACE_WARNING_PARAM("rvm_start_group(): Error to get memory ",RV_TRACE_LEVEL_ERROR);			
+		return RVM_MEMORY_ERR;
+	} else if (mb_status == RVF_YELLOW) {
+		RVM_TRACE_WARNING_PARAM("rvm_start_group(): Getting short on memory ", RV_TRACE_LEVEL_WARNING);
+	}
+
+	p_msg->hdr.msg_id			= RVM_RT_MOD_YIELD_T2_MSG;   /* from internal header */
+	p_msg->val					= val;
+
+	/* Send the message using mailbox. */
+	return rvf_send_priority_msg(addrId, p_msg); //? cast (void*) i/p
+}
+
+/* ONLY used for return path msgs from entities started/stopped by the RVM */
+#ifdef _CONSOLE
+void _callerProxy(T_RVM_APPLI_RESULT *p_msg_res) {  /*A-M-E-N-D-E-D! */
+	char *ret_val=NULL;
+
+	switch(p_msg_res->result) {
+		case RV_OK:					ret_val="RVM: Successful entity start or stop:";					
+		break;
+		case RV_NOT_SUPPORTED:		ret_val="RVM: Not Supported:";
+		break;
+		case RV_NOT_READY:			ret_val="RVM: Not Ready:";	
+		break;
+		case RV_MEMORY_ERR:			ret_val="RVM: Memory Alloc. Error:";
+		break;
+		case RV_MEMORY_REMAINING:	ret_val="RVM: Memory REMAINING AFTER STOP & KILL!: ";
+		break;
+		case RV_INTERNAL_ERR:		ret_val="RVM: Memory Alloc. Error:";	
+		break;
+		case RV_INVALID_PARAMETER:	ret_val="RVM: Invalid Parameter:";
+		break;
+		default:					ret_val="RVM: Not recognised:n";
+		break;
+	}
+	RVM_TRACE_WARNING_PARAM(ret_val, p_msg_res->swe_index);
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvm/rvm_use_id_list.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,362 @@
+/**
+ * @file	rvm_use_id_list.h
+ *
+ * List of common SWE USE IDs.
+ *
+ * Note on USE ID management:
+ * This file should only contain USE ID of SWE part of the standard TI releases.
+ * Development SWE as well as customer SWE should use the rvm_ext_use_id_list.h
+ * file for their USE IDs.
+ *
+ * @author	David Lamy-Charrier (d-lamy@ti.com)
+ * @version	0.1
+ */
+
+/*
+ * Revision History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	10/25/2001	David Lamy-Charrier		Create.
+ *	11/20/2001	Vincent Oberle			Added BUILD_MESSAGE_OFFSET.
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+
+#ifndef __RVM_USE_ID_LIST_H_
+#define __RVM_USE_ID_LIST_H_
+
+
+/**
+ * Macro used to build the use_id from the cust, offset and mask parameters.
+ *
+ * IMPORTANT: The mask parameter must a 16-bit unsigned integer with only one
+ * bit at 1 and others at 0.
+ * E.g. possible values are 0x0001, 0x0002, 0x0004, 0x0008, 0x0010... 0x8000.
+ */
+#define BUILD_USE_ID(cust, cluster, mask) ( (cust<<31) | ( (cluster & 0x7FFF) <<16) | (mask & 0xFFFF) )
+
+/**
+ * Macro for building the message offset from the USE ID.
+ */
+#define BUILD_MESSAGE_OFFSET(useid) ( (useid & 0xFFFF0000) +			\
+									  ((((useid & 0xAAAA) ? 1 : 0) +	\
+										((useid & 0xCCCC) ? 2 : 0) +	\
+										((useid & 0xF0F0) ? 4 : 0) +	\
+										((useid & 0xFF00) ? 8 : 0)) << 12) )
+
+
+#define RIVIERA_USE_ID_CLUSTER_1	(1)
+
+#define DRIVERS_USE_ID_CLUSTER_1	(10)
+
+#define BLUETOOTH_USE_ID_CLUSTER_1	(20)
+
+#define SERVICES_USE_ID_CLUSTER_1	(30)
+#define SERVICES_USE_ID_CLUSTER_2	(31)
+
+#define TEST_USE_ID_CLUSTER_1		(40)
+
+#define CONDAT_USE_ID_CLUSTER_1		(50)
+
+#define JAVA_USE_ID_CLUSTER_1		(60)
+
+#define TCPIP_USE_ID_CLUSTER_1		(70)
+
+#define OBIGO_USE_ID_CLUSTER_1		(80)
+#define OBIGO_USE_ID_CLUSTER_2		(81)
+
+#define WIDCOMM_BT_USE_ID_CLUSTER_1 (90)
+
+/**
+ * @name	Widcomm cluster
+ *
+ * Riviera insfrastructure
+ */
+/*@{*/
+
+
+#define BTU_USE_ID  BUILD_USE_ID( 0, WIDCOMM_BT_USE_ID_CLUSTER_1, 0x0002)
+#define GKI_USE_ID  BUILD_USE_ID( 0, WIDCOMM_BT_USE_ID_CLUSTER_1, 0x0004)
+#define BTH_USE_ID  BUILD_USE_ID( 0, WIDCOMM_BT_USE_ID_CLUSTER_1, 0x0008)
+#define BTUI_USE_ID BUILD_USE_ID( 0, WIDCOMM_BT_USE_ID_CLUSTER_1, 0x0010)
+#define RPC_USE_ID  BUILD_USE_ID( 0, WIDCOMM_BT_USE_ID_CLUSTER_1, 0x0020)
+/**
+ * @name	Riviera cluster
+ *
+ * Riviera insfrastructure
+ */
+/*@{*/
+
+/* this one is only used for trace purpose */
+#define RVM_USE_ID		BUILD_USE_ID( 0, RIVIERA_USE_ID_CLUSTER_1, 0x0001)
+
+#define RVT_USE_ID		BUILD_USE_ID( 0, RIVIERA_USE_ID_CLUSTER_1, 0x0002)
+
+#define TI_PRF_USE_ID	BUILD_USE_ID( 0, RIVIERA_USE_ID_CLUSTER_1, 0x0004)
+
+/*@}*/
+
+
+
+/**
+ * @name	Driver cluster
+ *
+ * Drivers
+ */
+/*@{*/
+
+#define R2D_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0001)
+
+#define RTC_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0002)
+
+#define FFS_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0004)
+
+#define KPD_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0008)
+
+#define SPI_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0010)
+
+/* Replacing PWR_USE_ID */
+#define LCC_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0020)	
+
+
+#define RGUI_USE_ID		BUILD_USE_ID( 0, DRIVERS_USE_ID_CLUSTER_1, 0x0040)
+
+/*@}*/
+
+
+
+
+/**
+ * @name	Bluetooth cluster
+ *
+ * Bluetooth related SWE
+ */
+/*@{*/
+
+#define HCI_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0001)
+
+#define L2CAP_USE_ID	BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0002)
+
+#define BTCTRL_USE_ID	BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0004)
+
+#define RFC_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0008)
+
+#define SPP_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0010)
+
+#define HS_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0020)
+
+#define	HSG_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0040)
+
+#define SDP_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0080)
+
+#define DUN_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0100)
+
+#define FAX_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0200)
+
+#define	OBX_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0400)
+
+#define	OPP_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x0800)
+
+#define	FTP_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x1000)
+
+#define	SYN_USE_ID		BUILD_USE_ID( 0, BLUETOOTH_USE_ID_CLUSTER_1, 0x2000)
+
+/*@}*/
+
+
+
+/**
+ * @name	Services cluster
+ *
+ * Services
+ */
+/*@{*/
+
+#define EXPL_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0001)
+
+#define	AUDIO_USE_ID   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0002)
+
+#define	ETM_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0004)
+
+#define	DAR_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0008)
+
+#define	MKS_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0010)
+
+#define	MPM_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0020)
+
+#define	LLS_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0040)
+
+#define	ATP_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0080)
+
+#define	ATP_UART_USE_ID	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0100)
+
+#define	MDC_USE_ID	   	BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0200)
+
+#define TTY_USE_ID		BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0400)
+
+#define	DCM_USE_ID		BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x0800)
+
+#define	DCFG_USE_ID		BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x1000)
+
+#define	MMS_USE_ID		BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_1, 0x1000)
+/*@}*/
+
+
+/**
+ * @name	Services cluster - 2
+ *
+ * Services
+ */
+/*@{*/
+
+#define MFW_USE_ID			BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_2, 0x0001)
+
+#define SMBS_USE_ID			BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_2, 0x0002)
+
+#define	AUDIO_BGD_USE_ID    BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_2, 0x0004)
+
+#define IMG_USE_ID 			BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_2, 0x0008)
+
+#define MDL_USE_ID		        BUILD_USE_ID( 0, SERVICES_USE_ID_CLUSTER_2, 0x0010)
+
+/*@}*/
+
+
+/**
+ * @name	Test cluster
+ *
+ * Tests related SWEs
+ */
+/*@{*/
+
+#define	 RTEST_USE_ID	BUILD_USE_ID( 0, TEST_USE_ID_CLUSTER_1, 0x0001)
+
+/* maybe put in another cluster */
+#define	 TUT_USE_ID		BUILD_USE_ID( 0, TEST_USE_ID_CLUSTER_1, 0x0002)
+
+/*@}*/
+
+
+/**
+ * @name	J2ME cluster
+ *
+ * Java related SWEs
+ */
+/*@{*/
+
+#define	 KIL_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0001)
+
+#define	 KGC_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0002)
+
+#define	 KCL_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0004)
+
+#define	 KMM_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0008)
+
+#define	 KNM_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0010)
+
+#define	 UVM_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0020)
+
+#define	 KZP_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0040)
+
+#define	 KPG_USE_ID		BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0080)
+
+#define	 JTM_USE_ID	    BUILD_USE_ID( 0, JAVA_USE_ID_CLUSTER_1, 0x0100)
+
+/*@}*/
+
+
+
+/**
+ * @name	Stack TCP/IP cluster
+ *
+ * Stack TCP/IP.
+ */
+/*@{*/
+#define RNET_USE_ID     BUILD_USE_ID( 0, TCPIP_USE_ID_CLUSTER_1, 0x0001)
+
+#define RNET_WS_USE_ID  BUILD_USE_ID( 0, TCPIP_USE_ID_CLUSTER_1, 0x0002)
+
+#define RNET_RT_USE_ID  BUILD_USE_ID( 0, TCPIP_USE_ID_CLUSTER_1, 0x0004)
+
+#define RNET_BR_USE_ID  BUILD_USE_ID( 0, TCPIP_USE_ID_CLUSTER_1, 0x0008)
+
+/*@}*/
+
+
+/**
+ * @name	Condat cluster
+ *
+ * Condat related SWEs
+ */
+/*@{*/
+
+#define	 CONDAT_FRM_USE_ID BUILD_USE_ID( 0, CONDAT_USE_ID_CLUSTER_1, 0x0001)
+
+
+/*@}*/
+
+
+
+/**
+ * @name	Obigo cluster
+ *
+ * Obigo related SWE's
+ */
+/*@{*/
+#define MSME_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0001)
+
+#define MSFE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0002)
+
+#define STKE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0004)
+
+#define BRSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0008)
+
+#define BRAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0010)
+
+#define PHSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0020)
+
+#define MMSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0040)
+
+#define SLSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0080)
+
+#define SMAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0100)
+
+#define MEAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0200)
+
+#define SECE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0400)
+
+#define SELE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x0800)
+
+#define PRSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x1000)
+
+#define JAAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x2000)
+
+#define JASE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_1, 0x4000)
+/*@{*/
+
+
+/**
+ * @name	Obigo second cluster
+ *
+ * Obigo related test SWE's
+ */
+#define EMAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0001)
+
+#define EMSE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0002)
+
+#define IT1E_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0004)
+
+#define IT2E_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0008)
+
+#define IT0E_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0010)
+
+#define UISE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0020)
+
+#define UIAE_USE_ID BUILD_USE_ID( 0, OBIGO_USE_ID_CLUSTER_2, 0x0040)
+/*@{*/
+
+
+#endif  /* __RVM_USE_ID_LIST_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_api.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,303 @@
+/**************************************************************************
+ *			
+ * rvt_api.c
+ *
+ * This module defines the interface of Trace Module
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/5/2000) - Created
+ *
+ * Date             : 7/5/2000
+ *
+ * Author           : Guido Pagana    g-pagana@ti.com															  *
+***************************************************************************/
+
+
+
+#include "rv/general.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include "rvt/rvt_gen.h"
+#include "rvt/rvt_def_i.h"
+#include "rvt/rvt_env.h"
+#include "rvt/rvt_env_i.h"
+
+#include <string.h>
+
+
+/*
+** Trace User data base global variable
+*/
+T_RVT_USER_DB rvt_user_db [] = RVT_USER_ID_MAPPING;
+
+/*
+** Number of messages lost
+*/
+T_RVT_LOST_MSG  rvt_lost_msg_cpt = {0};
+
+extern UINT8 rvf_trace_level;
+
+extern UINT32 rvf_layer_mask;
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_set_trace_level                                      */
+/*                                                                              */
+/*    Purpose:         Updating the level of filtering, as well as the 32-bit   */
+/*                     mask related to the software entities to be monitored,   */
+/*                     according to the PC.                                     */
+/*                                                                              */
+/*    Note:            None.                                                    */
+/*                                                                              */
+/********************************************************************************/
+void rvt_set_trace_level (T_RVT_BUFFER p_msg, UINT16 msg_length)
+{
+
+	/* Checking for an invalid PDU. */
+	if ((p_msg == NULL) || \
+		(msg_length != (sizeof (UINT8) + sizeof (UINT32))))
+	{
+		return;
+	}
+
+	/* Update the level of filtering. */
+	if (*p_msg <= RV_TRACE_LEVEL_DEBUG_LOW)
+	{
+		rvf_trace_level = *p_msg;
+	}
+
+	/* Update the 32-bit mask related to the software entities to be monitored.
+	Note that the 32-bit mask is transmitted LSB first. */
+	rvf_layer_mask = *(++p_msg);
+	rvf_layer_mask |= *(++p_msg) << 8;
+	rvf_layer_mask |= *(++p_msg) << 16;
+	rvf_layer_mask |= *(++p_msg) << 24;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_send_trace_no_copy									*/
+/*                                                                              */
+/*    Purpose:         This function is used send trace messages without        */
+/*                     copying.                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        WARNING!!!! The buffer containing the message has been allocated      */
+/*        by the trace module!!!                                                */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVT_RET
+rvt_send_trace_no_cpy(	T_RVT_BUFFER msg, 
+						T_RVT_USER_ID user_id, 
+						T_RVT_MSG_LG msg_length, 
+						T_RVT_FORMAT msg_format)
+{
+	/* Shift the pointer back to write control values */
+	T_RVT_TRACE_RQST * req_msg = (T_RVT_TRACE_RQST * )((UINT8*)msg - RVT_HEADER_SIZE);
+
+	/* Check is Trace Module is running	*/
+	if (rvt_module_state != RVT_STARTED)
+	{
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).not_started = 1;
+		return RVT_NOT_READY;
+	}
+
+    
+	/* Add the id, size and format of the msg at the beginning */	
+	
+	req_msg->header.msg_id	= RVT_TRACE_RQST_ID;
+	req_msg->format			= msg_format;
+	req_msg->user_id		= user_id;
+	req_msg->msg_length		= msg_length;
+    
+	if (rvf_send_msg(rvt_addr_id, (void *) req_msg) != RVF_OK)
+	{
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).message_not_sent = 1;
+		return RVT_INTERNAL_ERR;
+	}
+	return RVT_OK;
+}		
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   send trace copy											*/
+/*                                                                              */
+/*    Purpose:         this function sends traces with copy						*/
+/*																				*/
+/*    Note:                                                                     */
+/*        No check on id parameter !!!! Must be done in PC.                     */
+/*                                                                              */
+/********************************************************************************/
+T_RVT_RET rvt_send_trace_cpy (T_RVT_BUFFER msg, 
+						T_RVT_USER_ID user_id, 
+						T_RVT_MSG_LG msg_length, 
+						T_RVT_FORMAT msg_format)
+
+		
+
+{
+	T_RVT_TRACE_RQST * req ;
+
+	/* Check is Trace Module is running	*/
+	if (rvt_module_state != RVT_STARTED)
+	{
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).not_started = 1;
+		return RVT_NOT_READY;
+	}
+	
+	/* Allocate memory (msg_length + necessary room for the header)	*/
+	if ((rvf_get_buf (rvt_mb_id, (UINT32) msg_length + RVT_HEADER_SIZE,	(T_RVF_BUFFER**) &req)) == RVF_RED)
+	{
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1;
+		return RVT_MEMORY_ERR;
+	}
+
+ 	/* Add the id, size and format of the msg at the beginning */	
+	req->header.msg_id	= RVT_TRACE_RQST_ID;
+	req->format			= msg_format;
+	req->user_id		= user_id;
+	req->msg_length		= msg_length;
+
+	/* Copy the message	*/
+	memcpy( (UINT8*)req + RVT_HEADER_SIZE, msg, msg_length);  
+
+	/*
+	** Send it as a message to Trace Task
+	*/
+	if (rvf_send_msg(rvt_addr_id, (void *) req) != RVF_OK)
+	{
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).message_not_sent = 1;
+		rvf_free_buf (req);
+		return RVT_INTERNAL_ERR;
+	}
+	return RVT_OK;
+}
+
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_register_id											*/
+/*                                                                              */
+/*    Purpose:         function rvt_register id									*/
+/*					   returns 0 if string not found, else the number			*/
+/*					   stocked in the array										*/
+/*                                                                              */
+/*    Note:                                                                     */
+/*        uses two arrays, one that stockes the messages,and another for the	*/
+/*        correspondent values.                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVT_RET rvt_register_id(T_RVT_NAME name[], T_RVT_USER_ID *rvt_id, RVT_CALLBACK_FUNC callback)
+{
+	UINT8 i;
+
+	/*looks in the array if the message is stocked */
+	for (i=0;rvt_user_db[i].user_id!=RVT_INVALID_HEADER;i++)
+	{
+	 if (rvt_name_cmp(rvt_user_db[i].user_name,name))
+	 {
+	 	*rvt_id = rvt_user_db[i].user_id;
+	 	rvt_user_db[i].rx_callback_func = callback;
+	 	return(RVT_OK);
+	 }			
+	}
+	
+	/*else returns zero */
+	return (RVT_INVALID_PARAMETER);
+
+}
+
+
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_mem_alloc											*/
+/*                                                                              */
+/*    Purpose:         this function allocates a buffer for tracing.			*/
+/*																				*/
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+T_RVT_RET rvt_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_length, T_RVT_BUFFER * buff)
+{
+	if (rvt_module_state != RVT_STARTED)
+	{
+		*buff = NULL;
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).not_started = 1;
+		return RVT_NOT_READY;
+	}
+
+	if (rvf_get_buf (rvt_mb_id, (UINT32) buffer_length + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff) == RVF_RED)
+	{
+		*buff = NULL;
+		(rvt_lost_msg_cpt.bit_mask).count++;
+		(rvt_lost_msg_cpt.bit_mask).insufficient_resources = 1;
+		return RVT_MEMORY_ERR;
+	}
+	*buff = *buff + RVT_HEADER_SIZE;
+	return RVT_OK;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_mem_free												*/
+/*                                                                              */
+/*    Purpose:      this function frees an allocated buffer for the trace task	*/
+/*																				*/
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+T_RVT_RET rvt_mem_free(T_RVT_BUFFER msg)
+{
+
+	/*
+	** Shift the pointer back to write control values
+	*/
+	char *buff = (char*) msg - RVT_HEADER_SIZE;
+
+	// Deallocates the buffer
+	if (rvf_free_buf((T_RVF_BUFFER*) buff) == RVF_MEMORY_ERR)
+	{
+		return RVT_MEMORY_ERR;
+	}
+	return RVT_OK;
+}
+
+
+/*
+** User function used to compare name
+*/
+BOOLEAN rvt_name_cmp( char * str1, char * str2)
+{
+	UINT8 i;
+	
+	for ( i = 0; (str1[i] == str2[i]) && (str1[i] != 0) && (str2[i] != 0) && (i < RVT_NAME_MAX_LEN); i++ );
+	if ( i == RVT_NAME_MAX_LEN)
+	{	return TRUE;
+	}
+	if ( (str1[i] == 0) && (str2[i] == 0) )
+	{	return TRUE;
+	}
+	return FALSE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_def_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ *
+ * rvt_def_i.h
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/5/2000) - Created
+ *
+ * Date             : 7/5/2000
+ *
+ * Author           : Guido Pagana  g-pagana@ti.com
+ *
+ ******************************************************************************/
+
+#ifndef __RVT_DEF_I_H__
+#define __RVT_DEF_I_H__
+
+#include "rvt/rvt_gen.h"
+
+#include "rvt/rvt_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+
+/************************* Internal definitions **************************/
+
+
+/* Define the maximum number of msg lost before sending an alert */
+#define RVT_MAX_LOST_TRACE_MSG (1)
+
+/* Trace user database (must end using RVT_END_OF_TABLE) */
+#define RVT_END_OF_TABLE	{"", RVT_INVALID_HEADER, NULL}
+
+#define RVT_USER_ID_MAPPING { \
+								{"RV",		RVT_RV_HEADER,		NULL}, \
+								{"L1",		RVT_L1_HEADER,		NULL}, \
+								{"L23",		RVT_L23_HEADER,		NULL}, \
+								{"TM",		RVT_TM_HEADER,		NULL}, \
+								{"RNET",	RVT_RNET_HEADER,	NULL}, \
+								{"PROF",	RVT_PROF_HEADER,	NULL}, \
+								{"GTTBACK",	RVT_GTTBACK_HEADER,	NULL}, \
+								{"OTHER",	RVT_OTHER_HEADER,	NULL}, \
+								RVT_END_OF_TABLE \
+							}
+
+
+/* Trace task mailbox */
+#define RVT_TRACE_MAILBOX	RVF_TASK_MBOX_0
+
+typedef struct
+{	T_RVT_NAME			user_name[RVT_NAME_MAX_LEN];
+	T_RVT_USER_ID		user_id;
+	RVT_CALLBACK_FUNC	rx_callback_func;
+} T_RVT_USER_DB;
+
+
+/* Define the unique message type used in RVT */
+#define RVT_TRACE_RQST_ID ( (RVT_USE_ID & 0xFFFF0000) | ( 0x1) | 0x001)
+
+typedef struct
+{	T_RV_HDR		header;
+	T_RVT_USER_ID	user_id;
+	T_RVT_FORMAT	format;
+	T_RVT_MSG_LG	msg_length;
+}	T_RVT_TRACE_RQST;
+
+
+/* Trace message header size */
+#define RVT_HEADER_SIZE	(sizeof(T_RVT_TRACE_RQST) )
+
+#define TRACE_TASK_STACK_SIZE TRACE_STACK_SIZE
+
+
+#define TRACE_MB_SIZE		      (TRACE_MB1_SIZE)
+#define TRACE_MB_WATERMARK	  (TRACE_MB_SIZE)
+
+/* Decimal to hexadecimal conversion table */
+static const char Num2Char[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+
+/*
+** Number of messages lost. Causes:
+**
+**    __ 'Format' differs from RVT_ASCII_FORMAT and RVT_BINARY_FORMAT.
+**   |  __ 'Message ID' differs from RVT_TRACE_RQST_ID.
+**   | |  __ rvf_read_mbox has returned NULL.
+**   | | |  __ Failed to send the message.
+**   | | | |  __ Insufficient resources.
+**   | | | | |  __ Trace Module not started.
+**   |_|_|_|_|_|____________________________________________________
+**  | ¦ ¦ ¦ ¦ ¦ ¦   |               |               |               |
+**  | ¦ ¦ ¦ ¦ ¦ ¦   |               |               |               |
+**  |_¦_¦_¦_¦_¦_¦_._|_._._._._._._._|_._._._._._._._|_._._._._._._._|
+*/
+typedef union
+{
+	struct
+	{
+		INT32  count                  : 26;
+		INT32  not_started            : 1;
+		INT32  insufficient_resources : 1;
+		INT32  message_not_sent       : 1;
+		INT32  message_empty          : 1;
+		INT32  unknown_request        : 1;
+		INT32  unknown_format         : 1;
+	} bit_mask;
+	UINT32     overall_value;
+} T_RVT_LOST_MSG;
+
+extern T_RVT_LOST_MSG  rvt_lost_msg_cpt;
+
+/* Prototypes */
+BOOLEAN rvt_name_cmp( char * str1, char * str2);
+void rvt_activate_RX_HISR (void);                                    
+void rvt_RX_process (void);
+
+#endif /* __RVT_DEF_I_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_env.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,335 @@
+/********************************************************************************
+ *
+ * rvt_env.c
+ *
+ * This module interfaces the environment and contains all start/init/stop...
+ * functions of the trace module.
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/4/2000) - Created
+ *
+ * Date             : 7/4/2000
+ *
+ * Author           : Cristian Livadiotti, c-livadiotti@ti.com
+ *
+ ********************************************************************************/
+
+#include "nucleus.h" 
+
+#include <string.h>
+
+#include "rvf/rvf_api.h"
+#include "rv/rv_general.h"
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_priorities.h"
+
+#include "rvt/rvt_gen.h"
+#include "rvt/rvt_def_i.h"
+#include "rvt/rvt_env.h"
+#include "rvt/rvt_env_i.h"
+
+#include "rvm/rvm_use_id_list.h"
+
+#include "uart/serialswitch.h"
+
+#ifndef _WINDOWS
+	#include "config/swconfig.cfg"
+	#include "config/debug.cfg"
+#endif
+
+#define TI_RX_HISR_STACK_SIZE     (1024)
+static UINT8  TI_RX_HISR_stack[TI_RX_HISR_STACK_SIZE];
+
+char           *p_rvt_lost_msg  = NULL;
+char           *p_rvt_sys_time  = NULL;
+NU_HISR        TI_rcv_HISR;
+T_RVF_MB_ID    rvt_mb_id        = 0;
+T_RVT_STATE    rvt_module_state = RVT_NOT_STARTED;
+T_RVF_ADDR_ID  rvt_addr_id      = 0;
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_get_info												*/
+/*                                                                              */
+/*    Purpose:         This function is used to notify the RVM					*/
+/*                     of the Trace's Memory Banks requirements.				*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        &p_info_swe (refer to rvm_gen.h).                                     */
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        p_info_swe (refer to rvm_gen.h).                                      */
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+rvt_get_info (T_RVM_INFO_SWE  *p_info_swe)
+{
+  if (!p_info_swe)
+    return RVM_INVALID_PARAMETER;
+
+  p_info_swe->swe_type                                  = RVM_SWE_TYPE_4;
+	
+  p_info_swe->type_info.type4.swe_use_id                = RVT_USE_ID;
+  p_info_swe->type_info.type4.version                   = 1;
+  memcpy (p_info_swe->type_info.type4.swe_name,
+          "TRACE",
+          sizeof ("TRACE"));
+
+  p_info_swe->type_info.type4.stack_size                = TRACE_TASK_STACK_SIZE;
+  p_info_swe->type_info.type4.priority                  = RVM_TRACE_TASK_PRIORITY;
+
+  p_info_swe->type_info.type4.return_path.addr_id       = 0;
+  p_info_swe->type_info.type4.return_path.callback_func = NULL;
+
+  // Memory banks definitions. For now, one memory bank is needed
+  p_info_swe->type_info.type4.nb_mem_bank                          = 1;
+  memcpy (p_info_swe->type_info.type4.mem_bank[0].bank_name,
+          "RV_TRACE",
+          RVM_NAME_MAX_LEN);
+  p_info_swe->type_info.type4.mem_bank[0].initial_params.size      = TRACE_MB_SIZE;
+  p_info_swe->type_info.type4.mem_bank[0].initial_params.watermark = TRACE_MB_WATERMARK;
+	
+  // Generic functions
+  p_info_swe->type_info.type4.init     = rvt_init;
+  p_info_swe->type_info.type4.core     = (T_RVM_SWE_CORE_FUNC)rvt_task_core;
+  p_info_swe->type_info.type4.stop     = rvt_stop;
+  p_info_swe->type_info.type4.kill     = rvt_kill;
+  p_info_swe->type_info.type4.set_info = rvt_set_info;
+
+  // Linked SW entities: none, except if Profiler or Nucleus Monitor are defined
+  #if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+    p_info_swe->type_info.type4.nb_linked_swe    = 1;
+    p_info_swe->type_info.type4.linked_swe_id[0] = TI_PRF_USE_ID;
+  #else
+    p_info_swe->type_info.type4.nb_linked_swe    = 0;
+  #endif
+
+  return RVM_OK;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_set_info												*/
+/*                                                                              */
+/*    Purpose:         This function is used to notify the Trace module         */
+/*                     about mb ids and task id.								*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        bk_id[]: array of memory bank IDs.									*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+rvt_set_info (T_RVF_ADDR_ID     addr_id,
+              T_RV_RETURN_PATH  return_path[],
+              T_RVF_MB_ID       bk_id[],
+              T_RVM_CB_FUNC     rvm_error_ft)
+{
+
+  // Save parameters given by the environment (Addr ID and MB ID respectively)
+  rvt_addr_id = addr_id;
+  rvt_mb_id   = bk_id [0];
+
+  return RVM_OK;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_init													*/
+/*                                                                              */
+/*    Purpose:         This is the initialization function.						*/
+/*					   It is called by the RVM.									*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.																	*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+rvt_init (void)
+{
+
+  if (rvt_module_state != RVT_NOT_STARTED)
+    return RVM_NOT_READY;
+
+  // The stack is entirely filled with the pattern 0xFE
+  memset (TI_RX_HISR_stack,
+          0xFE,
+          TI_RX_HISR_STACK_SIZE);
+
+  // Create the RX HISR
+  if (NU_Create_HISR (&TI_rcv_HISR, \
+                      "TI_RCV_HISR", \
+                      rvt_RX_process, \
+                      2, \
+                      TI_RX_HISR_stack, \
+                      TI_RX_HISR_STACK_SIZE) != NU_SUCCESS)
+    return RVM_INTERNAL_ERR;
+
+  // Initialize the baud rate and the callback function for the RX HISR
+  SER_tr_Init (SER_LAYER_1,
+               TR_BAUD_CONFIG,
+               rvt_activate_RX_HISR); 
+
+  #ifdef FRAMING_PROTOCOL
+
+    // Allocate a buffer that reports the system time (refer to rvf_trace_adapt.c):
+    //  - 'User ID' (1 byte),
+    //  - 'Trace Type' (4 bytes),
+    //  - 'Trace Level' (1 byte),
+    //  - 'System Time' (RVT_SYS_TIME_LENGTH bytes),
+    //  - Hexadecimal value (RVT_HEX_VALUE_LENGTH bytes).
+    if (rvf_get_buf (rvt_mb_id, \
+                     (RVT_HDR_LENGTH + RVT_SYS_TIME_LENGTH + RVT_HEX_VALUE_LENGTH), \
+                     (T_RVF_BUFFER**)&p_rvt_sys_time) != RVF_RED)
+    {
+       UINT8  *header_p = NULL;
+
+       header_p    = (UINT8*)p_rvt_sys_time;
+       *header_p++ = (UINT8)rv_trace_user_id;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = RV_TRACE_LEVEL_ERROR;
+       memcpy (header_p,
+               RVT_SYS_TIME,
+               RVT_SYS_TIME_LENGTH);
+    }
+
+    // Allocate a buffer that reports a lack of memory (refer to rvf_trace_adapt.c):
+    //  - 'User ID' (1 byte),
+    //  - 'Trace Type' (4 bytes),
+    //  - 'Trace Level' (1 byte),
+    //  - 'Lost Message' (RVT_LOST_MSG_LENGTH bytes),
+    //  - Hexadecimal value (RVT_HEX_VALUE_LENGTH bytes).
+    if (rvf_get_buf (rvt_mb_id,
+                     (RVT_HDR_LENGTH + RVT_LOST_MSG_LENGTH + RVT_HEX_VALUE_LENGTH), \
+                     (T_RVF_BUFFER**)&p_rvt_lost_msg) != RVF_RED)
+    {
+       UINT8  *header_p = NULL;
+
+       header_p    = (UINT8*)p_rvt_lost_msg;
+       *header_p++ = (UINT8)rv_trace_user_id;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = 0;
+       *header_p++ = RV_TRACE_LEVEL_ERROR;
+       memcpy (header_p,
+               RVT_LOST_MSG,
+               RVT_LOST_MSG_LENGTH);
+    }
+  #else
+
+    // Allocate a buffer that reports the system time
+    if (rvf_get_buf (rvt_mb_id, \
+                     (RVT_SYS_TIME_LENGTH + RVT_HEX_VALUE_LENGTH + RVT_HYPERTERM_LENGTH), \
+                     (T_RVF_BUFFER**)&p_rvt_sys_time) != RVF_RED)
+    {
+       memcpy (p_rvt_sys_time,
+               RVT_SYS_TIME,
+               RVT_SYS_TIME_LENGTH);
+    }
+
+    // Allocate a buffer that reports a lack of memory
+    if (rvf_get_buf (rvt_mb_id, \
+                     (RVT_LOST_MSG_LENGTH + RVT_HEX_VALUE_LENGTH + RVT_HYPERTERM_LENGTH), \
+                     (T_RVF_BUFFER**)&p_rvt_lost_msg) != RVF_RED)
+    {
+        memcpy (p_rvt_lost_msg,
+                RVT_LOST_MSG,
+                RVT_LOST_MSG_LENGTH);
+    }
+  #endif
+
+  // State RVT as "STARTED"
+  rvt_module_state = RVT_STARTED;
+
+  return RVM_OK;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_stop													*/
+/*                                                                              */
+/*    Purpose:         This function is defined for compilation only.			*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.																	*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+rvt_stop (void)
+{
+  return RVM_OK;
+}
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_kill													*/
+/*                                                                              */
+/*    Purpose:         This function is defined for compilation only.			*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.																	*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+rvt_kill (void)
+{
+  return RVM_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_env.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ *
+ * rvt_env.c
+ *
+ * This module interfaces the environment and contains all start/init/stop...
+ * functions of the trace module.
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/4/2000) - Created
+ *
+ * Date             : 7/4/2000
+ *
+ * Author           : Cristian Livadiotti, c-livadiotti@ti.com
+ *
+ ******************************************************************************/
+
+#ifndef __RVT_ENV_H__
+#define __RVT_ENV_H__
+
+#include "rvm/rvm_gen.h"
+
+
+typedef enum { RVT_NOT_STARTED,	RVT_STARTED	} T_RVT_STATE;
+
+extern T_RVF_MB_ID		rvt_mb_id;
+
+extern T_RVT_STATE		rvt_module_state;
+
+T_RVM_RETURN
+rvt_get_info (T_RVM_INFO_SWE *p_info_swe);
+
+T_RVM_RETURN
+rvt_set_info (T_RVF_ADDR_ID		addr_id,
+			  T_RV_RETURN_PATH	return_path[],
+			  T_RVF_MB_ID		bk_id[],
+			  T_RVM_CB_FUNC		rvm_error_ft);
+
+T_RVM_RETURN
+rvt_init (void);
+
+T_RVM_RETURN
+rvt_task_core (void);
+
+T_RVM_RETURN
+rvt_stop (void);
+
+T_RVM_RETURN
+rvt_kill (void);
+
+
+#endif /* __RVT_ENV_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_env_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ *
+ * rvt_env_i.h
+ *
+ * This file should be included by rvt_env.c ONLY!!!
+ * It includes definitions of global variables used for trace.
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.11
+ *
+ * History			: 0.1  (7/4/2000) - Created
+ *       			: 0.11 (6/13/2002) - Remove useless dependency.
+ *
+ * Date             : 6/13/2002
+ *
+ * Author           : Cristian Livadiotti, c-livadiotti@ti.com
+ *
+ ******************************************************************************/
+
+#ifndef __RVT_ENV_I_H__
+#define __RVT_ENV_I_H__
+
+
+/*
+** Environment global variables
+*/
+extern T_RVF_MB_ID    rvt_mb_id;
+extern T_RVF_ADDR_ID  rvt_addr_id;
+
+
+/*
+** Trace Module State
+*/
+extern T_RVT_STATE    rvt_module_state;
+
+extern char           *p_rvt_lost_msg;
+extern char           *p_rvt_sys_time;
+extern T_RVT_USER_DB  rvt_user_db [];
+extern T_RVT_USER_ID  rv_trace_user_id;
+
+#define RVT_LOST_MSG              ("RVT: Lost Message ")
+#define RVT_LOST_MSG_LENGTH       (sizeof (RVT_LOST_MSG) - 1)
+
+#define RVT_SYS_TIME              ("RVT: System Time ")
+#define RVT_SYS_TIME_LENGTH       (sizeof (RVT_SYS_TIME) - 1)
+
+#define RVT_HEX_VALUE_LENGTH      (sizeof ("00000000") - 1)
+
+#ifndef FRAMING_PROTOCOL
+	#define RVT_HYPERTERM_LENGTH  (sizeof ('\n') + sizeof ('\r'))
+#else
+	#define RVT_HDR_LENGTH        (6)
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_gen.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ *
+ * tr_gen.h
+ *
+ * This file contain general definitions of Trace Module.
+ * Definitions are exportable
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/4/2000) - Created
+ *
+ * Date             : 7/4/2000
+ *
+ * Author           : Cristian Livadiotti, c-livadiotti@ti.com
+ *
+ ******************************************************************************/
+
+#ifndef __RVT_GEN_H__
+#define __RVT_GEN_H__
+
+#include "rv/general.h"
+
+/*
+** If TRACE_MODULE is defined, the trace is using the trace task API.
+** Otherwise, the trace is using the RVF.  NOW OBSOLETE !!!!!!!!
+*/
+//#define TRACE_MODULE
+
+
+/*
+** If FRAMING_PROTOCOL is defined, the trace mux should be used because of encapsulation and byte stuffing.
+** Otherwise, the hyperterminal should be used.
+*/
+#define FRAMING_PROTOCOL
+
+
+/*
+** If MIXED_TRACE is defined, all traces are mixed on the same UART and the
+** trace task handles the RX commands.
+*/
+//#define MIXED_TRACE
+
+/*
+** Type definitions
+*/
+
+/* Define return parameters.                                                     */
+typedef enum {
+	RVT_OK							= 0,
+	RVT_NOT_SUPPORTED				= -2,
+	RVT_NOT_READY					= -3,
+	RVT_MEMORY_ERR					= -4,
+	RVT_INTERNAL_ERR				= -9,
+	RVT_INVALID_PARAMETER			= -10
+} T_RVT_RET;
+
+
+
+typedef UINT8  T_RVT_USER_ID;
+typedef UINT32 T_RVT_MSG_LG;
+
+typedef enum { 
+	RVT_ASCII_FORMAT,   // 0
+	RVT_BINARY_FORMAT   // 1
+} T_RVT_FORMAT;
+
+
+typedef UINT8 * T_RVT_BUFFER;
+
+typedef char T_RVT_NAME;
+#define RVT_NAME_MAX_LEN		(10)
+
+#define RVT_RV_HEADER        0x11
+#define RVT_L1_HEADER        0x12
+#define RVT_L23_HEADER       0x13
+#define RVT_TM_HEADER        0x14
+#define RVT_RNET_HEADER      0x15
+#define RVT_PROF_HEADER      0x16
+#define RVT_GTTBACK_HEADER   0x17
+#define RVT_OTHER_HEADER     0x18
+#define RVT_INVALID_HEADER   0xFF
+
+typedef void (*RVT_CALLBACK_FUNC)(T_RVT_BUFFER, UINT16);
+
+/********* Fonction Prototypes ***********/
+void
+rvt_set_trace_level(T_RVT_BUFFER p_msg, UINT16 msg_length);
+
+T_RVT_RET
+rvt_send_trace_no_cpy(T_RVT_BUFFER p_buffer,
+					 T_RVT_USER_ID user_id,
+					 T_RVT_MSG_LG msg_lenght,
+					 T_RVT_FORMAT msg_format);
+
+T_RVT_RET 
+rvt_send_trace_cpy(T_RVT_BUFFER msg,
+				  T_RVT_USER_ID user_id,
+				  T_RVT_MSG_LG msg_length,
+				  T_RVT_FORMAT msg_format);
+
+
+T_RVT_RET
+rvt_register_id(T_RVT_NAME name[], T_RVT_USER_ID *tr_id, RVT_CALLBACK_FUNC callback);
+
+T_RVT_RET
+rvt_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_lenght, T_RVT_BUFFER * buff);
+
+T_RVT_RET 
+rvt_mem_free(T_RVT_BUFFER msg);
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,49 @@
+/**
+ * @file	rvt_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 __RVT_POOL_SIZE_H_
+#define __RVT_POOL_SIZE_H_
+
+
+#ifndef _WINDOWS
+  #include "rv.cfg"
+  #include "swconfig.cfg"
+#endif
+
+
+/*
+ * Values used in rvt_def_i.h
+ */
+#define TRACE_STACK_SIZE (2000)
+
+#if (TEST==1)
+  #define TRACE_MB1_SIZE (750000) /*(25000)*/
+#elif (!GSMLITE)
+  #define TRACE_MB1_SIZE (25000)
+#else
+  #define TRACE_MB1_SIZE (4000)
+#endif
+
+#define TRACE_POOL_SIZE  (TRACE_STACK_SIZE + TRACE_MB1_SIZE)
+
+
+#endif /*__RVT_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/rvt_task.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,548 @@
+/**************************************************************************
+*
+* rvt_task.c
+*
+* This contains the core of the Trace task.
+*
+* (C) Texas Instruments, all rights reserved
+*
+* Version number   : 0.1
+*
+* History		   : 0.1 (7/5/2000) - Created
+*
+* Date             : 7/5/2000
+*
+* Author           : Guido Pagana
+*
+* Update           : Pascal Puel
+*                  : David Lamy-Charrier (changes for Riviera 1.6)
+*
+***************************************************************************/
+
+
+#include "nucleus.h"
+
+#include "rv/general.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvt/rvt_gen.h"
+#include "rvt/rvt_def_i.h"
+#include "rvt/rvt_env.h"
+#include "rvt/rvt_env_i.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include "uart/serialswitch.h"
+
+#ifndef _WINDOWS
+	#include "config/swconfig.cfg"
+#endif
+
+#include <string.h>
+
+extern NU_HISR        TI_rcv_HISR;
+
+/* Time (in milliseconds) between two consecutive 'System Time' messages */
+#define RVT_ALIVE_POLLING_TIME    (RVF_MS_TO_TICKS (20000))
+
+#define RVT_WAIT_FOR_HEADER       (1)
+#define RVT_WAIT_FOR_DATA         (2)
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_task_core                                            */
+/*                                                                              */
+/*    Purpose:         Core of Trace task.                                      */
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+T_RVM_RETURN rvt_task_core (void)
+{
+	UINT16  event         = 0;
+	UINT32  nb_bytes_sent = 0;
+
+	#ifdef FRAMING_PROTOCOL
+
+		// Request for the level of filtering, as well as the 32-bit
+		// mask related to the software entities to be monitored.
+		{
+			UINT8  trace_level_request[] = {RVM_INVALID_USE_ID, 0, 0, 0, 0, (RV_TRACE_LEVEL_ERROR - 1), 0, 0, 0, 0};
+
+			// Note that the level is defined as invalid
+			trace_level_request[0] = (char) rv_trace_user_id;
+
+			// Transmit an 'empty' message
+			nb_bytes_sent = 0;
+			while (nb_bytes_sent < sizeof (trace_level_request))
+			{
+				nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1,
+													 trace_level_request + nb_bytes_sent,
+													 sizeof (trace_level_request) - nb_bytes_sent);
+			}
+		}
+
+		// Start the 'Alive Polling Timer'
+		#if (OP_WCP == 0)
+			rvf_start_timer (RVF_TIMER_0,
+							 RVT_ALIVE_POLLING_TIME,
+							 TRUE);
+		#endif
+
+		for (;
+			 ;
+			 )
+		{
+			// Infinite wait on 'Trace Task' mailbox or timer events
+			event = rvf_wait ((1 << RVT_TRACE_MAILBOX) | (RVF_TIMER_0_EVT_MASK),
+							  0);
+
+			// Check for some messages lost
+			if (((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) && (p_rvt_lost_msg))
+			{
+				INT8    count           = 0;
+				UINT8   lost_msg_length = RVT_HDR_LENGTH + RVT_LOST_MSG_LENGTH;
+				UINT32  lost_msg_cpt    = rvt_lost_msg_cpt.overall_value;
+
+				// Append with the number of messages lost
+				rvt_lost_msg_cpt.overall_value = 0;
+				for (count = 0;
+					 count < RVT_HEX_VALUE_LENGTH;
+					 count++)
+				{
+					p_rvt_lost_msg[lost_msg_length + count] = Num2Char[(UINT8) ((lost_msg_cpt << (count << 2)) >> 28)];	
+				}
+				lost_msg_length += RVT_HEX_VALUE_LENGTH;
+
+				// Send message to the UART with byte stuffing
+				nb_bytes_sent = 0;
+				while (nb_bytes_sent < lost_msg_length)
+				{
+					nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1,
+														 (UINT8 *) p_rvt_lost_msg + nb_bytes_sent,
+														 lost_msg_length - nb_bytes_sent);
+				}
+
+			} // End of if ((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG)
+
+			if (event & EVENT_MASK (RVT_TRACE_MAILBOX))
+			{
+				T_RV_HDR  *msg = NULL;
+
+				// Read the message from the mailbox
+				if ((msg = (T_RV_HDR *) rvf_read_mbox (RVT_TRACE_MAILBOX)) != NULL)
+				{
+					if (msg->msg_id == RVT_TRACE_RQST_ID)
+					{
+						UINT8   msg_format = 0;
+						UINT32  msg_length = 0;
+
+						// Get the length
+						msg_length = ((T_RVT_TRACE_RQST *) msg)->msg_length;
+
+						// Get the format
+						msg_format = ((T_RVT_TRACE_RQST *) msg)->format;
+
+						// Copy the 'User ID'
+						((UINT8 *) msg + RVT_HEADER_SIZE - 1)[0] = ((T_RVT_TRACE_RQST *) msg)->user_id;
+						msg_length++;
+
+						switch (msg_format)
+						{
+							case RVT_ASCII_FORMAT:
+								{
+									// Send message to the UART without byte stuffing
+									nb_bytes_sent = 0;
+									while (nb_bytes_sent < msg_length)
+									{
+										nb_bytes_sent += SER_tr_EncapsulateNChars (SER_LAYER_1,
+																				   (char *) msg + RVT_HEADER_SIZE - 1 + nb_bytes_sent,
+																				   msg_length - nb_bytes_sent);
+									}
+									break;
+								}
+							case RVT_BINARY_FORMAT:
+								{
+									// Send message to the UART with byte stuffing
+									nb_bytes_sent = 0;
+									while (nb_bytes_sent < msg_length)
+									{
+										nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1,
+																			 (UINT8 *) msg + RVT_HEADER_SIZE - 1 + nb_bytes_sent,
+																			 msg_length - nb_bytes_sent);
+									}
+									break;
+								}
+							default:
+								{
+									// Increment the number of messages lost.
+									// Is the buffer corrupted?
+									(rvt_lost_msg_cpt.bit_mask).count++;
+									(rvt_lost_msg_cpt.bit_mask).unknown_format = 1;
+									break;
+								}
+						}
+
+						// Deallocate the buffer
+						rvf_free_buf (msg);
+
+					} // End of if (msg->msg_id == RVT_TRACE_RQST_ID)
+
+					else
+					{
+						// Increment the number of messages lost. Is the buffer
+						// corrupted?
+						(rvt_lost_msg_cpt.bit_mask).count++;
+						(rvt_lost_msg_cpt.bit_mask).unknown_request = 1;
+					}
+
+				} // End of if (msg != NULL)
+
+				else
+				{
+					// Increment the number of messages lost. Is the buffer
+					// corrupted?
+					(rvt_lost_msg_cpt.bit_mask).count++;
+					(rvt_lost_msg_cpt.bit_mask).message_empty = 1;
+				}
+
+			}  // End of if (event & EVENT_MASK (RVT_TRACE_MAILBOX))
+
+			if ((event & (RVF_TIMER_0_EVT_MASK)) && (p_rvt_sys_time))			
+			{
+				UINT8   count           = 0;
+				UINT8   sys_time_length = RVT_HDR_LENGTH + RVT_SYS_TIME_LENGTH;
+				UINT32  current_time    = rvf_get_tick_count ();
+
+				// Append with the system time
+				for (count = 0;
+					 count < RVT_HEX_VALUE_LENGTH;
+					 count++)
+				{
+					p_rvt_sys_time[sys_time_length + count] = Num2Char[(UINT8) ((current_time << (count << 2)) >> 28)];	
+				}
+				sys_time_length += RVT_HEX_VALUE_LENGTH;
+
+				// Send message to the UART with byte stuffing
+				nb_bytes_sent = 0;
+				while (nb_bytes_sent < sys_time_length)
+				{
+					nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1,
+														 (UINT8 *) p_rvt_sys_time + nb_bytes_sent,
+														 sys_time_length - nb_bytes_sent);
+				}
+
+			} // End of if (event & (RVF_TIMER_0_EVT_MASK))
+		}
+	#else
+	
+		// Start the 'Alive Polling Timer'
+		#if (OP_WCP == 0)
+		  rvf_start_timer (RVF_TIMER_0,
+						   RVT_ALIVE_POLLING_TIME,
+						   TRUE);
+		#endif
+		
+		for (;
+			 ;
+			 )
+		{
+			// Infinite wait on 'Trace Task' mailbox or timer events
+			event = rvf_wait ((1 << RVT_TRACE_MAILBOX) | (RVF_TIMER_0_EVT_MASK),
+							  0);
+
+			// Check for some messages lost
+			if (((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) && (p_rvt_lost_msg))			
+			{
+				INT8    count           = 0;
+				UINT8   lost_msg_length = RVT_LOST_MSG_LENGTH;
+				UINT32  lost_msg_cpt    = rvt_lost_msg_cpt.overall_value;
+
+				// Append with the number of messages lost
+				rvt_lost_msg_cpt.overall_value = 0;
+				for (count = 0;
+					 count < RVT_HEX_VALUE_LENGTH;
+					 count ++)
+				{
+					p_rvt_lost_msg[lost_msg_length + count] = Num2Char[(UINT8) ((lost_msg_cpt << (count << 2)) >> 28)];
+				}
+				rvt_lost_msg_length += RVT_HEX_VALUE_LENGTH;
+
+				// Append with the '\n' and '\r' characters for the hyper terminal
+				p_rvt_lost_msg[lost_msg_length++] = '\n';
+				p_rvt_lost_msg[lost_msg_length++] = '\r';
+
+				// Send the message to the UART without byte stuffing
+				nb_bytes_sent = 0;
+				while (nb_bytes_sent < lost_msg_length)
+				{
+					nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1,
+														 (UINT8 *) p_rvt_lost_msg + nb_bytes_sent,
+														 lost_msg_length - nb_bytes_sent);
+				}
+
+			} // End of if ((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG)
+
+			if (event & EVENT_MASK (RVT_TRACE_MAILBOX))
+			{
+				T_RV_HDR  *msg = NULL;
+
+				// Read the message from the mailbox
+				if ((msg = (T_RV_HDR *) rvf_read_mbox (RVT_TRACE_MAILBOX)) != NULL)
+				{
+					if (msg->msg_id == RVT_TRACE_RQST_ID)
+					{
+						UINT32  msg_length = 0;
+
+						// Get the length
+						msg_length = ((T_RVT_TRACE_RQST *) msg)->msg_length;
+
+						// Send message to the UART without byte stuffing
+						nb_bytes_sent = 0;
+						while (nb_bytes_sent < msg_length)
+						{
+							nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1,
+																 msg + RVT_HEADER_SIZE + nb_bytes_sent,
+																 msg_length - nb_bytes_sent);
+						}
+
+						// Append with the '\n' and '\r' characters for the hyper terminal
+						msg_length        = 0;
+						msg[msg_length++] = '\n';
+						msg[msg_length++] = '\r';
+
+						// Send message to the UART without byte stuffing
+						nb_bytes_sent = 0;
+						while (nb_bytes_sent < msg_length)
+						{
+							nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1,
+																 msg + nb_bytes_sent,
+																 msg_length - nb_bytes_sent);
+						}
+
+						// Deallocate the buffer
+						rvf_free_buf (msg);
+
+					} // End of if (msg->msg_id == RVT_TRACE_RQST_ID)
+
+					else
+					{
+						// Increment the number of messages lost. Is the buffer
+						// corrupted?
+						(rvt_lost_msg_cpt.bit_mask).count++;
+						(rvt_lost_msg_cpt.bit_mask).unknown_request = 1;
+					}
+
+				} // End of if (msg != NULL)
+
+				else
+				{
+					// Increment the number of messages lost. Is the buffer
+					// corrupted?
+					(rvt_lost_msg_cpt.bit_mask).count++;
+					(rvt_lost_msg_cpt.bit_mask).message_empty = 1;
+				}
+
+			}  // End of if (event & EVENT_MASK (RVT_TRACE_MAILBOX))
+
+			if ((event & (RVF_TIMER_0_EVT_MASK)) && (p_rvt_sys_time))
+			{
+				UINT8   count           = 0;
+				UINT8   sys_time_length = RVT_SYS_TIME_LENGTH;
+				UINT32  current_time    = rvf_get_tick_count ();
+
+				// Append with the system time
+				for (count = 0;
+					 count < RVT_HEX_VALUE_LENGTH;
+					 count++)
+				{
+					p_rvt_sys_time[sys_time_length + count] = Num2Char[(UINT8) ((current_time << (count << 2)) >> 28)];	
+				}
+				sys_time_length += RVT_HEX_VALUE_LENGTH;
+
+				// Append with the '\n' and '\r' characters for the hyper terminal
+				p_rvt_sys_time[sys_time_length++] = '\n';
+				p_rvt_sys_time[sys_time_length++] = '\r';
+
+				// Send message to the UART without byte stuffing
+				nb_bytes_sent = 0;
+				while (nb_bytes_sent < sys_time_length)
+				{
+					nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1,
+														 (UINT8 *) p_rvt_sys_time + nb_bytes_sent,
+														 sys_time_length - nb_bytes_sent);
+				}
+
+			} // End of if (event & (RVF_TIMER_0_EVT_MASK))
+		}
+	#endif
+}	
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_RX_process                                           */
+/*                                                                              */
+/*    Purpose:         This function is called when characters are received     */
+/*                     on the serial port on receive HISR.                      */
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+void rvt_RX_process (void)
+{
+	UINT32        bytesRead;
+	static UINT8  inBuffer[255];
+
+	#ifdef FRAMING_PROTOCOL
+		BOOL                      eof              = 0;
+		static UINT8              rcv_state        = RVT_WAIT_FOR_HEADER;
+		static UINT32             total_bytesRead  = 0;
+		static RVT_CALLBACK_FUNC  rx_callback_func = NULL;
+
+		// Get all bytes from the UART RX FIFO
+		for (;
+			 ;
+			 )
+		{
+			// Read and destuff the UART RX FIFO and fill inBuffer with received
+			// bytes
+			bytesRead = SER_tr_ReadNBytes (SER_LAYER_1,
+										   (char *) (inBuffer + total_bytesRead),
+										   sizeof (inBuffer) - total_bytesRead,
+										   &eof);
+
+			// Check for the header. Hence, get the sendee
+			if ((rcv_state == RVT_WAIT_FOR_HEADER) && \
+				(bytesRead) && \
+				!(total_bytesRead))
+			{
+				if ((inBuffer[0] == RVT_RV_HEADER) || \
+					(inBuffer[0] == RVT_L1_HEADER) || \
+					(inBuffer[0] == RVT_L23_HEADER) || \
+					(inBuffer[0] == RVT_TM_HEADER) || \
+					(inBuffer[0] == RVT_RNET_HEADER) || \
+					(inBuffer[0] == RVT_PROF_HEADER) || \
+					(inBuffer[0] == RVT_GTTBACK_HEADER) || \
+					(inBuffer[0] == RVT_OTHER_HEADER))
+				{
+					UINT8  idtab = 0;
+				
+					// Search for the ID in the table
+					for (idtab = 0;
+						 rvt_user_db[idtab].user_id != RVT_INVALID_HEADER;
+						 idtab++)
+					{
+						if (rvt_user_db[idtab].user_id == inBuffer[0])
+						{
+							rx_callback_func = rvt_user_db[idtab].rx_callback_func;
+							break;
+						}
+					}
+					rcv_state = RVT_WAIT_FOR_DATA;
+				}
+			}
+
+			// Update the total number of bytes read, regarding the current frame 
+			total_bytesRead += bytesRead;
+
+			// Call the corresponding callback function when a complete message is
+			// received (eof odd)
+			if (eof & 0x01)
+			{
+				// Invoke the callback function
+				if (rx_callback_func != NULL)
+				{
+					rx_callback_func ((T_RVT_BUFFER) (inBuffer + 1),
+									  total_bytesRead - 1);
+					rx_callback_func = NULL;
+				}
+
+				// Wait for the next frame to come
+				rcv_state       = RVT_WAIT_FOR_HEADER;
+				total_bytesRead = 0;
+			}
+
+			// inBuffer may be full due to some synchro lost problems
+			else if (total_bytesRead == sizeof (inBuffer))
+			{
+				// If still waiting for the header, discard received characters and
+				// reset static variables for the next frame to come
+				if (rcv_state == RVT_WAIT_FOR_HEADER)
+				{
+					total_bytesRead = 0;
+					break;
+				}
+
+				// Just discard characters received as payload
+				total_bytesRead = sizeof (inBuffer[0]);
+			}
+
+			// Proceed with the next concatenated frame whether more bytes left
+			if (eof > 1)
+			{
+				continue;
+			}
+			break;
+		}
+	#else
+
+		// Read the UART RX FIFO and fill inBuffer with received bytes
+		bytesRead = SER_tr_ReadNChars (SER_LAYER_1,
+									   (char *) inBuffer,
+									   sizeof (inBuffer));
+
+		// Invoke the Testmode callback function : this is the only one able,
+		// for the moment, to send an external command !!  WARNING : This
+		// should be the same name than the one already registered in
+		// create_RVtasks.c.
+		tm_receive ((T_RVT_BUFFER) inBuffer,
+					bytesRead);
+	#endif
+}
+
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   rvt_activate_RX_HISR                                     */
+/*                                                                              */
+/*    Purpose:         This function is called when an RX interrupt occurs.     */
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+void rvt_activate_RX_HISR (void)                                    
+{                                                         
+	NU_Activate_HISR (&TI_rcv_HISR);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/ti_profiler/ti_prf_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,46 @@
+/**
+ * @file	ti_prf_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 __TI_PRF_POOL_SIZE_H_
+#define __TI_PRF_POOL_SIZE_H_
+
+
+#ifndef _WINDOWS
+  #include "debug.cfg"
+#endif
+
+
+/*
+ * Values used in ti_profiler_env.h
+ */
+#define TI_PRF_STACK_SIZE (1000)
+
+#if (TI_NUC_MONITOR == 1)
+  #define TI_PRF_MB1_SIZE (1080000)
+#else
+  #define TI_PRF_MB1_SIZE (400)
+#endif
+
+#define TI_PRF_POOL_SIZE  (TI_PRF_STACK_SIZE + TI_PRF_MB1_SIZE)
+
+
+#endif /*__TI_PRF_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/ti_profiler/ti_profiler.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,1773 @@
+/************************************************************************************
+* ti_profiler.c :  contains ti profiling module function                            *
+*																					*	
+*																					*
+*	Author: Philippe Martinez														*
+*																					*
+*	version: 1.0																	*
+*																					*
+*	Date: 07/16/2001																*
+*   (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved		*		
+************************************************************************************/
+
+#include "config/debug.cfg"
+
+#if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+
+  /*-------------------------------------------------------*/
+  /* include files                                         */
+  /*-------------------------------------------------------*/
+
+  #include <string.h>
+
+  #include "main/sys_types.h"
+
+  #include "nucleus.h" 
+  #include "qu_defs.h" 
+  #include "tc_defs.h" 
+
+  #include "rvf/rvf_api.h"
+  #include "rvt/rvt_gen.h"
+  #include "rvt/rvt_def_i.h"
+
+  #include "mem.h"
+  #include "iq.h"
+
+  #include "rvt/ti_profiler/ti_profiler.h"
+
+  #include "timer.h"       
+  #include "inth.h"
+
+  /*-------------------------------------------------------*/
+  /* Global instances                                      */
+  /*-------------------------------------------------------*/
+
+  // task variable instance
+  T_RVF_MB_ID   prof_mb_id;
+  T_RVT_USER_ID prof_trace_id;
+  T_RVF_ADDR_ID prof_addr_id;
+  
+  /*-------------------------------------------------------*/
+  /* internal prototypes                                   */
+  /*-------------------------------------------------------*/
+
+  void     ti_prf_init( void );
+  T_RV_RET ti_prf_core(void);
+  void     ti_profiler_trace_rx_callback( T_RVT_BUFFER trace_msg, UINT16 trace_msg_size );
+  #if (L1_TRACER == 1)
+    extern void SendTraces(char *s);
+  #endif
+   
+#endif
+
+
+#if (TI_PROFILER == 1)
+
+  /*-------------------------------------------------------*/
+  /* Global instances                                      */
+  /*-------------------------------------------------------*/
+
+  // Internal state of profiling
+  T_PROFILER_STATE profiler_state = PROFILER_STOPPED;
+
+
+  // Buffer that contains the Profiling samples.
+  //  Structure (SYS_UWORD32 buffer):
+  //     C_OP_CODE_TDMA_BEGIN
+  //     PC Samples ......
+  //     C_OP_CODE_TDMA_END
+  //     ......
+  //     C_OP_CODE_TDMA_BEGIN
+  //     PC Samples ......
+  //     C_OP_CODE_TDMA_END
+
+  SYS_UWORD32   pr_buffer[PR_BUFFER_SIZE];
+  // pointer on pr_buffer
+  SYS_UWORD32   pos_pr_buffer    = 0;
+  SYS_UWORD32   pr_buffer_length = PR_BUFFER_SIZE;
+
+  T_PROFILER_BUFFER_STATE ti_profiler_buffer_state = LOGGING;
+  T_PROFILER_HANDLER      ti_profiler_active       = NOT_ACTIVE;
+ 
+  // hisr variable instance
+  NU_HISR       ti_profiler_cb;
+  SYS_UWORD8    ti_profiler_hisr_stack[500];
+
+   // Event variables
+   // NO_SLEEP_EVENT
+   SYS_UWORD32   ti_profiler_nb_sleep_call         = 0;
+   SYS_UWORD32   ti_profiler_nb_sleep_counter_ref  = 0;
+ 
+   T_PROFILER_EVENTS    ti_profiler_event_state = NO_EVENT;
+  
+  /*-------------------------------------------------------*/
+  /* internal prototypes                                   */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_start( BOOL enable );
+  void ti_profiler_handler( SYS_UWORD32 programCounter );
+  void ti_profiler_freeze( void );
+  void ti_profiler_unfreeze( void );
+  void ti_profiler_tdma_action( void );
+  void ti_profiler_init_profiler_module( void );
+  void ti_profiler_hisr( void );
+
+  void l1_profiler_open( void );
+  void l1_profiler_close( void );
+  void l1_profiler_flush( void );
+
+  /*-------------------------------------------------------*/
+  /* external prototypes                                   */
+  /*-------------------------------------------------------*/
+  
+  SYS_UWORD32 l1_get_next_absolute_fn( void );
+   
+  /*-------------------------------------------------------*/
+  /* ti_profiler_start()                                   */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description: Start or Stop the timer                  */
+  /* ------------                                          */
+  /* parameters                                            */
+  /*  enable = 1 => Unmask + start the timer 1             */
+  /*    Initialize buffer.								   */
+  /*  enable = 0 => mask + stop the timer 1                */
+  /*    Close Buffer.									   */
+  /*-------------------------------------------------------*/
+ 
+  void ti_profiler_start( BOOL enable )
+  {
+    if( enable ) 
+    {   
+      TM_EnableTimer( PR_TIMER_NUM );
+      IQ_Unmask( IQ_TIM1 );
+      IQ_InitLevel( IQ_TIM1, FIQ, 0, 1 );
+
+      TM_ResetTimer( PR_TIMER_NUM, PR_TIMER_RESET_VALUE, 1, 0 );
+      TM_StartTimer( PR_TIMER_NUM );
+    }
+    else
+    {
+      IQ_Mask( IQ_TIM1 );
+      IQ_InitLevel( IQ_TIM1, 0, 0, 1 );
+      TM_StopTimer( PR_TIMER_NUM );
+    }
+  } // ti_profiler_start
+
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_handler()                                 */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Store the Program counter in a static buffer	       */
+  /*  If buffer is full, deactivate the profiling and      */
+  /*  activate the ti_profiler_hisr();                     */
+  /*-------------------------------------------------------*/
+ 
+  void ti_profiler_handler( SYS_UWORD32 programCounter )
+  {
+ 
+    // Store the program Counter in log buffer 
+    pr_buffer[ pos_pr_buffer++ ] = programCounter; 
+ 
+  } // ti_profiler_handler
+
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_freeze()  ti_profiler_unfreeze()          */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Function to suspend/resume the profiling             */
+  /*-------------------------------------------------------*/
+ 
+  void ti_profiler_freeze()
+  {
+    TM_StopTimer( PR_TIMER_NUM );
+  } // ti_profiler_freeze
+
+  void ti_profiler_unfreeze()
+  {
+    TM_StartTimer( PR_TIMER_NUM );  
+  } // ti_profiler_unfreeze
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_init_profiler_module()                    */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description: Initialize profiling task and hisr       */
+  /* ------------                                          */
+  /* Note : this init will changed                         */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_init_profiler_module( void )
+  {
+    // Fill the entire stack with the pattern 0xFE
+    memset( ti_profiler_hisr_stack, 0xFE, sizeof( ti_profiler_hisr_stack ) );
+
+    // Create the HISR which is called from power interrupts
+    NU_Create_HISR( &ti_profiler_cb, 
+                    "TI PROF", 
+                    ti_profiler_hisr, 
+                    2,
+                    ti_profiler_hisr_stack, 
+                    sizeof( ti_profiler_hisr_stack ) ); // lowest prty
+
+  } // ti_profiler_init_profiler_module
+
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_hisr() High Interrupt service routine     */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This hisr stands as relay for the profiler LISR.     */
+  /*  It sends a message to the profiler task to start the */
+  /*   buffer extraction.                                  */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_hisr( void )
+  {	
+    T_PROFILER_MSG * msg;
+	 
+    //send a message to the ti profiler task
+	if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
+	{
+	  msg->msg_id = TI_PROFILER_OUTPUT_BUFFER;
+	  rvf_send_msg( prof_addr_id, msg );
+	}
+  } // ti_profiler_hisr
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_tdma_action()                              */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*                                                       */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_tdma_action(void)
+  {
+ 
+    switch( profiler_state )
+    {
+      case PROFILER_RUNNING : 
+      {
+	    SYS_UWORD8  output_buffer_condition = 0;
+
+        // suspend the profiler
+        //ti_profiler_freeze();
+		ti_profiler_start( FALSE );
+
+        if( ti_profiler_event_state == NO_SLEEP_EVENT )
+		{
+		  // Need to reach the event to output the buffer
+		  if( ti_profiler_nb_sleep_call++ >= ti_profiler_nb_sleep_counter_ref )
+		  {
+			  output_buffer_condition   = 1;
+			  ti_profiler_nb_sleep_call = 0;
+			 // ti_profiler_buffer_state = FLUSH;			  
+		  } // End if
+		}
+		else
+		{
+		  output_buffer_condition = 1;  
+		} // End if 
+ 
+
+        // Check if buffer threshold reached
+   	    if( pos_pr_buffer >= PR_BUFFER_THRESHOLD )
+	    {
+          // change the status of the buffer
+		  ti_profiler_buffer_state = LOGGING;
+
+	      // Insert the End of Buffer OP code
+	      pr_buffer[ pos_pr_buffer++ ] = C_OP_CODE_END_BUFFER;
+          
+		  // Specifie used length of buffer in SYS_UWORD32
+          pr_buffer_length = pos_pr_buffer;
+           
+          if( output_buffer_condition == 1 )
+          { 
+            // Change profiler state to freezed
+	        profiler_state = PROFILER_FREEZED;
+
+	        // Activate the hisr in order to start the buffer output
+	        NU_Activate_HISR( &ti_profiler_cb );
+          }
+	      else
+	      {
+		    // insert TDMA begin OP Code
+            pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;	           
+            pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;	           
+		    // Insert current fn
+	        pr_buffer[ 2 ] = l1_get_next_absolute_fn();
+
+		    // initialize buffer pointer
+	        pos_pr_buffer = 3;
+
+			ti_profiler_start( TRUE );
+		  } // End if
+
+        }
+	    else
+	    {
+	      // insert OP Code begining of TDMA
+	      pr_buffer[pos_pr_buffer++] = C_OP_CODE_TDMA_BEGIN;
+		  // Insert current fn
+	      pr_buffer[pos_pr_buffer++] = l1_get_next_absolute_fn();
+
+	      // resume profiler
+	      //ti_profiler_unfreeze();
+		  ti_profiler_start( TRUE );
+        } // End if
+
+
+        break;
+      }	// PROFILER_RUNNING
+
+      case PROFILER_TO_BE_RAN : 
+      {
+		// insert TDMA begin OP Code
+        pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;	           
+        pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;	           
+		// Insert current fn
+	    pr_buffer[ 2 ] = l1_get_next_absolute_fn();
+
+		// initialize buffer pointer
+	    pos_pr_buffer = 3;
+        // start the profiler
+        profiler_state = PROFILER_RUNNING;
+
+	    // start the profiler
+	    ti_profiler_start( TRUE );
+
+        break;
+      }	// PROFILER_TO_BE_RAN
+
+      case PROFILER_TO_BE_STOPPED : 
+      {
+	    // stop the profiler
+	    ti_profiler_start( FALSE );
+
+        // Insert End Buffer Op Code.
+        pr_buffer[pos_pr_buffer++] = C_OP_CODE_END_BUFFER; 
+        profiler_state             = PROFILER_STOPPED;
+
+	    // Activate the hisr in order to start the buffer output
+	    NU_Activate_HISR( &ti_profiler_cb );
+
+        // Returns to inactive
+		ti_profiler_active = NOT_ACTIVE;
+
+        break;
+      } // PROFILER_TO_BE_STOPPED
+
+      case PROFILER_TO_BE_UNFREEZED : 
+      {
+		// Init profiling buffer
+		// insert TDMA begin OP Code
+        pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;	           
+        pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;	           
+		// Insert current fn
+	    pr_buffer[ 2 ] = l1_get_next_absolute_fn();
+
+		// initialize buffer pointer
+	    pos_pr_buffer = 3;
+        // Insert the TDMA Start Op Code
+        profiler_state = PROFILER_RUNNING;
+
+	    // resume profiler
+	    //ti_profiler_unfreeze();
+		ti_profiler_start( TRUE );
+
+        break;
+      }	// PROFILER_TO_BE_UNFREEZED
+
+      default :
+      {
+        // nothing to do
+        break;
+      }	// default
+
+    } // End switch
+  
+  } // ti_profiler_tdma_action
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_open()                                    */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Start the profiling on the next TDMA occurence       */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_open( void )
+  {
+    if( ti_profiler_active == NOT_ACTIVE )
+	{
+
+	} // End if
+  } // ti_profiler_open
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_close()                                   */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Stop the profiling on the next TDMA occurence        */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_close( void )  
+  {
+    if( ti_profiler_active == NOT_ACTIVE )
+	{
+	   l1_profiler_close();
+	} // End if
+  } // ti_profiler_close
+
+  /*-------------------------------------------------------*/
+  /* l1_profiler_flush()                                   */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  freeze the profiling and flush the current profiling */
+  /*   buffer. Profiling will restart after output of the  */
+  /*   buffer.                                             */ 
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_flush( void )
+  {
+    if( ti_profiler_active == NOT_ACTIVE )
+	{
+	  l1_profiler_flush();
+	} // End if
+  } // ti_profiler_flush
+
+  // To be used only TI internal modules
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_open()                                    */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Start the profiling on the next TDMA occurence       */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void l1_profiler_open( void )
+  {
+
+     if( ti_profiler_active != NOT_ACTIVE )
+	 {
+	   // stop profiler timer 
+	   ti_profiler_start( FALSE );
+       // go to idle
+	   profiler_state = PROFILER_STOPPED;
+     } // Endif
+
+   	 // insert TDMA begin OP Code
+     pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;	           
+     pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;	           
+
+	 // Insert current fn
+	 pr_buffer[ 2 ] = l1_get_next_absolute_fn();
+								
+	 // initialize buffer pointer
+	 pos_pr_buffer = 3;
+
+     // change state of profiler
+     profiler_state = PROFILER_TO_BE_RAN; 
+
+  } // ti_profiler_open
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_close()                                   */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  Stop the profiling on the next TDMA occurence        */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void l1_profiler_close( void )  
+  {
+	// stop the profiler
+	ti_profiler_start( FALSE );
+
+    // Insert TDMA_BOUNDARY Op Code.
+    pr_buffer[pos_pr_buffer++] = C_OP_CODE_END_BUFFER; 
+    profiler_state             = PROFILER_STOPPED;
+
+	// Activate the hisr in order to start the buffer output
+	NU_Activate_HISR( &ti_profiler_cb );
+
+  } // ti_profiler_close
+
+  /*-------------------------------------------------------*/
+  /* l1_profiler_flush()                                   */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  freeze the profiling and flush the current profiling */
+  /*   buffer. Profiling will restart after output of the  */
+  /*   buffer.                                             */ 
+  /*-------------------------------------------------------*/
+
+  void l1_profiler_flush( void )
+  {
+    ti_profiler_buffer_state = FLUSH;
+  } // ti_profiler_flush
+
+#endif // PROFILER
+
+#if (TI_NUC_MONITOR == 1)
+
+  /*-------------------------------------------------------*/
+  /* Global instances                                      */
+  /*-------------------------------------------------------*/
+  // management of monitoring buffer
+   
+  //    Internal state of nucleus monitoring
+   
+  T_NUC_MONITOR_STATE ti_nuc_monitor_state       = NUC_MONITOR_STOPPED;
+
+  // pointers on current buffer
+  SYS_UWORD8*    ti_nuc_monitor_current_buffer   = NULL;
+  SYS_UWORD8     ti_nuc_monitor_current_position = 0;
+
+  // Create static doubled bufferised LISR buffers (max 10 LISR by TDMA)
+  SYS_UWORD8     ti_nuc_monitor_LISR_Buffer[C_NUC_LISR_BUF_PG_NB][C_NUC_MAX_LISR];
+  SYS_UWORD8     ti_nuc_monitor_LISR_current_page = 0;
+  SYS_UWORD8     ti_nuc_monitor_LISR_current_pos  = 0;
+  SYS_UWORD8     ti_nuc_monitor_LISR_next_page    = 0;
+  SYS_UWORD8     ti_nuc_monitor_LISR_next_pos     = 0;
+
+  // Create static doubled bufferised LISR buffers (max 10 LISR by TDMA)
+  SYS_UWORD8     ti_nuc_monitor_Thread_Buffer[C_NUC_THREAD_BUF_PG_NB][C_NUC_MAX_THREAD];
+  SYS_UWORD8     ti_nuc_monitor_Thread_current_page = 0;
+  SYS_UWORD8     ti_nuc_monitor_Thread_current_pos  = 0;
+  SYS_UWORD8     ti_nuc_monitor_Thread_next_page    = 0;
+  SYS_UWORD8     ti_nuc_monitor_Thread_next_pos     = 0;
+
+  // hisr variable instance
+  NU_HISR        ti_nuc_monitor_cb;
+  SYS_UWORD8     ti_nuc_monitor_hisr_stack[ 500 ];
+
+  // Array that store the ID <-> pointer of the Nucleus Components
+  //SYS_UWORD32*   ti_nuc_monitor_thread_id[ NUC_MONITOR_MAX_ID ];
+  SYS_UWORD32    ti_nuc_monitor_thread_id[ NUC_MONITOR_MAX_ID ];
+  SYS_UWORD8     ti_nuc_monitor_thread_pos      = 0;
+
+  //SYS_UWORD32*   ti_nuc_monitor_queue_id[ NUC_MONITOR_MAX_ID ];
+  SYS_UWORD32    ti_nuc_monitor_queue_id[ NUC_MONITOR_MAX_ID ];
+  SYS_UWORD8     ti_nuc_monitor_queue_pos       = 0;
+
+  // LISR IRQ value
+  SYS_UWORD8     IRQ_value;
+
+  // Indicates the nucleus monitor part to switch Thread buffer page
+  SYS_UWORD8     ti_nuc_monitor_change_thread_page = 0;
+
+  // Indicates that the IDLE mode has been reached
+  // (to be reset in LISR or Thread monitor function)
+  SYS_UWORD8     ti_nuc_monitor_idle_reached  = 0;
+
+  // debug
+  SYS_UWORD32    ti_nuc_monitor_lost_messages = 0;
+
+  /*-------------------------------------------------------*/
+  /* internal prototypes                                   */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_tdma_action( void );
+  void ti_nuc_monitor_init_module( void );
+  void ti_nuc_monitor_hisr( void );
+  void ti_nuc_monitor_check_ID_buffer( void );
+  void ti_nuc_monitor_LISR_log( void );
+  void ti_nuc_monitor_LISR_log_end( void );
+  void ti_nuc_monitor_Thread_log( void );
+  void ti_nuc_monitor_Queue_log( SYS_UWORD32* queue_pointer, SYS_UWORD8 status, SYS_UWORD8 Direction );
+  void ti_nuc_monitor_sleep( void );
+
+  T_RVT_RET ti_nuc_monitor_mem_alloc(T_RVT_USER_ID user_id, 
+                                     T_RVT_MSG_LG buffer_lenght, 
+                                     T_RVT_BUFFER * buff);
+
+  /*-------------------------------------------------------*/
+  /* external prototypes                                   */
+  /*-------------------------------------------------------*/
+  
+  extern SYS_UWORD16  l1_get_actual_fn_mod42432( void );
+  extern SYS_UWORD32* TCD_Current_Thread;
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_init_module()                          */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description: Initialize hisr                          */
+  /* ------------                                          */
+  /* Create hisr and initialize thread/queue structures.   */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_init_module( void )
+  {
+    SYS_UWORD8	i;
+
+    // Fill the entire stack with the pattern 0xFE
+    memset( ti_nuc_monitor_hisr_stack, 0xFE, sizeof( ti_nuc_monitor_hisr_stack ) );
+
+    // Create the HISR 
+        NU_Create_HISR( &ti_nuc_monitor_cb, 
+                    "TI MON", 
+                    ti_nuc_monitor_hisr, 
+                    2,
+                    ti_nuc_monitor_hisr_stack, 
+                    sizeof( ti_nuc_monitor_hisr_stack ) ); // lowest prty
+
+  } // ti_nuc_monitor_init_module
+
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_hisr() High Interrupt service routine  */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  It sends a message to the profiler task to start the */
+  /*   buffer extraction.                                  */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_hisr( void )
+  {	
+    SYS_UWORD8     remaining_bytes; 
+	SYS_UWORD16    fn;
+    T_PROFILER_MSG *msg;
+	SYS_UWORD8     i;
+
+    // Allocate a buffer first time
+    if(( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN ) || 
+	   ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STARTED ))
+	{
+	  if((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                     NUC_MONITOR_BUFFER_SIZE, 
+			             (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+		            == RVT_OK)
+	  {
+	    
+		ti_nuc_monitor_current_position = 0;
+
+		// Insert the interrupt OP Code (0x00 0x00 0x00) 
+		if( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN )
+		{
+		  for( i=0; i < 3; i++)
+		  {
+		    ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = 0x00;			     
+		  } // End for
+	    } // Endif
+
+        // Reset intermediate buffer pointers
+		ti_nuc_monitor_Thread_current_pos  = 0;
+		ti_nuc_monitor_LISR_current_pos    = 0;
+	  }
+	  else
+	  {
+	    return;
+	  } // End if
+	  
+	  // Write FN OP CODE  : (0x00 | xx)
+
+	  ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	    (SYS_UWORD8) ( C_OP_CODE_FN_LOG );
+
+      // Insert the fn%42432 
+      fn = l1_get_actual_fn_mod42432();
+
+      // insert LSB
+	  ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	    (SYS_UWORD8) (fn & 0x00ff);
+	 
+	  // insert MSB 
+	  ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	    (SYS_UWORD8) ((fn & 0xff00) >> 8);
+
+      ti_nuc_monitor_state            = NUC_MONITOR_RUNNING;
+      	  
+	  return; 
+	} // End if
+	
+	// Copy the LISR and Thread buffer into current buffer.
+
+    //   - LISR array
+
+    // Check the number of byte remaining in the current 
+    // log buffer vs LISR buffer.
+
+    remaining_bytes =  NUC_MONITOR_BUFFER_SIZE - ti_nuc_monitor_current_position;
+
+	if( remaining_bytes > ti_nuc_monitor_LISR_next_pos )
+	{
+	  // Copy ti_nuc_monitor_LISR_next_pos bytes to Nucleus log buffer
+
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ 0 ],
+              ti_nuc_monitor_LISR_next_pos);
+
+	  ti_nuc_monitor_current_position += ti_nuc_monitor_LISR_next_pos;
+
+	}
+	else
+	{
+
+	  // Copy remaining_bytes bytes to Nucleus log buffer
+
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ 0 ],
+              remaining_bytes);
+
+      ti_nuc_monitor_current_position += remaining_bytes;
+
+      // Send current buffer
+
+      // send a message to the ti profiler task
+
+	  if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
+	  {
+	    msg->msg_id                     = TI_NUC_MONITOR_OUTPUT_BUFFER;
+	    msg->p_buffer                   = ti_nuc_monitor_current_buffer;
+	    msg->buffer_size                = ti_nuc_monitor_current_position;
+
+	    ti_nuc_monitor_current_position = 0;
+
+	    if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
+		{
+          ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	      return;		  
+		} // End if
+	  }
+	  else
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return; 
+	  } // End if
+
+      // Change Nucleus log buffer
+
+	  if((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                     NUC_MONITOR_BUFFER_SIZE, 
+			             (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+		            != RVT_OK)
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return;
+	  } // End if 
+
+	  // Copy remaining_bytes bytes to Nucleus log buffer
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ remaining_bytes ],
+              ( ti_nuc_monitor_LISR_next_pos - remaining_bytes ));
+
+	  ti_nuc_monitor_current_position += ( ti_nuc_monitor_LISR_next_pos - remaining_bytes );
+
+	} // End if
+         
+    //   - Thread Array
+
+    // Check the number of byte remaining in the current 
+    // log buffer vs Thread buffer.
+
+    remaining_bytes =  NUC_MONITOR_BUFFER_SIZE - ti_nuc_monitor_current_position;
+
+	if( remaining_bytes > ti_nuc_monitor_Thread_next_pos )
+	{
+	  // Copy ti_nuc_monitor_Thread_next_pos bytes to Nucleus log buffer
+
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ 0 ],
+              ti_nuc_monitor_Thread_next_pos);
+
+	  ti_nuc_monitor_current_position += ti_nuc_monitor_Thread_next_pos;
+
+	}
+	else
+	{
+
+	  // Copy remaining_bytes bytes to Nucleus log buffer
+
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ 0 ],
+              remaining_bytes);
+
+      ti_nuc_monitor_current_position += remaining_bytes;
+
+      // Send current buffer
+
+      // send a message to the ti profiler task
+
+	  if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
+	  {
+	    msg->msg_id                     = TI_NUC_MONITOR_OUTPUT_BUFFER;
+	    msg->p_buffer                   = ti_nuc_monitor_current_buffer;
+	    msg->buffer_size                = ti_nuc_monitor_current_position;
+
+	    ti_nuc_monitor_current_position = 0;
+
+	    if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
+		{
+          ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	      return;		  
+		} // End if
+	  }
+	  else
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return; 
+	  } // End if
+
+      // Change Nucleus log buffer
+
+	  if((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                     NUC_MONITOR_BUFFER_SIZE, 
+			             (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+		            != RVT_OK)
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return;
+	  } // End if 
+
+	  // Copy remaining_bytes bytes to Nucleus log buffer
+      memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ], 
+              &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ remaining_bytes ],
+              ( ti_nuc_monitor_Thread_next_pos - remaining_bytes ));
+
+	  ti_nuc_monitor_current_position += ( ti_nuc_monitor_Thread_next_pos - remaining_bytes );
+
+	} // End if
+    
+	// Exit if monitoring must be stopped
+
+    if( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STOP )
+	{
+	  ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
+	  return;
+	} // End if
+
+    // Insert actual Frame number 
+
+    // Check if enough space in current buffer
+	if( ti_nuc_monitor_current_position >= (NUC_MONITOR_BUFFER_SIZE - 3) )
+	{
+      // send a message to the ti profiler task
+
+	  if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
+	  {
+	    msg->msg_id                     = TI_NUC_MONITOR_OUTPUT_BUFFER;
+	    msg->p_buffer                   = ti_nuc_monitor_current_buffer;
+	    msg->buffer_size                = ti_nuc_monitor_current_position;
+
+	    ti_nuc_monitor_current_position = 0;
+
+	    if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
+		{
+          ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	      return;		  
+		} // End if
+	  }
+	  else
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return; 
+	  } // End if
+
+      // Change Nucleus log buffer
+
+	  if((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                     NUC_MONITOR_BUFFER_SIZE, 
+			             (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+		            != RVT_OK)
+	  {
+	    ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
+	    return;
+	  } // End if 
+	} // End if
+
+	// Write FN OP CODE  : (0x00 | xx)
+
+	ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	  (SYS_UWORD8) ( C_OP_CODE_FN_LOG );
+
+    // Insert the fn%42432 
+    fn = l1_get_actual_fn_mod42432();
+
+    // insert LSB
+	ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	  (SYS_UWORD8) (fn & 0x00ff);
+	 
+	// insert MSB 
+	ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
+	  (SYS_UWORD8) ((fn & 0xff00) >> 8);
+
+  } // ti_nuc_monitor_hisr
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_check_ID_buffer()                      */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  During the Thread/Queue ID -> names buffer           */
+  /*  transmission, change current buffer.                 */
+  /*  Send the full buffer and allocate a new one.         */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_check_ID_buffer( void )
+  {
+    // Reset pointer
+	ti_nuc_monitor_current_position = 0; 
+
+	// Send a message to the Riviera Tracer to Output the current buffer.
+    if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) ti_nuc_monitor_current_buffer, 
+                               prof_trace_id,
+                               NUC_MONITOR_BUFFER_SIZE,   // Length in bytes  
+                               RVT_BINARY_FORMAT ) != RVT_OK )
+    {
+	  // code to insert a breakpoint if failed. 
+      ti_nuc_monitor_state = NUC_MONITOR_STOPPED; 		     
+    } // End if
+
+
+    // Allocate one buffer.
+     do
+     {
+	   ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
+			  
+	   if ((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                       NUC_MONITOR_BUFFER_SIZE, 
+		   	             (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+		     	!= RVT_OK)
+  	   {
+	     ti_nuc_monitor_state = NUC_MONITOR_WAITING;			  
+	   } // End if
+      } while (ti_nuc_monitor_state == NUC_MONITOR_WAITING);
+         	
+  } // ti_nuc_monitor_check_ID_buffer
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_tdma_action()                          */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  this function activate the HISR monitor              */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_tdma_action( void )
+  {
+
+    if(( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )   ||
+	   ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN ) ||
+	   ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STOP ) ||
+	   ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STARTED ))
+	{
+
+      // Activate the hisr in order to start the buffer	fill
+	  NU_Activate_HISR( &ti_nuc_monitor_cb );
+       	  
+	} // End if
+
+  } // ti_nuc_monitor_tdma_action
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_LISR_log()                             */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This function permits to include the LISR IRQ and    */
+  /*   timer value in the LISR log buffer                  */
+  /* Warning : To save cpu, no overflow check is done	   */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_LISR_log( void )
+  {
+  	SYS_UWORD16 timer_value;
+
+    if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
+	{ 
+
+      // Exit Idle mode if reached
+
+	  ti_nuc_monitor_idle_reached  = 0;
+
+	  IRQ_value = (SYS_UWORD8) ((* (volatile SYS_UWORD16 *) INTH_B_IRQ_REG) & 0x001f);
+
+	  // Write LISR OP CODE and IRQ : (0xC0 | IRQ)
+
+	  ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
+	                            [ ti_nuc_monitor_LISR_current_pos ] =
+	    (SYS_UWORD8) (C_OP_CODE_LISR_FLAG | IRQ_value);
+	  
+	  // Write the timer value
+
+	  timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
+
+	  // insert LSB
+	   
+	  ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
+	                            [ ti_nuc_monitor_LISR_current_pos + 1 ] =
+	    (SYS_UWORD8) (timer_value & 0x00ff);
+	  
+	  // insert MSB
+
+	  ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
+	                            [ ti_nuc_monitor_LISR_current_pos + 2 ] =
+	    (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
+
+      ti_nuc_monitor_LISR_current_pos += 3;
+
+	} // End if
+
+  } // ti_nuc_monitor_LISR_log
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_LISR_log_end()                         */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This function permits to include the LISR end        */
+  /*   timer value in the LISR log buffer                  */
+  /* Warning : To save cpu, no overflow check is done	   */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_LISR_log_end( void )
+  {
+	SYS_UWORD16 timer_value;
+
+    if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
+	{ 	  
+	  // Write the timer value
+
+	  timer_value = TM_ReadTimer(2);
+
+	  // insert LSB
+	   
+	  ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
+	                            [ ti_nuc_monitor_LISR_current_pos ] =
+	    (SYS_UWORD8) (timer_value & 0x00ff);
+	  
+	  // insert MSB
+
+	  ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
+	                            [ ti_nuc_monitor_LISR_current_pos + 1 ] =
+	    (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
+
+      ti_nuc_monitor_LISR_current_pos += 2;
+
+      // Switch LISR & thread buffer page if IRQ4 (TDMA)
+	  if( IRQ_value == 4 )
+	  {
+        // copy current to next 
+        ti_nuc_monitor_LISR_next_pos    = ti_nuc_monitor_LISR_current_pos;
+	    ti_nuc_monitor_LISR_next_page   = ti_nuc_monitor_LISR_current_page;
+
+        // instead of changing the Thread page here, set a boolean
+		ti_nuc_monitor_change_thread_page = 1;
+
+        //ti_nuc_monitor_Thread_next_pos  = ti_nuc_monitor_Thread_current_pos;
+	    //ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
+
+        // Reset current pointer
+        ti_nuc_monitor_LISR_current_pos   = 0;
+        //ti_nuc_monitor_Thread_current_pos = 0;
+      
+        // Change page
+        if( ti_nuc_monitor_LISR_current_page == 0 )
+        {
+	       ti_nuc_monitor_LISR_current_page   = 1;
+	    //   ti_nuc_monitor_Thread_current_page = 1;
+	    }
+        else
+        {
+	       ti_nuc_monitor_LISR_current_page   = 0;
+		//   ti_nuc_monitor_Thread_current_page = 0;
+        } // End if
+
+		// reset IRQ_value
+		IRQ_value = 0;
+
+        // reset timer 
+        TM_ResetTimer (2, 0xFFFF, 1, 0);
+        TM_StartTimer (2);
+
+        // Doesn't work
+	    // * (volatile SYS_UWORD16 *) TIMER2_LOAD_TIM = 0xFFFF;
+		// * (volatile SYS_UWORD16 *) TIMER2_CNTL     = 0x0003;
+
+	  } // End if  
+  	  
+	} // End if
+    
+  } // ti_nuc_monitor_LISR_log_end
+   
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_Thread_log()                           */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This function permits to include the Thread and      */
+  /*   timer value in the log buffer                       */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_Thread_log( void )
+  {
+	SYS_UWORD16	timer_value;
+	SYS_UWORD8  i;
+
+    if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
+	{ 
+
+      // Exit Idle mode if reached
+
+	  ti_nuc_monitor_idle_reached  = 0;
+
+      // Check if page must be changed 
+	  if( ti_nuc_monitor_change_thread_page == 1 )
+	  {
+
+	    ti_nuc_monitor_change_thread_page = 0;
+
+        // copy current to next 
+        ti_nuc_monitor_Thread_next_pos  = ti_nuc_monitor_Thread_current_pos;
+	    ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
+
+        // Reset current pointer
+        ti_nuc_monitor_Thread_current_pos = 0;
+      
+        // Change page
+        if( ti_nuc_monitor_Thread_current_page == 0 )
+        {
+	       ti_nuc_monitor_Thread_current_page = 1;
+	    }
+        else
+        {
+		   ti_nuc_monitor_Thread_current_page = 0;
+        } // End if
+        
+	  } // End if
+
+	  // Search the ID considering the Nucleus_Current_thread Pointer
+
+      for( i = 0; i < ti_nuc_monitor_thread_pos ; i++ )
+	  {
+		if( ti_nuc_monitor_thread_id[ i ] == (SYS_UWORD32) TCD_Current_Thread )
+		{
+		  // insert the OP Code Thread | ID
+	      ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                                  [ ti_nuc_monitor_Thread_current_pos ] =
+	                       (SYS_UWORD8) (C_OP_CODE_THREAD_FLAG | i);
+          // exit loop
+	      break;	      		  
+		} // End if
+      } // End for
+	  
+	  // Write the timer value
+
+	  timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
+
+	  // insert LSB
+	   
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                            [ ti_nuc_monitor_Thread_current_pos + 1 ] =
+	    (SYS_UWORD8) (timer_value & 0x00ff);
+	  
+	  // insert MSB
+
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                            [ ti_nuc_monitor_Thread_current_pos + 2 ] =
+	    (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
+
+      ti_nuc_monitor_Thread_current_pos += 3;
+
+	} // End if
+
+  } // ti_nuc_monitor_Thread_log
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_Queue_log()                            */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This function permits to include the Queue ID and    */
+  /*   status value in the log buffer                      */
+  /*  Direction = 0 => Send message						   */
+  /*  Direction = 1 => Receive message					   */
+  /*  status    = 0 => OK       						   */
+  /*  status    = 1 => Queue full  					       */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_Queue_log( SYS_UWORD32* queue_pointer, SYS_UWORD8 status, SYS_UWORD8 Direction )
+  {
+	SYS_UWORD8	status_word;
+	SYS_UWORD8  i;
+
+
+
+    if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
+	{ 
+
+      // Exit Idle mode if reached
+
+	  ti_nuc_monitor_idle_reached  = 0;
+
+      // Check if page must be changed 
+	  if( ti_nuc_monitor_change_thread_page == 1 )
+	  {
+
+	    ti_nuc_monitor_change_thread_page = 0;
+
+        // copy current to next 
+        ti_nuc_monitor_Thread_next_pos  = ti_nuc_monitor_Thread_current_pos;
+	    ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
+
+        // Reset current pointer
+        ti_nuc_monitor_Thread_current_pos = 0;
+      
+        // Change page
+        if( ti_nuc_monitor_Thread_current_page == 0 )
+        {
+	       ti_nuc_monitor_Thread_current_page = 1;
+	    }
+        else
+        {
+		   ti_nuc_monitor_Thread_current_page = 0;
+        } // End if
+        
+	  } // End if
+
+	  // Search the ID considering the Nucleus_Current_thread Pointer
+      for( i = 0; i < ti_nuc_monitor_queue_pos ; i++ )
+	  {
+		if( ti_nuc_monitor_queue_id[ i ] == (SYS_UWORD32) queue_pointer)
+		{
+		  // insert the OP Code Thread | ID
+	      ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                                  [ ti_nuc_monitor_Thread_current_pos ] =
+	                       (SYS_UWORD8) (C_OP_CODE_QUEUE_FLAG | i);
+	      
+		  // exit loop
+	      break;	      		  
+	      		  
+		} // End if
+      } // End for
+
+	  // Write the status value and Receive/send flag
+	  
+      status_word =  (Direction << 8) | (status << 7) | i; // Direction | Status | ID
+
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                            [ ti_nuc_monitor_Thread_current_pos + 1 ] =
+	    (SYS_UWORD8) (status_word);
+	  
+	  ti_nuc_monitor_Thread_current_pos += 2;
+	  	  	  
+	} // End if
+
+  } // ti_nuc_monitor_Queue_log
+
+
+
+  /*-------------------------------------------------------*/
+  /* ti_nuc_monitor_sleep()                                */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  This function permits to include the sleep and      */
+  /*   timer value in the log buffer                       */
+  /*-------------------------------------------------------*/
+
+  void ti_nuc_monitor_sleep( void )
+  {
+
+	SYS_UWORD16	timer_value;
+	SYS_UWORD8  i;
+
+    if(( ti_nuc_monitor_state        == NUC_MONITOR_RUNNING ) &&
+	   ( ti_nuc_monitor_idle_reached == 0 ))
+	{ 
+
+      ti_nuc_monitor_idle_reached = 1;
+
+      // insert the OP Code Thread | ID
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                              [ ti_nuc_monitor_Thread_current_pos ] =
+	                    (SYS_UWORD8) (0xBF);
+	  
+	  // Write the timer value
+
+	  timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
+
+	  // insert LSB
+	   
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                            [ ti_nuc_monitor_Thread_current_pos + 1 ] =
+	    (SYS_UWORD8) (timer_value & 0x00ff);
+	  
+	  // insert MSB
+
+	  ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
+	                            [ ti_nuc_monitor_Thread_current_pos + 2 ] =
+	    (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
+
+      ti_nuc_monitor_Thread_current_pos += 3;
+	} // End if
+
+  } // ti_nuc_monitor_sleep
+
+// -------------- RVT Copied function --------------------------------
+//    --- Modified Memory Bank ----
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   ti_nuc_monitor_mem_alloc									*/
+/*                                                                              */
+/*    Purpose:         this function creates a memory bank for the profiler task*/
+/*																				*/
+/*    Input Parameters:                                                         */
+/*        refer to t_rvt_type.h													*/
+/*																				*/
+/*    Output Parameters:                                                        */
+/*        refer to t_rvt_type.h													*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+
+T_RVT_RET ti_nuc_monitor_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_lenght, T_RVT_BUFFER * buff)
+{
+	T_RVF_MB_STATUS return_value;	
+
+	return_value = rvf_get_buf (prof_mb_id, (UINT32) buffer_lenght + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff);
+
+	if (return_value == RVF_RED)
+	{
+		*buff = NULL;
+		return RVT_MEMORY_ERR;
+	}
+	else
+	{
+		*buff = *buff + RVT_HEADER_SIZE;
+		return RVT_OK;
+	}
+}  // ti_nuc_monitor_mem_alloc
+
+// -------------------------------------------------------------------
+
+#endif // TI_NUC_MONITOR
+
+#if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+
+  /*-------------------------------------------------------*/
+  /* ti_prf_init()                                         */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description: Initialize profiling hisrs               */
+  /* ------------                                          */
+  /*  Register the profiling to rvt                        */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_prf_init( void )
+  {
+    #if (TI_PROFILER == 1)
+      ti_profiler_init_profiler_module();
+	#endif
+    #if (TI_NUC_MONITOR == 1)
+      ti_nuc_monitor_init_module();
+	#endif
+    // Register to Trace task module
+	rvt_register_id( "PROF", &prof_trace_id, ti_profiler_trace_rx_callback );
+
+  } // ti_prf_init
+
+  /*-------------------------------------------------------*/
+  /* ti_prf_core()                                         */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------                                          */
+  /*  this function :                                      */
+  /*    - start the profiler on PC side message reception  */
+  /*    - stop the profiler on PC side message reception   */
+  /*    - cut the profiler buffer less than 256 bytes      */
+  /*      messages to rvt                                  */
+  /*													   */
+  /*-------------------------------------------------------*/
+
+  T_RV_RET ti_prf_core(void)
+  {
+
+    SYS_UWORD16      i = 0;
+
+    SYS_UWORD16      event;
+	SYS_UWORD16      message_length;
+    T_PROFILER_MSG   *msg;
+
+    while( INFINITE_LOOP )
+    {	
+
+	  // Suspend the task on empty queue
+	  event = rvf_wait( RVF_TASK_MBOX_0_EVT_MASK, 0 );
+	  msg   = ( T_PROFILER_MSG* ) rvf_read_mbox( RVF_TASK_MBOX_0 );
+      
+      // Check the msg ID code 
+      switch( msg->msg_id )
+	   {
+
+       #if (TI_PROFILER == 1)
+	     case TI_PROFILER_OUTPUT_BUFFER : 
+	     // Cut the buffer in small element to be sent to 
+		 // PC by the RVT.
+		 {
+		   message_length = TRACE_MESSAGE_SIZE;
+		   pos_pr_buffer  = 0;
+
+		   // loop until end of buffer
+		   while( pos_pr_buffer < pr_buffer_length )
+		   {
+              // Update message length for next loop turn
+			  if ( pos_pr_buffer <= ( pr_buffer_length - TRACE_MESSAGE_SIZE ) )
+			  {
+			    message_length = TRACE_MESSAGE_SIZE;
+			  }
+			  else
+			  {
+				message_length = pr_buffer_length - pos_pr_buffer;
+			  }
+
+              if( rvt_send_trace_cpy( ( T_RVT_BUFFER ) &pr_buffer[ pos_pr_buffer ], 
+                                      prof_trace_id,
+                                      message_length * 4,   // Length in bytes  
+                                      RVT_BINARY_FORMAT ) == RVT_OK )
+              {		     
+				// Update pr_buffer pointer
+                pos_pr_buffer += message_length;  
+                 
+			  } // End if 
+
+		   } // End while
+
+           // Restart the profiling at vitam aeternam unless stop command received.
+		   if( profiler_state == PROFILER_FREEZED )
+		   {
+		     profiler_state = PROFILER_TO_BE_UNFREEZED;
+		   } // End if 
+
+		   break;
+		 } // TI_PROFILER_OUTPUT_BUFFER
+
+		 case TI_PROFILER_START_PROFILING :
+		 { 
+		   #if (L1_TRACER == 1)
+		     SendTraces("TI_PROF: msg TI_PROFILER_START\n\r");
+		   #endif
+
+ 		   ti_profiler_event_state     = (T_PROFILER_EVENTS) (msg->event_number);
+ 
+ 		   if( ti_profiler_event_state == NO_SLEEP_EVENT )
+ 		   {
+ 			 ti_profiler_nb_sleep_counter_ref = msg->arg1;	// nb_tdma 
+ 		   } // End if
+
+           // Source of Activation
+ 		   ti_profiler_active = ACTIVE_BY_HOST;
+
+           // change state of profiler
+           profiler_state = PROFILER_TO_BE_RAN; 
+
+		   break;
+		 } // TI_PROFILER_START_PROFILING
+
+		 case TI_PROFILER_END_PROFILING :
+		 {
+		   #if (L1_TRACER == 1)
+		     SendTraces("TI_PROF: msg TI_PROFILER_STOP\n\r");
+		   #endif
+
+           profiler_state = PROFILER_TO_BE_STOPPED; 
+		   break;
+		 } // TI_PROFILER_END_PROFILING
+
+	   #endif
+
+       #if (TI_NUC_MONITOR == 1)
+
+		 case TI_NUC_MONITOR_START :
+		 {
+		   SYS_UWORD8   i = 0;
+		   SYS_UWORD8   j = 0;
+		   #if (L1_TRACER == 1)
+		     SendTraces("TI_PROF: msg TI_NUC_MONITOR_START\n\r");
+		   #endif
+
+		   if( ti_nuc_monitor_state == NUC_MONITOR_STOPPED )
+		   {
+
+             // Output the task and queues create info.
+			 // buffer format is following : 
+			 //   C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
+			 //   < Thread ID0 > 			   | (1 byte)
+             //   < Thread name >              | (8 bytes)
+             //   < Thread ID1 >			   | (1 byte)
+			 //   < Thread name >              | (8 bytes)
+			 //    ..............
+			 //   C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
+			 //   < Queue ID0 > 			   | (1 byte)
+             //   < Queue name >               | (8 bytes)
+             //   < Queue ID1 >			       | (1 byte)
+			 //   < Queue name >               | (8 bytes)
+			 //    ..............
+			 //   C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
+			       
+			 // Allocate one buffer.
+
+	         while ((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                                 NUC_MONITOR_BUFFER_SIZE, 
+			                         (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+			          != RVT_OK);
+
+
+             // Output the ID (thread and Queue array)
+
+			 ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
+
+             // Output the Thread IDs and corresponding Thread name.
+
+             for( i = 0 ; i < ti_nuc_monitor_thread_pos ; i++ )
+			 {
+			   // distinghuish Task and HISR
+			   if( (( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_id == TC_HISR_ID)
+			   {
+			     ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = (0x80 | i); // ID
+			   }
+			   else
+			   {
+			     ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = i;  // ID
+			   } // End if
+
+			   if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			   {
+			     ti_nuc_monitor_check_ID_buffer();
+			   } // End if
+
+               // Write task priority
+			   ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =  
+				   (SYS_UWORD8) ((( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_priority);
+
+			   if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			   {
+			     ti_nuc_monitor_check_ID_buffer();
+			   } // End if
+  
+               // Write name in the Log buffer.
+			   for( j = 0 ; j < NU_MAX_NAME ; j++ )
+			   {
+			     ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = 
+			       (SYS_UWORD8) ((( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_name[ j ]);	// Thread_name
+			     if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			     {
+			       ti_nuc_monitor_check_ID_buffer();
+			     } // End if
+			   } // End for
+
+			 } // End for 
+
+             // Output the ID (thread and Queue array)
+			 if( ti_nuc_monitor_queue_pos != 0 )
+			 {
+			   ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
+
+               // Output the Queue IDs and corresponding Queue name.
+
+		       if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			   {
+			     ti_nuc_monitor_check_ID_buffer();
+			   } // End if
+
+               for( i = 0 ; i < ti_nuc_monitor_queue_pos ; i++ )
+			   {
+			     ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = i;  // ID
+
+			     if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			     {
+			       ti_nuc_monitor_check_ID_buffer();
+			     } // End if
+
+			     // Write name in the Log buffer.	   
+			     for( j = 0 ; j < NU_MAX_NAME ; j++ )
+			     {
+			       ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = 
+			         (SYS_UWORD8) ((( QU_QCB * ) ( ti_nuc_monitor_queue_id[ i ] ))->qu_name[ j ]);	// Thread_name
+			       if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
+			       {
+			         ti_nuc_monitor_check_ID_buffer();
+			       } // End if
+			     } // End for
+
+			   } // End for 
+			 } // End if
+
+			 // Insert end op code (same as begin op code)
+
+			 ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
+              
+			 // flush the last buffer.
+
+		     // Send a message to the Riviera Tracer to Output the current buffer.
+             if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) ti_nuc_monitor_current_buffer, 
+                                        prof_trace_id,
+                                        ti_nuc_monitor_current_position,   // Length in bytes  
+                                        RVT_BINARY_FORMAT ) != RVT_OK )
+             {
+			   // Code to insert break point.
+               ti_nuc_monitor_state = NUC_MONITOR_STOPPED;		     
+             } // End if
+
+             // Configuration buffer has been logged out.
+
+	         /*
+	          ** Allocate a buffer for Nucleus profiling
+	          */
+
+	         while ((ti_nuc_monitor_mem_alloc (prof_trace_id, 
+	                                 NUC_MONITOR_BUFFER_SIZE, 
+			                        (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer)) 
+			        != RVT_OK);
+
+             // reset the current pointer.
+		     ti_nuc_monitor_current_position = 0;
+
+			 // Set the new Monitoring state.
+             ti_nuc_monitor_state            = NUC_MONITOR_TO_BE_STARTED;
+		   } // End if
+
+		  break;
+
+		 } // TI_NUC_MONITOR_START
+
+		 case TI_NUC_MONITOR_OUTPUT_BUFFER :
+		 {
+		   // The buffer is output only if it is full.
+
+		   // Send a message to the Riviera Tracer to Output the current buffer.
+           if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) msg->p_buffer, 
+                                      prof_trace_id,
+                                      msg->buffer_size,   // Length in bytes  
+                                      RVT_BINARY_FORMAT ) != RVT_OK )
+           {
+             // increment lost messages variable
+			 ti_nuc_monitor_lost_messages++; 	     
+           } // End if
+
+		   break;
+
+		 } // TI_NUC_MONITOR_OUTPUT_BUFFER
+
+		 case TI_NUC_MONITOR_STOP :
+		 {
+		   #if (L1_TRACER == 1)
+		     SendTraces("TI_PROF: msg TI_NUC_MONITOR_STOP\n\r");
+		   #endif
+
+		   ti_nuc_monitor_state = NUC_MONITOR_TO_BE_STOP; 
+
+		   break;
+
+		 } // TI_NUC_MONITOR_STOP
+
+       #endif
+
+         default :
+		 {
+		   #if (L1_TRACER == 1)		   
+		     SendTraces("TI_PROF: msg default\n\r");
+		   #endif
+
+		   break;
+		 } // default
+
+	   } // End switch
+
+      
+      // Free the msg alloc 
+	  rvf_free_buf( msg );
+
+	} // End while ( INFINITE_LOOP )
+
+  } // ti_profiler_task
+
+
+  /*-------------------------------------------------------*/
+  /* ti_profiler_trace_rx_callback()                       */
+  /*-------------------------------------------------------*/
+  /*                                                       */
+  /* Description:                                          */
+  /* ------------ 										   */
+  /* callback function called when the trace               */
+  /* module receives a msg for the profiler                */
+  /*  or the nucleus monitor.                              */
+  /*                                                       */
+  /*-------------------------------------------------------*/
+
+  void ti_profiler_trace_rx_callback(T_RVT_BUFFER trace_msg, UINT16 trace_msg_size)
+  {	 
+    T_PROFILER_MSG * msg;
+
+    // send a message to the ti profiler received from Rvt
+	if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
+	{
+	/*
+	  if( trace_msg[0] == 1 )
+	    msg->msg_id = TI_PROFILER_START_PROFILING;
+	  else if ( trace_msg[0] == 0 )
+	    msg->msg_id = TI_PROFILER_END_PROFILING;
+	  else if ( trace_msg[0] == 2 )
+	    msg->msg_id = TI_NUC_MONITOR_START;
+	  else if ( trace_msg[0] == 3 )
+	    msg->msg_id = TI_NUC_MONITOR_STOP;
+	 */
+ 	  msg->msg_id        = ((T_PROFILER_MSG_UART*) trace_msg)->msg_id;
+ 	  msg->event_number  = ((T_PROFILER_MSG_UART*) trace_msg)->event_number;
+ 	  msg->arg1          = ((T_PROFILER_MSG_UART*) trace_msg)->arg1;
+
+	  rvf_send_msg( prof_addr_id, msg );
+	}
+
+  } // ti_profiler_trace_rx_callback
+
+#endif // NUC_MONITOR || PROFILER
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/ti_profiler/ti_profiler.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,151 @@
+/************************************************************************************
+* ti_profiler.h :  contains ti profiling and Nucleus Monitoring module header                              *
+*																					*	
+*																					*
+*	Author: Philippe Martinez														*
+*																					*
+*	version: 1.1																	*
+*																					*
+*	Date: 07/16/2001																*
+*   (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved		*		
+************************************************************************************/
+
+
+#ifndef _TI_PROFILER_H_
+  #define _TI_PROFILER_H_
+
+  #define INFINITE_LOOP               ( 1 )
+  #define L1_TRACER		      ( 1 )  // Add debug traces into Layer 1 stream
+
+  // Log buffer size in 32 bit words  (profiler only)
+  #define PR_BUFFER_SIZE              ( 20000 )
+  #define PR_BUFFER_THRESHOLD         ( PR_BUFFER_SIZE - 95 )
+
+
+  // buffer OP code	(profiler only)
+  #define C_OP_CODE_START_PR          ( 0xfffffff0 )
+  #define C_OP_CODE_STOP_PR           ( 0xfffffffe )
+
+  #define C_OP_CODE_BEGIN_BUFFER      ( 0xfffffff0 )
+  #define C_OP_CODE_TDMA_BEGIN        ( 0xfffffff2 )
+  #define C_OP_CODE_TDMA_END          ( 0xfffffff4 )
+  #define C_OP_CODE_END_BUFFER        ( 0xfffffff8 )
+
+  // Rx message ID code	(profiler only)
+  #define TI_PROFILER_END_PROFILING   ( 0x0000 )
+  #define TI_PROFILER_START_PROFILING ( 0x0001 )
+
+  #define TI_PROFILER_OUTPUT_BUFFER   ( 0xffff )
+
+
+  // Timer used	 (profiler only)
+  #define PR_TIMER_NUM                ( 1 ) 
+
+  #define PR_TIMER_RESET_VALUE        ( 21 )  // load value 50 us
+
+  // define the length of cutted element buffer in order to
+  // Generate rvt messages. (profiler only)
+  #define TRACE_MESSAGE_SIZE	      ( 50 )  // x4 = n bytes
+
+  // Nucleus monitoring buffer size (bytes) for rvt (Nucleus Monitoring only)
+  #define NUC_MONITOR_BUFFER_SIZE     ( 240 )
+
+  // Nucleus Monitoring Buffer (Nucleus Monitoring only)
+  #define C_OP_CODE_NUC_MON_THREAD_IDS ( 0xff )
+  #define C_OP_CODE_FN_LOG   		   ( 0x00 )
+  #define C_OP_CODE_LISR_FLAG          ( 0xC0 )
+  #define C_OP_CODE_THREAD_FLAG        ( 0x80 )
+  #define C_OP_CODE_QUEUE_FLAG         ( 0x40 )
+
+  // Rx message ID code (Nucleus Monitoring only)
+  #define TI_NUC_MONITOR_OUTPUT_BUFFER ( 0xfff0 )
+  #define TI_NUC_MONITOR_START         ( 0x0002 )
+  #define TI_NUC_MONITOR_STOP          ( 0x0003 )
+
+  // ID Thread NULL (Nucleus Monitoring only)
+  #define NUC_MONITOR_ID_IDLE         ( 0xff )
+
+  // Nuleus monitoring : Number max of component of same type
+  // that can be monitored	(Nucleus Monitoring only)
+  #define NUC_MONITOR_MAX_ID          ( 64 )
+
+  // Define LISR doubled buffer Size (Nucleus Monitoring only)
+  #define C_NUC_LISR_BUF_PG_NB        ( 2 )
+  #define C_NUC_LISR_LOG_SZ           ( 5 )  // bytes
+
+  // Must be strickly < NUC_MONITOR_BUFFER_SIZE	(Nucleus Monitoring only)
+  #define C_NUC_MAX_LISR              ( 20 *  C_NUC_LISR_LOG_SZ )
+
+  // Define LISR doubled buffer Size (Nucleus Monitoring only)
+  #define C_NUC_THREAD_BUF_PG_NB        ( 2 )
+  #define C_NUC_THREAD_LOG_SZ           ( 3 )  // bytes
+
+  // Must be strickly < NUC_MONITOR_BUFFER_SIZE (Nucleus Monitoring only)
+  #define C_NUC_MAX_THREAD              ( 30 *  C_NUC_THREAD_LOG_SZ )
+
+  // Differents state of profiling
+  typedef enum 
+    {               
+      PROFILER_STOPPED,
+      PROFILER_RUNNING,
+      PROFILER_FREEZED,
+      PROFILER_TO_BE_RAN,
+      PROFILER_TO_BE_UNFREEZED,
+      PROFILER_TO_BE_STOPPED
+    } T_PROFILER_STATE;
+
+  // Differents state of nucleus monitoring	(Nucleus Monitoring only)
+  typedef enum 
+    {               
+      NUC_MONITOR_STOPPED,
+      NUC_MONITOR_RUNNING,
+	  NUC_MONITOR_TO_BE_RUN,
+	  NUC_MONITOR_TO_BE_STARTED,
+	  NUC_MONITOR_TO_BE_STOP,
+	  NUC_MONITOR_WAITING
+	} T_NUC_MONITOR_STATE;
+
+  typedef enum 
+    {               
+      LOGGING,
+      FLUSH
+    } T_PROFILER_BUFFER_STATE;
+
+  typedef enum 
+    {               
+      NOT_ACTIVE,
+      ACTIVE_BY_TI,
+      ACTIVE_BY_EXT,
+      ACTIVE_BY_HOST
+    } T_PROFILER_HANDLER;
+
+  typedef enum 
+    {               
+      NO_EVENT,
+      NO_SLEEP_EVENT,
+      EVENT2,
+      EVENT3,
+	  EVENT4
+    } T_PROFILER_EVENTS;
+
+  typedef struct 
+    {
+      SYS_UWORD16  msg_id;
+      SYS_UWORD8   event_number;
+	  SYS_UWORD8   arg1;
+      SYS_UWORD8   *p_buffer;
+      SYS_UWORD8   buffer_size;
+    } T_PROFILER_MSG_UART;
+
+  typedef struct 
+    {
+      T_RV_HDR     header;
+      SYS_UWORD16  msg_id;
+      SYS_UWORD8   event_number;
+	  SYS_UWORD8   arg1;
+      SYS_UWORD8   *p_buffer;
+      SYS_UWORD8   buffer_size;
+    } T_PROFILER_MSG;
+
+#endif
+                 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/ti_profiler/ti_profiler_env.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ *
+ * ti_profiler_env.c
+ *
+ * This module interfaces the environment and contains all start/init/stop...
+ * functions of the TI profiler module.
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/30/2001) - Created
+ *
+ * Date             : 7/30/2001
+ *
+ * Author           : Philippe Martinez, 
+ *
+ ******************************************************************************/
+
+#include "config/debug.cfg"
+
+#if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
+
+#include <string.h>
+
+#include "nucleus.h"
+
+#include "rvf/rvf_api.h"
+#include "rv/rv_general.h"
+#include "rvm/rvm_gen.h"
+#include "rvm/rvm_priorities.h"
+#include "rvm/rvm_use_id_list.h"
+
+#include "rvt/ti_profiler/ti_profiler_env.h"
+
+/*-------------------------------------------------------*/
+/* external variables & prototypes                       */
+/*-------------------------------------------------------*/
+
+  extern T_RVF_MB_ID   prof_mb_id;
+  extern T_RVF_ADDR_ID prof_addr_id;
+
+  extern T_RV_RET ti_prf_core( void );
+  extern void     ti_prf_init( void );
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   ti_prf_get_info										    */
+/*                                                                              */
+/*    Purpose:         This function is used to notify the Bluetooth            */
+/*                     Environment of the TI profiler's  requirements.          */
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+T_RVM_RETURN
+ti_prf_get_info (T_RVM_INFO_SWE *p_info_swe)
+{
+	if (!p_info_swe)
+		return RVM_INVALID_PARAMETER;
+
+   /* SWE info */
+   p_info_swe->swe_type = RVM_SWE_TYPE_4;
+   p_info_swe->type_info.type4.swe_use_id = TI_PRF_USE_ID;
+
+   memcpy( p_info_swe->type_info.type4.swe_name, "TI_PRF", sizeof("TI_PRF") );
+
+   p_info_swe->type_info.type4.stack_size = TI_PROFILER_TASK_STACK_SIZE;
+   p_info_swe->type_info.type4.priority   = TI_PROFILER_TASK_PRIORITY;
+
+
+   /* Set the return path */
+   p_info_swe->type_info.type4.return_path.callback_func	= NULL;
+   p_info_swe->type_info.type4.return_path.addr_id	      = 0;
+
+
+   /* memory bank info */
+   p_info_swe->type_info.type4.nb_mem_bank = 1;
+
+   memcpy ((UINT8 *) 	p_info_swe->type_info.type4.mem_bank[0].bank_name, "TI_PRF", RVM_NAME_MAX_LEN);
+   p_info_swe->type_info.type4.mem_bank[0].initial_params.size          = TI_PROFILER_MB_SIZE;
+   p_info_swe->type_info.type4.mem_bank[0].initial_params.watermark     = TI_PROFILER_MB_WATERMARK;
+
+   /* linked SWE info */
+   /* this SWE does not require any SWE to run */
+   p_info_swe->type_info.type4.nb_linked_swe = 0;
+
+   /* generic functions */
+   p_info_swe->type_info.type4.set_info = ti_prf_set_info;
+   p_info_swe->type_info.type4.init     = ti_prf_env_init;
+   p_info_swe->type_info.type4.core     = ti_prf_core;
+   p_info_swe->type_info.type4.stop     = ti_prf_env_stop;
+   p_info_swe->type_info.type4.kill     = ti_prf_kill;
+
+	return RVM_OK;
+}
+
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   ti_prf_set_info							    			*/
+/*                                                                              */
+/*    Purpose:         This function is used to notify the TI profiler          */
+/*                     about mb ids and address id	.							*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        addr_id: Address id.													*/
+/*        mb_id[]: array of memory bank ids.									*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+ti_prf_set_info( T_RVF_ADDR_ID  addr_id,
+				      T_RV_RETURN_PATH		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))
+{
+	/*
+	** Save the parameters given by environment
+	*/
+
+	/* Addr Id */
+	prof_addr_id = addr_id;
+
+	/* Bank Id */
+	prof_mb_id = bk_id [0];
+
+	return RVM_OK;
+}
+
+
+
+
+/********************************************************************************/
+/*                                                                              */
+/*    Function Name:   ti_prf_env_init											*/
+/*                                                                              */
+/*    Purpose:         This is the initialization function.						*/
+/*					   It is called by the RVM									*/
+/*                                                                              */
+/*    Input Parameters:                                                         */
+/*        None.																	*/
+/*                                                                              */
+/*    Output Parameters:                                                        */
+/*        None.																	*/
+/*                                                                              */
+/*    Global Parameters:                                                        */
+/*        None.                                                                 */
+/*                                                                              */
+/*    Note:                                                                     */
+/*        None.                                                                 */
+/*                                                                              */
+/********************************************************************************/
+
+T_RVM_RETURN
+ti_prf_env_init (void)
+{
+
+  ti_prf_init();
+  return RVM_OK;
+}
+
+
+
+/*
+** Functions stop and kill are defined for compilation only
+*/
+T_RVM_RETURN
+ti_prf_env_stop (void)
+{
+	return RVM_OK;
+}
+
+
+T_RVM_RETURN
+ti_prf_kill (void)
+{
+	return RVM_OK;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/rvt/ti_profiler/ti_profiler_env.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ *
+ * ti_profiler_env.c
+ *
+ * This module interfaces the environment and contains all start/init/stop...
+ * functions of the TI profiler.
+ *
+ * (C) Texas Instruments, all rights reserved
+ *
+ * Version number	: 0.1
+ *
+ * History			: 0.1 (7/30/2001) - Created
+ *
+ * Date             : 7/30/2001
+ *
+ * Author           : Philippe Martinez, 
+ *
+ ******************************************************************************/
+
+#ifndef __TI_PROFILER_ENV_H__
+#define __TI_PROFILER_ENV_H__
+
+#include "rvm/rvm_gen.h"
+
+#include "ti_prf_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+
+#define TI_PROFILER_TASK_STACK_SIZE TI_PRF_STACK_SIZE
+
+#define TI_PROFILER_MB_SIZE         TI_PRF_MB1_SIZE
+#define TI_PROFILER_MB_WATERMARK    TI_PROFILER_MB_SIZE
+
+#define TI_PROFILER_MAILBOX         RVF_TASK_MBOX_0
+#define TI_PROFILER_TASK_PRIORITY   255
+
+T_RVM_RETURN
+ti_prf_get_info (T_RVM_INFO_SWE *p_info_swe);
+
+
+T_RVM_RETURN
+ti_prf_set_info(T_RVF_ADDR_ID addr_id,
+				T_RV_RETURN_PATH	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
+ti_prf_env_init (void);
+
+T_RVM_RETURN
+ti_prf_env_stop (void);
+
+T_RVM_RETURN
+ti_prf_kill (void);
+
+
+#endif /* __TI_PROFILER_ENV_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/support/exception.c	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,140 @@
+/*
+ ******************************
+ * 
+ *
+ * Initialial version: Laurent Deniau, Laurent.Deniau@cern.ch
+ *
+ * For more information, please see the paper:
+ * http://cern.ch/Laurent.Deniau/html/oopc/exception.html
+ * 
+ * -----------------------------------------------------------
+ *
+ * Strong rework and adaption to riviera by Christophe Favergeon
+ *
+ ******************************
+ */
+
+// Authorization to use this source code communicated to Christophe Favergeon
+// by email
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "support/exception.h"
+
+#ifndef _WINDOWS
+  #include "config/swconfig.cfg"
+#endif
+
+
+/* global stack of exception context */
+struct _exceptionContext_ *const _returnExceptionContext_[MAX_RVF_TASKS]=
+#if (!GSMLITE)
+  {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+#else
+  {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+#endif
+
+struct _exceptionContext_ *_currentExceptionContext_ [MAX_RVF_TASKS]= 
+#if (!GSMLITE)
+  {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+#else
+  {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+#endif
+
+/* delete protected pointers and throw exception */
+void
+_exceptionThrow_(int exception)
+{
+  struct _protectedPtr_ *p;
+  struct _protectedPtr_ *oldp;
+
+  /* no exception context saved, exit program */
+  if (!_currentExceptionContext_[rvf_get_taskid()]) exit(exception); 
+
+  /* free pointers stored on the current exception context pointers stack */
+  p=_currentExceptionContext_[rvf_get_taskid()]->stack;
+
+  while(p)
+  {
+	  oldp=p->previous;
+	  p->func(p->ptr);
+	  rvf_free_buf(p);
+	  p=oldp;
+  }
+
+  _currentExceptionContext_[rvf_get_taskid()]->stack=NULL;
+
+  /* jump to previous exception context */
+  rvf_restore_context_buffer_(_currentExceptionContext_[rvf_get_taskid()]->context, exception); 
+} 
+
+
+// Protect a pointer when there is a try/ctahc block active
+void rvf_protect_pointer(T_RVF_MB_ID mb_id,void *p,T_RVF_RELEASE_PROTECTED_POINTER func)
+{
+
+	struct _protectedPtr_ *ptr;
+	struct _exceptionContext_ *context;
+	T_RVF_MB_STATUS err;
+
+
+
+	if (_currentExceptionContext_[rvf_get_taskid()])
+	{
+
+	if (p==NULL)
+		throw(E_not_enough_memory);
+
+	context=_currentExceptionContext_[rvf_get_taskid()];
+	err=rvf_get_buf(mb_id,sizeof(struct _protectedPtr_),(void*)&ptr);
+	
+
+	if (err==RVF_GREEN)
+	{
+		ptr->next=NULL;
+	    ptr->previous=NULL;
+	    ptr->ptr=p;
+	    ptr->func=func;
+
+         if (context->stack==NULL)
+		 {
+			  context->stack=ptr;
+		 }
+		 else
+		 {
+			  ptr->previous=context->stack;
+			  context->stack->next=ptr;
+			  context->stack=ptr;
+		 }
+	 }
+	 else
+	 {
+		 if (p!=NULL)
+		   rvf_free_buf(p);
+		 throw(E_not_enough_memory);
+	 }
+	}
+}
+
+void rvf_forget_protected_ptr()
+{
+   struct _protectedPtr_ *p;
+   struct _protectedPtr_ *oldp;
+
+   p=_currentExceptionContext_[rvf_get_taskid()]->stack;
+
+   while(p)
+   {
+	   oldp=p->previous;
+	   rvf_free_buf(p);
+	   p=oldp;
+   }
+
+   _currentExceptionContext_[rvf_get_taskid()]->stack=NULL;
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/support/exception.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,123 @@
+/*
+ ******************************
+ * 
+ *
+ * Initialial version: Laurent Deniau, Laurent.Deniau@cern.ch
+ *
+ * For more information, please see the paper:
+ * http://cern.ch/Laurent.Deniau/html/oopc/exception.html
+ * 
+ * -----------------------------------------------------------
+ *
+ * Strong rework and adaption to riviera by Christophe Favergeon
+ *
+ ******************************
+ */
+
+#ifndef RVF_EXCEPTION_H
+#define RVF_EXCEPTION_H
+
+#include "rvf/rvf_api.h"
+#include "rvf/rvf_target.h"
+
+#include <string.h>
+
+
+
+//#ifndef __STDC__
+//#  error "exception.h needs ISO C compiler to work properly"
+//#endif
+
+#include <setjmp.h>
+
+typedef enum K_RVF_EXCEPTIONS { E_invalid=1, E_not_enough_memory,E_unknown } T_RVF_EXCEPTIONS; 
+
+typedef void (*T_RVF_RELEASE_PROTECTED_POINTER)(void *p);
+
+/*
+  choose context savings
+*/
+
+#define rvf_save_context_buffer_(context)         setjmp(context)
+#define rvf_restore_context_buffer_(context, val) longjmp(context, val)
+
+/*
+  some hidden types used to handle exceptions
+*/
+
+/* type of stack of protected pointer */
+struct _protectedPtr_ {
+  struct _protectedPtr_ *next;
+  struct _protectedPtr_ *previous;
+  void *ptr;
+  T_RVF_RELEASE_PROTECTED_POINTER func;
+};
+
+/* type of stack of exception */
+struct _exceptionContext_ {
+  struct _exceptionContext_ *next;
+  struct _protectedPtr_ *stack;
+  jmp_buf context;
+};
+
+extern struct _exceptionContext_ *const _returnExceptionContext_[MAX_RVF_TASKS];
+extern struct _exceptionContext_ *_currentExceptionContext_[MAX_RVF_TASKS];
+
+/* exception keywords */
+#define try								 \
+  do {									 \
+	struct _exceptionContext_ _localExceptionContext_ ;\
+	memset(&_localExceptionContext_,0,sizeof(struct _exceptionContext_));\
+    _localExceptionContext_.next=_currentExceptionContext_[rvf_get_taskid()];\
+    _currentExceptionContext_[rvf_get_taskid()] = &_localExceptionContext_;		 \
+    do {								 \
+      int const exception =						 \
+              rvf_save_context_buffer_(_currentExceptionContext_[rvf_get_taskid()]->context); \
+      if (!exception) {
+
+#define catch(except)							\
+      } else if ((int)(except) == exception) {				\
+        _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;
+
+#define catch_any							\
+      } else {								\
+        _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;
+
+#define endtry								\
+      }									\
+    } while(0);								\
+    if (_currentExceptionContext_[rvf_get_taskid()] == &_localExceptionContext_) {	\
+      rvf_forget_protected_ptr();\
+      _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;	\
+    }									\
+  } while(0)
+
+#define rethrow throw(exception)
+#define break_try break
+
+/*
+#define return_try(...)						\
+  do {								\
+    _currentExceptionContext_ = _returnExceptionContext_;	\
+    return __VA_ARGS__;						\
+  } while(0)
+*/
+
+#define throw(except) _exceptionThrow_((int)(except))
+
+
+/*
+  extern declarations
+*/
+
+extern void _exceptionThrow_(int except);
+
+extern void rvf_forget_protected_ptr();
+extern void rvf_protect_pointer(T_RVF_MB_ID mb_id,void *p,T_RVF_RELEASE_PROTECTED_POINTER func);
+
+#define RVF_PROTECT(bank,p) rvf_protect_pointer(bank,p,(T_RVF_RELEASE_PROTECTED_POINTER)rvf_free_buf)
+
+#define THROW_IF_ERROR(err) if (err!=0) throw(E_unknown)
+#define THROW_IF_NULL(p) if (p==NULL) throw(E_not_enough_memory)
+#define THROW_IF_YELLOW(b,p) if ((p==NULL) || (rvf_get_mb_status(b)==RVF_YELLOW)) throw(E_not_enough_memory)
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rtest/rtest_api.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,155 @@
+/**
+ * @file	rtest_api.h
+ *
+ * API Definition for the RTEST SWE.
+ *
+ * Please not the distinction that is made from where the API
+ * functions can be called:
+ * - from the test task only
+ * - from RTEST only
+ * - from both
+ *
+ * @author	Vincent Oberle (v-oberle@ti.com)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *	11/21/2001	Create
+ *	03/04/2002	Changed name to RTEST
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __RTEST_API_H_
+#define __RTEST_API_H_
+
+
+#include "rvm/rvm_gen.h"		/* Generic RVM types and functions. */
+
+#include "tests/rv/rv_test_certif.h"
+#include "tests/rv/rv_test_demo.h"
+#include "tests/rv/rv_test_regr.h"
+#include "tests/rv/rv_test_misc.h"
+
+
+/**
+ * Type for the test function pointers.
+ */
+typedef void (*T_RTEST_FUNC) (void);
+
+
+/** FROM TEST TASK ONLY **/
+
+/**
+ * Starts a test.
+ *
+ * This function is called by the test task (ie the task to which
+ * the main gives the hand). It BLOCKS until a RTEST_TEST_RESULT message
+ * is received.
+ *
+ * Usage:
+ * To be called from the test task only, not from RTEST!
+ *
+ * @param	test_fct	Test function.
+ * @return	Result of the test.
+ */
+T_RV_TEST_RET rtest_start_test(T_RTEST_FUNC test_fct);
+
+
+/** FROM TEST TASK AND RNET **/
+
+/**
+ * Sets up the RTEST SWE to forward the messages that are not 
+ * RTEST messages to another handle_message function.
+ *
+ * Usage:
+ * Can be called from outside and from inside RTEST.
+ *
+ * @param	hm	handle_message function to forward the messages to.
+ */
+void rtest_set_swe_handle_message (T_RVM_RETURN (* hm) (T_RV_HDR*));
+
+/**
+ * Sets up the RTEST SWE to forward the timers to another 
+ * handle_timer function.
+ *
+ * Usage:
+ * Can be called from outside and from inside RTEST.
+ *
+ * @param	ht	handle_timer function to forward the timers to.
+ */
+void rtest_set_swe_handle_timer (T_RVM_RETURN (* ht) (T_RV_HDR*));
+
+
+/**
+ * Trace information on the verdict (result) of a test.
+ *
+ * Usage:
+ * Can be called from outside and from inside RTEST.
+ *
+ * @param	test_verdict	Result of the test.
+ */
+void rtest_trace_test_verdict (T_RV_TEST_RET test_verdict);
+
+
+/** FROM RNET ONLY **/
+
+/**
+ * Sends the test result back to the test task.
+ *
+ * This function is to be used by a test when finished. It will
+ * unblock the test_start_xxx functions.
+ *
+ * Usage:
+ * To be called from RTEST only!
+ *
+ * @param	result	The result of the test.
+ * @return	RV_MEMORY_ERR or RV_INTERNAL_ERR if there was a problem
+ *			to send the message, RV_OK otherwise.
+ */
+T_RV_RET rtest_send_result (T_RV_TEST_RET result);
+
+
+/**
+ * Returns the address ID of the RTEST SWE.
+ *
+ * Usage:
+ * To be called from RTEST only!
+ *
+ * @return	Address ID of RTEST.
+ */
+T_RVF_ADDR_ID rtest_get_addr_id (void);
+
+/**
+ * Returns the MB ID of the RTEST SWE.
+ *
+ * Usage:
+ * To be called from RTEST only!
+ *
+ * @return	Memory bank ID of RTEST
+ */
+T_RVF_MB_ID rtest_get_mb_id (void);
+
+
+/**
+ * Blocks RTEST waiting for a message.
+ *
+ * If the parameter msg_id is not null, the function blocks until receiving
+ * a message with the same ID, DISCARDING all other messages.
+ * If the parameter msg_id is null, the function returns the first message received.
+ *
+ * Usage:
+ * To be called from RTEST only!
+ *
+ * @param	msg_id	Waited message ID, null for any message.
+ * @return	The received message.
+ */
+T_RV_HDR * rtest_wait_for_message (UINT32 msg_id);
+
+
+#endif /*__RTEST_API_H_*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rtest/rtest_env.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,67 @@
+/**
+ * @file	rtest_env.h
+ *
+ * Declarations of the Riviera Generic Functions 
+ * for the Test SW Entity of Riviera.
+ *
+ * @author	Vincent Oberle (v-oberle@ti.com)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ * 	Date       	Modification
+ *  ------------------------------------
+ *	11/21/2001	Create
+ *	03/04/2002	Changed name to RTEST
+ *
+ * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __RTEST_ENV_H_
+#define __RTEST_ENV_H_
+
+
+#include "rvm/rvm_gen.h"		/* Generic RVM types and functions. */
+//#include "rvf/rvf_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+#include "tests/rtest/rtest_pool_size.h"	/* Stack & Memory Bank sizes definitions */
+
+
+/**
+ * @name Mem bank
+ *
+ * Memory bank size and watermark.
+ */
+/*@{*/
+#define RTEST_MB_PRIM_SIZE				RTEST_MB1_SIZE
+#define RTEST_MB_PRIM_WATERMARK			(RTEST_MB_PRIM_SIZE - 1072)
+/*@}*/
+
+
+
+
+/**
+ * @name Generic functions
+ *
+ * Generic functions declarations needed for a type 4 SWE
+ * (Self-made SWE).
+ */
+/*@{*/
+T_RVM_RETURN rtest_get_info (T_RVM_INFO_SWE  *info_swe);
+
+T_RVM_RETURN rtest_set_info (T_RVF_ADDR_ID	addr_id,
+							T_RV_RETURN_PATH return_path[],
+							T_RVF_MB_ID		bk_id_table[],
+							T_RVM_CB_FUNC	call_back_error_ft);
+
+T_RVM_RETURN rtest_init (void);
+
+T_RVM_RETURN rtest_core (void);
+
+T_RVM_RETURN rtest_stop (void);
+T_RVM_RETURN rtest_kill (void);
+/*@}*/
+
+
+#endif /*__RTEST_ENV_H_*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rtest/rtest_msg_i.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,116 @@
+/**
+ * @file	rtest_msg_i.h
+ *
+ * Data structures:
+ * 1) Used to send messages to the RTEST SWE,
+ * 2) RTEST can receive.
+ *
+ * Only for internal use.
+ *
+ * @author	Vincent Oberle (v-oberle@ti.com)
+ * @version 0.1
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	11/21/2001	Vincent Oberle			Create
+ *	03/04/2002	Vincent Oberle			Changed name to RTEST
+ *	03/15/2002	Vincent Oberle			Put as a internal file, 
+ *										reduced nb of messages
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef __RTEST_MSG_I_H_
+#define __RTEST_MSG_I_H_
+
+
+#include "rv/rv_general.h"
+
+#include "tests/rtest/rtest_api.h"
+
+
+
+/**
+ * Macro used for tracing RTEST messages.
+ */
+#define RTEST_SEND_TRACE(string, trace_level) \
+	rvf_send_trace (string, (sizeof(string) - 1), NULL_PARAM, trace_level, RTEST_USE_ID)
+
+#define RTEST_SEND_TRACE_PARAM(string, param, trace_level) \
+	rvf_send_trace (string, (sizeof(string) - 1), param, trace_level, RTEST_USE_ID)
+
+
+
+/** 
+ * The message offset must differ for each SWE in order to have 
+ * unique msg_id in the system.
+ */
+#define RTEST_MESSAGE_OFFSET	 BUILD_MESSAGE_OFFSET(RTEST_USE_ID)
+
+
+
+/***************
+ * to RTEST SWE *
+ ***************/
+
+/**
+ * @name RTEST_START_TEST
+ *
+ * Message to indicate to the Test SWE to proceed
+ * to a test.
+ */
+/*@{*/
+/** Message ID. */
+#define RTEST_START_TEST (RTEST_MESSAGE_OFFSET | 0x001)
+
+/** Message structure. */
+typedef struct 
+{
+	/** Message header. */
+	T_RV_HDR			hdr;
+
+	/**
+	 * The pointer on the test function.
+	 */
+	T_RTEST_FUNC test_fct;
+
+} T_RTEST_START_TEST;
+/*@}*/
+
+
+
+/*****************
+ * from RTEST SWE *
+ *****************/
+
+/**
+ * @name RTEST_TEST_RESULT
+ *
+ * Message issued by the RTEST SWE to indicate the result of a test.
+ */
+/*@{*/
+/** Message ID. */
+#define RTEST_TEST_RESULT (RTEST_MESSAGE_OFFSET | 0x02)
+
+/** Message structure. */
+typedef struct 
+{
+	/** Message header. */
+	T_RV_HDR		hdr;
+
+	/** 
+	 * Test result value. Possible values are:
+	 * - TEST_PASSED:	No error occured
+	 * - TEST_FAILED:	An error occured but continue test suite
+	 * - TEST_IRRECOVERABLY_FAILED:	An error occured, stop test suite
+	 */
+	T_RV_TEST_RET	result;
+
+} T_RTEST_TEST_RESULT;
+/*@}*/
+
+#endif /* __RTEST_MSG_I_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rtest/rtest_pool_size.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,35 @@
+/**
+ * @file	rtest_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 __RTEST_POOL_SIZE_H_
+#define __RTEST_POOL_SIZE_H_
+
+
+/*
+ * Values used in rtest_env.h
+ */
+#define RTEST_STACK_SIZE (2048) //1024)
+#define RTEST_MB1_SIZE   (300000) // + 550000) //190000
+#define RTEST_POOL_SIZE  (RTEST_STACK_SIZE + RTEST_MB1_SIZE)
+
+
+#endif /*__RTEST_POOL_SIZE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,284 @@
+/**
+ * @file	rv_test.h
+ *
+ * Definitions used by all tests in Riviera.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	10/02/00	Cedric Baudelet			Create.
+ *	10/03/00	Cedric Baudelet			Add UPF4 value for TEST_TYPE parameter.
+ *	10/05/00	David Lamy-Charrier		Add BTCTRL value for TEST_LEVEL	parameter.
+ *	10/06/00	Cedric Baudelet			Add trace_test_verdict function's definition.
+ *	10/12/00	Cedric Baudelet			Add possibility to set testing
+ *										parameters dynamically using LCD and
+ *										keypad features.
+ *	11/16/00	Cedric Baudelet			Add TRACE_RVTEST traces macros.
+ *	11/21/00	Cristian Livadiotti		Add xxx_return_path parameters.
+ *	11/24/00	Cedric Baudelet			Update macros.
+ *	11/30/00	Cedric Baudelet			Change EOL from (0xFFFF) to (0xFF).
+ *	12/08/00	Cedric Baudelet			Add XXX_STATE definitions.
+ *	12/14/00	Cedric Baudelet			Update DISPLAY_TEST_VERDICT_SCREEN macro.
+ *	01/11/01	Cedric Baudelet			Add Flash File System (FFS) SWE.
+ *	01/12/01	Cedric Baudelet			Add T_RV_TEST_INIT definition.
+ *	01/16/01	Cedric Baudelet			Include 'rv_test_filter.h' file and
+ *										define redirections needed to set test
+ *										filter.
+ *	03/29/01	Cedric Baudelet			- Updated LCD and keypad macros.
+ *										- Replaced UPF4 by UPF.
+ *  07/12/01    Stephanie Gerthoux		Add Audio test parameters using LCD.
+ *  10/18/01	Christophe Favergeon	R2D added.
+ *  12/18/01	Vincent Oberle			Changed DISPLAY_START_SCREEN,
+ *		DISPLAY_TRANSITION_SCREEN and DISPLAY_TEST_VERDICT_SCREEN macros
+ *		into functions.
+ *		Replaced SET_STEP_PARAM macro with set_step_param function.
+ *  03/08/02	Vincent Oberle			Changed SCROLL_LCD and START_APPLI into functions.
+ *	03/08/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *	11/28/02	Vincent Oberle			Deleted XXX lines, generated rv_test_inc.h used instead.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_H_
+#define _RV_TEST_H_
+
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_gen.h"
+
+
+
+#ifdef DEVICE_A
+#define DISPLAY_DEVICE_STRING ("   Device A   ")
+#endif
+#ifdef DEVICE_B
+#define DISPLAY_DEVICE_STRING ("   Device B   ")
+#endif
+
+
+
+/**
+ * !!! IMPORTANT !!!
+ *
+ * END OF LIST -> This flag defines the end of the list containing tests to
+ * perform (NON REGRESSION only). Lists TEST_TABLE[] (defined in rv_test_cfg.h
+ * file) and test_list_all[] (defined in rv_test_regr.c file) MUST contain
+ * this flag as their last element.
+ */
+#define EOL (0xFF)
+
+
+/**
+ * RV TEST -> GENERAL PARAMETERS
+ *
+ * TEST_PARAM_NOT_DEFINED is default value for a parameter not defined yet.
+ */
+#define TEST_PARAM_NOT_DEFINED (0)
+
+
+/**
+ * RV TEST -> TEST INIT PARAMETER
+ *
+ * TEST_INIT parameter is set in rv_test_cfg.h file.
+ */
+typedef UINT8 T_RV_TEST_INIT;
+
+#define COMP (1)
+#define EXEC (2)
+
+
+/**
+ *
+ * RV TEST -> TEST TYPE PARAMETER
+ *
+ * TEST_TYPE parameter is set in rv_test_cfg.h file.
+ */
+typedef UINT8 T_RV_TEST_TYPE;
+
+#define REGR   (1)
+#define CERTIF (2)
+#define DEMO   (3)
+#define MISC   (4)
+#define UPF    (5)
+
+
+/**
+ * RV TEST -> TEST LEVEL PARAMETER
+ *
+ * TEST_LEVEL parameter is set in rv_test_cfg.h file.
+ * Values from rv_test_inc.h are used.
+ */
+typedef UINT8 T_RV_TEST_LEVEL;
+
+
+
+/**
+ * RV TEST -> TEST AUDIO PARAMETER
+ *
+ * TEST_AUDIO parameter is set in rv_test_cfg.h file.
+ */
+typedef UINT8 T_RV_TEST_AUDIO;
+
+#define LIST    (1)
+#define ONESHOT (2)
+
+
+/**
+ * RV TEST -> TEST AUDIO SERVICES PARAMETER
+ *
+ * TEST_AUDIO_ SERVICES parameter is set in rv_test_cfg.h file.
+ */
+typedef UINT8 T_RV_TEST_AUDIO_SERVICES;
+
+#define KBEEP   (1)
+#define TRITONE (2)
+#define MELO    (3)
+
+
+/**
+ * RV TEST -> TEST NUMBER PARAMETER
+ *
+ * TEST_NUMBER parameter is set in rv_test_cfg.h file.
+ */
+typedef UINT16 T_RV_TEST_NBR;
+
+
+/**
+ * RV TEST -> ERROR TYPE PARAMETER
+ */
+typedef enum {
+	NO_ERR				=  0, /* No error occurs										*/
+	NO_EVENT_RECV		= -2, /* Received no event										*/
+	BAD_EVENT_RECV		= -3, /* Received event not waited								*/
+	EVENT_PARAM_ERROR	= -4, /* Received event -> parameter not waited					*/
+	FUNCTION_ERROR		= -5, /* A function has been called and 0 ->  returned an error	*/
+	DATA_ERROR			= -9, /* An error has been found in the RX or TX data			*/
+	MEMORY_ERROR		= -10 /* A memory error occurs									*/
+} T_RV_TEST_ERR_TYPE;
+
+
+/**
+ * RV TEST -> RETURN PARAMETER
+ */
+typedef enum {
+	TEST_PASSED					=  0, /* No error occurs						*/
+	TEST_FAILED					= -2, /* An error occurs -> continu test suite	*/
+	TEST_IRRECOVERABLY_FAILED	= -3  /* An error occurs -> stop test suite		*/
+} T_RV_TEST_RET;
+
+
+/**
+ * BT DEVICES
+ *
+ * Notes: bd_addr are set in rv_test_cfg.h file.
+ */
+/*
+extern T_BD_ADDR bd_addr_loc; /* bd_addr of the LOCAL  device				
+extern T_BD_ADDR bd_addr_rem; /* bd_addr of the REMOTE device			
+*/
+
+/**
+ * RETURN PATHS
+ *
+ * Notes: Return paths are used to send messages to layers. These parameters are
+ * initialized at the start of each test.
+ */
+extern T_RV_RETURN_PATH rv_test_g_l2cap_return_path;
+extern T_RV_RETURN_PATH rv_test_g_sdp_return_path;
+extern T_RV_RETURN_PATH rv_test_g_rfc_return_path;
+
+
+
+
+
+
+
+
+/*************
+ * FUNCTIONS *
+ *************/
+
+/**
+ * This task is started from Application_Initialize and
+ * calls the test main function depending on test type.
+ */
+void rv_test (UINT32 p);
+
+
+/**
+ * Gets memory banks for the tests.
+ */
+T_RV_RET rv_test_mb_init (T_RVF_MB_ID mbIds[]);
+
+
+/**
+ * Trace verdict of the	performed test depending on test_verdict parameter's
+ */	
+void trace_test_verdict (T_RV_TEST_RET test_verdict);
+
+
+/**
+ * Start the specified SWE.
+ * Originaly the START_APPLI macros.
+ *
+ * @param	swe_use_id	SWE USE ID.
+ */
+void rv_test_start_swe (T_RVM_USE_ID swe_use_id);
+
+
+
+
+
+/**
+ * RV_TEST_TRACE_XXX(_PARAM) macros.
+ *
+ * Handle TRACE_RVTEST TRACE_TYPE traces, with or without parameter.
+ */
+/*@{*/
+#define RV_TEST_TRACE(string, level) { \
+	rvf_send_trace((string), sizeof(string) - 1, NULL_PARAM, level, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_PARAM(string, param, level) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, level, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_ERROR(string) { \
+	rvf_send_trace((string), sizeof(string) - 1, NULL_PARAM, RV_TRACE_LEVEL_ERROR, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_ERROR_PARAM(string, param) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, RV_TRACE_LEVEL_ERROR, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_WARNING(string) { \
+	rvf_send_trace((string), sizeof (string) - 1, NULL_PARAM, RV_TRACE_LEVEL_WARNING, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_WARNING_PARAM(string, param) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, RV_TRACE_LEVEL_WARNING, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_HIGH(string) { \
+	rvf_send_trace((string), sizeof(string) - 1, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_HIGH_PARAM(string, param) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, RV_TRACE_LEVEL_DEBUG_HIGH, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_MEDIUM(string) { \
+	rvf_send_trace((string), sizeof(string) - 1, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_MEDIUM, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_MEDIUM_PARAM(string, param) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, RV_TRACE_LEVEL_DEBUG_MEDIUM, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_LOW(string) { \
+	rvf_send_trace((string), sizeof(string) - 1, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, TRACE_RVTEST); }
+
+#define RV_TEST_TRACE_LOW_PARAM(string, param) { \
+	rvf_send_trace((string), sizeof(string) - 1, param, RV_TRACE_LEVEL_DEBUG_LOW, TRACE_RVTEST); }
+/*@}*/
+
+
+
+#endif /* _RV_TEST_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_certif.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,53 @@
+/**
+ * @file	rv_test_certif.h
+ *
+ * Definitions used for certification tests.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	09/29/00	Cedric Baudelet			Create.
+ *	03/15/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_CERTIF_H_
+#define _RV_TEST_CERTIF_H_
+
+#include "tests/rv/rv_test.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * DO NOT MODIFY THIS FILE!
+ * Add your test in the corresponding .c file only.
+ */
+
+
+/** Certification test number type */
+typedef T_RV_TEST_NBR T_RV_CERTIF_TEST_NBR;
+
+/** Certification test return value type */
+typedef T_RV_TEST_RET T_RV_CERTIF_RET;
+
+/** Certification test error type */
+typedef T_RV_TEST_ERR_TYPE T_RV_CERTIF_ERR_TYPE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RV_TEST_CERTIF_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_cfg.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,225 @@
+/**
+ * @file	rv_test_cfg.h
+ *
+ * This file allows to set parameters used to perform tests.
+ *
+ * Parameters to set are:
+ * - TEST_INIT (to set parameters statically or dynamically)
+ * - TEST_TYPE
+ * - TEST_LEVEL
+ * - TEST_NUMBER
+ * - TEST_CFG (non regression)
+ * - TEST_TABLE (non regression)
+ * - NB_OF_TEST_TO_PASS (non regression)
+ * - TEST_OCC (non regression)
+ *
+ * It is also possible to set bd_addr used for the tests by
+ * setting BD_ADDR_LOC and BD_ADDR_REM values at the end of this file.
+ *
+ * IMPORTANT: Copy contents of rv_test_cfg_template.h
+ * file into this file before building.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+#ifndef _RV_TEST_CFG_H_
+#define _RV_TEST_CFG_H_
+
+#include "rv_test_regr.h"
+
+
+/**
+ *
+ * Define TEST_INIT parameter.
+ *
+ * TEST_INIT parameter's available values are:
+ *
+ * -> COMP:   Set testing parameters statically during compilation using
+ *            rv_test_cfg file.
+ * -> EXEC:   Set testing parameters dynamically during execution using LCD
+ *            and keypad.
+ *
+ */
+#define TEST_INIT (EXEC)
+
+
+
+/*
+ * Only with TEST_INIT = COMP
+ * --------------------------
+ */
+
+/**
+ *
+ * Define TEST_TYPE parameter.
+ *
+ * TEST_TYPE parameter's available values are:
+ *
+ * -> REGR:   Execute NON REGRESSION tests.
+ * -> CERTIF: Execute CERTIFICATION tests.
+ * -> DEMO:   Execute DEMONSTRATION events.
+ * -> MISC:   Execute MISCELLANEOUS tests.
+ * -> UPF4:   Execute UPF4 tests.
+ *
+ */
+#define TEST_TYPE (MISC)
+
+
+
+/**
+ *
+ * Define TEST_LEVEL parameter.
+ *
+ * TEST_LEVEL parameter is TEST_XXX_SWE, where XXX can take one of the
+ * following values:
+ *
+ * REGR:
+ * |    L2CAP     RFCOMM    SPP       SDP       SDAP      ATP
+ * |    HS        OBX       OPP       EXPL      FFS       SYN
+ * |    DAR       PWR       TUT
+ * |______________________________________________________________
+ *
+ * CERTIF:
+ * |    L2CAP     SDP       SPP
+ * |______________________________________________________________
+ *
+ * DEMO:
+ * |    HS        EXPL      RNET      TUT		R2D
+ * |______________________________________________________________
+ *
+ * MISC:
+ * |    BTE       SDP       HCI       SPP       BTCTRL    DUN_GW
+ * |    ATP       TCS       FFS       BMI       SCM
+ * |    RTC       AUDIO     R2D       KPD       TUT       MKS
+ * |    RGUI      RNET      UVM       MSME
+ * |______________________________________________________________
+ *
+ * UPF4:
+ * |    L2CAP     RFCOMM    SDP       SPP       BTCTRL    DUN_GW
+ * |    OPP       FAX_GW
+ * |______________________________________________________________
+ *
+ */
+#define TEST_LEVEL (TEST_MSME_SWE)
+
+
+/**
+ *
+ * Define TEST_NUMBER parameter.
+ *
+ * This parameter should not be used with REGR TEST_TYPE (except if
+ * TEST_TABLE[] = {TEST_NUMBER, CONFIG_X, EOL}.
+ *
+ */
+#define TEST_NUMBER (5)
+
+
+
+/*
+ * Only with TEST_MISC = REGR
+ * --------------------------
+ */
+
+/**
+ *
+ * Define TEST_CFG parameter.
+ *
+ * TEST_CFG parameter's available values are:
+ *
+ * -> TEST_LIST:      Execute all scenarios from TEST_TABLE[] sequentially.
+ * -> TEST_LIST_RAND: Execute NB_OF_TEST_TO_PASS scenarios from TEST_TABLE[] randomly.
+ * -> TEST_ALL:       Execute all the scenarios sequentially using the two
+ *                    regression configurations (CONFIG_A and CONFIG_B).
+ * -> TEST_ALL_RAND:  Execute NB_OF_TEST_TO_PASS scenarios randomly using the
+ *                    two regression configurations (CONFIG_A and CONFIG_B).
+ *
+ * Note:
+ *    If TEST_INIT = EXEC, test_cfg parameter (defined in rv_test.c file) is
+ *    automatically set to TEST_ALL_RAND value.
+ *
+ */
+#define TEST_CFG (TEST_ALL_RAND)
+
+
+/**
+ *
+ * Define TEST_TABLE parameter.
+ *
+ * T_RV_REGR_TEST_LIST type is:
+ * -> T_RV_REGR_TEST_LIST_NBR: Scenario number.
+ * -> T_RV_REGR_TEST_LIST_CFG: Test configuration (CONFIG_A or CONFIG_B)
+ *
+ * Note:
+ *    TEST_TABLE MUST contain EOL flag as its last element.
+ *
+ */
+static const T_RV_REGR_TEST_LIST TEST_TABLE[] = {TEST_NUMBER, CONFIG_A, TEST_NUMBER, CONFIG_B,
+                                                 EOL};
+
+/**
+ *
+ * Define NB_OF_TEST_TO_PASS parameter.
+ *
+ * This parameter is only used with REGR TEST_TYPE when TEST_CFG parameter is
+ * set to TEST_LIST_RAND or TEST_ALL RAND. Else not used.
+ *
+ */
+#define NB_OF_TEST_TO_PASS (1)
+
+
+/**
+ *
+ * Define TEST_OCC parameter.
+ *
+ * This parameter defines the number of occurence for each test.
+ *
+ * Note:
+ *    This parameter can't be set dynamically.
+ *
+ */
+#define TEST_OCC (1)
+
+
+/*
+ * Only with TEST LEVEL = AUDIO
+ * ----------------------------
+ */
+
+/**
+ *
+ * Define TEST_AUDIO parameter.
+ *
+ * TEST_AUDIO parameter's available values are:
+ * -> LIST:     to test all the Keybeep or Tones or Melody or Voice memo Tests
+ * -> ONESHOT:  to test just one audio test
+ */
+#define TEST_AUDIO (ONESHOT)
+
+
+
+/*
+ * Only with BT devices
+ * --------------------
+ */
+
+/**
+ *
+ * bd_addr of BT devices used to execute tests.
+ *
+ * Note that in case where two separated devices are used, BD_ADDR_LOC and
+ * BD_ADDR_REM values shouldn't depend on DEVICE_A or DEVICE_B.
+ *
+ */
+
+#ifdef DEVICE_A
+   #define BD_ADDR_LOC {0x00, 0xD0, 0xB7, 0x03, 0x17, 0x26}
+   #define BD_ADDR_REM {0x00, 0xD0, 0xB7, 0x03, 0x17, 0x48}
+#endif
+#ifdef DEVICE_B
+   #define BD_ADDR_LOC {0x00, 0xD0, 0xB7, 0x03, 0x17, 0x48}
+   #define BD_ADDR_REM {0x00, 0xD0, 0xB7, 0x03, 0x17, 0x26}
+#endif
+
+
+#endif /* _RV_TEST_CFG_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_demo.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,50 @@
+/**
+ * @file	rv_test_demo.h
+ *
+ * Definitions used for demonstration tests.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	09/29/00	Cedric Baudelet			Create.
+ *	03/15/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_DEMO_H_
+#define _RV_TEST_DEMO_H_
+
+#include "tests/rv/rv_test.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * DO NOT MODIFY THIS FILE!
+ * Add your test in the corresponding .c file only.
+ */
+
+	
+/** Demo test number type */
+typedef T_RV_TEST_NBR T_RV_DEMO_TEST_NBR;
+
+/** Demo test return value type */
+typedef T_RV_TEST_RET T_RV_DEMO_RET;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RV_TEST_DEMO_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_exec_def.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,71 @@
+/**
+ * @file	rv_test_exec_def.h
+ *
+ * LCD and Keypad definitions.
+ *
+ * All the definitions below are used to control LCD and keypad
+ * when being in EXEC mode (tests to execute are chosen at execution
+ * time with the keypad and the LCD).
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	03/13/02	Vincent Oberle			Put from rv_test.h in its own file.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_EXEC_DEF_H_
+#define _RV_TEST_EXEC_DEF_H_
+
+
+#define TEST_TYPE_STATE				(1)
+#define TEST_LEVEL_STATE			(2)
+#define TEST_NUMBER_STATE			(3)
+#define NB_OF_TEST_TO_PASS_STATE	(4)
+#define TEST_AUDIO_STATE			(5)
+#define TEST_AUDIO_SERVICES_STATE	(6)
+
+#define LCD_LEN (6)
+
+/* RV TEST TEST_TYPE PARAMETER */
+#define TEST_TYPE_LCD_LEN (6)
+static char TEST_TYPE_LCD [TEST_TYPE_LCD_LEN][15] = {"  TEST TYPE   ",
+													 "  1 - REGR    ",
+													 "  2 - CERTIF  ",
+													 "  3 - DEMO    ",
+													 "  4 - MISC    ",
+													 "  5 - UPF     "};
+
+/* RV TEST TEST_AUDIO PARAMETER */
+#define TEST_AUDIO_LCD_LEN (3)
+static char TEST_AUDIO_LCD [TEST_TYPE_LCD_LEN][15] = {"  TEST AUDIO ",
+													  "  1-LIST    ",
+													  "  2-ONESHOT  "};
+/* RV TEST TEST_AUDIO_SERVICES PARAMETER */
+#define TEST_AUDIO_SERVICES_LCD_LEN (5)
+static char TEST_AUDIO_SERVICES_LCD [TEST_TYPE_LCD_LEN][15] = {" AUDIO SERVICE",
+															   " 1 - KEYBEEP",
+															   " 2 - TONES  ",
+															   " 3 - MELODY "};
+
+/* RV TEST TEST_MPM_SERVICES PARAMETER */
+#define TEST_MPM_LCD_LEN (/*8*/6)
+static char TEST_MPM_LCD [TEST_MPM_LCD_LEN][15] = {  "   TEST MPM   ",
+					    						     "              ",
+													 "1- TEST LOOP  ",
+													 "2- WAIT STATES",
+													 "3- PREDEFINED ",
+													 "   COMMANDS   "}; /*,
+													 "4- OTHER      ",
+													 "   COMMAND    "};*/
+
+
+
+#endif /* _RV_TEST_EXEC_DEF_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_filter.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,342 @@
+/**
+ * DEPRECATED: USE env_test.mak instead
+ *
+ * SWEs should not use XXX_REGR, XXX_MISC... anymore.
+ * The tests are now included/excluded at makefile level, specified
+ * by env.mak.
+ */
+
+#ifndef _RV_TEST_FILTER_H_
+#define _RV_TEST_FILTER_H_
+
+#include "rv_test_inc.h"
+
+#define SW_COMPILED		1
+#define SW_NOT_COMPILED	0
+
+
+
+#ifdef TEST_HCI_SWE
+#define HCI_MISC        (SW_COMPILED)
+#else
+#define HCI_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_L2CAP_SWE
+#define L2CAP_REGR      (SW_COMPILED)
+#else
+#define L2CAP_REGR      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_L2CAP_SWE
+#define L2CAP_CERTIF    (SW_COMPILED)
+#else
+#define L2CAP_CERTIF    (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_L2CAP_SWE
+#define L2CAP_UPF4      (SW_COMPILED)
+#else
+#define L2CAP_UPF4      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_RFCOMM_SWE
+#define RFCOMM_REGR     (SW_COMPILED)
+#else
+#define RFCOMM_REGR     (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_RFCOMM_SWE
+#define RFCOMM_UPF4     (SW_COMPILED)
+#else
+#define RFCOMM_UPF4     (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SPP_SWE
+#define SPP_REGR        (SW_COMPILED)
+#else
+#define SPP_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SPP_SWE
+#define SPP_CERTIF      (SW_COMPILED)
+#else
+#define SPP_CERTIF      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SPP_SWE
+#define SPP_MISC        (SW_COMPILED)
+#else
+#define SPP_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SDP_SWE
+#define SDP_REGR        (SW_COMPILED)
+#else
+#define SDP_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SDP_SWE
+#define SDP_CERTIF      (SW_COMPILED)
+#else
+#define SDP_CERTIF      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SDP_SWE
+#define SDP_MISC        (SW_COMPILED)
+#else
+#define SDP_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SDP_SWE
+#define SDP_UPF4        (SW_COMPILED)
+#else
+#define SDP_UPF4        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SDAP_SWE
+#define SDAP_REGR       (SW_COMPILED)
+#else
+#define SDAP_REGR       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_ATP_SWE
+#define ATP_REGR        (SW_COMPILED)
+#else
+#define ATP_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_ATP_SWE
+#define ATP_MISC        (SW_COMPILED)
+#else
+#define ATP_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_ATP_SWE
+#define ATP_DEMO        (SW_COMPILED)
+#else
+#define ATP_DEMO        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_HS_SWE
+#define HS_REGR         (SW_COMPILED)
+#else
+#define HS_REGR         (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_HS_SWE
+#define HS_DEMO         (SW_COMPILED)
+#else
+#define HS_DEMO         (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_BTCTRL_SWE
+#define BTCTRL_MISC     (SW_COMPILED)
+#else
+#define BTCTRL_MISC     (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_BTCTRL_SWE
+#define BTCTRL_UPF4     (SW_COMPILED)
+#else
+#define BTCTRL_UPF4     (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DUN_SWE
+#define DUN_MISC        (SW_COMPILED)
+#else
+#define DUN_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DUN_SWE
+#define DUN_UPF4        (SW_COMPILED)
+#else
+#define DUN_UPF4        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_FAX_SWE
+#define FAX_UPF4        (SW_COMPILED)
+#else
+#define FAX_UPF4        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_EXPL_SWE
+#define EXPL_REGR       (SW_COMPILED)
+#else
+#define EXPL_REGR       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_EXPL_SWE
+#define EXPL_DEMO       (SW_COMPILED)
+#else
+#define EXPL_DEMO       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_TCS_SWE
+#define TCS_REGR        (SW_COMPILED)
+#else
+#define TCS_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_OBX_SWE
+#define OBX_REGR        (SW_COMPILED)
+#else
+#define OBX_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_BMI_SWE
+#define BMI_MISC        (SW_COMPILED)
+#else
+#define BMI_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SCM_SWE
+#define SCM_MISC        (SW_COMPILED)
+#else
+#define SCM_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_OPP_SWE
+#define OPP_REGR        (SW_COMPILED)
+#else
+#define OPP_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_OPP_SWE
+#define OPP_UPF4        (SW_COMPILED)
+#else
+#define OPP_UPF4        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_SYN_SWE
+#define SYN_REGR        (SW_COMPILED)
+#else
+#define SYN_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_FTP_SWE
+#define FTP_REGR        (SW_COMPILED)
+#else
+#define FTP_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_FTP_SWE
+#define FTP_UPF4        (SW_COMPILED)
+#else
+#define FTP_UPF4        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_FFS_SWE
+#define FFS_MISC        (SW_COMPILED)
+#else
+#define FFS_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_RTC_SWE
+#define RTC_MISC        (SW_COMPILED)
+#else
+#define RTC_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_RTC_SWE
+#define RTC_REGR        (SW_COMPILED)
+#else
+#define RTC_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_AUDIO_SWE
+#define AUDIO_MISC      (SW_COMPILED)
+#else
+#define AUDIO_MISC      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_AUDIO_SWE
+#define AUDIO_REGR      (SW_COMPILED)
+#else
+#define AUDIO_REGR      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_R2D_SWE
+#define R2D_MISC		(SW_COMPILED)
+#else
+#define R2D_MISC		(SW_NOT_COMPILED)
+#endif
+#ifdef TEST_R2D_DEMO
+#define R2D_DEMO     (SW_COMPILED)
+#else
+#define R2D_DEMO     (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DAR_SWE
+#define DAR_MISC        (SW_COMPILED)
+#else
+#define DAR_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DAR_SWE
+#define DAR_REGR        (SW_COMPILED)
+#else
+#define DAR_REGR        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_PWR_SWE
+#define PWR_MISC      (SW_COMPILED)
+#else
+#define PWR_MISC      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_PWR_SWE
+#define PWR_REGR      (SW_COMPILED)
+#else
+#define PWR_REGR      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_KPD_SWE
+#define KPD_MISC        (SW_COMPILED)
+#else
+#define KPD_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MKS_SWE
+#define MKS_MISC        (SW_COMPILED)
+#else
+#define MKS_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MPM_SWE
+#define MPM_MISC        (SW_COMPILED)
+#else
+#define MPM_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MPM_SWE
+#define MPM_DEMO        (SW_COMPILED)
+#else
+#define MPM_DEMO        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_RGUI_SWE
+#define RGUI_MISC		(SW_COMPILED)
+#else
+#define RGUI_MISC		(SW_NOT_COMPILED)
+#endif
+#ifdef TEST_JAVA_K_SWE
+#define UVM_MISC        (SW_COMPILED)
+#else
+#define UVM_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DEV1_SWE
+#define DEV1_MISC       (SW_COMPILED)
+#else
+#define DEV1_MISC       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DEV2_SWE
+#define DEV2_MISC       (SW_COMPILED)
+#else
+#define DEV2_MISC       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_DEV3_SWE
+#define DEV3_MISC       (SW_COMPILED)
+#else
+#define DEV3_MISC       (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_LLS_SWE
+#define LLS_MISC        (SW_COMPILED)
+#else
+#define LLS_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_LZO_SWE
+#define LZO_MISC        (SW_COMPILED)
+#else
+#define LZO_MISC        (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MDC_SWE
+#define MDC_MISC      (SW_COMPILED)
+#else
+#define MDC_MISC      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MDC_SWE
+#define MDC_REGR      (SW_COMPILED)
+#else
+#define MDC_REGR      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MDL_SWE
+#define MDL_MISC      (SW_COMPILED)
+#else
+#define MDL_MISC      (SW_NOT_COMPILED)
+#endif
+#ifdef TEST_MDL_SWE
+#define MDL_REGR      (SW_COMPILED)
+#else
+#define MDL_REGR      (SW_NOT_COMPILED)
+#endif
+
+
+
+/*
+ *
+ *   Define DEVICE SELECTION parameter.
+ *
+ *   This parameter allows to select the device used for testing.
+ *
+ *   ONLY used with BOARD
+ *
+ */
+
+#ifndef _WINDOWS
+#define DEVICE_A (1)
+#endif
+
+
+#endif /* _RV_TEST_FILTER_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_filter_redirect.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,283 @@
+/**
+ * DEPRECATED: USE env_test.mak instead
+ *
+ * SWEs should not use XXX_REGR, XXX_MISC... anymore.
+ * The tests are now included/excluded at makefile level, specified
+ * by env.mak.
+ */
+
+
+#ifndef _RV_TEST_FILTER_REDIRECT_H_
+#define _RV_TEST_FILTER_REDIRECT_H_
+
+#include "tests/rv/rv_test_filter.h"
+
+/*
+ * HCI SWE
+ */
+#if ((HCI_MISC	 == SW_COMPILED) || (L2CAP_REGR == SW_COMPILED) ||  \
+	 (L2CAP_CERTIF == SW_COMPILED) || (SPP_CERTIF == SW_COMPILED))
+	#define HCI_TEST (SW_COMPILED)
+#else
+	#define HCI_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * L2CAP SWE
+ */
+#if ((L2CAP_REGR  == SW_COMPILED) || (L2CAP_CERTIF == SW_COMPILED) || (L2CAP_UPF4 == SW_COMPILED) || \
+	 (SDP_REGR	  == SW_COMPILED) || (SDP_CERTIF   == SW_COMPILED) || (SDP_MISC	  == SW_COMPILED) || (SDP_UPF4 == SW_COMPILED) || \
+	 (RFCOMM_REGR == SW_COMPILED) || (RFCOMM_UPF4  == SW_COMPILED) || \
+	 (SPP_CERTIF  == SW_COMPILED))
+	#define L2CAP_TEST (SW_COMPILED)
+#else
+	#define L2CAP_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * RFCOMM SWE
+ */
+#if ((RFCOMM_REGR == SW_COMPILED) || (RFCOMM_UPF4 == SW_COMPILED) || \
+	 (SPP_CERTIF  == SW_COMPILED))
+	#define RFC_TEST (SW_COMPILED)
+#else
+	#define RFC_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * SPP SWE
+ */
+#if ((SPP_REGR	  == SW_COMPILED) || (SPP_CERTIF == SW_COMPILED) || (SPP_MISC == SW_COMPILED) || \
+	 (RFCOMM_UPF4 == SW_COMPILED))
+	#define SPP_TEST (SW_COMPILED)
+#else
+	#define SPP_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * SDP-SDAP SWE
+ */
+#if ((SDP_REGR	 == SW_COMPILED) || (SDP_CERTIF == SW_COMPILED) || (SDP_MISC == SW_COMPILED) || (SDP_UPF4 == SW_COMPILED) || \
+	 (SPP_CERTIF == SW_COMPILED))
+	#define SDP_TEST (SW_COMPILED)
+#else
+	#define SDP_TEST (SW_NOT_COMPILED)
+#endif
+#if (SDAP_REGR == SW_COMPILED)
+	#define SDAP_TEST (SW_COMPILED)
+#else
+	#define SDAP_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * ATP SWE
+ */
+#if ((ATP_REGR == SW_COMPILED) || (ATP_MISC == SW_COMPILED) || (HS_REGR  == SW_COMPILED))
+	#define ATP_TEST (SW_COMPILED)
+#else
+	#define ATP_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * HS SWE
+ */
+#if ((HS_REGR == SW_COMPILED) || (HS_DEMO == SW_COMPILED))
+	#define HS_TEST (SW_COMPILED)
+#else
+	#define HS_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * EXPL SWE
+ */
+#if ((EXPL_REGR == SW_COMPILED) || (EXPL_DEMO == SW_COMPILED))
+	#define EXPL_TEST (SW_COMPILED)
+#else
+	#define EXPL_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * BTCTRL-SCM SWE
+ */
+#if ((BTCTRL_MISC == SW_COMPILED) || (BTCTRL_UPF4 == SW_COMPILED))
+	#define BTCTRL_TEST (SW_COMPILED)
+#else
+	#define BTCTRL_TEST (SW_NOT_COMPILED)
+#endif
+#if (SCM_MISC == SW_COMPILED)
+	#define SCM_TEST (SW_COMPILED)
+#else
+	#define SCM_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * DUN-GW SWE
+ */
+#if ((DUN_MISC == SW_COMPILED) || (DUN_UPF4 == SW_COMPILED))
+	#define DUN_TEST (SW_COMPILED)
+#else
+	#define DUN_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * FAX-GW SWE
+ */
+#if (FAX_UPF4 == SW_COMPILED)
+	#define FAX_TEST (SW_COMPILED)
+#else
+	#define FAX_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * OBX SWE
+ */
+#if (OBX_REGR == SW_COMPILED)
+	#define OBX_TEST (SW_COMPILED)
+#else
+	#define OBX_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * OPP SWE
+ */
+#if ((OPP_REGR == SW_COMPILED) || (OPP_UPF4 == SW_COMPILED))
+	#define OPP_TEST (SW_COMPILED)
+#else
+	#define OPP_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * FFS SWE
+ */
+#if (FFS_MISC == SW_COMPILED)
+	#define FFS_TEST (SW_COMPILED)
+#else
+	#define FFS_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * BMI SWE
+ */
+#if (BMI_MISC == SW_COMPILED)
+	#define BMI_TEST (SW_COMPILED)
+#else
+	#define BMI_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * SYN SWE
+ */
+#if (SYN_REGR == SW_COMPILED)
+	#define SYN_TEST (SW_COMPILED)
+#else
+	#define SYN_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * RTC SWE
+ */
+#if (RTC_REGR == SW_COMPILED) || (RTC_MISC == SW_COMPILED)
+	#define RTC_TEST (SW_COMPILED)
+#else
+	#define RTC_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * AUDIO SWE
+ */
+#if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
+  #define AUDIO_TEST (SW_COMPILED)
+#else
+	#define AUDIO_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * R2D SWE
+ */
+#if ((R2D_MISC == SW_COMPILED) || (R2D_DEMO == SW_COMPILED))
+	#define R2D_TEST (SW_COMPILED)
+#else
+	#define R2D_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * RGUI SWE
+ */
+#if (RGUI_MISC == SW_COMPILED)
+	#define RGUI_TEST (SW_COMPILED)
+#else
+	#define RGUI_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * DAR SWE
+ */
+#if ((DAR_REGR == SW_COMPILED) || (DAR_MISC == SW_COMPILED))
+  #define DAR_TEST (SW_COMPILED)
+#else
+	#define DAR_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * POWER SWE
+ */
+#if ((PWR_REGR == SW_COMPILED) || (PWR_MISC == SW_COMPILED))
+	#define PWR_TEST (SW_COMPILED)
+#else
+	#define PWR_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * KPD SWE
+ */
+#if (KPD_MISC == SW_COMPILED)
+  #define KPD_TEST (SW_COMPILED)
+#else
+	#define KPD_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * MKS SWE
+ */
+#if (MKS_MISC == SW_COMPILED)
+  #define MKS_TEST (SW_COMPILED)
+#else
+	#define MKS_TEST (SW_NOT_COMPILED)
+#endif
+/* SWE below is still not included in current Workspace */
+#if ((FTP_REGR == SW_COMPILED)|| (FTP_UPF4 == SW_COMPILED))
+	#define FTP_TEST (SW_COMPILED)
+#else
+	#define FTP_TEST (SW_NOT_COMPILED)
+#endif
+/*
+ * DEV1, DEV2, DEV3 SWE
+ */
+#if (DEV1_MISC == SW_COMPILED)
+	#define DEV1_TEST (SW_COMPILED)
+#else
+	#define DEV1_TEST (SW_NOT_COMPILED)
+#endif
+#if (DEV2_MISC == SW_COMPILED)
+	#define DEV2_TEST (SW_COMPILED)
+#else
+	#define DEV2_TEST (SW_NOT_COMPILED)
+#endif
+#if (DEV3_MISC == SW_COMPILED)
+	#define DEV3_TEST (SW_COMPILED)
+#else
+	#define DEV3_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * LLS SWE
+ */
+#if (LLS_MISC == SW_COMPILED)
+  #define LLS_TEST (SW_COMPILED)
+#else
+	#define LLS_TEST (SW_NOT_COMPILED)
+#endif
+/* 
+ * MPM SWE
+ */
+#if ((MPM_MISC == SW_COMPILED) || (MPM_DEMO == SW_COMPILED))
+  #define MPM_TEST (SW_COMPILED)
+#else
+	#define MPM_TEST (SW_NOT_COMPILED)
+#endif
+
+/* 
+ * MDC SWE
+ */
+#if ((MDC_MISC == SW_COMPILED) || (MDC_REGR == SW_COMPILED))
+  #define MDC_TEST (SW_COMPILED)
+#else
+	#define MDC_TEST (SW_NOT_COMPILED)
+#endif
+
+/* 
+ * MDL SWE
+ */
+#if ((MDL_MISC == SW_COMPILED) || (MDL_REGR == SW_COMPILED))
+  #define MDL_TEST (SW_COMPILED)
+#else
+	#define MDL_TEST (SW_NOT_COMPILED)
+#endif
+
+#endif /* _RV_TEST_FILTER_REDIRECT_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_misc.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,53 @@
+/**
+ * @file	rv_test_misc.h
+ *
+ * Definitions used for miscellaneous tests.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	09/29/00	Cedric Baudelet			Create.
+ *	03/15/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_MISC_H_
+#define _RV_TEST_MISC_H_
+
+#include "tests/rv/rv_test.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * DO NOT MODIFY THIS FILE!
+ * Add your test in the corresponding .c file only.
+ */
+
+
+/** Misc test number type */
+typedef T_RV_TEST_NBR T_RV_MISC_TEST_NBR;
+
+/** Misc test return value type */
+typedef T_RV_TEST_RET T_RV_MISC_RET;
+
+/** Misc test error type */
+typedef T_RV_TEST_ERR_TYPE T_RV_MISC_ERR_TYPE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RV_TEST_MISC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_regr.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,88 @@
+/**
+ * @file	rv_test_regr.h
+ *
+ * Definitions used for non-regression tests.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	09/29/00	Cedric Baudelet			Create.
+ *	03/15/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_REGR_H_
+#define _RV_TEST_REGR_H_
+
+#include "tests/rv/rv_test.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * DO NOT MODIFY THIS FILE!
+ * Add your test in the corresponding .c file only.
+ */
+
+
+/**
+ * Define the MAX number of tests which it will be possible to execute during
+ * the regression.
+ */
+#define MAX_NB_OF_TEST_TO_PASS (200)
+
+/** Non-Regression test error type */
+typedef T_RV_TEST_ERR_TYPE T_RV_REGR_ERR_TYPE;
+
+/** Non-Regression test return value type */
+typedef T_RV_TEST_RET T_RV_REGR_RET;
+
+
+/** Non-Regression test configuration parameter */
+typedef enum {
+	TEST_LIST					=  0, /* Allows to execute chosen tests				*/
+	TEST_LIST_RAND				= -2, /* Allows to execute rand chosen tests		*/ 
+	TEST_ALL					= -3, /* Allows to execute all tests available		*/
+	TEST_ALL_RAND				= -4  /* Allows to execute rand all tests available	*/
+} T_RV_REGR_TEST_CFG;
+
+
+/** Non-Regression test list contents */
+typedef UINT8 T_RV_REGR_TEST_LIST_NBR;
+typedef UINT8 T_RV_REGR_TEST_LIST_CFG;
+
+#define CONFIG_A (0) /* DEVICE_A = SOURCE & DEVICE_B = TARGET	*/
+#define CONFIG_B (1) /* DEVICE_A = TARGET & DEVICE_B = SOURCE	*/
+
+typedef struct {
+    T_RV_REGR_TEST_LIST_NBR	list_nbr;	/* Number of the executed test			*/
+	T_RV_REGR_TEST_LIST_CFG	list_cfg;	/* Configuration of the executed test	*/
+} T_RV_REGR_TEST_LIST;
+
+
+/** Non-Regression test total number of tests */
+typedef UINT16 T_RV_REGR_TEST_TOT;
+
+/** Non-Regression test nb of occurence of each test */
+typedef UINT8 T_RV_REGR_TEST_OCC;
+
+/** Non-Regression test initialization parameter */
+#define RV_REGR_RAND_INIT (1)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RV_TEST_REGR_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nuc-fw/riviera/tests/rv/rv_test_upf.h	Tue Oct 29 07:03:45 2013 +0000
@@ -0,0 +1,53 @@
+/**
+ * @file	rv_test_upf.h
+ *
+ * Definitions used for Bluetooth Unplug-Fest tests.
+ *
+ * @author	Cedric Baudelet
+ * @author	Vincent Oberle
+ */
+
+/*
+ * History:
+ *
+ *	Date       	Author					Modification
+ *	-------------------------------------------------------------------
+ *	09/29/00	Cedric Baudelet			Create.
+ *	03/15/02	Vincent Oberle			Passed all remaining macros into function.
+ *										Comment and formating cleaning.
+ *
+ * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
+ */
+
+#ifndef _RV_TEST_UPF_H_
+#define _RV_TEST_UPF_H_
+
+#include "tests/rv/rv_test.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * DO NOT MODIFY THIS FILE!
+ * Add your test in the corresponding .c file only.
+ */
+
+
+/** UPF test number type */
+typedef T_RV_TEST_NBR T_RV_UPF_TEST_NBR;
+
+/** UPF test return value type */
+typedef T_RV_TEST_RET T_RV_UPF_RET;
+
+/** UPF test error type */
+typedef T_RV_TEST_ERR_TYPE T_RV_UPF_ERR_TYPE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RV_TEST_UPF_H_ */