]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/include/rpp/gio.h
Make the RPP layer thread safe
[pes-rpp/rpp-lib.git] / rpp / include / rpp / gio.h
index b2fc6a77013701d5a39cb95e80fbde4d0c4960bf..9b00364089276f655a40652d6c4dc2eef0cc8fa1 100644 (file)
@@ -1,20 +1,99 @@
 /*
- * gio.h
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Michal Sojka <sojkam1@fel.cvut.cz>
+ *     - Michal Horn
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
  *
- *  Created on: 29.10.2014
- *      Author: Michal Horn
  */
 
-#ifndef GIO_H_
-#define GIO_H_
+#ifndef RPP_GIO_H
+#define RPP_GIO_H
 
-#include "drv/digital_io.h"
+#include "types.h"
+#include "drv/gio_names.h"
 
 #define RPP_GIO_PORT_GIOA   0x2
 #define RPP_GIO_PORT_GIOB   0x4
 #define RPP_GIO_PORT_NHET1  0x8
 #define RPP_GIO_PORT_ALL    (RPP_GIO_PORT_GIOA|RPP_GIO_PORT_GIOB|RPP_GIO_PORT_NHET1)
 
+/**
+ * Intialize GIO ports.
+ *
+ * The ports are initialized according to the definition in gio_def.h.
+ *
+ * @param[in] init_ports Specifies which ports to initialize.
+ * RPP_GIO_PORT_ALL causes all ports to be initialized.
+ *
+ * This function is not thread safe. Do not call it from multiple
+ * threads.
+ *
+ * @return SUCCESS if successful, FAILURE otherwise.
+ */
 int8_t rpp_gio_init(uint32_t init_ports);
 
+/**
+ * Sets GIO output pin to a value.
+ *
+ * The function is thread safe.
+ *
+ * @param pin Pin to set
+ * @param value Value to the pin to.
+ *
+ * @return SUCCESS if successful, FAILURE otherwise.
+ */
+int8_t rpp_gio_set(enum pin_name pin, boolean_t value);
+
+/**
+ * Reads the value of a GIO pin.
+ *
+ * The function is thread safe.
+ *
+ * @param pin Pin to read.
+ *
+ * @return Pin value (0 or 1) in case of success, FAILURE otherwise.
+ */
+int8_t rpp_gio_get(enum pin_name pin);
+
+/** GIO pin input mode */
+enum rpp_gio_in_mode {
+       RPP_GIO_MODE_PULLDIS,       /**< Disable pull resistor */
+       RPP_GIO_MODE_PULLUP,
+       RPP_GIO_MODE_PULLDOWN,
+};
+
+/** GIO pin direction */
+enum rpp_gio_io {
+       RPP_GIO_IN,
+       RPP_GIO_OUT,
+};
+
+/**
+ * Configure GIO pin.
+ *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
+ * @param pin Pin to configure
+ * @param io Configure the pin as input or output.
+ * @param in_mode Input settings. Ignored when pin is configured as
+ *                output.
+ * @param open_drain Output is open drain when TRUE, pull/push when
+ *                   FALSE. Ignored when pin is configured as input.
+ *
+ * @return SUCCESS or FAILURE.
+ */
+int8_t rpp_gio_setup(enum pin_name pin,
+                                        enum rpp_gio_io io,
+                                        enum rpp_gio_in_mode in_mode,
+                                        boolean_t open_drain);
+
+int8_t rpp_gio_port_set(int port, uint32_t bits);
+int8_t rpp_gio_port_get(int port, uint32_t *bits);
+
 #endif /* GIO_H_ */