changeset 1769:8667859d61ab

* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL supplied them and they're not needed. * cdl/io_flash.cdl, src/flash.c, src/flash_legacy.h, src/legacy_dev.c: add support for V2 drivers which can take care of the cache and interrupts themselves.
author jlarmour
date Wed, 27 Sep 2006 14:24:46 +0000
parents ef75ad79dfe3
children be052fe43d4d
files packages/io/flash/current/ChangeLog packages/io/flash/current/cdl/io_flash.cdl packages/io/flash/current/src/flash.c packages/io/flash/current/src/flash_legacy.h packages/io/flash/current/src/legacy_dev.c
diffstat 5 files changed, 56 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/packages/io/flash/current/ChangeLog
+++ b/packages/io/flash/current/ChangeLog
@@ -8,6 +8,9 @@ 2005-01-28  Nick Garnett  <nickg@ecoscen
 
 2005-01-19  Jonathan Larmour  <jifl@eCosCentric.com>
 
+	* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
+	supplied them and they're not needed.
+	
 	* src/legacy_api.c (flash_errmsg): Was missing. Add.
 
 2004-12-02  Bart Veer  <bartv@ecoscentric.com>
@@ -46,6 +49,12 @@ 2004-11-25  Andrew Lunn  <andrew.lunn@as
 	* src/flash.c (find_dev): All devices on the list are initialised so
 	don't both checking the init flag.
 
+2004-11-24  Bart Veer  <bartv@ecoscentric.com>
+
+	* cdl/io_flash.cdl, src/flash.c, src/flash_legacy.h,
+	src/legacy_dev.c: add support for V2 drivers which can take care
+	of the cache and interrupts themselves.
+
 2004-11-22  Bart Veer  <bartv@ecoscentric.com>
 
 	* src/legacy_dev.c: remove .2ram attributes. These functions do
@@ -459,6 +468,7 @@ 2000-07-29  Gary Thomas  <gthomas@redhat
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2005, 2006 eCosCentric Limited
 //
 // 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
@@ -482,9 +492,6 @@ 2000-07-29  Gary Thomas  <gthomas@redhat
 //
 // This exception does not invalidate any other reasons why a work based on
 // this file might be covered by the GNU General Public License.
-//
-// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
-// at http://sources.redhat.com/ecos/ecos-license/
 // -------------------------------------------
 //####ECOSGPLCOPYRIGHTEND####
 //===========================================================================
--- a/packages/io/flash/current/cdl/io_flash.cdl
+++ b/packages/io/flash/current/cdl/io_flash.cdl
@@ -8,7 +8,7 @@
 #####ECOSGPLCOPYRIGHTBEGIN####
 ## -------------------------------------------
 ## This file is part of eCos, the Embedded Configurable Operating System.
-## Copyright (C) 2004 eCosCentric Ltd
+## Copyright (C) 2004, 2006 eCosCentric Ltd
 ## Copyright (C) 2004 Andrew Lunn
 ## Copyright (C) 2003 Gary Thomas
 ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
@@ -94,6 +94,18 @@ cdl_package CYGPKG_IO_FLASH {
             can be eliminated."
     }
     
+    cdl_interface CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED {
+	display	    "Device driver needs cache handled centrally"
+	flavor	    booldata
+	description "
+            Managing flash often requires interacting with the flash.
+            Some device drivers do not require the generic flash code to
+            manipulate the flash, either because they do it themselves or
+            because the hardware does the right thing. Other drivers
+            require the generic code to disable/enable the flash before
+            calling into the driver."
+    }
+    
     cdl_interface CYGHWR_IO_FLASH_DEVICE_LEGACY {
         display     "Hardware driver uses the legacy interface"
         flavor      booldata
@@ -103,6 +115,10 @@ cdl_package CYGPKG_IO_FLASH {
             driver or with V2 drivers. If a legacy driver is used on the
             current platform then this option will be implemented."
 	requires    { CYGHWR_IO_FLASH_DEVICE_LEGACY <= 1 }
+
+	# For now assume all legacy devices need the cache handled by
+	# the central code
+	implements CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
     }
 
     cdl_option CYGSEM_IO_FLASH_READ_INDIRECT {
--- a/packages/io/flash/current/src/flash.c
+++ b/packages/io/flash/current/src/flash.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 2004 Andrew Lunn
-// Copyright (C) 2004 eCosCentric Ltd.
+// Copyright (C) 2004, 2005, 2006 eCosCentric Ltd.
 // Copyright (C) 2003 Gary Thomas
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
 //
@@ -162,8 +162,8 @@ static bool flash_sort_and_check(void)
     }
   }
   
-  // If there are no devices, abort. This could happen because none
-  // of the devices initialised. 
+  // If there are no valid devices, abort. This might happen if
+  // all drivers failed to initialize.
   if (flash_head == NULL) {
     return false;
   }
@@ -293,7 +293,7 @@ cyg_flash_verify_addr(const cyg_flashadd
 cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info)
 {
   struct cyg_flash_dev * dev;
-  
+
   if (!init) return CYG_FLASH_ERR_NOT_INIT;
 
 #if (1 == CYGHWR_IO_FLASH_DEVICE)
@@ -439,7 +439,7 @@ cyg_flash_erase(cyg_flashaddr_t flash_ba
   struct cyg_flash_dev * dev;
   size_t erase_count;
   int stat = CYG_FLASH_ERR_OK;
-  int d_cache, i_cache;
+  HAL_FLASH_CACHES_STATE(d_cache, i_cache);
 
   dev = find_dev(flash_base, &stat);
   if (!dev) return stat;
@@ -529,7 +529,7 @@ cyg_flash_program(cyg_flashaddr_t flash_
   const unsigned char * ram = ram_base;
   size_t write_count, offset;
   int stat = CYG_FLASH_ERR_OK;
-  int d_cache, i_cache;
+  HAL_FLASH_CACHES_STATE(d_cache, i_cache);
 
   dev = find_dev(flash_base, &stat);
   if (!dev) return stat;
@@ -643,9 +643,9 @@ cyg_flash_read(const cyg_flashaddr_t fla
       // We have to indirect through the device driver.
       // The first read may be in the middle of a block. Do the necessary
       // adjustment here rather than inside the loop.
-      int               d_cache, i_cache;
       size_t            offset;
       cyg_flashaddr_t   block = flash_block_begin(flash_base, dev);
+      HAL_FLASH_CACHES_STATE(d_cache, i_cache);
       if (addr == block) {
           offset = 0;
       } else {
@@ -701,7 +701,7 @@ cyg_flash_lock(const cyg_flashaddr_t fla
   struct cyg_flash_dev * dev;
   size_t lock_count;
   int stat = CYG_FLASH_ERR_OK;
-  int d_cache, i_cache;
+  HAL_FLASH_CACHES_STATE(d_cache, i_cache);
 
   dev = find_dev(flash_base, &stat);
   if (!dev) return stat;
@@ -764,7 +764,7 @@ cyg_flash_unlock(const cyg_flashaddr_t f
   struct cyg_flash_dev * dev;
   size_t unlock_count;
   int stat = CYG_FLASH_ERR_OK;
-  int d_cache, i_cache;
+  HAL_FLASH_CACHES_STATE(d_cache, i_cache);
 
   dev = find_dev(flash_base, &stat);
   if (!dev) return stat;
--- a/packages/io/flash/current/src/flash_legacy.h
+++ b/packages/io/flash/current/src/flash_legacy.h
@@ -11,6 +11,7 @@
 // copyright (C) 2004 Andrew Lunn
 // Copyright (C) 2003 Gary Thomas
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2004 eCosCentric Limited
 //
 // 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
@@ -83,6 +84,17 @@ externC cyg_bool plf_flash_query_soft_wp
 #endif
 
 //---------------------------------------------------------------------------
+// If all of the flash devices handle cache themselves, or do not need any
+// special cache treatment, then the flash macros can be no-ops.
+#ifndef CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
+# undef HAL_FLASH_CACHES_OFF
+# undef HAL_FLASH_CACHES_ON
+# undef HAL_FLASH_CACHES_STATE
+# define HAL_FLASH_CACHES_OFF(_d_, _i_)     CYG_EMPTY_STATEMENT
+# define HAL_FLASH_CACHES_ON(_d_, _i_)      CYG_EMPTY_STATEMENT
+# define HAL_FLASH_CACHES_STATE(_d_, _i_)   CYG_EMPTY_STATEMENT
+#endif
+
 // Execution of flash code must be done inside a
 // HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the
 // cache on unified cache systems is necessary to prevent burst access
@@ -168,3 +180,7 @@ externC cyg_bool plf_flash_query_soft_wp
 #endif  // HAL_FLASH_CACHES_OLD_MACROS
 
 #endif  // HAL_FLASH_CACHES_OFF
+
+#ifndef HAL_FLASH_CACHES_STATE
+# define HAL_FLASH_CACHES_STATE(_d_, _i_) int _d_, _i_
+#endif
--- a/packages/io/flash/current/src/legacy_dev.c
+++ b/packages/io/flash/current/src/legacy_dev.c
@@ -9,6 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 2004 Andrew Lunn
+// Copyright (C) 2004 eCosCentric Limited
 //
 // 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
@@ -141,7 +142,7 @@ legacy_flash_program(struct cyg_flash_de
 {
   typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int);
   code_fun *_flash_program_buf;
-  size_t block_mask = ~(block_mask -1);
+  size_t block_mask = ~(block_size -1);
   int    stat;
   
   _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf);
@@ -159,7 +160,7 @@ legacy_flash_read (struct cyg_flash_dev 
   typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int);
   code_fun *_flash_read_buf;
   size_t block_size = dev->block_info[0].block_size;
-  size_t block_mask = ~(block_mask -1);
+  size_t block_mask = ~(block_size -1);
   int    stat;
   _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf);
   
@@ -208,7 +209,7 @@ flash_dev_query(void* data)
 {
     typedef void code_fun(void*);
     code_fun *_flash_query;
-    int d_cache, i_cache;
+    HAL_FLASH_CACHES_STATE(d_cache, i_cache);
 
     _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);