1 #ifndef __ALT_FLASH_H__
2 #define __ALT_FLASH_H__
3 /******************************************************************************
4 * *
5 * License Agreement *
6 * *
7 * Copyright (c) 2015 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 * *
29 * Altera does not recommend, suggest or require that this reference design *
30 * file be used in conjunction or combination with any other product. *
31 ******************************************************************************/
32
33 /******************************************************************************
34 * *
35 * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
36 * *
37 ******************************************************************************/
38
39 /******************************************************************************
40 * *
41 * Alt_flash.h - User interface for flash code *
42 * *
43 * Use this interface to avoid being exposed to the internals of the device *
44 * driver architecture. If you chose to use the flash driver internal *
45 * structures we don't guarantee not to change them *
46 * *
47 * Author PRR *
48 * *
49 ******************************************************************************/
50
51
52
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif /* __cplusplus */
57
58 #include "alt_types.h"
59 #include "alt_flash_types.h"
60 #include "alt_flash_dev.h"
61 #include "sys/alt_cache.h"
62
63 alt_flash_fd* alt_flash_open_dev(const char* name);
64 void alt_flash_close_dev(alt_flash_fd* fd );
65
66 /*
67 * alt_flash_lock
68 *
69 * Locks the range of the memory sectors, which
70 * protected from write and erase.
71 *
72 */
alt_lock_flash(alt_flash_fd * fd,alt_u32 sectors_to_lock)73 static __inline__ int __attribute__ ((always_inline)) alt_lock_flash(
74 alt_flash_fd* fd, alt_u32 sectors_to_lock)
75 {
76 return fd->lock( fd, sectors_to_lock);
77 }
78
79 /*
80 * alt_write_flash
81 *
82 * Program a buffer into flash.
83 *
84 * This routine erases all the affected erase blocks (if necessary)
85 * and then programs the data. However it does not read the data out first
86 * and preserve and none overwritten data, because this would require very
87 * large buffers on the target. If you need
88 * that functionality use the functions below.
89 */
alt_write_flash(alt_flash_fd * fd,int offset,const void * src_addr,int length)90 static __inline__ int __attribute__ ((always_inline)) alt_write_flash(
91 alt_flash_fd* fd,
92 int offset,
93 const void* src_addr,
94 int length )
95 {
96 return fd->write( fd, offset, src_addr, length );
97 }
98
99 /*
100 * alt_read_flash
101 *
102 * Read a block of flash for most flashes this is just memcpy
103 * it's here for completeness in case we need it for some serial flash device
104 *
105 */
alt_read_flash(alt_flash_fd * fd,int offset,void * dest_addr,int length)106 static __inline__ int __attribute__ ((always_inline)) alt_read_flash(
107 alt_flash_fd* fd, int offset,
108 void* dest_addr, int length )
109 {
110 return fd->read( fd, offset, dest_addr, length );
111 }
112
113 /*
114 * alt_get_flash_info
115 *
116 * Return the information on the flash sectors.
117 *
118 */
alt_get_flash_info(alt_flash_fd * fd,flash_region ** info,int * number_of_regions)119 static __inline__ int __attribute__ ((always_inline)) alt_get_flash_info(
120 alt_flash_fd* fd, flash_region** info,
121 int* number_of_regions)
122 {
123 return fd->get_info( fd, info, number_of_regions);
124 }
125
126 /*
127 * alt_erase_flash_block
128 *
129 * Erase a particular erase block, pass in the offset to the start of
130 * the block and it's size
131 */
alt_erase_flash_block(alt_flash_fd * fd,int offset,int length)132 static __inline__ int __attribute__ ((always_inline)) alt_erase_flash_block(
133 alt_flash_fd* fd, int offset, int length)
134 {
135 int ret_code;
136 ret_code = fd->erase_block( fd, offset );
137
138 /* remove dcache_flush call for FB330552
139 if(!ret_code)
140 alt_dcache_flush((alt_u8*)fd->base_addr + offset, length);
141 */
142 return ret_code;
143 }
144
145 /*
146 * alt_write_flash_block
147 *
148 * Write a particular flash block, block_offset is the offset
149 * (from the base of flash) to start of the block
150 * data_offset is the offset (from the base of flash)
151 * where you wish to start programming
152 *
153 * NB this function DOES NOT check that you are only writing a single
154 * block of data as that would slow down this function.
155 *
156 * Use alt_write_flash if you want that level of error checking.
157 */
158
alt_write_flash_block(alt_flash_fd * fd,int block_offset,int data_offset,const void * data,int length)159 static __inline__ int __attribute__ ((always_inline)) alt_write_flash_block(
160 alt_flash_fd* fd, int block_offset,
161 int data_offset,
162 const void *data, int length)
163 {
164
165 int ret_code;
166 ret_code = fd->write_block( fd, block_offset, data_offset, data, length );
167
168 /* remove dcache_flush call for FB330552
169 if(!ret_code)
170 alt_dcache_flush((alt_u8*)fd->base_addr + data_offset, length);
171 */
172 return ret_code;
173 }
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif /* __ALT_FLASH_H__ */
180