annotate packages/io/flash/current/src/legacy_dev.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents a2f5434df2cb
children 422d0a343b4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
1 //==========================================================================
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
2 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
3 // legacy_dev.c
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
4 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
5 // Interface to the legacy device drivers
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
6 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
11 // Copyright (C) 2004, 2006 Free Software Foundation, Inc.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
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: 2626
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: 2626
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: 2626
diff changeset
16 // version.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
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: 2626
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: 2626
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: 2626
diff changeset
21 // for more details.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
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: 2626
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: 2626
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
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: 2626
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: 2626
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: 2626
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: 2626
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: 2626
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: 2626
diff changeset
33 // General Public License v2.
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
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: 2626
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: 2626
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
39 //==========================================================================
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
41 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
42 // Author(s): Andrew Lunn
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
43 // Contributors: Andrew Lunn
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
44 // Date: 2004-07-02
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
45 // Purpose:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
46 // Description: Implement an interface to the legacy device drivers
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
47 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
48 //####DESCRIPTIONEND####
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
49 //
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
50 //==========================================================================
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
51
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
52 #include <pkgconf/system.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
53 #include <pkgconf/io_flash.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
54
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
55 #include <cyg/hal/hal_arch.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
56 #include <cyg/hal/hal_intr.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
57 #include <cyg/hal/hal_cache.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
58 #include <string.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
59
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
60 #include <cyg/io/flash.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
61 #include <cyg/io/flash_dev.h>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
62 #include "flash_legacy.h"
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
63
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
64 // When this flag is set, do not actually jump to the relocated code.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
65 // This can be used for running the function in place (RAM startup only),
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
66 // allowing calls to diag_printf() and similar.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
67 #undef RAM_FLASH_DEV_DEBUG
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
68 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
69 # warning "Can only enable the flash debugging when configured for RAM startup"
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
70 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
71
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
72 struct flash_info flash_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
73
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
74 // These are the functions in the HW specific driver we need to call.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
75 typedef void code_fun(void*);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
76
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
77 externC code_fun flash_query;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
78 externC code_fun flash_erase_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
79 externC code_fun flash_program_buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
80 externC code_fun flash_read_buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
81 externC code_fun flash_lock_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
82 externC code_fun flash_unlock_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
83
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
84 // Initialize the device
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
85 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
86 legacy_flash_init (struct cyg_flash_dev *dev)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
87 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
88 int err;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
89 static cyg_flash_block_info_t block_info[1];
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
90
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
91 flash_info.pf = dev->pf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
92
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
93 err=flash_hwr_init();
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
94
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
95 if (!err) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
96 dev->start = (cyg_flashaddr_t)flash_info.start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
97 dev->end = dev->start + flash_info.block_size * flash_info.blocks - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
98 dev->num_block_infos = 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
99 dev->block_info = block_info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
100 block_info[0].block_size = flash_info.block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
101 block_info[0].blocks = flash_info.blocks;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
102 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
103 return err;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
104 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
105
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
106 static size_t
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
107 legacy_flash_query (struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
108 void * data,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
109 size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
110 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
111 typedef void code_fun(void*);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
112 code_fun *_flash_query;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
113
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
114 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
115
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
116 (*_flash_query)(data);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
117
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
118 return len;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
119 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
120
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
121 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
122 legacy_flash_erase_block (struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
123 cyg_flashaddr_t block_base)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
124 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
125 typedef int code_fun(cyg_flashaddr_t, unsigned int);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
126 code_fun *_flash_erase_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
127 size_t block_size = dev->block_info[0].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
128 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
129
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
130 _flash_erase_block = (code_fun*) cyg_flash_anonymizer(&flash_erase_block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
131
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
132 stat = (*_flash_erase_block)(block_base, block_size);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
133 return flash_hwr_map_error(stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
134 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
135
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
136 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
137 legacy_flash_program(struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
138 cyg_flashaddr_t base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
139 const void* data, size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
140 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
141 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
142 code_fun *_flash_program_buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
143 size_t block_size = dev->block_info[0].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
144 size_t block_mask = ~(block_size -1);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
145 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
146
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
147 _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
148
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
149 stat = (*_flash_program_buf)(base, data, len, block_mask, flash_info.buffer_size);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
150 return flash_hwr_map_error(stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
151 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
152
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
153 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
154 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
155 legacy_flash_read (struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
156 const cyg_flashaddr_t base,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
157 void* data, size_t len)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
158 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
159 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
160 code_fun *_flash_read_buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
161 size_t block_size = dev->block_info[0].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
162 size_t block_mask = ~(block_size -1);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
163 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
164 _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
165
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
166 stat = (*_flash_read_buf)(base, data, len, block_mask, block_size);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
167 return flash_hwr_map_error(stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
168 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
169
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
170 # define LEGACY_FLASH_READ legacy_flash_read
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
171 #else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
172 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
173 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
174
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
175
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
176 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
177 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
178 legacy_flash_block_lock (struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
179 const cyg_flashaddr_t block_base)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
180 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
181 typedef int code_fun(cyg_flashaddr_t);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
182 code_fun *_flash_lock_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
183 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
184 _flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
185
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
186 stat = (*_flash_lock_block)(block_base);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
187 return flash_hwr_map_error(stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
188 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
189
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
190 static int
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
191 legacy_flash_block_unlock (struct cyg_flash_dev *dev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
192 const cyg_flashaddr_t block_base)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
193 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
194 typedef int code_fun(cyg_flashaddr_t, int, int);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
195 code_fun *_flash_unlock_block;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
196 size_t block_size = dev->block_info[0].block_size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
197 cyg_uint32 blocks = dev->block_info[0].blocks;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
198 int stat;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
199 _flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
200
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
201 stat = (*_flash_unlock_block)(block_base, block_size, blocks);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
202 return flash_hwr_map_error(stat);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
203 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
204 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
205
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
206 void
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
207 flash_dev_query(void* data)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
208 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
209 typedef void code_fun(void*);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
210 code_fun *_flash_query;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
211 HAL_FLASH_CACHES_STATE(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
212
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
213 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
214
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
215 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
216 (*_flash_query)(data);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
217 HAL_FLASH_CACHES_ON(d_cache, i_cache);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
218 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
219
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
220 static const CYG_FLASH_FUNS(cyg_legacy_funs,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
221 legacy_flash_init,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
222 legacy_flash_query,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
223 legacy_flash_erase_block,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
224 legacy_flash_program,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
225 LEGACY_FLASH_READ,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
226 legacy_flash_block_lock,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
227 legacy_flash_block_unlock
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
228 );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
229
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
230 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
231 &cyg_legacy_funs,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
232 0, // Flags
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
233 0, // Start address, filled in by init
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
234 0, // End address, filled in by init
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
235 0, // Number of block infos, filled in by init
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
236 NULL, // Block infos, again filled in by init
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
237 NULL // Driver private data, none needed
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
238 );