2 * Serial Communication Interface RPP API header file.
6 * @copyright Copyright (C) 2013-2015 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
19 * SCI module initialization.
21 * Call this method before using this module. The default baudrate is
22 * initialized to 115200. It can be changed later by calling
25 * This function is not thread safe. Do not call it from multiple threads.
27 * @return SUCCESS if initialization successful.\n
28 * FAILURE if module already initialized.
30 int8_t rpp_sci_init();
36 * The function is thread safe.
38 * Configure the SCI module.
40 * @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
41 * Default is 9600. If 0 is provided default is used.
43 * @return TRUE if baud rate is a known value.\n
46 boolean_t rpp_sci_setup(uint32_t baud);
51 * Number of bytes available on input buffer.
53 * The function is thread safe.
55 * Get the number of bytes (characters) available for reading from the serial
56 * port. This is data that's already arrived and stored in the SCI input buffer.
58 * @return [0-MAX_BUFFER_LEN] The number of bytes available to read.
60 uint16_t rpp_sci_available();
64 * Read n number of bytes from input buffer.
66 * The function is thread safe.
68 * Transfer given amount of bytes from SCI input buffer into given buffer.
69 * Buffer should be at least as large as the amount of data requested.
71 * This is a blocking call.
73 * Will block until requested amount of data is available.
75 * @param[in] amount Amount/number of bytes to read.
76 * @param[out] buffer Pointer to buffer where to store data.
78 * @return SUCCESS when all data was transfered.
80 int8_t rpp_sci_read(uint32_t amount, uint8_t *buffer);
84 * Read n number of bytes from input buffer if possible.
86 * The function is thread safe.
88 * Transfer given amount of bytes from SCI input buffer into given buffer.
89 * Buffer should be at least as large as the amount of data requested.
91 * This is a non-blocking call.
93 * This function will only succeed if requested amount of data is present
94 * already in the input buffer.
96 * @param[in] amount Amount/number of bytes to read.
97 * @param[out] buffer Pointer to buffer where to store data.
99 * @return SUCCESS if the requested amount of data could be transfered.\n
100 * FAILURE if requested amount of data is unavailable.
102 int8_t rpp_sci_read_nb(uint32_t amount, uint8_t *buffer);
106 * Write n number of bytes to the output buffer.
108 * The function is thread safe.
110 * Transfer given amount of bytes from given buffer to the SCI output buffer.
111 * Data buffer should be at least as large as the amount of data requested to be
114 * This is a blocking call.
116 * This will block if SCI output buffer is full waiting until some space is
119 * @param[in] amount Amount/number of bytes to send.
120 * @param[in] data Pointer to buffer from where to read data.
122 * @return SUCCESS when all data was transfered.
124 int8_t rpp_sci_write(uint32_t amount, uint8_t *data);
128 * Write n number of bytes to the output buffer if possible.
130 * The function is thread safe.
132 * Transfer given amount of bytes from given buffer to the SCI output buffer.
133 * Data buffer should be at least as large as the amount of data requested to be
136 * This is a non-blocking call.
138 * This is a best effort call, that means that this will try to put the maximum
139 * amount of data into the output buffer until it's full or all the requested
140 * amount of data could be transfered. If output buffer is blocked by another
141 * process this function will not wait to acquire the lock for the buffer.
143 * @param[in] amount Amount/number of bytes to send.
144 * @param[in] data Pointer to buffer from where to read data.
146 * @return SUCCESS if the requested amount of data could be transfered to the
148 * FAILURE if the SCI output buffer was locked by another process or
149 * not all the bytes requested to send could be transfered.
151 int8_t rpp_sci_write_nb(uint32_t amount, uint8_t *data);
155 * Flush incomming or outgoing buffers.
157 * The function is thread safe.
159 * This is a blocking call.
161 * This will block if another process is writing to or reading data from the
162 * selected buffer to flush until this process releases the lock on the buffer.
164 * @param[in] buff TRUE to flush incomming buffer.
165 * FALSE to flush outgoing buffer.
167 * @return SUCCESS if flushed buffer had some data.\n
168 * FAILURE if flushed buffer had no data left.
170 int8_t rpp_sci_flush(boolean_t buff);
175 * C style printk using RPP SCI module.
177 * The function is not thread safe.
179 * This call is intended to be used from interrupt only.
180 * Function blocks until whole string was sent to the SCI output, therefore
181 * it should be used with care. Frequent usage is for debugging.
183 * This function will wait until all the bytes are sent to the SCI output.
184 * Implementation uses vsnprintf() from stdio.h using a fixed
185 * MAX_BUFFER_LEN bytes buffer.
187 * @param[in] format C string that contains a format string that follows the
188 * same specifications as format in printf (see stdio.h's
189 * printf for details).
190 * @param[in] ... (additional arguments) Depending on the format string,
191 * the function may expect a sequence of additional
192 * arguments, each containing a value to be used to replace
193 * a format specifier in the format string (or a pointer to
194 * a storage location).
195 * There should be at least as many of these arguments as
196 * the number of values specified in the format specifiers.
197 * Additional arguments are ignored by the function.
199 * @return SUCCESS when string was sent
200 * FAILURE when an error occurred
202 int32_t rpp_sci_printk(const char *format, ...);
206 * C style printk using RPP SCI module.
208 * The function is not thread safe.
210 * This call is intended to be used from interrupt only.
211 * Function tries to append string to the output buffer.
213 * Implementation uses vsnprintf() from stdio.h using a fixed
214 * MAX_BUFFER_LEN bytes buffer.
216 * @param[in] format C string that contains a format string that follows the
217 * same specifications as format in printf (see stdio.h's
218 * printf for details).
219 * @param[in] ... (additional arguments) Depending on the format string,
220 * the function may expect a sequence of additional
221 * arguments, each containing a value to be used to replace
222 * a format specifier in the format string (or a pointer to
223 * a storage location).
224 * There should be at least as many of these arguments as
225 * the number of values specified in the format specifiers.
226 * Additional arguments are ignored by the function.
228 * @return The number of characters that have been written to the buffer.
229 * If an error occurs, a negative number is returned.
231 int32_t rpp_sci_printkb(const char *format, ...);
236 * C style printf using RPP SCI module.
238 * The function is thread safe.
240 * This is a blocking call.
242 * This function will wait until all the bytes are sent to the SCI output
243 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
244 * MAX_BUFFER_LEN bytes buffer.
246 * @param[in] format C string that contains a format string that follows the
247 * same specifications as format in printf (see stdio.h's
248 * printf for details).
249 * @param[in] ... (additional arguments) Depending on the format string,
250 * the function may expect a sequence of additional
251 * arguments, each containing a value to be used to replace
252 * a format specifier in the format string (or a pointer to
253 * a storage location).
254 * There should be at least as many of these arguments as
255 * the number of values specified in the format specifiers.
256 * Additional arguments are ignored by the function.
258 * @return The number of characters that would have been written if the buffer
259 * had been sufficiently large, not counting the terminating null
260 * character. If an encoding error occurs, a negative number is
261 * returned. Please note that only when this returned value is
262 * non-negative and less than the buffer size, the string has been
263 * completely written.
265 int32_t rpp_sci_printf(const char *format, ...);
269 * C style vprintf using RPP SCI module.
271 * The function is thread safe.
273 * This is a blocking call.
275 * This function will wait until all the bytes are sent to the SCI output
276 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
277 * MAX_BUFFER_LEN bytes buffer.
279 * @param[in] format C string that contains a format string that follows the
280 * same specifications as format in printf (see stdio.h's
281 * printf for details).
282 * @param[in] args (additional arguments) Depending on the format string,
283 * the function may expect a sequence of additional
284 * arguments, each containing a value to be used to replace
285 * a format specifier in the format string (or a pointer to
286 * a storage location).
287 * There should be at least as many of these arguments as
288 * the number of values specified in the format specifiers.
289 * Additional arguments are ignored by the function.
291 * @return The number of characters that would have been written if the buffer
292 * had been sufficiently large, not counting the terminating null
293 * character. If an encoding error occurs, a negative number is
294 * returned. Please note that only when this returned value is
295 * non-negative and less than the buffer size, the string has been
296 * completely written.
298 int32_t rpp_sci_vprintf(const char *format, va_list args);
302 * C style putc (put character) using RPP SCI module.
304 * The function is not thread safe.
306 * This is a blocking call.
308 * This function will wait until the given byte is put into SCI output buffer if
311 * @param[in] byte Byte to put into SCI output buffer.
313 * @return SUCCESS when the given byte could be transfered.
315 int8_t rpp_sci_putc(uint8_t byte);
319 * C style getc (get character) using RPP SCI module.
321 * The function is not thread safe.
323 * This is a blocking call.
325 * This function will wait until a byte is available in the SCI input buffer if
328 * @note The byte is promoted to an int16_t in order to accommodate for
329 * FAILURE/EOF/-1 if an error occurs. This is in order to conform with C getc,
330 * but should never happen in current implementation because this is a blocking
331 * call and will always wait for one byte to be available in the input buffer.
332 * Nevertheless, if user compiles it's programs against POSIX FreeRTOS for
333 * Simulation then the compatibility layers makes it possible to return EOF so
334 * user expecting to run in Simulation should always check for FAILURE.
336 * @return [0-255] The byte read from the SCI input buffer.\n
337 * FAILURE If and error occurred.
339 int16_t rpp_sci_getc();
343 #endif /* __RPP_SCI_H */