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