2 * Serial Communication Interface RPP API header file.
6 * @copyright Copyright (C) 2013 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.
20 * @return SUCCESS if initialization successful.\n
21 * FAILURE if module already initialized.
23 int8_t rpp_sci_init();
29 * Configure the SCI module.
31 * @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
32 * Default is 9600. If 0 is provided default is used.
34 * @return TRUE if baud rate is a known value.\n
37 boolean_t rpp_sci_setup(uint32_t baud);
42 * Number of bytes available on input buffer.
44 * Get the number of bytes (characters) available for reading from the serial
45 * port. This is data that's already arrived and stored in the SCI input buffer.
47 * @return [0-MAX_BUFFER_LEN] The number of bytes available to read.
49 uint16_t rpp_sci_available();
53 * Read n number of bytes from input buffer.
55 * Transfer given amount of bytes from SCI input buffer into given buffer.
56 * Buffer should be at least as large as the amount of data requested.
58 * This is a blocking call.
60 * Will block until requested amount of data is available.
62 * @param[in] amount Amount/number of bytes to read.
63 * @param[out] buffer Pointer to buffer where to store data.
65 * @return SUCCESS when all data was transfered.
67 int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);
71 * Read n number of bytes from input buffer if possible.
73 * Transfer given amount of bytes from SCI input buffer into given buffer.
74 * Buffer should be at least as large as the amount of data requested.
76 * This is a non-blocking call.
78 * This function will only succeed if requested amount of data is present
79 * already in the input buffer.
81 * @param[in] amount Amount/number of bytes to read.
82 * @param[out] buffer Pointer to buffer where to store data.
84 * @return SUCCESS if the requested amount of data could be transfered.\n
85 * FAILURE if requested amount of data is unavailable.
87 int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);
91 * Write n number of bytes to the output buffer.
93 * Transfer given amount of bytes from given buffer to the SCI output buffer.
94 * Data buffer should be at least as large as the amount of data requested to be
97 * This is a blocking call.
99 * This will block if SCI output buffer is full waiting until some space is
102 * @param[in] amount Amount/number of bytes to send.
103 * @param[in] data Pointer to buffer from where to read data.
105 * @return SUCCESS when all data was transfered.
107 int8_t rpp_sci_write(uint32_t amount, uint8_t* data);
111 * Write n number of bytes to the output buffer if possible.
113 * Transfer given amount of bytes from given buffer to the SCI output buffer.
114 * Data buffer should be at least as large as the amount of data requested to be
117 * This is a non-blocking call.
119 * This is a best effort call, that means that this will try to put the maximum
120 * amount of data into the output buffer until it's full or all the requested
121 * amount of data could be transfered. If output buffer is blocked by another
122 * process this function will not wait to acquire the lock for the buffer.
124 * @param[in] amount Amount/number of bytes to send.
125 * @param[in] data Pointer to buffer from where to read data.
127 * @return SUCCESS if the requested amount of data could be transfered to the
129 * FAILURE if the SCI output buffer was locked by another process or
130 * not all the bytes requested to send could be transfered.
132 int8_t rpp_sci_write_nb(uint32_t amount, uint8_t* data);
136 * Flush incomming or outgoing buffers.
138 * This is a blocking call.
140 * This will block if another process is writing to or reading data from the
141 * selected buffer to flush until this process releases the lock on the buffer.
143 * @param[in] buff TRUE to flush incomming buffer.
144 * FALSE to flush outgoing buffer.
146 * @return SUCCESS if flushed buffer had some data.\n
147 * FAILURE if flushed buffer had no data left.
149 int8_t rpp_sci_flush(boolean_t buff);
154 * C style printf using RPP SCI module.
156 * This is a blocking call.
158 * This function will wait until all the bytes are sent to the SCI output
159 * buffer. Implementation uses vsnprintf() from stdio.h using a fixed
160 * MAX_BUFFER_LEN bytes buffer.
162 * @param[in] format C string that contains a format string that follows the
163 * same specifications as format in printf (see stdio.h's
164 * printf for details).
165 * @param[in] ... (additional arguments) Depending on the format string,
166 * the function may expect a sequence of additional
167 * arguments, each containing a value to be used to replace
168 * a format specifier in the format string (or a pointer to
169 * a storage location).
170 * There should be at least as many of these arguments as
171 * the number of values specified in the format specifiers.
172 * Additional arguments are ignored by the function.
174 * @return The number of characters that would have been written if the buffer
175 * had been sufficiently large, not counting the terminating null
176 * character. If an encoding error occurs, a negative number is
177 * returned. Please note that only when this returned value is
178 * non-negative and less than the buffer size, the string has been
179 * completely written.
181 int32_t rpp_sci_printf(const char* format, ...);
182 int32_t rpp_sci_vprintf(const char* format, va_list args);
186 * C style putc (put character) using RPP SCI module.
188 * This is a blocking call.
190 * This function will wait until the given byte is put into SCI output buffer if
193 * @param[in] byte Byte to put into SCI output buffer.
195 * @return SUCCESS when the given byte could be transfered.
197 int8_t rpp_sci_putc(uint8_t byte);
201 * C style getc (get character) using RPP SCI module.
203 * This is a blocking call.
205 * This function will wait until a byte is available in the SCI input buffer if
208 * @note The byte is promoted to an int16_t in order to accommodate for
209 * FAILURE/EOF/-1 if an error occurs. This is in order to conform with C getc,
210 * but should never happen in current implementation because this is a blocking
211 * call and will always wait for one byte to be available in the input buffer.
212 * Nevertheless, if user compiles it's programs against POSIX FreeRTOS for
213 * Simulation then the compatibility layers makes it possible to return EOF so
214 * user expecting to run in Simulation should always check for FAILURE.
216 * @return [0-255] The byte read from the SCI input buffer.\n
217 * FAILURE If and error occurred.
219 int16_t rpp_sci_getc();
223 #endif /* __RPP_SCI_H */