Mercurial > flash_v2
annotate packages/io/flash/current/src/flash.c @ 1762:9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
and use these in the V2 drivers where appropriate
| author | bartv |
|---|---|
| date | Mon, 29 Nov 2004 00:43:48 +0000 |
| parents | 9abe5ac74a1a |
| children | 42c8ea63b78d |
| 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 | 58 #ifdef CYGPKG_KERNEL |
| 59 #include <cyg/kernel/kapi.h> | |
| 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 | 64 #include <cyg/hal/hal_tables.h> |
| 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 | 73 // This can be used for running the function in place (RAM startup |
| 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 | 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 | 111 static bool init = false; |
| 112 | |
| 113 // This array contains entries for all flash devices that are | |
| 114 // installed in the system. | |
| 115 __externC struct cyg_flash_dev cyg_flashdevtab[]; | |
| 116 CYG_HAL_TABLE_BEGIN(cyg_flashdevtab, cyg_flashdev); | |
| 117 | |
| 118 // end of the flashdev table | |
| 119 __externC struct cyg_flash_dev cyg_flashdevtab_end; | |
| 120 CYG_HAL_TABLE_END(cyg_flashdevtab_end, cyg_flashdev); | |
| 1400 | 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 | 154 bool moved; |
| 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 | 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 | 175 do { |
| 176 moved=false; | |
| 177 for (dev=flash_head, previous_next=&flash_head; | |
| 178 dev->next; | |
| 179 previous_next = &dev->next, dev=dev->next ){ | |
| 180 if (dev->start > dev->next->start) { | |
| 181 *previous_next=dev->next; | |
| 182 dev->next = (*previous_next)->next; | |
| 183 (*previous_next)->next = dev; | |
| 184 moved=true; | |
| 185 break; | |
| 186 } | |
| 187 } | |
| 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 | 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 | 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 | 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 | 219 // Initialise all registered device. Any device that fails to |
| 220 // initialise we leave dev->init as false. Then sort the devices into | |
| 221 // ascending order of address and put them into a linked list. Lastly | |
| 222 // check if we have any overlap of the addresses. | |
| 223 __externC int | |
| 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 | 226 int err; |
| 227 struct cyg_flash_dev * dev; | |
| 228 | |
| 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 | 232 |
| 233 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) { | |
| 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 | 236 |
| 237 err = dev->funs->flash_init(dev); | |
| 238 if (err != CYG_FLASH_ERR_OK) { | |
| 239 continue; | |
| 240 } | |
| 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 | 243 CYG_ASSERT(dev->block_info, "No block infos"); |
| 244 CYG_ASSERT(!(((cyg_flashaddr_t)dev->block_info >= dev->start) && | |
| 245 ((cyg_flashaddr_t)dev->block_info < dev->end)), | |
| 246 "Block info is in the flash"); | |
| 247 CYG_ASSERT(dev->funs->flash_erase_block, "No erase function"); | |
| 248 CYG_ASSERT(dev->funs->flash_program, "No program function"); | |
| 249 CYG_ASSERT(dev->funs->flash_hwr_map_error, "No hwr map error function"); | |
|
1729
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
250 #ifdef CYGDBG_USE_ASSERTS |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
251 { |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
252 int i; |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
253 cyg_flashaddr_t addr = dev->start; |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
254 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
|
255 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
|
256 } |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
257 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
|
258 } |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
259 #endif |
| 1706 | 260 dev->init = true; |
| 261 } | |
| 262 | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
263 #if (1 == CYGHWR_IO_FLASH_DEVICE) |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
264 // 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
|
265 // 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
|
266 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
|
267 return CYG_FLASH_ERR_INVALID; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
268 } |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
269 #else |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
270 // 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
|
271 // 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
|
272 if (! flash_sort_and_check() ) { |
| 1706 | 273 return CYG_FLASH_ERR_INVALID; |
| 274 } | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
275 #endif |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
276 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
277 // 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
|
278 // consistent. |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
279 init = true; |
| 1706 | 280 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
|
281 } |
|
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
282 |
| 1706 | 283 // Is the address within one of the flash drivers? |
| 284 __externC int | |
| 285 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
|
286 { |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
287 int stat = CYG_FLASH_ERR_OK; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
288 (void) find_dev(address, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
289 return stat; |
|
143
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
290 } |
|
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
291 |
| 1706 | 292 // Return information about the Nth driver |
| 293 __externC int | |
| 294 cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info) | |
| 295 { | |
| 296 struct cyg_flash_dev * dev; | |
| 297 | |
| 298 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
|
299 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
300 #if (1 == CYGHWR_IO_FLASH_DEVICE) |
|
1760
9abe5ac74a1a
Correctly handle scenario where there are multiple flash devices but
bartv
parents:
1750
diff
changeset
|
301 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
|
302 dev = &(cyg_flashdevtab[0]); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
303 } else { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
304 return CYG_FLASH_ERR_INVALID; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
305 } |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
306 #else |
|
1760
9abe5ac74a1a
Correctly handle scenario where there are multiple flash devices but
bartv
parents:
1750
diff
changeset
|
307 // Only initialized devices are on the list. |
| 1706 | 308 for (dev = flash_head; dev && Nth; dev=dev->next, Nth--) |
| 309 ; | |
|
1760
9abe5ac74a1a
Correctly handle scenario where there are multiple flash devices but
bartv
parents:
1750
diff
changeset
|
310 if (!dev) { |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
311 return CYG_FLASH_ERR_INVALID; |
| 1706 | 312 } |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
313 #endif |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
314 info->start = dev->start; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
315 info->end = dev->end; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
316 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
|
317 info->block_info = dev->block_info; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
318 return CYG_FLASH_ERR_OK; |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
319 } |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
320 |
| 1706 | 321 // Return information about the flash at the given address |
| 322 __externC int | |
| 1749 | 323 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
|
324 { |
| 1706 | 325 struct cyg_flash_dev *dev; |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
326 int stat = CYG_FLASH_ERR_OK; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
327 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
328 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
329 if (dev) { |
| 1706 | 330 info->start = dev->start; |
| 331 info->end = dev->end; | |
| 332 info->num_block_infos = dev->num_block_infos; | |
| 333 info->block_info = dev->block_info; | |
| 334 } | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
335 return stat; |
| 1706 | 336 } |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
337 |
| 1706 | 338 #ifdef CYGPKG_KERNEL |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
339 // Lock the mutex's for a range of addresses |
| 1706 | 340 __externC int |
| 1749 | 341 cyg_flash_mutex_lock(const cyg_flashaddr_t from, size_t len) |
| 1706 | 342 { |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
343 struct cyg_flash_dev * dev; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
344 int stat = CYG_FLASH_ERR_OK; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
345 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
346 dev = find_dev(from, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
347 if (dev) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
348 LOCK(dev); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
349 if (len > (dev->end + 1 - from)) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
350 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
|
351 if (CYG_FLASH_ERR_OK != stat) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
352 // 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
|
353 UNLOCK(dev); |
| 1706 | 354 } |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
355 } |
| 1706 | 356 } |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
357 return stat; |
| 1706 | 358 } |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
359 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
360 // Unlock the mutex's for a range of addresses |
| 1706 | 361 __externC int |
| 1749 | 362 cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len) |
| 1706 | 363 { |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
364 struct cyg_flash_dev * dev; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
365 int stat = CYG_FLASH_ERR_OK; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
366 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
367 dev = find_dev(from, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
368 if (dev) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
369 UNLOCK(dev); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
370 if (len > (dev->end + 1 - from)) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
371 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
|
372 if (CYG_FLASH_ERR_OK != stat) { |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
373 // 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
|
374 // 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
|
375 // 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
|
376 // cyg_flash_mutex_lock(); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
377 LOCK(dev); |
| 1706 | 378 } |
| 379 } | |
| 380 } | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
381 return stat; |
| 1706 | 382 } |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
383 #endif |
|
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
384 |
| 1706 | 385 // Return the size of the block which is at the given address |
| 386 static size_t | |
| 387 flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr) | |
| 388 { | |
| 389 int i; | |
| 390 size_t offset; | |
| 391 | |
| 392 CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device"); | |
| 393 | |
| 394 offset = addr - dev->start; | |
| 395 for (i=0; i < dev->num_block_infos; i++) { | |
| 396 if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size)) | |
| 397 return dev->block_info[i].block_size; | |
| 398 offset = offset - | |
| 399 (dev->block_info[i].blocks * dev->block_info[i].block_size); | |
| 400 } | |
| 401 CYG_FAIL("Programming error"); | |
| 402 return 0; | |
| 403 } | |
| 404 | |
| 405 // Return the size of the block which is at the given address | |
| 406 __externC size_t | |
| 407 cyg_flash_block_size(const cyg_flashaddr_t flash_base) | |
| 408 { | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
409 struct cyg_flash_dev * dev; |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
410 int stat; |
| 1706 | 411 |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
412 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
413 if (!dev) return stat; |
| 1706 | 414 return flash_block_size(dev, flash_base); |
| 415 } | |
| 416 | |
|
1723
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
417 // 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
|
418 // 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
|
419 // offsets. |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
420 static inline cyg_flashaddr_t |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
421 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
|
422 { |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
423 size_t block_size; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
424 cyg_flashaddr_t offset; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
425 |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
426 block_size = flash_block_size(dev, addr); |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
427 |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
428 offset = addr - dev->start; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
429 offset = (offset / block_size) * block_size; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
430 return offset + dev->start; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
431 } |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
432 |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
433 |
| 1706 | 434 __externC int |
| 1749 | 435 cyg_flash_erase(cyg_flashaddr_t flash_base, |
| 436 size_t len, | |
| 1706 | 437 cyg_flashaddr_t *err_address) |
| 438 { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
439 cyg_flashaddr_t block, end_addr; |
| 1706 | 440 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
441 size_t erase_count; |
| 1706 | 442 int stat = CYG_FLASH_ERR_OK; |
| 443 int d_cache, i_cache; | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
444 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
445 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
446 if (!dev) return stat; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
447 |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
448 CHECK_SOFT_WRITE_PROTECT(flash_base, len); |
| 1706 | 449 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
450 LOCK(dev); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
451 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
452 // 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
|
453 // 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
|
454 // recursive call later on. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
455 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
456 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
457 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
458 end_addr = flash_base + len - 1; |
| 1706 | 459 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
460 // 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
|
461 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
462 erase_count = (end_addr + 1) - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
463 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
464 CHATTER(dev, "... Erase from %p-%p: ", (void*)block, (void*)end_addr); |
| 1706 | 465 |
| 466 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
|
467 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
468 while (erase_count > 0) { |
| 1706 | 469 int i; |
| 470 unsigned char *dp; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
471 bool erased = false; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
472 size_t block_size = flash_block_size(dev, block); |
| 1706 | 473 |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
474 // Pad to the block boundary, if necessary |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
475 if (erase_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
476 erase_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
477 } |
|
1723
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
478 |
| 1706 | 479 // If there is a read function it probably means the flash |
| 480 // cannot be read directly. | |
| 481 if (!dev->funs->flash_read) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
482 erased = true; |
| 1706 | 483 dp = (unsigned char *)block; |
| 484 for (i = 0; i < block_size; i++) { | |
| 485 if (*dp++ != (unsigned char)0xFF) { | |
| 486 erased = false; | |
| 487 break; | |
| 488 } | |
| 489 } | |
| 490 } | |
| 491 if (!erased) { | |
| 492 stat = dev->funs->flash_erase_block(dev,block); | |
| 493 stat = dev->funs->flash_hwr_map_error(dev,stat); | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
494 } |
| 1706 | 495 if (CYG_FLASH_ERR_OK != stat && err_address) { |
| 496 *err_address = block; | |
| 497 break; | |
| 498 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
499 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
500 erase_count -= block_size; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
501 CHATTER(dev, "."); |
| 1706 | 502 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
503 FLASH_Disable(flash_base, end_addr); |
| 1706 | 504 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
505 CHATTER(dev, "\n"); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
506 UNLOCK(dev); |
| 1706 | 507 if (stat != CYG_FLASH_ERR_OK) { |
| 508 return stat; | |
| 509 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
510 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
511 // 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
|
512 // 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
|
513 // 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
|
514 // devices will be small. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
515 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 516 return cyg_flash_erase(dev->end+1, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
517 len - (dev->end + 1 - flash_base), |
| 1706 | 518 err_address); |
| 519 } | |
| 520 return CYG_FLASH_ERR_OK; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
521 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
522 |
| 1706 | 523 __externC int |
| 1749 | 524 cyg_flash_program(cyg_flashaddr_t flash_base, |
| 525 const void *ram_base, | |
| 526 size_t len, | |
| 1706 | 527 cyg_flashaddr_t *err_address) |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
528 { |
| 1706 | 529 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
530 cyg_flashaddr_t addr, end_addr, block; |
| 1749 | 531 const unsigned char * ram = ram_base; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
532 size_t write_count, offset; |
| 1706 | 533 int stat = CYG_FLASH_ERR_OK; |
| 534 int d_cache, i_cache; | |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
535 |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
536 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
537 if (!dev) return stat; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
538 |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
539 CHECK_SOFT_WRITE_PROTECT(flash_base, len); |
| 1706 | 540 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
541 LOCK(dev); |
| 1706 | 542 addr = flash_base; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
543 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 544 end_addr = dev->end; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
545 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
546 end_addr = flash_base + len - 1; |
| 1706 | 547 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
548 write_count = (end_addr + 1) - flash_base; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
549 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
550 // 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
|
551 // adjustment here rather than inside the loop. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
552 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
553 if (addr == block) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
554 offset = 0; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
555 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
556 offset = addr - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
557 } |
| 1706 | 558 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
559 CHATTER(dev, "... Program from %p-%p to %p: ", ram_base, ((CYG_ADDRESS)ram_base)+write_count, addr); |
| 1706 | 560 |
| 561 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
|
562 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
563 while (write_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
564 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
|
565 size_t this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
566 if (write_count > (block_size - offset)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
567 this_write = block_size - offset; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
568 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
569 this_write = write_count; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
570 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
571 // Only the first block may need the offset. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
572 offset = 0; |
| 1706 | 573 |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
574 stat = dev->funs->flash_program(dev, addr, ram, this_write); |
| 1706 | 575 stat = dev->funs->flash_hwr_map_error(dev,stat); |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
576 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM |
| 1706 | 577 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
|
578 if (!dev->funs->flash_read && memcmp((void *)addr, ram, this_write) != 0) { |
| 1706 | 579 stat = CYG_FLASH_ERR_DRV_VERIFY; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
580 CHATTER(dev, "V"); |
| 1706 | 581 } |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
582 #endif |
| 1706 | 583 if (CYG_FLASH_ERR_OK != stat && err_address) { |
| 584 *err_address = addr; | |
| 585 break; | |
| 586 } | |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
587 CHATTER(dev, "."); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
588 write_count -= this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
589 addr += this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
590 ram += this_write; |
| 1706 | 591 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
592 FLASH_Disable(flash_base, end_addr); |
| 1706 | 593 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
594 CHATTER(dev, "\n"); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
595 UNLOCK(dev); |
| 1706 | 596 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
|
597 return (stat); |
| 1706 | 598 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
599 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 600 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
|
601 len - (dev->end + 1 - flash_base), |
| 1706 | 602 err_address); |
| 603 } | |
| 604 return CYG_FLASH_ERR_OK; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
605 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
606 |
| 1706 | 607 __externC int |
| 1749 | 608 cyg_flash_read(const cyg_flashaddr_t flash_base, |
| 609 void *ram_base, | |
| 610 size_t len, | |
| 1706 | 611 cyg_flashaddr_t *err_address) |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
612 { |
| 1706 | 613 struct cyg_flash_dev * dev; |
|
1742
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
614 cyg_flashaddr_t addr, end_addr; |
| 1706 | 615 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
|
616 size_t read_count; |
| 1706 | 617 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
|
618 |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
619 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
620 if (!dev) return stat; |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
621 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
622 LOCK(dev); |
| 1706 | 623 addr = flash_base; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
624 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
625 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
626 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
627 end_addr = flash_base + len - 1; |
| 1706 | 628 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
629 read_count = (end_addr + 1) - flash_base; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
630 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
631 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
|
632 |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
633 // 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
|
634 // 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
|
635 // programs/erases. |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
636 if (! dev->funs->flash_read) { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
637 memcpy(ram, (void*)addr, read_count); |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
638 } else { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
639 #ifndef CYGHWR_IO_FLASH_INDIRECT_READS |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
640 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
|
641 stat = CYG_FLASH_ERR_PROTOCOL; |
| 1744 | 642 if (err_address) { |
| 643 *err_address = addr; | |
| 644 } | |
|
1742
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
645 #else |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
646 // 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
|
647 // 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
|
648 // 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
|
649 int d_cache, i_cache; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
650 size_t offset; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
651 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
|
652 if (addr == block) { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
653 offset = 0; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
654 } else { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
655 offset = addr - block; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
656 } |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
657 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
|
658 FLASH_Enable(flash_base, end_addr); |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
659 while (read_count > 0) { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
660 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
|
661 size_t this_read; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
662 if (read_count > (block_size - offset)) { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
663 this_read = block_size - offset; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
664 } else { |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
665 this_read = read_count; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
666 } |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
667 // 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
|
668 offset = 0; |
| 1706 | 669 |
|
1742
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
670 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
|
671 stat = dev->funs->flash_hwr_map_error(dev,stat); |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
672 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
|
673 *err_address = addr; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
674 break; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
675 } |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
676 CHATTER(dev, "."); |
|
1742
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
677 read_count -= this_read; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
678 addr += this_read; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
679 ram += this_read; |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
680 } |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
681 FLASH_Disable(flash_base, end_addr); |
|
a668b95e5f2e
Only include the support for indirect flash reads if there are devices
bartv
parents:
1741
diff
changeset
|
682 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
|
683 #endif |
| 1706 | 684 } |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
685 CHATTER(dev, "\n"); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
686 UNLOCK(dev); |
| 1706 | 687 if (stat != CYG_FLASH_ERR_OK) { |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
688 return (stat); |
| 1706 | 689 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
690 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
691 return cyg_flash_read(dev->end+1, ram, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
692 len - (dev->end + 1 - flash_base), |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
693 err_address); |
| 1706 | 694 } |
| 695 return CYG_FLASH_ERR_OK; | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
696 } |
|
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
697 |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
174
diff
changeset
|
698 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 1706 | 699 __externC int |
| 700 cyg_flash_lock(const cyg_flashaddr_t flash_base, | |
| 1749 | 701 size_t len, |
| 1706 | 702 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
|
703 { |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
704 cyg_flashaddr_t block, end_addr; |
| 1706 | 705 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
706 size_t lock_count; |
| 1706 | 707 int stat = CYG_FLASH_ERR_OK; |
| 708 int d_cache, i_cache; | |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
709 |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
710 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
711 if (!dev) return stat; |
| 1706 | 712 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
|
713 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
714 CHECK_SOFT_WRITE_PROTECT(flash_base, len); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
715 |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
716 LOCK(dev); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
717 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
718 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
719 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
720 end_addr = flash_base + len - 1; |
| 1706 | 721 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
722 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
723 lock_count = (end_addr + 1) - block; |
| 1706 | 724 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
725 CHATTER(dev, "... Locking from %p-%p: ", (void*)block, (void*)end_addr); |
| 1706 | 726 |
| 727 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
|
728 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
729 while (lock_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
730 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
|
731 if (lock_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
732 lock_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
733 } |
| 1706 | 734 stat = dev->funs->flash_block_lock(dev,block); |
| 735 stat = dev->funs->flash_hwr_map_error(dev,stat); | |
| 736 | |
| 737 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
|
738 *err_address = block; |
| 1706 | 739 break; |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
740 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
741 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
742 lock_count -= block_size; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
743 CHATTER(dev, "."); |
| 1706 | 744 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
745 FLASH_Disable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
746 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
747 CHATTER(dev, "\n"); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
748 UNLOCK(dev); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
749 if (stat != CYG_FLASH_ERR_OK) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
750 return stat; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
751 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
752 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
753 // Recurse if necessary for the next device |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
754 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
755 return cyg_flash_lock(dev->end+1, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
756 len - (dev->end + 1 - flash_base), |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
757 err_address); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
758 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
759 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
760 return CYG_FLASH_ERR_OK; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
761 } |
|
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 __externC int |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
764 cyg_flash_unlock(const cyg_flashaddr_t flash_base, |
| 1749 | 765 size_t len, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
766 cyg_flashaddr_t *err_address) |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
767 { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
768 cyg_flashaddr_t block, end_addr; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
769 struct cyg_flash_dev * dev; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
770 size_t unlock_count; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
771 int stat = CYG_FLASH_ERR_OK; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
772 int d_cache, i_cache; |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
773 |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
774 dev = find_dev(flash_base, &stat); |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1746
diff
changeset
|
775 if (!dev) return stat; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
776 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
|
777 |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
778 CHECK_SOFT_WRITE_PROTECT(flash_base, len); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
779 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
780 LOCK(dev); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
781 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
782 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
783 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
784 end_addr = flash_base + len - 1; |
|
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 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
787 unlock_count = (end_addr + 1) - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
788 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
789 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
|
790 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
791 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
792 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
793 while (unlock_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
794 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
|
795 if (unlock_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
796 unlock_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
797 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
798 stat = dev->funs->flash_block_unlock(dev,block); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
799 stat = dev->funs->flash_hwr_map_error(dev,stat); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
800 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
801 if (CYG_FLASH_ERR_OK != stat && err_address) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
802 *err_address = block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
803 break; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
804 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
805 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
806 unlock_count -= block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
807 |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
808 CHATTER(dev, "."); |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
809 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
810 FLASH_Disable(flash_base, end_addr); |
| 1706 | 811 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1743
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
812 CHATTER(dev, "\n"); |
|
0d824ba900cc
Encapsulate various bits of optional functionality inside macros, to
bartv
parents:
1742
diff
changeset
|
813 UNLOCK(dev); |
| 1706 | 814 if (stat != CYG_FLASH_ERR_OK) { |
| 815 return stat; | |
| 816 } | |
| 817 | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
818 // Recurse if necessary for the next device |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
819 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 820 return cyg_flash_lock(dev->end+1, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
821 len - (dev->end + 1 - flash_base), |
| 1706 | 822 err_address); |
| 823 } | |
| 824 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
|
825 } |
|
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
826 #endif |
|
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
827 |
| 1706 | 828 const char * |
| 829 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
|
830 { |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
831 switch (err) { |
| 1706 | 832 case CYG_FLASH_ERR_OK: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
833 return "No error - operation complete"; |
| 1706 | 834 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
|
835 return "Device is in erase suspend state"; |
| 1706 | 836 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
|
837 return "Device is in program suspend state"; |
| 1706 | 838 case CYG_FLASH_ERR_INVALID: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
839 return "Invalid FLASH address"; |
| 1706 | 840 case CYG_FLASH_ERR_ERASE: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
841 return "Error trying to erase"; |
| 1706 | 842 case CYG_FLASH_ERR_LOCK: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
843 return "Error trying to lock/unlock"; |
| 1706 | 844 case CYG_FLASH_ERR_PROGRAM: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
845 return "Error trying to program"; |
| 1706 | 846 case CYG_FLASH_ERR_PROTOCOL: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
847 return "Generic error"; |
| 1706 | 848 case CYG_FLASH_ERR_PROTECT: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
849 return "Device/region is write-protected"; |
| 1706 | 850 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
|
851 return "FLASH sub-system not initialized"; |
| 1706 | 852 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
|
853 return "Data verify failed after operation"; |
| 1706 | 854 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
|
855 return "Driver timed out waiting for device"; |
| 1706 | 856 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
|
857 return "Driver does not support device"; |
| 1706 | 858 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
|
859 return "Device reports low voltage"; |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
860 default: |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
861 return "Unknown error"; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
862 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
863 } |
|
151
25e238959bae
Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents:
143
diff
changeset
|
864 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
865 // 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
|
866 // 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
|
867 // support block locking. |
|
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 // 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
|
870 // 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
|
871 // anything similar. |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
872 int |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
873 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
|
874 { |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
875 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
|
876 return CYG_FLASH_ERR_OK; |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
877 } |
|
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 // 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
|
880 // 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
|
881 // nothing. |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
882 size_t |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
883 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
|
884 { |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
885 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
|
886 CYG_UNUSED_PARAM(void*, data); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
887 CYG_UNUSED_PARAM(size_t, len); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
888 return 0; |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
889 } |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
890 |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
891 // Dummy lock/unlock routines |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
892 int |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
893 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
|
894 { |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
895 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
|
896 CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
897 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
|
898 } |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
899 |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
900 int |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
901 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
|
902 { |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
903 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
|
904 CYG_UNUSED_PARAM(const cyg_flashaddr_t, addr); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
905 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
|
906 } |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
907 |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
908 // 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
|
909 // 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
|
910 // 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
|
911 // 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
|
912 // 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
|
913 // pointer is passed through an anonymizer. |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
914 void* |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
915 cyg_flash_anonymizer(void* fn) |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
916 { |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
917 return fn; |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
918 } |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1760
diff
changeset
|
919 |
|
151
25e238959bae
Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents:
143
diff
changeset
|
920 // EOF io/flash/..../flash.c |
