diff packages/io/flash/current/include/flash.h @ 1706:3845779eca10

* src/flash.c: Major rewrite to implement a new API * src/legacy_api.c: Support the legacy API * src/legacy_drv.c: Support the legacy driver API * src/flashiodev.c: Support the new API and multiple devices * include/flash_priv.h: Interface devices should use * cdl/io_flash.cdl: Updates for new interface and multiple devices.
author asl
date Thu, 05 Aug 2004 13:50:00 +0000
parents 86d40b65e079
children c4240af0fa28
line wrap: on
line diff
--- a/packages/io/flash/current/include/flash.h
+++ b/packages/io/flash/current/include/flash.h
@@ -10,6 +10,7 @@
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
 // Copyright (C) 2003 Gary Thomas
+// copyright (C) 2004 Andrew Lunn
 //
 // 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
@@ -42,7 +43,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas
+// Contributors: gthomas, Andrew Lunn
 // Date:         2000-07-14
 // Purpose:      
 // Description:  
@@ -54,15 +55,94 @@
 #ifndef _IO_FLASH_H_
 #define _IO_FLASH_H_
 
+#include <pkgconf/system.h>
 #include <pkgconf/io_flash.h>
 #include <cyg/hal/hal_cache.h>
+#include <cyg/hal/hal_tables.h>
+#ifdef CYGPKG_KERNEL
+#include <cyg/kernel/kapi.h>
+#endif
 
+typedef CYG_ADDRESS cyg_flashaddr_t;
+
+typedef struct cyg_block_info 
+{
+  size_t                    block_size;
+  cyg_uint32                blocks;
+} cyg_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_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, 
+                                      cyg_flash_info_t * info);
+__externC int cyg_flash_verify_addr(const cyg_flashaddr_t address);
+__externC bool cyg_flash_code_overlaps(const cyg_flashaddr_t start, 
+                                       const cyg_flashaddr_t end);
+__externC int cyg_flash_get_block_info(size_t *block_size, 
+                                       cyg_uint32 *blocks);
+__externC int cyg_flash_get_limits(cyg_flashaddr_t *start, 
+                                   cyg_flashaddr_t *end);
+__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, 
+                             cyg_flashaddr_t *err_address);
+__externC int cyg_flash_erase(const cyg_flashaddr_t flash_base, 
+                              const 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, 
+                                cyg_flashaddr_t *err_address);
+__externC int cyg_flash_lock(const cyg_flashaddr_t flash_base, 
+                             const size_t len, 
+                             cyg_flashaddr_t *err_address);
+__externC int cyg_flash_unlock(const cyg_flashaddr_t flash_base, 
+                               const 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);
+__externC int cyg_flash_mutex_unlock(const cyg_flashaddr_t from, 
+                                     const size_t len);
+#endif
+
+#define CYG_FLASH_ERR_OK              0x00  // No error - operation complete
+#define CYG_FLASH_ERR_INVALID         0x01  // Invalid FLASH address
+#define CYG_FLASH_ERR_ERASE           0x02  // Error trying to erase
+#define CYG_FLASH_ERR_LOCK            0x03  // Error trying to lock/unlock
+#define CYG_FLASH_ERR_PROGRAM         0x04  // Error trying to program
+#define CYG_FLASH_ERR_PROTOCOL        0x05  // Generic error
+#define CYG_FLASH_ERR_PROTECT         0x06  // Device/region is write-protected
+#define CYG_FLASH_ERR_NOT_INIT        0x07  // FLASH info not yet initialized
+#define CYG_FLASH_ERR_HWR             0x08  // Hardware (configuration?) problem
+#define CYG_FLASH_ERR_ERASE_SUSPEND   0x09  // Device is in erase suspend mode
+#define CYG_FLASH_ERR_PROGRAM_SUSPEND 0x0a  // Device is in program suspend mode
+#define CYG_FLASH_ERR_DRV_VERIFY      0x0b  // Driver failed to verify data
+#define CYG_FLASH_ERR_DRV_TIMEOUT     0x0c  // Driver timed out 
+#define CYG_FLASH_ERR_DRV_WRONG_PART  0x0d  // Driver does not support device
+#define CYG_FLASH_ERR_LOW_VOLTAGE     0x0e  // Not enough juice to complete job
+
+#ifdef CYGSEM_IO_FLASH_LEGACY_API
 typedef int _printf(const char *fmt, ...);
 
 externC int flash_init(_printf *pf);
 externC int flash_erase(void *base, int len, void **err_address);
-externC int flash_program(void *flash_base, void *ram_base, int len, void **err_address);
-externC int flash_read(void *flash_base, void *ram_base, int len, void **err_address);
+externC int flash_program(void *flash_base, void *ram_base, int len, 
+                          void **err_address);
+externC int flash_read(void *flash_base, void *ram_base, int len, 
+                       void **err_address);
 externC void flash_dev_query(void *data);
 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
 externC int flash_lock(void *base, int len, void **err_address);
@@ -73,169 +153,46 @@ externC int flash_get_limits(void *base,
 externC int flash_get_block_info(int *block_size, int *blocks);
 externC bool flash_code_overlaps(void *start, void *end);
 externC char *flash_errmsg(int err);
+#endif // CYGSEM_IO_FLASH_LEGACY_API
 
-#define FLASH_ERR_OK              0x00  // No error - operation complete
-#define FLASH_ERR_INVALID         0x01  // Invalid FLASH address
-#define FLASH_ERR_ERASE           0x02  // Error trying to erase
-#define FLASH_ERR_LOCK            0x03  // Error trying to lock/unlock
-#define FLASH_ERR_PROGRAM         0x04  // Error trying to program
-#define FLASH_ERR_PROTOCOL        0x05  // Generic error
-#define FLASH_ERR_PROTECT         0x06  // Device/region is write-protected
-#define FLASH_ERR_NOT_INIT        0x07  // FLASH info not yet initialized
-#define FLASH_ERR_HWR             0x08  // Hardware (configuration?) problem
-#define FLASH_ERR_ERASE_SUSPEND   0x09  // Device is in erase suspend mode
-#define FLASH_ERR_PROGRAM_SUSPEND 0x0a  // Device is in in program suspend mode
-#define FLASH_ERR_DRV_VERIFY      0x0b  // Driver failed to verify data
-#define FLASH_ERR_DRV_TIMEOUT     0x0c  // Driver timed out waiting for device
-#define FLASH_ERR_DRV_WRONG_PART  0x0d  // Driver does not support device
-#define FLASH_ERR_LOW_VOLTAGE     0x0e  // Not enough juice to complete job
+#if defined(CYGSEM_IO_FLASH_LEGACY_API) || defined(CYGSEM_IO_FLASH_LEGACY_DEVICE_API)
+#define FLASH_ERR_OK              CYG_FLASH_ERR_OK              
+#define FLASH_ERR_INVALID         CYG_FLASH_ERR_INVALID         
+#define FLASH_ERR_ERASE           CYG_FLASH_ERR_ERASE           
+#define FLASH_ERR_LOCK            CYG_FLASH_ERR_LOCK            
+#define FLASH_ERR_PROGRAM         CYG_FLASH_ERR_PROGRAM         
+#define FLASH_ERR_PROTOCOL        CYG_FLASH_ERR_PROTOCOL        
+#define FLASH_ERR_PROTECT         CYG_FLASH_ERR_PROTECT         
+#define FLASH_ERR_NOT_INIT        CYG_FLASH_ERR_NOT_INIT        
+#define FLASH_ERR_HWR             CYG_FLASH_ERR_HWR             
+#define FLASH_ERR_ERASE_SUSPEND   CYG_FLASH_ERR_ERASE_SUSPEND   
+#define FLASH_ERR_PROGRAM_SUSPEND CYG_FLASH_ERR_PROGRAM_SUSPEND 
+#define FLASH_ERR_DRV_VERIFY      CYG_FLASH_ERR_DRV_VERIFY      
+#define FLASH_ERR_DRV_TIMEOUT     CYG_FLASH_ERR_DRV_TIMEOUT     
+#define FLASH_ERR_DRV_WRONG_PART  CYG_FLASH_ERR_DRV_WRONG_PART  
+#define FLASH_ERR_LOW_VOLTAGE     CYG_FLASH_ERR_LOW_VOLTAGE     
+#endif 
 
 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
 typedef struct {
     CYG_ADDRESS offset;
-    int len;
+    size_t len;
     int flasherr;
-    void **err_address;
+    cyg_flashaddr_t *err_address;
 } cyg_io_flash_getconfig_erase_t;
 
 typedef struct {
-    int dev_size;
+    size_t dev_size;
 } cyg_io_flash_getconfig_devsize_t;
 
 typedef struct {
     CYG_ADDRESS offset;
-    int block_size;
+    size_t block_size;
 } cyg_io_flash_getconfig_blocksize_t;
 #endif
 
 #ifdef _FLASH_PRIVATE_
-
-struct flash_info {
-    int   block_size;   // Assuming fixed size "blocks"
-    int   blocks;       // Number of blocks
-    int   buffer_size;  // Size of write buffer (only defined for some devices)
-    unsigned long block_mask;
-    void *start, *end;  // Address range
-    int   init;
-    _printf *pf;
-};
-
-externC struct flash_info flash_info;
-externC int  flash_hwr_init(void);
-externC int  flash_hwr_map_error(int err);
-
-// 
-// Some FLASH devices may require additional support, e.g. to turn on
-// appropriate voltage drivers, before any operation.
-//
-#ifdef  CYGIMP_FLASH_ENABLE
-#define FLASH_Enable CYGIMP_FLASH_ENABLE
-extern void CYGIMP_FLASH_ENABLE(void *, void *);
-#else
-#define FLASH_Enable(_start_, _end_)
-#endif
-#ifdef  CYGIMP_FLASH_DISABLE
-#define FLASH_Disable CYGIMP_FLASH_DISABLE
-extern void CYGIMP_FLASH_DISABLE(void *, void *);
-#else
-#define FLASH_Disable(_start_, _end_)
-#endif
-
-//
-// Some platforms have a DIP switch or jumper that tells the software that
-// the flash is write protected.
-//
-#ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
-externC cyg_bool plf_flash_query_soft_wp(void *addr, int len);
+#include <cyg/io/flash_priv.h>
 #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
-// to the flash area being programmed. With Harvard style caches, only
-// the data cache needs to be disabled, but the instruction cache is
-// disabled for consistency.
-
-// Targets may provide alternative implementations for these macros in
-// the hal_cache.h (or var/plf) files.
-
-// The first part below is a generic, optimal implementation.  The
-// second part is the old implementation that has been tested to work
-// on some targets - but it is not be suitable for targets that would
-// do burst access to the flash (it does not disable the data cache).
-
-// Both implementations must be called with interrupts disabled.
-
-// NOTE: Do _not_ change any of the below macros without checking that
-//       the changed code still works on _all_ platforms that rely on these
-//       macros. There is no such thing as logical and correct when dealing
-//       with different cache and IO models, so _do not_ mess with this code
-//       unless you test it properly afterwards.
-
-#ifndef HAL_FLASH_CACHES_OFF
-
-// Some drivers have only been tested with the old macros below.
-#ifndef HAL_FLASH_CACHES_OLD_MACROS
-
-#ifdef HAL_CACHE_UNIFIED
-
-// Note: the ucache code has not been tested yet on any target.
-#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
-    CYG_MACRO_START                             \
-    _i_ = 0; /* avoids warning */               \
-    HAL_UCACHE_IS_ENABLED(_d_);                 \
-    HAL_UCACHE_SYNC();                          \
-    HAL_UCACHE_INVALIDATE_ALL();                \
-    HAL_UCACHE_DISABLE();                       \
-    CYG_MACRO_END
-
-#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
-    CYG_MACRO_START                             \
-    if (_d_) HAL_UCACHE_ENABLE();               \
-    CYG_MACRO_END
-
-#else  // HAL_CACHE_UNIFIED
-
-#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
-    CYG_MACRO_START                             \
-    _i_ = 0; /* avoids warning */               \
-    HAL_DCACHE_IS_ENABLED(_d_);                 \
-    HAL_DCACHE_SYNC();                          \
-    HAL_DCACHE_INVALIDATE_ALL();                \
-    HAL_DCACHE_DISABLE();                       \
-    HAL_ICACHE_INVALIDATE_ALL();                \
-    CYG_MACRO_END
-
-#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
-    CYG_MACRO_START                             \
-    if (_d_) HAL_DCACHE_ENABLE();               \
-    CYG_MACRO_END
-
-#endif // HAL_CACHE_UNIFIED
-
-#else  // HAL_FLASH_CACHES_OLD_MACROS
-
-// Note: This implementation is broken as it will always enable the i-cache
-//       even if it was not enabled before. It also doesn't work if the
-//       target uses burst access to flash since the d-cache is left enabled.
-//       However, this does not mean you can change this code! Leave it as
-//       is - if you want a different implementation, provide it in the
-//       arch/var/platform cache header file.
-
-#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
-    _d_ = 0; /* avoids warning */               \
-    _i_ = 0; /* avoids warning */               \
-    HAL_DCACHE_SYNC();                          \
-    HAL_ICACHE_DISABLE();
-
-#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
-    HAL_ICACHE_ENABLE();
-
-#endif  // HAL_FLASH_CACHES_OLD_MACROS
-
-#endif  // HAL_FLASH_CACHES_OFF
-
-#endif  // _FLASH_PRIVATE_
-
 #endif  // _IO_FLASH_H_