From 5161713eaf2ebdf0eee8a843db5949acb1939a59 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Tue, 6 May 2014 10:42:06 +0100 Subject: [PATCH] init: allow init to be called multiple times Signed-off-by: Brendan Le Foll --- api/maa.h | 1 + src/intel_galileo_rev_d.c | 2 +- src/maa.c | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/maa.h b/api/maa.h index ecadb51..e2e01c0 100644 --- a/api/maa.h +++ b/api/maa.h @@ -50,6 +50,7 @@ typedef enum { MAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */ MAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */ MAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */ + MAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */ } maa_result_t; diff --git a/src/intel_galileo_rev_d.c b/src/intel_galileo_rev_d.c index 316c33f..ef7aa86 100644 --- a/src/intel_galileo_rev_d.c +++ b/src/intel_galileo_rev_d.c @@ -31,7 +31,7 @@ maa_board_t* maa_intel_galileo_rev_d() { maa_board_t* b = (maa_board_t*) malloc(sizeof(maa_board_t)); - if(b == NULL) + if (b == NULL) return NULL; b->phy_pin_count = 20; diff --git a/src/maa.c b/src/maa.c index 971c239..31e3f95 100644 --- a/src/maa.c +++ b/src/maa.c @@ -31,7 +31,7 @@ #include "version.h" static maa_pininfo_t* pindata; -static maa_board_t* plat; +static maa_board_t* plat = NULL; const char * maa_get_version() @@ -45,6 +45,9 @@ maa_init() /** Once more board definitions have been added, * A method for detecting them will need to be devised. */ + if (plat != NULL) { + return MAA_ERROR_PLATFORM_ALREADY_INITIALISED; + } plat = maa_intel_galileo_rev_d(); return MAA_SUCCESS; }