]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_cansetup.c
Remove unnecessary CAN_Common_MdlInitSizes call
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_cansetup.c
1 /* Copyright (C) 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Michal Horn <hornmich@fel.cvut.cz>
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : sfunction_cansetup.c
12  * Abstract:
13  *     C-MEX S-function block for RPP CAN bus setup.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_cansetup.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: CAN Setup
27 Category: CAN
28 Header: rpp/can.h
29 Mnemonic: CANC
30
31 Inputs:
32
33 Outputs:
34
35 Parameters:
36   - { name: "Baud rate for CAN bus port 1 [bps]", type: "uint32", range: "1 – 10000000" }
37   - { name: "Baud rate for CAN bus port 2 [bps]", type: "uint32", range: "1 – 10000000" }
38   - { name: "Baud rate for CAN bus port 3 [bps]", type: "uint32", range: "1 – 10000000" }
39
40 # Description is in Markdown mark-up
41 Description: |
42
43   This block configures the CAN bus controllers. Exactly one CAN bus
44   configuration block must be in the model if any of the CAN Receive
45   or CAN Transmit block is used.
46
47 Status:
48   Tested:
49     - Configuring CAN1, CAN2 and CAN3
50   Untested:
51   Not working:
52     - Receiving at baudrate higher than 700kb
53     - External mode - throwing syntax error during compilation
54
55 RPP API functions used:
56     - rpp_can_init()
57
58 Relevant demos:
59     - cantransmit
60     - can_demo
61 ...
62 */
63
64
65 #define S_FUNCTION_NAME sfunction_cansetup
66 #include "header.c"
67 #include <stdio.h> 
68
69 #define BAUDRATE_MIN    1
70 #define BAUDRATE_MAX    1000000
71
72 #define BAUDRATE_CAN1_PARAM_NAME        "baudrate_can1"
73 #define BAUDRATE_CAN2_PARAM_NAME        "baudrate_can2"
74 #define BAUDRATE_CAN3_PARAM_NAME        "baudrate_can3"
75
76 /** Identifiers of the block parameters */
77 enum params{
78         PARAM_CAN1_BAUDRATE,
79         PARAM_CAN2_BAUDRATE,
80         PARAM_CAN3_BAUDRATE,    
81         PARAM_COUNT
82 };
83
84 static void mdlInitializeSizes(SimStruct *S)
85 {
86     if (!rppSetNumParams(S, PARAM_COUNT)) {
87         return;
88     }
89         
90         /* No input ports */
91     if (!ssSetNumInputPorts(S, 0)) {
92         return;
93     }
94  
95         /* No output ports */
96     if (!ssSetNumOutputPorts(S, 0)) {
97         return;
98     }
99  
100     rppSetStandardOptions(S);
101 }    
102
103
104 #ifdef MATLAB_MEX_FILE
105 #define MDL_CHECK_PARAMETERS
106 static void mdlCheckParameters(SimStruct *S)
107 {
108     /* Check the parameter CAN1 baudrate */
109     if (!rppValidParamRange(S, PARAM_CAN1_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
110         return;
111     }
112     /* Check the parameter CAN2 baudrate */
113     if (!rppValidParamRange(S, PARAM_CAN2_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
114         return;
115     }
116     /* Check the parameter CAN3 baudrate */
117     if (!rppValidParamRange(S, PARAM_CAN3_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
118         return;
119     }
120 }
121 #endif
122
123
124 #ifdef MATLAB_MEX_FILE
125 #define MDL_SET_WORK_WIDTHS
126 static void mdlSetWorkWidths(SimStruct *S)
127 {
128     
129     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
130         return;
131     }
132     
133         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN1_BAUDRATE, PARAM_CAN1_BAUDRATE, BAUDRATE_CAN1_PARAM_NAME, SS_UINT32);     
134         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN2_BAUDRATE, PARAM_CAN2_BAUDRATE, BAUDRATE_CAN2_PARAM_NAME, SS_UINT32);
135         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN3_BAUDRATE, PARAM_CAN3_BAUDRATE, BAUDRATE_CAN3_PARAM_NAME, SS_UINT32);
136 }
137 #endif
138
139 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
140 #define UNUSED_MDLOUTPUTS
141 #define UNUSED_MDLTERMINATE
142 #include "trailer.c"