This is the mail archive of the ecos-patches@sources.redhat.com 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]

V2 flash - API clean-up


This patch is a clean-up for the exported API. There are two main
changes:

1) I have renamed cyg_block_info to cyg_flash_block_info.
   cyg_block_info could refer to memory blocks, disk blocks, etc. The
   term is too ambiguous to be claimed by the flash code. This affects
   the V2 device drivers a little bit. Applications should not
   normally be affected since they are likely to only access block
   info structures, not define them.

2) I have added const where appropriate, removed it where
   inappropriate. Previously the program and erase operations involved
   a const flash address, even though the flash would be modified.
   Worse, read used a non-const flash address but a const ram address.
   In theory the compiler could miscompile the latter.

   Now

     const is never applied to scalars passed by value such as length
     fields. There is no point in making these const, the compiler
     cannot do anything useful with the info.

     const is applied to cyg_flashaddr_t addresses when the flash is
     not going to change, but not when the flash is being erased or
     programmed. With the current definition of cyg_flashaddr_t this
     won't actually achieve anything, but the principle is right.

     The same applies for ram address. Here in theory the compiler can
     do useful things with the const information.

I have also made sure that <cyg/io/flash.h> #include's the headers it
depends on, rather than relying on the calling code for this.

The documentation has only been partly updated, there is more work to
be done there.

Bart

Index: devs/flash/amd/am29xxxxxv2/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/amd/am29xxxxxv2/current/Attic/ChangeLog,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 ChangeLog
--- devs/flash/amd/am29xxxxxv2/current/ChangeLog	21 Nov 2004 23:48:19 -0000	1.1.2.3
+++ devs/flash/amd/am29xxxxxv2/current/ChangeLog	22 Nov 2004 11:23:51 -0000
@@ -1,3 +1,8 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/am29xxxxx_dev.h: rename cyg_block_info to
+	cyg_flash_block_info
+
 2004-11-21  Bart Veer  <bartv@ecoscentric.com>
 
 	* doc/am29xxxxx.sgml: describe CDL implications for custom locking
Index: devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/amd/am29xxxxxv2/current/include/Attic/am29xxxxx_dev.h,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 am29xxxxx_dev.h
--- devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h	20 Nov 2004 18:09:53 -0000	1.1.2.1
+++ devs/flash/amd/am29xxxxxv2/current/include/am29xxxxx_dev.h	22 Nov 2004 11:23:51 -0000
@@ -105,11 +105,11 @@
 // a cyg_flash_dev structure.
 typedef struct cyg_am29xxxxx_dev {
     // The device id, mainly for use by the init_check_devid() routines
-    cyg_uint32          devid;
+    cyg_uint32              devid;
     // Space for the block_info fields needed for the cyg_flash_dev.
     // These can be statically initialized, or dynamically via
     // init_cfi().
-    cyg_block_info_t    block_info[CYGNUM_DEVS_FLASH_AMD_AM29XXXXX_V2_ERASE_REGIONS];
+    cyg_flash_block_info_t  block_info[CYGNUM_DEVS_FLASH_AMD_AM29XXXXX_V2_ERASE_REGIONS];
 } cyg_am29xxxxx_dev;
 
 #endif  // CYGONCE_DEVS_FLASH_AM29xxxxx_dev_V2_H
Index: devs/flash/atmel/dataflash/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/atmel/dataflash/current/Attic/ChangeLog,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 ChangeLog
--- devs/flash/atmel/dataflash/current/ChangeLog	21 Nov 2004 17:33:51 -0000	1.1.2.5
+++ devs/flash/atmel/dataflash/current/ChangeLog	22 Nov 2004 11:23:55 -0000
@@ -1,3 +1,8 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* src/devs_flash_atmel_dataflash_flash_dev_funs.c (df_flash_init):
+	Rename cyg_block_info to cyg_flash_block_info
+
 2004-11-21  Bart Veer  <bartv@ecoscentric.com>
 
 	* cdl/devs_flash_atmel_dataflash.cdl: CYGHWR_IO_FLASH_DEVICE_V2 is
Index: devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/atmel/dataflash/current/src/Attic/devs_flash_atmel_dataflash_flash_dev_funs.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 devs_flash_atmel_dataflash_flash_dev_funs.c
--- devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c	7 Oct 2004 19:59:28 -0000	1.1.2.2
+++ devs/flash/atmel/dataflash/current/src/devs_flash_atmel_dataflash_flash_dev_funs.c	22 Nov 2004 11:23:55 -0000
@@ -73,7 +73,7 @@
 static int 
 df_flash_init(struct cyg_flash_dev *dev)
 {
-    static cyg_block_info_t block_info[1];
+    static cyg_flash_block_info_t block_info[1];
     
     cyg_dataflash_flash_dev_config_t *config;
     cyg_dataflash_flash_dev_priv_t   *priv;
Index: devs/flash/intel/stratav2/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/intel/stratav2/current/Attic/ChangeLog,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 ChangeLog
--- devs/flash/intel/stratav2/current/ChangeLog	21 Nov 2004 17:33:50 -0000	1.1.2.5
+++ devs/flash/intel/stratav2/current/ChangeLog	22 Nov 2004 11:23:56 -0000
@@ -1,3 +1,8 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_strata_v2.inl: rename cyg_block_info to
+	cyg_flash_block_info
+
 2004-11-21  Bart Veer  <bartv@ecoscentric.com>
 
 	* cdl/flash_strata_v2.cdl: CYGHWR_IO_FLASH_DEVICE_V2 is now
Index: devs/flash/intel/stratav2/current/include/flash_strata_v2.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/intel/stratav2/current/include/Attic/flash_strata_v2.inl,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 flash_strata_v2.inl
--- devs/flash/intel/stratav2/current/include/flash_strata_v2.inl	14 Sep 2004 16:02:54 -0000	1.1.2.4
+++ devs/flash/intel/stratav2/current/include/flash_strata_v2.inl	22 Nov 2004 11:23:58 -0000
@@ -112,8 +112,8 @@
 //----------------------------------------------------------------------------
 // Private structure used by the device.
 struct cyg_flash_strata_v2_priv {
-    cyg_block_info_t block_info [1];
-    unsigned int     buffer_size;    // Size of write buffer
+    cyg_flash_block_info_t block_info [1];
+    unsigned int	   buffer_size;    // Size of write buffer
 };
 //----------------------------------------------------------------------------
 
Index: devs/flash/sst/39vfxxx/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/sst/39vfxxx/current/ChangeLog,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 ChangeLog
--- devs/flash/sst/39vfxxx/current/ChangeLog	14 Sep 2004 16:03:26 -0000	1.1.2.3
+++ devs/flash/sst/39vfxxx/current/ChangeLog	22 Nov 2004 11:24:03 -0000
@@ -1,3 +1,8 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_sst_39vfxxx.inl: rename cyg_block_info to
+	cyg_flash_block_info
+
 2004-09-14  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* include/flash_sst_39vfxxx.inl: Set the end address to the last
Index: devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 flash_sst_39vfxxx.inl
--- devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl	14 Sep 2004 16:03:26 -0000	1.1.2.3
+++ devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl	22 Nov 2004 11:24:03 -0000
@@ -137,7 +137,7 @@
 // Private structure used by the device
 struct cyg_flash_sst_priv 
 {
-  cyg_block_info_t block_info[1];
+  cyg_flash_block_info_t block_info[1];
 };
 //----------------------------------------------------------------------------
 // Functions that put the flash device into non-read mode must reside
Index: devs/flash/synthv2/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/Attic/ChangeLog,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 ChangeLog
--- devs/flash/synthv2/current/ChangeLog	21 Nov 2004 17:33:50 -0000	1.1.2.5
+++ devs/flash/synthv2/current/ChangeLog	22 Nov 2004 11:24:04 -0000
@@ -1,3 +1,8 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/synth.h (struct cyg_flash_synth_priv): rename
+	cyg_block_info to cyg_flash_block_info
+
 2004-11-21  Bart Veer  <bartv@ecoscentric.com>
 
 	* tests/flash1.c (cyg_user_start):
Index: devs/flash/synthv2/current/include/synth.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/include/Attic/synth.h,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 synth.h
--- devs/flash/synthv2/current/include/synth.h	5 Aug 2004 13:25:34 -0000	1.1.2.1
+++ devs/flash/synthv2/current/include/synth.h	22 Nov 2004 11:24:04 -0000
@@ -68,8 +68,8 @@
 // Structure of data private to the drive
 struct cyg_flash_synth_priv 
 {
-  int                   flashfd;
-  struct cyg_block_info block_info[2];
+  int                           flashfd;
+  struct cyg_flash_block_info   block_info[2];
 };
 
 extern struct cyg_flash_dev_funs cyg_flash_synth_funs;
Index: io/flash/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/ChangeLog,v
retrieving revision 1.38.2.17
diff -u -r1.38.2.17 ChangeLog
--- io/flash/current/ChangeLog	21 Nov 2004 23:39:01 -0000	1.38.2.17
+++ io/flash/current/ChangeLog	22 Nov 2004 11:24:58 -0000
@@ -1,3 +1,9 @@
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash.h, include/flash_priv.h, doc/flash.sgml,
+	src/flash.c, src/legacy_dev.c: put const in the right places,
+	and rename cyg_block_info to cyg_flash_block_info
+
 2004-11-21  Bart Veer  <bartv@ecoscentric.com>
 
 	* src/flash.c, include/flash_priv.h, cdl/io_flash.h: optimize
Index: io/flash/current/include/flash.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/include/flash.h,v
retrieving revision 1.18.2.4
diff -u -r1.18.2.4 flash.h
--- io/flash/current/include/flash.h	21 Nov 2004 18:39:15 -0000	1.18.2.4
+++ io/flash/current/include/flash.h	22 Nov 2004 11:25:02 -0000
@@ -43,7 +43,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas, Andrew Lunn
+// Contributors: gthomas, Andrew Lunn, bartv
 // Date:         2000-07-14
 // Purpose:      
 // Description:  
@@ -57,59 +57,62 @@
 
 #include <pkgconf/system.h>
 #include <pkgconf/io_flash.h>
-#include <cyg/hal/hal_cache.h>
-#include <cyg/hal/hal_tables.h>
+#include <stddef.h>
+#include <cyg/infra/cyg_type.h>
 #ifdef CYGPKG_KERNEL
 #include <cyg/kernel/kapi.h>
 #endif
 
+// Currently a 32-bit quantity. In future this may be 64-bits on some
+// platforms, e.g. to support very large nand flashes which can only
+// be accessed indirectly.
 typedef CYG_ADDRESS cyg_flashaddr_t;
 
-typedef struct cyg_block_info 
+typedef struct cyg_flash_block_info 
 {
   size_t                    block_size;
   cyg_uint32                blocks;
-} cyg_block_info_t;
+} cyg_flash_block_info_t;
 
 // Information about what one device driver drives
 typedef struct {
-  cyg_flashaddr_t           start;           // First address
-  cyg_flashaddr_t           end;             // Last address
-  cyg_uint32                num_block_infos; // Number of entries
-  cyg_block_info_t          *block_info;     // Info about block sizes
+  cyg_flashaddr_t               start;              // First address
+  cyg_flashaddr_t               end;                // Last address
+  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_get_info(cyg_uint32 devno, 
                                  cyg_flash_info_t * info);
-__externC int cyg_flash_get_info_addr(cyg_flashaddr_t flash_base, 
+__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);
 __externC size_t cyg_flash_block_size(const cyg_flashaddr_t flash_base);
-__externC int cyg_flash_read(cyg_flashaddr_t flash_base, 
-                             const void *ram_base, 
-                             const size_t len, 
+__externC int cyg_flash_read(const cyg_flashaddr_t flash_base, 
+                             void *ram_base, 
+                             size_t len, 
                              cyg_flashaddr_t *err_address);
-__externC int cyg_flash_erase(const cyg_flashaddr_t flash_base, 
-                              const size_t len, 
+__externC int cyg_flash_erase(cyg_flashaddr_t flash_base, 
+                              size_t len, 
                               cyg_flashaddr_t *err_address);
-__externC int cyg_flash_program(const cyg_flashaddr_t flash_base, 
-                                void *ram_base, 
-                                const size_t len, 
+__externC int cyg_flash_program(cyg_flashaddr_t flash_base, 
+                                const void *ram_base, 
+                                size_t len, 
                                 cyg_flashaddr_t *err_address);
 __externC int cyg_flash_lock(const cyg_flashaddr_t flash_base, 
-                             const size_t len, 
+                             size_t len, 
                              cyg_flashaddr_t *err_address);
 __externC int cyg_flash_unlock(const cyg_flashaddr_t flash_base, 
-                               const size_t len, 
+                               size_t len, 
                                cyg_flashaddr_t *err_address);
 __externC const char *cyg_flash_errmsg(const int err);
 #ifdef CYGPKG_KERNEL
 __externC int cyg_flash_mutex_lock(const cyg_flashaddr_t from, 
-                                   const size_t len);
+                                   size_t len);
 __externC int cyg_flash_mutex_unlock(const cyg_flashaddr_t from, 
-                                     const size_t len);
+                                     size_t len);
 #endif
 
 #define CYG_FLASH_ERR_OK              0x00  // No error - operation complete
Index: io/flash/current/include/flash_priv.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/include/Attic/flash_priv.h,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 flash_priv.h
--- io/flash/current/include/flash_priv.h	21 Nov 2004 23:39:01 -0000	1.1.2.3
+++ io/flash/current/include/flash_priv.h	22 Nov 2004 11:25:07 -0000
@@ -56,6 +56,8 @@
 
 #include <pkgconf/system.h>
 #include <pkgconf/io_flash.h>
+#include <cyg/hal/hal_cache.h>
+#include <cyg/hal/hal_tables.h>
 
 // Forward reference of the device structure
 struct cyg_flash_dev;
@@ -86,7 +88,7 @@
   cyg_flashaddr_t             start;           // First address
   cyg_flashaddr_t             end;             // Last address
   cyg_uint32                  num_block_infos; // Number of entries
-  cyg_block_info_t            *block_info;     // Info about one block size
+  cyg_flash_block_info_t      *block_info;     // Info about one block size
 
   void                        *priv;           // Devices private data
   void                        *config;         // Configuration info
Index: io/flash/current/src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flash.c,v
retrieving revision 1.26.2.12
diff -u -r1.26.2.12 flash.c
--- io/flash/current/src/flash.c	21 Nov 2004 23:39:01 -0000	1.26.2.12
+++ io/flash/current/src/flash.c	22 Nov 2004 11:25:07 -0000
@@ -319,7 +319,7 @@
 
 // Return information about the flash at the given address
 __externC int
-cyg_flash_get_info_addr(cyg_flashaddr_t flash_base, cyg_flash_info_t * info)
+cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base, cyg_flash_info_t * info)
 {
   struct cyg_flash_dev *dev;
   int                   stat = CYG_FLASH_ERR_OK;
@@ -337,7 +337,7 @@
 #ifdef CYGPKG_KERNEL
 // Lock the mutex's for a range of addresses
 __externC int
-cyg_flash_mutex_lock(const cyg_flashaddr_t from, const size_t len) 
+cyg_flash_mutex_lock(const cyg_flashaddr_t from, size_t len) 
 {
   struct cyg_flash_dev *    dev;
   int                       stat    = CYG_FLASH_ERR_OK;
@@ -358,7 +358,7 @@
 
 // Unlock the mutex's for a range of addresses
 __externC int
-cyg_flash_mutex_unlock(const cyg_flashaddr_t from, const size_t len) 
+cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len) 
 {
   struct cyg_flash_dev *    dev;
   int                       stat = CYG_FLASH_ERR_OK;
@@ -431,8 +431,8 @@
 
 
 __externC int 
-cyg_flash_erase(const cyg_flashaddr_t flash_base, 
-                const size_t len, 
+cyg_flash_erase(cyg_flashaddr_t flash_base, 
+                size_t len, 
                 cyg_flashaddr_t *err_address)
 {
   cyg_flashaddr_t block, end_addr;
@@ -520,14 +520,14 @@
 }
 
 __externC int 
-cyg_flash_program(const cyg_flashaddr_t flash_base, 
-                  void *ram_base, 
-                  const size_t len, 
+cyg_flash_program(cyg_flashaddr_t flash_base, 
+                  const void *ram_base, 
+                  size_t len, 
                   cyg_flashaddr_t *err_address)
 {
   struct cyg_flash_dev * dev;
   cyg_flashaddr_t addr, end_addr, block;
-  unsigned char * ram = ram_base;
+  const unsigned char * ram = ram_base;
   size_t write_count, offset;
   int stat = CYG_FLASH_ERR_OK;
   int d_cache, i_cache;
@@ -604,9 +604,9 @@
 }
 
 __externC int 
-cyg_flash_read(cyg_flashaddr_t flash_base, 
-               const void *ram_base, 
-               const size_t len, 
+cyg_flash_read(const cyg_flashaddr_t flash_base, 
+               void *ram_base, 
+               size_t len, 
                cyg_flashaddr_t *err_address)
 {
   struct cyg_flash_dev * dev;
@@ -697,7 +697,7 @@
 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
 __externC int 
 cyg_flash_lock(const cyg_flashaddr_t flash_base, 
-               const size_t len, 
+               size_t len, 
                cyg_flashaddr_t *err_address)
 {
   cyg_flashaddr_t block, end_addr;
@@ -761,7 +761,7 @@
 
 __externC int 
 cyg_flash_unlock(const cyg_flashaddr_t flash_base, 
-                 const size_t len, 
+                 size_t len, 
                  cyg_flashaddr_t *err_address)
 {
   cyg_flashaddr_t block, end_addr;
Index: io/flash/current/src/legacy_dev.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/Attic/legacy_dev.c,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 legacy_dev.c
--- io/flash/current/src/legacy_dev.c	21 Nov 2004 12:09:40 -0000	1.1.2.5
+++ io/flash/current/src/legacy_dev.c	22 Nov 2004 11:25:09 -0000
@@ -86,7 +86,7 @@
 legacy_flash_init (struct cyg_flash_dev *dev)
 {
   int err;
-  static cyg_block_info_t block_info[1];
+  static cyg_flash_block_info_t block_info[1];
 
   err=flash_hwr_init();
 
Index: io/flash/current/doc/flash.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/doc/flash.sgml,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 flash.sgml
--- io/flash/current/doc/flash.sgml	21 Nov 2004 18:39:15 -0000	1.1.2.3
+++ io/flash/current/doc/flash.sgml	22 Nov 2004 11:25:01 -0000
@@ -147,16 +147,16 @@
 __externC int cyg_flash_verify_addr(const flashaddr_t address);
 __extern size_t cyg_flash_block_size(const cyg_flashaddr_t flash_base);
 
-typedef struct cyg_block_info
+typedef struct cyg_flash_block_info
     size_t                    block_size;
     cyg_unit32                blocks;
-} cyg_block_info_t;
+} cyg_flash_block_info_t;
 
 typedef struct {
     flashaddr_t               start;          // First address
     flashaddr_t               end;            // Last address
     cyg_uint32                num_block_infos // Number of entries
-    cyg_block_info_t          *blocks_info;   // Info about one block size
+    const cyg_flash_block_info_t    *blocks_info;   // Info about one block size
 } cyg_flash_info_t;
 </PROGRAMLISTING>
 
@@ -329,7 +329,7 @@
     flashaddr_t               *end;            // Last address
     void                      *priv;           // Devices private data
     cyg_uint32                num_block_infos; // Number of entries
-    cyg_block_info_t          *blocks_info;    // Info about one block size
+    cyg_flash_block_info_t    *blocks_info;    // Info about one block size
 
 
 // The following are only written to by the FLASH IO layer.


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