/*
 * File: ert_main.c
 *
 * Code generated for Simulink model 'NXTway_ET2012'.
 *
 * Model version                  : 1.617
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Mon Apr 16 09:34:27 2012
 *
 * Target selection: realtime.tlc
 * Embedded hardware selection: ARM Compatible->ARM 7
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "NXTway_ET2012.h"
#include "kernel.h"
#include "kernel_id.h"
#include "ecrobot_interface.h"
#include "ecrobot_private.h"

int tick = 0;
double period = 0.004;
int sampleTime = 0;
int or_ext = 0;
int or_mdl = 0;
int timesup = 0;
DeclareEvent(TIMESUP);
DeclareTask(OSEK_Task_main);
DeclareTask(OSEK_Task_background);
void user_1ms_isr_type2(void)
{
  tick++;
  if (tick >= sampleTime) {
    tick = 0;
    or_ext++;
    or_mdl++;
    SetEvent(OSEK_Task_main, TIMESUP);
    timesup = 0;
  }
}

void ecrobot_device_initialize(void)
{
  NXTway_ET2012_initialize();
}

TASK(OSEK_Task_main)
{
  sampleTime = (int)(period/0.001);
  while (1) {
    WaitEvent(TIMESUP);
    ClearEvent(TIMESUP);
    NXTway_ET2012_output();

    /* Get model outputs here */
    NXTway_ET2012_update();
    or_mdl = 0;
  }

  TerminateTask();
}

TASK(OSEK_Task_background)
{
  TerminateTask();
}

void ecrobot_device_terminate(void)
{
  NXTway_ET2012_terminate();
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
