2 * Serial Communication Interface RPP API header file.
6 * @copyright Copyright (C) 2013-2014 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
18 * SCI module initialization.
20 * Call this method before using this module. The default baudrate is
21 * initialized to 115200. It can be changed later by calling
24 * @return SUCCESS if initialization successful.\n
25 * FAILURE if module already initialized.
27 int8_t rpp_sci_init();
33 * Configure the SCI module.
35 * @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
36 * Default is 9600. If 0 is provided default is used.
38 * @return TRUE if baud rate is a known value.\n
41 boolean_t rpp_sci_setup(uint32_t baud);
46 * Number of bytes available on input buffer.
48 * Get the number of bytes (characters) available for reading from the serial
49 * port. This is data that's already arrived and stored in the SCI input buffer.
51 * @return [0-MAX_BUFFER_LEN] The number of bytes available to read.
53 uint16_t rpp_sci_available();
57 * Read n number of bytes from input buffer.
59 * Transfer given amount of bytes from SCI input buffer into given buffer.
60 * Buffer should be at least as large as the amount of data requested.
62 * This is a blocking call.
64 * Will block until requested amount of data is available.
66 * @param[in] amount Amount/number of bytes to read.
67 * @param[out] buffer Pointer to buffer where to store data.
69 * @return SUCCESS when all data was transfered.
71 int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);
75 * Read n number of bytes from input buffer if possible.
77 * Transfer given amount of bytes from SCI input buffer into given buffer.
78 * Buffer should be at least as large as the amount of data requested.
80 * This is a non-blocking call.
82 * This function will only succeed if requested amount of data is present
83 * already in the input buffer.
85 * @param[in] amount Amount/number of bytes to read.
86 * @param[out] buffer Pointer to buffer where to store data.
88 * @return SUCCESS if the requested amount of data could be transfered.\n
89 * FAILURE if requested amount of data is unavailable.
91 int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);
95 * Write n number of bytes to the output buffer.
97 * Transfer given amount of bytes from given buffer to the SCI output buffer.
98 * Data buffer should be at least as large as the amount of data requested to be
101 * This is a blocking call.
103 * This will block if SCI output buffer is full waiting until some space is
106 * @param[in] amount Amount/number of bytes to send.
107 * @param[in] data Pointer to buffer from where to read data.
109 * @return SUCCESS when all data was transfered.
111 int8_t rpp_sci_write(uint32_t amount, uint8_t* data);
115 * Write n number of bytes to the output buffer if possible.
117 * Transfer given amount of bytes from given buffer to the SCI output buffer.
118 * Data buffer should be at least as large as the amount of data requested to be
121 * This is a non-blocking call.
123 * This is a best effort call, that means that this will try to put the maximum
124 * amount of data into the output buffer until it's full or all the requested
125 * amount of data could be transfered. If output buffer is blocked by another
126 * process this function will not wait to acquire the lock for the buffer.
128 * @param[in] amount Amount/number of bytes to send.
129 * @param[in] data Pointer to buffer from where to read data.
131 * @return SUCCESS if the requested amount of data could be transfered to the
133 * FAILURE if the SCI output buffer was locked by another process or
134 * not all the bytes requested to send could be transfered.
136 int8_t rpp_sci_write_nb(uint32_t amount, uint8_t* data);
140 * Flush incomming or outgoing buffers.
142 * This is a blocking call.
144 * This will block if another process is writing to or reading data from the
145 * selected buffer to flush until this process releases the lock on the buffer.
147 * @param[in] buff TRUE to flush incomming buffer.
148 * FALSE to flush outgoing buffer.
150 * @return SUCCESS if flushed buffer had some data.\n
151 * FAILURE if flushed buffer had no data left.
153 int8_t rpp_sci_flush(boolean_t buff);
158 * C style printk using RPP SCI module.
160 * This call is intended to be used from interrupt only.
161 * Function blocks until whole string was sent to the SCI output, therefore
162 * it should be used with care. Frequent usage is for debugging.
164 * This function will wait until all the bytes are sent to the SCI output.
165 * Implementation uses vsnprintf() from stdio.h using a fixed
166 * MAX_BUFFER_LEN bytes buffer.
168 * @param[in] format C string that contains a format string that follows the
169 * same specifications as format in printf (see stdio.h's
170 * printf for details).
171 * @param[in] ... (additional arguments) Depending on the format string,
172 * the function may expect a sequence of additional
173 * arguments, each containing a value to be used to replace
174 * a format specifier in the format string (or a pointer to
175 * a storage location).
176 * There should be at least as many of these arguments as
177 * the number of values specified in the format specifiers.
178 * Additional arguments are ignored by the function.
180 * @return SUCCESS when string was sent
181 * FAILURE when an error occurred
183 int32_t rpp_sci_printk(const char* format, ...);
187 * C style printk using RPP SCI module.
189 * This call is intended to be used from interrupt only.
190 * Function tries to append string to the output buffer.
192 * Implementation uses vsnprintf() from stdio.h using a fixed
193 * MAX_BUFFER_LEN bytes buffer.
195 * @param[in] format C string that contains a format string that follows the
196 * same specifications as format in printf (see stdio.h's
197 * printf for details).
198 * @param[in] ... (additional arguments) Depending on the format string,
199 * the function may expect a sequence of additional
200 * arguments, each containing a value to be used to replace
201 * a format specifier in the format string (or a pointer to
202 * a storage location).
203 * There should be at least as many of these arguments as
204 * the number of values specified in the format specifiers.
205 * Additional arguments are ignored by the function.
207 * @return The number of characters that have been written to the buffer.
208 * If an error occurs, a negative number is returned.
210 int32_t rpp_sci_printkb(const char* format, ...);
215 * C style printf using RPP SCI module.
217 * This is a blocking call.
219 * This function will wait until all the bytes are sent to the SCI output
220 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
221 * MAX_BUFFER_LEN bytes buffer.
223 * @param[in] format C string that contains a format string that follows the
224 * same specifications as format in printf (see stdio.h's
225 * printf for details).
226 * @param[in] ... (additional arguments) Depending on the format string,
227 * the function may expect a sequence of additional
228 * arguments, each containing a value to be used to replace
229 * a format specifier in the format string (or a pointer to
230 * a storage location).
231 * There should be at least as many of these arguments as
232 * the number of values specified in the format specifiers.
233 * Additional arguments are ignored by the function.
235 * @return The number of characters that would have been written if the buffer
236 * had been sufficiently large, not counting the terminating null
237 * character. If an encoding error occurs, a negative number is
238 * returned. Please note that only when this returned value is
239 * non-negative and less than the buffer size, the string has been
240 * completely written.
242 int32_t rpp_sci_printf(const char* format, ...);
246 * C style vprintf using RPP SCI module.
248 * This is a blocking call.
250 * This function will wait until all the bytes are sent to the SCI output
251 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
252 * MAX_BUFFER_LEN bytes buffer.
254 * @param[in] format C string that contains a format string that follows the
255 * same specifications as format in printf (see stdio.h's
256 * printf for details).
257 * @param[in] args (additional arguments) Depending on the format string,
258 * the function may expect a sequence of additional
259 * arguments, each containing a value to be used to replace
260 * a format specifier in the format string (or a pointer to
261 * a storage location).
262 * There should be at least as many of these arguments as
263 * the number of values specified in the format specifiers.
264 * Additional arguments are ignored by the function.
266 * @return The number of characters that would have been written if the buffer
267 * had been sufficiently large, not counting the terminating null
268 * character. If an encoding error occurs, a negative number is
269 * returned. Please note that only when this returned value is
270 * non-negative and less than the buffer size, the string has been
271 * completely written.
273 int32_t rpp_sci_vprintf(const char* format, va_list args);
277 * C style putc (put character) using RPP SCI module.
279 * This is a blocking call.
281 * This function will wait until the given byte is put into SCI output buffer if
284 * @param[in] byte Byte to put into SCI output buffer.
286 * @return SUCCESS when the given byte could be transfered.
288 int8_t rpp_sci_putc(uint8_t byte);
292 * C style getc (get character) using RPP SCI module.
294 * This is a blocking call.
296 * This function will wait until a byte is available in the SCI input buffer if
299 * @note The byte is promoted to an int16_t in order to accommodate for
300 * FAILURE/EOF/-1 if an error occurs. This is in order to conform with C getc,
301 * but should never happen in current implementation because this is a blocking
302 * call and will always wait for one byte to be available in the input buffer.
303 * Nevertheless, if user compiles it's programs against POSIX FreeRTOS for
304 * Simulation then the compatibility layers makes it possible to return EOF so
305 * user expecting to run in Simulation should always check for FAILURE.
307 * @return [0-255] The byte read from the SCI input buffer.\n
308 * FAILURE If and error occurred.
310 int16_t rpp_sci_getc();
314 #endif /* __RPP_SCI_H */