/*                                                                          */
/* Function    : host simulation, symchronize with DSP                      */

#include  "windef.h"
#include  "mbdr_dsp_utils.h"
#include  "mbdr_dsp_common_sync_msg.h"
#include  "mbdr_dsp_cyclic_buffer.h"
#include  "mbdr_dsp_cyclic_buffer_double_header.h"
#include  "mbdr_dsp_sdc_hwimage_int.h"
#include  "mbdr_dsp_cpu_common_hwimage.h"
#include  "mbdr_dsp_sdc_system_simulation_host_code.h"
#include  "mbdr_dsp_sdc_system_simulation_host_hwimage.h"
#include  "mbdr_dsp_sdc_system_simulation_app.h"




void mbdr_dsp_sdc_system_simulation_host_sync_with_dsp_work_1_0(void)
{/* mbdr_dsp_sdc_system_simulation_host_sync_with_dsp_work_1_0 */

 /* initialize helpful pointers */
 mbdr_dsp_sdc_dsp_image_ptrs.main_interface_p =
  (mbdr_dsp_cpu_common_interface_t *)
  mbdr_dsp_cpu_common_interface_cpu[0].main_interface_dsp_bofs;

 /* update twice a lot of fieldsin common area */
 MBDR_DSP_SET_DW_IN_BOTH_DSP_SDC_CPU_MAIN_INTERFACE_IMAGES_M(1, dsp_life_sign_value);


}/* mbdr_dsp_sdc_system_simulation_host_sync_with_dsp_work_1_0 */


void mbdr_dsp_sdc_system_simulation_host_wake_up(void)
{/* mbdr_dsp_sdc_system_simulation_host_wake_up */

  /* CPU wake up */
  /* sync message has been already written */
  memset(&mbdr_dsp_cpu_common_interface_cpu[0],
         0x77,
         sizeof(mbdr_dsp_cpu_common_interface_t));


}/* mbdr_dsp_sdc_system_simulation_host_wake_up */

void mbdr_dsp_sdc_system_simulation_host_write_cpu_state_number(
                              SHORT pi_next_cpu_state_number)
{/* mbdr_dsp_sdc_system_simulation_host_write_cpu_state_number */

   /* update/report CPU state number */
   MBDR_DSP_SET_DW_IN_BOTH_DSP_SDC_CPU_MAIN_INTERFACE_IMAGES_M(
                   pi_next_cpu_state_number,
                   cpu_state_number);

}/* mbdr_dsp_sdc_system_simulation_host_write_cpu_state_number */

void mbdr_dsp_sdc_system_simulation_host_poll_dsp_state_number(
                              SHORT pi_next_dsp_state_number)
{/* mbdr_dsp_sdc_system_simulation_host_poll_dsp_state_number */

  /* cpu waits till DSP reports 1 in its state*/
  mbdr_dsp_utils_poll_dw_with_wait(
        (volatile LONG *)
        &mbdr_dsp_cpu_common_interface_cpu[0].dsp_state_number,
        pi_next_dsp_state_number,
        256);

}/* mbdr_dsp_sdc_system_simulation_host_poll_dsp_state_number */
