comparison packages/io/flash/current/include/flash_dev.h @ 1764:96ec7e534d98

V2 flash header files clean-up. Eliminate flash_priv.h, moving the functionality into flash_dev.h instead.
author bartv
date Tue, 22 Feb 2005 21:03:43 +0000
parents f493618bc252
children
comparison
equal deleted inserted replaced
1763:42c8ea63b78d 1764:96ec7e534d98
8 // 8 //
9 //========================================================================== 9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN#### 10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // ------------------------------------------- 11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System. 12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 2004 eCosCentric Ltd.
14 // Copyright (C) 2004 Andrew Lunn
15 // Copyright (C) 2003 Gary Thomas
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 16 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 // 17 //
15 // eCos is free software; you can redistribute it and/or modify it under 18 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free 19 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version. 20 // Software Foundation; either version 2 or (at your option) any later version.
40 // ------------------------------------------- 43 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND#### 44 //####ECOSGPLCOPYRIGHTEND####
42 //========================================================================== 45 //==========================================================================
43 //#####DESCRIPTIONBEGIN#### 46 //#####DESCRIPTIONBEGIN####
44 // 47 //
48 // Author(s): gthomas
49 // Contributors: gthomas, Andrew Lunn, bartv
50 // Date: 2000-07-14
51 // Purpose:
52 // Description:
53 //
54 //####DESCRIPTIONEND####
55 //
56 //==========================================================================
57
58 #include <pkgconf/system.h>
59 #include <pkgconf/io_flash.h>
60 #include <cyg/infra/cyg_type.h>
61 #include <cyg/io/flash.h>
62 #include <cyg/hal/hal_cache.h>
63 #include <cyg/hal/hal_tables.h>
64
65 // Forward reference of the device structure
66 struct cyg_flash_dev;
67
68 // Structure of pointers to functions in the device driver
69 struct cyg_flash_dev_funs {
70 int (*flash_init) (struct cyg_flash_dev *dev);
71 size_t (*flash_query) (struct cyg_flash_dev *dev,
72 void * data, size_t len);
73 int (*flash_erase_block) (struct cyg_flash_dev *dev,
74 cyg_flashaddr_t block_base);
75 int (*flash_program) (struct cyg_flash_dev *dev,
76 cyg_flashaddr_t base,
77 const void* data, size_t len);
78 int (*flash_read) (struct cyg_flash_dev *dev,
79 const cyg_flashaddr_t base,
80 void* data, size_t len);
81 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
82 int (*flash_block_lock) (struct cyg_flash_dev *dev,
83 const cyg_flashaddr_t block_base);
84 int (*flash_block_unlock) (struct cyg_flash_dev *dev,
85 const cyg_flashaddr_t block_base);
86 #endif
87 };
88
89 // Dummy functions for some of the above operations, if a device does
90 // not support e.g. locking.
91 externC int cyg_flash_devfn_init_nop(struct cyg_flash_dev*);
92 externC size_t cyg_flash_devfn_query_nop(struct cyg_flash_dev*, void*, const size_t);
93 externC int cyg_flash_devfn_lock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
94 externC int cyg_flash_devfn_unlock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
95
96 // Facilitate function calls between flash-resident code and .2ram
97 // functions.
98 externC void* cyg_flash_anonymizer(void*);
99
100 // Structure each device places in the HAL table
101 struct cyg_flash_dev {
102 const struct cyg_flash_dev_funs *funs; // Function pointers
103 cyg_uint32 flags; // Device characteristics
104 cyg_flashaddr_t start; // First address
105 cyg_flashaddr_t end; // Last address
106 cyg_uint32 num_block_infos; // Number of entries
107 const cyg_flash_block_info_t *block_info; // Info about one block size
108
109 const void *priv; // Devices private data
110
111 // The following are only written to by the FLASH IO layer.
112 cyg_flash_printf *pf; // Pointer to diagnostic printf
113 bool init; // Device has been initialised
114 #ifdef CYGPKG_KERNEL
115 cyg_mutex_t mutex; // Mutex for thread safeness
116 #endif
117 #if (CYGHWR_IO_FLASH_DEVICE > 1)
118 struct cyg_flash_dev *next; // Pointer to next device
119 #endif
120 } CYG_HAL_TABLE_TYPE;
121
122 // Macros for instantiating the above structures.
123 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
124 # define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _lock_, _unlock_) \
125 struct cyg_flash_dev_funs _funs_ = \
126 { \
127 .flash_init = _init_, \
128 .flash_query = _query_, \
129 .flash_erase_block = _erase_, \
130 .flash_program = _prog_, \
131 .flash_read = _read_, \
132 .flash_block_lock = _lock_, \
133 .flash_block_unlock = _unlock_ \
134 }
135 #else
136 # define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _lock_, _unlock_) \
137 struct cyg_flash_dev_funs _funs_ = \
138 { \
139 .flash_init = _init_, \
140 .flash_query = _query_, \
141 .flash_erase_block = _erase_, \
142 .flash_program = _prog_, \
143 .flash_read = _read_ \
144 }
145 #endif
146
147 // We assume HAL tables are placed into RAM.
148 #define CYG_FLASH_DRIVER(_name_, _funs_, _flags_, _start_, _end_, _num_block_infos_, _block_info_, _priv_) \
149 struct cyg_flash_dev _name_ CYG_HAL_TABLE_ENTRY(cyg_flashdev) = \
150 { \
151 .funs = _funs_, \
152 .flags = _flags_, \
153 .start = _start_, \
154 .end = _end_, \
155 .num_block_infos = _num_block_infos_, \
156 .block_info = _block_info_, \
157 .priv = _priv_ \
158 }
159
160 // Additional support for legacy device drivers.
161 #ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY
162 struct flash_info {
163 int block_size; // Assuming fixed size "blocks"
164 int blocks; // Number of blocks
165 int buffer_size; // Size of write buffer (only defined for some devices)
166 unsigned long block_mask;
167 void *start, *end; // Address range
168 int init;
169 cyg_flash_printf *pf;
170 };
171
172 externC struct flash_info flash_info;
173 externC int flash_hwr_init(void);
174 externC int flash_hwr_map_error(int err);
175 externC void flash_dev_query(void *data);
176 #endif // CYGHWR_IO_FLASH_DEVICE_LEGACY
177
178 // ----------------------------------------------------------------------------
179 // This section provides utility macros used by some flash drivers, especially
180 // the legacy ones. Such flash drivers need to #define _FLASH_PRIVATE before
181 // including this file.
182
183 #ifdef _FLASH_PRIVATE_
184
185 //==========================================================================
45 // Author(s): hmt 186 // Author(s): hmt
46 // Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com> 187 // Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com>
47 // Date: 2001-02-22 188 // Date: 2001-02-22
48 // Purpose: Define common flash device driver definitions 189 // Purpose: Define common flash device driver definitions
49 // Description: The flash_data_t type is used for accessing 190 // Description: The flash_data_t type is used for accessing
51 // The FLASHWORD macro must be used to create constants 192 // The FLASHWORD macro must be used to create constants
52 // of suitable width. 193 // of suitable width.
53 // The FLASH_P2V macro can be used to fix up non-linear 194 // The FLASH_P2V macro can be used to fix up non-linear
54 // mappings of flash blocks (defaults to a linear 195 // mappings of flash blocks (defaults to a linear
55 // implementation). 196 // implementation).
56 // 197 //==========================================================================
57 //####DESCRIPTIONEND#### 198
58 //
59 //==========================================================================
60
61 #ifdef _FLASH_PRIVATE_
62 #include <cyg/infra/cyg_type.h>
63
64 // ------------------------------------------------------------------------
65 //
66 // No mapping on this target - but these casts would be needed if some 199 // No mapping on this target - but these casts would be needed if some
67 // manipulation did occur. An example of this might be: 200 // manipulation did occur. An example of this might be:
68 // // First 4K page of flash at physical address zero is 201 // // First 4K page of flash at physical address zero is
69 // // virtually mapped at address 0xa0000000. 202 // // virtually mapped at address 0xa0000000.
70 // #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ? 203 // #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ?
163 #endif // _FLASH_PRIVATE_ 296 #endif // _FLASH_PRIVATE_
164 297
165 #endif // CYGONCE_IO_FLASH_FLASH_DEV_H 298 #endif // CYGONCE_IO_FLASH_FLASH_DEV_H
166 //---------------------------------------------------------------------------- 299 //----------------------------------------------------------------------------
167 // end of flash_dev.h 300 // end of flash_dev.h
301