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