uart: add init post hook
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Sun, 19 Oct 2014 15:09:19 +0000 (16:09 +0100)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Sun, 19 Oct 2014 15:14:24 +0000 (16:14 +0100)
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
include/mraa_adv_func.h
include/mraa_internal_types.h
src/uart/uart.c

index f8b4ce0..f9f84b5 100644 (file)
@@ -60,4 +60,6 @@ typedef struct {
 
     mraa_result_t (*spi_init_pre) (int bus);
     mraa_result_t (*spi_init_post) (mraa_spi_context spi);
+
+    mraa_result_t (*uart_init_post) (mraa_uart_context uart);
 } mraa_adv_func_t;
index efe0a09..182f456 100644 (file)
@@ -83,3 +83,12 @@ struct _aio {
     int adc_in_fp; /**< File Pointer to raw sysfs */
     int value_bit; /**< 10 bits by default. Can be increased if board */
 };
+
+/**
+ * A structure representing a UART device
+ */
+struct _uart {
+    /*@{*/
+    int index; /**< the uart index, as known to the os. */
+    /*@}*/
+};
index 42ff5e0..389ba2c 100644 (file)
 #include "uart.h"
 #include "mraa_internal.h"
 
-/**
- * A structure representing a UART device
- */
-struct _uart {
-    /*@{*/
-    int index; /**< the uart index, as known to the os. */
-    /*@}*/
-};
-
 mraa_uart_context
 mraa_uart_init(int index)
 {
@@ -49,6 +40,13 @@ mraa_uart_init(int index)
     memset(dev, 0, sizeof(struct _uart));
 
     dev->index = index;
+    if (advance_func->uart_init_post != NULL) {
+        mraa_result_t ret = advance_func->uart_init_post(dev);
+        if (ret != MRAA_SUCCESS) {
+            free(dev);
+            return NULL;
+        }
+    }
 
     return dev;
 }