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 - synth driver update


This driver needed a bit more work than the previous one because it
involved merging the config and priv structures. All tests pass.

Bart

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/Attic/ChangeLog,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 ChangeLog
--- ChangeLog	22 Nov 2004 12:06:06 -0000	1.1.2.6
+++ ChangeLog	22 Nov 2004 20:51:47 -0000
@@ -1,5 +1,10 @@
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 
+	* include/synth.h, src/synth.c, tests/flash3.c: merge the config
+	and priv structures. Adjust device driver API as per changes to
+	the generic flash code.
+	* tests/flash2.c, tests/flash3.c: do not depend on both synthetic
+	flash drivers being loaded.
 	* include/synth.h (struct cyg_flash_synth_priv): rename
 	cyg_block_info to cyg_flash_block_info
 
Index: include/synth.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/include/Attic/synth.h,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 synth.h
--- include/synth.h	22 Nov 2004 12:06:04 -0000	1.1.2.2
+++ include/synth.h	22 Nov 2004 20:51:47 -0000
@@ -54,25 +54,23 @@
 
 #include <cyg/io/flash_priv.h>
 
-// Structure of configuration parameters
-struct cyg_flash_synth_config 
-{
-  size_t     block_size;
-  cyg_uint32 blocks;
-  size_t     boot_block_size;
-  cyg_uint32 boot_blocks;
-  cyg_bool   boot_block_bottom;
-  char *     filename;
-};
-
-// Structure of data private to the drive
+// Structure of data private to each flash device
 struct cyg_flash_synth_priv 
 {
-  int                           flashfd;
-  struct cyg_flash_block_info   block_info[2];
+    // Configuration parameters,
+    size_t                      block_size;
+    cyg_uint32                  blocks;
+    size_t                      boot_block_size;
+    cyg_uint32                  boot_blocks;
+    cyg_bool                    boot_block_bottom;
+    char *                      filename;
+    // Run-time data
+    int                         flashfd;
+    // Space for the block layout
+    struct cyg_flash_block_info block_info[2];
 };
 
-extern struct cyg_flash_dev_funs cyg_flash_synth_funs;
+extern const struct cyg_flash_dev_funs cyg_flash_synth_funs;
 
 #endif
 
Index: src/synth.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/src/Attic/synth.c,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 synth.c
--- src/synth.c	14 Sep 2004 16:03:54 -0000	1.1.2.3
+++ src/synth.c	22 Nov 2004 20:51:48 -0000
@@ -86,13 +86,12 @@
 static int
 synth_flash_init(struct cyg_flash_dev *dev)
 {
-    struct cyg_flash_synth_config *config = dev->config;
-    struct cyg_flash_synth_priv *priv = dev->priv;
+    struct cyg_flash_synth_priv *priv = (struct cyg_flash_synth_priv*)dev->priv;
     cyg_flashaddr_t base;
     int flags=CYG_HAL_SYS_MAP_SHARED;
     
     priv->flashfd = 
-        cyg_hal_sys_open(config->filename,
+        cyg_hal_sys_open(priv->filename,
                          CYG_HAL_SYS_O_RDWR, 
                          CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|
                          CYG_HAL_SYS_S_IRWXO);
@@ -101,15 +100,15 @@
         char buf[128];
         
         priv->flashfd = cyg_hal_sys_open(
-            config->filename, 
+            priv->filename, 
             CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, 
             CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
         CYG_ASSERT( priv->flashfd >= 0, 
                     "Opening of the file for the synth flash failed!");
         // fill with 0xff
         memset( buf, 0xff, sizeof(buf) );
-        bytesleft = config->block_size * config->blocks +
-            config->boot_block_size * config->boot_blocks;
+        bytesleft = priv->block_size * priv->blocks +
+            priv->boot_block_size * priv->boot_blocks;
 
         while (bytesleft > 0) {
             int bytesneeded;
@@ -134,8 +133,8 @@
     }
     base = (cyg_flashaddr_t)cyg_hal_sys_do_mmap( 
         (void *)dev->start,
-        config->blocks * config->block_size + 
-        config->boot_block_size * config->boot_blocks,
+        priv->blocks * priv->block_size + 
+        priv->boot_block_size * priv->boot_blocks,
         CYG_HAL_SYS_PROT_READ, 
         flags,
         priv->flashfd, 
@@ -145,24 +144,24 @@
         return CYG_FLASH_ERR_HWR;
     }
     dev->start = base;
-    dev->end = base + (config->blocks * config->block_size) +
-        (config->boot_blocks * config->boot_block_size) - 1;
-    if (config->boot_blocks) {
-        if (config->boot_block_bottom) {
-            priv->block_info[0].block_size = config->boot_block_size;
-            priv->block_info[0].blocks = config->boot_blocks;
-            priv->block_info[1].block_size = config->block_size;
-            priv->block_info[1].blocks = config->blocks;
+    dev->end = base + (priv->blocks * priv->block_size) +
+        (priv->boot_blocks * priv->boot_block_size) - 1;
+    if (priv->boot_blocks) {
+        if (priv->boot_block_bottom) {
+            priv->block_info[0].block_size = priv->boot_block_size;
+            priv->block_info[0].blocks = priv->boot_blocks;
+            priv->block_info[1].block_size = priv->block_size;
+            priv->block_info[1].blocks = priv->blocks;
         } else {
-            priv->block_info[0].block_size = config->block_size;
-            priv->block_info[0].blocks = config->blocks;
-            priv->block_info[1].block_size = config->boot_block_size;
-            priv->block_info[1].blocks = config->boot_blocks;
+            priv->block_info[0].block_size = priv->block_size;
+            priv->block_info[0].blocks = priv->blocks;
+            priv->block_info[1].block_size = priv->boot_block_size;
+            priv->block_info[1].blocks = priv->boot_blocks;
         }
         dev->num_block_infos = 2;
     } else {
-        priv->block_info[0].block_size = config->block_size;
-        priv->block_info[0].blocks = config->blocks;
+        priv->block_info[0].block_size = priv->block_size;
+        priv->block_info[0].blocks = priv->blocks;
         dev->num_block_infos = 1;
     }
     dev->block_info = &priv->block_info[0];
@@ -205,9 +204,9 @@
 
 static int 
 synth_flash_erase_block(struct cyg_flash_dev *dev, 
-                        const cyg_flashaddr_t block_base)
+                        cyg_flashaddr_t block_base)
 {
-    struct cyg_flash_synth_priv *priv = dev->priv;
+    const struct cyg_flash_synth_priv *priv = dev->priv;
     int offset = (int)block_base;
     size_t remaining;
     int write_size;
@@ -235,9 +234,9 @@
 static int
 synth_flash_program (struct cyg_flash_dev *dev, 
                      cyg_flashaddr_t base, 
-                     const void* data, const size_t len)
+                     const void* data, size_t len)
 {
-    struct cyg_flash_synth_priv *priv = dev->priv;
+    const struct cyg_flash_synth_priv *priv = dev->priv;
     int offset = base;
     offset -= dev->start;
     
@@ -251,35 +250,60 @@
 
 static size_t
 synth_flash_query(struct cyg_flash_dev *dev, void * data, 
-                  const size_t len)
+                  size_t len)
 {
     memcpy(data,QUERY,sizeof(QUERY));
     return sizeof(QUERY);
 }
 
-static struct cyg_flash_synth_config config = {
-    CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
-    CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
-    CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
-    CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
-    CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
-    CYGDAT_FLASH_SYNTH_V2_FILENAME
-};
+// 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;
+}
 
-CYG_FLASH_FUNS(cyg_flash_synth_funs,
-               synth_flash_init,
-               synth_flash_query,
-               synth_flash_erase_block,
-               synth_flash_program,
-               NULL,                 // read
-               synth_flash_hwr_map_error,
-               NULL,                 // lock
-               NULL);                // unlock
+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,
+                     synth_flash_erase_block,
+                     synth_flash_program,
+                     NULL,                 // read
+                     synth_flash_hwr_map_error,
+                     synth_flash_lock,
+                     synth_flash_unlock);
+
+static struct cyg_flash_synth_priv synth_flash_priv = {
+    .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
+    .blocks             = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
+    .boot_block_size    = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
+    .boot_blocks        = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
+    .boot_block_bottom  = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
+    .filename           = CYGDAT_FLASH_SYNTH_V2_FILENAME,
+    .flashfd            = -1
+};
 
 CYG_FLASH_DRIVER(cyg_flash_synth_flashdev,
                  &cyg_flash_synth_funs,
-                 &config,  
-                 CYGMEM_FLASH_SYNTH_V2_BASE,
-                 sizeof(struct cyg_flash_synth_priv)); 
+                 0,                             // flags
+                 CYGMEM_FLASH_SYNTH_V2_BASE,    // Start, if 0 will be updated by init
+                 0,                             // end, filled in by init
+                 0,                             // number of block_info's, filled in by init
+                 synth_flash_priv.block_info,
+                 &synth_flash_priv);
 
 // EOF synth.c
Index: tests/flash2.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/tests/Attic/flash2.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 flash2.c
--- tests/flash2.c	21 Aug 2004 13:45:53 -0000	1.1.2.2
+++ tests/flash2.c	22 Nov 2004 20:51:50 -0000
@@ -56,8 +56,12 @@
 ;
 
 #include <pkgconf/system.h>
+#ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
 #include <pkgconf/devs_flash_synth_v2.h>
+#endif
+#ifdef CYGPKG_DEVS_FLASH_SYNTH
 #include <pkgconf/devs_flash_synth.h>
+#endif
 #include <cyg/io/flash.h>
 #include <cyg/infra/testcase.h>
 #include <cyg/infra/diag.h>
Index: tests/flash3.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/flash/synthv2/current/tests/Attic/flash3.c,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 flash3.c
--- tests/flash3.c	9 Sep 2004 13:13:23 -0000	1.1.2.3
+++ tests/flash3.c	22 Nov 2004 20:51:50 -0000
@@ -56,8 +56,12 @@
 ;
 
 #include <pkgconf/system.h>
+#ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
 #include <pkgconf/devs_flash_synth_v2.h>
+#endif
+#ifdef CYGPKG_DEVS_FLASH_SYNTH
 #include <pkgconf/devs_flash_synth.h>
+#endif
 #include <cyg/io/flash.h>
 #include <cyg/infra/testcase.h>
 #include <cyg/infra/diag.h>
@@ -77,20 +81,24 @@
 }
 #else
 
-static struct cyg_flash_synth_config config = {
-    CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
-    CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
-    CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
-    CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
-    CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
-    "synth.flash3"
+static struct cyg_flash_synth_priv synth_flash_priv3 = {
+    .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
+    .blocks             = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
+    .boot_block_size    = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
+    .boot_blocks        = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
+    .boot_block_bottom  = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
+    .filename           = "synth.flash3",
+    .flashfd            = -1
 };
 
 CYG_FLASH_DRIVER(cyg_flash_synth_flashdev_flash3,
                  &cyg_flash_synth_funs,
-                 &config,  // Pointer to priv structure
-                 0x40020000,
-                 sizeof(struct cyg_flash_synth_priv));
+                 0,             // flags
+                 0x40020000,    // start
+                 0,             // end, filled in by init
+                 0,             // number of block_info's, filled in by init
+                 synth_flash_priv3.block_info,
+                 &synth_flash_priv3);
 
 //==========================================================================
 // main


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