주요 콘텐츠

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

부울 데이터를 비트필드로 묶어 코드 생성을 최적화하기

이 예제는 부울 데이터를 비트필드로 묶어 코드 생성을 최적화하는 방법을 보여줍니다. 모델 구성 파라미터 부울 데이터를 비트필드로 압축을 선택하면, Embedded Coder®는 부울 신호를 1비트 비트필드로 압축하여 RAM 사용량을 줄입니다. 기본적으로 최적화 기능이 활성화되어 있습니다. 이 최적화를 통해 RAM 사용량이 줄어듭니다. 이 최적화는 코드 크기와 실행 시간을 증가시킬 수 있으므로 유의하시기 바랍니다.

예제 모델

PackBooleanData 모델을 고려해 보자.

model = 'PackBooleanData';
open_system(model);

최적화 비활성화

  1. 구성 파라미터 대화 상자를 엽니다.

  2. 최적화 창에서 부울 데이터를 비트필드로 묶기를 선택 해제합니다.

또는 명령줄 API를 사용하여 최적화를 비활성화할 수도 있습니다:

set_param(model,'BooleansAsBitfields','off');

최적화 없이 코드 생성하기

Embedded Coder를 사용하여 모델을 빌드합니다.

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

Build Summary

Top model targets:

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

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

최적화가 적용되지 않은 생성된 코드를 확인합니다. 이 코드 라인들은 PackBooleanData.h에 있습니다.

hfile = fullfile('PackBooleanData_ert_rtw','PackBooleanData.h');
coder.example.extractLines(hfile,'/* Block signals and states','/* External inputs',1,0);
/* Block signals and states (default storage) for system '<Root>' */
typedef struct {
  boolean_T LogicalOp1;                /* '<Root>/Logical Op1' */
  boolean_T LogicalOp2;                /* '<Root>/Logical Op2' */
  boolean_T LogicalOp5;                /* '<Root>/Logical Op5' */
  boolean_T LogicalOp3;                /* '<Root>/Logical Op3' */
  boolean_T LogicalOp4;                /* '<Root>/Logical Op4' */
  boolean_T RelationalOperator;        /* '<Root>/Relational Operator' */
  boolean_T UnitDelay_DSTATE;          /* '<Root>/Unit Delay' */
} DW;

최적화 활성화

  1. 구성 파라미터 대화 상자를 엽니다.

  2. 최적화 창에서 부울 데이터를 비트필드로 압축을 선택합니다.

또는 명령줄 API를 사용하여 최적화를 활성화할 수도 있습니다:

set_param(model,'BooleansAsBitfields','on');

최적화를 적용하여 코드 생성

Embedded Coder를 사용하여 모델을 빌드합니다.

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

Build Summary

Top model targets:

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

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

최적화가 적용된 생성된 코드를 확인합니다. 이 코드 라인들은 PackBooleanData.h에 있습니다.

hfile = fullfile('PackBooleanData_ert_rtw','PackBooleanData.h');
coder.example.extractLines(hfile,'/* Block signals and states','/* External inputs',1,0);
/* Block signals and states (default storage) for system '<Root>' */
typedef struct {
  struct {
    uint_T LogicalOp1 : 1;             /* '<Root>/Logical Op1' */
    uint_T LogicalOp2 : 1;             /* '<Root>/Logical Op2' */
    uint_T LogicalOp5 : 1;             /* '<Root>/Logical Op5' */
    uint_T LogicalOp3 : 1;             /* '<Root>/Logical Op3' */
    uint_T LogicalOp4 : 1;             /* '<Root>/Logical Op4' */
    uint_T RelationalOperator : 1;     /* '<Root>/Relational Operator' */
    uint_T UnitDelay_DSTATE : 1;       /* '<Root>/Unit Delay' */
  } bitsForTID0;
} DW;

부울 데이터를 비트필드로 묶기를 선택하면 모델 파라미터 비트필드 선언자 유형 지정자가 활성화됩니다. 코드를 더욱 최적화하려면 uchar_t를 선택합니다. 그러나 비트필드 선언자 유형 지정자 설정의 최적화 효과는 선택한 타깃에 따라 달라집니다.

모델 및 코드 생성 리포트를 닫으십시오.

bdclose(model)

참고 항목

도움말 항목