📄 s0_usertel_rxd.tlc
字号:
%% File : s0_userTel_rxd.tlc
%%
%%
%implements s0_userTel_rxd "C"
%%
%% P1 SAMPLE_TIME_ARG /* Sample time in seconds */
%% P2 CHANNEL_NO_ARG /* communication channel number (up to MAX_UCOM_CHANNELS) */
%% P3 NUM_ELEMENTS_ARG /* block output width -> # of elements */
%% P4 DATA_TYPE_ARG /* data type to be expected at block input */
%% add required include files... -- fw-03-05
%<LibAddToCommonIncludes("<stdlib.h>")>
%<LibAddToCommonIncludes("<mc9s12dp256.h>")>
%<LibAddToCommonIncludes("tmwtypes.h")>
%<LibAddToCommonIncludes("s0_usertel.h")>
%% Function: BlockTypeSetup =================================================
%%
%% Purpose:
%% User telegram communication block setup code.
%%
%function BlockTypeSetup(block, system) void
%% Place function prototypes in the model's header file
%openfile buffer
extern myUsrBuf *AllocateUserBuffer(uint_T channel, uint16_T bufsize, uint8_T data_type_len);
%closefile buffer
%<LibCacheFunctionPrototype(buffer)>
%endfunction
%% Function: Start ==========================================================
%%
%% Purpose:
%% User telegram communication initialization code.
%%
%function Start(block, system) Output
%assign CHANNEL_NO = %<CAST( "Number", LibBlockParameterValue(P2,1) )>
%assign NUM_ELEMENTS = %<CAST( "Number", LibBlockParameterValue(P3,1) )>
%assign DATA_TYPE = %<CAST( "Number", LibBlockParameterValue(P4,1) )>
%assign BuiltInDTypesSizes = [4, 1, 1, 2, 2, 4, 4, 2]
%assign DATA_TYPE_LEN = %<BuiltInDTypesSizes>[%<DATA_TYPE>-1]
%assign BUF_SIZE = %<DATA_TYPE_LEN> * %<NUM_ELEMENTS>
%assign pAdminStruct = LibBlockPWork("", "", "", 0)
/* S-Function "s0_userTel_rxd" initialization Block: %<Name> */
{
myUsrBuf *admin;
/* allocate memory for buffer (BUF_SIZE bytes) and its admin structure, returns the access pointer */
if((admin = AllocateUserBuffer(%<CHANNEL_NO>, %<BUF_SIZE>, %<DATA_TYPE_LEN>)) == NULL) abort_LED(34);
/* store the access pointer in the workspace variable */
userTelBuf[%<CHANNEL_NO>] = admin;
/* retain a local copy for fast access */
%<pAdminStruct> = admin;
}
%endfunction
%% Function: Outputs ==========================================================
%%
%% Purpose:
%% Code generation rules for mdlOutputs function.
%%
%function Outputs(block, system) Output
%assign pAdminStruct = LibBlockPWork("", "", "", 0)
%assign y = LibBlockOutputSignal(0, "", "", 0)
/* S-Function "s0_userTel_rxd" Block: %<Name> */
{
myUsrBuf *admin = %<pAdminStruct>;
/* check 'buffer full' flag */
if(admin->buffer_full == 1) {
uint16_T size = (uint16_T)admin->buf_size;
uint8_T *buf = (uint8_T *)&(admin->buf[4]);
uint8_T *blockOutput = (uint8_T *)&%<y>;
/* new data for this instance available -> copy data to the block outputs (data begins at index 4) */
(void)memcpy(blockOutput, buf, size);
/* reset 'buffer full flag' */
admin->buffer_full = 0;
}
}
%endfunction
%% Function: Terminate ==========================================================
%%
%% Purpose:
%% Code generation rules for mdlTerminate function.
%%
%function Terminate(block, system) Output
%assign pAdminStruct = LibBlockPWork("", "", "", 0)
%assign CHANNEL_NO = %<CAST( "Number", LibBlockParameterValue(P2,1) )>
/* free instance local data buffer */
#ifdef ALLOCDEBUG
SCI0_OutString("mdlTerminate - userTel (1/2) : freeing [unknown] number of bytes (admin->buf).\n\r");
#endif
(void)free(((myUsrBuf *)%<pAdminStruct>)->buf);
#ifdef ALLOCDEBUG
SCI0_OutString("mdlTerminate - userTel (2/2) : freeing [unknown] number of bytes (admin).\n\r");
#endif
(void)free((myUsrBuf *)%<pAdminStruct>);
/* reset global buffer access pointer to NULL */
userTelBuf[%<CHANNEL_NO>] = NULL;
%endfunction
%% [EOF] s0_userTel_sfcn_9S12.tlc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -