Skip to contentSkip to conversation

export SPI functions to standalone apps

PATCH New Mike Frysinger 2 participants 6 messages Jul 23, 2009 – Aug 13, 2009

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 export SPI functions to standalone apps

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

---
v3
- tweak code style

 common/exports.c   |    8 ++++++++
 include/_exports.h |   14 ++++++++++----
 include/exports.h  |    3 ++-
 3 files changed, 20 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 +10 -4
index af43885..f3df568 100644
@@ -1,3 +1,7 @@
+/*
+ * 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 +18,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
#1 lore raw

PATCH v3 1/1 export SPI functions to standalone apps

Dear Mike Frysinger,

Quoted 11 lines · In message <[email protected]> you wrote:

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

---
v3
- tweak code style

 common/exports.c   |    8 ++++++++
 include/_exports.h |   14 ++++++++++----
 include/exports.h  |    3 ++-
 3 files changed, 20 insertions(+), 5 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 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
When a program is being  tested,  it  is  too  late  to  make  design
changes.                  -- Geoffrey James, "The Tao of Programming"
#2 lore raw

PATCH v3 1/1 export SPI functions to standalone apps

In reply to Mike Frysinger

Dear Mike,

Quoted 11 lines · In message <[email protected]> you wrote:

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

---
v3
- tweak code style

 common/exports.c   |    8 ++++++++
 include/_exports.h |   14 ++++++++++----
 include/exports.h  |    3 ++-
 3 files changed, 20 insertions(+), 5 deletions(-)

This patch causes a build error on the "trab" board:

board/trab/../../examples/standalone/libstubs.a(stubs.o): In function `dummy':
include/_exports.h:27: multiple definition of `spi_init' board/trab/tsc2000.o:board/trab/tsc2000.c:52: first defined here make[1]: *** [board/trab/trab_fkt.srec] Error 1
make: *** [board/trab/libtrab.a] Error 2

Please provide a fix.

Best regards,

Wolfgang Denk

Signature · 5 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
Another dream that failed.  There's nothing sadder.
	-- Kirk, "This side of Paradise", stardate 3417.3
#3 lore raw

PATCH 1/1 trab: rename spi_init()

The local board-specific spi_init() function conflicts with the common SPI layer, so rename it to something board-specific.

---
Note: i've only semi-compile tested this because building for arm results
in common math build/link failures related to libgcc math and i really have no interest in tracking those down

 board/trab/cmd_trab.c |    8 ++++----
 board/trab/trab_fkt.c |    2 +-
 board/trab/tsc2000.c  |    2 +-
 board/trab/tsc2000.h  |    2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
board/trab/cmd_trab.c +4 -4
index d0465fb..ae6f7c6 100644
@@ -106,7 +106,7 @@ extern int i2c_write (uchar, uint, int , uchar* , int);
 extern int i2c_read (uchar, uint, int , uchar* , int);
 extern void tsc2000_reg_init (void);
 extern s32 tsc2000_contact_temp (void);
-extern void spi_init(void);
+extern void tsc2000_spi_init(void);
 
 /* function declarations */
 int do_dip (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
@@ -175,7 +175,7 @@ int do_burn_in (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	led_init ();
 	global_vars_init ();
 	test_function_table_init ();
-	spi_init ();
+	tsc2000_spi_init ();
 
 	if (global_vars_write_to_eeprom () != 0) {
 		printf ("%s: error writing global_vars to eeprom\n",
@@ -336,7 +336,7 @@ int do_contact_temp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 1;
 	}
 
-	spi_init ();
+	tsc2000_spi_init ();
 
 	contact_temp = tsc2000_contact_temp();
 	printf ("%d degree C * 100\n", contact_temp) ;
@@ -859,7 +859,7 @@ int do_temp_log (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		delay = simple_strtoul(argv[1], NULL, 10);
 	}
 
-	spi_init ();
+	tsc2000_spi_init ();
 	while (1) {
 
 #if defined(CONFIG_CMD_DATE)
board/trab/trab_fkt.c +1 -1
index 53cdb5a..74cdbfc 100644
@@ -729,7 +729,7 @@ int do_dac (char **argv)
 	int brightness;
 
 	/* initialize SPI */
-	spi_init ();
+	tsc2000_spi_init ();
 
 	if  (((brightness = simple_strtoul (argv[2], NULL, 10)) < 0) ||
 	     (brightness > 255)) {
board/trab/tsc2000.c +1 -1
index f13a5a9..986b6fb 100644
@@ -42,7 +42,7 @@
  */
 #define MAX_DEVIATION	18	/* unit: DIGITs of adc; 18 DIGIT = 0.5 ?C */
 
-void spi_init(void)
+void tsc2000_spi_init(void)
 {
 	S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
 	S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
board/trab/tsc2000.h +1 -1
index af1b644..50c09c2 100644
@@ -121,7 +121,7 @@ void tsc2000_set_range (unsigned int);
 void tsc2000_reg_init (void);
 s32 tsc2000_contact_temp (void);
 void spi_wait_transmit_done (void);
-void spi_init(void);
+void tsc2000_spi_init(void);
 int tsc2000_interpolate(long value, long data[][2], long *result);
 void adc_wait_conversion_done(void);
 
Signature · 1 line
1.6.3.3
#4 lore raw

PATCH 1/1 trab: rename spi_init()

Dear Mike Frysinger,

Quoted 4 lines · In message <[email protected]> you wrote:

The local board-specific spi_init() function conflicts with the common SPI layer, so rename it to something board-specific.

Thanks.

Quoted 3 lines

Note: i've only semi-compile tested this because building for arm results
in common math build/link failures related to libgcc math and i really have no interest in tracking those down

If your tool chain has problems, exporting "USE_PRIVATE_LIBGCC=yes" will use U-Boot's local routines which are supposed to work.

Best regards,

Wolfgang Denk

Signature · 5 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
Syntactic sugar causes cancer of the semicolon.
                - Epigrams in Programming, ACM SIGPLAN Sept. 1982
#5 lore raw

PATCH 1/1 trab: rename spi_init()

In reply to Mike Frysinger

Dear Mike Frysinger,

Quoted 9 lines · In message <[email protected]> you wrote:

The local board-specific spi_init() function conflicts with the common SPI layer, so rename it to something board-specific.

---
Note: i've only semi-compile tested this because building for arm results
in common math build/link failures related to libgcc math and i really have no interest in tracking those down

Quoted 5 lines
 board/trab/cmd_trab.c |    8 ++++----
 board/trab/trab_fkt.c |    2 +-
 board/trab/tsc2000.c  |    2 +-
 board/trab/tsc2000.h  |    2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

Compile tested by me.

Applied. Thanks.

Best regards,

Wolfgang Denk

Signature · 6 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
"We all agree on the necessity of compromise. We just can't agree  on
when it's necessary to compromise."
                - Larry Wall in  <[email protected]>