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

📄 c1_myuart1.c

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

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

/* Type Definitions */

/* Named Constants */
#define c1_IN_NO_ACTIVE_CHILD          (0)
#define c1_IN_S                        (1)
#define c1_IN_WAIT                     (2)
#define c1_IN_DEC                      (1)
#define c1_IN_STORE                    (5)
#define c1_IN_IDLE                     (2)
#define c1_IN_START                    (3)
#define c1_IN_DATA                     (1)
#define c1_IN_delay                    (6)
#define c1_IN_STOP                     (4)

/* Variable Declarations */

/* Variable Definitions */
static SFc1_MyUART1InstanceStruct chartInstance;

/* Function Declarations */
static void initialize_c1_MyUART1(void);
static void initialize_params_c1_MyUART1(void);
static void enable_c1_MyUART1(void);
static void disable_c1_MyUART1(void);
static void finalize_c1_MyUART1(void);
static void sf_c1_MyUART1(void);
static void c1_RxdPro(void);
static void init_script_number_translation(uint32_T c1_machineNumber, uint32_T
  c1_chartNumber);
static uint8_T c1__u8_s32_(int32_T c1_b);
static int32_T c1__s32_shl_s32_(int32_T c1_b, int32_T c1_c);
static int32_T c1__s32_add__(int32_T c1_b, int32_T c1_c);
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_c1_MyUART1(void)
{
  uint8_T c1_previousEvent;
  uint8_T *c1_RxDData;
  uint8_T *c1_Valid;
  c1_Valid = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c1_RxDData = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  chartInstance.c1_tp_S = 0U;
  chartInstance.c1_is_active_CntPro = 0U;
  chartInstance.c1_is_CntPro = 0U;
  chartInstance.c1_tp_CntPro = 0U;
  chartInstance.c1_tp_DEC = 0U;
  chartInstance.c1_tp_WAIT = 0U;
  chartInstance.c1_is_active_RxdPro = 0U;
  chartInstance.c1_is_RxdPro = 0U;
  chartInstance.c1_tp_RxdPro = 0U;
  chartInstance.c1_tp_DATA = 0U;
  chartInstance.c1_tp_IDLE = 0U;
  chartInstance.c1_tp_START = 0U;
  chartInstance.c1_tp_STOP = 0U;
  chartInstance.c1_tp_STORE = 0U;
  chartInstance.c1_tp_delay = 0U;
  chartInstance.c1_is_active_c1_MyUART1 = 0U;
  chartInstance.c1_is_c1_MyUART1 = 0U;
  chartInstance.c1_RateCnt = 0U;
  chartInstance.c1_BitCnt = 0U;
  chartInstance.c1_Tmp = 0U;
  if (!((boolean_T)cdrGetOutputPortReusable(chartInstance.S, 1) != 0)) {
    *c1_RxDData = 0U;
  }

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

  c1_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_ENTRY_FUNCTION_TAG,0);
  chartInstance.c1_is_active_c1_MyUART1 = 1U;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,0);
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,0);
  chartInstance.c1_is_c1_MyUART1 = (uint8_T)c1_IN_S;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,0);
  chartInstance.c1_tp_S = 1U;
  chartInstance.c1_is_active_RxdPro = 1U;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,4);
  chartInstance.c1_tp_RxdPro = 1U;
  _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,6);
  _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,6);
  chartInstance.c1_is_RxdPro = (uint8_T)c1_IN_IDLE;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,6);
  chartInstance.c1_tp_IDLE = 1U;
  chartInstance.c1_BitCnt = 0U;
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_BitCnt, 3U);
  *c1_Valid = 0U;
  _SFD_DATA_RANGE_CHECK((real_T)*c1_Valid, 4U);
  chartInstance.c1_is_active_CntPro = 1U;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,1);
  chartInstance.c1_tp_CntPro = 1U;
  _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,0);
  _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,0);
  chartInstance.c1_is_CntPro = (uint8_T)c1_IN_WAIT;
  _SFD_CS_CALL(STATE_ACTIVE_TAG,3);
  chartInstance.c1_tp_WAIT = 1U;
  chartInstance.c1_RateCnt = 15U;
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,0);
  _sfEvent_ = c1_previousEvent;
}

static void initialize_params_c1_MyUART1(void)
{
}

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

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

static void finalize_c1_MyUART1(void)
{
}

static void sf_c1_MyUART1(void)
{
  uint8_T c1_previousEvent;
  uint8_T c1_u0;
  uint8_T c1_u1;
  uint8_T *c1_RxD;
  uint8_T *c1_RxDData;
  uint8_T *c1_Valid;
  uint8_T *c1_Rd;
  c1_Rd = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 1);
  c1_Valid = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c1_RxD = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 0);
  c1_RxDData = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG,0);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
  _SFD_DATA_RANGE_CHECK((real_T)*c1_RxD, 1U);
  _SFD_DATA_RANGE_CHECK((real_T)*c1_RxDData, 2U);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_BitCnt, 3U);
  _SFD_DATA_RANGE_CHECK((real_T)*c1_Valid, 4U);
  _SFD_DATA_RANGE_CHECK((real_T)*c1_Rd, 5U);
  _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_Tmp, 6U);
  c1_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,0);
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,0);
  c1_RxdPro();
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,1);
  switch (chartInstance.c1_is_CntPro) {
   case c1_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.c1_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,1);
      chartInstance.c1_RateCnt = 15U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,2);
      if (CV_TRANSITION_EVAL(2U, (_SFD_CCP_CALL(2,0,(((uint8_T)
               (chartInstance.c1_BitCnt & 15U) == 10U)!=0)) != 0) ||
                             (_SFD_CCP_CALL(2,1,(((
                uint8_T)(chartInstance.c1_BitCnt & 15U) == 0)!=0)) != 0)) != 0U
          != 0) {
        _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,2);
        _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,2);
        chartInstance.c1_tp_DEC = 0U;
        chartInstance.c1_is_CntPro = (uint8_T)c1_IN_NO_ACTIVE_CHILD;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,2);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
        chartInstance.c1_is_CntPro = (uint8_T)c1_IN_WAIT;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,3);
        chartInstance.c1_tp_WAIT = 1U;
        chartInstance.c1_RateCnt = 15U;
        _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
      } 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.c1_tp_DEC = 0U;
        chartInstance.c1_is_CntPro = (uint8_T)c1_IN_NO_ACTIVE_CHILD;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,2);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
        chartInstance.c1_is_CntPro = (uint8_T)c1_IN_DEC;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,2);
        chartInstance.c1_tp_DEC = 1U;
      }
    } else {
      c1_u0 = c1__u8_s32_(chartInstance.c1_RateCnt - 1);
      if (c1_u0 > 31) {
        sf_debug_overflow_detection(0U, 0U);
      }

      chartInstance.c1_RateCnt = (uint8_T)(c1_u0 & 31U);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,2);
    break;

   case c1_IN_WAIT:
    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)(*c1_RxD &
             1U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,4);
      c1_u1 = c1__u8_s32_(chartInstance.c1_RateCnt >> 1);
      if (c1_u1 > 31) {
        sf_debug_overflow_detection(0U, 0U);
      }

      chartInstance.c1_RateCnt = (uint8_T)(c1_u1 & 31U);
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,3);
      chartInstance.c1_tp_WAIT = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,3);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,3);
      chartInstance.c1_is_CntPro = (uint8_T)c1_IN_DEC;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,2);
      chartInstance.c1_tp_DEC = 1U;
    } else {
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,5);
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,5);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,3);
      chartInstance.c1_tp_WAIT = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,3);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,3);
      chartInstance.c1_is_CntPro = (uint8_T)c1_IN_WAIT;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,3);
      chartInstance.c1_tp_WAIT = 1U;
      chartInstance.c1_RateCnt = 15U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_RateCnt, 0U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,3);
    break;

   default:
    CV_STATE_EVAL(1,0,0);
    chartInstance.c1_is_CntPro = (uint8_T)c1_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,0);
  _sfEvent_ = c1_previousEvent;
  sf_debug_check_for_state_inconsistency(_MyUART1MachineNumber_,
    chartInstance.chartNumber, chartInstance.instanceNumber);
}

static void c1_RxdPro(void)
{
  uint8_T c1_u2;
  uint8_T *c1_RxD;
  uint8_T *c1_Valid;
  uint8_T *c1_RxDData;
  c1_Valid = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c1_RxD = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 0);
  c1_RxDData = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,4);
  switch (chartInstance.c1_is_RxdPro) {
   case c1_IN_DATA:
    CV_STATE_EVAL(4,0,1);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,5);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,7);
    if (CV_TRANSITION_EVAL(7U, (int32_T)_SFD_CCP_CALL(7,0,(((uint8_T)
            (chartInstance.c1_RateCnt & 31U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,7);
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,8);
      if (CV_TRANSITION_EVAL(8U, (int32_T)_SFD_CCP_CALL(8,0,(((uint8_T)
              (chartInstance.c1_BitCnt & 15U) == 9U)!=0))) != 0U != 0) {
        _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,8);
        _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,5);
        chartInstance.c1_tp_DATA = 0U;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,5);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,5);
        chartInstance.c1_is_RxdPro = (uint8_T)c1_IN_delay;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,10);
        chartInstance.c1_tp_delay = 1U;
        *c1_Valid = 1U;
        _SFD_DATA_RANGE_CHECK((real_T)*c1_Valid, 4U);
        *c1_RxDData = chartInstance.c1_Tmp;
        _SFD_DATA_RANGE_CHECK((real_T)*c1_RxDData, 2U);
      } else {
        _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,9);
        _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,9);
        _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,5);
        chartInstance.c1_tp_DATA = 0U;
        _SFD_CS_CALL(STATE_INACTIVE_TAG,5);
        _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,5);
        chartInstance.c1_is_RxdPro = (uint8_T)c1_IN_STORE;
        _SFD_CS_CALL(STATE_ACTIVE_TAG,9);
        chartInstance.c1_tp_STORE = 1U;
        chartInstance.c1_Tmp = c1__u8_s32_(c1__s32_add__(c1__s32_shl_s32_
          ((int32_T)*c1_RxD, 7), chartInstance.c1_Tmp >> 1));
        _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_Tmp, 6U);
        c1_u2 = c1__u8_s32_(chartInstance.c1_BitCnt + 1);
        if (c1_u2 > 15) {
          sf_debug_overflow_detection(0U, 0U);
        }

        chartInstance.c1_BitCnt = (uint8_T)(c1_u2 & 15U);
        _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_BitCnt, 3U);
      }
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,5);
    break;

   case c1_IN_IDLE:
    CV_STATE_EVAL(4,0,2);
    _SFD_CS_CALL(STATE_ENTER_DURING_FUNCTION_TAG,6);
    _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,10);
    if (CV_TRANSITION_EVAL(10U, (int32_T)_SFD_CCP_CALL(10,0,(((uint8_T)(*c1_RxD
             & 1U) == 0)!=0))) != 0U != 0) {
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,10);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,6);
      chartInstance.c1_tp_IDLE = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,6);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,6);
      chartInstance.c1_is_RxdPro = (uint8_T)c1_IN_START;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,7);
      chartInstance.c1_tp_START = 1U;
      chartInstance.c1_BitCnt = 1U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_BitCnt, 3U);
    } else {
      _SFD_CT_CALL(TRANSITION_BEFORE_PROCESSING_TAG,11);
      _SFD_CT_CALL(TRANSITION_ACTIVE_TAG,11);
      _SFD_CS_CALL(STATE_ENTER_EXIT_FUNCTION_TAG,6);
      chartInstance.c1_tp_IDLE = 0U;
      _SFD_CS_CALL(STATE_INACTIVE_TAG,6);
      _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,6);
      chartInstance.c1_is_RxdPro = (uint8_T)c1_IN_IDLE;
      _SFD_CS_CALL(STATE_ACTIVE_TAG,6);
      chartInstance.c1_tp_IDLE = 1U;
      chartInstance.c1_BitCnt = 0U;
      _SFD_DATA_RANGE_CHECK((real_T)chartInstance.c1_BitCnt, 3U);
      *c1_Valid = 0U;
      _SFD_DATA_RANGE_CHECK((real_T)*c1_Valid, 4U);
    }

    _SFD_CS_CALL(EXIT_OUT_OF_FUNCTION_TAG,6);
    break;

⌨️ 快捷键说明

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