]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/include/rpp/sci.h
Make the RPP layer thread safe
[pes-rpp/rpp-lib.git] / rpp / include / rpp / sci.h
index b84682735ad324dea1696532a57ba691891ba2d6..e3481ff244daecfb34831f87c16fea8e0357d1a0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * @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.
@@ -26,6 +33,8 @@ int8_t rpp_sci_init();
 /**
  * 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
@@ -41,6 +50,8 @@ boolean_t rpp_sci_setup(uint32_t baud);
 /**
  * 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.
  *
@@ -52,6 +63,8 @@ uint16_t rpp_sci_available();
 /**
  * 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.
  *
@@ -64,12 +77,14 @@ uint16_t rpp_sci_available();
  *
  * @return SUCCESS when all data was transfered.
  */
-int8_t rpp_sci_read(uint32_t amount, uint8_tbuffer);
+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.
  *
@@ -84,12 +99,14 @@ int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);
  * @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_tbuffer);
+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.
@@ -104,12 +121,14 @@ int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);
  *
  * @return SUCCESS when all data was transfered.
  */
-int8_t rpp_sci_write(uint32_t amount, uint8_tdata);
+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.
@@ -129,12 +148,14 @@ int8_t rpp_sci_write(uint32_t amount, uint8_t* data);
  *         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_tdata);
+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
@@ -153,6 +174,8 @@ int8_t rpp_sci_flush(boolean_t buff);
 /**
  * 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.
@@ -176,12 +199,14 @@ int8_t rpp_sci_flush(boolean_t buff);
  * @return SUCCESS when string was sent
  *         FAILURE when an error occurred
  */
-int32_t rpp_sci_printk(const charformat, ...);
+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.
  *
@@ -203,13 +228,15 @@ int32_t rpp_sci_printk(const char* format, ...);
  * @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 charformat, ...);
+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
@@ -235,12 +262,14 @@ int32_t rpp_sci_printkb(const char* format, ...);
  *          non-negative and less than the buffer size, the string has been
  *          completely written.
  */
-int32_t rpp_sci_printf(const charformat, ...);
+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
@@ -266,12 +295,14 @@ int32_t rpp_sci_printf(const char* format, ...);
  *          non-negative and less than the buffer size, the string has been
  *          completely written.
  */
-int32_t rpp_sci_vprintf(const charformat, 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
@@ -287,6 +318,8 @@ int8_t rpp_sci_putc(uint8_t byte);
 /**
  * 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
@@ -308,4 +341,3 @@ int16_t rpp_sci_getc();
 
 
 #endif /* __RPP_SCI_H */
-