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>
16 * SCI module initialization.
18 * Call this method before using this module. The default baudrate is
19 * initialized to 115200. It can be changed later by calling
22 * @return SUCCESS if initialization successful.\n
23 * FAILURE if module already initialized.
25 int8_t rpp_sci_init();
31 * Configure the SCI module.
33 * @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
34 * Default is 9600. If 0 is provided default is used.
36 * @return TRUE if baud rate is a known value.\n
39 boolean_t rpp_sci_setup(uint32_t baud);
44 * Number of bytes available on input buffer.
46 * Get the number of bytes (characters) available for reading from the serial
47 * port. This is data that's already arrived and stored in the SCI input buffer.
49 * @return [0-MAX_BUFFER_LEN] The number of bytes available to read.
51 uint16_t rpp_sci_available();
55 * Read n number of bytes from input buffer.
57 * Transfer given amount of bytes from SCI input buffer into given buffer.
58 * Buffer should be at least as large as the amount of data requested.
60 * This is a blocking call.
62 * Will block until requested amount of data is available.
64 * @param[in] amount Amount/number of bytes to read.
65 * @param[out] buffer Pointer to buffer where to store data.
67 * @return SUCCESS when all data was transfered.
69 int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);
73 * Read n number of bytes from input buffer if possible.
75 * Transfer given amount of bytes from SCI input buffer into given buffer.
76 * Buffer should be at least as large as the amount of data requested.
78 * This is a non-blocking call.
80 * This function will only succeed if requested amount of data is present
81 * already in the input buffer.
83 * @param[in] amount Amount/number of bytes to read.
84 * @param[out] buffer Pointer to buffer where to store data.
86 * @return SUCCESS if the requested amount of data could be transfered.\n
87 * FAILURE if requested amount of data is unavailable.
89 int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);
93 * Write n number of bytes to the output buffer.
95 * Transfer given amount of bytes from given buffer to the SCI output buffer.
96 * Data buffer should be at least as large as the amount of data requested to be
99 * This is a blocking call.
101 * This will block if SCI output buffer is full waiting until some space is
104 * @param[in] amount Amount/number of bytes to send.
105 * @param[in] data Pointer to buffer from where to read data.
107 * @return SUCCESS when all data was transfered.
109 int8_t rpp_sci_write(uint32_t amount, uint8_t* data);
113 * Write n number of bytes to the output buffer if possible.
115 * Transfer given amount of bytes from given buffer to the SCI output buffer.
116 * Data buffer should be at least as large as the amount of data requested to be
119 * This is a non-blocking call.
121 * This is a best effort call, that means that this will try to put the maximum
122 * amount of data into the output buffer until it's full or all the requested
123 * amount of data could be transfered. If output buffer is blocked by another
124 * process this function will not wait to acquire the lock for the buffer.
126 * @param[in] amount Amount/number of bytes to send.
127 * @param[in] data Pointer to buffer from where to read data.
129 * @return SUCCESS if the requested amount of data could be transfered to the
131 * FAILURE if the SCI output buffer was locked by another process or
132 * not all the bytes requested to send could be transfered.
134 int8_t rpp_sci_write_nb(uint32_t amount, uint8_t* data);
138 * Flush incomming or outgoing buffers.
140 * This is a blocking call.
142 * This will block if another process is writing to or reading data from the
143 * selected buffer to flush until this process releases the lock on the buffer.
145 * @param[in] buff TRUE to flush incomming buffer.
146 * FALSE to flush outgoing buffer.
148 * @return SUCCESS if flushed buffer had some data.\n
149 * FAILURE if flushed buffer had no data left.
151 int8_t rpp_sci_flush(boolean_t buff);
156 * C style printk using RPP SCI module.
158 * This call is intended to be used from interrupt only.
159 * Function blocks until whole string was sent to the SCI output, therefore
160 * it should be used with care. Frequent usage is for debugging.
162 * This function will wait until all the bytes are sent to the SCI output.
163 * Implementation uses vsnprintf() from stdio.h using a fixed
164 * MAX_BUFFER_LEN bytes buffer.
166 * @param[in] format C string that contains a format string that follows the
167 * same specifications as format in printf (see stdio.h's
168 * printf for details).
169 * @param[in] ... (additional arguments) Depending on the format string,
170 * the function may expect a sequence of additional
171 * arguments, each containing a value to be used to replace
172 * a format specifier in the format string (or a pointer to
173 * a storage location).
174 * There should be at least as many of these arguments as
175 * the number of values specified in the format specifiers.
176 * Additional arguments are ignored by the function.
178 * @return SUCCESS when string was sent
179 * FAILURE when an error occurred
181 int32_t rpp_sci_printk(const char* format, ...);
185 * C style printk using RPP SCI module.
187 * This call is intended to be used from interrupt only.
188 * Function tries to append string to the output buffer.
190 * Implementation uses vsnprintf() from stdio.h using a fixed
191 * MAX_BUFFER_LEN bytes buffer.
193 * @param[in] format C string that contains a format string that follows the
194 * same specifications as format in printf (see stdio.h's
195 * printf for details).
196 * @param[in] ... (additional arguments) Depending on the format string,
197 * the function may expect a sequence of additional
198 * arguments, each containing a value to be used to replace
199 * a format specifier in the format string (or a pointer to
200 * a storage location).
201 * There should be at least as many of these arguments as
202 * the number of values specified in the format specifiers.
203 * Additional arguments are ignored by the function.
205 * @return The number of characters that have been written to the buffer.
206 * If an error occurs, a negative number is returned.
208 int32_t rpp_sci_printkb(const char* format, ...);
213 * C style printf using RPP SCI module.
215 * This is a blocking call.
217 * This function will wait until all the bytes are sent to the SCI output
218 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
219 * MAX_BUFFER_LEN bytes buffer.
221 * @param[in] format C string that contains a format string that follows the
222 * same specifications as format in printf (see stdio.h's
223 * printf for details).
224 * @param[in] ... (additional arguments) Depending on the format string,
225 * the function may expect a sequence of additional
226 * arguments, each containing a value to be used to replace
227 * a format specifier in the format string (or a pointer to
228 * a storage location).
229 * There should be at least as many of these arguments as
230 * the number of values specified in the format specifiers.
231 * Additional arguments are ignored by the function.
233 * @return The number of characters that would have been written if the buffer
234 * had been sufficiently large, not counting the terminating null
235 * character. If an encoding error occurs, a negative number is
236 * returned. Please note that only when this returned value is
237 * non-negative and less than the buffer size, the string has been
238 * completely written.
240 int32_t rpp_sci_printf(const char* format, ...);
244 * C style vprintf using RPP SCI module.
246 * This is a blocking call.
248 * This function will wait until all the bytes are sent to the SCI output
249 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
250 * MAX_BUFFER_LEN bytes buffer.
252 * @param[in] format C string that contains a format string that follows the
253 * same specifications as format in printf (see stdio.h's
254 * printf for details).
255 * @param[in] args (additional arguments) Depending on the format string,
256 * the function may expect a sequence of additional
257 * arguments, each containing a value to be used to replace
258 * a format specifier in the format string (or a pointer to
259 * a storage location).
260 * There should be at least as many of these arguments as
261 * the number of values specified in the format specifiers.
262 * Additional arguments are ignored by the function.
264 * @return The number of characters that would have been written if the buffer
265 * had been sufficiently large, not counting the terminating null
266 * character. If an encoding error occurs, a negative number is
267 * returned. Please note that only when this returned value is
268 * non-negative and less than the buffer size, the string has been
269 * completely written.
271 int32_t rpp_sci_vprintf(const char* format, va_list args);
275 * C style putc (put character) using RPP SCI module.
277 * This is a blocking call.
279 * This function will wait until the given byte is put into SCI output buffer if
282 * @param[in] byte Byte to put into SCI output buffer.
284 * @return SUCCESS when the given byte could be transfered.
286 int8_t rpp_sci_putc(uint8_t byte);
290 * C style getc (get character) using RPP SCI module.
292 * This is a blocking call.
294 * This function will wait until a byte is available in the SCI input buffer if
297 * @note The byte is promoted to an int16_t in order to accommodate for
298 * FAILURE/EOF/-1 if an error occurs. This is in order to conform with C getc,
299 * but should never happen in current implementation because this is a blocking
300 * call and will always wait for one byte to be available in the input buffer.
301 * Nevertheless, if user compiles it's programs against POSIX FreeRTOS for
302 * Simulation then the compatibility layers makes it possible to return EOF so
303 * user expecting to run in Simulation should always check for FAILURE.
305 * @return [0-255] The byte read from the SCI input buffer.\n
306 * FAILURE If and error occurred.
308 int16_t rpp_sci_getc();
312 #endif /* __RPP_SCI_H */