]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_lout.c
doc: Introduce Help field in YAML doc
[jenkicar/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
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 and Help is in Markdown mark-up
41 Description: &desc |
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 Help: *desc
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_lout_set()
60     - rpp_lout_update()
61
62 Relevant demos:
63     - digital_passthrough
64     - led_blink_all
65     - led_blink
66 ...
67 */
68
69 #define S_FUNCTION_NAME sfunction_lout
70 #include "header.c"
71
72
73 static void mdlInitializeSizes(SimStruct *S)
74 {
75     /*
76      * Configure parameters: 1
77      *  - Pin number: [1-8]
78      */
79     if (!rppSetNumParams(S, 1)) {
80         return;
81     }
82
83     /*
84      * Configure input ports: 1
85      *  - Digital output.
86      */
87     if (!ssSetNumInputPorts(S, 1)) {
88         return;
89     }
90     rppAddInputPort(S, 0, SS_BOOLEAN);
91
92     /*
93      * Configure output ports: 1
94      *  - Error flag.
95      */
96     if (!ssSetNumOutputPorts(S, 1)) {
97         return;
98     }
99     rppAddOutputPort(S, 0, SS_BOOLEAN);
100
101     /* Set standard options for this block */
102     rppSetStandardOptions(S);
103 }
104
105
106 #ifdef MATLAB_MEX_FILE
107 #define MDL_CHECK_PARAMETERS
108 static void mdlCheckParameters(SimStruct *S)
109 {
110     /* Check the parameter 1 */
111     if (!rppValidParamRange(S, 0, 1, 8)) {
112         return;
113     }
114 }
115 #endif
116
117
118 #ifdef MATLAB_MEX_FILE
119 #define MDL_SET_WORK_WIDTHS
120 static void mdlSetWorkWidths(SimStruct *S)
121 {
122     /* Set number of run-time parameters */
123     if (!ssSetNumRunTimeParams(S, 1)) {
124         return;
125     }
126
127     /* Register the run-time parameter 1 */
128     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
129 }
130 #endif
131
132
133 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
134 #define UNUSED_MDLOUTPUTS
135 #define UNUSED_MDLTERMINATE
136 #include "trailer.c"