1 /* Copyright (C) 2014 Czech Technical University in Prague
4 * - Michal Horn <hornmich@fel.cvut.cz>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
18 * 3. Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * File : sfunction_cansetup.c
36 * C-MEX S-function block for RPP CAN bus setup.
43 * <matlabroot>/bin/mex sfunction_cansetup.c
59 - { name: "Baud rate for CAN bus port 1 [bps]", type: "uint32", range: "1 – 10000000" }
60 - { name: "Baud rate for CAN bus port 2 [bps]", type: "uint32", range: "1 – 10000000" }
61 - { name: "Baud rate for CAN bus port 3 [bps]", type: "uint32", range: "1 – 10000000" }
63 # Description is in Markdown mark-up
66 This block configures the CAN bus controllers. Exactly one CAN bus
67 configuration block must be in the model if any of the CAN Receive
68 or CAN Transmit block is used.
72 - Configuring CAN1, CAN2 and CAN3
75 - Receiving at baudrate higher than 700kb
76 - External mode - throwing syntax error during compilation
78 RPP API functions used:
88 #define S_FUNCTION_NAME sfunction_cansetup
92 #define BAUDRATE_MIN 1
93 #define BAUDRATE_MAX 1000000
95 #define BAUDRATE_CAN1_PARAM_NAME "baudrate_can1"
96 #define BAUDRATE_CAN2_PARAM_NAME "baudrate_can2"
97 #define BAUDRATE_CAN3_PARAM_NAME "baudrate_can3"
99 /** Identifiers of the block parameters */
107 static void mdlInitializeSizes(SimStruct *S)
109 if (!rppSetNumParams(S, PARAM_COUNT)) {
114 if (!ssSetNumInputPorts(S, 0)) {
118 /* No output ports */
119 if (!ssSetNumOutputPorts(S, 0)) {
123 rppSetStandardOptions(S);
124 void CAN_Common_MdlInitSizes(SimStruct *S);
128 #ifdef MATLAB_MEX_FILE
129 #define MDL_CHECK_PARAMETERS
130 static void mdlCheckParameters(SimStruct *S)
132 /* Check the parameter CAN1 baudrate */
133 if (!rppValidParamRange(S, PARAM_CAN1_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
136 /* Check the parameter CAN2 baudrate */
137 if (!rppValidParamRange(S, PARAM_CAN2_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
140 /* Check the parameter CAN3 baudrate */
141 if (!rppValidParamRange(S, PARAM_CAN3_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
148 #ifdef MATLAB_MEX_FILE
149 #define MDL_SET_WORK_WIDTHS
150 static void mdlSetWorkWidths(SimStruct *S)
153 if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
157 ssRegDlgParamAsRunTimeParam(S, PARAM_CAN1_BAUDRATE, PARAM_CAN1_BAUDRATE, BAUDRATE_CAN1_PARAM_NAME, SS_UINT32);
158 ssRegDlgParamAsRunTimeParam(S, PARAM_CAN2_BAUDRATE, PARAM_CAN2_BAUDRATE, BAUDRATE_CAN2_PARAM_NAME, SS_UINT32);
159 ssRegDlgParamAsRunTimeParam(S, PARAM_CAN3_BAUDRATE, PARAM_CAN3_BAUDRATE, BAUDRATE_CAN3_PARAM_NAME, SS_UINT32);
163 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
164 #define UNUSED_MDLOUTPUTS
165 #define UNUSED_MDLTERMINATE