OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [flash/] [v2_0/] [src/] [flashiodev.c] - Blame information for rev 310

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      flashiodev.c
4
//
5
//      Flash device interface to I/O subsystem
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    jlarmour
44
// Contributors: 
45
// Date:         2002-01-16
46
// Purpose:      
47
// Description:  
48
//              
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#define _FLASH_PRIVATE_
54
#include <pkgconf/io_flash.h>
55
 
56
#include <errno.h>
57
#include <cyg/infra/cyg_type.h>
58
#include <cyg/io/devtab.h>
59
#include <cyg/io/config_keys.h>
60
#include <cyg/io/flash.h>
61
#include <string.h> // memcpy
62
 
63
#define MIN(x,y) ((x)<(y) ? (x) : (y))
64
 
65
// 1 per devtab entry, so only 1 for now
66
static char flashiodev_workspaces[1][FLASH_MIN_WORKSPACE];
67
 
68
static int dummy_printf( const char *fmt, ... ) {return 0;}
69
 
70
static bool
71
flashiodev_init( struct cyg_devtab_entry *tab )
72
{
73
    char *ws = (char *)tab->priv;
74
    int stat = flash_init( ws, FLASH_MIN_WORKSPACE, &dummy_printf );
75
 
76
    if ( stat == 0 )
77
        return true;
78
    else
79
        return false;
80
} // flashiodev_init()
81
 
82
#if 0
83
static Cyg_ErrNo
84
flashiodev_lookup( struct cyg_devtab_entry **tab,
85
                   struct cyg_devtab_entry *sub_tab,
86
                   const char *name)
87
{
88
} // flashiodev_lookup()
89
#endif
90
 
91
static Cyg_ErrNo
92
flashiodev_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len,
93
                  cyg_uint32 pos)
94
{
95
    char *startpos = (char *)flash_info.start + pos +
96
        CYGNUM_IO_FLASH_BLOCK_OFFSET_1;
97
 
98
#ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
99
    char *endpos = startpos + *len - 1;
100
    char *flashend = MIN( (char *)flash_info.end,
101
                          ((char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 +
102
                           CYGNUM_IO_FLASH_BLOCK_LENGTH_1));
103
    if ( startpos < (char *)flash_info.start+CYGNUM_IO_FLASH_BLOCK_OFFSET_1 )
104
        return -EINVAL;
105
    if ( endpos > flashend )
106
        return -EINVAL;
107
#endif
108
    memcpy( buf, startpos, *len );
109
 
110
    return ENOERR;
111
} // flashiodev_bread()
112
 
113
static Cyg_ErrNo
114
flashiodev_bwrite( cyg_io_handle_t handle, const void *buf, cyg_uint32 *len,
115
                   cyg_uint32 pos )
116
{
117
    Cyg_ErrNo err = ENOERR;
118
    void *erraddr;
119
 
120
    char *startpos = (char *)flash_info.start + pos + CYGNUM_IO_FLASH_BLOCK_OFFSET_1;
121
 
122
#ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
123
    char *endpos = startpos + *len - 1;
124
    char *flashend = MIN( (char *)flash_info.end,
125
                          ((char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 +
126
                           CYGNUM_IO_FLASH_BLOCK_LENGTH_1));
127
    if ( startpos < (char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 )
128
        return -EINVAL;
129
    if ( endpos > flashend )
130
        return -EINVAL;
131
#endif
132
    err = flash_program( startpos,
133
                         (void *)buf, *len, &erraddr );
134
 
135
    if ( err )
136
        err = -EIO; // just something sane
137
    return err;
138
} // flashiodev_bwrite()
139
 
140
static Cyg_ErrNo
141
flashiodev_get_config( cyg_io_handle_t handle,
142
                       cyg_uint32 key,
143
                       void* buf,
144
                       cyg_uint32* len)
145
{
146
    switch (key) {
147
    case CYG_IO_GET_CONFIG_FLASH_ERASE:
148
    {
149
        if ( *len != sizeof( cyg_io_flash_getconfig_erase_t ) )
150
             return -EINVAL;
151
        {
152
            cyg_io_flash_getconfig_erase_t *e =
153
                (cyg_io_flash_getconfig_erase_t *)buf;
154
            char *startpos = (char *)flash_info.start + e->offset + CYGNUM_IO_FLASH_BLOCK_OFFSET_1;
155
 
156
#ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
157
            char *endpos = startpos + e->len - 1;
158
            char *flashend = MIN( (char *)flash_info.end,
159
                          ((char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 +
160
                           CYGNUM_IO_FLASH_BLOCK_LENGTH_1));
161
            if ( startpos < (char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 )
162
                return -EINVAL;
163
            if ( endpos > flashend )
164
                return -EINVAL;
165
#endif
166
            e->flasherr = flash_erase( startpos, e->len, e->err_address );
167
        }
168
        return ENOERR;
169
    }
170
    case CYG_IO_GET_CONFIG_FLASH_DEVSIZE:
171
    {
172
        if ( *len != sizeof( cyg_io_flash_getconfig_devsize_t ) )
173
             return -EINVAL;
174
        {
175
            cyg_io_flash_getconfig_devsize_t *d =
176
                (cyg_io_flash_getconfig_devsize_t *)buf;
177
 
178
            //d->dev_size = flash_info.blocks * flash_info.block_size;
179
            d->dev_size = CYGNUM_IO_FLASH_BLOCK_LENGTH_1;
180
        }
181
        return ENOERR;
182
    }
183
 
184
    case CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE:
185
    {
186
        cyg_io_flash_getconfig_blocksize_t *b =
187
            (cyg_io_flash_getconfig_blocksize_t *)buf;
188
        char *startpos = (char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 + b->offset;
189
#ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
190
        char *flashend = MIN( (char *)flash_info.end,
191
                          ((char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 +
192
                           CYGNUM_IO_FLASH_BLOCK_LENGTH_1));
193
        if ( startpos < (char *)flash_info.start + CYGNUM_IO_FLASH_BLOCK_OFFSET_1 )
194
            return -EINVAL;
195
        if ( startpos > flashend )
196
            return -EINVAL;
197
#endif  
198
        if ( *len != sizeof( cyg_io_flash_getconfig_blocksize_t ) )
199
             return -EINVAL;
200
 
201
        // offset unused for now
202
        b->block_size = flash_info.block_size;
203
        return ENOERR;
204
    }
205
 
206
    default:
207
        return -EINVAL;
208
    }
209
} // flashiodev_get_config()
210
 
211
#if 0
212
static Cyg_ErrNo
213
flashiodev_set_config( cyg_io_handle_t handle,
214
                       cyg_uint32 key,
215
                       const void* buf,
216
                       cyg_uint32* len)
217
{
218
    switch (key) {
219
    default:
220
        return -EINVAL;
221
    }
222
} // flashiodev_set_config()
223
#endif
224
 
225
// get_config/set_config should be added later to provide the other flash
226
// operations possible, like erase etc.
227
 
228
BLOCK_DEVIO_TABLE( cyg_io_flashdev1_ops,
229
                   &flashiodev_bwrite,
230
                   &flashiodev_bread,
231
                   0, // no select
232
                   &flashiodev_get_config,
233
 
234
    );
235
 
236
 
237
BLOCK_DEVTAB_ENTRY( cyg_io_flashdev1,
238
                    CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1,
239
                    0,
240
                    &cyg_io_flashdev1_ops,
241
                    &flashiodev_init,
242
                    0, // No lookup required
243
                    &flashiodev_workspaces[0] );
244
 
245
// EOF flashiodev.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.