OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [flash/] [v2_0/] [include/] [flash.h] - Blame information for rev 576

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      flash.h
4
//
5
//      Flash programming - external interfaces
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    gthomas
44
// Contributors: gthomas
45
// Date:         2000-07-14
46
// Purpose:      
47
// Description:  
48
//              
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#ifndef _IO_FLASH_H_
54
#define _IO_FLASH_H_
55
 
56
#include <pkgconf/io_flash.h>
57
#include <cyg/hal/hal_cache.h>
58
 
59
typedef int _printf(const char *fmt, ...);
60
 
61
#define FLASH_MIN_WORKSPACE CYGNUM_FLASH_WORKSPACE_SIZE  // Space used by FLASH code
62
 
63
externC int flash_init(void *work_space, int work_space_length, _printf *pf);
64
externC int flash_erase(void *base, int len, void **err_address);
65
externC int flash_program(void *flash_base, void *ram_base, int len, void **err_address);
66
externC void flash_dev_query(void *data);
67
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
68
externC int flash_lock(void *base, int len, void **err_address);
69
externC int flash_unlock(void *base, int len, void **err_address);
70
#endif
71
externC int flash_verify_addr(void *base);
72
externC int flash_get_limits(void *base, void **start, void **end);
73
externC int flash_get_block_info(int *block_size, int *blocks);
74
externC bool flash_code_overlaps(void *start, void *end);
75
externC char *flash_errmsg(int err);
76
 
77
#define FLASH_ERR_OK              0x00  // No error - operation complete
78
#define FLASH_ERR_INVALID         0x01  // Invalid FLASH address
79
#define FLASH_ERR_ERASE           0x02  // Error trying to erase
80
#define FLASH_ERR_LOCK            0x03  // Error trying to lock/unlock
81
#define FLASH_ERR_PROGRAM         0x04  // Error trying to program
82
#define FLASH_ERR_PROTOCOL        0x05  // Generic error
83
#define FLASH_ERR_PROTECT         0x06  // Device/region is write-protected
84
#define FLASH_ERR_NOT_INIT        0x07  // FLASH info not yet initialized
85
#define FLASH_ERR_HWR             0x08  // Hardware (configuration?) problem
86
#define FLASH_ERR_ERASE_SUSPEND   0x09  // Device is in erase suspend mode
87
#define FLASH_ERR_PROGRAM_SUSPEND 0x0a  // Device is in in program suspend mode
88
#define FLASH_ERR_DRV_VERIFY      0x0b  // Driver failed to verify data
89
#define FLASH_ERR_DRV_TIMEOUT     0x0c  // Driver timed out waiting for device
90
#define FLASH_ERR_DRV_WRONG_PART  0x0d  // Driver does not support device
91
#define FLASH_ERR_LOW_VOLTAGE     0x0e  // Not enough juice to complete job
92
 
93
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
94
typedef struct {
95
    CYG_ADDRESS offset;
96
    int len;
97
    int flasherr;
98
    void **err_address;
99
} cyg_io_flash_getconfig_erase_t;
100
 
101
typedef struct {
102
    int dev_size;
103
} cyg_io_flash_getconfig_devsize_t;
104
 
105
typedef struct {
106
    CYG_ADDRESS offset;
107
    int block_size;
108
} cyg_io_flash_getconfig_blocksize_t;
109
#endif
110
 
111
#ifdef _FLASH_PRIVATE_
112
 
113
struct flash_info {
114
    void *work_space;
115
    int   work_space_size;
116
    int   block_size;   // Assuming fixed size "blocks"
117
    int   blocks;       // Number of blocks
118
    int   buffer_size;  // Size of write buffer (only defined for some devices)
119
    unsigned long block_mask;
120
    void *start, *end;  // Address range
121
    int   init;
122
    _printf *pf;
123
};
124
 
125
externC struct flash_info flash_info;
126
externC int  flash_hwr_init(void);
127
externC int  flash_hwr_map_error(int err);
128
 
129
// 
130
// Some FLASH devices may require additional support, e.g. to turn on
131
// appropriate voltage drivers, before any operation.
132
//
133
#ifdef  CYGIMP_FLASH_ENABLE
134
#define FLASH_Enable CYGIMP_FLASH_ENABLE
135
extern void CYGIMP_FLASH_ENABLE(void *, void *);
136
#else
137
#define FLASH_Enable(_start_, _end_)
138
#endif
139
#ifdef  CYGIMP_FLASH_DISABLE
140
#define FLASH_Disable CYGIMP_FLASH_DISABLE
141
extern void CYGIMP_FLASH_DISABLE(void *, void *);
142
#else
143
#define FLASH_Disable(_start_, _end_)
144
#endif
145
 
146
//
147
// Some platforms have a DIP switch or jumper that tells the software that
148
// the flash is write protected.
149
//
150
#ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
151
externC cyg_bool plf_flash_query_soft_wp(void *addr, int len);
152
#endif
153
 
154
//---------------------------------------------------------------------------
155
// Execution of flash code must be done inside a
156
// HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the
157
// cache on unified cache systems is necessary to prevent burst access
158
// to the flash area being programmed. With Harvard style caches, only
159
// the data cache needs to be disabled, but the instruction cache is
160
// disabled for consistency.
161
 
162
// Targets may provide alternative implementations for these macros in
163
// the hal_cache.h (or var/plf) files.
164
 
165
// The first part below is a generic, optimal implementation.  The
166
// second part is the old implementation that has been tested to work
167
// on some targets - but it is not be suitable for targets that would
168
// do burst access to the flash (it does not disable the data cache).
169
 
170
// Both implementations must be called with interrupts disabled.
171
 
172
// NOTE: Do _not_ change any of the below macros without checking that
173
//       the changed code still works on _all_ platforms that rely on these
174
//       macros. There is no such thing as logical and correct when dealing
175
//       with different cache and IO models, so _do not_ mess with this code
176
//       unless you test it properly afterwards.
177
 
178
#ifndef HAL_FLASH_CACHES_OFF
179
 
180
// Some drivers have only been tested with the old macros below.
181
#ifndef HAL_FLASH_CACHES_OLD_MACROS
182
 
183
#ifdef HAL_CACHE_UNIFIED
184
 
185
// Note: the ucache code has not been tested yet on any target.
186
#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
187
    CYG_MACRO_START                             \
188
    _i_ = 0; /* avoids warning */               \
189
    HAL_UCACHE_IS_ENABLED(_d_);                 \
190
    HAL_UCACHE_SYNC();                          \
191
    HAL_UCACHE_INVALIDATE_ALL();                \
192
    HAL_UCACHE_DISABLE();                       \
193
    CYG_MACRO_END
194
 
195
#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
196
    CYG_MACRO_START                             \
197
    if (_d_) HAL_UCACHE_ENABLE();               \
198
    CYG_MACRO_END
199
 
200
#else  // HAL_CACHE_UNIFIED
201
 
202
#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
203
    CYG_MACRO_START                             \
204
    _i_ = 0; /* avoids warning */               \
205
    HAL_DCACHE_IS_ENABLED(_d_);                 \
206
    HAL_DCACHE_SYNC();                          \
207
    HAL_DCACHE_INVALIDATE_ALL();                \
208
    HAL_DCACHE_DISABLE();                       \
209
    HAL_ICACHE_INVALIDATE_ALL();                \
210
    CYG_MACRO_END
211
 
212
#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
213
    CYG_MACRO_START                             \
214
    if (_d_) HAL_DCACHE_ENABLE();               \
215
    CYG_MACRO_END
216
 
217
#endif // HAL_CACHE_UNIFIED
218
 
219
#else  // HAL_FLASH_CACHES_OLD_MACROS
220
 
221
// Note: This implementation is broken as it will always enable the i-cache
222
//       even if it was not enabled before. It also doesn't work if the
223
//       target uses burst access to flash since the d-cache is left enabled.
224
//       However, this does not mean you can change this code! Leave it as
225
//       is - if you want a different implementation, provide it in the
226
//       arch/var/platform cache header file.
227
 
228
#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
229
    _d_ = 0; /* avoids warning */               \
230
    _i_ = 0; /* avoids warning */               \
231
    HAL_DCACHE_SYNC();                          \
232
    HAL_ICACHE_DISABLE();
233
 
234
#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
235
    HAL_ICACHE_ENABLE();
236
 
237
#endif  // HAL_FLASH_CACHES_OLD_MACROS
238
 
239
#endif  // HAL_FLASH_CACHES_OFF
240
 
241
#endif  // _FLASH_PRIVATE_
242
 
243
#endif  // _IO_FLASH_H_

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.