From d0412a3b476aef55e3866f144f59c57251904f19 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Mon, 6 Oct 2014 16:32:06 +0200 Subject: [PATCH] Include printf block with same interface as RPP SCI block is. --- blocks/sfunction_printf.c | 133 ++++++++++++++++++++++++++++++ blocks/tlc_c/sfunction_printf.tlc | 99 ++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 blocks/sfunction_printf.c create mode 100644 blocks/tlc_c/sfunction_printf.tlc diff --git a/blocks/sfunction_printf.c b/blocks/sfunction_printf.c new file mode 100644 index 0000000..0dcbe90 --- /dev/null +++ b/blocks/sfunction_printf.c @@ -0,0 +1,133 @@ +/* Copyright (C) 2013 Czech Technical University in Prague + * + * Authors: + * - Carlos Jenkins + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * File : sfunction_printf.c + * Abstract: + * C-MEX S-function block for RPP Serial Communication Printf. + * + * References: + * header.c + * trailer.c + * + * Compile with: + * /bin/mex sfunction_printf.c + */ + + +#define S_FUNCTION_NAME sfunction_printf +#include "header.c" + + +static void mdlInitializeSizes(SimStruct *S) +{ + /* + * Configure parameters: 2 + * - Printf format [setting]. + */ + if (!rppSetNumParams(S, 1)) { + return; + } + + /* + * Configure input ports: 1 + * - Data send. + */ + if (!ssSetNumInputPorts(S, 1)) { + return; + } + rppAddInputVectorPort(S, 0, DYNAMICALLY_TYPED, DYNAMICALLY_SIZED); + + /* + * Configure output ports: 1 + * - Error flag. + */ + if (!ssSetNumOutputPorts(S, 1)) { + return; + } + rppAddOutputPort(S, 0, SS_BOOLEAN); + + /* Set standard options for this block */ + rppSetStandardOptions(S); +} + + +#ifdef MATLAB_MEX_FILE +#define MDL_CHECK_PARAMETERS +static void mdlCheckParameters(SimStruct *S) +{ + /* Check the parameter 1 */ + /*if (!rppValidParamBoolean(S, 0)) { + return; + } + + /* Note that parameter 2 is not checked */ +} +#endif + + +#ifdef MATLAB_MEX_FILE +#define MDL_SET_WORK_WIDTHS +static void mdlSetWorkWidths(SimStruct *S) +{ + /* Set number of run-time parameters */ + /*if (!ssSetNumRunTimeParams(S, 1)) { + return; + } + + /* Register the run-time parameter 1 */ + /*ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_BOOLEAN);*/ +} +#endif + + +#ifdef MATLAB_MEX_FILE +#define MDL_RTW +static void mdlRTW(SimStruct* S) +{ + /* Register parameter as a parameter setting */ + static char_T str[128]; + mxGetString(ssGetSFcnParam(S, 0), (char*)&str, sizeof(str)); /* Get string */ + if (!ssWriteRTWParamSettings(S, 1, + SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) { + /* An error ocurred */ + return; + } +} +#endif + + + +#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT +#define UNUSED_MDLOUTPUTS +#define UNUSED_MDLTERMINATE +#include "trailer.c" diff --git a/blocks/tlc_c/sfunction_printf.tlc b/blocks/tlc_c/sfunction_printf.tlc new file mode 100644 index 0000000..43cfb7d --- /dev/null +++ b/blocks/tlc_c/sfunction_printf.tlc @@ -0,0 +1,99 @@ +%% Copyright (C) 2013-2014 Czech Technical University in Prague +%% +%% Authors: +%% - Carlos Jenkins +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are +%% met: +%% +%% 1. Redistributions of source code must retain the above copyright +%% notice, this list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright +%% notice, this list of conditions and the following disclaimer in the +%% documentation and/or other materials provided with the +%% distribution. +%% +%% 3. Neither the name of the copyright holder nor the names of its +%% contributors may be used to endorse or promote products derived +%% from this software without specific prior written permission. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +%% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +%% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +%% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +%% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +%% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +%% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +%% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +%% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +%% +%% File : sfunction_printf.tlc +%% Abstract: +%% TLC file for inlining RPP serial communication interface printf block. +%% +%% References: +%% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277 +%% Start() : refs/rtw_tlc.pdf p. 279 +%% Outputs() : refs/rtw_tlc.pdf p. 281 + + +%implements sfunction_printf "C" + +%include "common.tlc" + + +%% Function: BlockTypeSetup ==================================================== +%function BlockTypeSetup(block, system) void + + %% Ensure required header files are included + % + +%endfunction + + +%% Function: Start ============================================================= +%function Start(block, system) Output + + %if !SLibCodeGenForSim() + %%No initialization needed for this block + %endif + +%endfunction + + +%% Function: Outputs =========================================================== +%function Outputs(block, system) Output + + %if !SLibCodeGenForSim() + + %% %if extMode + %% %return + %% %endif + + %% Get IO signals + %assign data_width = LibBlockInputSignalWidth(0) + %assign err_flag = LibBlockOutputSignal(0, "", "", 0) + + %assign printf_format = SFcnParamSettings.PrintfFormat + if (printf("%", + %foreach loop_i = % + %assign data = LibBlockInputSignal(0, "%", "", 0) + % \ + %if loop_i < (% - 1) + , + %endif + %endforeach + ) >= 0) { + % = FALSE; + } else { + % = TRUE; + } + %endif + +%endfunction + +%% [EOF] -- 2.39.2