+/* Copyright (C) 2014 Czech Technical University in Prague
+ *
+ * Authors:
+ * - Michal Horn <hornmich@fel.cvut.cz>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * File : sfunction_cansetup.c
+ * Abstract:
+ * C-MEX S-function block for RPP CAN bus setup.
+ *
+ * References:
+ * header.c
+ * trailer.c
+ *
+ * Compile with:
+ * <matlabroot>/bin/mex sfunction_cansetup.c
+ */
+
+/*
+%YAML 1.2
+---
+Name: CAN Setup
+Category: CAN
+Header: rpp/can.h
+Mnemonic: CANC
+
+Inputs:
+
+Outputs:
+
+Parameters:
+ - { name: "CAN1 baud rate in bps", type: "uint32", range: "1 – 10000000" }
+ - { name: "CAN2 baud rate in bps", type: "uint32", range: "1 – 10000000" }
+ - { name: "CAN3 baud rate in bps", type: "uint32", range: "1 – 10000000" }
+
+# Description and Help is in Markdown mark-up
+Description: &desc |
+
+ This block configures the CAN bus controllers. Exactly one CAN bus
+ configuration block must be in the model if any of the CAN Receive
+ or CAN Transmit block is used.
+
+Help: *desc
+
+Status: Stable
+
+RPP API functions used:
+ - rpp_can_init()
+
+Relevant demos:
+ - cantransmit
+ - can_demo
+...
+*/
+
+
#define S_FUNCTION_NAME sfunction_cansetup
#include "header.c"
#include <stdio.h>
+#define BAUDRATE_MIN 1
+#define BAUDRATE_MAX 1000000
+
+#define BAUDRATE_CAN1_PARAM_NAME "baudrate_can1"
+#define BAUDRATE_CAN2_PARAM_NAME "baudrate_can2"
+#define BAUDRATE_CAN3_PARAM_NAME "baudrate_can3"
+
+/** Identifiers of the block parameters */
enum params{
- baudrate_can1_idx = 0,
- baudrate_can2_idx = 1,
- baudrate_can3_idx = 2,
+ PARAM_CAN1_BAUDRATE,
+ PARAM_CAN2_BAUDRATE,
+ PARAM_CAN3_BAUDRATE,
PARAM_COUNT
};
-
static void mdlInitializeSizes(SimStruct *S)
{
if (!rppSetNumParams(S, PARAM_COUNT)) {
return;
}
-
+
+ /* No input ports */
if (!ssSetNumInputPorts(S, 0)) {
return;
}
+ /* No output ports */
if (!ssSetNumOutputPorts(S, 0)) {
return;
}
rppSetStandardOptions(S);
- void CAN_Common_MdlInitSizes(SimStruct *S);
}
#define MDL_CHECK_PARAMETERS
static void mdlCheckParameters(SimStruct *S)
{
-
+ /* Check the parameter CAN1 baudrate */
+ if (!rppValidParamRange(S, PARAM_CAN1_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
+ return;
+ }
+ /* Check the parameter CAN2 baudrate */
+ if (!rppValidParamRange(S, PARAM_CAN2_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
+ return;
+ }
+ /* Check the parameter CAN3 baudrate */
+ if (!rppValidParamRange(S, PARAM_CAN3_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
+ return;
+ }
}
#endif
return;
}
- ssRegDlgParamAsRunTimeParam(S, baudrate_can1_idx, baudrate_can1_idx, "baudrate_can1", SS_UINT32);
- ssRegDlgParamAsRunTimeParam(S, baudrate_can2_idx, baudrate_can2_idx, "baudrate_can2", SS_UINT32);
- ssRegDlgParamAsRunTimeParam(S, baudrate_can3_idx, baudrate_can3_idx, "baudrate_can3", SS_UINT32);
+ ssRegDlgParamAsRunTimeParam(S, PARAM_CAN1_BAUDRATE, PARAM_CAN1_BAUDRATE, BAUDRATE_CAN1_PARAM_NAME, SS_UINT32);
+ ssRegDlgParamAsRunTimeParam(S, PARAM_CAN2_BAUDRATE, PARAM_CAN2_BAUDRATE, BAUDRATE_CAN2_PARAM_NAME, SS_UINT32);
+ ssRegDlgParamAsRunTimeParam(S, PARAM_CAN3_BAUDRATE, PARAM_CAN3_BAUDRATE, BAUDRATE_CAN3_PARAM_NAME, SS_UINT32);
}
#endif