]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_sdrw.c
doc: Update S-function YAML block to match the current state of the blocks
[jenkicar/rpp-simulink.git] / rpp / blocks / sfunction_sdrw.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_sdrw.c
12  * Abstract:
13  *     C-MEX S-function block for RPP SD-RAM log write.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_sdrw.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: SD-RAM Write
27 Category: Logging
28 Header: rpp/sdc.h
29 Mnemonic: SDRW
30
31 Inputs:
32   - { name: "Data", type: "double" }
33
34 Outputs:
35   - { name: "ErrFlag", type: "bool" }
36
37 Parameters:
38   - { name: "Block ID",              type: "uint8", range: "[0-255]" }
39   - { name: "Printf format for logging", type: "string", range: "(include specifiers)" }
40
41 # Description and Help is in Markdown mark-up
42 Description: &desc |
43
44   This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat 
45   string to format and register the double value on the log. The PrintFormat string should include 
46   two specifiers:  
47     1. For the block ID. Any valid integer specifier.  
48     2. For the value to log. Any valid double specifier.  
49
50   Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there 
51   is no validation on it. Error to provide a valid PrintFormat could generate compilation errors or 
52   even run-time errors (normally this generates a warning on compile time). Note that the function 
53   for logging used is `rpp_sdr_printf()`, which is a blocking call, and can potentially overrun the 
54   step. The ErrFlag will set if `rpp_sdr_printf()` returns an error (for example out of memory), 
55   but will clear back if the next step the call to this function is successful.
56
57 Help: *desc
58
59 Status:
60   Tested:
61     - Logging data.
62     - Compilation and general use.
63   Untested:
64     - Faulty situation for the ErrFlag to set.
65   Not working:
66
67 RPP API functions used:
68     - rpp_sdr_printf()
69
70 Relevant demos:
71     - log_analog_input
72 ...
73 */
74
75 #define S_FUNCTION_NAME sfunction_sdrw
76 #include "header.c"
77
78
79 static void mdlInitializeSizes(SimStruct *S)
80 {
81     /*
82      * Configure parameters: 2
83      *  - Block ID.
84      *  - Printf format [setting].
85      */
86     if (!rppSetNumParams(S, 2)) {
87         return;
88     }
89
90     /*
91      * Configure input ports: 1
92      *  - Data.
93      */
94     if (!ssSetNumInputPorts(S, 1)) {
95         return;
96     }
97     rppAddInputPort(S, 0, SS_DOUBLE);
98
99     /*
100      * Configure output ports: 1
101      *  - Error flag.
102      */
103     if (!ssSetNumOutputPorts(S, 1)) {
104         return;
105     }
106     rppAddOutputPort(S, 0, SS_BOOLEAN);
107
108     /* Set standard options for this block */
109     rppSetStandardOptions(S);
110 }
111
112
113 #ifdef MATLAB_MEX_FILE
114 #define MDL_CHECK_PARAMETERS
115 static void mdlCheckParameters(SimStruct *S)
116 {
117     /* Check the parameter 1 */
118     if (!rppValidParamRange(S, 0, 0, 255)) {
119         return;
120     }
121 }
122 #endif
123
124
125 #ifdef MATLAB_MEX_FILE
126 #define MDL_SET_WORK_WIDTHS
127 static void mdlSetWorkWidths(SimStruct *S)
128 {
129     /* Set number of run-time parameters */
130     if (!ssSetNumRunTimeParams(S, 1)) {
131         return;
132     }
133
134     /* Register the run-time parameter 1 */
135     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
136 }
137 #endif
138
139
140 #ifdef MATLAB_MEX_FILE
141 #define MDL_RTW
142 static void mdlRTW(SimStruct* S)
143 {
144     /* Register parameter 2 as a parameter setting */
145     static char_T str[128];
146     mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); /* Get string */
147     if (!ssWriteRTWParamSettings(S, 1,
148             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
149         /* An error ocurred */
150         return;
151     }
152 }
153 #endif
154
155
156 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
157 #define UNUSED_MDLOUTPUTS
158 #define UNUSED_MDLTERMINATE
159 #include "trailer.c"