how to define my own function in my block.tlc?

1 view (last 30 days)
hello,everyone,i am developing blocks with S-function and tlc files, i need to write my own function in the block.tlc file. i don't know how to write it,can anybody help me ? thanks in advance The block.tlc file is like this:
%implements mpc5634_sci "C"
%function BlockTypeSetup(block, system) void
%assign scia_dfm_idx = CAST("Number",SFcnParamSettings.scia_dfm)
%assign scib_dfm_idx = CAST("Number",SFcnParamSettings.scib_dfm)
%switch scia_dfm_idx
%case 1
%assign scia_dfm = 8
%break
%case 2
%assign scia_dfm = 9
%break
%case 3
%assign scia_dfm = 12
%break
%case 4
%assign scia_dfm = 13
%break
%endswitch
%switch scib_dfm_idx
%case 1
%assign scib_dfm = 8
%break
%case 2
%assign scib_dfm = 9
%break
%case 3
%assign scib_dfm = 12
%break
%case 4
%assign scib_dfm = 13
%break
%endswitch
%openfile tmp
/************************SCI***************************************************/
#define SCIA_FORMATMODE_MD (U08)%<scia_dfm>
#define SCIB_FORMATMODE_MD (U08)%<scib_dfm>
%closefile tmp
%assign cFile = LibCreateSourceFile("Header", "Custom", "interfunc_cfg")
%<LibSetSourceFileSection(cFile, "Defines", tmp)>\
%endfunction
i want to take the following part out of this function,and define a new function for it. how should i write the function? i've searched it for several times, but i still can't get it.
%switch scia_dfm_idx
%case 1
%assign scia_dfm = 8
%break
%case 2
%assign scia_dfm = 9
%break
%case 3
%assign scia_dfm = 12
%break
%case 4
%assign scia_dfm = 13
%break
%endswitch

Answers (1)

Prateekshya
Prateekshya on 8 Oct 2024
Hello Lisa,
TLC files are used to specify how a block should be translated into code during code generation.TLC syntax is somewhat similar to C but with its own set of commands and functions. Functions in TLC are defined using the %function directive. You can pass arguments to the function and use them within the function body. TLC provides various commands for control flow, variable handling, etc., such as %if, %assign, %return, %include, etc.
To know more about S-Function and TLC files, please follow this link: https://www.mathworks.com/help/rtw/ug/write-wrapper-s-function-and-tlc-files.html
I hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!