주요 콘텐츠

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

coder.mapping.api.CodeMapping

C 코드 생성을 위한 모델 데이터 및 함수 인터페이스 구성

    설명

    코드 매핑 객체와 관련 함수를 사용하면 Simulink® 모델의 데이터에 대한 C 코드 생성을 구성할 수 있습니다. 모델 데이터 요소의 경우, 코드 매핑을 통해 데이터 요소를 스토리지 클래스 및 스토리지 클래스 속성으로 구성된 구성과 연결합니다. 모델 전반에 걸쳐 데이터 요소 범주별 기본 구성을 지정함으로써 C 코드 생성을 위한 모델 준비에 드는 수고를 줄일 수 있습니다. 데이터 요소를 개별적으로 구성하여 기본 설정을 재정의하십시오. 더 작은 모델의 경우, 각 데이터 요소를 개별적으로 구성할 수 있습니다.

    생성

    Simulink 편집기의 앱 탭에서 Simulink CoderEmbedded Coder와 같은 코드 생성 앱을 선택하면, 코드 매핑이 아직 존재하지 않는 경우 해당 앱이 coder.mapping.api.CodeMapping 객체를 생성합니다. 이 앱은 모델의 활성 구성 세트 객체에 저장된 코드 사용자 지정 설정을 기반으로 코드 매핑을 생성합니다. 구성 세트 객체는 데이터 및 함수를 위한 메모리 섹션을 지정할 수 있습니다.

    coder.mapping.utils.create 함수를 호출하여 프로그래밍 방식으로 coder.mapping.api.CodeMapping 객체를 생성합니다.

    객체 함수

    addSignalAdd block output signal to model code mappings
    coder.mapping.api.getGet code mappings for model
    coder.mapping.utils.createCreate code mappings object for configuring data and function interface for C and C++ code generation
    findGet model elements for the category of model code mappings
    getDataDefaultGet default storage class or storage class property setting for model data category
    getDataStoreGet code and calibration configuration from code mappings for local or shared local data store
    getInportGet code and calibration configuration from code mappings for root-level inport
    getModelParameterGet code and calibration configuration from code mappings for model parameters
    getModelVariantControlGet code configuration from code mappings for Simulink.VariantControl object
    getModelVariantVariableGet code configuration from code mappings for Simulink.VariantVariable object
    getOutportGet code and calibration configuration from code mappings for root-level outport
    getSignalGet code and calibration configuration from code mappings for block output signal
    getStateGet code and calibration configuration from code mappings for block state
    removeSignalRemove block output signal from model code mappings
    setDataDefaultSet default storage class and storage class property values for model data category
    setDataStoreConfigure local or shared local data store for code and calibration file (a2l) generation
    setInportConfigure root-level inports for code and calibration file (a2l) generation
    setModelParameterConfigure model parameter for code and calibration file (a2l) generation
    setModelVariantControlConfigure Simulink.VariantControl object for code generation
    setOutportConfigure root-level outport for code and calibration file (a2l) generation
    setSignalConfigure block signal data for code and calibration file (a2l) generation
    setStateConfigure block states for code and calibration file (a2l) generation

    예제

    모두 축소

    프로그래밍 인터페이스를 사용하여 Simulink 모델의 코드 매핑 객체를 생성하고 사용하십시오.

    NoCoderMapping 모델을 불러옵니다.

    simulinkModel = "NoCoderMapping";
    load_system(simulinkModel);

    try-catch 블록을 사용하여 해당 모델에 대한 코드 매핑 객체가 존재하는지 확인합니다. try 블록 내에서 coder.mapping.api.get 함수를 사용하여 기존 객체를 가져오려고 시도합니다. catch 블록 내에서 coder.mapping.utils.create 함수를 사용하여 새로운 코드 매핑 객체를 생성합니다. 코드 매핑 객체를 codeMapObj 변수에 저장합니다.

    모델에 기존 코드 매핑 객체가 있는지 여부를 표시하는 출력 메시지를 추가합니다.

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ...
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ==========================================
     The model does not have code mappings.
     Creating new code mappings for the model.
     ==========================================
    

    모델의 입력 포트 inport_1의 스토리지 클래스를 가져옵니다.

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'Auto'
    

    입력 포트 inport_1의 스토리지 클래스를 ExportedGlobal로 설정하십시오.

    setInport(codeMapObj,"inport_1",StorageClass="ExportedGlobal")

    동일한 try-catch 블록을 사용하여 coder.mapping.api.get 함수가 이제 모델의 기존 코드 매핑을 어떻게 가져올 수 있는지 확인합니다.

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ...
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ========================================================
     The model already had code mappings.
     ========================================================
    

    모델의 입력 포트 inport_1의 스토리지 클래스를 가져옵니다. 이것이 바로 앞서 설정했던 스토리지 클래스라는 점에 유의하십시오.

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'ExportedGlobal'
    

    모델을 저장하지 않고 닫습니다.

    close_system(simulinkModel,false)

    버전 내역

    R2020b에 개발됨

    모두 확장