]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_lout.c
doc: Change YAML field Status to simple string
[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", type: "uint8", range: "[1-8]" }
39
40 # Description and Help is in Markdown mark-up
41 Description: |
42
43   Sends the digital value to the specified logic output pin on the RPP
44   board.
45
46   An input of 1 sets the pin high and 0 sets the pin low.
47
48   If an error is detected while setting the pin, the ErrFlag is set
49   high.
50
51 Help: |
52
53   This block allows to write to the digital outputs on the RPP board. The ErrFlag should raise if 
54   `rpp_lout_set()` or `rpp_lout_update()` returns error. Because the ErrFlag should never set, 
55   once set the following steps will never clear it back. `rpp_lout_update()` is called on each 
56   block, which is not the most efficient but guaranties consistent behavior.
57
58 Status: Stable
59
60 RPP API functions used:
61     - rpp_lout_set()
62     - rpp_lout_update()
63
64 Relevant demos:
65     - digital_passthrough
66     - led_blink_all
67     - led_blink
68 ...
69 */
70
71 #define S_FUNCTION_NAME sfunction_lout
72 #include "header.c"
73
74
75 static void mdlInitializeSizes(SimStruct *S)
76 {
77     /*
78      * Configure parameters: 1
79      *  - Pin number: [1-8]
80      */
81     if (!rppSetNumParams(S, 1)) {
82         return;
83     }
84
85     /*
86      * Configure input ports: 1
87      *  - Digital output.
88      */
89     if (!ssSetNumInputPorts(S, 1)) {
90         return;
91     }
92     rppAddInputPort(S, 0, SS_BOOLEAN);
93
94     /*
95      * Configure output ports: 1
96      *  - Error flag.
97      */
98     if (!ssSetNumOutputPorts(S, 1)) {
99         return;
100     }
101     rppAddOutputPort(S, 0, SS_BOOLEAN);
102
103     /* Set standard options for this block */
104     rppSetStandardOptions(S);
105 }
106
107
108 #ifdef MATLAB_MEX_FILE
109 #define MDL_CHECK_PARAMETERS
110 static void mdlCheckParameters(SimStruct *S)
111 {
112     /* Check the parameter 1 */
113     if (!rppValidParamRange(S, 0, 1, 8)) {
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     /* Set number of run-time parameters */
125     if (!ssSetNumRunTimeParams(S, 1)) {
126         return;
127     }
128
129     /* Register the run-time parameter 1 */
130     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
131 }
132 #endif
133
134
135 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
136 #define UNUSED_MDLOUTPUTS
137 #define UNUSED_MDLTERMINATE
138 #include "trailer.c"