changeset 1762:9c1d9e5039c2

Move dummy init/query/lock/unlock functions to the generic flash code, and use these in the V2 drivers where appropriate
author bartv
date Mon, 29 Nov 2004 00:43:48 +0000
parents af5ce7899d45
children 42c8ea63b78d
files packages/devs/flash/amd/am29xxxxxv2/current/ChangeLog packages/devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx.c packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx_aux.c packages/devs/flash/atmel/dataflash/current/ChangeLog packages/devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c packages/devs/flash/intel/stratav2/current/ChangeLog packages/devs/flash/intel/stratav2/current/include/flash_strata_v2.inl packages/devs/flash/sst/39vfxxx/current/ChangeLog packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl packages/devs/flash/synthv2/current/ChangeLog packages/devs/flash/synthv2/current/src/synth.c packages/io/flash/current/ChangeLog packages/io/flash/current/include/flash_priv.h packages/io/flash/current/src/flash.c packages/io/flash/current/src/legacy_dev.c
diffstat 16 files changed, 120 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/packages/devs/flash/amd/am29xxxxxv2/current/ChangeLog
+++ b/packages/devs/flash/amd/am29xxxxxv2/current/ChangeLog
@@ -1,3 +1,10 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/am29xxxxx_dev.h, src/am29xxxxx.c, src/am29xxxxx_aux.c:
+	The dummy init/query/lock/unlock functions have been moved to the
+	generic flash package. That also now exports an anonymizer
+	function.
+
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 
 	* include/am29xxxxx_dev.h, src/am29xxxxx.c, src/am29xxxxx_aux.c,
--- a/packages/devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h
+++ b/packages/devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h
@@ -52,11 +52,7 @@
 #include <cyg/io/flash.h>
 #include <cyg/io/flash_priv.h>
 
-externC int     cyg_am29xxxxx_init_nop(struct cyg_flash_dev*);
-externC size_t  cyg_am29xxxxx_query_nop(struct cyg_flash_dev*, void*, const size_t);
 externC int     cyg_am29xxxxx_hwr_map_error_nop(struct cyg_flash_dev*, int);
-externC int     cyg_am29xxxxx_lock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
-externC int     cyg_am29xxxxx_unlock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
 
 externC int cyg_am29xxxxx_read_devid_8(     struct cyg_flash_dev*);
 externC int cyg_am29xxxxx_read_devid_16(    struct cyg_flash_dev*);
--- a/packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx.c
+++ b/packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx.c
@@ -195,26 +195,6 @@
 // ----------------------------------------------------------------------------
 // Generic code.
 
-// A dummy initialization routine, for platforms where everything is
-// done statically and there is no need to check device ids or anything similar.
-int
-cyg_am29xxxxx_init_nop(struct cyg_flash_dev* dev)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    return CYG_FLASH_ERR_OK;
-}
-
-// A dummy query routine. The implementation of this is specific to
-// each device driver, and I choose to do as little as possible.
-size_t
-cyg_am29xxxxx_query_nop(struct cyg_flash_dev* dev, void* data, size_t len)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    CYG_UNUSED_PARAM(void*, data);
-    CYG_UNUSED_PARAM(size_t, len);
-    return 0;
-}
-
 // A dummy hwr_map_error routine.
 int
 cyg_am29xxxxx_hwr_map_error_nop(struct cyg_flash_dev* dev, int err)
@@ -223,36 +203,6 @@ cyg_am29xxxxx_hwr_map_error_nop(struct c
     return err;
 }
 
-// Dummy lock/unlock routines
-int
-cyg_am29xxxxx_lock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
-    return CYG_FLASH_ERR_DRV_WRONG_PART;
-}
-
-int
-cyg_am29xxxxx_unlock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
-    return CYG_FLASH_ERR_DRV_WRONG_PART;
-}
-
-// On some architectures there are problems calling the .2ram
-// functions from the main ones. Specifically the compiler may issue a
-// short call, even though the flash and ram are too far apart. The
-// solution is to indirect via a function pointer, but the simplistic
-// approach is vulnerable to compiler optimization. Hence the function
-// pointer is passed through an anonymizer. Even this may fail in
-// future if the compiler starts doing global optimization.
-static void*
-am29_anonymizer(void* fn)
-{
-    return fn;
-}
-
 // Get info about the current block, i.e. base and size.
 static void
 am29_get_block_info(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr, cyg_flashaddr_t* block_start, size_t* block_size)
--- a/packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx_aux.c
+++ b/packages/devs/flash/amd/am29xxxxxv2/current/src/am29xxxxx_aux.c
@@ -343,7 +343,7 @@ AM29_FNNAME(cyg_am29xxxxx_read_devid) (s
     CYG_CHECK_DATA_PTR(dev, "valid flash device pointer required");
     
     addr     = AM29_P2V(dev->start);
-    query_fn = (int (*)(volatile AM29_TYPE*)) am29_anonymizer( & AM29_FNNAME(am29_hw_query) );
+    query_fn = (int (*)(volatile AM29_TYPE*)) cyg_flash_anonymizer( & AM29_FNNAME(am29_hw_query) );
     devid    = (*query_fn)(addr);
     return devid;
 }
@@ -380,7 +380,7 @@ AM29_FNNAME(cyg_am29xxxxx_init_cfi)(stru
     am29_dev    = (cyg_am29xxxxx_dev*) dev->priv;    // Remove const, only place where this is needed.
     addr        = AM29_P2V(dev->start);
     cfi_fn      = (int (*)(struct cyg_flash_dev*, cyg_am29xxxxx_dev*, volatile AM29_TYPE*))
-        am29_anonymizer( & AM29_FNNAME(am29_hw_cfi));
+        cyg_flash_anonymizer( & AM29_FNNAME(am29_hw_cfi));
 
     result      = (*cfi_fn)(dev, am29_dev, addr);
 
@@ -414,7 +414,7 @@ AM29_FNNAME(cyg_am29xxxxx_erase)(struct 
     CYG_ASSERT(addr == block_start, "erase address should be the start of a flash block");
     
     block       = AM29_P2V(addr);
-    erase_fn    = (void (*)(volatile AM29_TYPE*)) am29_anonymizer( & AM29_FNNAME(am29_hw_erase) );
+    erase_fn    = (void (*)(volatile AM29_TYPE*)) cyg_flash_anonymizer( & AM29_FNNAME(am29_hw_erase) );
     (*erase_fn)(block);
 
     // The erase may have failed for a number of reasons, e.g. because
@@ -467,7 +467,7 @@ AM29_FNNAME(cyg_am29xxxxx_program)(struc
     data        = (const cyg_uint8*) src;
 
     program_fn  = (void (*)(volatile AM29_TYPE*, volatile AM29_TYPE*, const cyg_uint8*, cyg_uint32))
-        am29_anonymizer( & AM29_FNNAME(am29_hw_program) );
+        cyg_flash_anonymizer( & AM29_FNNAME(am29_hw_program) );
     (*program_fn)(block, addr, (const cyg_uint8*)src, len / sizeof(AM29_TYPE));
     
     // Too many things can go wrong when manipulating the h/w, so
--- a/packages/devs/flash/atmel/dataflash/current/ChangeLog
+++ b/packages/devs/flash/atmel/dataflash/current/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* src/devs_flash_atmel_dataflash_flash_dev_funs.c: use the dummy
+	query/lock/unlock functions provided by the generic flash code
+
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 
 	* include/dataflash.h, src/devs_flash_atmel_dataflash.c,
--- a/packages/devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c
+++ b/packages/devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c
@@ -115,12 +115,6 @@ df_flash_init(struct cyg_flash_dev *dev)
     return CYG_DATAFLASH_ERR_OK;
 }
 
-static size_t 
-df_flash_query(struct cyg_flash_dev *dev, void *data, size_t len)
-{
-    return len;
-}
-
 static int 
 df_flash_erase_block(struct cyg_flash_dev   *dev, 
                      cyg_flashaddr_t  base)
@@ -216,33 +210,17 @@ df_flash_hwr_map_error(struct cyg_flash_
     }
 }
 
-#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
-static int 
-df_flash_block_lock(struct cyg_flash_dev   *dev, 
-                    const  cyg_flashaddr_t  block_base)
-{
-    return CYG_DATAFLASH_ERR_INVALID;
-}
-
-static int 
-df_flash_block_unlock(struct cyg_flash_dev  *dev, 
-                      const cyg_flashaddr_t  block_base)
-{
-    return CYG_DATAFLASH_ERR_INVALID;
-}
-#endif
-
 // -------------------------------------------------------------------------- 
 
 CYG_FLASH_FUNS(cyg_dataflash_flash_dev_funs,
                df_flash_init,
-               df_flash_query,
+               cyg_flash_devfn_query_nop,
                df_flash_erase_block,
                df_flash_program,
                df_flash_read,
                df_flash_hwr_map_error,
-               df_flash_block_lock,
-               df_flash_block_unlock
+               cyg_flash_devfn_lock_nop,
+               cyg_flash_devfn_unlock_nop
 );
 
 //----------------------------------------------------------------------------
--- a/packages/devs/flash/intel/stratav2/current/ChangeLog
+++ b/packages/devs/flash/intel/stratav2/current/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_strata_v2.inl: use the dummy lock/unlock functions
+	provided by the generic flash code.
+
 2004-11-25  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* include/flash_strata_v2.inl: Correct the usage of const
--- a/packages/devs/flash/intel/stratav2/current/include/flash_strata_v2.inl
+++ b/packages/devs/flash/intel/stratav2/current/include/flash_strata_v2.inl
@@ -576,8 +576,8 @@ static CYG_FLASH_FUNS (cyg_flash_strata_
                 strata_program_buf,
                 NULL,
                 strata_hwr_map_error,
-                NULL,
-                NULL);
+                cyg_flash_devfn_lock_nop,
+                cyg_flash_devfn_unlock_nop);
 #endif
 #endif //CYGONCE_DEVS_FLASH_STRATA_V2_INL
 // EOF strata.c
--- a/packages/devs/flash/sst/39vfxxx/current/ChangeLog
+++ b/packages/devs/flash/sst/39vfxxx/current/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_sst_39vfxxx.inl: use the dummy lock/unlock
+	functions provided by the generic flash code.
+
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 	
 	* include/flash_sst_39vfxxx.inl: assume static initialization and
--- a/packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl
+++ b/packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl
@@ -326,20 +326,6 @@ sst_program(struct cyg_flash_dev *dev, c
     return res;
 }
 
-#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
-static int 
-sst_block_lock(struct cyg_flash_dev   *dev, const  cyg_flashaddr_t  block_base)
-{
-    return CYG_DATAFLASH_ERR_INVALID;
-}
-
-static int 
-sst_block_unlock(struct cyg_flash_dev  *dev, const cyg_flashaddr_t  block_base)
-{
-    return CYG_DATAFLASH_ERR_INVALID;
-}
-#endif
-
 static const CYG_FLASH_FUNS(cyg_sst_funs,
 	               sst_init,
 	               sst_query,
@@ -347,7 +333,7 @@ static const CYG_FLASH_FUNS(cyg_sst_funs
 	               sst_program,
 	               NULL,              // read
 	               sst_hwr_map_error,
-	               sst_block_lock,
-	               sst_block_unlock);
+	               cyg_flash_devfn_lock_nop,
+	               cyg_flash_devfn_unlock_nop);
 
 #endif // CYGONCE_DEVS_FLASH_SST_39VFXXX_INL
--- a/packages/devs/flash/synthv2/current/ChangeLog
+++ b/packages/devs/flash/synthv2/current/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* src/synth.c: use the dummy lock/unlock functions provided by the
+	generic flash package.
+
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 
 	* include/synth.h, src/synth.c, tests/flash3.c: merge the config
--- a/packages/devs/flash/synthv2/current/src/synth.c
+++ b/packages/devs/flash/synthv2/current/src/synth.c
@@ -256,27 +256,6 @@ synth_flash_query(struct cyg_flash_dev *
     return sizeof(QUERY);
 }
 
-// Just in case there is another flash driver which does implement locking
-#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
-static int
-synth_flash_lock(struct cyg_flash_dev* dev,
-                 const cyg_flashaddr_t addr)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr);
-    return CYG_FLASH_ERR_INVALID;
-}
-
-static int
-synth_flash_unlock(struct cyg_flash_dev* dev,
-                   const cyg_flashaddr_t addr)
-{
-    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
-    CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr);
-    return CYG_FLASH_ERR_INVALID;
-}
-#endif
-
 const CYG_FLASH_FUNS(cyg_flash_synth_funs,
                      synth_flash_init,
                      synth_flash_query,
@@ -284,8 +263,8 @@ const CYG_FLASH_FUNS(cyg_flash_synth_fun
                      synth_flash_program,
                      NULL,                 // read
                      synth_flash_hwr_map_error,
-                     synth_flash_lock,
-                     synth_flash_unlock);
+                     cyg_flash_devfn_lock_nop,
+                     cyg_flash_devfn_unlock_nop);
 
 static struct cyg_flash_synth_priv synth_flash_priv = {
     .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
--- a/packages/io/flash/current/ChangeLog
+++ b/packages/io/flash/current/ChangeLog
@@ -1,3 +1,10 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_priv.h, src/flash.c, src/legacy_dev.c: provide
+	dummy init/query/lock/unlock functions for use by device drivers
+	which do not support/need this functionality. Export the
+	anonymizer function.
+
 2004-11-28  Bart Veer  <bartv@ecoscentric.com>
 
 	* src/flash.c (flash_sort_and_check): previous patch would have
--- a/packages/io/flash/current/include/flash_priv.h
+++ b/packages/io/flash/current/include/flash_priv.h
@@ -84,6 +84,17 @@ struct cyg_flash_dev_funs {
 #endif    
 };
 
+// Dummy functions for some of the above operations, if a device does
+// not support e.g. locking.
+externC int     cyg_flash_devfn_init_nop(struct cyg_flash_dev*);
+externC size_t  cyg_flash_devfn_query_nop(struct cyg_flash_dev*, void*, const size_t);
+externC int     cyg_flash_devfn_lock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
+externC int     cyg_flash_devfn_unlock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
+
+// Facilitate function calls between flash-resident code and .2ram
+// functions.
+externC void*   cyg_flash_anonymizer(void*);
+
 // Structure each device places in the HAL table
 struct cyg_flash_dev {
   const struct cyg_flash_dev_funs *funs;            // Function pointers
--- a/packages/io/flash/current/src/flash.c
+++ b/packages/io/flash/current/src/flash.c
@@ -862,4 +862,59 @@ cyg_flash_errmsg(const int err)
     }
 }
 
+// Dummy routines to put into the device function tables, to handle
+// unsupported/unnecessary functionality. For example not all devices
+// support block locking.
+//
+// A dummy initialization routine, for platforms where everything is
+// done statically and there is no need to check device ids or
+// anything similar.
+int
+cyg_flash_devfn_init_nop(struct cyg_flash_dev* dev)
+{
+    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
+    return CYG_FLASH_ERR_OK;
+}
+
+// A dummy query routine. The implementation of this is specific to
+// each device driver, so some device drivers may choose to do
+// nothing.
+size_t
+cyg_flash_devfn_query_nop(struct cyg_flash_dev* dev, void* data, size_t len)
+{
+    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
+    CYG_UNUSED_PARAM(void*, data);
+    CYG_UNUSED_PARAM(size_t, len);
+    return 0;
+}
+
+// Dummy lock/unlock routines
+int
+cyg_flash_devfn_lock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
+{
+    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
+    CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr);
+    return CYG_FLASH_ERR_DRV_WRONG_PART;
+}
+
+int
+cyg_flash_devfn_unlock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
+{
+    CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
+    CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr);
+    return CYG_FLASH_ERR_DRV_WRONG_PART;
+}
+
+// On some architectures there are problems calling the .2ram
+// functions from the main ones. Specifically the compiler may issue a
+// short call, even though the flash and ram are too far apart. The
+// solution is to indirect via a function pointer, but the simplistic
+// approach is vulnerable to compiler optimization. Hence the function
+// pointer is passed through an anonymizer.
+void*
+cyg_flash_anonymizer(void* fn)
+{
+    return fn;
+}
+
 // EOF io/flash/..../flash.c
--- a/packages/io/flash/current/src/legacy_dev.c
+++ b/packages/io/flash/current/src/legacy_dev.c
@@ -102,14 +102,6 @@ legacy_flash_init (struct cyg_flash_dev 
   return err;
 }
 
-// Use this function to make function pointers anonymous - forcing the
-// compiler to use jumps instead of branches when calling driver
-// services.
-static void* __anonymizer(void* p)
-{
-  return p;
-}
-
 static size_t 
 legacy_flash_query (struct cyg_flash_dev *dev, 
                     void * data, 
@@ -118,7 +110,7 @@ legacy_flash_query (struct cyg_flash_dev
   typedef void code_fun(void*);
   code_fun *_flash_query;
   
-  _flash_query = (code_fun*) __anonymizer(&flash_query);
+  _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
   
   (*_flash_query)(data);
   
@@ -133,7 +125,7 @@ legacy_flash_erase_block (struct cyg_fla
   code_fun *_flash_erase_block;
   size_t block_size = dev->block_info[0].block_size;
   
-  _flash_erase_block = (code_fun*) __anonymizer(&flash_erase_block);
+  _flash_erase_block = (code_fun*) cyg_flash_anonymizer(&flash_erase_block);
 
   return (*_flash_erase_block)(block_base, block_size);
 }
@@ -148,7 +140,7 @@ legacy_flash_program(struct cyg_flash_de
   size_t block_size = dev->block_info[0].block_size;
   size_t block_mask = ~(block_mask -1);
 
-  _flash_program_buf = (code_fun*) __anonymizer(&flash_program_buf);
+  _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf);
 
   return (*_flash_program_buf)(base, data, len, block_mask ,block_size);
 }
@@ -164,7 +156,7 @@ legacy_flash_read (struct cyg_flash_dev 
   size_t block_size = dev->block_info[0].block_size;
   size_t block_mask = ~(block_mask -1);
 
-  _flash_read_buf = (code_fun*) __anonymizer(&flash_read_buf);
+  _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf);
   
   return (*_flash_read_buf)(base, data, len, block_mask, block_size);
 }
@@ -183,7 +175,7 @@ legacy_flash_block_lock (struct cyg_flas
   typedef int code_fun(cyg_flashaddr_t);
   code_fun *_flash_lock_block;
   
-  _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block);
+  _flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block);
 
   return (*_flash_lock_block)(block_base);
 }
@@ -197,7 +189,7 @@ legacy_flash_block_unlock (struct cyg_fl
   size_t block_size = dev->block_info[0].block_size;
   cyg_uint32 blocks = dev->block_info[0].blocks;
   
-  _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block);
+  _flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block);
   
   return (*_flash_unlock_block)(block_base, block_size, blocks);
 }
@@ -217,7 +209,7 @@ flash_dev_query(void* data)
     code_fun *_flash_query;
     int d_cache, i_cache;
 
-    _flash_query = (code_fun*) __anonymizer(&flash_query);
+    _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
 
     HAL_FLASH_CACHES_OFF(d_cache, i_cache);
     (*_flash_query)(data);