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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [flash/] [current/] [src/] [legacy_api.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      legacy_api.c
4
//
5
//      Legacy API implementation on top of the new API
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2004, 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/io/flash.h>
56
 
57
int
58
flash_init(_printf *pf)
59
{
60
  cyg_flash_set_global_printf(pf);
61
  return cyg_flash_init(NULL);
62
}
63
 
64
int
65
flash_verify_addr(void *target)
66
{
67
  return cyg_flash_verify_addr((cyg_flashaddr_t) target);
68
}
69
 
70
int
71
flash_get_limits(void *target, void **start, void **end)
72
{
73
  int err;
74
  cyg_flash_info_t info;
75
 
76
  err = cyg_flash_get_info(0, &info);
77
  if (err != CYG_FLASH_ERR_OK) {
78
    return err;
79
  }
80
 
81
  *start = (void *)info.start;
82
  *end = (void *)info.end;
83
 
84
  return CYG_FLASH_ERR_OK;
85
}
86
 
87
 
88
int
89
flash_get_block_info(int *block_size, int *blocks)
90
{
91
  size_t biggest_size=0;
92
  cyg_uint32 i;
93
  cyg_flash_info_t info;
94
  int err;
95
 
96
  err = cyg_flash_get_info(0, &info);
97
  if (err != CYG_FLASH_ERR_OK) {
98
    return err;
99
  }
100
 
101
  // Find the biggest size of blocks
102
  for (i=0; i < info.num_block_infos; i++) {
103
    if (info.block_info[i].block_size > biggest_size) {
104
      biggest_size = info.block_info[i].block_size;
105
    }
106
  }
107
 
108
  // Calculate the number of biggest size blocks
109
  *block_size = biggest_size;
110
  *blocks = 0;
111
  for (i=0; i < info.num_block_infos; i++) {
112
    *blocks += (info.block_info[i].block_size *
113
                info.block_info[i].blocks) /
114
      biggest_size;
115
  }
116
  return CYG_FLASH_ERR_OK;
117
}
118
 
119
int
120
flash_erase(void *addr, int len, void **err_addr)
121
{
122
  return cyg_flash_erase((cyg_flashaddr_t)addr, len,
123
                         (cyg_flashaddr_t *)err_addr);
124
}
125
 
126
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
127
 
128
int
129
flash_lock(void *addr, int len, void **err_addr)
130
{
131
  return cyg_flash_lock((cyg_flashaddr_t)addr, len,
132
                        (cyg_flashaddr_t *)err_addr);
133
}
134
 
135
int
136
flash_unlock(void *addr, int len, void **err_addr)
137
{
138
  return cyg_flash_unlock((cyg_flashaddr_t)addr, len,
139
                          (cyg_flashaddr_t *)err_addr);
140
}
141
 
142
#endif
143
 
144
int flash_program(void *flash_base, void *ram_base, int len,
145
                  void **err_address)
146
{
147
  return cyg_flash_program((cyg_flashaddr_t)flash_base, ram_base,
148
                           len, (cyg_flashaddr_t *)err_address);
149
}
150
 
151
int flash_read(void *flash_base, void *ram_base, int len, void **err_address)
152
{
153
  return cyg_flash_read((cyg_flashaddr_t)flash_base, ram_base,
154
                        len, (cyg_flashaddr_t *)err_address);
155
}
156
 
157
char *flash_errmsg(int err)
158
{
159
  return (char *)cyg_flash_errmsg(err);
160
}
161
 
162
// EOF legacy_api.c

powered by: WebSVN 2.1.0

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