]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_cansetup.c
doc: Change formatting of block description in YAML
[jenkicar/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 Bus Configuration
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
53 RPP API functions used:
54     - rpp_can_init()
55
56 Relevant demos:
57     - cantransmit
58     - can_demo
59 ...
60 */
61
62
63 #define S_FUNCTION_NAME sfunction_cansetup
64 #include "header.c"
65 #include <stdio.h> 
66
67 #define BAUDRATE_MIN    1
68 #define BAUDRATE_MAX    10000000
69
70 #define BAUDRATE_CAN1_PARAM_NAME        "baudrate_can1"
71 #define BAUDRATE_CAN2_PARAM_NAME        "baudrate_can2"
72 #define BAUDRATE_CAN3_PARAM_NAME        "baudrate_can3"
73
74 /** Identifiers of the block parameters */
75 enum params{
76         PARAM_CAN1_BAUDRATE,
77         PARAM_CAN2_BAUDRATE,
78         PARAM_CAN3_BAUDRATE,    
79         PARAM_COUNT
80 };
81
82 static void mdlInitializeSizes(SimStruct *S)
83 {
84     if (!rppSetNumParams(S, PARAM_COUNT)) {
85         return;
86     }
87         
88         /* No input ports */
89     if (!ssSetNumInputPorts(S, 0)) {
90         return;
91     }
92  
93         /* No output ports */
94     if (!ssSetNumOutputPorts(S, 0)) {
95         return;
96     }
97  
98     rppSetStandardOptions(S);
99     void CAN_Common_MdlInitSizes(SimStruct *S);
100 }    
101
102
103 #ifdef MATLAB_MEX_FILE
104 #define MDL_CHECK_PARAMETERS
105 static void mdlCheckParameters(SimStruct *S)
106 {
107     /* Check the parameter CAN1 baudrate */
108     if (!rppValidParamRange(S, PARAM_CAN1_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
109         return;
110     }
111     /* Check the parameter CAN2 baudrate */
112     if (!rppValidParamRange(S, PARAM_CAN2_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
113         return;
114     }
115     /* Check the parameter CAN3 baudrate */
116     if (!rppValidParamRange(S, PARAM_CAN3_BAUDRATE, BAUDRATE_MIN, BAUDRATE_MAX)) {
117         return;
118     }
119 }
120 #endif
121
122
123 #ifdef MATLAB_MEX_FILE
124 #define MDL_SET_WORK_WIDTHS
125 static void mdlSetWorkWidths(SimStruct *S)
126 {
127     
128     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
129         return;
130     }
131     
132         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN1_BAUDRATE, PARAM_CAN1_BAUDRATE, BAUDRATE_CAN1_PARAM_NAME, SS_UINT32);     
133         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN2_BAUDRATE, PARAM_CAN2_BAUDRATE, BAUDRATE_CAN2_PARAM_NAME, SS_UINT32);
134         ssRegDlgParamAsRunTimeParam(S, PARAM_CAN3_BAUDRATE, PARAM_CAN3_BAUDRATE, BAUDRATE_CAN3_PARAM_NAME, SS_UINT32);
135 }
136 #endif
137
138 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
139 #define UNUSED_MDLOUTPUTS
140 #define UNUSED_MDLTERMINATE
141 #include "trailer.c"