changeset 2816:422d0a343b4d

* 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().
author jlarmour
date Thu, 19 Feb 2009 00:14:26 +0000
parents 3cd309d2d829
children 6e1e5c6da98e
files packages/io/flash/current/ChangeLog packages/io/flash/current/doc/flash.sgml packages/io/flash/current/include/flash.h packages/io/flash/current/src/flash.c packages/io/flash/current/src/flashiodev.c packages/io/flash/current/src/flashiodevlegacy.c packages/io/flash/current/src/legacy_api.c packages/io/flash/current/src/legacy_dev.c
diffstat 8 files changed, 140 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/packages/io/flash/current/ChangeLog
+++ b/packages/io/flash/current/ChangeLog
@@ -1,3 +1,32 @@
+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.
@@ -642,7 +671,7 @@ 2000-07-29  Gary Thomas  <gthomas@redhat
 // ####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     
--- a/packages/io/flash/current/doc/flash.sgml
+++ b/packages/io/flash/current/doc/flash.sgml
@@ -11,7 +11,7 @@
 <!-- =============================================================== -->
 <!-- ####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          -->
@@ -118,19 +118,7 @@ operations can be performed. This only n
 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>
@@ -281,7 +269,43 @@ blocked.</PARA>
 __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>
 
--- a/packages/io/flash/current/include/flash.h
+++ b/packages/io/flash/current/include/flash.h
@@ -8,7 +8,7 @@
 // ####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     
@@ -80,7 +80,10 @@ typedef struct {
 } 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, 
--- a/packages/io/flash/current/src/flash.c
+++ b/packages/io/flash/current/src/flash.c
@@ -8,7 +8,7 @@
 // ####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     
@@ -76,7 +76,10 @@
 // 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
@@ -217,7 +220,7 @@ find_dev(cyg_flashaddr_t addr, int* stat
 // 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;
@@ -225,15 +228,10 @@ cyg_flash_init(cyg_flash_printf *pf)
   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);
@@ -281,6 +279,51 @@ cyg_flash_init(cyg_flash_printf *pf)
   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)
--- a/packages/io/flash/current/src/flashiodev.c
+++ b/packages/io/flash/current/src/flashiodev.c
@@ -8,7 +8,7 @@
 // ####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     
@@ -123,12 +123,10 @@ BLOCK_DEVTAB_ENTRY( cyg_io_flashdev,
 
 // 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)
--- a/packages/io/flash/current/src/flashiodevlegacy.c
+++ b/packages/io/flash/current/src/flashiodevlegacy.c
@@ -8,7 +8,7 @@
 // ####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     
@@ -74,12 +74,10 @@ struct flashiodev_priv_t{
   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()
--- a/packages/io/flash/current/src/legacy_api.c
+++ b/packages/io/flash/current/src/legacy_api.c
@@ -8,7 +8,7 @@
 // ####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     
@@ -57,7 +57,8 @@
 int
 flash_init(_printf *pf)
 {
-  return cyg_flash_init(pf);
+  cyg_flash_set_global_printf(pf);
+  return cyg_flash_init();
 }
 
 int
--- a/packages/io/flash/current/src/legacy_dev.c
+++ b/packages/io/flash/current/src/legacy_dev.c
@@ -8,7 +8,7 @@
 // ####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     
@@ -81,6 +81,8 @@ 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)
@@ -88,7 +90,11 @@ legacy_flash_init (struct cyg_flash_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();