1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34
35
36 /*!
37 * ======== SysMin ========
38 *
39 * Minimal implementation of `{@link ISystemSupport}`.
40 *
41 * This implementation provides a fully functional implementation of
42 * all methods specified by `ISystemSupport`.
43 *
44 * The module maintains an internal buffer (with a configurable size)
45 * that stores on the "output". When full, the data is over-written. When
46 * `System_flush()` is called the characters in the internal buffer are
47 * "output" using the user configuratble `{@link #outputFxn}`.
48 *
49 * As with all `ISystemSupport` modules, this module is the back-end for the
50 * `{@link System}` module; application code does not directly call these
51 * functions.
52 */
53 @Template("./SysMin.xdt")
54 @ModuleStartup
55 module SysMin inherits xdc.runtime.ISystemSupport {
56
57 metaonly struct ModuleView {
58 Ptr outBuf;
59 UInt outBufIndex;
60 Bool getTime;
61 Bool wrapped;
62 };
63
64 metaonly struct BufferEntryView {
65 String entry;
66 }
67
68 /*!
69 * ======== rovViewInfo ========
70 * @_nodoc
71 */
72 @Facet
73 metaonly config xdc.rov.ViewInfo.Instance rovViewInfo =
74 xdc.rov.ViewInfo.create({
75 viewMap: [
76 ['Module',
77 {
78 type: xdc.rov.ViewInfo.MODULE,
79 viewInitFxn: 'viewInitModule',
80 structName: 'ModuleView'
81 }
82 ],
83 ['OutputBuffer',
84 {
85 type: xdc.rov.ViewInfo.MODULE_DATA,
86 viewInitFxn: 'viewInitOutputBuffer',
87 structName: 'BufferEntryView'
88 }
89 ]
90 ]
91 });
92
93 /*!
94 * ======== LINEBUFSIZE ========
95 * Size (in MAUs) of the line buffer
96 *
97 * An internal line buffer of this size is allocated. All output is stored
98 * in this internal buffer until a new line is output.
99 */
100 const SizeT LINEBUFSIZE = 0x100;
101
102 /*!
103 * ======== bufSize ========
104 * Size (in MAUs) of the output.
105 *
106 * An internal buffer of this size is allocated. All output is stored
107 * in this internal buffer.
108 *
109 * If 0 is specified for the size, no buffer is created and ALL
110 * tracing is disabled.
111 */
112 config SizeT bufSize = 0x1000;
113
114 /*!
115 * ======== sectionName ========
116 * Section where the internal character output buffer is placed
117 *
118 * The default is to have no explicit placement; i.e., the linker is
119 * free to place it anywhere in the memory map.
120 */
121 metaonly config String sectionName = null;
122
123 /*!
124 * ======== flushAtExit ========
125 * Flush the internal buffer during `{@link #exit}` or `{@link #abort}`.
126 *
127 * If the application's target is a TI target, the internal buffer is
128 * flushed via the `HOSTwrite` function in the TI C Run Time Support
129 * (RTS) library.
130 *
131 * If the application's target is not a TI target, the internal buffer
132 * is flushed to `stdout` via `fwrite(..., stdout)`.
133 *
134 * Setting this parameter to `false` reduces the footprint of the
135 * application at the expense of not getting output when the application
136 * ends via a `System_exit()`, `System_abort()`, `exit()` or `abort()`.
137 */
138 config Bool flushAtExit = true;
139
140 /*!
141 * ======== abort ========
142 * Backend for `{@link System#abort()}`
143 *
144 * This abort function writes the string to the internal
145 * output buffer and then gives all internal output to the
146 * `{@link #outputFxn}` function if the `{@link #flushAtExit}`
147 * configuration parameter is true.
148 *
149 * @param(str) message to output just prior to aborting
150 *
151 * If non-`NULL`, this string should be output just prior to
152 * terminating.
153 *
154 * @see ISystemSupport#abort
155 */
156 override Void abort(CString str);
157
158 /*!
159 * ======== exit ========
160 * Backend for `{@link System#exit()}`
161 *
162 * This exit function gives all internal output to the
163 * `{@link #outputFxn}` function if the `{@link #flushAtExit}`
164 * configuration parameter is true.
165 *
166 * @see ISystemSupport#exit
167 */
168 override Void exit(Int stat);
169
170 /*!
171 * ======== flush ========
172 * Backend for `{@link System#flush()}`
173 *
174 * The `flush` writes the contents of the internal character buffer
175 * via the `{@link #outputFxn}` function.
176 *
177 * @a(Warning)
178 * The `{@link System}` gate is used for thread safety during the
179 * entire flush operation, so care must be taken when flushing with
180 * this `ISystemSupport` module. Depending on the nature of the
181 * `System` gate, your application's interrupt latency
182 * may become a function of the `bufSize` parameter!
183 *
184 * @see ISystemSupport#flush
185 */
186 override Void flush();
187
188 /*!
189 * ======== putch ========
190 * Backend for `{@link System#printf()}` and `{@link System#putch()}`
191 *
192 * Places the character into an internal buffer. The `{@link #flush}`
193 * sends the internal buffer to the `{@link #outputFxn}` function.
194 * The internal buffer is also sent to the `SysMin_outputFxn`
195 * function by `{@link #exit}` and `{@link #abort}` if the
196 * `{@link #flushAtExit}` configuration parameter is true.
197 *
198 * @see ISystemSupport#putch
199 */
200 override Void putch(Char ch);
201
202 /*!
203 * ======== ready ========
204 * Test if character output can proceed
205 *
206 * This function returns true if the internal buffer is non-zero.
207 *
208 * @see ISystemSupport#ready
209 */
210 override Bool ready();
211
212 internal:
213
214 struct LineBuffer {
215 UInt lineidx;
216 Char linebuf[LINEBUFSIZE];
217 }
218
219 struct Module_State {
220 LineBuffer lineBuffers[];
221 Char outbuf[];
222 UInt outidx;
223 Bool getTime;
224 Bool wrapped;
225 UInt writeidx[];
226 UInt readidx[]; 227
228 }
229 }