⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c2_myuart1.c

📁 这份是实验课上的教师和学生用的实例。关于用matlab simulink仿真状态机并生成vhdl代码的详细内容
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Include files */

#include "MyUART1_sfun.h"
#include "c2_MyUART1.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance.chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance.instanceNumber)
#include "MyUART1_sfun_debug_macros.h"

/* Type Definitions */

/* Named Constants */
#define c2_IN_NO_ACTIVE_CHILD          (0)
#define c2_IN_WAIT                     (3)
#define c2_IN_DEC                      (1)
#define c2_IN_S                        (1)
#define c2_IN_START                    (5)
#define c2_IN_IDLE                     (4)
#define c2_IN_DATA                     (1)
#define c2_IN_STOP                     (6)
#define c2_IN_Delay                    (3)
#define c2_IN_Last                     (2)
#define c2_IN_DELAY2                   (2)

/* Variable Declarations */

/* Variable Definitions */
static SFc2_MyUART1InstanceStruct chartInstance;

/* Function Declarations */
static void initialize_c2_MyUART1(void);
static void initialize_params_c2_MyUART1(void);
static void enable_c2_MyUART1(void);
static void disable_c2_MyUART1(void);
static void finalize_c2_MyUART1(void);
static void sf_c2_MyUART1(void);
static void c2_TxdPro(void);
static void init_script_number_translation(uint32_T c2_machineNumber, uint32_T
  c2_chartNumber);
static uint8_T c2__u8_s32_(int32_T c2_b);
static void init_test_point_addr_map(void);
static void **get_test_point_address_map(void);
static rtwCAPI_ModelMappingInfo *get_test_point_mapping_info(void);
static void init_dsm_address_info(void);

/* Function Definitions */
static void initialize_c2_MyUART1(void)
{
  uint8_T c2_previousEvent;
  uint8_T *c2_TxD;
  uint8_T *c2_Wr;
  c2_Wr = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c2_TxD = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  chartInstance.c2_tp_S = 0U;
  chartInstance.c2_is_active_CntPro = 0U;
  chartInstance.c2_is_CntPro = 0U;
  chartInstance.c2_tp_CntPro = 0U;
  chartInstance.c2_tp_DEC = 0U;
  chartInstance.c2_tp_Last = 0U;
  chartInstance.c2_tp_WAIT = 0U;
  chartInstance.c2_is_active_TxdPro = 0U;
  chartInstance.c2_is_TxdPro = 0U;
  chartInstance.c2_tp_TxdPro = 0U;
  chartInstance.c2_tp_DATA = 0U;
  chartInstance.c2_tp_DELAY2 = 0U;
  chartInstance.c2_tp_Delay = 0U;
  chartInstance.c2_tp_IDLE = 0U;
  chartInstance.c2_tp_START = 0U;
  chartInstance.c2_tp_STOP = 0U;
  chartInstance.c2_is_active_c2_MyUART1 = 0U;
  chartInstance.c2_is_c2_MyUART1 = 0U;
  chartInstance.c2_Tmp = 0U;
  chartInstance.c2_BitCnt = 0U;
  chartInstance.c2_RateCnt = 0U;
  if (!((boolean_T)cdrGetOutputPortReusable(chartInstance.S, 1) != 0)) {
    *c2_TxD = 0U;
  }

  if (!((boolean_T)cdrGetOutputPortReusable(chartInstance.S, 2) != 0)) {
    *c2_Wr = 0U;
  }

  c2_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_ENTRY_FUNCTION_TAG,1);
  chartInstance.c2_is_active_c2_MyUART1 = 1U;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,1);
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,1);
  chartInstance.c2_is_c2_MyUART1 = (uint8_T)c2_IN_S;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,0);
  chartInstance.c2_tp_S = 1U;
  chartInstance.c2_is_active_TxdPro = 1U;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,5);
  chartInstance.c2_tp_TxdPro = 1U;
  _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,7);
  _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,7);
  chartInstance.c2_is_TxdPro = (uint8_T)c2_IN_IDLE;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,9);
  chartInstance.c2_tp_IDLE = 1U;
  chartInstance.c2_BitCnt = 0U;
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_BitCnt, 3U);
  *c2_TxD = 1U;
  _SFD_DATA_RANGE_CHECK((real_T)*c2_TxD, 1U);
  *c2_Wr = 0U;
  _SFD_DATA_RANGE_CHECK((real_T)*c2_Wr, 5U);
  chartInstance.c2_is_active_CntPro = 1U;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,1);
  chartInstance.c2_tp_CntPro = 1U;
  _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,0);
  _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,0);
  chartInstance.c2_is_CntPro = (uint8_T)c2_IN_WAIT;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,4);
  chartInstance.c2_tp_WAIT = 1U;
  chartInstance.c2_RateCnt = 0U;
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,1);
  _sfEvent_ = c2_previousEvent;
}

static void initialize_params_c2_MyUART1(void)
{
}

static void enable_c2_MyUART1(void)
{
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
}

static void disable_c2_MyUART1(void)
{
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
}

static void finalize_c2_MyUART1(void)
{
}

static void sf_c2_MyUART1(void)
{
  uint8_T c2_previousEvent;
  uint8_T c2_u0;
  uint8_T c2_u1;
  uint8_T *c2_TxDData;
  uint8_T *c2_TxD;
  uint8_T *c2_Wr;
  uint8_T *c2_Ready;
  c2_TxDData = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 0);
  c2_Wr = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c2_TxD = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  c2_Ready = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG,1);
  _SFD_DATA_RANGE_CHECK((real_T)*c2_TxDData, 0U);
  _SFD_DATA_RANGE_CHECK((real_T)*c2_TxD, 1U);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_Tmp, 2U);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_BitCnt, 3U);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
  _SFD_DATA_RANGE_CHECK((real_T)*c2_Wr, 5U);
  _SFD_DATA_RANGE_CHECK((real_T)*c2_Ready, 6U);
  c2_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,1);
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,0);
  c2_TxdPro();
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,1);
  switch (chartInstance.c2_is_CntPro) {
   case c2_IN_DEC:
    CV_STATE_EVAL(1,0,1);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,2);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,1);
    if (CV_TRANSITION_EVAL(1U, (int32_T)_SFD_CCP_CALL(1,0,(((uint8_T)
            (chartInstance.c2_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,1);
      chartInstance.c2_RateCnt = 15U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,2);
      if (CV_TRANSITION_EVAL(2U, (int32_T)_SFD_CCP_CALL(2,0,(((uint8_T)
              (chartInstance.c2_BitCnt & 15U) == 9U)!=0))) != 0U != 0) {
        _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,2);
        _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,2);
        chartInstance.c2_tp_DEC = 0U;
        chartInstance.c2_is_CntPro = (uint8_T)c2_IN_NO_ACTIVE_CHILD;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,2);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
        chartInstance.c2_is_CntPro = (uint8_T)c2_IN_Last;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,3);
        chartInstance.c2_tp_Last = 1U;
      } else {
        _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,3);
        _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,3);
        _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,2);
        chartInstance.c2_tp_DEC = 0U;
        chartInstance.c2_is_CntPro = (uint8_T)c2_IN_NO_ACTIVE_CHILD;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,2);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
        chartInstance.c2_is_CntPro = (uint8_T)c2_IN_DEC;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,2);
        chartInstance.c2_tp_DEC = 1U;
      }
    } else {
      c2_u0 = c2__u8_s32_(chartInstance.c2_RateCnt - 1);
      if (c2_u0 > 31) {
        sf_debug_overflow_detection(0U, 0U);
      }

      chartInstance.c2_RateCnt = (uint8_T)(c2_u0 & 31U);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
    break;

   case c2_IN_Last:
    CV_STATE_EVAL(1,0,2);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,3);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,4);
    if (CV_TRANSITION_EVAL(4U, (int32_T)_SFD_CCP_CALL(4,0,(((uint8_T)
            (chartInstance.c2_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,4);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,3);
      chartInstance.c2_tp_Last = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,3);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,3);
      chartInstance.c2_is_CntPro = (uint8_T)c2_IN_WAIT;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,4);
      chartInstance.c2_tp_WAIT = 1U;
      chartInstance.c2_RateCnt = 0U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
    } else {
      c2_u1 = c2__u8_s32_(chartInstance.c2_RateCnt - 1);
      if (c2_u1 > 31) {
        sf_debug_overflow_detection(0U, 0U);
      }

      chartInstance.c2_RateCnt = (uint8_T)(c2_u1 & 31U);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,3);
    break;

   case c2_IN_WAIT:
    CV_STATE_EVAL(1,0,3);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,4);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,5);
    if (CV_TRANSITION_EVAL(5U, (int32_T)_SFD_CCP_CALL(5,0,(((uint8_T)(*c2_TxD &
             1U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,5);
      chartInstance.c2_RateCnt = 15U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,4);
      chartInstance.c2_tp_WAIT = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,4);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,4);
      chartInstance.c2_is_CntPro = (uint8_T)c2_IN_DEC;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,2);
      chartInstance.c2_tp_DEC = 1U;
    } else {
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,6);
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,6);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,4);
      chartInstance.c2_tp_WAIT = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,4);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,4);
      chartInstance.c2_is_CntPro = (uint8_T)c2_IN_WAIT;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,4);
      chartInstance.c2_tp_WAIT = 1U;
      chartInstance.c2_RateCnt = 0U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_RateCnt, 4U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,4);
    break;

   default:
    CV_STATE_EVAL(1,0,0);
    chartInstance.c2_is_CntPro = (uint8_T)c2_IN_NO_ACTIVE_CHILD;
    _SFD_CS_CALL(STATE_INACTIVE_TAG,2);
    break;
  }

  _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,1);
  _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,0);
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,1);
  _sfEvent_ = c2_previousEvent;
  sf_debug_check_for_state_inconsistency(_MyUART1MachineNumber_,
    chartInstance.chartNumber, chartInstance.instanceNumber);
}

static void c2_TxdPro(void)
{
  uint8_T c2_u2;
  uint8_T c2_u3;
  real_T c2_d0;
  uint8_T c2_u4;
  real_T c2_d1;
  uint8_T *c2_TxD;
  uint8_T *c2_Ready;
  uint8_T *c2_TxDData;
  uint8_T *c2_Wr;
  c2_TxDData = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 0);
  c2_Wr = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c2_TxD = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  c2_Ready = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 1);
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,5);
  switch (chartInstance.c2_is_TxdPro) {
   case c2_IN_DATA:
    CV_STATE_EVAL(5,0,1);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,6);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,8);
    if (CV_TRANSITION_EVAL(8U, (int32_T)_SFD_CCP_CALL(8,0,(((uint8_T)
            (chartInstance.c2_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,8);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,6);
      chartInstance.c2_tp_DATA = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,6);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,6);
      chartInstance.c2_is_TxdPro = (uint8_T)c2_IN_Delay;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,8);
      chartInstance.c2_tp_Delay = 1U;
      c2_u2 = c2__u8_s32_(chartInstance.c2_BitCnt + 1);
      if (c2_u2 > 15) {
        sf_debug_overflow_detection(0U, 0U);
      }

      chartInstance.c2_BitCnt = (uint8_T)(c2_u2 & 15U);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_BitCnt, 3U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,6);
    break;

   case c2_IN_DELAY2:
    CV_STATE_EVAL(5,0,2);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,7);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,9);
    if (CV_TRANSITION_EVAL(9U, (int32_T)_SFD_CCP_CALL(9,0,(((uint8_T)
            (chartInstance.c2_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,9);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,7);
      chartInstance.c2_tp_DELAY2 = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,7);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,7);
      chartInstance.c2_is_TxdPro = (uint8_T)c2_IN_DATA;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,6);
      chartInstance.c2_tp_DATA = 1U;
      c2_u3 = chartInstance.c2_Tmp;
      if (c2_u3 > 1) {
        sf_debug_overflow_detection(0U, 0U);
      }

      *c2_TxD = (uint8_T)(c2_u3 & 1U);
      _SFD_DATA_RANGE_CHECK((real_T)*c2_TxD, 1U);
      c2_d0 = (real_T)*c2_TxD;
      sf_mex_printf("%s =\\n", "TxD");
      sf_mex_call("disp", 0U, 1U, 6, c2_d0);
      chartInstance.c2_Tmp = c2__u8_s32_(chartInstance.c2_Tmp >> 1);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c2_Tmp, 2U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,7);
    break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -