/*
 * MotoHawk_IO.c
 *
 * Real-Time Workshop code generation for Simulink model "Controller.mdl".
 *
 * Model Version              : 1.375
 * Real-Time Workshop version : 7.3  (R2009a)  15-Jan-2009
 * C source code generated on : Mon Jan 11 12:01:10 2010
 *
 * Target selection: motohawk_ert_rtw.tlc
 * Embedded hardware selection: Specified
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "MotoHawk_IO.h"

/* S-Function Block: <S38>/motohawk_ain5 Resource: ECUP */
NativeError_S ECUP_AnalogInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_AnalogInCreateAttributes CreateInfo;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_ANALOG_CONDITION;
  CreateInfo.uValidAttributesMask = USE_ANALOG_DYNAMIC_ON_CREATE;
  VolatileWork.mh_init_resource_ECUP = -1;
  if (((int32_T) RES_ECUP) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) (((int32_T) RES_ECUP)),
      &CreateInfo, BEHAVIOUR_ANALOGIN);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_ECUP = ((int32_T) RES_ECUP);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T ain_create_ECUP;
      if (SUCCESS(sErrorResult))
        ain_create_ECUP = 0;
      else
        ain_create_ECUP = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S ECUP_AnalogInput_Get(uint16_T *adc, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_ECUP >= 0) {
    S_AnalogHowToGet HowToGetObj;
    S_AnalogResult AnalogResultObj;
    HowToGetObj.uValidAttributesMask = 0;
    sErrorResult = GetResourceValueBEHAVIOUR_ANALOGIN((E_ModuleResource)
      (VolatileWork.mh_init_resource_ECUP), &HowToGetObj, &AnalogResultObj);
    if (SUCCESS(sErrorResult)) {
      *adc = AnalogResultObj.uADCValue;
    } else {
      *adc = 0;
    }

    {
      extern uint8_T ain_read_ECUP;
      if (SUCCESS(sErrorResult))
        ain_read_ECUP = 0;
      else
        ain_read_ECUP = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

/* S-Function Block: <S1>/motohawk_ain Resource: AN4M */
NativeError_S AN4M_AnalogInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_AnalogInCreateAttributes CreateInfo;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_ANALOG_CONDITION;
  CreateInfo.uValidAttributesMask = USE_ANALOG_DYNAMIC_ON_CREATE;
  VolatileWork.mh_init_resource_AN4M = -1;
  if (((int32_T) RES_AN4M) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) (((int32_T) RES_AN4M)),
      &CreateInfo, BEHAVIOUR_ANALOGIN);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_AN4M = ((int32_T) RES_AN4M);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T ain_create_AN4M;
      if (SUCCESS(sErrorResult))
        ain_create_AN4M = 0;
      else
        ain_create_AN4M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S AN4M_AnalogInput_Get(uint16_T *adc, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_AN4M >= 0) {
    S_AnalogHowToGet HowToGetObj;
    S_AnalogResult AnalogResultObj;
    HowToGetObj.uValidAttributesMask = 0;
    sErrorResult = GetResourceValueBEHAVIOUR_ANALOGIN((E_ModuleResource)
      (VolatileWork.mh_init_resource_AN4M), &HowToGetObj, &AnalogResultObj);
    if (SUCCESS(sErrorResult)) {
      *adc = AnalogResultObj.uADCValue;
    } else {
      *adc = 0;
    }

    {
      extern uint8_T ain_read_AN4M;
      if (SUCCESS(sErrorResult))
        ain_read_AN4M = 0;
      else
        ain_read_AN4M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

/* S-Function Block: <S1>/motohawk_ain1 Resource: AN5M */
NativeError_S AN5M_AnalogInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_AnalogInCreateAttributes CreateInfo;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_ANALOG_CONDITION;
  CreateInfo.uValidAttributesMask = USE_ANALOG_DYNAMIC_ON_CREATE;
  VolatileWork.mh_init_resource_AN5M = -1;
  if (((int32_T) RES_AN5M) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) (((int32_T) RES_AN5M)),
      &CreateInfo, BEHAVIOUR_ANALOGIN);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_AN5M = ((int32_T) RES_AN5M);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T ain_create_AN5M;
      if (SUCCESS(sErrorResult))
        ain_create_AN5M = 0;
      else
        ain_create_AN5M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S AN5M_AnalogInput_Get(uint16_T *adc, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_AN5M >= 0) {
    S_AnalogHowToGet HowToGetObj;
    S_AnalogResult AnalogResultObj;
    HowToGetObj.uValidAttributesMask = 0;
    sErrorResult = GetResourceValueBEHAVIOUR_ANALOGIN((E_ModuleResource)
      (VolatileWork.mh_init_resource_AN5M), &HowToGetObj, &AnalogResultObj);
    if (SUCCESS(sErrorResult)) {
      *adc = AnalogResultObj.uADCValue;
    } else {
      *adc = 0;
    }

    {
      extern uint8_T ain_read_AN5M;
      if (SUCCESS(sErrorResult))
        ain_read_AN5M = 0;
      else
        ain_read_AN5M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

/* S-Function Block: <S1>/motohawk_din Resource: AN6M */
NativeError_S AN6M_DigitalInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_SwitchCreateResourceAttributes CreateInfo;
  CreateInfo.ePolarity = RES_POL_ACTIVE_HIGH;
  CreateInfo.eSwitchPullUp = (E_SwitchPullUp) 0;
  CreateInfo.uSampleRateInMilliSecs = 0;/* Default is to not de-bounce the digital input */
  CreateInfo.DynamicObj.eAssertionThreshold = THRESH_DIGITAL;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_SWITCH_CONDITION |
    USE_SWITCH_ASSERT_THRESH;
  CreateInfo.uValidAttributesMask = USE_SWITCH_DYNAMIC_ON_CREATE |
    USE_SWITCH_POLARITY | USE_SWITCH_PULLUP_STRENGTH |
    USE_SWITCH_DEBOUNCE_SAMPLE_RATE;
  VolatileWork.mh_init_resource_AN6M = -1;
  if (((int32_T) RES_AN6M) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) ((int32_T) RES_AN6M),
      &CreateInfo, BEHAVIOUR_SWITCH);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_AN6M = ((int32_T) RES_AN6M);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T din_create_AN6M;
      if (SUCCESS(sErrorResult))
        din_create_AN6M = 0;
      else
        din_create_AN6M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S AN6M_DigitalInput_Get(boolean_T *out, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_AN6M >= 0) {
    E_ResourceState ResourceState;
    NativeError_S sErrorResult;
    sErrorResult = GetSwitchResourceState((E_ModuleResource)
      VolatileWork.mh_init_resource_AN6M, &ResourceState);
    if (SUCCESS(sErrorResult)) {
      *out = (ResourceState != RES_OFF);
    } else {
      *out = 0;
    }

    {
      extern uint8_T din_read_AN6M;
      if (SUCCESS(sErrorResult))
        din_read_AN6M = 0;
      else
        din_read_AN6M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

/* S-Function Block: <S1>/motohawk_din1 Resource: AN1M */
NativeError_S AN1M_DigitalInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_SwitchCreateResourceAttributes CreateInfo;
  CreateInfo.ePolarity = RES_POL_ACTIVE_HIGH;
  CreateInfo.eSwitchPullUp = (E_SwitchPullUp) 0;
  CreateInfo.uSampleRateInMilliSecs = 0;/* Default is to not de-bounce the digital input */
  CreateInfo.DynamicObj.eAssertionThreshold = THRESH_DIGITAL;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_SWITCH_CONDITION |
    USE_SWITCH_ASSERT_THRESH;
  CreateInfo.uValidAttributesMask = USE_SWITCH_DYNAMIC_ON_CREATE |
    USE_SWITCH_POLARITY | USE_SWITCH_PULLUP_STRENGTH |
    USE_SWITCH_DEBOUNCE_SAMPLE_RATE;
  VolatileWork.mh_init_resource_AN1M = -1;
  if (((int32_T) RES_AN1M) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) ((int32_T) RES_AN1M),
      &CreateInfo, BEHAVIOUR_SWITCH);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_AN1M = ((int32_T) RES_AN1M);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T din_create_AN1M;
      if (SUCCESS(sErrorResult))
        din_create_AN1M = 0;
      else
        din_create_AN1M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S AN1M_DigitalInput_Get(boolean_T *out, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_AN1M >= 0) {
    E_ResourceState ResourceState;
    NativeError_S sErrorResult;
    sErrorResult = GetSwitchResourceState((E_ModuleResource)
      VolatileWork.mh_init_resource_AN1M, &ResourceState);
    if (SUCCESS(sErrorResult)) {
      *out = (ResourceState != RES_OFF);
    } else {
      *out = 0;
    }

    {
      extern uint8_T din_read_AN1M;
      if (SUCCESS(sErrorResult))
        din_read_AN1M = 0;
      else
        din_read_AN1M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

/* S-Function Block: <S1>/motohawk_din2 Resource: AN2M */
NativeError_S AN2M_DigitalInput_Create(void)
{
  NativeError_S sErrorResult = ERROR_RESOURCE_NOT_CREATED;
  S_SwitchCreateResourceAttributes CreateInfo;
  CreateInfo.ePolarity = RES_POL_ACTIVE_HIGH;
  CreateInfo.eSwitchPullUp = (E_SwitchPullUp) 0;
  CreateInfo.uSampleRateInMilliSecs = 0;/* Default is to not de-bounce the digital input */
  CreateInfo.DynamicObj.eAssertionThreshold = THRESH_DIGITAL;
  CreateInfo.DynamicObj.eResourceCondition = RES_ENABLED;
  CreateInfo.DynamicObj.uValidAttributesMask = USE_SWITCH_CONDITION |
    USE_SWITCH_ASSERT_THRESH;
  CreateInfo.uValidAttributesMask = USE_SWITCH_DYNAMIC_ON_CREATE |
    USE_SWITCH_POLARITY | USE_SWITCH_PULLUP_STRENGTH |
    USE_SWITCH_DEBOUNCE_SAMPLE_RATE;
  VolatileWork.mh_init_resource_AN2M = -1;
  if (((int32_T) RES_AN2M) >= 0) {
    sErrorResult = CreateResource((E_ModuleResource) ((int32_T) RES_AN2M),
      &CreateInfo, BEHAVIOUR_SWITCH);
    if (SUCCESS(sErrorResult)) {
      VolatileWork.mh_init_resource_AN2M = ((int32_T) RES_AN2M);
    } else {
      LogNativeError(sErrorResult);
    }

    {
      extern uint8_T din_create_AN2M;
      if (SUCCESS(sErrorResult))
        din_create_AN2M = 0;
      else
        din_create_AN2M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}

NativeError_S AN2M_DigitalInput_Get(boolean_T *out, uint16_T *status)
{
  NativeError_S sErrorResult = ERROR_FAIL;
  if (VolatileWork.mh_init_resource_AN2M >= 0) {
    E_ResourceState ResourceState;
    NativeError_S sErrorResult;
    sErrorResult = GetSwitchResourceState((E_ModuleResource)
      VolatileWork.mh_init_resource_AN2M, &ResourceState);
    if (SUCCESS(sErrorResult)) {
      *out = (ResourceState != RES_OFF);
    } else {
      *out = 0;
    }

    {
      extern uint8_T din_read_AN2M;
      if (SUCCESS(sErrorResult))
        din_read_AN2M = 0;
      else
        din_read_AN2M = (uint8_T) GetErrorCode(sErrorResult);
    }
  }

  return sErrorResult;
}
