1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// legacy_dev.c
|
4 |
|
|
//
|
5 |
|
|
// Interface to the legacy device drivers
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2004, 2006, 2009 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Andrew Lunn
|
43 |
|
|
// Contributors: Andrew Lunn
|
44 |
|
|
// Date: 2004-07-02
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description: Implement an interface to the legacy device drivers
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//==========================================================================
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/system.h>
|
53 |
|
|
#include <pkgconf/io_flash.h>
|
54 |
|
|
|
55 |
|
|
#include <cyg/hal/hal_arch.h>
|
56 |
|
|
#include <cyg/hal/hal_intr.h>
|
57 |
|
|
#include <cyg/hal/hal_cache.h>
|
58 |
|
|
#include <string.h>
|
59 |
|
|
|
60 |
|
|
#include <cyg/io/flash.h>
|
61 |
|
|
#include <cyg/io/flash_dev.h>
|
62 |
|
|
#include "flash_legacy.h"
|
63 |
|
|
|
64 |
|
|
// When this flag is set, do not actually jump to the relocated code.
|
65 |
|
|
// This can be used for running the function in place (RAM startup only),
|
66 |
|
|
// allowing calls to diag_printf() and similar.
|
67 |
|
|
#undef RAM_FLASH_DEV_DEBUG
|
68 |
|
|
#if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG)
|
69 |
|
|
# warning "Can only enable the flash debugging when configured for RAM startup"
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
struct flash_info flash_info;
|
73 |
|
|
|
74 |
|
|
// These are the functions in the HW specific driver we need to call.
|
75 |
|
|
typedef void code_fun(void*);
|
76 |
|
|
|
77 |
|
|
externC code_fun flash_query;
|
78 |
|
|
externC code_fun flash_erase_block;
|
79 |
|
|
externC code_fun flash_program_buf;
|
80 |
|
|
externC code_fun flash_read_buf;
|
81 |
|
|
externC code_fun flash_lock_block;
|
82 |
|
|
externC code_fun flash_unlock_block;
|
83 |
|
|
|
84 |
|
|
static int dummy_printf( const char *fmt, ... ) {return 0;}
|
85 |
|
|
|
86 |
|
|
// Initialize the device
|
87 |
|
|
static int
|
88 |
|
|
legacy_flash_init (struct cyg_flash_dev *dev)
|
89 |
|
|
{
|
90 |
|
|
int err;
|
91 |
|
|
static cyg_flash_block_info_t block_info[1];
|
92 |
|
|
|
93 |
|
|
// Legacy device drivers can't handle NULL printf function
|
94 |
|
|
if (NULL != dev->pf)
|
95 |
|
|
flash_info.pf = dev->pf;
|
96 |
|
|
else
|
97 |
|
|
flash_info.pf = &dummy_printf;
|
98 |
|
|
|
99 |
|
|
err=flash_hwr_init();
|
100 |
|
|
|
101 |
|
|
if (!err) {
|
102 |
|
|
dev->start = (cyg_flashaddr_t)flash_info.start;
|
103 |
|
|
dev->end = dev->start + flash_info.block_size * flash_info.blocks - 1;
|
104 |
|
|
dev->num_block_infos = 1;
|
105 |
|
|
dev->block_info = block_info;
|
106 |
|
|
block_info[0].block_size = flash_info.block_size;
|
107 |
|
|
block_info[0].blocks = flash_info.blocks;
|
108 |
|
|
}
|
109 |
|
|
return err;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
static size_t
|
113 |
|
|
legacy_flash_query (struct cyg_flash_dev *dev,
|
114 |
|
|
void * data,
|
115 |
|
|
size_t len)
|
116 |
|
|
{
|
117 |
|
|
typedef void code_fun(void*);
|
118 |
|
|
code_fun *_flash_query;
|
119 |
|
|
|
120 |
|
|
_flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
|
121 |
|
|
|
122 |
|
|
(*_flash_query)(data);
|
123 |
|
|
|
124 |
|
|
return len;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
static int
|
128 |
|
|
legacy_flash_erase_block (struct cyg_flash_dev *dev,
|
129 |
|
|
cyg_flashaddr_t block_base)
|
130 |
|
|
{
|
131 |
|
|
typedef int code_fun(cyg_flashaddr_t, unsigned int);
|
132 |
|
|
code_fun *_flash_erase_block;
|
133 |
|
|
size_t block_size = dev->block_info[0].block_size;
|
134 |
|
|
int stat;
|
135 |
|
|
|
136 |
|
|
_flash_erase_block = (code_fun*) cyg_flash_anonymizer(&flash_erase_block);
|
137 |
|
|
|
138 |
|
|
stat = (*_flash_erase_block)(block_base, block_size);
|
139 |
|
|
return flash_hwr_map_error(stat);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
static int
|
143 |
|
|
legacy_flash_program(struct cyg_flash_dev *dev,
|
144 |
|
|
cyg_flashaddr_t base,
|
145 |
|
|
const void* data, size_t len)
|
146 |
|
|
{
|
147 |
|
|
typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int);
|
148 |
|
|
code_fun *_flash_program_buf;
|
149 |
|
|
size_t block_size = dev->block_info[0].block_size;
|
150 |
|
|
size_t block_mask = ~(block_size -1);
|
151 |
|
|
int stat;
|
152 |
|
|
|
153 |
|
|
_flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf);
|
154 |
|
|
|
155 |
|
|
stat = (*_flash_program_buf)(base, data, len, block_mask, flash_info.buffer_size);
|
156 |
|
|
return flash_hwr_map_error(stat);
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
#ifdef CYGSEM_IO_FLASH_READ_INDIRECT
|
160 |
|
|
static int
|
161 |
|
|
legacy_flash_read (struct cyg_flash_dev *dev,
|
162 |
|
|
const cyg_flashaddr_t base,
|
163 |
|
|
void* data, size_t len)
|
164 |
|
|
{
|
165 |
|
|
typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int);
|
166 |
|
|
code_fun *_flash_read_buf;
|
167 |
|
|
size_t block_size = dev->block_info[0].block_size;
|
168 |
|
|
size_t block_mask = ~(block_size -1);
|
169 |
|
|
int stat;
|
170 |
|
|
_flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf);
|
171 |
|
|
|
172 |
|
|
stat = (*_flash_read_buf)(base, data, len, block_mask, block_size);
|
173 |
|
|
return flash_hwr_map_error(stat);
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
# define LEGACY_FLASH_READ legacy_flash_read
|
177 |
|
|
#else
|
178 |
|
|
# define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0)
|
179 |
|
|
#endif
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
183 |
|
|
static int
|
184 |
|
|
legacy_flash_block_lock (struct cyg_flash_dev *dev,
|
185 |
|
|
const cyg_flashaddr_t block_base)
|
186 |
|
|
{
|
187 |
|
|
typedef int code_fun(cyg_flashaddr_t);
|
188 |
|
|
code_fun *_flash_lock_block;
|
189 |
|
|
int stat;
|
190 |
|
|
_flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block);
|
191 |
|
|
|
192 |
|
|
stat = (*_flash_lock_block)(block_base);
|
193 |
|
|
return flash_hwr_map_error(stat);
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
static int
|
197 |
|
|
legacy_flash_block_unlock (struct cyg_flash_dev *dev,
|
198 |
|
|
const cyg_flashaddr_t block_base)
|
199 |
|
|
{
|
200 |
|
|
typedef int code_fun(cyg_flashaddr_t, int, int);
|
201 |
|
|
code_fun *_flash_unlock_block;
|
202 |
|
|
size_t block_size = dev->block_info[0].block_size;
|
203 |
|
|
cyg_uint32 blocks = dev->block_info[0].blocks;
|
204 |
|
|
int stat;
|
205 |
|
|
_flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block);
|
206 |
|
|
|
207 |
|
|
stat = (*_flash_unlock_block)(block_base, block_size, blocks);
|
208 |
|
|
return flash_hwr_map_error(stat);
|
209 |
|
|
}
|
210 |
|
|
#endif
|
211 |
|
|
|
212 |
|
|
void
|
213 |
|
|
flash_dev_query(void* data)
|
214 |
|
|
{
|
215 |
|
|
typedef void code_fun(void*);
|
216 |
|
|
code_fun *_flash_query;
|
217 |
|
|
HAL_FLASH_CACHES_STATE(d_cache, i_cache);
|
218 |
|
|
|
219 |
|
|
_flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
|
220 |
|
|
|
221 |
|
|
HAL_FLASH_CACHES_OFF(d_cache, i_cache);
|
222 |
|
|
(*_flash_query)(data);
|
223 |
|
|
HAL_FLASH_CACHES_ON(d_cache, i_cache);
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
static const CYG_FLASH_FUNS(cyg_legacy_funs,
|
227 |
|
|
legacy_flash_init,
|
228 |
|
|
legacy_flash_query,
|
229 |
|
|
legacy_flash_erase_block,
|
230 |
|
|
legacy_flash_program,
|
231 |
|
|
LEGACY_FLASH_READ,
|
232 |
|
|
legacy_flash_block_lock,
|
233 |
|
|
legacy_flash_block_unlock
|
234 |
|
|
);
|
235 |
|
|
|
236 |
|
|
CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev,
|
237 |
|
|
&cyg_legacy_funs,
|
238 |
|
|
0, // Flags
|
239 |
|
|
0, // Start address, filled in by init
|
240 |
|
|
0, // End address, filled in by init
|
241 |
|
|
0, // Number of block infos, filled in by init
|
242 |
|
|
NULL, // Block infos, again filled in by init
|
243 |
|
|
NULL // Driver private data, none needed
|
244 |
|
|
);
|