주요 콘텐츠

이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.

임베디드 애플리케이션을 위한 단정밀도 데이터형 지정

단정밀도만 사용하는 코드가 필요한 경우(예: 단정밀도 프로세서를 타깃으로 할 때) 모델 구성 파라미터와 블록 파라미터를 사용하여 모델에 double가 포함되지 않도록 할 수 있습니다.

단정밀도 모델을 설계하고 검증하려면 Validate a Floating-Point Embedded Model를 참조하십시오. Fixed-Point Designer™가 있다면, 단정밀도 변환기 앱을 사용할 수 있습니다(단정밀도 변환기 (Fixed-Point Designer) 참조).

명시되지 않은 데이터형에 대해 single 데이터형을 기본값으로 사용

이 예제는 단정밀도 하드웨어 타깃용으로 생성된 코드에 배정밀도 데이터형이 포함되지 않도록 하는 방법을 보여줍니다.

신호에 상속된 데이터형을 지정했지만, 데이터형 전파 규칙을 통해 해당 신호의 데이터형을 결정할 수 없는 경우, 신호의 데이터형은 기본적으로 double로 설정됩니다. 모델 구성 파라미터를 사용하여 기본 데이터형을 single로 지정할 수 있습니다.

예제 모델 살펴보기

예제 모델 UnderspecifiedDataType을 열고, 생성된 블록 이름이 표시되도록 구성하십시오.

model = 'UnderspecifiedDataType';
load_system(model)
set_param(model,'HideAutomaticNames','off')
open_system(model);

루트 인포트 In2, In3In4데이터형 블록 파라미터로 Inherit: Auto를 지정합니다. 하류 블록들도 상속된 데이터형을 사용합니다.

기본 데이터형으로 double를 사용하여 코드 생성

이 모델은 구성 파라미터 시스템 타깃 파일ert.tlc로 설정된 상태에서 시작되며, 이를 위해서는 Embedded Coder®가 필요합니다. 시스템 타깃 파일grt.tlc로 설정하십시오.

set_param(model,'SystemTargetFile','grt.tlc')

모델에서 코드를 생성합니다.

slbuild(model)
### Searching for referenced models in model 'UnderspecifiedDataType'.
### Total of 1 models to build.
### Starting build procedure for: UnderspecifiedDataType
### Successful completion of build procedure for: UnderspecifiedDataType

Build Summary

Top model targets:

Model                   Build Reason                                         Status                        Build Duration
=========================================================================================================================
UnderspecifiedDataType  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 4.3205s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 4.7684s

코드 생성 리포트에서 UnderspecifiedDataType.h 파일을 확인하십시오. 모델에서 인포트 데이터형이 충분히 명시되지 않았기 때문에, 이 코드에서는 double 데이터형을 사용하여 In2, In3In4 변수를 정의합니다.

cfile = fullfile('UnderspecifiedDataType_grt_rtw',...
    'UnderspecifiedDataType.h');
coder.example.extractLines(cfile,...
    '/* External inputs (root inport signals with default storage) */',...
    '/* External outputs (root outports fed by signals with default storage) */',...
    1, 0);
/* External inputs (root inport signals with default storage) */
typedef struct {
  int8_T In1;                          /* '<Root>/In1' */
  real_T In2;                          /* '<Root>/In2' */
  real_T In3;                          /* '<Root>/In3' */
  real_T In4;                          /* '<Root>/In4' */
} ExtU_UnderspecifiedDataType_T;

기본 데이터형으로 single를 사용하여 코드 생성

구성 파라미터 대화 상자를 엽니다. 수학 및 데이터형 창에서 명시되지 않은 데이터형의 기본값 드롭다운 목록에서 single를 선택합니다.

또는 명령 프롬프트에서 최적화 기능을 활성화하십시오.

set_param(model, 'DefaultUnderspecifiedDataType', 'single');

모델에서 코드를 생성합니다.

slbuild(model)
### Searching for referenced models in model 'UnderspecifiedDataType'.
### Total of 1 models to build.
### Starting build procedure for: UnderspecifiedDataType
### Successful completion of build procedure for: UnderspecifiedDataType

Build Summary

Top model targets:

Model                   Build Reason                     Status                        Build Duration
=====================================================================================================
UnderspecifiedDataType  Generated code was out of date.  Code generated and compiled.  0h 0m 3.4688s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 3.8957s

코드 생성 리포트에서 UnderspecifiedDataType.h 파일을 확인하십시오. 이 코드는 single 데이터형을 사용하여 In2, In3, In4 변수를 정의합니다.

coder.example.extractLines(cfile,...
    '/* External inputs (root inport signals with default storage) */',...
    '/* External outputs (root outports fed by signals with default storage) */',...
    1, 0);
/* External inputs (root inport signals with default storage) */
typedef struct {
  int8_T In1;                          /* '<Root>/In1' */
  real32_T In2;                        /* '<Root>/In2' */
  real32_T In3;                        /* '<Root>/In3' */
  real32_T In4;                        /* '<Root>/In4' */
} ExtU_UnderspecifiedDataType_T;

참고 항목

도움말 항목