annotate packages/io/flash/current/src/flash.c @ 1763:42c8ea63b78d

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