This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Flash API change: remove printf function from cyg_flash_init


This has been discussed to death on ecos-maintainers.

Checked in.

Jifl
--
*See us at Embedded World 2009, Nürnberg, Germany, 3-5 Mar, Stand 11-300*
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine
Index: devs/flash/spi/m25pxx/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/spi/m25pxx/current/ChangeLog,v
retrieving revision 1.1
diff -u -5 -p -r1.1 ChangeLog
--- devs/flash/spi/m25pxx/current/ChangeLog	5 Feb 2009 17:25:24 -0000	1.1
+++ devs/flash/spi/m25pxx/current/ChangeLog	18 Feb 2009 23:47:59 -0000
@@ -1,5 +1,11 @@
+2009-02-18  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* test/m25pxx_test.c (cyg_user_start): Update for minor flash API
+	mod to call cyg_flash_set_global_printf() to set printf
+	function.
+
 2009-02-05  Chris Holgate  <chris@zynaptic.com>
 
 	* cdl/m25pxx.cdl: 
 	* include/m25pxx.h: 
 	* src/m25pxx.c: 
Index: devs/flash/spi/m25pxx/current/test/m25pxx_test.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/spi/m25pxx/current/test/m25pxx_test.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 m25pxx_test.c
--- devs/flash/spi/m25pxx/current/test/m25pxx_test.c	5 Feb 2009 17:25:25 -0000	1.1
+++ devs/flash/spi/m25pxx/current/test/m25pxx_test.c	18 Feb 2009 23:48:00 -0000
@@ -374,11 +374,12 @@ out:
 void cyg_user_start
     (void)
 {
     do_version();
     diag_printf ("----\nChecking for M25Pxx compatible devices.\n");
-    cyg_flash_init (&diag_printf);
+    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+    cyg_flash_init();
     CYG_TEST_INIT();
     cyg_thread_create(
         10,                                   // Arbitrary priority
         (cyg_thread_entry_t*) run_tests,      // Thread entry point
         0,                                    // 
Index: devs/flash/synth/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synth/current/ChangeLog,v
retrieving revision 1.12
diff -u -5 -p -r1.12 ChangeLog
--- devs/flash/synth/current/ChangeLog	29 Jan 2009 17:48:31 -0000	1.12
+++ devs/flash/synth/current/ChangeLog	18 Feb 2009 23:48:00 -0000
@@ -1,5 +1,11 @@
+2009-02-18  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* tests/flash2.c (cyg_user_start): Update for minor flash API
+	mod to call cyg_flash_set_global_printf() to set printf
+	function.
+
 2008-12-23  Simon Kallweit  <simon.kallweit@intefo.ch>
 
 	* src/flash_erase_block.c:
 	* src/flash_program_buf.c:
 	Implemented simulation of proper NOR flash writes. General cleanup.
@@ -79,11 +85,11 @@
  	
 //===========================================================================
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
 // the Free Software Foundation; either version 2 or (at your option) any   
 // later version.                                                           
Index: devs/flash/synth/current/tests/flash2.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synth/current/tests/flash2.c,v
retrieving revision 1.4
diff -u -5 -p -r1.4 flash2.c
--- devs/flash/synth/current/tests/flash2.c	29 Jan 2009 17:48:32 -0000	1.4
+++ devs/flash/synth/current/tests/flash2.c	18 Feb 2009 23:48:00 -0000
@@ -9,11 +9,11 @@ static char copyright[] = 
 "//"
 "//=========================================================================="
 "// ####ECOSGPLCOPYRIGHTBEGIN####                                          "
 "// -------------------------------------------                            "
 "// This file is part of eCos, the Embedded Configurable Operating System. "
-"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. "
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. "
 "//                                                                   "
 "// eCos is free software; you can redistribute it and/or modify it under  "
 "// the terms of the GNU General Public License as published by the Free   "
 "// Software Foundation; either version 2 or (at your option) any later    "
 "// version.                                                               "
@@ -87,11 +87,12 @@ void cyg_user_start(void)
     cyg_uint32 i=0;
     cyg_uint32 j;
     
     CYG_TEST_INIT();
   
-    ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
+    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+    ret=cyg_flash_init();
   
     CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
 
     do {
       ret = cyg_flash_get_info(i, &info);
Index: devs/flash/synthv2/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/ChangeLog,v
retrieving revision 1.7
diff -u -5 -p -r1.7 ChangeLog
--- devs/flash/synthv2/current/ChangeLog	29 Jan 2009 17:48:32 -0000	1.7
+++ devs/flash/synthv2/current/ChangeLog	18 Feb 2009 23:48:00 -0000
@@ -1,5 +1,12 @@
+2009-02-18  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* tests/flash2.c (cyg_user_start): Update for minor flash API
+	mod to call cyg_flash_set_global_printf() to set printf
+	function.
+	* tests/flash3.c (cyg_user_start): Ditto.
+
 2008-12-23  Simon Kallweit  <simon.kallweit@intefo.ch>
 
 	* src/synth.c: Implemented simulation of proper NOR flash writes.
 	General cleanup.
 
@@ -73,11 +80,11 @@
  	
 //===========================================================================
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
 // the Free Software Foundation; either version 2 or (at your option) any   
 // later version.                                                           
Index: devs/flash/synthv2/current/tests/flash2.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/tests/flash2.c,v
retrieving revision 1.5
diff -u -5 -p -r1.5 flash2.c
--- devs/flash/synthv2/current/tests/flash2.c	29 Jan 2009 17:48:32 -0000	1.5
+++ devs/flash/synthv2/current/tests/flash2.c	18 Feb 2009 23:48:02 -0000
@@ -9,11 +9,11 @@ static char copyright[] = 
 "//"
 "//=========================================================================="
 "// ####ECOSGPLCOPYRIGHTBEGIN####                                          "
 "// -------------------------------------------                            "
 "// This file is part of eCos, the Embedded Configurable Operating System. "
-"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. "
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. "
 "//                                                                   "
 "// eCos is free software; you can redistribute it and/or modify it under  "
 "// the terms of the GNU General Public License as published by the Free   "
 "// Software Foundation; either version 2 or (at your option) any later    "
 "// version.                                                               "
@@ -93,11 +93,12 @@ void cyg_user_start(void)
     cyg_flashaddr_t prog_start;
     unsigned char * ptr;
 
     CYG_TEST_INIT();
   
-    ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
+    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+    ret=cyg_flash_init();
     
     CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
 
     do {
       ret = cyg_flash_get_info(i, &info);
Index: devs/flash/synthv2/current/tests/flash3.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/tests/flash3.c,v
retrieving revision 1.5
diff -u -5 -p -r1.5 flash3.c
--- devs/flash/synthv2/current/tests/flash3.c	29 Jan 2009 17:48:32 -0000	1.5
+++ devs/flash/synthv2/current/tests/flash3.c	18 Feb 2009 23:48:02 -0000
@@ -9,11 +9,11 @@ static char copyright[] = 
 "//"
 "//=========================================================================="
 "// ####ECOSGPLCOPYRIGHTBEGIN####                                          "
 "// -------------------------------------------                            "
 "// This file is part of eCos, the Embedded Configurable Operating System. "
-"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. "
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. "
 "//                                                                   "
 "// eCos is free software; you can redistribute it and/or modify it under  "
 "// the terms of the GNU General Public License as published by the Free   "
 "// Software Foundation; either version 2 or (at your option) any later    "
 "// version.                                                               "
@@ -117,11 +117,12 @@ void cyg_user_start(void)
     CYG_TEST_INIT();
 
     // Reference the flash dev so the linker does not throw it away
     CYG_REFERENCE_OBJECT(cyg_flash_synth_flashdev_flash3);  
 
-    ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
+    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+    ret=cyg_flash_init();
     
     CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
 
     do {
       ret = cyg_flash_get_info(i, &info);
Index: io/flash/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/ChangeLog,v
retrieving revision 1.49
diff -u -5 -p -r1.49 ChangeLog
--- io/flash/current/ChangeLog	13 Feb 2009 16:36:26 -0000	1.49
+++ io/flash/current/ChangeLog	18 Feb 2009 23:48:20 -0000
@@ -1,5 +1,34 @@
+2009-02-18  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* include/flash.h: Modest API change: cyg_flash_init() no longer
+	takes a printf function argument. Instead two new API functions
+	are available: cyg_flash_set_printf() and
+	cyg_flash_set_global_printf().
+	
+	* src/flash.c (CHATTER): Don't attempt output if printf function
+	is NULL.
+	(cyg_flash_init): No longer takes printf arg.
+	(cyg_flash_set_printf): New. Set per-device printf function, locking
+	if needed.
+	(cyg_flash_set_global_printf): New. Set printf function for all
+	devices, locking if needed.
+	
+	* src/flashiodev.c (flashiodev_init): cyg_flash_init no longer takes
+	printf arg, and we can leave global printf at default.
+	* src/flashiodevlegacy.c (flashiodev_init): Ditto.
+
+	* src/legacy_api.c (flash_init): cyg_flash_init no longer takes
+	printf arg. So call cyg_flash_set_global_printf as well.
+
+	* src/legacy_dev.c (legacy_flash_init): legacy drivers can't handle
+	NULL printf function, so provide a dummy.
+
+	* doc/flash.sgml: Document removal of printf functionality of
+	cyg_flash_init() and document cyg_flash_set_printf() and
+	cyg_flash_set_global_printf().
+
 2009-02-13  Bart Veer  <bartv@ecoscentric.com>
 
 	* doc/flash.sgml: remove incomplete sentence.
 
 	* cdl/io_flash.cdl: remove CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM, no
@@ -640,11 +669,11 @@
 
 //===========================================================================
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006, 2008 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
 // the Free Software Foundation; either version 2 or (at your option) any   
 // later version.                                                           
Index: io/flash/current/doc/flash.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/doc/flash.sgml,v
retrieving revision 1.6
diff -u -5 -p -r1.6 flash.sgml
--- io/flash/current/doc/flash.sgml	13 Feb 2009 16:36:26 -0000	1.6
+++ io/flash/current/doc/flash.sgml	18 Feb 2009 23:48:22 -0000
@@ -9,11 +9,11 @@
 <!--     eCos FLASH support                                          -->
 <!--                                                                 -->
 <!-- =============================================================== -->
 <!-- ####ECOSDOCCOPYRIGHTBEGIN####                                   -->
 <!-- =============================================================== -->
-<!-- Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. -->
+<!-- Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. -->
 <!-- This material may be distributed only subject to the terms      -->
 <!-- and conditions set forth in the Open Publication License, v1.0  -->
 <!-- or later (the latest version is presently available at          -->
 <!-- http://www.opencontent.org/openpub/)                            -->
 <!-- Distribution of the work or derivative of the work in any       -->
@@ -116,23 +116,11 @@ the FLASH library should include.</PARA>
 <PARA>The FLASH library needs to be initialized before other FLASH
 operations can be performed. This only needs to be done once. The
 following function will only do the initialization once so it's safe
 to call multiple times: </PARA>
 
-<PROGRAMLISTING>__externC int cyg_flash_init(const cyg_flash_printf *pf); 
-typedef int cyg_flash_printf(const char *fmt, ...); </PROGRAMLISTING>
-
-<PARA>
-The parameter <parameter>pf</parameter> is a pointer to a function
-which is to be used for diagnostic output. Typically the function
-<function>diag_printf()</function> will be passed. Normally this
-function is not used by the higher layer of the library unless
-<literal>CYGSEM_IO_FLASH_CHATTER</literal> is enabled.  Passing a
-<parameter>NULL</parameter> is not recommended, even when
-CYGSEM_IO_FLASH_CHATTER is disabled. The lower layers of the library
-may unconditionally call this function, especially when errors occur,
-probably resulting in a more serious error/crash!.</PARA>
+<PROGRAMLISTING>__externC int cyg_flash_init(void); </PROGRAMLISTING>
 </SECT2>
 
 <SECT2>
 <TITLE>Retrieving information about FLASH devices</TITLE> 
 
@@ -279,11 +267,47 @@ blocked.</PARA>
 <PROGRAMLISTING>
 __externC int cyg_flash_mutex_lock(const cyg_flashaddr_t from, size_t len);
 __externC int cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len);
 </PROGRAMLISTING>
 
-</SECT2
+</SECT2>
+
+<SECT2>
+<TITLE>Configuring diagnostic output</TITLE>
+
+<PARA> Each FLASH device can have an associated function which is
+called to perform diagnostic output. The function to be used can
+be configured with the following functions: </PARA>
+
+<PROGRAMLISTING>__externC int cyg_flash_set_printf(const cyg_flashaddr_t flash_base,
+                                   cyg_flash_printf *pf);
+__externC void cyg_flash_set_global_printf(cyg_flash_printf *pf);
+typedef int cyg_flash_printf(const char *fmt, ...); </PROGRAMLISTING>
+
+<PARA>The parameter <parameter>pf</parameter> is a pointer to a function
+which is to be used for diagnostic output. Typically the function
+<function>diag_printf()</function> will be passed. Normally this
+function is not used by the higher layer of the library unless
+<literal>CYGSEM_IO_FLASH_CHATTER</literal> is enabled.  Passing a
+<parameter>NULL</parameter> causes diagnostic output from lower level
+drivers to be discarded.</PARA>
+
+<PARA><function>cyg_flash_set_printf</function> is used to set a
+diagnostic output function which will be used specifically when
+diagnostic output is attempted from the FLASH device driver associated
+with the base address of <parameter>flash_base</parameter>. An error
+will be returned if no FLASH device is found for this address, or the
+FLASH subsystem has not yet been initialised with
+<function>cyg_flash_init</function>.</PARA>
+
+<PARA><function>cyg_flash_set_global_printf</function> sets a
+diagnostic output function for all available FLASH devices. Any
+previous setting of a diagnostic output function (including with
+<function>cyg_flash_set_printf</function>) will be discarded.
+This function may be called prior to
+<function>cyg_flash_init</function>.</PARA>
+</SECT2>
 
 <SECT2>
 
 <TITLE>Return values and errors</TITLE>
 
Index: io/flash/current/include/flash.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/include/flash.h,v
retrieving revision 1.20
diff -u -5 -p -r1.20 flash.h
--- io/flash/current/include/flash.h	29 Jan 2009 17:49:46 -0000	1.20
+++ io/flash/current/include/flash.h	18 Feb 2009 23:48:22 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -78,11 +78,14 @@ typedef struct {
   cyg_uint32                    num_block_infos;    // Number of entries
   const cyg_flash_block_info_t* block_info;         // Info about block sizes
 } cyg_flash_info_t;
 
 typedef int cyg_flash_printf(const char *fmt, ...);
-__externC int cyg_flash_init( cyg_flash_printf *pf );
+__externC int cyg_flash_init(void);
+__externC int cyg_flash_set_printf(const cyg_flashaddr_t flash_base,
+                                   cyg_flash_printf *pf);
+__externC void cyg_flash_set_global_printf(cyg_flash_printf *pf);
 __externC int cyg_flash_get_info(cyg_uint32 devno, 
                                  cyg_flash_info_t * info);
 __externC int cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base, 
                                       cyg_flash_info_t * info);
 __externC int cyg_flash_verify_addr(const cyg_flashaddr_t address);
Index: io/flash/current/src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flash.c,v
retrieving revision 1.30
diff -u -5 -p -r1.30 flash.c
--- io/flash/current/src/flash.c	29 Jan 2009 17:49:46 -0000	1.30
+++ io/flash/current/src/flash.c	18 Feb 2009 23:48:22 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc.
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -74,11 +74,14 @@
 #endif
 
 // Optional verbosity. Using a macro here avoids lots of ifdefs in the
 // rest of the code.
 #ifdef CYGSEM_IO_FLASH_CHATTER
-# define CHATTER(_dev_, _fmt_, ...) (*(_dev_)->pf)((_fmt_), ## __VA_ARGS__)
+# define CHATTER(_dev_, _fmt_, ...) CYG_MACRO_START \
+    if ((_dev_)->pf)                                \
+        (*(_dev_)->pf)((_fmt_), ## __VA_ARGS__);    \
+    CYG_MACRO_END
 #else
 # define CHATTER(_dev_, _fmt_, ...) CYG_EMPTY_STATEMENT
 #endif
 
 // Per-thread locking. Again using macros avoids lots of ifdefs
@@ -215,27 +218,22 @@ find_dev(cyg_flashaddr_t addr, int* stat
 // Initialise all registered device. Any device that fails to
 // initialise we leave dev->init as false. Then sort the devices into
 // ascending order of address and put them into a linked list. Lastly
 // check if we have any overlap of the addresses.
 __externC int 
-cyg_flash_init(cyg_flash_printf *pf) 
+cyg_flash_init(void) 
 {
   int err;
   struct cyg_flash_dev * dev;
   
   CYG_ASSERT(&(cyg_flashdevtab[CYGHWR_IO_FLASH_DEVICE]) == &cyg_flashdevtab_end, "incorrect number of flash devices");
   
   if (init) {
-      // In case the printf function has changed.
-      for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
-          dev->pf = pf;
-      }
       return CYG_FLASH_ERR_OK;
   }
 
   for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
-    dev->pf = pf;
     LOCK_INIT(dev);
     
     err = dev->funs->flash_init(dev);
     if (err != CYG_FLASH_ERR_OK) {
       continue;
@@ -279,10 +277,55 @@ cyg_flash_init(cyg_flash_printf *pf) 
   // consistent.
   init = true;
   return CYG_FLASH_ERR_OK;
 }
 
+// Set a printf function to use for a particular device,
+// which is associated with the supplied base address
+__externC int
+cyg_flash_set_printf(const cyg_flashaddr_t flash_base,
+                     cyg_flash_printf *pf)
+{
+  struct cyg_flash_dev *dev;
+  int                   stat = CYG_FLASH_ERR_OK;
+
+  dev = find_dev(flash_base, &stat);
+  if (dev) {
+    // Locking may seem like overkill, but if there's any chance of CHATTER
+    // mid-change then bad things are theoretically possible. But we only
+    // lock if this device is usable, i.e. it's been initialised.
+    if (dev->init) {
+      LOCK(dev);
+    }
+    dev->pf = pf;
+    if (dev->init) {
+      UNLOCK(dev);
+    }
+  }
+  return stat;
+}
+
+// Set a printf function to use for all flash devices.
+// This overrides any previously set printf function.
+__externC void
+ cyg_flash_set_global_printf(cyg_flash_printf *pf)
+{
+  struct cyg_flash_dev *dev;
+  for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
+    // Locking may seem like overkill, but if there's any chance of CHATTER
+    // mid-change then bad things are theoretically possible. But we only
+    // lock if this device is usable, i.e. it's been initialised.
+    if (dev->init) {
+      LOCK(dev);
+    }
+    dev->pf = pf;
+    if (dev->init) {
+      UNLOCK(dev);
+    }
+  }
+}
+
 // Is the address within one of the flash drivers?
 __externC int
 cyg_flash_verify_addr(const cyg_flashaddr_t address)
 {
   int stat = CYG_FLASH_ERR_OK;
Index: io/flash/current/src/flashiodev.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flashiodev.c,v
retrieving revision 1.10
diff -u -5 -p -r1.10 flashiodev.c
--- io/flash/current/src/flashiodev.c	29 Jan 2009 17:49:46 -0000	1.10
+++ io/flash/current/src/flashiodev.c	18 Feb 2009 23:48:23 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007, 2009 Free Software Foundation, Inc.
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -121,16 +121,14 @@ BLOCK_DEVTAB_ENTRY( cyg_io_flashdev,
                     &flashiodev_lookup,
                     NULL );
 
 // FUNCTIONS
 
-static int dummy_printf( const char *fmt, ... ) {return 0;}
-
 static bool
 flashiodev_init( struct cyg_devtab_entry *tab )
 {
-  int stat = cyg_flash_init( &dummy_printf );
+  int stat = cyg_flash_init();
   cyg_ucount32 i;
 
   if (stat == CYG_FLASH_ERR_OK)
   {
       for (i=0; i<CYGNUM_IO_FLASH_BLOCK_DEVICES; i++)
Index: io/flash/current/src/flashiodevlegacy.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flashiodevlegacy.c,v
retrieving revision 1.2
diff -u -5 -p -r1.2 flashiodevlegacy.c
--- io/flash/current/src/flashiodevlegacy.c	29 Jan 2009 17:49:46 -0000	1.2
+++ io/flash/current/src/flashiodevlegacy.c	18 Feb 2009 23:48:25 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2009 Free Software Foundation, Inc.
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -72,16 +72,14 @@ struct flashiodev_priv_t{
   char *          fis_name;
   cyg_uint32      block_size;
   cyg_bool        init;
 };
 
-static int dummy_printf( const char *fmt, ... ) {return 0;}
-
 static bool
 flashiodev_init( struct cyg_devtab_entry *tab )
 {
-  int stat = cyg_flash_init( &dummy_printf );
+  int stat = cyg_flash_init();
 
   return (stat == CYG_FLASH_ERR_OK);
 } // flashiodev_init()
 
 static Cyg_ErrNo
Index: io/flash/current/src/legacy_api.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/legacy_api.c,v
retrieving revision 1.3
diff -u -5 -p -r1.3 legacy_api.c
--- io/flash/current/src/legacy_api.c	29 Jan 2009 17:49:46 -0000	1.3
+++ io/flash/current/src/legacy_api.c	18 Feb 2009 23:48:25 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 2004 Free Software Foundation, Inc.                        
+// Copyright (C) 2004, 2009 Free Software Foundation, Inc.                        
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -55,11 +55,12 @@
 #include <cyg/io/flash.h>
 
 int
 flash_init(_printf *pf)
 {
-  return cyg_flash_init(pf);
+  cyg_flash_set_global_printf(pf);
+  return cyg_flash_init();
 }
 
 int
 flash_verify_addr(void *target)
 {
Index: io/flash/current/src/legacy_dev.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/legacy_dev.c,v
retrieving revision 1.3
diff -u -5 -p -r1.3 legacy_dev.c
--- io/flash/current/src/legacy_dev.c	29 Jan 2009 17:49:46 -0000	1.3
+++ io/flash/current/src/legacy_dev.c	18 Feb 2009 23:48:25 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 2004, 2006 Free Software Foundation, Inc.                  
+// Copyright (C) 2004, 2006, 2009 Free Software Foundation, Inc.                  
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -79,18 +79,24 @@ externC code_fun flash_erase_block;
 externC code_fun flash_program_buf;
 externC code_fun flash_read_buf;
 externC code_fun flash_lock_block;
 externC code_fun flash_unlock_block;
 
+static int dummy_printf( const char *fmt, ... ) {return 0;}
+
 // Initialize the device
 static int 
 legacy_flash_init (struct cyg_flash_dev *dev)
 {
   int err;
   static cyg_flash_block_info_t block_info[1];
 
-  flash_info.pf = dev->pf;
+  // Legacy device drivers can't handle NULL printf function
+  if (NULL != dev->pf)
+      flash_info.pf = dev->pf;
+  else
+      flash_info.pf = &dummy_printf;
   
   err=flash_hwr_init();
 
   if (!err) {
     dev->start = (cyg_flashaddr_t)flash_info.start;
Index: redboot/current/src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.86
diff -u -5 -p -r1.86 flash.c
--- redboot/current/src/flash.c	29 Jan 2009 17:50:04 -0000	1.86
+++ redboot/current/src/flash.c	18 Feb 2009 23:48:31 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 //
 // eCos is free software; you can redistribute it and/or modify it under    
 // the terms of the GNU General Public License as published by the Free     
 // Software Foundation; either version 2 or (at your option) any later      
 // version.                                                                 
@@ -1859,12 +1859,13 @@ do_flash_init(void)
 
 
 
     if (!__flash_init) {
         __flash_init = 1;
-        
-        if ((stat = cyg_flash_init(diag_printf)) != 0) {
+
+        cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+        if ((stat = cyg_flash_init()) != 0) {
             diag_printf("FLASH: driver init failed: %s\n", cyg_flash_errmsg(stat));
             return -1;
         }
 
 #ifdef CYGNUM_REDBOOT_FLASH_BASE

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]