*
* @file sci.h
*
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2013-2015 Czech Technical University in Prague
*
* @author Carlos Jenkins <carlos@jenkins.co.cr>
*/
#ifndef __RPP_SCI_H
#define __RPP_SCI_H
+#include <stdarg.h>
+#include "types.h"
+
/**
* SCI module initialization.
*
- * Call this method before using this module.
+ * Call this method before using this module. The default baudrate is
+ * initialized to 115200. It can be changed later by calling
+ * rpp_sci_setup().
+ *
+ * This function is not thread safe. Do not call it from multiple threads.
*
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
/**
* SCI module setup.
*
+ * The function is thread safe.
+ *
* Configure the SCI module.
*
* @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
/**
* Number of bytes available on input buffer.
*
+ * The function is thread safe.
+ *
* Get the number of bytes (characters) available for reading from the serial
* port. This is data that's already arrived and stored in the SCI input buffer.
*
/**
* Read n number of bytes from input buffer.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from SCI input buffer into given buffer.
* Buffer should be at least as large as the amount of data requested.
*
*
* @return SUCCESS when all data was transfered.
*/
-int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);
+int8_t rpp_sci_read(uint32_t amount, uint8_t *buffer);
/**
* Read n number of bytes from input buffer if possible.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from SCI input buffer into given buffer.
* Buffer should be at least as large as the amount of data requested.
*
* @return SUCCESS if the requested amount of data could be transfered.\n
* FAILURE if requested amount of data is unavailable.
*/
-int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);
+int8_t rpp_sci_read_nb(uint32_t amount, uint8_t *buffer);
/**
* Write n number of bytes to the output buffer.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from given buffer to the SCI output buffer.
* Data buffer should be at least as large as the amount of data requested to be
* sent.
*
* @return SUCCESS when all data was transfered.
*/
-int8_t rpp_sci_write(uint32_t amount, uint8_t* data);
+int8_t rpp_sci_write(uint32_t amount, uint8_t *data);
/**
* Write n number of bytes to the output buffer if possible.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from given buffer to the SCI output buffer.
* Data buffer should be at least as large as the amount of data requested to be
* sent.
* FAILURE if the SCI output buffer was locked by another process or
* not all the bytes requested to send could be transfered.
*/
-int8_t rpp_sci_write_nb(uint32_t amount, uint8_t* data);
+int8_t rpp_sci_write_nb(uint32_t amount, uint8_t *data);
/**
* Flush incomming or outgoing buffers.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This will block if another process is writing to or reading data from the
/**
* C style printk using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This call is intended to be used from interrupt only.
* Function blocks until whole string was sent to the SCI output, therefore
* it should be used with care. Frequent usage is for debugging.
* @return SUCCESS when string was sent
* FAILURE when an error occurred
*/
-int32_t rpp_sci_printk(const char* format, ...);
+int32_t rpp_sci_printk(const char *format, ...);
/**
* C style printk using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This call is intended to be used from interrupt only.
* Function tries to append string to the output buffer.
*
* @return The number of characters that have been written to the buffer.
* If an error occurs, a negative number is returned.
*/
-int32_t rpp_sci_printkb(const char* format, ...);
+int32_t rpp_sci_printkb(const char *format, ...);
// C style API
/**
* C style printf using RPP SCI module.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This function will wait until all the bytes are sent to the SCI output
* non-negative and less than the buffer size, the string has been
* completely written.
*/
-int32_t rpp_sci_printf(const char* format, ...);
+int32_t rpp_sci_printf(const char *format, ...);
/**
* C style vprintf using RPP SCI module.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This function will wait until all the bytes are sent to the SCI output
* non-negative and less than the buffer size, the string has been
* completely written.
*/
-int32_t rpp_sci_vprintf(const char* format, va_list args);
+int32_t rpp_sci_vprintf(const char *format, va_list args);
/**
* C style putc (put character) using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This is a blocking call.
*
* This function will wait until the given byte is put into SCI output buffer if
/**
* C style getc (get character) using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This is a blocking call.
*
* This function will wait until a byte is available in the SCI input buffer if
#endif /* __RPP_SCI_H */
-