/*
 * File: Test_1.c
 *
 * Real-Time Workshop code generated for Simulink model Test_1.
 *
 * Model version                        : 1.29
 * Real-Time Workshop file version      : 6.3  (R14SP3)  26-Jul-2005
 * Real-Time Workshop file generated on : Thu Sep 25 20:48:24 2008
 * TLC version                          : 6.3 (Aug  5 2005)
 * C source code generated on           : Thu Sep 25 20:48:24 2008
 */
#include "mpc5554.h"
#include "Test_1.h"
#include "Test_1_private.h"


/* Block signals (auto storage) */
BlockIO_Test_1 Test_1_B;

/* Real-time model */
RT_MODEL_Test_1 Test_1_M_;
RT_MODEL_Test_1 *Test_1_M = &Test_1_M_;

/* Set which subrates need to run this base step (base rate always runs).
 * This function must be called prior to calling the model step function
 * in order to "remember" which rates need to run this base step.  The
 * buffering of events allows for overlapping preemption.
 */
void Test_1_SetEventsForThisBaseStep(boolean_T *eventFlags)
{
  /* Task runs when its counter is zero, computed via rtmStepTask macro */
  eventFlags[1] = rtmStepTask(Test_1_M, 1);
}

/* This function implements a deterministic rate-monotonic multitasking
 * scheduler for a system with 2 rates.  The function is called by the
 * generated step function, hence the generated code self-manages all
 * its subrates.
 */
static void rate_monotonic_scheduler(void)
{
  /* To ensure a safe and deterministic data transfer between two rates,
   * data is transfered at the priority of a fast task and the frequency
   * of the slow task.  The following flags indicate when the data transfer
   * happens.  That is, a rate interaction flag is set true when both rates
   * will run, and false otherwise.
   */

  /* tid 0 shares data with slower tid rate: 1 */
  Test_1_M->Timing.RateInteraction.TID0_1 =
    (Test_1_M->Timing.TaskCounters.TID[1] == 0);

  /* Compute which subrates run during the next base time step.  Subrates
   * are an integer multiple of the base rate counter.  Therefore, the subtask
   * counter is reset when it reaches its limit (zero means run).
   */
  if (++Test_1_M->Timing.TaskCounters.TID[1] == 2) { /* Sample time: [2.0s, 0.0s] */
    Test_1_M->Timing.TaskCounters.TID[1] = 0;
  }
}

/* Model step function for TID0 */
void Test_1_step0(void)                 /* Sample time: [1.0s, 0.0s] */
{

  {                                     /* Sample time: [1.0s, 0.0s] */
    rate_monotonic_scheduler();
  }

  /* Function-call Generator Block: '<Root>/Function-Call Generator' */

  /* Output and update for function-call system: '<Root>/Subsystem1' */

  {
    int32_T i1;
    for(i1 = 0; i1 < 12; i1++) {

      /* Constant: '<S3>/Constant' */
      Test_1_B.Constant[i1] = (Test_1_ConstP.Constant_Value_c[i1]);
    }
  }

  /* Rate Transition Block: <Root>/Rate Transition */
  /* rate transition block          */
  /* (Higher Priority to lower priority, deterministic, */
  /* ensure data integrity)        */
  if (Test_1_M->Timing.RateInteraction.TID0_1) {

    (void) memcpy(Test_1_B.RateTransition,Test_1_B.Constant,12*sizeof(uint16_T));
  }

  {

    eqadc_cfifo1_sw_trigger_fcn();
  }
}

/* Model step function for TID1 */
void Test_1_step1(void)                 /* Sample time: [2.0s, 0.0s] */
{
  /* local block i/o variables */
  int32_T rtb_ForIterator;



  /* Function-call Generator Block: '<Root>/Function-Call Generator1' */

  /* Output and update for function-call system: '<Root>/Subsystem' */

  {
    int32_T rtb_s32_iter;

    for(rtb_s32_iter = 0; rtb_s32_iter < 19; rtb_s32_iter++) {
      rtb_ForIterator = rtb_s32_iter;

      /* Output and update for iterator system: '<S2>/For Iterator Subsystem' */

      {
        uint16_T rtb_u16_tmp[19];
        uint16_T rtb_u16_U[12];
        uint16_T rtb_u16_U_b[7];
        int32_T i1;

        /* MultiPortSwitch: '<S4>/Index Vector' incorporates:
         *  Constant: '<S4>/Constant'
         */
        for(i1 = 0; i1 < 12; i1++) {
          rtb_u16_U[i1] = Test_1_B.RateTransition[i1];
        }
        for(i1 = 0; i1 < 7; i1++) {
          rtb_u16_U_b[i1] = (Test_1_ConstP.Constant_Value[i1]);
        }
        for(i1 = 0; i1 < 12; i1++) {
          rtb_u16_tmp[i1] = rtb_u16_U[i1];
        }
        for(i1 = 0; i1 < 7; i1++) {
          rtb_u16_tmp[12 + i1] = rtb_u16_U_b[i1];
        }
        switch(rtb_ForIterator) {
         case 0:
          Test_1_B.IndexVector = rtb_u16_tmp[0];
          break;
         case 1:
          Test_1_B.IndexVector = rtb_u16_tmp[1];
          break;
         case 2:
          Test_1_B.IndexVector = rtb_u16_tmp[2];
          break;
         case 3:
          Test_1_B.IndexVector = rtb_u16_tmp[3];
          break;
         case 4:
          Test_1_B.IndexVector = rtb_u16_tmp[4];
          break;
         case 5:
          Test_1_B.IndexVector = rtb_u16_tmp[5];
          break;
         case 6:
          Test_1_B.IndexVector = rtb_u16_tmp[6];
          break;
         case 7:
          Test_1_B.IndexVector = rtb_u16_tmp[7];
          break;
         case 8:
          Test_1_B.IndexVector = rtb_u16_tmp[8];
          break;
         case 9:
          Test_1_B.IndexVector = rtb_u16_tmp[9];
          break;
         case 10:
          Test_1_B.IndexVector = rtb_u16_tmp[10];
          break;
         case 11:
          Test_1_B.IndexVector = rtb_u16_tmp[11];
          break;
         case 12:
          Test_1_B.IndexVector = rtb_u16_tmp[12];
          break;
         case 13:
          Test_1_B.IndexVector = rtb_u16_tmp[13];
          break;
         case 14:
          Test_1_B.IndexVector = rtb_u16_tmp[14];
          break;
         case 15:
          Test_1_B.IndexVector = rtb_u16_tmp[15];
          break;
         case 16:
          Test_1_B.IndexVector = rtb_u16_tmp[16];
          break;
         case 17:
          Test_1_B.IndexVector = rtb_u16_tmp[17];
          break;
         case 18:
          Test_1_B.IndexVector = rtb_u16_tmp[18];
          break;
        }
      }

      /*Append the data to the SCI module buffer for a Transmit*/
      esci_package_to_transmit_fnc(esci_mod_A, Test_1_B.IndexVector); /* Transmit Input Data */
    }
  }
}

void Test_1_step(int_T tid) {

  switch(tid) {
   case 0 :
    Test_1_step0();
    break;
   case 1 :
    Test_1_step1();
    break;
   default :
    break;
  }
}

/* Model initialize function */

void Test_1_initialize(boolean_T firstTime)
{

  if (firstTime) {
    /* initialize real-time model */
    (void) memset((char_T *)Test_1_M,0,sizeof(RT_MODEL_Test_1));

    /* block I/O */
    (void) memset(((void *) &Test_1_B),0,sizeof(BlockIO_Test_1));

    sys_init_rp();
  }
}

/* Model terminate function */

void Test_1_terminate(void)
{
  /* (no terminate code required) */
}

/* File trailer for Real-Time Workshop generated code.
 *
 * [EOF]
 */
