![]() |
|
|||
File indexing completed on 2025-05-11 08:23:53
0001 #ifndef BSP_FLASH_PGM_API_H 0002 #define BSP_FLASH_PGM_API_H 0003 0004 /* Trivial Flash Programmer */ 0005 0006 /* Author: Till Straumann <strauman@slac.stanford.edu>, 2006 0007 * NOTE: copyright info at the bottom of this file 0008 */ 0009 0010 /* IMPORTANT NOTE 0011 * 0012 * The flash API is NOT THREAD SAFE. During the execution of any of the 0013 * BSP_flashXXX() routines, flash (residing in the same device) 0014 * MUST NOT be accessed by other threads in ANY way (NOT EVEN READ!). 0015 * Read operations may return internal device register contents 0016 * instead of memory array data when issued while a flash device 0017 * is erased, written or queried by the library. 0018 * 0019 * The routines are intended for occasional maintenance use only 0020 * (i.e., not for implementing a file system or similar). 0021 * 0022 * While polling for the completion of block erase operations the 0023 * CPU is yielded to other threads. Busy waiting (interrupts and 0024 * thread dispatching remain enabled) on write operations is employed. 0025 */ 0026 0027 #include <stdio.h> 0028 0029 #ifdef __cplusplus 0030 extern "C" { 0031 #endif 0032 0033 /* Disengage flash write protection. Write protection is implemented 0034 * at the board or chipset level by disabling all write operations/bus cycles 0035 * to the flash device(s). 0036 * With write protection enabled, nothing but 'ordinary' (array) read operations 0037 * are possible. 0038 * Write protection must be disabled not only to erase and write contents 0039 * but also in order to read ID, size, status etc. 0040 * None of the operations (except for BSP_flashWriteEnable()) are possible 0041 * on a write-protected device. 0042 * 0043 * 'bank': flash bank # (usually 0) 0044 * RETURNS: 0 on success, nonzero on error (printing message to stderr). 0045 * 0046 * NOTES: - some boards (MVME5500) don't support 'bank' granularity but 0047 * enable/disable write protection for all devices at once. 0048 * - a jumper-based protection mechanism might be in place 0049 * in addition to the software-based one. Consult the user's 0050 * manual of your board for more information. 0051 */ 0052 int 0053 BSP_flashWriteEnable(int bank); 0054 0055 /* Engage flash write protection (see above) 0056 */ 0057 int 0058 BSP_flashWriteDisable(int bank); 0059 0060 /* Erase a region of flash memory. 0061 * 'bank': flash bank # (usually 0). 0062 * 'offset': destination address offset (from start of bank). 0063 * 'size': number of bytes to erase. 0064 * 'quiet': if non-zero, suppress confirmation message / prompt 0065 * if > 1 also suppress the progress indicator. 0066 * 0067 * RETURNS: 0 on success, nonzero on error (printing messages to stderr). 0068 * 0069 * NOTES: - 'offset' and 'size' must be block-aligned. Common 16-bit devices 0070 * have a block size of 0x20000 bytes. If two such devices are 0071 * operated in parallel to form a 32-bit word then the 'effective' 0072 * block size is 0x40000 bytes. The block size can be queried by 0073 * BSP_flashBlockSize(int bank); 0074 * 0075 * - erase operation is verified. 0076 */ 0077 int 0078 BSP_flashErase(int bank, uint32_t offset, uint32_t size, int quiet); 0079 0080 /* Write data from a buffer to flash. The target area is erased if necessary. 0081 * 0082 * 'bank': flash bank # (usually 0). 0083 * 'offset': destination address offset (from start of bank). 0084 * 'src': data source block address (in memory). 0085 *'n_bytes': number of bytes to copy. 0086 * 'quiet': if non-zero, suppress confirmation message / prompt 0087 * if > 1 also suppress the progress indicator. 0088 * 0089 * NOTES: - Erase operations are only performed where necessary. I.e., 0090 * if one or both of the boundaries of the destination region is/are 0091 * not block-aligned then adjacent data are preserved provided that 0092 * the relevant chunks of the destination are blank (erased). 0093 * 0094 * | <neighbour> fffffff | 0095 * ^--- destination ----- ^ 0096 * | : block boundary 0097 * f : blank/erased pieces 0098 * 0099 * (If the start of the destination region up to the next block boundary 0100 * is blank then '<neighbour>'-data is preserved. The end of the 0101 * destination is treated the same way.) 0102 * 0103 * - user confirmation is requested before changes are made 0104 * 0105 * - 'src' must not point into the destination bank (no copy 0106 * within a flash bank). 0107 * 0108 * - erase and write operations are verified. 0109 * 0110 * RETURNS: 0 on success, nonzero on error (message printed to stderr). 0111 */ 0112 int 0113 BSP_flashWrite(int bank, uint32_t offset, const char *src, uint32_t n_bytes, int quiet); 0114 0115 /* Copy contents of a file to flash. 0116 * 0117 * 'fname': Path of a file. 0118 * 'quiet': if non-zero, suppress confirmation message / prompt 0119 * if > 1 also suppress the progress indicator. 0120 * 0121 * NOTES: Convenience wrapper around BSP_flashWrite(); see above for 0122 * args and return value. 0123 */ 0124 int 0125 BSP_flashWriteFile(int bank, uint32_t offset, const char *path, int quiet); 0126 0127 /* Dump info about available flash to file 0128 * (stdout is used if f==NULL). 0129 * 0130 * RETURNS: 0 0131 * NOTES: Write protection must be disengaged (see above); 0132 */ 0133 int 0134 BSP_flashDumpInfo(FILE *f); 0135 0136 /* 0137 * Obtain starting-address of flash bank (as seen from CPU) 0138 * (returns ((uint32_t) -1) if the bank argument is invalid). 0139 */ 0140 0141 uint32_t 0142 BSP_flashStart(int bank); 0143 0144 /* 0145 * Obtain size of flash bank (returns ((uint32_t) -1) if the 0146 * bank argument is invalid). 0147 */ 0148 uint32_t 0149 BSP_flashSize(int bank); 0150 0151 /* 0152 * Obtain block size of flash bank (sector size times 0153 * number of devices in parallel; the block size determines 0154 * alignment and granularity accepted by BSP_flashErase() 0155 * (returns ((uint32_t) -1) if the bank argument is invalid). 0156 */ 0157 uint32_t 0158 BSP_flashBlockSize(int bank); 0159 0160 #ifdef __cplusplus 0161 } 0162 #endif 0163 0164 /* 0165 * Authorship 0166 * ---------- 0167 * This software was created by 0168 * Till Straumann <strauman@slac.stanford.edu>, 2005-2007, 0169 * Stanford Linear Accelerator Center, Stanford University. 0170 * 0171 * Acknowledgement of sponsorship 0172 * ------------------------------ 0173 * The software was produced by 0174 * the Stanford Linear Accelerator Center, Stanford University, 0175 * under Contract DE-AC03-76SFO0515 with the Department of Energy. 0176 * 0177 * Government disclaimer of liability 0178 * ---------------------------------- 0179 * Neither the United States nor the United States Department of Energy, 0180 * nor any of their employees, makes any warranty, express or implied, or 0181 * assumes any legal liability or responsibility for the accuracy, 0182 * completeness, or usefulness of any data, apparatus, product, or process 0183 * disclosed, or represents that its use would not infringe privately owned 0184 * rights. 0185 * 0186 * Stanford disclaimer of liability 0187 * -------------------------------- 0188 * Stanford University makes no representations or warranties, express or 0189 * implied, nor assumes any liability for the use of this software. 0190 * 0191 * Stanford disclaimer of copyright 0192 * -------------------------------- 0193 * Stanford University, owner of the copyright, hereby disclaims its 0194 * copyright and all other rights in this software. Hence, anyone may 0195 * freely use it for any purpose without restriction. 0196 * 0197 * Maintenance of notices 0198 * ---------------------- 0199 * In the interest of clarity regarding the origin and status of this 0200 * SLAC software, this and all the preceding Stanford University notices 0201 * are to remain affixed to any copy or derivative of this software made 0202 * or distributed by the recipient and are to be affixed to any copy of 0203 * software made or distributed by the recipient that contains a copy or 0204 * derivative of this software. 0205 * 0206 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 0207 */ 0208 0209 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |