]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_lout.c
Move documentation from Tex to s-function source files.
[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
33     type: bool
34
35 Outputs:
36   - name: ErrFlag
37     type: bool
38
39 Parameters:
40   - name: Pin number [1-8]
41     type: uint8
42
43 # Description is in Markdown mark-up
44 Description: >
45
46   This block allows to write to the digital outputs on the RPP board. The ErrFlag should raise if 
47   `rpp_lout_set()` or `rpp_lout_update()` returns error. Because the ErrFlag should never set, 
48   once set the following steps will never clear it back. `rpp_lout_update()` is called on each 
49   block, which is not the most efficient but guaranties consistent behavior.
50
51 Status:
52   Tested:
53     - Changing the pin.
54     - Compilation and general use.
55   Untested:
56     - Faulty situation for the ErrFlag to set.
57   Not working:
58
59 RPP API functions used:
60     - rpp_lout_set()
61     - rpp_lout_update()
62
63 Relevant demos:
64     - digital_passthrough
65     - led_blink_all
66     - led_blink
67 ...
68 */
69
70 #define S_FUNCTION_NAME sfunction_lout
71 #include "header.c"
72
73
74 static void mdlInitializeSizes(SimStruct *S)
75 {
76     /*
77      * Configure parameters: 1
78      *  - Pin number: [1-8]
79      */
80     if (!rppSetNumParams(S, 1)) {
81         return;
82     }
83
84     /*
85      * Configure input ports: 1
86      *  - Digital output.
87      */
88     if (!ssSetNumInputPorts(S, 1)) {
89         return;
90     }
91     rppAddInputPort(S, 0, SS_BOOLEAN);
92
93     /*
94      * Configure output ports: 1
95      *  - Error flag.
96      */
97     if (!ssSetNumOutputPorts(S, 1)) {
98         return;
99     }
100     rppAddOutputPort(S, 0, SS_BOOLEAN);
101
102     /* Set standard options for this block */
103     rppSetStandardOptions(S);
104 }
105
106
107 #ifdef MATLAB_MEX_FILE
108 #define MDL_CHECK_PARAMETERS
109 static void mdlCheckParameters(SimStruct *S)
110 {
111     /* Check the parameter 1 */
112     if (!rppValidParamRange(S, 0, 1, 8)) {
113         return;
114     }
115 }
116 #endif
117
118
119 #ifdef MATLAB_MEX_FILE
120 #define MDL_SET_WORK_WIDTHS
121 static void mdlSetWorkWidths(SimStruct *S)
122 {
123     /* Set number of run-time parameters */
124     if (!ssSetNumRunTimeParams(S, 1)) {
125         return;
126     }
127
128     /* Register the run-time parameter 1 */
129     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
130 }
131 #endif
132
133
134 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
135 #define UNUSED_MDLOUTPUTS
136 #define UNUSED_MDLTERMINATE
137 #include "trailer.c"