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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [inc/] [sys/] [alt_flash.h] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
#ifndef __ALT_FLASH_H__
2
#define __ALT_FLASH_H__
3
/******************************************************************************
4
*                                                                             *
5
* License Agreement                                                           *
6
*                                                                             *
7
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA.           *
8
* All rights reserved.                                                        *
9
*                                                                             *
10
* Permission is hereby granted, free of charge, to any person obtaining a     *
11
* copy of this software and associated documentation files (the "Software"),  *
12
* to deal in the Software without restriction, including without limitation   *
13
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
14
* and/or sell copies of the Software, and to permit persons to whom the       *
15
* Software is furnished to do so, subject to the following conditions:        *
16
*                                                                             *
17
* The above copyright notice and this permission notice shall be included in  *
18
* all copies or substantial portions of the Software.                         *
19
*                                                                             *
20
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
21
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
22
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
25
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
26
* DEALINGS IN THE SOFTWARE.                                                   *
27
*                                                                             *
28
* This agreement shall be governed in all respects by the laws of the State   *
29
* of California and by the laws of the United States of America.              *
30
*                                                                             *
31
* Altera does not recommend, suggest or require that this reference design    *
32
* file be used in conjunction or combination with any other product.          *
33
******************************************************************************/
34
 
35
/******************************************************************************
36
*                                                                             *
37
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT.                       *
38
*                                                                             *
39
******************************************************************************/
40
 
41
/******************************************************************************
42
*                                                                             *
43
* Alt_flash.h - User interface for flash code                                 *
44
*                                                                             *
45
* Use this interface to avoid being exposed to the internals of the device    *
46
* driver architecture. If you chose to use the flash driver internal          *
47
* structures we don't guarantee not to change them                            *
48
*                                                                             *
49
* Author PRR                                                                  *
50
*                                                                             *
51
******************************************************************************/
52
 
53
 
54
 
55
#ifdef __cplusplus
56
extern "C"
57
{
58
#endif /* __cplusplus */
59
 
60
#include "alt_types.h"
61
#include "alt_flash_types.h"
62
#include "alt_flash_dev.h"
63
#include "sys/alt_cache.h"
64
 
65
alt_flash_fd* alt_flash_open_dev(const char* name);
66
void alt_flash_close_dev(alt_flash_fd* fd );
67
 
68
/*
69
 *  alt_write_flash
70
 *
71
 *  Program a buffer into flash.
72
 *
73
 *  This routine erases all the affected erase blocks (if necessary)
74
 *  and then programs the data. However it does not read the data out first
75
 *  and preserve and none overwritten data, because this would require very
76
 *  large buffers on the target. If you need
77
 *  that functionality use the functions below.
78
 */
79
static __inline__ int __attribute__ ((always_inline)) alt_write_flash(
80
                                                           alt_flash_fd* fd,
81
                                                           int offset,
82
                                                           const void* src_addr,
83
                                                           int length )
84
{
85
  return fd->write( fd, offset, src_addr, length );
86
}
87
 
88
/*
89
 *  alt_read_flash
90
 *
91
 *  Read a block of flash for most flashes this is just memcpy
92
 *  it's here for completeness in case we need it for some serial flash device
93
 *
94
 */
95
static __inline__ int __attribute__ ((always_inline)) alt_read_flash(
96
                                      alt_flash_fd* fd, int offset,
97
                                      void* dest_addr, int length )
98
{
99
  return fd->read( fd, offset, dest_addr, length );
100
}
101
 
102
/*
103
 *  alt_get_flash_info
104
 *
105
 *  Return the information on the flash sectors.
106
 *
107
 */
108
static __inline__ int __attribute__ ((always_inline)) alt_get_flash_info(
109
                                      alt_flash_fd* fd, flash_region** info,
110
                                      int* number_of_regions)
111
{
112
  return fd->get_info( fd, info, number_of_regions);
113
}
114
 
115
/*
116
 *  alt_erase_flash_block
117
 *
118
 *  Erase a particular erase block, pass in the offset to the start of
119
 *  the block and it's size
120
 */
121
static __inline__ int __attribute__ ((always_inline)) alt_erase_flash_block(
122
                                      alt_flash_fd* fd, int offset, int length)
123
{
124
  int ret_code;
125
  ret_code = fd->erase_block( fd, offset );
126
 
127
  if(!ret_code)
128
      alt_dcache_flush((alt_u8*)fd->base_addr + offset, length);
129
 
130
  return ret_code;
131
}
132
 
133
/*
134
 *  alt_write_flash_block
135
 *
136
 *  Write a particular flash block, block_offset is the offset
137
 *  (from the base of flash) to start of the block
138
 *  data_offset is the offset (from the base of flash)
139
 *  where you wish to start programming
140
 *
141
 *  NB this function DOES NOT check that you are only writing a single
142
 *  block of data as that would slow down this function.
143
 *
144
 *  Use alt_write_flash if you want that level of error checking.
145
 */
146
 
147
static __inline__ int __attribute__ ((always_inline)) alt_write_flash_block(
148
                                      alt_flash_fd* fd, int block_offset,
149
                                      int data_offset,
150
                                      const void *data, int length)
151
{
152
 
153
  int ret_code;
154
  ret_code = fd->write_block( fd, block_offset, data_offset, data, length );
155
 
156
  if(!ret_code)
157
      alt_dcache_flush((alt_u8*)fd->base_addr + data_offset, length);
158
 
159
  return ret_code;
160
}
161
 
162
#ifdef __cplusplus
163
}
164
#endif
165
 
166
#endif /* __ALT_FLASH_H__ */

powered by: WebSVN 2.1.0

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