annotate packages/io/flash/current/src/flash.c @ 2626:a2f5434df2cb

Merge flashv2 branch to trunk, with eCosCentric additions
author jlarmour
date Tue, 18 Nov 2008 00:56:04 +0000
parents a7557f72de47
children 592d727733df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
1 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
2 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
3 // flash.c
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
4 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
5 // Flash programming
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
6 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
7 //==========================================================================
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
9 // -------------------------------------------
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
11 // Copyright (C) 2004 Andrew Lunn
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
12 // Copyright (C) 2004, 2005, 2006 eCosCentric Ltd.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
13 // Copyright (C) 2003 Gary Thomas
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
15 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
16 // eCos is free software; you can redistribute it and/or modify it under
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
17 // the terms of the GNU General Public License as published by the Free
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
18 // Software Foundation; either version 2 or (at your option) any later version.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
19 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
23 // for more details.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
24 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
25 // You should have received a copy of the GNU General Public License along
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
28 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
29 // As a special exception, if other files instantiate templates or use macros
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
30 // or inline functions from this file, or you compile this file and link it
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
31 // with other works to produce a work based on this file, this file does not
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
32 // by itself cause the resulting work to be covered by the GNU General Public
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
33 // License. However the source code for this file must still be made available
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
34 // in accordance with section (3) of the GNU General Public License.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
35 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
36 // This exception does not invalidate any other reasons why a work based on
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
37 // this file might be covered by the GNU General Public License.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
38 // -------------------------------------------
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
40 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
42 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
43 // Author(s): gthomas
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
44 // Contributors: gthomas, Andrew Lunn, Bart Veer
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
45 // Date: 2000-07-26
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
46 // Purpose:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
47 // Description:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
48 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
49 //####DESCRIPTIONEND####
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
50 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
51 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
52
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
53 #include <pkgconf/system.h>
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
54 #include <pkgconf/io_flash.h>
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
55 #ifdef CYGPKG_KERNEL
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
56 #include <cyg/kernel/kapi.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
57 #endif
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
58 #include <cyg/hal/hal_arch.h>
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
59 #include <cyg/hal/hal_intr.h>
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
60 #include <cyg/hal/hal_cache.h>
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
61 #include <cyg/hal/hal_tables.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
62 #include <cyg/infra/cyg_ass.h>
191
678094f34118 Merge from eCos master repository on 2001-10-19-06:43:02-BST
jlarmour
parents: 177
diff changeset
63 #include <string.h>
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
64
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
65 #include <cyg/io/flash.h>
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
66 #include <cyg/io/flash_dev.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
67 #include "flash_legacy.h"
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
68
143
6b5f480c6929 Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents: 141
diff changeset
69 // When this flag is set, do not actually jump to the relocated code.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
70 // This can be used for running the function in place (RAM startup
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
71 // only), allowing calls to diag_printf() and similar.
136
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
72 #undef RAM_FLASH_DEV_DEBUG
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
73 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG)
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
74 # warning "Can only enable the flash debugging when configured for RAM startup"
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
75 #endif
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
76
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
77 // Optional verbosity. Using a macro here avoids lots of ifdefs in the
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
78 // rest of the code.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
79 #ifdef CYGSEM_IO_FLASH_CHATTER
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
80 # define CHATTER(_dev_, _fmt_, ...) (*(_dev_)->pf)((_fmt_), ## __VA_ARGS__)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
81 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
82 # define CHATTER(_dev_, _fmt_, ...) CYG_EMPTY_STATEMENT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
83 #endif
1400
707a873489c8 * src/flash.c: gcc 3.x vs gcc 2.x problems.
asl
parents: 1389
diff changeset
84
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
85 // Per-thread locking. Again using macros avoids lots of ifdefs
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
86 #ifdef CYGPKG_KERNEL
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
87 # define LOCK_INIT(_dev_) cyg_mutex_init(&((_dev_)->mutex))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
88 # define LOCK(_dev_) cyg_mutex_lock(&((_dev_)->mutex))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
89 # define UNLOCK(_dev_) cyg_mutex_unlock(&((_dev_)->mutex))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
90 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
91 # define LOCK_INIT(_dev_) CYG_EMPTY_STATEMENT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
92 # define LOCK(_dev_) CYG_EMPTY_STATEMENT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
93 # define UNLOCK(_dev_) CYG_EMPTY_STATEMENT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
94 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
95
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
96 // Software write-protect. Very rarely used.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
97 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
98 # define CHECK_SOFT_WRITE_PROTECT(_addr_, _len_) \
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
99 CYG_MACRO_START \
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
100 if (plf_flash_query_soft_wp((_addr_), (_len_))) \
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
101 return CYG_FLASH_ERR_PROTECT; \
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
102 CYG_MACRO_END
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
103 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
104 #define CHECK_SOFT_WRITE_PROTECT(_addr_, _len_) CYG_EMPTY_STATEMENT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
105 #endif
1400
707a873489c8 * src/flash.c: gcc 3.x vs gcc 2.x problems.
asl
parents: 1389
diff changeset
106
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
107 // Has the FLASH IO library been initialised?
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
108 static bool init;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
109
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
110 // This array contains entries for all flash devices that are
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
111 // installed in the system.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
112 __externC struct cyg_flash_dev cyg_flashdevtab[];
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
113 CYG_HAL_TABLE_BEGIN(cyg_flashdevtab, cyg_flashdev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
114
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
115 // end of the flashdev table
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
116 __externC struct cyg_flash_dev cyg_flashdevtab_end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
117 CYG_HAL_TABLE_END(cyg_flashdevtab_end, cyg_flashdev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
118
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
119 #if (1 == CYGHWR_IO_FLASH_DEVICE)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
120
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
121 // Optimize the code for a single flash device, which is the common case.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
122 // The flash subsystem must have been initialized, the single device must
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
123 // contain the specified address, and the device itself must have
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
124 // initialized successfully.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
125 static struct cyg_flash_dev*
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
126 find_dev(cyg_flashaddr_t addr, int* stat)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
127 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
128 if (!init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
129 *stat = CYG_FLASH_ERR_NOT_INIT;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
130 return NULL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
131 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
132 if (! ((addr >= cyg_flashdevtab[0].start) && (addr <= cyg_flashdevtab[0].end))) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
133 *stat = CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
134 return NULL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
135 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
136 if (! cyg_flashdevtab[0].init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
137 *stat = CYG_FLASH_ERR_NOT_INIT;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
138 return NULL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
139 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
140 return &cyg_flashdevtab[0];
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
141 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
142
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
143 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
144
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
145 // There are multiple devices. For convenience these are kept in a
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
146 // linked list, sorted by address. This is the head of the list
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
147 static struct cyg_flash_dev *flash_head = NULL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
148
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
149 static bool flash_sort_and_check(void)
154
e2d866e32dac Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents: 151
diff changeset
150 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
151 bool moved;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
152 struct cyg_flash_dev *dev, **previous_next;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
153
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
154 // Place all devices that initialised on the list, unsorted for now.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
155 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
156 if (dev->init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
157 dev->next = flash_head;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
158 flash_head = dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
159 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
160 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
161
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
162 // If there are no valid devices, abort. This might happen if
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
163 // all drivers failed to initialize.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
164 if (flash_head == NULL) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
165 return false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
166 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
167
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
168 // Sort the linked list into ascending order of flash address. Use a
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
169 // primitive ripple sort, but since we don't expect to have many
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
170 // devices this should be OK. This loop may run safely with just one
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
171 // entry on the list.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
172 do {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
173 moved=false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
174 for (dev=flash_head, previous_next=&flash_head;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
175 dev->next;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
176 previous_next = &dev->next, dev=dev->next ){
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
177 if (dev->start > dev->next->start) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
178 *previous_next=dev->next;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
179 dev->next = (*previous_next)->next;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
180 (*previous_next)->next = dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
181 moved=true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
182 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
183 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
184 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
185 } while (moved);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
186
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
187 // Now walk the linked list and see if there are any overlaps in the
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
188 // addresses the devices claim to use using.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
189 for (dev=flash_head; dev->next; dev=dev->next){
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
190 if (dev->end >= dev->next->start)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
191 return false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
192 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
193 return true;
154
e2d866e32dac Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents: 151
diff changeset
194 }
e2d866e32dac Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents: 151
diff changeset
195
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
196 // Find the device at the specified address, if any.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
197 static struct cyg_flash_dev*
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
198 find_dev(cyg_flashaddr_t addr, int* stat)
143
6b5f480c6929 Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents: 141
diff changeset
199 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
200 struct cyg_flash_dev* dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
201 if (!init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
202 *stat = CYG_FLASH_ERR_NOT_INIT;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
203 return NULL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
204 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
205 for (dev = flash_head; dev; dev = dev->next) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
206 if ((dev->start <= addr) && (addr <= dev->end)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
207 return dev;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
208 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
209 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
210 *stat = CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
211 return NULL;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
212 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
213
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
214 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
215
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
216 // Initialise all registered device. Any device that fails to
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
217 // initialise we leave dev->init as false. Then sort the devices into
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
218 // ascending order of address and put them into a linked list. Lastly
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
219 // check if we have any overlap of the addresses.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
220 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
221 cyg_flash_init(cyg_flash_printf *pf)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
222 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
223 int err;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
224 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
225
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
226 if (init) return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
227
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
228 CYG_ASSERT(&(cyg_flashdevtab[CYGHWR_IO_FLASH_DEVICE]) == &cyg_flashdevtab_end, "incorrect number of flash devices");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
229
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
230 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
231 dev->pf = pf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
232 LOCK_INIT(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
233
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
234 err = dev->funs->flash_init(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
235 if (err != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
236 continue;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
237 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
238 CYG_ASSERT(dev->funs, "No flash functions");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
239 CYG_ASSERT(dev->num_block_infos, "No number of block infos");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
240 CYG_ASSERT(dev->block_info, "No block infos");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
241 CYG_ASSERT(!(((cyg_flashaddr_t)dev->block_info >= dev->start) &&
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
242 ((cyg_flashaddr_t)dev->block_info < dev->end)),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
243 "Block info is in the flash");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
244 CYG_ASSERT(dev->funs->flash_erase_block, "No erase function");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
245 CYG_ASSERT(dev->funs->flash_program, "No program function");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
246 #ifdef CYGDBG_USE_ASSERTS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
247 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
248 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
249 cyg_flashaddr_t addr = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
250 for (i = 0; i < dev->num_block_infos; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
251 addr += dev->block_info[i].block_size * dev->block_info[i].blocks;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
252 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
253 CYG_ASSERT(dev->end == addr-1, "Invalid end address");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
254 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
255 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
256 dev->init = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
257 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
258
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
259 #if (1 == CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
260 // Make sure there is one device, otherwise we could end up
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
261 // accessing a non-existent cyg_flash_dev structure.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
262 if (&(cyg_flashdevtab[0]) == &cyg_flashdevtab_end) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
263 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
264 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
265 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
266 // Place the devices on a sorted linked list and check that there
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
267 // are no overlaps in the address space.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
268 if (! flash_sort_and_check() ) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
269 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
270 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
271 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
272
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
273 // Only mark the flash subsystem as initialized if the world is
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
274 // consistent.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
275 init = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
276 return CYG_FLASH_ERR_OK;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
277 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
278
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
279 // Is the address within one of the flash drivers?
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
280 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
281 cyg_flash_verify_addr(const cyg_flashaddr_t address)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
282 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
283 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
284 (void) find_dev(address, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
285 return stat;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
286 }
157
b65ec671dd4c Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents: 156
diff changeset
287
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
288 // Return information about the Nth driver
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
289 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
290 cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
291 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
292 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
293
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
294 if (!init) return CYG_FLASH_ERR_NOT_INIT;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
295
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
296 #if (1 == CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
297 if ((0 == Nth) && cyg_flashdevtab[0].init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
298 dev = &(cyg_flashdevtab[0]);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
299 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
300 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
301 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
302 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
303 // Only initialized devices are on the list.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
304 for (dev = flash_head; dev && Nth; dev=dev->next, Nth--)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
305 ;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
306 if (!dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
307 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
308 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
309 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
310 info->start = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
311 info->end = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
312 info->num_block_infos = dev->num_block_infos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
313 info->block_info = dev->block_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
314 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
315 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
316
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
317 // Return information about the flash at the given address
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
318 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
319 cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base, cyg_flash_info_t * info)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
320 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
321 struct cyg_flash_dev *dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
322 int stat = CYG_FLASH_ERR_OK;
174
38892b97b685 Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents: 163
diff changeset
323
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
324 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
325 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
326 info->start = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
327 info->end = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
328 info->num_block_infos = dev->num_block_infos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
329 info->block_info = dev->block_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
330 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
331 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
332 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
333
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
334 #ifdef CYGPKG_KERNEL
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
335 // Lock the mutex's for a range of addresses
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
336 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
337 cyg_flash_mutex_lock(const cyg_flashaddr_t from, size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
338 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
339 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
340 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
341
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
342 dev = find_dev(from, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
343 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
344 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
345 if (len > (dev->end + 1 - from)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
346 stat = cyg_flash_mutex_lock(dev->end + 1, len - (dev->end + 1 - from));
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
347 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
348 // Something went wrong, unlock what we just locked
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
349 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
350 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
351 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
352 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
353 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
354 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
355
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
356 // Unlock the mutex's for a range of addresses
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
357 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
358 cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
359 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
360 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
361 int stat = CYG_FLASH_ERR_OK;
195
67850532eebb Merge from eCos master repository on 2001-11-02-06:43:03-GMT
jlarmour
parents: 191
diff changeset
362
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
363 dev = find_dev(from, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
364 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
365 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
366 if (len > (dev->end + 1 - from)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
367 stat = cyg_flash_mutex_lock(dev->end + 1, len - (dev->end + 1 - from));
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
368 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
369 // Something went wrong, relock what we just unlocked. This may not
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
370 // be worth it since things must be pretty messed up, and could
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
371 // conceivably end in deadlock if there is a concurrent call to
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
372 // cyg_flash_mutex_lock();
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
373 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
374 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
375 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
376 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
377 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
378 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
379 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
380
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
381 // Return the size of the block which is at the given address
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
382 static size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
383 flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
384 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
385 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
386 size_t offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
387
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
388 CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
389
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
390 offset = addr - dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
391 for (i=0; i < dev->num_block_infos; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
392 if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
393 return dev->block_info[i].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
394 offset = offset -
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
395 (dev->block_info[i].blocks * dev->block_info[i].block_size);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
396 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
397 CYG_FAIL("Programming error");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
398 return 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
399 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
400
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
401 // Return the size of the block which is at the given address
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
402 __externC size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
403 cyg_flash_block_size(const cyg_flashaddr_t flash_base)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
404 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
405 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
406 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
407
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
408 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
409 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
410 return flash_block_size(dev, flash_base);
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
411 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
412
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
413 // Return the first address of a block. The flash might not be aligned
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
414 // in terms of its block size. So we have to be careful and use
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
415 // offsets.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
416 static inline cyg_flashaddr_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
417 flash_block_begin(cyg_flashaddr_t addr, struct cyg_flash_dev *dev)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
418 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
419 size_t block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
420 cyg_flashaddr_t offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
421
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
422 block_size = flash_block_size(dev, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
423
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
424 offset = addr - dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
425 offset = (offset / block_size) * block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
426 return offset + dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
427 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
428
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
429
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
430 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
431 cyg_flash_erase(cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
432 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
433 cyg_flashaddr_t *err_address)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
434 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
435 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
436 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
437 size_t erase_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
438 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
439 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
440
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
441 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
442 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
443
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
444 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
445
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
446 LOCK(dev);
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
447
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
448 // Check whether or not we are going past the end of this device, on
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
449 // to the next one. If so the next device will be handled by a
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
450 // recursive call later on.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
451 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
452 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
453 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
454 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
455 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
456 // erase can only happen on a block boundary, so adjust for this
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
457 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
458 erase_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
459
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
460 CHATTER(dev, "... Erase from %p-%p: ", (void*)block, (void*)end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
461
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
462 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
463 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
464 while (erase_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
465 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
466 unsigned char *dp;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
467 bool erased = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
468 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
469
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
470 // Pad to the block boundary, if necessary
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
471 if (erase_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
472 erase_count = block_size;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
473 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
474
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
475 // If there is a read function it probably means the flash
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
476 // cannot be read directly.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
477 if (!dev->funs->flash_read) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
478 erased = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
479 dp = (unsigned char *)block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
480 for (i = 0; i < block_size; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
481 if (*dp++ != (unsigned char)0xFF) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
482 erased = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
483 break;
174
38892b97b685 Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents: 163
diff changeset
484 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
485 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
486 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
487 if (!erased) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
488 stat = dev->funs->flash_erase_block(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
489 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
490 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
491 if (err_address)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
492 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
493 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
494 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
495 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
496 erase_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
497 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
498 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
499 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
500 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
501 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
502 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
503 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
504 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
505 }
174
38892b97b685 Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents: 163
diff changeset
506
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
507 // If there are multiple flash devices in series the erase operation
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
508 // may touch successive devices. This can be handled by recursion.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
509 // The stack overheads should be minimal because the number of
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
510 // devices will be small.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
511 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
512 return cyg_flash_erase(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
513 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
514 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
515 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
516 return CYG_FLASH_ERR_OK;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
517 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
518
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
519 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
520 cyg_flash_program(cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
521 const void *ram_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
522 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
523 cyg_flashaddr_t *err_address)
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
524 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
525 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
526 cyg_flashaddr_t addr, end_addr, block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
527 const unsigned char * ram = ram_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
528 size_t write_count, offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
529 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
530 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
531
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
532 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
533 if (!dev) return stat;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
534
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
535 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
536
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
537 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
538 addr = flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
539 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
540 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
541 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
542 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
543 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
544 write_count = (end_addr + 1) - flash_base;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
545
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
546 // The first write may be in the middle of a block. Do the necessary
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
547 // adjustment here rather than inside the loop.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
548 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
549 if (addr == block) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
550 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
551 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
552 offset = addr - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
553 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
554
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
555 CHATTER(dev, "... Program from %p-%p to %p: ", ram_base, ((CYG_ADDRESS)ram_base)+write_count, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
556
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
557 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
558 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
559 while (write_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
560 size_t block_size = flash_block_size(dev, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
561 size_t this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
562 if (write_count > (block_size - offset)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
563 this_write = block_size - offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
564 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
565 this_write = write_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
566 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
567 // Only the first block may need the offset.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
568 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
569
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
570 stat = dev->funs->flash_program(dev, addr, ram, this_write);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
571 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
572 if (CYG_FLASH_ERR_OK == stat) // Claims to be OK
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
573 if (!dev->funs->flash_read && memcmp((void *)addr, ram, this_write) != 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
574 stat = CYG_FLASH_ERR_DRV_VERIFY;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
575 CHATTER(dev, "V");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
576 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
577 #endif
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
578 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
579 if (err_address)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
580 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
581 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
582 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
583 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
584 write_count -= this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
585 addr += this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
586 ram += this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
587 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
588 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
589 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
590 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
591 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
592 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
593 return (stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
594 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
595 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
596 return cyg_flash_program(dev->end+1, ram,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
597 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
598 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
599 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
600 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
601 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
602
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
603 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
604 cyg_flash_read(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
605 void *ram_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
606 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
607 cyg_flashaddr_t *err_address)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
608 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
609 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
610 cyg_flashaddr_t addr, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
611 unsigned char * ram = (unsigned char *)ram_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
612 size_t read_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
613 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
614
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
615 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
616 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
617
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
618 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
619 addr = flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
620 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
621 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
622 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
623 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
624 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
625 read_count = (end_addr + 1) - flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
627 // CHATTER(dev, "... Read from %p-%p to %p: ", addr, end_addr, ram_base);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
628
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
629 // If the flash is directly accessible, just read it in one go. This
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
630 // still happens with the mutex locked to protect against concurrent
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
631 // programs/erases.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
632 if (! dev->funs->flash_read) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
633 memcpy(ram, (void*)addr, read_count);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
634 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
635 #ifndef CYGHWR_IO_FLASH_INDIRECT_READS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
636 CYG_FAIL("read function supplied but indirect reads not enabled");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
637 stat = CYG_FLASH_ERR_PROTOCOL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
638 if (err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
639 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
640 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
641 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
642 // We have to indirect through the device driver.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
643 // The first read may be in the middle of a block. Do the necessary
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
644 // adjustment here rather than inside the loop.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
645 size_t offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
646 cyg_flashaddr_t block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
647 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
648 if (addr == block) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
649 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
650 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
651 offset = addr - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
652 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
653 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
654 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
655 while (read_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
656 size_t block_size = flash_block_size(dev, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
657 size_t this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
658 if (read_count > (block_size - offset)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
659 this_read = block_size - offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
660 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
661 this_read = read_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
662 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
663 // Only the first block may need the offset
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
664 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
665
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
666 stat = dev->funs->flash_read(dev, addr, ram, this_read);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
667 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
668 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
669 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
670 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
671 // CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
672 read_count -= this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
673 addr += this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
674 ram += this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
675 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
676 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
677 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
678 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
679 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
680 // CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
681 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
682 if (stat != CYG_FLASH_ERR_OK) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
683 return (stat);
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
684 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
685 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
686 return cyg_flash_read(dev->end+1, ram,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
687 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
688 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
689 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
690 return CYG_FLASH_ERR_OK;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
691 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
692
177
4c750ce71ae3 Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents: 174
diff changeset
693 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
694 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
695 cyg_flash_lock(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
696 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
697 cyg_flashaddr_t *err_address)
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
698 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
699 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
700 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
701 size_t lock_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
702 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
703 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
704
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
705 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
706 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
707 if (!dev->funs->flash_block_lock) return CYG_FLASH_ERR_INVALID;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
708
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
709 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
710
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
711 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
712 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
713 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
714 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
715 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
716 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
717 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
718 lock_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
719
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
720 CHATTER(dev, "... Locking from %p-%p: ", (void*)block, (void*)end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
721
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
722 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
723 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
724 while (lock_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
725 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
726 if (lock_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
727 lock_count = block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
728 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
729 stat = dev->funs->flash_block_lock(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
730
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
731 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
732 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
733 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
734 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
735 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
736 lock_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
737 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
738 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
739 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
740 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
741 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
742 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
743 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
744 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
745 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
746
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
747 // Recurse if necessary for the next device
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
748 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
749 return cyg_flash_lock(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
750 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
751 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
752 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
753
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
754 return CYG_FLASH_ERR_OK;
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
755 }
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
756
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
757 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
758 cyg_flash_unlock(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
759 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
760 cyg_flashaddr_t *err_address)
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
761 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
762 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
763 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
764 size_t unlock_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
765 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
766 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
767
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
768 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
769 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
770 if (!dev->funs->flash_block_unlock) return CYG_FLASH_ERR_INVALID;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
771
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
772 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
773
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
774 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
775 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
776 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
777 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
778 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
779 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
780 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
781 unlock_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
782
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
783 CHATTER(dev, "... Unlocking from %p-%p: ", (void*)block, (void*)end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
784
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
785 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
786 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
787 while (unlock_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
788 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
789 if (unlock_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
790 unlock_count = block_size;
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
791 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
792 stat = dev->funs->flash_block_unlock(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
793
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
794 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
795 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
796 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
797 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
798 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
799 unlock_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
800
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
801 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
802 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
803 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
804 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
805 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
806 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
807 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
808 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
809 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
810
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
811 // Recurse if necessary for the next device
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
812 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
813 return cyg_flash_lock(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
814 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
815 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
816 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
817 return CYG_FLASH_ERR_OK;
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
818 }
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
819 #endif
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
820
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
821 const char *
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
822 cyg_flash_errmsg(const int err)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
823 {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
824 switch (err) {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
825 case CYG_FLASH_ERR_OK:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
826 return "No error - operation complete";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
827 case CYG_FLASH_ERR_ERASE_SUSPEND:
136
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
828 return "Device is in erase suspend state";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
829 case CYG_FLASH_ERR_PROGRAM_SUSPEND:
136
a9ac27ec7abc Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents: 121
diff changeset
830 return "Device is in program suspend state";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
831 case CYG_FLASH_ERR_INVALID:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
832 return "Invalid FLASH address";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
833 case CYG_FLASH_ERR_ERASE:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
834 return "Error trying to erase";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
835 case CYG_FLASH_ERR_LOCK:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
836 return "Error trying to lock/unlock";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
837 case CYG_FLASH_ERR_PROGRAM:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
838 return "Error trying to program";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
839 case CYG_FLASH_ERR_PROTOCOL:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
840 return "Generic error";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
841 case CYG_FLASH_ERR_PROTECT:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
842 return "Device/region is write-protected";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
843 case CYG_FLASH_ERR_NOT_INIT:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
844 return "FLASH sub-system not initialized";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
845 case CYG_FLASH_ERR_DRV_VERIFY:
143
6b5f480c6929 Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents: 141
diff changeset
846 return "Data verify failed after operation";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
847 case CYG_FLASH_ERR_DRV_TIMEOUT:
154
e2d866e32dac Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents: 151
diff changeset
848 return "Driver timed out waiting for device";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
849 case CYG_FLASH_ERR_DRV_WRONG_PART:
154
e2d866e32dac Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents: 151
diff changeset
850 return "Driver does not support device";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
851 case CYG_FLASH_ERR_LOW_VOLTAGE:
156
b939e9cada46 Merge from eCos master repository on 2001-03-29-21:44:39-BST
jlarmour
parents: 154
diff changeset
852 return "Device reports low voltage";
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
853 default:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
854 return "Unknown error";
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
855 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
856 }
151
25e238959bae Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents: 143
diff changeset
857
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
858 // Dummy routines to put into the device function tables, to handle
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
859 // unsupported/unnecessary functionality. For example not all devices
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
860 // support block locking.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
861 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
862 // A dummy initialization routine, for platforms where everything is
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
863 // done statically and there is no need to check device ids or
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
864 // anything similar.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
865 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
866 cyg_flash_devfn_init_nop(struct cyg_flash_dev* dev)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
867 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
868 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
869 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
870 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
871
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
872 // A dummy query routine. The implementation of this is specific to
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
873 // each device driver, so some device drivers may choose to do
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
874 // nothing.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
875 size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
876 cyg_flash_devfn_query_nop(struct cyg_flash_dev* dev, void* data, size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
877 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
878 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
879 CYG_UNUSED_PARAM(void*, data);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
880 CYG_UNUSED_PARAM(size_t, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
881 return 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
882 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
883
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
884 // Dummy lock/unlock routines
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
885 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
886 cyg_flash_devfn_lock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
887 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
888 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
889 CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
890 #if defined(CYGHWR_IO_FLASH_BLOCK_LOCKING) && (1 < CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
891 // If we've been built with locking, and there's more than one flash
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
892 // device in the system, then this is probably only being called because
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
893 // we can't tell what devices do and don't support locking, and for a _nop
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
894 // function this is the device that doesn't support locking. So we don't
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
895 // complain if we're asked to.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
896 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
897 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
898 return CYG_FLASH_ERR_DRV_WRONG_PART;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
899 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
900 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
901
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
902 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
903 cyg_flash_devfn_unlock_nop(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
904 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
905 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
906 CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
907 #if defined(CYGHWR_IO_FLASH_BLOCK_LOCKING) && (1 < CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
908 // If we've been built with locking, and there's more than one flash
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
909 // device in the system, then this is probably only being called because
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
910 // we can't tell what devices do and don't support locking, and for a _nop
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
911 // function this is the device that doesn't support locking. So we don't
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
912 // complain if we're asked to.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
913 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
914 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
915 return CYG_FLASH_ERR_DRV_WRONG_PART;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
916 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
917 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
918
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
919 // On some architectures there are problems calling the .2ram
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
920 // functions from the main ones. Specifically the compiler may issue a
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
921 // short call, even though the flash and ram are too far apart. The
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
922 // solution is to indirect via a function pointer, but the simplistic
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
923 // approach is vulnerable to compiler optimization. Hence the function
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
924 // pointer is passed through an anonymizer.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
925 void*
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
926 cyg_flash_anonymizer(void* fn)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
927 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
928 return fn;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
929 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
930
151
25e238959bae Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents: 143
diff changeset
931 // EOF io/flash/..../flash.c