annotate packages/io/flash/current/src/flash.c @ 2633:592d727733df

* src/flash.c (cyg_flash_init): Allow repeated calls to change the printf function for all devices. There are times you don't any output, eg you are downloading an image over the serial port.
author jlarmour
date Tue, 18 Nov 2008 01:57:58 +0000
parents a2f5434df2cb
children 74dbf4c3f2e1
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 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
227
2633
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
228 if (init) {
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
229 // In case the printf function has changed.
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
230 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
231 dev->pf = pf;
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
232 }
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
233 return CYG_FLASH_ERR_OK;
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
234 }
592d727733df * src/flash.c (cyg_flash_init): Allow repeated calls to
jlarmour
parents: 2626
diff changeset
235
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
236 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
237 dev->pf = pf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
238 LOCK_INIT(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
239
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
240 err = dev->funs->flash_init(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
241 if (err != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
242 continue;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
243 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
244 CYG_ASSERT(dev->funs, "No flash functions");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
245 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
246 CYG_ASSERT(dev->block_info, "No block infos");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
247 CYG_ASSERT(!(((cyg_flashaddr_t)dev->block_info >= dev->start) &&
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
248 ((cyg_flashaddr_t)dev->block_info < dev->end)),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
249 "Block info is in the flash");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
250 CYG_ASSERT(dev->funs->flash_erase_block, "No erase function");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
251 CYG_ASSERT(dev->funs->flash_program, "No program function");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
252 #ifdef CYGDBG_USE_ASSERTS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
253 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
254 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
255 cyg_flashaddr_t addr = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
256 for (i = 0; i < dev->num_block_infos; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
257 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
258 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
259 CYG_ASSERT(dev->end == addr-1, "Invalid end address");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
260 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
261 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
262 dev->init = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
263 }
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 #if (1 == CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
266 // 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
267 // accessing a non-existent cyg_flash_dev structure.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
268 if (&(cyg_flashdevtab[0]) == &cyg_flashdevtab_end) {
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 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
272 // 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
273 // are no overlaps in the address space.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
274 if (! flash_sort_and_check() ) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
275 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
276 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
277 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
278
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
279 // 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
280 // consistent.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
281 init = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
282 return CYG_FLASH_ERR_OK;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
283 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
284
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
285 // Is the address within one of the flash drivers?
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
286 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
287 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
288 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
289 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
290 (void) find_dev(address, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
291 return stat;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
292 }
157
b65ec671dd4c Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents: 156
diff changeset
293
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
294 // Return information about the Nth driver
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
295 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
296 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
297 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
298 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
299
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
300 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
301
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
302 #if (1 == CYGHWR_IO_FLASH_DEVICE)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
303 if ((0 == Nth) && cyg_flashdevtab[0].init) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
304 dev = &(cyg_flashdevtab[0]);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
305 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
306 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
307 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
308 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
309 // Only initialized devices are on the list.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
310 for (dev = flash_head; dev && Nth; dev=dev->next, Nth--)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
311 ;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
312 if (!dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
313 return CYG_FLASH_ERR_INVALID;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
314 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
315 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
316 info->start = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
317 info->end = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
318 info->num_block_infos = dev->num_block_infos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
319 info->block_info = dev->block_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
320 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
321 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
322
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
323 // Return information about the flash at the given address
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
324 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
325 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
326 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
327 struct cyg_flash_dev *dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
328 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
329
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
330 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
331 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
332 info->start = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
333 info->end = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
334 info->num_block_infos = dev->num_block_infos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
335 info->block_info = dev->block_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
336 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
337 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
338 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
339
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
340 #ifdef CYGPKG_KERNEL
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
341 // Lock the mutex's for a range of addresses
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
342 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
343 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
344 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
345 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
346 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
347
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
348 dev = find_dev(from, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
349 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
350 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
351 if (len > (dev->end + 1 - from)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
352 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
353 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
354 // Something went wrong, unlock what we just locked
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
355 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
356 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
357 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
358 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
359 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
360 }
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
361
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
362 // Unlock the mutex's for a range of addresses
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
363 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
364 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
365 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
366 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
367 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
368
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
369 dev = find_dev(from, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
370 if (dev) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
371 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
372 if (len > (dev->end + 1 - from)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
373 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
374 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
375 // 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
376 // 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
377 // 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
378 // cyg_flash_mutex_lock();
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
379 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
380 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
381 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
382 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
383 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
384 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
385 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
386
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
387 // 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
388 static size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
389 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
390 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
391 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
392 size_t offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
393
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
394 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
395
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
396 offset = addr - dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
397 for (i=0; i < dev->num_block_infos; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
398 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
399 return dev->block_info[i].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
400 offset = offset -
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
401 (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
402 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
403 CYG_FAIL("Programming error");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
404 return 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
405 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
406
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
407 // 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
408 __externC size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
409 cyg_flash_block_size(const cyg_flashaddr_t flash_base)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
410 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
411 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
412 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
413
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
414 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
415 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
416 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
417 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
418
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
419 // 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
420 // 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
421 // offsets.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
422 static inline cyg_flashaddr_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
423 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
424 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
425 size_t block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
426 cyg_flashaddr_t offset;
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 block_size = flash_block_size(dev, addr);
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 offset = addr - dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
431 offset = (offset / block_size) * block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
432 return offset + dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
433 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
434
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
435
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
436 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
437 cyg_flash_erase(cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
438 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
439 cyg_flashaddr_t *err_address)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
440 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
441 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
442 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
443 size_t erase_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
444 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
445 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
446
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
447 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
448 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
449
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
450 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
451
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
452 LOCK(dev);
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
453
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
454 // 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
455 // 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
456 // recursive call later on.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
457 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
458 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
459 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
460 end_addr = flash_base + len - 1;
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 // 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
463 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
464 erase_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
465
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
466 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
467
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
468 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
469 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
470 while (erase_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
471 int i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
472 unsigned char *dp;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
473 bool erased = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
474 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
475
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
476 // Pad to the block boundary, if necessary
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
477 if (erase_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
478 erase_count = block_size;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
479 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
480
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
481 // 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
482 // cannot be read directly.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
483 if (!dev->funs->flash_read) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
484 erased = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
485 dp = (unsigned char *)block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
486 for (i = 0; i < block_size; i++) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
487 if (*dp++ != (unsigned char)0xFF) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
488 erased = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
489 break;
174
38892b97b685 Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents: 163
diff changeset
490 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
491 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
492 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
493 if (!erased) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
494 stat = dev->funs->flash_erase_block(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
495 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
496 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
497 if (err_address)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
498 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
499 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
500 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
501 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
502 erase_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
503 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
504 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
505 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
506 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
507 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
508 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
509 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
510 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
511 }
174
38892b97b685 Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents: 163
diff changeset
512
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
513 // 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
514 // may touch successive devices. This can be handled by recursion.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
515 // The stack overheads should be minimal because the number of
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
516 // devices will be small.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
517 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
518 return cyg_flash_erase(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
519 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
520 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
521 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
522 return CYG_FLASH_ERR_OK;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
523 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
524
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
525 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
526 cyg_flash_program(cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
527 const void *ram_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
528 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
529 cyg_flashaddr_t *err_address)
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
530 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
531 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
532 cyg_flashaddr_t addr, end_addr, block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
533 const unsigned char * ram = ram_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
534 size_t write_count, offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
535 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
536 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
537
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
538 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
539 if (!dev) return stat;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
540
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
541 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
542
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
543 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
544 addr = flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
545 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
546 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
547 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
548 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
549 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
550 write_count = (end_addr + 1) - flash_base;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
551
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
552 // 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
553 // adjustment here rather than inside the loop.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
554 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
555 if (addr == block) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
556 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
557 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
558 offset = addr - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
559 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
560
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
561 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
562
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
563 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
564 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
565 while (write_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
566 size_t block_size = flash_block_size(dev, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
567 size_t this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
568 if (write_count > (block_size - offset)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
569 this_write = block_size - offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
570 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
571 this_write = write_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
572 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
573 // Only the first block may need the offset.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
574 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
575
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
576 stat = dev->funs->flash_program(dev, addr, ram, this_write);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
577 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
578 if (CYG_FLASH_ERR_OK == stat) // Claims to be OK
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
579 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
580 stat = CYG_FLASH_ERR_DRV_VERIFY;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
581 CHATTER(dev, "V");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
582 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
583 #endif
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
584 if (CYG_FLASH_ERR_OK != stat) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
585 if (err_address)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
586 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
587 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
588 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
589 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
590 write_count -= this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
591 addr += this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
592 ram += this_write;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
593 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
594 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
595 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
596 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
597 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
598 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
599 return (stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
600 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
601 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
602 return cyg_flash_program(dev->end+1, ram,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
603 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
604 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
605 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
606 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
607 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
608
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
609 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
610 cyg_flash_read(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
611 void *ram_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
612 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
613 cyg_flashaddr_t *err_address)
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 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
616 cyg_flashaddr_t addr, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
617 unsigned char * ram = (unsigned char *)ram_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
618 size_t read_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
619 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
620
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
621 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
622 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
623
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
624 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
625 addr = flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
626 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
627 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
628 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
629 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
630 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
631 read_count = (end_addr + 1) - flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
632
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
633 // 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
634
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
635 // 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
636 // still happens with the mutex locked to protect against concurrent
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
637 // programs/erases.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
638 if (! dev->funs->flash_read) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
639 memcpy(ram, (void*)addr, read_count);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
640 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
641 #ifndef CYGHWR_IO_FLASH_INDIRECT_READS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
642 CYG_FAIL("read function supplied but indirect reads not enabled");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
643 stat = CYG_FLASH_ERR_PROTOCOL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
644 if (err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
645 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
646 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
647 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
648 // We have to indirect through the device driver.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
649 // 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
650 // adjustment here rather than inside the loop.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
651 size_t offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
652 cyg_flashaddr_t block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
653 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
654 if (addr == block) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
655 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
656 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
657 offset = addr - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
658 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
659 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
660 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
661 while (read_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
662 size_t block_size = flash_block_size(dev, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
663 size_t this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
664 if (read_count > (block_size - offset)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
665 this_read = block_size - offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
666 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
667 this_read = read_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
668 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
669 // Only the first block may need the offset
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
670 offset = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
671
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
672 stat = dev->funs->flash_read(dev, addr, ram, this_read);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
673 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
674 *err_address = addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
675 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
676 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
677 // CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
678 read_count -= this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
679 addr += this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
680 ram += this_read;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
681 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
682 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
683 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
684 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
685 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
686 // CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
687 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
688 if (stat != CYG_FLASH_ERR_OK) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
689 return (stat);
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
690 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
691 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
692 return cyg_flash_read(dev->end+1, ram,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
693 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
694 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
695 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
696 return CYG_FLASH_ERR_OK;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
697 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents: 210
diff changeset
698
177
4c750ce71ae3 Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents: 174
diff changeset
699 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
700 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
701 cyg_flash_lock(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
702 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
703 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
704 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
705 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
706 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
707 size_t lock_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
708 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
709 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
710
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
711 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
712 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
713 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
714
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
715 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
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 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
718 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
719 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
720 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
721 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
722 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
723 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
724 lock_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
725
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
726 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
727
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
728 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
729 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
730 while (lock_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
731 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
732 if (lock_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
733 lock_count = block_size;
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 stat = dev->funs->flash_block_lock(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
736
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
737 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
738 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
739 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
740 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
741 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
742 lock_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
743 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
744 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
745 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
746 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
747 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
748 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
749 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
750 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
751 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 195
diff changeset
752
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
753 // Recurse if necessary for the next device
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
754 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
755 return cyg_flash_lock(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
756 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
757 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
758 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
759
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
760 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
761 }
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
762
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
763 __externC int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
764 cyg_flash_unlock(const cyg_flashaddr_t flash_base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
765 size_t len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
766 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
767 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
768 cyg_flashaddr_t block, end_addr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
769 struct cyg_flash_dev * dev;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
770 size_t unlock_count;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
771 int stat = CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
772 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
773
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
774 dev = find_dev(flash_base, &stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
775 if (!dev) return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
776 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
777
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
778 CHECK_SOFT_WRITE_PROTECT(flash_base, len);
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 LOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
781 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
782 end_addr = dev->end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
783 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
784 end_addr = flash_base + len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
785 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
786 block = flash_block_begin(flash_base, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
787 unlock_count = (end_addr + 1) - block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
788
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
789 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
790
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
791 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
792 FLASH_Enable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
793 while (unlock_count > 0) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
794 size_t block_size = flash_block_size(dev, block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
795 if (unlock_count < block_size) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
796 unlock_count = block_size;
119
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
797 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
798 stat = dev->funs->flash_block_unlock(dev,block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
799
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
800 if (CYG_FLASH_ERR_OK != stat && err_address) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
801 *err_address = block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
802 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
803 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
804 block += block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
805 unlock_count -= block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
806
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
807 CHATTER(dev, ".");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
808 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
809 FLASH_Disable(flash_base, end_addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
810 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
811 CHATTER(dev, "\n");
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
812 UNLOCK(dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
813 if (stat != CYG_FLASH_ERR_OK) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
814 return stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
815 }
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 // Recurse if necessary for the next device
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
818 if (len > (dev->end + 1 - flash_base)) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
819 return cyg_flash_lock(dev->end+1,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
820 len - (dev->end + 1 - flash_base),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
821 err_address);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
822 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
823 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
824 }
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
825 #endif
77cec8369160 Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents: 117
diff changeset
826
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
827 const char *
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
828 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
829 {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
830 switch (err) {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
831 case CYG_FLASH_ERR_OK:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
832 return "No error - operation complete";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
833 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
834 return "Device is in erase suspend state";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
835 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
836 return "Device is in program suspend state";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
837 case CYG_FLASH_ERR_INVALID:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
838 return "Invalid FLASH address";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
839 case CYG_FLASH_ERR_ERASE:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
840 return "Error trying to erase";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
841 case CYG_FLASH_ERR_LOCK:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
842 return "Error trying to lock/unlock";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
843 case CYG_FLASH_ERR_PROGRAM:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
844 return "Error trying to program";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
845 case CYG_FLASH_ERR_PROTOCOL:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
846 return "Generic error";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
847 case CYG_FLASH_ERR_PROTECT:
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
848 return "Device/region is write-protected";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
849 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
850 return "FLASH sub-system not initialized";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
851 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
852 return "Data verify failed after operation";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
853 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
854 return "Driver timed out waiting for device";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
855 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
856 return "Driver does not support device";
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
857 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
858 return "Device reports low voltage";
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
859 default:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
860 return "Unknown error";
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
861 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
862 }
151
25e238959bae Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents: 143
diff changeset
863
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
864 // 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
865 // unsupported/unnecessary functionality. For example not all devices
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
866 // support block locking.
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 // A dummy initialization routine, for platforms where everything is
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
869 // 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
870 // anything similar.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
871 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
872 cyg_flash_devfn_init_nop(struct cyg_flash_dev* dev)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
873 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
874 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
875 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
876 }
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 // 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
879 // 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
880 // nothing.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
881 size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
882 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
883 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
884 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
885 CYG_UNUSED_PARAM(void*, data);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
886 CYG_UNUSED_PARAM(size_t, len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
887 return 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
888 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
889
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
890 // Dummy lock/unlock routines
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
891 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
892 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
893 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
894 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
895 CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
896 #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
897 // 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
898 // 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
899 // 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
900 // 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
901 // complain if we're asked to.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
902 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
903 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
904 return CYG_FLASH_ERR_DRV_WRONG_PART;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
905 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
906 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
907
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
908 int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
909 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
910 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
911 CYG_UNUSED_PARAM(struct cyg_flash_dev*, dev);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
912 CYG_UNUSED_PARAM(cyg_flashaddr_t, addr);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
913 #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
914 // 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
915 // 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
916 // 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
917 // 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
918 // complain if we're asked to.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
919 return CYG_FLASH_ERR_OK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
920 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
921 return CYG_FLASH_ERR_DRV_WRONG_PART;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
922 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
923 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
924
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
925 // On some architectures there are problems calling the .2ram
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
926 // 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
927 // 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
928 // 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
929 // approach is vulnerable to compiler optimization. Hence the function
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
930 // pointer is passed through an anonymizer.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
931 void*
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
932 cyg_flash_anonymizer(void* fn)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
933 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
934 return fn;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
935 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2142
diff changeset
936
151
25e238959bae Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents: 143
diff changeset
937 // EOF io/flash/..../flash.c