alt_flash.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * 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. * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
  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. #ifdef __cplusplus
  51. extern "C"
  52. {
  53. #endif /* __cplusplus */
  54. #include "alt_types.h"
  55. #include "alt_flash_types.h"
  56. #include "alt_flash_dev.h"
  57. #include "sys/alt_cache.h"
  58. alt_flash_fd* alt_flash_open_dev(const char* name);
  59. void alt_flash_close_dev(alt_flash_fd* fd );
  60. /*
  61. * alt_flash_lock
  62. *
  63. * Locks the range of the memory sectors, which
  64. * protected from write and erase.
  65. *
  66. */
  67. static __inline__ int __attribute__ ((always_inline)) alt_lock_flash(
  68. alt_flash_fd* fd, alt_u32 sectors_to_lock)
  69. {
  70. return fd->lock( fd, sectors_to_lock);
  71. }
  72. /*
  73. * alt_write_flash
  74. *
  75. * Program a buffer into flash.
  76. *
  77. * This routine erases all the affected erase blocks (if necessary)
  78. * and then programs the data. However it does not read the data out first
  79. * and preserve and none overwritten data, because this would require very
  80. * large buffers on the target. If you need
  81. * that functionality use the functions below.
  82. */
  83. static __inline__ int __attribute__ ((always_inline)) alt_write_flash(
  84. alt_flash_fd* fd,
  85. int offset,
  86. const void* src_addr,
  87. int length )
  88. {
  89. return fd->write( fd, offset, src_addr, length );
  90. }
  91. /*
  92. * alt_read_flash
  93. *
  94. * Read a block of flash for most flashes this is just memcpy
  95. * it's here for completeness in case we need it for some serial flash device
  96. *
  97. */
  98. static __inline__ int __attribute__ ((always_inline)) alt_read_flash(
  99. alt_flash_fd* fd, int offset,
  100. void* dest_addr, int length )
  101. {
  102. return fd->read( fd, offset, dest_addr, length );
  103. }
  104. /*
  105. * alt_get_flash_info
  106. *
  107. * Return the information on the flash sectors.
  108. *
  109. */
  110. static __inline__ int __attribute__ ((always_inline)) alt_get_flash_info(
  111. alt_flash_fd* fd, flash_region** info,
  112. int* number_of_regions)
  113. {
  114. return fd->get_info( fd, info, number_of_regions);
  115. }
  116. /*
  117. * alt_erase_flash_block
  118. *
  119. * Erase a particular erase block, pass in the offset to the start of
  120. * the block and it's size
  121. */
  122. static __inline__ int __attribute__ ((always_inline)) alt_erase_flash_block(
  123. alt_flash_fd* fd, int offset, int length)
  124. {
  125. int ret_code;
  126. ret_code = fd->erase_block( fd, offset );
  127. /* remove dcache_flush call for FB330552
  128. if(!ret_code)
  129. alt_dcache_flush((alt_u8*)fd->base_addr + offset, length);
  130. */
  131. return ret_code;
  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. static __inline__ int __attribute__ ((always_inline)) alt_write_flash_block(
  147. alt_flash_fd* fd, int block_offset,
  148. int data_offset,
  149. const void *data, int length)
  150. {
  151. int ret_code;
  152. ret_code = fd->write_block( fd, block_offset, data_offset, data, length );
  153. /* remove dcache_flush call for FB330552
  154. if(!ret_code)
  155. alt_dcache_flush((alt_u8*)fd->base_addr + data_offset, length);
  156. */
  157. return ret_code;
  158. }
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* __ALT_FLASH_H__ */