changeset 925:c56ba3363aa3

gsm-fw: l1_dyn_dwl code imported from tcs211-l1-reconst
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Thu, 22 Oct 2015 18:19:42 +0000
parents aac4d4b15d2f
children 3f178b3ac50a
files gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_afunc.c gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_apihisr.c gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_async.c gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_func.c gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_init.c gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_sync.c gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_const.h gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_defty.h
diffstat 8 files changed, 2431 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_afunc.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,493 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_AFUNC.C
+ *
+ *        Filename l1_dyn_dwl_afunc.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+
+#include "l1_confg.h"
+#include "l1_types.h"
+#include "sys_types.h"
+#include "cust_os.h"
+#include "l1_macro.h"
+#include "l1_const.h"
+#if TESTMODE
+  #include "l1tm_defty.h"
+#endif
+#if (AUDIO_TASK == 1)
+  #include "l1audio_const.h"
+  #include "l1audio_cust.h"
+  #include "l1audio_defty.h"
+  #include "l1audio_signa.h"
+#endif
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+  #include "l1gtt_signa.h"
+#endif
+#if (L1_DYN_DSP_DWNLD == 1)
+  #include "l1_dyn_dwl_msgty.h"
+  #include "l1_dyn_dwl_defty.h"
+  #include "l1_dyn_dwl_proto.h"
+  #include "l1_dyn_dwl_const.h"
+#endif //L1_DYN_DSP_DWNLD
+#if (L1_MP3 == 1)
+  #include "l1mp3_signa.h"
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+#if (L1_AAC == 1)
+  #include "l1aac_signa.h"
+  #include "l1aac_defty.h"
+#endif //L1_AAC
+#include "l1_defty.h"
+#include "l1_varex.h"
+#include "l1_msgty.h"
+#include "l1_proto.h"
+#include "l1_signa.h"
+#include <string.h>
+#include <stdio.h>
+
+
+#if (TRACE_TYPE == 1) ||(TRACE_TYPE == 4) || (TRACE_TYPE == 7) || (TESTMODE)
+  #include "l1_trace.h"
+#endif
+
+#if (L1_DYN_DSP_DWNLD == 1)
+
+extern const BOOL primitives_to_patch_matrix[][MAX_NUM_OF_PATCH_IDS];
+extern const BOOL incompatibility_matrix[][MAX_NUM_OF_PATCH_IDS];
+extern const BOOL semaphore_matrix[][MAX_NUM_OF_SEMAPHORES];
+
+/* table reconstructed from disassembly of TCS211 binary object */
+const T_SIGNAL_PATCH signal_patch_array[NUM_OF_DYN_DWNLD_PRIMITIVES] =
+{
+	{L1C_STOP_DEDICATED_DONE,			0},
+    #if (L1_GTT == 1)
+	{MMI_GTT_START_REQ,				1},
+    #endif
+	{MPHC_IMMED_ASSIGN_REQ,				2},
+    #if (MELODY_E2 == 1)
+	{MMI_MELODY0_E2_START_REQ,			3},
+	{MMI_MELODY1_E2_START_REQ,			4},
+	{L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON,	5},
+    #endif
+};
+
+
+/*
+ * LoCosto version of L1 has a function called l1_check_flag_for_download_area()
+ * here.  TCS211 binary object has l1_handle_particular_cases_for_TCS211()
+ * instead.  We are going to reconstruct the TCS211 function based on
+ * disassembly, using the LoCosto version as our starting point.
+ */
+
+void l1_handle_particular_cases_for_TCS211(UWORD32 msg_code, BOOL *return_flag)
+{
+  switch(msg_code)
+  {
+    /* from disassembly */
+    case MPHC_IMMED_ASSIGN_REQ:				/* 0x0033 */
+	/* code at 0x8e */
+	l1a.dyn_dwnld.dedicated_stop_flag = FALSE;
+	return;
+    case L1C_STOP_DEDICATED_DONE:			/* 0x0081 */
+	/* code at 0x86 */
+	l1a.dyn_dwnld.dedicated_stop_flag = TRUE;
+	return;
+  #if (MELODY_E2 == 1)
+    case MMI_MELODY0_E2_START_REQ:			/* 0x182E */
+	/* code at 0x6c */
+	l1a.dyn_dwnld.melody0_E2_flag_activated = TRUE;
+	if (l1a.dyn_dwnld.melody1_E2_flag_activated == TRUE) {
+		/* code at 0x80 */
+		*return_flag = FALSE;
+		return;
+	}
+	return;
+    case MMI_MELODY1_E2_START_REQ:			/* 0x1832 */
+	/* code at 0x56 */
+	l1a.dyn_dwnld.melody1_E2_flag_activated = TRUE;
+	if (l1a.dyn_dwnld.melody0_E2_flag_activated == TRUE) {
+		/* code at 0x80 */
+		*return_flag = FALSE;
+		return;
+	}
+	return;
+    case L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON:	/* 0x1866 */
+	/* code at 0x3e */
+	if (l1a.dyn_dwnld.melody0_E2_flag_activated == TRUE ||
+	    l1a.dyn_dwnld.melody1_E2_flag_activated == TRUE) {
+		/* code at 0x80 */
+		*return_flag = FALSE;
+		return;
+	}
+	return;
+    case L1_MELODY0_E2_STOP_CON:			/* 0x1867 */
+	/* code at 0x36 */
+	l1a.dyn_dwnld.melody0_E2_flag_activated = FALSE;
+	return;
+    case L1_MELODY1_E2_STOP_CON:			/* 0x1868 */
+	/* code at 0x2e */
+	l1a.dyn_dwnld.melody1_E2_flag_activated = FALSE;
+	return;
+  #endif
+    default:
+	return;
+  }
+
+}
+/*------------------------------------------------------------------------------------------------------------------- */
+/* l1_does_the_incoming_primitive_trigger_dynamic_dwnld                                                               */
+/*------------------------------------------------------------------------------------------------------------------- */
+/*                                                                                                                    */
+/* Parameters : Signal Code of the message, delay flag                                                                */
+/*                                                                                                                    */
+/* Return     :    TRUE if the primitive triggers a dynamic download, FALSE in the other case                         */
+/*                                                                                                                    */
+/* Description :  Check if the primitive triggers a dynamic download; if yes it return TRUE, otherwise FALSE          */
+/*                                                                                                                    */
+/*                                                                                                                    */
+/*------------------------------------------------------------------------------------------------------------------- */
+
+BOOL l1_does_the_incoming_primitive_trigger_dynamic_dwnld(UWORD32 msg_code, BOOL delay_flag)
+{
+  BOOL return_flag = FALSE;
+  UWORD16 i;
+  for (i=0;i<l1a.dyn_dwnld.num_of_primitives;i++)
+  {
+    if(msg_code == signal_patch_array[i].primitive)
+      return_flag = TRUE;
+
+  }
+
+  l1_handle_particular_cases_for_TCS211(msg_code, &return_flag);
+
+  return return_flag;
+}
+
+/*----------------------------------------------------------------------------------------   */
+/* l1_lookup_primitive_patch_matrix                                                          */
+/*----------------------------------------------------------------------------------------   */
+/*                                                                                           */
+/* Parameters : Signal Code of the message, patch_id vector                                  */
+/*                                                                                           */
+/* Return     :    number of patches to download, patch ids vectore (by reference)           */
+/*                                                                                           */
+/* Description :  Retrieves the patch ids to be downloaded and number of patches to download */
+/*                     Patch ID is retrieved via look-up in primitives to patch ID matrix    */
+/*                                                                                           */
+/*----------------------------------------------------------------------------------------   */
+
+UWORD16 l1_lookup_primitive_patch_matrix(UWORD32 msg_code, UWORD16* patch_id_p)
+{
+  UWORD16 j;
+  UWORD16 counter=0;
+  UWORD16 msg_code_id=0 ;//omaps00090550
+
+  // Check if one of the messages belongs to the set of primitves which triggers a dynamic download and saves its index
+
+#if 0	// LoCosto-ism not present in TCS211
+ if (!((l1a.state[L1A_GTT_STATE] == 0) || (l1a.state[L1A_GTT_STATE] == 1))) // TTY ON
+  {
+      if(msg_code == MMI_TCH_VOCODER_CFG_REQ) // AND Current_message == VOCODER
+      	{
+      	    // Dont do anything
+      	    return 0;
+      	}
+  }
+#endif
+  
+  for (j=0;j<NUM_OF_DYN_DWNLD_PRIMITIVES;j++)
+  {
+    if (msg_code == signal_patch_array[j].primitive)
+      msg_code_id = signal_patch_array[j].msg_id;
+  }
+
+
+  // Compute the number of elements to be downloaded and their ids
+  for (j=0; j<MAX_NUM_OF_PATCH_IDS; j++)
+  {
+    patch_id_p[j]=0xFFFF; //omaps00090550 ;
+    if(primitives_to_patch_matrix[msg_code_id][j] == 1)
+    {
+      patch_id_p[counter++]=j;
+     }
+  }
+  return counter;
+}
+
+/*------------------------------------------------------------------------- */
+/* l1_is_patch_already_installed                                            */
+/*------------------------------------------------------------------------- */
+/*                                                                          */
+/* Parameters : patch id                                                    */
+/*                                                                          */
+/* Return     :    TRUE patch is already installed, FALSE otherwise         */
+/*                                                                          */
+/* Description :  Check if the selected patch id is already installed or not*/
+/*                                                                          */
+/*                                                                          */
+/*------------------------------------------------------------------------- */
+
+BOOL l1_is_patch_already_installed (UWORD16 patch_id)
+{
+  UWORD16 i=0;
+  while(i<l1a.dyn_dwnld.num_patches_installed)
+  {
+    if(l1a.dyn_dwnld.patch_id[i]==patch_id)
+      break;
+    else
+      i++;
+  }
+  if(i<l1a.dyn_dwnld.num_patches_installed)
+    return TRUE;
+  else
+    return FALSE;
+}
+
+/*-----------------------------------------------------------------------------  */
+/* l1_is_patch_id_in_uninstall_set                                               */
+/*-----------------------------------------------------------------------------  */
+/*                                                                               */
+/* Parameters : patch id, uninstall address vector, num of uninstall elements    */
+/*                                                                               */
+/* Return     :    TRUE patch is in the set, FALSE otherwise                     */
+/*                                                                               */
+/* Description :  Check if the selected patch id is in the uninstall set or not  */
+/*                                                                               */
+/*                                                                               */
+/*-----------------------------------------------------------------------------  */
+
+BOOL l1_is_patch_id_in_uninstall_set (UWORD16 patch_id, UWORD16 *uninstall_patch_vect, UWORD16 num_of_uninstall_elem)
+{
+  UWORD16 i;
+  for (i=0;i<num_of_uninstall_elem;i++)
+  {
+    if(patch_id==uninstall_patch_vect[i])
+      return TRUE;
+  }
+  return FALSE;
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------------------- */
+/* l1_manage_patch_incompatibilty                                                                                                         */
+/*--------------------------------------------------------------------------------------------------------------------------------------- */
+/*                                                                                                                                        */
+/* Parameters :    num of patch to download, num of uninstalled elements (pointer), uninstall vect                                        */
+/* Return     :    TRUE if there is some patch to uninstall, FALSE otherwise. By reference, num of patches to uninstall and their IDs     */
+/*                                                                                                                                        */
+/* Description :  Check if some patch must be uninstalled: in case, retrieves the number of patch to uninstall and their IDs              */
+/*                                                                                                                                        */
+/*--------------------------------------------------------------------------------------------------------------------------------------- */
+
+BOOL l1_manage_patch_incompatibilty(UWORD16 num_of_patch_id_to_dwnld, UWORD16 *num_of_uninstall_elem, UWORD16 *uninstall_patch_id_vect)
+{
+  UWORD16 i,j;
+  UWORD16 patch_id;
+
+  // Reset values passed by reference
+  *num_of_uninstall_elem=0;
+  for(j=0;j<MAX_NUM_OF_PATCH_IDS;j++)
+    uninstall_patch_id_vect[j]=0xFFFF; //omaps00090550 ;
+
+   // First cycle: for all the patches that must be downloaded
+  for(i=0;i<num_of_patch_id_to_dwnld;i++)
+  {
+    patch_id=l1a.dyn_dwnld.next_patch_id[i];
+    // Check all incompatibilities
+    for(j=0;j<MAX_NUM_OF_PATCH_IDS;j++)
+    {
+      // If patch ID j is incompatible with selected patch id that must be downloaded
+      if(incompatibility_matrix[patch_id][j]==1)
+      {
+        // If patch j is already installed and not yet in the uninstall set
+        if((l1_is_patch_already_installed(j) == TRUE) && (l1_is_patch_id_in_uninstall_set(j,uninstall_patch_id_vect,(*num_of_uninstall_elem))==FALSE))
+        {
+          // Add patch j in the uninstall set and increase number of uninstall elements
+          uninstall_patch_id_vect[*num_of_uninstall_elem]=j;
+          (*num_of_uninstall_elem)++;
+        }
+    }
+    }
+  }
+  if(*num_of_uninstall_elem==0)
+    return TRUE;
+  else
+    return FALSE;
+}
+
+/*----------------------------------------------------------------- */
+/* l1_set_semaphores_for_all_state_machines_involved                */
+/*----------------------------------------------------------------- */
+/*                                                                  */
+/* Parameters :  num of patches to download,                        */
+/* Return     :   none                                              */
+/*                                                                  */
+/* Description :  Set semaphores for the state machines impacted    */
+/*                                                                  */
+/*                                                                  */
+/*----------------------------------------------------------------- */
+
+void l1_set_semaphores_for_all_state_machines_involved(UWORD16 num_of_patch_id_to_dwnld, UWORD16* next_patch_id)
+{
+  UWORD16 i,j, patch_id;
+  for (i=0;i<num_of_patch_id_to_dwnld;i++)
+  {
+    patch_id = next_patch_id[i];
+    for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
+    {
+      if(semaphore_matrix[patch_id][j]==1)
+      {
+        l1a.dyn_dwnld.semaphore_vect[j]=RED;
+      }
+    }
+  }
+}
+
+/*----------------------------------------------------------------- */
+/* l1_update_semaphores_for_all_state_machines                      */
+/*----------------------------------------------------------------- */
+/*                                                                  */
+/* Parameters :  num of patches to download,                        */
+/* Return     :   none                                              */
+/*                                                                  */
+/* Description :  Update semaphores for the state machines impacted */
+/*                (DELAY case)                                      */
+/*                                                                  */
+/*----------------------------------------------------------------- */
+
+void l1_update_semaphores_for_all_state_machines(UWORD16 num_of_patch_id_to_dwnld)
+{
+  /* In case of delay the patch which is DELAYED may have been be already installed*/
+  /* The semaphores that have been raised during the previous dynamic download */
+  /* for that patch must be updated */
+
+  UWORD16 i,j, patch_id;
+  for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
+    l1a.dyn_dwnld.semaphore_vect[j] = GREEN;
+  for (i=0;i<num_of_patch_id_to_dwnld;i++)
+  {
+    patch_id = l1a.dyn_dwnld.next_patch_id[i];
+    for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
+    {
+      if(semaphore_matrix[patch_id][j]==1)
+      {
+        l1a.dyn_dwnld.semaphore_vect[j]=RED;
+      }
+    }
+  }
+}
+
+/*-------------------------------------------------------*/
+/* l1_reset_semaphores                                   */
+/*-------------------------------------------------------*/
+/*                                                       */
+/* Parameters :  none                                    */
+/* Return     :                                          */
+/*                                                       */
+/* Description :  Reset semaphores only for the state machines related to the currently downloaded patches                      */
+/*                     In fact, because of delay, some semaphores can be set for patch that will be downloaded in the follwoing step                                  */
+/*                                                       */
+/*-------------------------------------------------------*/
+void l1_reset_semaphores()
+{
+  UWORD16 i,j, patch_id;
+  for (i=0;i<l1a.dyn_dwnld.num_of_elem_to_copy;i++)
+  {
+    patch_id = l1a.dyn_dwnld.next_patch_id[i];
+    for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
+    {
+      if(semaphore_matrix[patch_id][j]==1)
+      {
+        l1a.dyn_dwnld.semaphore_vect[j]=GREEN;
+      }
+    }
+  }
+}
+
+
+/*---------------------------------------------------------- */
+/* l1_push_Primitive                                         */
+/*---------------------------------------------------------- */
+/*                                                           */
+/* Parameters :  primitive ID                                */
+/* Return     :  TRUE if push is successful, FALSE otherwise */
+/*                                                           */
+/* Description :  Push primitive ID into DELAY FIFO          */
+/*                                                           */
+/*                                                           */
+/*---------------------------------------------------------- */
+
+BOOL l1_push_Primitive(UWORD32 primitive_id)
+{
+  UWORD32 num_elem = l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
+  BOOL return_flag = TRUE;
+
+  if(num_elem >= MAX_NUM_OF_PATCH_IDS)
+  {
+    return_flag = FALSE;
+  }
+  else
+  {
+    l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[num_elem++] = primitive_id;
+    l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = num_elem;
+  }
+  return return_flag;
+}
+
+/*---------------------------------------------------------- */
+/* l1_pop_Primitive                                          */
+/*---------------------------------------------------------- */
+/*                                                           */
+/* Parameters :  primitive ID (pointer)                      */
+/* Return     :  TRUE if pop is successful, FALSE otherwise  */
+/*                                                           */
+/* Description :  Pop primitive from DELAY FIFO              */
+/*                                                           */
+/*                                                           */
+/*---------------------------------------------------------- */
+
+BOOL l1_pop_Primitive(UWORD32 *p_primitive)
+{
+  UWORD32 primitive_id;
+  UWORD8 ind;
+  UWORD32 num_elem = l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
+  BOOL return_flag = TRUE;
+
+  if(num_elem <= 0)
+  {
+    return_flag = FALSE;
+  }
+  else
+  {
+    primitive_id = l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[0];
+    for (ind = 0;ind<num_elem-1;ind++)
+      l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[ind] = l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[ind+1];
+    l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[num_elem-1] = 0;
+    l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = num_elem-1;
+    *p_primitive = primitive_id;
+  }
+  return return_flag;
+}
+/*---------------------------------------------------------- */
+/* l1_check_Fifo_Primitive                                   */
+/*---------------------------------------------------------- */
+/*                                                           */
+/* Parameters :  none                                        */
+/* Return     :  Number of elements in the FIFO              */
+/*                                                           */
+/* Description :  Return number of elements in the FIFO      */
+/*                                                           */
+/*                                                           */
+/*---------------------------------------------------------- */
+
+UWORD32 l1_check_Fifo_Primitive()
+{
+  return l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
+}
+#endif // L1_DYN_DSP_DWNLD == 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_apihisr.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,409 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_APIHISR.C
+ *
+ *        Filename l1_dyn_dwl_apihisr.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+
+#include <stdio.h>
+#include <string.h>
+#include "nucleus.h"
+#include "l1_confg.h"
+#include "sys_types.h"
+#include "l1_types.h"
+#include "l1audio_cust.h"
+#include "l1audio_defty.h"
+#include "l1audio_const.h"
+#include "l1_const.h"
+#include "l1tm_defty.h"
+
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+#endif
+
+#if (L1_DYN_DSP_DWNLD == 1)
+  #include "l1_dyn_dwl_const.h"
+  #include "l1_dyn_dwl_signa.h"
+  #include "l1_dyn_dwl_defty.h"
+  #include "l1_dyn_dwl_msgty.h"
+  #include "l1_dyn_dwl_error.h"
+  #include "l1_dyn_dwl_proto.h"
+  #include "l1_api_hisr.h"
+#endif
+#if (L1_MP3 == 1)
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+
+#include "l1_defty.h"
+#include "cust_os.h"
+/* #include "nu_main.h" */
+#include "l1audio_signa.h"
+#include "l1audio_cust.h"
+#include "l1_varex.h"
+#include "l1_macro.h"
+#include "l1_api_hisr.h"
+#include "l1_trace.h"
+
+#if (L1_DYN_DSP_DWNLD == 1)
+
+/* Dynamic Download NDB API */
+T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb;
+
+#if (CODE_VERSION == SIMULATION)
+  T_DYN_DWNLD_MCU_DSP dyn_dwl_ndb_sim;
+  UWORD16 dwnld_area_array[SIZE_DWNLD_AREA_SIMU];
+#endif
+
+enum states
+  {
+     RESET = 0, 
+     WAIT_UNINSTALL = 1,
+     WAIT_DSP_END_BUFFER = 2,
+     WAIT_CRC = 3,
+     WAIT_INSTALL = 4
+  };
+/*------------------------------------------------------------------------------------------------------------- */
+/* l1_dyn_dwnld_copy_patch_process()                                                                            */
+/*------------------------------------------------------------------------------------------------------------- */
+/*                                                                                                              */
+/* Parameters : BOOL new_patch: TRUE if the patch is copied from scratch, FALSE if it has been started so far   */
+/*                                                                                                              */
+/* Return     : state in which must be stepped into                                                             */
+/*                                                                                                              */
+/* Description : Performs the copy of the patch and computes next state of corresponding APIHISR state machine  */
+/*                                                                                                              */
+/*------------------------------------------------------------------------------------------------------------- */
+
+UWORD8 l1_dyn_dwnld_copy_patch_process (BOOL new_patch)
+{
+  BOOL        still_words_to_be_copied;
+  UWORD16     tmp_dwnld_area_size;
+  UWORD8      return_state;
+  UWORD16     *p_src_mcu = NULL;
+  UWORD16     *p_dest_mcu = NULL;
+  UWORD16     *tmp_pointer = NULL;
+
+  UWORD16 tmp_patch_size = l1_apihisr.dyn_dwnld.tmp_patch_size;
+
+  /* Copy first N block of data */
+  still_words_to_be_copied = l1_init_pointers_and_copy_first_block_of_data(&(tmp_dwnld_area_size), &(tmp_patch_size), &(p_dest_mcu), &(p_src_mcu),new_patch);
+
+  /* Set download command */
+   dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_DOWNLOAD;  
+
+   #if (CODE_VERSION == SIMULATION)
+     l1_trigger_api_interrupt();
+   #endif
+
+  /* Check if there are still words to be copied after first API interrupt generation: if not */
+  /* the patch has been completely downloaded and MCU waits for CRC*/
+  if(still_words_to_be_copied == FALSE)
+  {
+    return_state = WAIT_CRC;
+  }
+
+  /* If not copy the patch: if download area is bigger than patch size copy until the end of the patch */
+  /* Else copy till the end of buffer download area and wait for DSP interrupt */
+  else
+  {
+    if (tmp_dwnld_area_size >= tmp_patch_size)
+    {
+      l1_copy_till_the_end_of_the_patch_and_update_write_pointer(tmp_patch_size,p_dest_mcu,p_src_mcu);
+      return_state = WAIT_CRC;
+    }
+    else
+    {
+      l1_copy_till_end_of_dwnld_area_and_update_write_pointer(tmp_dwnld_area_size,p_dest_mcu,&tmp_patch_size,&p_src_mcu);
+
+      /* Save source patch file pointerand temporary patch size*/
+      l1_apihisr.dyn_dwnld.running_source_pointer = (UWORD32) p_src_mcu;
+      l1_apihisr.dyn_dwnld.tmp_patch_size  = tmp_patch_size;
+
+      /* Change state*/
+      return_state = WAIT_DSP_END_BUFFER;
+    }
+  }
+  return return_state;
+}
+/*-------------------------------------------------------------*/
+/* l1_dyn_dwnld_apihisr()                                      */
+/*-------------------------------------------------------------*/
+/*                                                             */
+/* Parameters : none                                           */
+/*                                                             */
+/* Return     : n/a                                            */
+/*                                                             */
+/* Description : implements Dynamic Download API HISR          */
+/*                                                             */
+/*-------------------------------------------------------------*/
+
+void l1_dyn_dwnld_apihisr()
+{
+
+  UWORD8 *state = &l1_apihisr.dyn_dwnld.state;
+
+
+  /* Variables for copy process */
+  
+  xSignalHeaderRec    *conf_msg;
+  BOOL                flag_error;
+  
+  /* Dynamic Download error handler : check if critical error occured */
+  if( l1_dyn_dwnld_apihisr_error_handler() == TRUE )
+  {
+     /* Send notification to L1A */
+     conf_msg = os_alloc_sig(sizeof(T_API_L1_DYN_DWNLD_STOP));
+     DEBUGMSG(status,NU_ALLOC_ERR)
+     conf_msg->SignalCode = API_L1_DYN_DWNLD_STOP;
+     ((T_API_L1_DYN_DWNLD_STOP *) (conf_msg->SigP))->error = dyn_dwl_ndb->d_api_dwl_error_code;
+     dyn_dwl_ndb->d_api_dwl_error_code = C_DWL_ERR_RESET;
+     os_send_sig(conf_msg,L1C1_QUEUE);
+     DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+
+     /* Branch state */
+     *state = RESET;
+     flag_error = TRUE;
+     return;
+  }
+  else
+  {
+    flag_error = FALSE;
+  }
+
+  /****************/
+  /*STATE MACHINE */
+  /****************/
+
+  while (1){
+  switch(*state)
+  {
+    /*********/
+    /* RESET */
+    /*********/
+    case RESET:
+    {
+      /* Check reset init command (if reset by DSP) / Restart in case dynamic download delayed */
+      if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK || 
+      l1a_apihisr_com.dyn_dwnld.command.restart == TRUE)
+      {
+        if (flag_error == FALSE)
+        {  
+
+          /* Send confirmation to L1A */
+          conf_msg = os_alloc_sig(0);
+          DEBUGMSG(status,NU_ALLOC_ERR)
+          conf_msg->SignalCode = API_L1_DYN_DWNLD_START_CON;
+          os_send_sig(conf_msg,L1C1_QUEUE);
+          DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+
+          /* Store patch IDs to install counter in global API */
+          l1_apihisr.dyn_dwnld.patch_ids_counter = l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem;
+      
+          /* Reset command */
+          l1a_apihisr_com.dyn_dwnld.command.restart = FALSE;
+
+          /* Test if number of uninstall elements is greater than zero */
+          if ( l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem > 0 )
+          {
+            /* Copy num of elem L1A-API variable counter into global uninstall counter */
+            l1_apihisr.dyn_dwnld.uninstall_counter = l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem;
+
+            l1_set_uninstall_parameters();
+
+            #if (CODE_VERSION == SIMULATION)
+              l1_trigger_api_interrupt();
+            #endif
+
+            /* Change state */
+            *state = WAIT_UNINSTALL;     
+          }
+          else /* No elements to uninstall*/
+          {
+            /* Reset patch size */
+            l1_apihisr.dyn_dwnld.tmp_patch_size = 0;
+
+            /* Copy the patch and update current state*/
+            *state =  l1_dyn_dwnld_copy_patch_process(TRUE);
+
+          }
+        }
+      }
+      return;
+    }   /* end case RESET */
+//omaps00090550    break;
+
+    /******************/
+    /* WAIT_UNINSTALL  */
+    /******************/
+    case WAIT_UNINSTALL:
+    {
+      /* Check uninstall command (if reset by DSP) */
+      if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK )
+      {
+        /* Decrement uninstall counter */
+        l1_apihisr.dyn_dwnld.uninstall_counter--;
+
+        /* Check uninstall counter: if it is 0 no more uninstall to perform*/
+        if ( l1_apihisr.dyn_dwnld.uninstall_counter == 0 )
+        {
+          /* Send confirmation to L1A */
+          conf_msg = os_alloc_sig(0);
+          DEBUGMSG(status,NU_ALLOC_ERR)
+          conf_msg->SignalCode = API_L1_DYN_DWNLD_UNINST_OK;
+          os_send_sig(conf_msg,L1C1_QUEUE);
+          DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+
+          /* Reset patch size */
+          l1_apihisr.dyn_dwnld.tmp_patch_size = 0;
+
+          /* Copy the patch and update current state*/
+           *state =  l1_dyn_dwnld_copy_patch_process(TRUE);
+        }  
+        else /* there are some uninstall to perform */
+        {
+          l1_set_uninstall_parameters();
+
+		  #if (CODE_VERSION == SIMULATION)
+            l1_trigger_api_interrupt();
+          #endif
+        }
+      }
+      return; 
+    }   /* end case WAIT_UNINSTALL */
+//omaps00090550    break;
+
+    /***********************/
+    /* WAIT_DSP_END_BUFFER */
+    /***********************/
+    case WAIT_DSP_END_BUFFER:
+    {
+      if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK )
+      {
+        /* Copy the patch and update current state*/
+        *state = l1_dyn_dwnld_copy_patch_process(FALSE);
+      }
+      return;
+    } /* end case WAIT_DSP_END_BUFFER */
+//omaps00090550    break;
+
+    /************/
+    /* WAIT_CRC */
+    /************/
+    case WAIT_CRC:
+    {
+      /* Check if DSP install command is reset */
+      if (dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK )
+      {
+        /* Test if CRC is OK */
+        if ( dyn_dwl_ndb->d_api_dwl_crc != l1a_apihisr_com.dyn_dwnld.copy_parameters.crc[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter])       /* CRC not OK */
+        {
+          /* Send notification to L1A */
+          conf_msg = os_alloc_sig(sizeof(T_API_L1_CRC_NOT_OK));
+          DEBUGMSG(status,NU_ALLOC_ERR)
+          conf_msg->SignalCode = API_L1_CRC_NOT_OK;
+          ((T_API_L1_CRC_NOT_OK *) (conf_msg->SigP))->patch_id = dyn_dwl_ndb->d_api_dwl_crc;
+          os_send_sig(conf_msg,L1C1_QUEUE);
+          DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+
+          /* Change state */
+          *state = RESET;
+        }
+        else              /* CRC OK */
+        {
+          conf_msg = os_alloc_sig(sizeof(T_API_L1_CRC_NOT_OK));
+          DEBUGMSG(status,NU_ALLOC_ERR)
+          conf_msg->SignalCode = API_L1_CRC_OK;
+          ((T_API_L1_CRC_NOT_OK *) (conf_msg->SigP))->patch_id = l1a_apihisr_com.dyn_dwnld.copy_parameters.crc[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter];
+          os_send_sig(conf_msg,L1C1_QUEUE);
+          DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+          *state = WAIT_INSTALL;
+
+          /* Set install parameters */
+          
+          dyn_dwl_ndb->d_api_dwl_function_address[0] = 
+          (API) (l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter] & 0x0000FFFF);
+          dyn_dwl_ndb->d_api_dwl_function_address[1] = 
+          (API) ((l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter] >> 16) & 0x0000FFFF);
+
+          dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_INSTALL;
+
+		  #if (CODE_VERSION == SIMULATION)
+            l1_trigger_api_interrupt();
+          #endif
+        }
+      }  
+      return;
+    }   /* end case WAIT_CRC */
+//omaps00090550    break;
+
+    /****************/
+    /* WAIT_INSTALL */
+    /****************/
+    case WAIT_INSTALL:
+    {
+      /* Check if DSP install command is reset */
+      if (dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK )
+      {
+        /* Decrement patch counter */
+        l1_apihisr.dyn_dwnld.patch_ids_counter--;
+
+        /* Test if patch counter is null */
+        if ( l1_apihisr.dyn_dwnld.patch_ids_counter == 0 )
+        {
+          /* Send notification to L1A */
+          conf_msg = os_alloc_sig(0);
+          DEBUGMSG(status,NU_ALLOC_ERR)
+          conf_msg->SignalCode = API_L1_DYN_DWNLD_FINISHED;
+          os_send_sig(conf_msg,L1C1_QUEUE);
+          DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+          *state = RESET;
+        }
+        else
+        {
+          /* Reset patch size */
+          l1_apihisr.dyn_dwnld.tmp_patch_size = 0;
+
+          /* Copy the patch and update current state*/
+          *state =  l1_dyn_dwnld_copy_patch_process(TRUE);
+        }
+      }
+      return;
+    }   /* end case WAIT_INSTALL */
+//omaps00090550    break;
+  }   /* end switch */
+}  /* end while */
+}
+
+/*-------------------------------------------------------------*/
+/* l1_dyn_dwnld_apihisr_error_handler()                        */
+/*-------------------------------------------------------------*/
+/*                                                             */ 
+/* Parameters : error_code (OUT) error_code received from DSP  */
+/*                                                             */
+/* Return     : TRUE if errors signaled by DSP                 */
+/*                                                             */
+/*-------------------------------------------------------------*/
+ BOOL l1_dyn_dwnld_apihisr_error_handler()
+{
+  BOOL  critical;
+
+  /* Initialisation */
+  critical = FALSE;
+
+  if(dyn_dwl_ndb->d_api_dwl_error_code != 0)
+  {
+    critical = TRUE;
+  }
+
+  return critical;
+}
+
+
+#endif  /* L1_DYN_DSP_DWNLD */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_async.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,721 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_ASYNC.C
+ *
+ *        Filename l1_dyn_dwl_async.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+#include <stdio.h>
+#include <string.h>
+#include "nucleus.h"
+#include "l1_confg.h"
+#include "l1_types.h"
+#include "sys_types.h"
+#include "cust_os.h"
+#include "l1audio_signa.h"
+#include "l1audio_const.h"
+#include "l1audio_cust.h"
+#include "l1audio_defty.h"
+#include "l1_const.h"
+#include "l1tm_defty.h"
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+#endif
+#if (L1_DYN_DSP_DWNLD==1)
+  #include "l1_dyn_dwl_defty.h"
+  #include "l1_dyn_dwl_msgty.h"
+  #include "l1_dyn_dwl_const.h"
+  #include "l1_dyn_dwl_signa.h"
+  #include "l1_dyn_dwl_error.h"
+  #include "l1_dyn_dwl_proto.h"
+#endif
+#if (L1_MP3 == 1)
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+#if (L1_AAC == 1)
+  #include "l1aac_defty.h"
+#endif //L1_AAC
+
+#include "l1_defty.h"
+#include "l1_varex.h"
+#include "l1_trace.h"
+#include "sys_dma.h"
+
+#if (OP_RIV_AUDIO == 1)
+  #include "rv/rv_general.h"
+#endif
+
+
+#if (L1_DYN_DSP_DWNLD == 1)
+#if(CODE_VERSION == SIMULATION)
+  extern   VOID trace_fct_simu_dyn_dwnld(CHAR *fct_name);
+#endif // CODE_VERSION == SIMULATION
+
+  
+
+extern UWORD32 dyn_dwnld_address_vect[];
+extern const UWORD8 *dyn_dwnld_copy_MCU_vect[];
+extern UWORD16 dyn_dwnld_crc_vect[];
+extern UWORD16 size_vect[];
+
+/*---------------------------------------------------------------------------------------------------------*/
+/* l1_patch_id2string                                                                                      */
+/*---------------------------------------------------------------------------------------------------------*/
+/*                                                                                                         */
+/* Parameters : patch identificator "patch_id", string vector "vector" which identifies the patch          */
+/*                                                                                                         */
+/* Return     : Fills the string vector containing the patch id by reference                               */
+/*                                                                                                         */
+/*                                                                                                         */
+/* Description :  Links the patch ID number to its string value                                            */
+/*                                                                                                         */
+/*                                                                                                         */
+/*---------------------------------------------------------------------------------------------------------*/
+
+#if 0
+void l1_patch_id2string(UWORD16 patch_id, char* vect)
+{
+
+  switch(patch_id)
+  {
+
+#if ((CODE_VERSION == SIMULATION) || (((CHIPSET == 12) || (CHIPSET == 15))))  
+    case MP3_PATCH:
+    {
+      vect[0] = 'M';
+      vect[1] = 'P';
+      vect[2] = '3';
+      vect[3] = '\0';
+    }
+    break;
+#endif
+    case MMS_PATCH:
+    {
+      vect[0] = 'M';
+      vect[1] = 'M';
+      vect[2] = 'S';
+      vect[3] = '\0';
+    }
+    break;
+
+#if ((CODE_VERSION == SIMULATION) || (((CHIPSET == 12) || (CHIPSET == 15))))
+    case E2_PATCH:
+    {
+      vect[0] = 'E';
+      vect[1] = '2';
+      vect[2] = ' ';
+      vect[3] = '\0';
+    }
+    break;
+#endif
+    case TTY_PATCH:
+    {
+      vect[0] = 'T';
+      vect[1] = 'T';
+      vect[2] = 'Y';
+      vect[3] = '\0';
+    }
+    break;
+    case SPEECH_ACOUSTIC_PATCH:
+    {
+      vect[0] = 'A';
+      vect[1] = 'N';
+      vect[2] = 'R';
+      vect[3] = '\0';
+    }
+    break;
+#if ((CODE_VERSION == SIMULATION) || (CHIPSET == 12) || (CHIPSET == 15))
+    case AAC_PATCH:
+    {
+      vect[0] = 'A';
+      vect[1] = 'A';
+      vect[2] = 'C';
+      vect[3] = '\0';
+    }
+    break;
+#endif
+#if ((CODE_VERSION == SIMULATION) || (CHIPSET == 12) || (CHIPSET == 15))
+    case PCM_EXTRACTION_PATCH:
+    {
+      vect[0] = 'P';
+      vect[1] = 'C';
+      vect[2] = 'M';
+      vect[3] = '\0';
+    }
+    break;
+#endif
+
+  }
+}
+#endif
+
+/*----------------------------------------------------------------------------------------*/
+/* l1_dynamic_download_manager                                                            */
+/*----------------------------------------------------------------------------------------*/
+/*                                                                                        */
+/* Parameters : Signal Code of the message, delay flag                                    */
+/*                                                                                        */
+/* Return     : True if the primitives triggers a dynamic download and sets all the       */
+/*              parameters to perform a dynamic download, false otherwise                 */
+/*                                                                                        */
+/* Description :  Implements the dynamic download manager algorithm                       */
+/*                                                                                        */
+/*                                                                                        */
+/*----------------------------------------------------------------------------------------*/
+
+
+BOOL l1_dynamic_download_manager(UWORD32 SignalCode, BOOL delay_flag)
+{
+
+  UWORD16 temp_patch_array[MAX_NUM_OF_PATCH_IDS];
+  UWORD16 temp_num_patch;
+  UWORD16 num_of_patch_id_to_dwnld;
+  UWORD16 num_of_uninstall_elem;
+  UWORD16 i;
+  UWORD16 patch_id_uninstall_vect[MAX_NUM_OF_PATCH_IDS];
+  UWORD16 patch_id;
+  UWORD16 temp_patch_id[MAX_NUM_OF_PATCH_IDS]= {0}; //omaps00090550
+  BOOL return_flag = FALSE;
+
+  // Primitive is processed only if it triggers a dynamic download or there is a delay
+  if(delay_flag == TRUE || l1_does_the_incoming_primitive_trigger_dynamic_dwnld(SignalCode, FALSE) == TRUE)
+  {
+
+    //----------------------------------------------------------------------    
+    // Compute which patch ids (passed by reference) and the number of patches to install
+    //----------------------------------------------------------------------
+    
+    temp_num_patch= l1_lookup_primitive_patch_matrix(SignalCode,temp_patch_array);  
+    i=0;
+    num_of_patch_id_to_dwnld = 0;
+
+    //--------------------------------------------
+    // Check if there is any patch that still must be installed
+    //--------------------------------------------
+    
+    while(i < temp_num_patch)
+    {
+      if(l1_is_patch_already_installed(temp_patch_array[i]) == FALSE)
+      {
+        l1a.dyn_dwnld.next_patch_id[num_of_patch_id_to_dwnld++] = temp_patch_array[i];
+      }
+      i++;
+    }
+
+    //--------------------------
+    // Manage patch incompatibilities
+    //--------------------------
+    
+    // if there's at least one patch that must be installed
+    if(num_of_patch_id_to_dwnld!=0)
+    {
+      return_flag = TRUE;
+      // Check if already installed patches are compatible or not and retrieve number of patches to uninstall and their ids
+      if(l1_manage_patch_incompatibilty(num_of_patch_id_to_dwnld,&(num_of_uninstall_elem),patch_id_uninstall_vect))
+      {
+        // Set L1A-API HISR variable: no elements to uninstall
+        l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem=0;
+
+        // Trace number of elements to uninstall 
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+        if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+        {
+          char string[18];
+          sprintf(string,"No UNINSTALL: \r\n");
+#if(CODE_VERSION == SIMULATION)
+          trace_fct_simu_dyn_dwnld(string);
+#else
+          rvt_send_trace_cpy((T_RVT_BUFFER)string,trace_info.l1_trace_user_id,strlen(string),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+        }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+    }
+    else
+    {
+      UWORD16 element,j,index_counter;
+             
+      // Set uninstall elements number and their address 
+      l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem=num_of_uninstall_elem;
+
+      // Trace number of elements to uninstall
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+      if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+      {
+        char str[20];
+        sprintf(str,"UNINST_NUM: %d |\r\n", l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem);
+#if(CODE_VERSION == SIMULATION)
+        trace_fct_simu_dyn_dwnld(str);
+#else
+        rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+      }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+      // For all patches to uninstall...
+      for(i=0;i<num_of_uninstall_elem;i++)
+      {  
+        element=patch_id_uninstall_vect[i]; 
+
+        // Trace IDs of elements to uninstall
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+        if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+        {
+          char str[16];
+          sprintf(str,"UNINST_ID: %d \r\n", element);
+#if(CODE_VERSION == SIMULATION)
+          trace_fct_simu_dyn_dwnld(str);
+#else
+          rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+        }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+        // Set uninstall function address 
+        l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[i]=dyn_dwnld_address_vect[element];
+      }
+
+      index_counter = 0;
+      for(i=0; i<l1a.dyn_dwnld.num_patches_installed;i++)
+      {
+        for(j=0;j<num_of_uninstall_elem;j++)
+        {
+          if(l1a.dyn_dwnld.patch_id[i] == patch_id_uninstall_vect[j])
+          {
+            l1a.dyn_dwnld.patch_id[i] = 0xFFFF; //omaps00090550 ;
+            break;
+          }  
+        }
+        if(j == num_of_uninstall_elem)
+        {
+          temp_patch_id[index_counter++]=l1a.dyn_dwnld.patch_id[i];
+        }
+      }
+      // Reset global variables used by dynamic download
+      l1a.dyn_dwnld.num_patches_installed-=num_of_uninstall_elem;
+      for(i=0;i<l1a.dyn_dwnld.num_patches_installed;i++)
+        l1a.dyn_dwnld.patch_id[i] = temp_patch_id[i];
+    }
+
+   //-----------------------------------------
+   // Update L1A-L1APIHISR communication structure
+   //-----------------------------------------
+   
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem=num_of_patch_id_to_dwnld; 
+    l1a.dyn_dwnld.num_of_elem_to_copy = num_of_patch_id_to_dwnld;
+     
+    // Trace number of elements to download
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+    if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+    {
+      char str[18];
+      sprintf(str,"DWNLD_NUM: %d \r\n", num_of_patch_id_to_dwnld);
+#if(CODE_VERSION == SIMULATION)
+      trace_fct_simu_dyn_dwnld(str);
+#else
+      rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+    }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+    // For all patches that must be downloaded...
+    for (i=0;i<num_of_patch_id_to_dwnld;i++)
+    {
+      patch_id=l1a.dyn_dwnld.next_patch_id[i];
+
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+      if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+      {
+        char str[22];
+        sprintf(str,"DWNLD_ID: %d \r\n", patch_id);
+
+#if(CODE_VERSION == SIMULATION)
+        trace_fct_simu_dyn_dwnld(str);
+#else
+        rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+      }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+      // Set patch IDs addresses: copy source address and install address             
+      l1a_apihisr_com.dyn_dwnld.copy_parameters.start_MCU_copy_address[i] =
+	  (UWORD32) dyn_dwnld_copy_MCU_vect[patch_id];
+      l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[i] =
+	  dyn_dwnld_address_vect[patch_id];     
+      l1a_apihisr_com.dyn_dwnld.copy_parameters.crc[i] =
+	  dyn_dwnld_crc_vect[patch_id];
+      l1a_apihisr_com.dyn_dwnld.copy_parameters.size_array[i] =
+	  size_vect[patch_id];
+    }
+
+   //-----------------------------------------
+   // Set semaphores to lock involved state machines
+   //-----------------------------------------
+
+    if(delay_flag == FALSE)
+      // Tell other state machines that they have to stay in steady state waiting for dynamic download activity to be completed
+
+      l1_set_semaphores_for_all_state_machines_involved(num_of_patch_id_to_dwnld,l1a.dyn_dwnld.next_patch_id);
+    else
+
+      // Update the already set semaphores if it is the case
+
+      l1_update_semaphores_for_all_state_machines(num_of_patch_id_to_dwnld);
+    }
+  }
+  return return_flag;
+}
+
+/*----------------------------------------------------------------------------------------*/
+/* l1a_dyn_dwnld_set_process                                                              */
+/*----------------------------------------------------------------------------------------*/
+/*                                                                                        */
+/* Parameters : Signal Code of the message, delay flag                                    */
+/*                                                                                        */
+/* Return     : True if the primitives triggers a dynamic download and sets all the       */
+/*              parameters to perform a dynamic download, false otherwise                 */
+/*                                                                                        */
+/* Description :  Implements the dynamic download manager algorithm                       */
+/*                                                                                        */
+/*                                                                                        */
+/*----------------------------------------------------------------------------------------*/
+void l1a_dyn_dwnld_set_process(void)
+{
+
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4))
+  // Disable trace DSP upon Dynamic Download activation
+  l1_disable_dsp_trace();
+#endif
+          
+  // Reset API variables
+  l1_dyn_dwnld_reset_api();
+
+  // In case E2 is running, dynamic download must use a different area as E2 samples use trace DSP buffer
+  // area which is used as well for dynamic download
+
+  if ((l1a.dyn_dwnld.melody0_E2_flag_activated == TRUE) || (l1a.dyn_dwnld.melody1_E2_flag_activated == TRUE))
+
+  // Set download parameters: size and start download address of API area and number of patches to download
+  {
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area= START_API_DWNLD_AREA_DURING_E2;
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area= SIZE_API_DWNLD_AREA_DURING_E2;
+  }
+  else
+  {
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area=START_API_DWNLD_AREA;
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area=SIZE_API_DWNLD_AREA;
+  }
+
+  // Dynamic download HISR can be activated
+  l1_apihisr.dyn_dwnld.running=TRUE;
+
+  // Tell the L1S to start the DSP background task
+  l1a_l1s_com.dyn_dwnld_task.start=TRUE;
+}
+
+
+/*-------------------------------------------------------*/
+/* l1a_dyn_dsp_dwnld_process()                           */
+/*-------------------------------------------------------*/
+/*                                                       */
+/* Description:                                          */
+/* ------------                                          */
+/* This function is a state machine which handles the    */
+/* dynamic download feature.                             */
+/*                                                       */
+/* Starting messages:                                    */
+/*                                                       */
+/* Result messages (input):                              */
+/*                                                       */
+/*                                                       */
+/* Result messages (output):                             */
+/*                                                       */
+/* Reset messages (input):   none                        */
+/*                                                       */
+/* Stop message (input):                                 */
+/*                                                       */
+/* Stop message (output):                                */
+/*                                                       */
+/* Rem:                                                  */
+/* ----                                                  */
+/*                                                       */
+/*-------------------------------------------------------*/
+
+void l1a_dyn_dsp_dwnld_process(xSignalHeaderRec *msg)
+{
+  enum states
+  {
+    RESET=0,
+    WAIT_INIT,
+    WAIT_RESULT,
+    WAIT_STOP
+  };
+
+  UWORD8  *state    =&l1a.dyn_dwnld.state;
+  UWORD32 SignalCode=msg->SignalCode;
+  UWORD16 i;
+  UWORD16 delay_patch_array[MAX_NUM_OF_PATCH_IDS];
+  UWORD16 delay_num_patch;
+  UWORD32 delay_primitive;
+
+  while(1)
+  {
+    switch(*state)
+    {
+      // *********
+      // * RESET *
+      // *********
+      case RESET:
+      {
+        // Reset intra L1 variables: L1A-L1S interface, L1A-API interface, global API HISR variables
+        l1_dyn_dwnld_reset();
+
+        // Change state
+        *state = WAIT_INIT;
+      }
+      break;
+
+      // ******************
+      // * WAIT START REQ *
+      // ******************
+      case WAIT_INIT:
+      {
+        
+        // *----------------------------*
+        // * Dynamic download manager   *
+        // *----------------------------*
+
+        
+        /* Run the dynamic download manager */
+        if (l1_dynamic_download_manager(SignalCode, FALSE) == TRUE)
+        {
+         
+          /* Initialisation of dynamic download process */
+          l1a_dyn_dwnld_set_process();
+         
+          // Change state
+          *state=WAIT_RESULT;
+
+        }
+        return;
+      }
+//omaps00090550      break;
+
+      // ***************
+      // * WAIT_RESULT *
+      // ***************
+
+      case WAIT_RESULT:
+      {
+        if (l1_does_the_incoming_primitive_trigger_dynamic_dwnld(SignalCode,TRUE) == TRUE)
+        {
+          if (l1_push_Primitive(SignalCode) == TRUE)
+          {
+            delay_num_patch = l1_lookup_primitive_patch_matrix(SignalCode,delay_patch_array);
+
+            // Tell other state machines that they have to stay in steady state waiting for dynamic download activity to be completed
+            l1_set_semaphores_for_all_state_machines_involved(delay_num_patch, delay_patch_array);
+          }
+          else
+          {
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+            if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+            {
+              char str[16];
+              sprintf(str,"Fifo ovflw:\r\n");
+#if(CODE_VERSION == SIMULATION)
+              trace_fct_simu_dyn_dwnld(str);
+#else
+              rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+            }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+          }
+        }
+        switch(SignalCode)
+        {
+
+          // *----------------------------------------------------------------------------------*
+          // * CRC reported is not OK or an error has been reported; Restart patch from scratch *
+          // *----------------------------------------------------------------------------------*
+          case API_L1_CRC_NOT_OK:
+          {
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+            // Trace 
+            if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+            {
+              char str[18];
+              sprintf(str,"CRC NOK: %4x \r\n",((T_API_L1_CRC_NOT_OK *)(msg->SigP))->patch_id);
+#if(CODE_VERSION == SIMULATION)
+              trace_fct_simu_dyn_dwnld(str);
+#else
+              rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+            }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+            // Set recovery flag to TRUE;
+            l1a_l1s_com.recovery_flag = TRUE;
+            *state = RESET;
+          }
+          break;
+          case API_L1_DYN_DWNLD_STOP:
+          {
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+            if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+            {
+              char str[15];
+              sprintf(str,"DSP Error \r\n");
+#if(CODE_VERSION == SIMULATION)
+              trace_fct_simu_dyn_dwnld(str);
+#else
+              rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+            }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+
+            // Set recovery flag to TRUE;
+            l1a_l1s_com.recovery_flag = TRUE;
+            *state = RESET;
+          }
+          break;
+
+          // *-------------------------------------------------------------*
+          // * Dynamic download finished: all patches have been downloaded *
+          // *-------------------------------------------------------------*
+          case API_L1_CRC_OK:
+          {
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+            // Trace 
+            if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+            {
+              char str[18];
+              sprintf(str,"CRC OK: %4x \r\n",((T_API_L1_CRC_NOT_OK *)(msg->SigP))->patch_id);
+#if(CODE_VERSION == SIMULATION)
+              trace_fct_simu_dyn_dwnld(str);
+#else
+              rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+            }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+          }
+          break;
+          case API_L1_DYN_DWNLD_FINISHED:
+          {
+
+            // Store currently installed patch
+            for (i=0;i<l1a.dyn_dwnld.num_of_elem_to_copy;i++)
+            {
+              l1a.dyn_dwnld.patch_id[l1a.dyn_dwnld.num_patches_installed+i]=l1a.dyn_dwnld.next_patch_id[i];
+            }
+
+            // Update the counter of the patch currently installed and reset sempahores
+            l1a.dyn_dwnld.num_patches_installed+=l1a.dyn_dwnld.num_of_elem_to_copy;
+            l1_reset_semaphores();
+
+            // Reset number of element to copy in the next phase
+            l1a.dyn_dwnld.num_of_elem_to_copy = 0;
+
+            // Reset next patch ID global variables
+            for(i=0;i<MAX_NUM_OF_PATCH_IDS;i++)
+              l1a.dyn_dwnld.next_patch_id[i] = 0xFFFF; //omaps00090550 ;
+            
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4) || (TRACE_TYPE == 5))
+            // Trace 
+            if((trace_info.current_config->l1_dyn_trace) & (1<<L1_DYN_TRACE_DYN_DWNLD))
+            {
+              char str[26];
+              sprintf(str,"Patch dwnld finished \r\n");
+#if(CODE_VERSION == SIMULATION)
+              trace_fct_simu_dyn_dwnld(str);
+#else
+              rvt_send_trace_cpy((T_RVT_BUFFER)str,trace_info.l1_trace_user_id,strlen(str),RVT_ASCII_FORMAT);
+#endif // CODE_VERSION == SIMULATION
+            }
+#endif    // (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
+            
+            //  Check if there is any pending primitive waiting to be de-queued
+            {
+              UWORD32 remaining_primitive_flag=0;
+              UWORD32 process_continue_flag=1;
+              UWORD32 delay_primitive_processed_flag=0;
+              
+              remaining_primitive_flag = (l1_check_Fifo_Primitive()>0);
+
+              while(remaining_primitive_flag && process_continue_flag)
+              {
+                l1_pop_Primitive(&(delay_primitive));
+                if (l1_dynamic_download_manager(delay_primitive, TRUE) == TRUE)
+                {
+                  process_continue_flag=0;                  
+                  delay_primitive_processed_flag=1;
+                  // If yes set the restart command at apihisr level
+                  l1a_apihisr_com.dyn_dwnld.command.restart = TRUE;
+
+                  /********** WORKAROUND *************/
+#if (OP_RIV_AUDIO == 1)
+                  {
+                    // WARNING: temporary until os_activate_hisr() is declared in L3 functions
+                    extern NU_HISR apiHISR;
+                    NU_Activate_HISR(&apiHISR);
+                  }
+#else
+                  os_activate_hisr(API_HISR);
+#endif // OP_RIV_AUDIO == 1         
+                  /********** WORKAROUND *************/
+                  *state = WAIT_RESULT;
+                }
+                remaining_primitive_flag = (l1_check_Fifo_Primitive()>0);
+              }
+
+              // else stop the DSP background task as no other patch must be downloaded
+              if(delay_primitive_processed_flag == 0)
+              {
+#if ((TRACE_TYPE == 1) || (TRACE_TYPE == 4))
+                // Enable trace DSP upon Dynamic Download deactivation
+                l1_enable_dsp_trace();
+                //Trace_dsp_dump();
+#endif  // omaps00090550 #14-D removal
+                l1a_l1s_com.dyn_dwnld_task.stop=TRUE;
+                *state = WAIT_STOP;
+              }
+            }
+          }
+          break;
+        }  // switch(SignalCode)
+        return;
+      }
+//omaps00090550      break;  // case WAIT_RESULT
+      case WAIT_STOP:
+      {
+        /* In case of a primitive which triggers a dynamic download arrives we must start over */
+	if (l1_does_the_incoming_primitive_trigger_dynamic_dwnld(SignalCode,TRUE) == TRUE)
+	{
+          /* Run the dynamic download manager */
+          if (l1_dynamic_download_manager(SignalCode, FALSE) == TRUE)
+	  {
+            /* Initialisation of dynamic download process */
+            l1a_dyn_dwnld_set_process();
+
+            // Change state
+            *state=WAIT_RESULT;
+	  }
+	}
+	else if (SignalCode == L1_DYN_DWNLD_STOP_CON)
+	{
+          // DYN DWNLD HISR must be deactivated
+          l1_apihisr.dyn_dwnld.running=FALSE;
+          // Change state
+          *state=RESET;	
+	} 		
+	return;		
+      }
+//omaps00090550      break;
+    }
+  }
+}
+#endif    // L1_DYN_DSP_DWNLD
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_func.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,392 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_FUNC.C
+ *
+ *        Filename l1_dyn_dwl_func.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+
+#include <stdio.h>
+#include <string.h>
+#include "l1_confg.h"
+#include "l1_types.h"
+#include "l1_const.h"        
+#include "l1_signa.h"     
+#include "sys_types.h"
+
+#if(L1_DYN_DSP_DWNLD == 1)
+#include "l1_dyn_dwl_const.h"
+#include "l1_dyn_dwl_proto.h"
+#include "l1_dyn_dwl_defty.h"
+#endif
+#if TESTMODE
+  #include "l1tm_defty.h"
+#endif
+#if (AUDIO_TASK == 1)
+  #include "l1audio_const.h"
+  #include "l1audio_cust.h"
+  #include "l1audio_defty.h"
+#endif
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+#endif
+#if (L1_MP3 == 1)
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+
+ #include "l1_defty.h"
+ #include "l1_varex.h"
+ #include "l1_macro.h"
+
+#if (L1_DYN_DSP_DWNLD == 1)
+  #ifndef NULL
+#define NULL 0
+  #endif
+
+  extern T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb;
+  #if (CODE_VERSION == SIMULATION)
+    extern T_DYN_DWNLD_MCU_DSP dyn_dwl_ndb_sim;
+  extern UWORD16 dwnld_area_array[SIZE_DWNLD_AREA_SIMU];
+#endif // CODE_VERSION == SIMULATION
+
+
+/*---------------------------------------------------------------------------- */
+/* l1_initialize_patch_parameters                                              */
+/*-------------------------------------------------------------------------    */
+/*                                                                             */
+/* Parameters :                                                                */
+/*                                                                             */
+/* Return     :    size of the patch                                           */
+/*                                                                             */
+/* Description :  Initialize patch parameters and returns the size of the patch*/
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+ 
+UWORD16 l1_initialize_patch_parameters(void)
+{
+  UWORD16 patch_size = 0;
+
+  /* Initialize download patch parameters */
+  l1_apihisr.dyn_dwnld.running_source_pointer = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_MCU_copy_address[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter];
+  patch_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_array[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter];
+  dyn_dwl_ndb->d_api_dwl_crc = 0x0; 
+  return patch_size;
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_set_uninstall_parameters                                                 */
+/*-------------------------------------------------------------------------    */
+/*                                                                             */
+/* Parameters : void                                                           */
+/*                                                                             */
+/* Return     :    void                                                        */
+/*                                                                             */
+/* Description :  Set uninstall parameters                                     */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+ 
+void l1_set_uninstall_parameters(void)
+{
+  /* Set next uninstall adress (pointer incremented) */
+  dyn_dwl_ndb->d_api_dwl_function_address[0] = (API) (l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem - l1_apihisr.dyn_dwnld.uninstall_counter] & 0x0000FFFF); 
+  dyn_dwl_ndb->d_api_dwl_function_address[1] = (API) ((l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem - l1_apihisr.dyn_dwnld.uninstall_counter] >> 16) & 0x0000FFFF); 
+
+  /* Set uninstall command */
+  dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_UNINSTALL;   
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_initialize_pointers_for_copy                                             */
+/*-------------------------------------------------------------------------    */
+/*                                                                             */
+/* Parameters :   address of source and destination pointer                    */
+/*                                                                             */
+/* Return     :   source and destination address modified by reference         */
+/*                                                                             */
+/* Description :  Initialize the pointers for the copy                         */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+void l1_initialize_pointers_for_copy(UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu)
+{
+  /* BEGIN: Initialize download area parameters at start download area */
+  dyn_dwl_ndb->d_api_dwl_write_pointer = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area - 1; // correction
+    
+  /* Initialize pointers */
+#if (CODE_VERSION == SIMULATION)
+  *pp_dest_mcu = (UWORD16 *) dwnld_area_array;
+#else
+  *pp_dest_mcu = (UWORD16 *) API_address_dsp2mcu(l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area);
+#endif // CODE_VERSION == SIMULATION
+
+  *pp_src_mcu  = (UWORD16 *) l1_apihisr.dyn_dwnld.running_source_pointer;   
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_copy_till_the_end_of_the_patch_and_update_write_pointer                  */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : size of the patch, source and destination pointer              */
+/*                                                                             */
+/* Return     : none                                                           */
+/*                                                                             */
+/* Description : Copy until the end of the patch is reached                    */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+void l1_copy_till_the_end_of_the_patch_and_update_write_pointer(UWORD16 tmp_patch_size, UWORD16* p_dest_mcu, UWORD16* p_src_mcu)
+{
+  while (tmp_patch_size > NUM_WORDS_COPY_API)
+  {
+    l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16));
+    p_dest_mcu += NUM_WORDS_COPY_API;
+    p_src_mcu  += NUM_WORDS_COPY_API;
+    tmp_patch_size -= NUM_WORDS_COPY_API;
+    dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API;
+  }
+  if (tmp_patch_size != 0)
+  {  
+    l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_patch_size*sizeof(UWORD16));
+    dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_patch_size;
+  }
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_copy_till_end_of_dwnld_area_and_update_write_pointer                     */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : address of size of the patch, size of download area,           */
+/*              addresses of source pointer, destination pointer               */
+/*                                                                             */
+/* Return     : source pointer and size modified by reference                  */
+/*                                                                             */
+/* Description : Copy until the end of download area is reached                */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+void l1_copy_till_end_of_dwnld_area_and_update_write_pointer(UWORD16 tmp_dwnld_area_size,UWORD16 *p_dest_mcu, UWORD16 *p_tmp_patch_size, UWORD16 **pp_src_mcu)
+{
+  UWORD16 tmp_patch_size = *p_tmp_patch_size;
+  UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu;
+
+  while (tmp_dwnld_area_size > NUM_WORDS_COPY_API)
+  {
+    l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16));
+    p_dest_mcu += NUM_WORDS_COPY_API;
+    p_src_mcu  += NUM_WORDS_COPY_API;
+    tmp_patch_size      -= NUM_WORDS_COPY_API;
+    tmp_dwnld_area_size -= NUM_WORDS_COPY_API;
+    dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API;
+  }
+
+  if (tmp_dwnld_area_size > 0)
+  {
+    l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_dwnld_area_size*sizeof(UWORD16));
+    p_src_mcu += tmp_dwnld_area_size;  
+    tmp_patch_size -= tmp_dwnld_area_size;
+    dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_dwnld_area_size;
+  }
+  *pp_src_mcu = (UWORD16 *) p_src_mcu;
+  *p_tmp_patch_size = tmp_patch_size;
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_copy_first_N_words                                                       */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : address of size of the patch, address of size of download area,*/
+/*              addresses of source pointer, address of destination pointer    */
+/*                                                                             */
+/* Return     : source and  destination  pointer modified by reference         */
+/*              size of download area and patch area modified by reference     */
+/*                                                                             */
+/* Description : Copy the min(N, remaining size of the patch) at the beginning */
+/*               download area                                                 */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+BOOL l1_copy_first_N_words (UWORD16 *dwnld_area_size_p, UWORD16 *patch_area_size_p, UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu)
+{
+  BOOL    return_flag;
+  UWORD16 num_words_interrupt;
+  UWORD16 tmp_patch_size = *patch_area_size_p;
+  UWORD16 tmp_dwnld_area_size = *dwnld_area_size_p;
+  UWORD16 *p_dest_mcu =(UWORD16 *)*pp_dest_mcu;
+  UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu;
+
+  /* Copy first N words and generate API interrupt*/
+  if (tmp_patch_size > NUM_WORDS_COPY_API)
+  {  
+    num_words_interrupt = NUM_WORDS_COPY_API;
+    return_flag = TRUE;
+  }
+  else
+  {
+    num_words_interrupt = tmp_patch_size;
+    return_flag = FALSE;
+  }
+
+  l1_memcpy_16bit(p_dest_mcu,p_src_mcu, num_words_interrupt*sizeof(UWORD16));
+
+  p_dest_mcu += num_words_interrupt;
+  p_src_mcu  += num_words_interrupt;
+
+  tmp_patch_size      -= num_words_interrupt;
+  tmp_dwnld_area_size -= num_words_interrupt;
+  
+  dyn_dwl_ndb->d_api_dwl_write_pointer+=num_words_interrupt;
+  
+  *patch_area_size_p = tmp_patch_size;
+  *dwnld_area_size_p = tmp_dwnld_area_size;
+  *pp_dest_mcu       = (UWORD16 *)p_dest_mcu;
+  *pp_src_mcu        = (UWORD16 *)p_src_mcu ;
+  
+  return return_flag;
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_initialize_download_area_parameters                                      */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : none                                                           */
+/*                                                                             */
+/*                                                                             */
+/* Return     : download area size                                             */
+/*                                                                             */
+/* Description : Initialize download area: all the parameters                  */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+UWORD16 l1_initialize_download_area_parameters(void)
+{
+  UWORD16 dwnld_area_size = 0;
+
+  /* Set download address and size in API-DSP com */
+  dyn_dwl_ndb->d_api_dwl_function_address[0] = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area;
+  dyn_dwl_ndb->d_api_dwl_function_address[1] = 0x0;      
+
+#if (CODE_VERSION == SIMULATION)
+  dyn_dwl_ndb->d_api_dwl_size = SIZE_DWNLD_AREA_SIMU;
+#else
+  dyn_dwl_ndb->d_api_dwl_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area;
+#endif  // CODE_VERSION == SIMULATION
+
+  dwnld_area_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area;
+  return dwnld_area_size;
+}
+
+/*---------------------------------------------------------------------------- */
+/* l1_init_pointers_and_copy_first_block_of_data                               */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : address of size of the patch, address of size of download area,*/
+/*              addresses of source pointer, address of destination pointer    */
+/*              new patch flag                                                 */
+/* Return     : TRUE if N< size of patch, FALSE otherwise                      */
+/*              source and  destination  pointer modified by reference         */
+/*              size of download area and patch area modified by reference,    */
+/*                                                                             */
+/* Description : Initialize pointers and starts the copy.                      */
+/*                                                                             */
+/*                                                                             */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+BOOL l1_init_pointers_and_copy_first_block_of_data(UWORD16 *dwnld_area_size_p, UWORD16 *patch_size_p, UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu, BOOL new_patch)
+{
+  BOOL return_flag;
+
+  /* Initialize download area*/
+  *dwnld_area_size_p = l1_initialize_download_area_parameters();
+
+  /* In case this is a new patch, initialize patch parameters*/
+  if (new_patch == TRUE)
+    *patch_size_p = l1_initialize_patch_parameters();
+
+  /* Initialize pointers for the copy*/
+  l1_initialize_pointers_for_copy(pp_dest_mcu, pp_src_mcu);
+
+  /* If this is a new patch, the header of the patch must be taken off from the copy*/
+  if (new_patch == TRUE)
+  {
+    /* Take the initial header off */
+    *pp_src_mcu= (*pp_src_mcu)+HEADER_PATCH_SIZE;
+    *patch_size_p= (*patch_size_p)-HEADER_PATCH_SIZE;
+  }
+    
+  /* Copy first N words; if remaining size of the patch is smaller than N copy until the end of the patch */
+  /* In this case, return FALSE as there are no more words to be copied*/
+  return_flag = l1_copy_first_N_words (dwnld_area_size_p, patch_size_p, pp_dest_mcu, pp_src_mcu);
+    
+  return return_flag;
+}
+
+
+/*---------------------------------------------------------------------------- */
+/* l1_set_dyn_dwnld_install_vect                                               */
+/*---------------------------------------------------------------------------- */
+/*                                                                             */
+/* Parameters : size vector, destination address vector, crc vector            */
+/*              patch code vector, identifier i of the patch                   */
+/*              new patch flag                                                 */
+/* Return     : TRUE operation is successful, FALSE otherwise                  */
+/*                                                                             */
+/* Description : Compute address, size and crc of i-th patch                   */
+/*                                                                             */
+/*---------------------------------------------------------------------------- */
+
+BOOL l1_set_dyn_dwnld_install_vect(UWORD16* size_p, UWORD32* dest_addr, UWORD16* crc_vect, const UWORD8 *patch_array_code, UWORD16 i)
+{
+  UWORD16 full_size_32_bit, size, size_ext, dsp_addr, dsp_addr_ext, crc_value;
+  UWORD16 *codePtr;
+  UWORD16 size_total = 0;
+  BOOL status_flag = FALSE;
+  codePtr = (UWORD16 *) patch_array_code;
+  
+  if ( (0 == *codePtr++) && (0 == *codePtr++)) 
+  {  // NULL TAG detection
+    if ( (3 == *codePtr++) && (0 == *codePtr++)) 
+    {   // coff2c version number detection
+      size = *codePtr++;
+      size_ext        = *codePtr++; 
+   
+      // first header:4
+      size_total+=HEADER_PATCH_SIZE; 
+      while(size != 0 || size_ext != 0)
+      {    
+        full_size_32_bit = (size_ext << 16) + size;
+        // reconstruction of the total 32-bit size of the section
+        size_total+=HEADER_PATCH_SIZE+full_size_32_bit+1;
+        // Header + size_block + cntrl_word(0xDEAD):1
+        codePtr+=full_size_32_bit+2+1; 
+        // Two words for address and one for the cntrl word 0xDEAD
+        size = *codePtr++;
+        size_ext = *codePtr++;
+      }
+      size_total+=HEADER_PATCH_SIZE;
+      // Last header to consider
+
+      dsp_addr = *codePtr++;
+      dsp_addr_ext = *codePtr++;
+      crc_value = *codePtr++;
+      dest_addr[i] = (dsp_addr_ext << 16)+dsp_addr;
+      crc_vect[i] = crc_value;
+      size_p[i] = size_total;
+      status_flag = TRUE;
+    }
+  }
+  return status_flag;
+}
+#endif //L1_DYN_DSP_DWNLD == 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_init.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,277 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_INIT.C
+ *
+ *        Filename l1_dyn_dwl_init.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+#include "nucleus.h"
+#include "l1_confg.h"
+#include "sys_types.h"
+#include "l1_types.h"
+#include "l1audio_const.h"
+#include "l1audio_cust.h"
+#include "l1audio_defty.h"
+#include "l1_const.h"
+#include "l1tm_defty.h"
+
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+#endif
+#if (L1_DYN_DSP_DWNLD == 1)
+ #include "l1_dyn_dwl_const.h"
+ #include "l1_dyn_dwl_defty.h"
+ #include "l1_dyn_dwl_proto.h"
+#endif
+
+#if (L1_MP3 == 1)
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+#if (L1_AAC == 1)
+  #include "l1aac_defty.h"
+#endif //L1_AAC
+
+#include "l1_defty.h"
+#include "cust_os.h"
+/* #include "nu_main.h" */
+#include "l1audio_signa.h"
+#include "l1_varex.h"
+#include "l1_macro.h"
+#include "l1_trace.h"
+
+#if (L1_DYN_DSP_DWNLD == 1)
+extern T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb;
+
+/* reconstructing from disassembly of TCS211 binary object */
+
+/* patch ID mapping:
+   0 = GPRS
+   1 = AMR_SCH
+   2 = TTY
+   3 = AMR_MMS
+   4 = E2
+*/
+
+const BOOL  primitives_to_patch_matrix[NUM_OF_DYN_DWNLD_PRIMITIVES][MAX_NUM_OF_PATCH_IDS] = {
+
+/* L1C_STOP_DEDICATED_DONE			*/	{1, 0, 0, 0, 0},
+/* MMI_GTT_START_REQ (?)			*/	{0, 0, 1, 0, 0},
+/* MPHC_IMMED_ASSIGN_REQ			*/	{0, 1, 0, 0, 0},
+/* MMI_MELODY0_E2_START_REQ			*/	{0, 0, 0, 0, 1},
+/* MMI_MELODY1_E2_START_REQ			*/	{0, 0, 0, 0, 1},
+/* L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON	*/	{0, 0, 0, 1, 0}
+
+};
+  
+const BOOL incompatibility_matrix[MAX_NUM_OF_PATCH_IDS][MAX_NUM_OF_PATCH_IDS] ={
+	{0, 1, 1, 0, 0},
+	{1, 0, 0, 0, 0},
+	{0, 0, 0, 1, 1},
+	{0, 0, 1, 0, 1},
+	{0, 0, 1, 1, 0},
+};
+
+const BOOL semaphore_matrix[MAX_NUM_OF_PATCH_IDS][MAX_NUM_OF_SEMAPHORES] = {
+	{0, 0, 0, 0, 0, 1},
+	{1, 0, 0, 0, 0, 1},
+	{0, 1, 0, 0, 0, 1},
+	{0, 0, 0, 1, 1, 1},
+	{0, 0, 1, 0, 0, 1},
+};
+
+UWORD32 dyn_dwnld_address_vect[MAX_NUM_OF_PATCH_IDS];
+UWORD16 dyn_dwnld_crc_vect[MAX_NUM_OF_PATCH_IDS];
+UWORD16 size_vect[MAX_NUM_OF_PATCH_IDS];
+
+UWORD8 const *dyn_dwnld_copy_MCU_vect[MAX_NUM_OF_PATCH_IDS];
+
+extern const UWORD8 amr_mms_patch_array[];
+extern const UWORD8 amr_sch_patch_array[];
+extern const UWORD8 e2_patch_array[];
+extern const UWORD8 gprs_patch_array[];
+extern const UWORD8 speech_acoustic_patch_array[];
+extern const UWORD8 tty_patch_array[];
+
+/*-------------------------------------------------------*/
+/* l1_dyn_dwnld_initialize_var()                         */
+/*-------------------------------------------------------*/
+/* Parameters : none                                     */
+/* Return     : nothing                                  */
+/* Functionality : Initialize Dynamic Download variables */
+/*                                                       */
+/*-------------------------------------------------------*/
+
+void l1_dyn_dwnld_initialize_var()
+{
+  UWORD16 i;
+  
+
+  /* Init Dynamic Download NDB */
+  dyn_dwl_ndb=(T_DYN_DWNLD_MCU_DSP *)API_address_dsp2mcu(C_DYN_DWNLD_API_BASE_ADDRESS);
+#if (CODE_VERSION == SIMULATION)
+  {
+    extern T_DYN_DWNLD_MCU_DSP dyn_dwl_ndb_sim;
+    dyn_dwl_ndb=&dyn_dwl_ndb_sim;
+  }
+#endif // CODE_VERSION == SIMULATION
+
+  /* Init Dynamic Download DSP background */
+  l1s_dsp_com.dsp_ndb_ptr->a_background_tasks[C_BGD_DSP_DYN_DWNLD] = (API)((C_BGD_DSP_DYN_DWNLD<<11) | 0);
+  l1s_dsp_com.dsp_ndb_ptr->d_background_enable&=(API)(~(1<<C_BGD_DSP_DYN_DWNLD));
+
+  if(l1s_dsp_com.dsp_ndb_ptr->d_max_background<(C_BGD_DSP_DYN_DWNLD+1))
+    l1s_dsp_com.dsp_ndb_ptr->d_max_background=(API)(C_BGD_DSP_DYN_DWNLD+1);
+
+  dyn_dwnld_copy_MCU_vect[0] = gprs_patch_array;
+  dyn_dwnld_copy_MCU_vect[1] = amr_sch_patch_array;
+  #if (L1_GTT == 1)
+    dyn_dwnld_copy_MCU_vect[2] = tty_patch_array;
+  #endif
+  #if (MELODY_E2 == 1)
+    dyn_dwnld_copy_MCU_vect[3] = amr_mms_patch_array;
+    dyn_dwnld_copy_MCU_vect[4] = e2_patch_array;
+  #endif
+
+  for(i=0;i<MAX_NUM_OF_PATCH_IDS;i++)
+  {
+    if (dyn_dwnld_copy_MCU_vect[i] != 0)
+    {
+      l1_set_dyn_dwnld_install_vect(size_vect,dyn_dwnld_address_vect,dyn_dwnld_crc_vect,dyn_dwnld_copy_MCU_vect[i],i);
+    }
+  }
+
+  /*---------- Set L1A globals at phone init ----------------------------*/
+  l1a.dyn_dwnld.melody0_E2_flag_activated = FALSE;
+  l1a.dyn_dwnld.melody1_E2_flag_activated = FALSE;
+  l1a.dyn_dwnld.state                     = 0;
+  
+
+  l1a.dyn_dwnld.num_patches_installed     = 0;  
+
+  l1a.dyn_dwnld.patch_id[0] = 0xFFFF; //omaps00090550
+
+  /**************************************************/
+
+  // Compute number of current primitives defined via compilation switch
+  l1a.dyn_dwnld.num_of_primitives = 2;
+  #if (L1_GTT == 1)
+    l1a.dyn_dwnld.num_of_primitives++;
+  #endif // L1_GTT
+  #if (MELODY_E2 == 1)
+    // Two primitives for MELODY E2
+    // FreeCalypso: apparently there are 3 in TCS211
+    l1a.dyn_dwnld.num_of_primitives += 3;
+  #endif // MELODY_E2
+
+  for (i=l1a.dyn_dwnld.num_patches_installed;i<MAX_NUM_OF_PATCH_IDS;i++)
+  {  
+    l1a.dyn_dwnld.patch_id[i]      = 0xFFFF; //omaps00090550 ;
+    l1a.dyn_dwnld.next_patch_id[i] = 0xFFFF; //omaps00090550 ;
+  }
+  for (i=0;i<MAX_NUM_OF_SEMAPHORES;i++)
+     l1a.dyn_dwnld.semaphore_vect[i] = GREEN;
+
+   
+    l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = 0;
+    for (i=0;i<MAX_NUM_OF_PATCH_IDS;i++)
+      l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[i] = 0;
+  
+  /*---------------------------------------------------------------------*/
+
+  /*---------- Set L1S globals at phone init ----------------------------*/
+  
+  l1s.dyn_dwnld_state=0;
+  
+  /*---------------------------------------------------------------------*/
+
+
+  /* Set API ACCESS bit to 16 bits mode */
+  /* Bit 5: 0 -> 32 bits mode           */
+  /*        1 -> 16 bits mode           */
+
+#if (CODE_VERSION != SIMULATION)
+  (*(volatile UWORD16 *) 0xFFFFFB0E) |= 0x0020;
+#endif // CODE_VERSION != SIMULATION
+}
+
+/*-------------------------------------------------------*/
+/* l1_dyn_dwl_reset()                                    */
+/*                                                       */
+/*-------------------------------------------------------*/
+/* Parameters : none                                     */
+/* Return     : nothing                                  */
+/* Functionality : Reset Dynamic Download variables      */
+/*                                                       */
+/*-------------------------------------------------------*/
+
+void l1_dyn_dwnld_reset()
+{
+  UWORD8 indx_loop;
+
+  /* Reset L1A-L1S commands */
+  l1a_l1s_com.dyn_dwnld_task.start = FALSE;
+  l1a_l1s_com.dyn_dwnld_task.stop  = FALSE;
+ 
+  /* Reset L1A-API HISR commands */
+
+  l1a_apihisr_com.dyn_dwnld.command.restart = FALSE;
+  l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem = 0;
+
+  for (indx_loop = 0 ; indx_loop < MAX_NUM_OF_PATCH_IDS ; indx_loop++  )
+  {
+    l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[indx_loop]
+	= 0;
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.start_MCU_copy_address[indx_loop]
+	= 0;
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[indx_loop]
+	= 0; 
+    l1a_apihisr_com.dyn_dwnld.copy_parameters.size_array[indx_loop]
+	= 0;
+  }
+
+  l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area  = 0;
+  l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area = 0;
+  l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem         = 0;
+
+  /* Reset global API HISR variable */
+  l1_apihisr.dyn_dwnld.state                  = 0;
+  l1_apihisr.dyn_dwnld.running                = FALSE;
+  l1_apihisr.dyn_dwnld.uninstall_counter      = 0;
+  l1_apihisr.dyn_dwnld.patch_ids_counter      = 0;
+  l1_apihisr.dyn_dwnld.running_source_pointer = 0;
+  l1_apihisr.dyn_dwnld.tmp_patch_size = 0;
+  
+  /* Reset L1A global FIFO for handling the DELAY (when two or more primitives fall within a dynamic download time frame)*/
+  l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = 0;
+  for (indx_loop=0;indx_loop<MAX_NUM_OF_PATCH_IDS;indx_loop++)
+  {  
+    l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[indx_loop] = 0;
+    l1a.dyn_dwnld.next_patch_id[indx_loop] = 0xFFFF; //omaps00090550 ;
+  }
+}
+
+/*---------------------------------------------------------------------*/
+/* l1_dyn_dwnld_reset_api()                                            */
+/*---------------------------------------------------------------------*/
+/* Parameters  : none                                                  */
+/* Return         : nothing                                            */
+/* Functionality : Reset Dynamic Download API variables                */
+/*                                                                     */
+/*---------------------------------------------------------------------*/
+void l1_dyn_dwnld_reset_api()
+{
+  dyn_dwl_ndb->d_api_dwl_download_ctrl       = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_error_code          = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_function_address[0] = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_function_address[1] = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_crc                 = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_size                = (API) 0;
+  dyn_dwl_ndb->d_api_dwl_write_pointer       = (API) 0;
+}
+
+#endif  // L1_DYN_DSP_DWNLD
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_sync.c	Thu Oct 22 18:19:42 2015 +0000
@@ -0,0 +1,137 @@
+/************* Revision Controle System Header *************
+ *                  GSM Layer 1 software
+ * L1_DYN_DWL_SYNC.C
+ *
+ *        Filename l1_dyn_dwl_sync.c
+ *  Copyright 2004 (C) Texas Instruments
+ *
+ ************* Revision Controle System Header *************/
+
+#include <stdio.h>
+#include <string.h>
+
+#include "nucleus.h"
+#include "l1_confg.h"
+#include "l1_types.h"
+#include "sys_types.h"
+#include "cust_os.h"
+#include "l1audio_signa.h"
+#include "l1audio_const.h"
+#include "l1audio_cust.h"
+#include "l1audio_defty.h"
+#include "l1_const.h"
+#include "l1tm_defty.h"
+#if (L1_GTT == 1)
+  #include "l1gtt_const.h"
+  #include "l1gtt_defty.h"
+#endif
+#if (L1_DYN_DSP_DWNLD==1)
+  #include "l1_dyn_dwl_defty.h"
+  #include "l1_dyn_dwl_msgty.h"
+  #include "l1_dyn_dwl_const.h"
+  #include "l1_dyn_dwl_signa.h"
+  #include "l1_dyn_dwl_error.h"
+  #include "l1_dyn_dwl_proto.h"
+  #include "l1_api_hisr.h"
+#endif
+
+#if (L1_MP3 == 1)
+  #include "l1mp3_defty.h"
+#endif //L1_MP3
+#if (L1_MIDI == 1)
+  #include "l1midi_defty.h"
+#endif
+
+#include "l1_macro.h"
+#include "l1_defty.h"
+#include "l1_varex.h"
+#include "l1_trace.h"
+#include "sys_dma.h"
+
+#if (L1_DYN_DSP_DWNLD == 1)
+
+extern T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb;
+
+
+/*-------------------------------------------------------*/
+/* l1s_dyn_dsp_dwnld_manager()                           */
+/*-------------------------------------------------------*/
+/*                                                       */
+/* Parameters :  n/a                                     */
+/*                                                       */
+/* Return     :  n/a                                     */
+/*                                                       */
+/* Description : dsp dynamic download L1S manager task.  */
+/*                                                       */
+/*-------------------------------------------------------*/
+
+void l1s_dyn_dwnld_manager(void)
+{
+  enum states
+  {
+    WAIT_INIT = 0,
+    WAIT_RESULT,
+    WAIT_STOP
+  };
+
+  UWORD8 *state = &l1s.dyn_dwnld_state;
+  xSignalHeaderRec *conf_msg;
+  
+  switch(*state)
+  {
+    case WAIT_INIT:
+    {
+      if(l1a_l1s_com.dyn_dwnld_task.start==TRUE)
+      {
+        // make sure the DSP is able to receive API interrupt
+        // for this, we wait 1 TDMA frame
+        // change state
+        *state=WAIT_RESULT;
+      }
+    }
+    break;
+
+    case WAIT_RESULT:
+    {
+      // reset the command
+      l1a_l1s_com.dyn_dwnld_task.start=FALSE;
+      // send start background to the DSP
+      dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_INIT;
+      l1s_dsp_com.dsp_ndb_ptr->a_background_tasks[C_BGD_DSP_DYN_DWNLD] = (API)((C_BGD_DSP_DYN_DWNLD<<11) | 1);
+      l1s_dsp_com.dsp_ndb_ptr->d_background_enable|=(API)(1<<C_BGD_DSP_DYN_DWNLD);
+      l1_trigger_api_interrupt();
+
+      // change state
+      *state=WAIT_STOP;
+    }
+    break;
+
+    case WAIT_STOP:
+    {
+      if(l1a_l1s_com.dyn_dwnld_task.stop==TRUE)
+      {
+        // reset the command
+        l1a_l1s_com.dyn_dwnld_task.stop=FALSE;
+
+        // send stop background to the DSP
+        l1s_dsp_com.dsp_ndb_ptr->a_background_tasks[C_BGD_DSP_DYN_DWNLD] = (API)((C_BGD_DSP_DYN_DWNLD<<11) | 0);
+        l1s_dsp_com.dsp_ndb_ptr->d_background_enable&=(API)(~(1<<C_BGD_DSP_DYN_DWNLD));
+        l1_trigger_api_interrupt(); 
+        
+        // send confirmation to the L1A
+        conf_msg=os_alloc_sig(0);
+        DEBUGMSG(status,NU_ALLOC_ERR)
+        conf_msg->SignalCode=L1_DYN_DWNLD_STOP_CON;
+        os_send_sig(conf_msg,L1C1_QUEUE);
+        DEBUGMSG(status,NU_SEND_QUEUE_ERR)
+
+        // change state
+        *state=WAIT_INIT;
+      }
+    }
+    break;
+  }
+}
+
+#endif    // L1_DYN_DSP_DWNLD==1
+
--- a/gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_const.h	Mon Oct 19 18:14:23 2015 +0000
+++ b/gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_const.h	Thu Oct 22 18:19:42 2015 +0000
@@ -17,7 +17,7 @@
 #define RED                                1
 #define GREEN                              0
 #define MAX_NUM_OF_PATCH_IDS               5
-#define MAX_NUM_OF_STATE_MACHINES_IMPACTED 6
+#define MAX_NUM_OF_SEMAPHORES              6
 
 #define NUM_OF_DYN_DWNLD_PRIMITIVES 6
 
--- a/gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_defty.h	Mon Oct 19 18:14:23 2015 +0000
+++ b/gsm-fw/L1/dyn_dwl_include/l1_dyn_dwl_defty.h	Thu Oct 22 18:19:42 2015 +0000
@@ -28,7 +28,7 @@
  UWORD16 patch_id[MAX_NUM_OF_PATCH_IDS];
  UWORD16 num_of_elem_to_copy;
  UWORD16 next_patch_id[MAX_NUM_OF_PATCH_IDS];
- BOOL    semaphore_vect[MAX_NUM_OF_STATE_MACHINES_IMPACTED];
+ BOOL    semaphore_vect[MAX_NUM_OF_SEMAPHORES];
  BOOL    melody0_E2_flag_activated;
  BOOL    melody1_E2_flag_activated; 
  UWORD16 dsp_trace_level_copy;