]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_lout.c
doc: Change formatting of block description in YAML
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_lout.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_lout.c
12  * Abstract:
13  *     C-MEX S-function block for RPP digital output.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_lout.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Digital Output block
27 Category: IO blocks
28 Header: rpp/lout.h
29 Mnemonic: LOUT
30
31 Inputs:
32   - { name: "Digital Output",   type: "bool"  }
33
34 Outputs:
35   - { name: "ErrFlag",          type: "bool"  }
36
37 Parameters:
38   - { name: "Pin number [1-8]", type: "uint8" }
39
40 # Description is in Markdown mark-up
41 Description: |
42
43   This block allows to write to the digital outputs on the RPP board. The ErrFlag should raise if 
44   `rpp_lout_set()` or `rpp_lout_update()` returns error. Because the ErrFlag should never set, 
45   once set the following steps will never clear it back. `rpp_lout_update()` is called on each 
46   block, which is not the most efficient but guaranties consistent behavior.
47
48 Status:
49   Tested:
50     - Changing the pin.
51     - Compilation and general use.
52   Untested:
53     - Faulty situation for the ErrFlag to set.
54   Not working:
55
56 RPP API functions used:
57     - rpp_lout_set()
58     - rpp_lout_update()
59
60 Relevant demos:
61     - digital_passthrough
62     - led_blink_all
63     - led_blink
64 ...
65 */
66
67 #define S_FUNCTION_NAME sfunction_lout
68 #include "header.c"
69
70
71 static void mdlInitializeSizes(SimStruct *S)
72 {
73     /*
74      * Configure parameters: 1
75      *  - Pin number: [1-8]
76      */
77     if (!rppSetNumParams(S, 1)) {
78         return;
79     }
80
81     /*
82      * Configure input ports: 1
83      *  - Digital output.
84      */
85     if (!ssSetNumInputPorts(S, 1)) {
86         return;
87     }
88     rppAddInputPort(S, 0, SS_BOOLEAN);
89
90     /*
91      * Configure output ports: 1
92      *  - Error flag.
93      */
94     if (!ssSetNumOutputPorts(S, 1)) {
95         return;
96     }
97     rppAddOutputPort(S, 0, SS_BOOLEAN);
98
99     /* Set standard options for this block */
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 1 */
109     if (!rppValidParamRange(S, 0, 1, 8)) {
110         return;
111     }
112 }
113 #endif
114
115
116 #ifdef MATLAB_MEX_FILE
117 #define MDL_SET_WORK_WIDTHS
118 static void mdlSetWorkWidths(SimStruct *S)
119 {
120     /* Set number of run-time parameters */
121     if (!ssSetNumRunTimeParams(S, 1)) {
122         return;
123     }
124
125     /* Register the run-time parameter 1 */
126     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
127 }
128 #endif
129
130
131 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
132 #define UNUSED_MDLOUTPUTS
133 #define UNUSED_MDLTERMINATE
134 #include "trailer.c"