Skip to contentSkip to conversation

export SPI functions to standalone apps

PATCH Superseded Mike Frysinger 3 participants 4 messages Jul 19, 2009 – Jul 23, 2009

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 export SPI functions to standalone apps

---
 common/exports.c   |    8 ++++++++
 include/_exports.h |    8 ++++++++
 include/exports.h  |    3 ++-
 3 files changed, 18 insertions(+), 1 deletions(-)
common/exports.c +8 -0
index ec4656b..b3b6e1f 100644
@@ -38,4 +38,12 @@ void jumptable_init (void)
 	gd->jt[XF_i2c_write] = (void *) i2c_write;
 	gd->jt[XF_i2c_read] = (void *) i2c_read;
 #endif
+#ifdef CONFIG_CMD_SPI
+	gd->jt[XF_spi_init] = (void *) spi_init;
+	gd->jt[XF_spi_setup_slave] = (void *) spi_setup_slave;
+	gd->jt[XF_spi_free_slave] = (void *) spi_free_slave;
+	gd->jt[XF_spi_claim_bus] = (void *) spi_claim_bus;
+	gd->jt[XF_spi_release_bus] = (void *) spi_release_bus;
+	gd->jt[XF_spi_xfer] = (void *) spi_xfer;
+#endif
 }
include/_exports.h +8 -0
index af43885..2ff95cf 100644
@@ -24,3 +24,11 @@ EXPORT_FUNC(strcmp)
 EXPORT_FUNC(i2c_write)
 EXPORT_FUNC(i2c_read)
 #endif
+#ifdef CONFIG_CMD_SPI
+EXPORT_FUNC(spi_init)
+EXPORT_FUNC(spi_setup_slave)
+EXPORT_FUNC(spi_free_slave)
+EXPORT_FUNC(spi_claim_bus)
+EXPORT_FUNC(spi_release_bus)
+EXPORT_FUNC(spi_xfer)
+#endif
include/exports.h +2 -1
index 0620e9e..16ea03a 100644
@@ -33,6 +33,7 @@ void forceenv (char *varname, char *varvalue);
 int i2c_write (uchar, uint, int , uchar* , int);
 int i2c_read (uchar, uint, int , uchar* , int);
 #endif
+#include <spi.h>
 
 void app_startup(char **);
 
@@ -46,7 +47,7 @@ enum {
 	XF_MAX
 };
 
-#define XF_VERSION	4
+#define XF_VERSION	5
 
 #if defined(CONFIG_I386)
 extern gd_t *global_data;
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/1 export SPI functions to standalone apps

Quoted 14 lines · Mike Frysinger

---

common/exports.c   |    8 ++++++++
include/_exports.h |    8 ++++++++
include/exports.h  |    3 ++-
3 files changed, 18 insertions(+), 1 deletions(-)
common/exports.c +0 -0
index ec4656b..b3b6e1f 100644
@@ -38,4 +38,12 @@ void jumptable_init (void)
 	gd->jt[XF_i2c_write] = (void *) i2c_write;
 	gd->jt[XF_i2c_read] = (void *) i2c_read;

common/exports.c void jumptable_init (void) · line 49

Quoted 10 lines
common/exports.c +8 -0
 #endif
+#ifdef CONFIG_CMD_SPI
+	gd->jt[XF_spi_init] = (void *) spi_init;
+	gd->jt[XF_spi_setup_slave] = (void *) spi_setup_slave;
+	gd->jt[XF_spi_free_slave] = (void *) spi_free_slave;
+	gd->jt[XF_spi_claim_bus] = (void *) spi_claim_bus;
+	gd->jt[XF_spi_release_bus] = (void *) spi_release_bus;
+	gd->jt[XF_spi_xfer] = (void *) spi_xfer;
+#endif
 }

Such conditional entries in the jumptable make this interface unstable, as the calls table is made dependent on configuration of a particular image built, while it should only depend on the interface version. The application in such case is entagled with the knowledge of how the underlying firmware was configured at build time. I know there are other calls already #ifdef'ed, but they should be all fixed.

Rafal

#2 lore raw

PATCH v2 1/1 export SPI functions to standalone apps

While we're here, fix the broken #ifdef handling in _exports.h.

---
v2
- drop all wrong #ifdef usage in _exports.h

 common/exports.c   |    8 ++++++++
 include/_exports.h |   13 +++++++++----
 include/exports.h  |    3 ++-
 3 files changed, 19 insertions(+), 5 deletions(-)
common/exports.c +8 -0
index ec4656b..b3b6e1f 100644
@@ -38,4 +38,12 @@ void jumptable_init (void)
 	gd->jt[XF_i2c_write] = (void *) i2c_write;
 	gd->jt[XF_i2c_read] = (void *) i2c_read;
 #endif
+#ifdef CONFIG_CMD_SPI
+	gd->jt[XF_spi_init] = (void *) spi_init;
+	gd->jt[XF_spi_setup_slave] = (void *) spi_setup_slave;
+	gd->jt[XF_spi_free_slave] = (void *) spi_free_slave;
+	gd->jt[XF_spi_claim_bus] = (void *) spi_claim_bus;
+	gd->jt[XF_spi_release_bus] = (void *) spi_release_bus;
+	gd->jt[XF_spi_xfer] = (void *) spi_xfer;
+#endif
 }
include/_exports.h +9 -4
index af43885..ba3920e 100644
@@ -1,3 +1,6 @@
+/* You do not need to use #ifdef around functions that may not exist
+ * in the final configuration (such as i2c).
+ */
 EXPORT_FUNC(get_version)
 EXPORT_FUNC(getc)
 EXPORT_FUNC(tstc)
@@ -14,13 +17,15 @@ EXPORT_FUNC(vprintf)
 EXPORT_FUNC(do_reset)
 EXPORT_FUNC(getenv)
 EXPORT_FUNC(setenv)
-#ifdef CONFIG_HAS_UID
 EXPORT_FUNC(forceenv)
-#endif
 EXPORT_FUNC(simple_strtoul)
 EXPORT_FUNC(simple_strtol)
 EXPORT_FUNC(strcmp)
-#if defined(CONFIG_CMD_I2C)
 EXPORT_FUNC(i2c_write)
 EXPORT_FUNC(i2c_read)
-#endif
+EXPORT_FUNC(spi_init)
+EXPORT_FUNC(spi_setup_slave)
+EXPORT_FUNC(spi_free_slave)
+EXPORT_FUNC(spi_claim_bus)
+EXPORT_FUNC(spi_release_bus)
+EXPORT_FUNC(spi_xfer)
include/exports.h +2 -1
index 0620e9e..16ea03a 100644
@@ -33,6 +33,7 @@ void forceenv (char *varname, char *varvalue);
 int i2c_write (uchar, uint, int , uchar* , int);
 int i2c_read (uchar, uint, int , uchar* , int);
 #endif
+#include <spi.h>
 
 void app_startup(char **);
 
@@ -46,7 +47,7 @@ enum {
 	XF_MAX
 };
 
-#define XF_VERSION	4
+#define XF_VERSION	5
 
 #if defined(CONFIG_I386)
 extern gd_t *global_data;
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH v2 1/1 export SPI functions to standalone apps

Dear Mike Frysinger,

Quoted 1 line · In message <[email protected]> you wrote:

While we're here, fix the broken #ifdef handling in _exports.h.

...

include/_exports.h line 3

Quoted 8 lines
include/_exports.h +3 -0
index af43885..ba3920e 100644
@@ -1,3 +1,6 @@
+/* You do not need to use #ifdef around functions that may not exist
+ * in the final configuration (such as i2c).
+ */

Incorrect multi-line comment style.

Please cleanup and resubmit.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Two wrongs don't make a right, but three rights make a left.