]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_mout.c
f4194bbf43d5f0dbd91d59480ac576c6c4145aad
[jenkicar/rpp-simulink.git] / rpp / blocks / sfunction_mout.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
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_mout.c
12  * Abstract:
13  *     C-MEX S-function block for RPP power output.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_mout.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Power Output
27 Category: Power output blocks
28 Header: rpp/mout.h
29 Mnemonic: MOUT
30
31 Inputs:
32   - { name: "Power Output", type: "bool" }
33
34 Outputs:
35   - { name: "ErrFlag", type: "bool" }
36
37 Parameters:
38   - { name: "Pin number [1-6]", type: "uint8" }
39
40 # Description is in Markdown mark-up
41 Description: |
42
43   This block allows to write the power outputs (2A) on the RPP board. The ErrFlag should raise only 
44   if `rpp_mout_set()` returns error. Note that `rpp_mout_set()` returns error only if some bad 
45   parameter or in case it could detect a faulty condition on the pin in a very very short period of 
46   time after setting the value, see the function API for details. If the faulty condition persist on 
47   the next step the call will successfully detect the faulty condition and ErrFlag should set. 
48   Because the ErrFlag should never set, once set the following steps will never clear it back.
49
50 Status:
51   Tested:
52     - Changing the pin.
53     - Compilation and general use.
54   Untested:
55     - Faulty situation for the ErrFlag to set.
56   Not working:
57
58 RPP API functions used:
59     - rpp_mout_set()
60
61 Relevant demos:
62     - power_toggle
63 ...
64 */
65
66 #define S_FUNCTION_NAME sfunction_mout
67 #include "header.c"
68
69
70 static void mdlInitializeSizes(SimStruct *S)
71 {
72     /*
73      * Configure parameters: 1
74      *  - Pin number: [1-6]
75      */
76     if (!rppSetNumParams(S, 1)) {
77         return;
78     }
79
80     /*
81      * Configure input ports: 1
82      *  - Power output.
83      */
84     if (!ssSetNumInputPorts(S, 1)) {
85         return;
86     }
87     rppAddInputPort(S, 0, SS_BOOLEAN);
88
89     /*
90      * Configure output ports: 1
91      *  - Error flag.
92      */
93     if (!ssSetNumOutputPorts(S, 1)) {
94         return;
95     }
96     rppAddOutputPort(S, 0, SS_BOOLEAN);
97
98     /* Set standard options for this block */
99     rppSetStandardOptions(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 1 */
108     if (!rppValidParamRange(S, 0, 1, 6)) {
109         return;
110     }
111 }
112 #endif
113
114
115 #ifdef MATLAB_MEX_FILE
116 #define MDL_SET_WORK_WIDTHS
117 static void mdlSetWorkWidths(SimStruct *S)
118 {
119     /* Set number of run-time parameters */
120     if (!ssSetNumRunTimeParams(S, 1)) {
121         return;
122     }
123
124     /* Register the run-time parameter 1 */
125     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
126 }
127 #endif
128
129
130 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
131 #define UNUSED_MDLOUTPUTS
132 #define UNUSED_MDLTERMINATE
133 #include "trailer.c"