]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_mout.c
doc: Update documentation of external mode and related stuff
[pes-rpp/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 and Help is in Markdown mark-up
41 Description: &desc |
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 Help: *desc
51
52 Status: Stable
53
54 RPP API functions used:
55     - rpp_mout_set()
56
57 Relevant demos:
58     - power_toggle
59 ...
60 */
61
62 #define S_FUNCTION_NAME sfunction_mout
63 #include "header.c"
64
65
66 static void mdlInitializeSizes(SimStruct *S)
67 {
68     /*
69      * Configure parameters: 1
70      *  - Pin number: [1-6]
71      */
72     if (!rppSetNumParams(S, 1)) {
73         return;
74     }
75
76     /*
77      * Configure input ports: 1
78      *  - Power output.
79      */
80     if (!ssSetNumInputPorts(S, 1)) {
81         return;
82     }
83     rppAddInputPort(S, 0, SS_BOOLEAN);
84
85     /*
86      * Configure output ports: 1
87      *  - Error flag.
88      */
89     if (!ssSetNumOutputPorts(S, 1)) {
90         return;
91     }
92     rppAddOutputPort(S, 0, SS_BOOLEAN);
93
94     /* Set standard options for this block */
95     rppSetStandardOptions(S);
96 }
97
98
99 #ifdef MATLAB_MEX_FILE
100 #define MDL_CHECK_PARAMETERS
101 static void mdlCheckParameters(SimStruct *S)
102 {
103     /* Check the parameter 1 */
104     if (!rppValidParamRange(S, 0, 1, 6)) {
105         return;
106     }
107 }
108 #endif
109
110
111 #ifdef MATLAB_MEX_FILE
112 #define MDL_SET_WORK_WIDTHS
113 static void mdlSetWorkWidths(SimStruct *S)
114 {
115     /* Set number of run-time parameters */
116     if (!ssSetNumRunTimeParams(S, 1)) {
117         return;
118     }
119
120     /* Register the run-time parameter 1 */
121     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
122 }
123 #endif
124
125
126 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
127 #define UNUSED_MDLOUTPUTS
128 #define UNUSED_MDLTERMINATE
129 #include "trailer.c"