[1166] | 1 | /* Copyright (c) 2006 Rice University */ |
---|
| 2 | /* All Rights Reserved */ |
---|
| 3 | /* This code is covered by the Rice-WARP license */ |
---|
| 4 | /* See http://warp.rice.edu/license/ for details */ |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 8 | // Filename: C:\EDK_User_Repository\WARP\drivers\EEPROM_v1_00_a\src\EEPROM_l.h |
---|
| 9 | // Version: 1.00.a |
---|
| 10 | // Description: EEPROM Driver Header File |
---|
| 11 | // Date: July 28, 2006 |
---|
| 12 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 13 | |
---|
| 14 | #ifndef EEPROM_L_H |
---|
| 15 | #define EEPROM_L_H |
---|
| 16 | |
---|
| 17 | /***************************** Include Files *******************************/ |
---|
| 18 | |
---|
| 19 | #include "xbasic_types.h" |
---|
| 20 | #include "xstatus.h" |
---|
| 21 | #include "xio.h" |
---|
| 22 | |
---|
| 23 | /************************** Constant Definitions ***************************/ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * User Logic Slave Space Offsets |
---|
| 28 | */ |
---|
| 29 | #define EEPROM_USER_SLAVE_SPACE_OFFSET (0x00000000) |
---|
| 30 | |
---|
| 31 | /***************** Macros (Inline Functions) Definitions *******************/ |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * |
---|
| 35 | * Write a value to a EEPROM register. A 32 bit write is performed. |
---|
| 36 | * If the component is implemented in a smaller width, only the least |
---|
| 37 | * significant data is written. |
---|
| 38 | * |
---|
| 39 | * @param BaseAddress is the base address of the EEPROM device. |
---|
| 40 | * @param RegOffset is the register offset from the base to write to. |
---|
| 41 | * @param Data is the data written to the register. |
---|
| 42 | * |
---|
| 43 | * @return None. |
---|
| 44 | * |
---|
| 45 | * @note None. |
---|
| 46 | * |
---|
| 47 | * C-style signature: |
---|
| 48 | * void EEPROM_mWriteReg(Xuint32 BaseAddress, unsigned RegOffset, Xuint32 Data) |
---|
| 49 | * |
---|
| 50 | */ |
---|
| 51 | #define EEPROM_mWriteReg(BaseAddress, RegOffset, Data) \ |
---|
| 52 | XIo_Out32((BaseAddress) + (RegOffset), (Xuint32)(Data)) |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * |
---|
| 56 | * Read a value from a EEPROM register. A 32 bit read is performed. |
---|
| 57 | * If the component is implemented in a smaller width, only the least |
---|
| 58 | * significant data is read from the register. The most significant data |
---|
| 59 | * will be read as 0. |
---|
| 60 | * |
---|
| 61 | * @param BaseAddress is the base address of the EEPROM device. |
---|
| 62 | * @param RegOffset is the register offset from the base to write to. |
---|
| 63 | * |
---|
| 64 | * @return Data is the data from the register. |
---|
| 65 | * |
---|
| 66 | * @note None. |
---|
| 67 | * |
---|
| 68 | * C-style signature: |
---|
| 69 | * Xuint32 EEPROM_mReadReg(Xuint32 BaseAddress, unsigned RegOffset) |
---|
| 70 | * |
---|
| 71 | */ |
---|
| 72 | #define EEPROM_mReadReg(BaseAddress, RegOffset) \ |
---|
| 73 | XIo_In32((BaseAddress) + (RegOffset)) |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | /******************* OneWire Master Constants/Functions ********************/ |
---|
| 77 | |
---|
| 78 | //Address offsets for registers in OWM |
---|
| 79 | #define COMMAND_REG_OFFSET 0x00 |
---|
| 80 | #define TXRXBUFFER_OFFSET 0x04 |
---|
| 81 | #define INTERRUPT_REG_OFFSET 0x08 |
---|
| 82 | #define ENABLE_INTERRUPT_REG_OFFSET 0x0C |
---|
| 83 | #define CLKDIV_REG_OFFSET 0x10 |
---|
| 84 | #define CONTROL_REG_OFFSET 0x14 |
---|
| 85 | |
---|
| 86 | //Return values |
---|
| 87 | #define SUCCESS 0x00 |
---|
| 88 | #define FAILURE 0xff |
---|
| 89 | #define NO_DEVICE 0xfe |
---|
| 90 | #define ABORT 0xfa |
---|
| 91 | |
---|
| 92 | // OPB_CLOCK defines which clock division should be made to drive the 1-wire bus |
---|
| 93 | // A value of 17 or 18 is suggested, to generate pulses on the one-wire interface |
---|
| 94 | /// that are in-spec. |
---|
| 95 | #define CLK_DIV_RATIO 17 // Default for 40 MHz OPB-clock |
---|
| 96 | |
---|
| 97 | // Initialize the EEPROM master for communication. Required before any communication |
---|
| 98 | // can be made on the 1wire bus. Must be done after a master reset. |
---|
| 99 | // Sets the clock divisor based on the input. |
---|
| 100 | // baseaddr is the base address of the EEPROM device. |
---|
| 101 | // Returns SUCCESS if clock set correctly |
---|
| 102 | // Returns FAILURE otherwise |
---|
| 103 | char WarpEEPROM_Initialize(unsigned int* baseaddr); |
---|
| 104 | |
---|
| 105 | // Send a Reset out on the 1-wire device and wait for a presence detect. |
---|
| 106 | // Returns SUCCESS if device found |
---|
| 107 | // Else returns FAILURE |
---|
| 108 | char WarpEEPROM_Detect(unsigned int* baseaddr); |
---|
| 109 | |
---|
| 110 | // Writes a byte to the transmit buffer |
---|
| 111 | // Waits until buffer is empty before returning. |
---|
| 112 | void WarpEEPROM_WriteByte(unsigned int* baseaddr, char data); |
---|
| 113 | |
---|
| 114 | // Reads a data byte from the EEPROM |
---|
| 115 | // The EEPROM must be ready to trasmit based on |
---|
| 116 | // other commands. Default value is FF. |
---|
| 117 | char WarpEEPROM_ReadByte(unsigned int* baseaddr); |
---|
| 118 | |
---|
| 119 | // Given a 64 bit ROM from an EEPROM, checks to see that the family code |
---|
| 120 | // and serial number flies with the CRC. |
---|
| 121 | // Serial is the 64 bit ROM information. |
---|
| 122 | // Returns SUCCESS if no error, otherwise FAILURE |
---|
| 123 | char WarpEEPROM_VerifyROM(unsigned char *Serial); |
---|
| 124 | |
---|
| 125 | // This function verifies that the 16bit-CRC produced by the EEPROM |
---|
| 126 | // jives with the information sent over the 1-wire bus during |
---|
| 127 | // Read/Write Scratchpad commands. |
---|
| 128 | // array is the 13-byte (11 + 2-byte CRC) or 14-byte (12 + 2-byte CRC) |
---|
| 129 | // array of information |
---|
| 130 | // RNW: 0 - if checking a write command, 1 -- if checking a read command |
---|
| 131 | // Returns SUCCESS if no error, otherwise FAILURE |
---|
| 132 | char WarpEEPROM_VerifyScratchpad(unsigned char *array, unsigned char RNW); |
---|
| 133 | |
---|
| 134 | // Given an array of information and addressing information, this function writes |
---|
| 135 | // the given information to the scratchpad of the EEPROM. This must be done |
---|
| 136 | // before information can be written to memory. |
---|
| 137 | // baseaddr is the base address of the EEPROM device |
---|
| 138 | // page must be 1-4, and refers to memory pages on the device |
---|
| 139 | // sector must be 1-4, and refers to the appropriate sector on the device |
---|
| 140 | // array must be an 8 byte array |
---|
| 141 | char WarpEEPROM_WriteScratch(unsigned int* baseaddr, char page, char sector, unsigned char *array); |
---|
| 142 | |
---|
| 143 | // This will read the current value in the scratchpad. |
---|
| 144 | // Returns the two memory location bytes and the E/S byte necessary |
---|
| 145 | // to copy the scratchpad to memory. |
---|
| 146 | // baseaddr is the base address of the EEPROM device |
---|
| 147 | // auth_code is a 3-byte array where the 3-bytes returned from the |
---|
| 148 | // EEPROM will be stored |
---|
| 149 | char WarpEEPROM_ReadScratch(unsigned int* baseaddr, unsigned char* auth_code); |
---|
| 150 | |
---|
| 151 | // After the information in the scratchpad has been verified via CRC check, the |
---|
| 152 | // scratchpad read, and the authorization code returned, this command will copy |
---|
| 153 | // the scratchpad into the flash memory specified. |
---|
| 154 | // baseaddr is the base address of the EEPROM device |
---|
| 155 | // auth_code a 3 byte array containing the 2-byte memory location and |
---|
| 156 | // 1-byte E/S regsiter value returned during a ReadScratch command. |
---|
| 157 | // Returns SUCCESS if no error, otherwise FAILURE |
---|
| 158 | char WarpEEPROM_Scratch2Mem(unsigned int* baseaddr, unsigned char* auth_code); |
---|
| 159 | |
---|
| 160 | // This function reads from a specified memory location in the 1024-bit memory. |
---|
| 161 | // Returns an 8-byte sector of the EEPROM. |
---|
| 162 | // baseaddr is the base address of the EEPROM device |
---|
| 163 | // page must be 0-3, and refers to memory pages on the device |
---|
| 164 | // sector must be 0-3, and refers to the appropriate sector on the device |
---|
| 165 | // array must be an 8 byte array |
---|
| 166 | // Returns SUCCESS if no error, otherwise FAILURE |
---|
| 167 | char WarpEEPROM_ReadMem(unsigned int* baseaddr, char page, char sector, unsigned char *array); |
---|
| 168 | |
---|
| 169 | // Writes a given 8-byte array to a designated location in memory. |
---|
| 170 | // Essentially a wrapper of the WriteScratch, ReadScratch and Scratch2Mem functions |
---|
| 171 | // baseaddr is the base address of the EEPROM device |
---|
| 172 | // page must be 0-3, and refers to memory pages on the device |
---|
| 173 | // sector must be 0-3, and refers to the appropriate sector on the device |
---|
| 174 | // array must be an 8 byte array |
---|
| 175 | char WarpEEPROM_WriteMem(unsigned int* baseaddr, char page, char sector, unsigned char *array); |
---|
| 176 | |
---|
| 177 | // Reads and outputs the values stored in the 5 protection bytes, the factory byte, and the |
---|
| 178 | // two user bytes. |
---|
| 179 | void WarpEEPROM_ReadControlBytes(unsigned int* baseaddr, char* control_regs); //, char* control_regs); |
---|
| 180 | |
---|
| 181 | // Retrieves the type of board |
---|
| 182 | char WarpEEPROM_GetDeviceType(unsigned int* baseaddr); |
---|
| 183 | |
---|
| 184 | // A utility function for taking ascii input and turning it into a hex number |
---|
| 185 | char WarpEEPROM_ascii2hex(unsigned char ascii); |
---|
| 186 | |
---|
| 187 | // A utility function for taking two sequential keyboard inputs and |
---|
| 188 | // returning a single hex byte. Used for hex input from keyboard |
---|
| 189 | char WarpEEPROM_ascii2hexbyte(unsigned char MSB, unsigned char LSB); |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 193 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 194 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 195 | //*************************************************************************************************************// |
---|
| 196 | //*************************************************************************************************************// |
---|
| 197 | //*************************************************************************************************************// |
---|
| 198 | // THE FOLLOWING FUNCTION CAN BE USED TO WRITE TO THE WRITE PROTECTION BYTES AND THE TWO USER BYTES // |
---|
| 199 | // SOME WRITES CAN NEVER BE CHANGED. EVER. USE AT YOUR OWN RISK. // |
---|
| 200 | //*************************************************************************************************************// |
---|
| 201 | //*************************************************************************************************************// |
---|
| 202 | //*************************************************************************************************************// |
---|
| 203 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 204 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 205 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 206 | |
---|
| 207 | //*********************************************************************************************************** |
---|
| 208 | //*********************************************************************************************************** |
---|
| 209 | //**WARNING**: Writing to any of the protection bytes is **IRREVERSIBLE**! |
---|
| 210 | // Both the write protect and EPROM mode commands write protect the |
---|
| 211 | // register to which they are written. |
---|
| 212 | //*********************************************************************************************************** |
---|
| 213 | //*********************************************************************************************************** |
---|
| 214 | // |
---|
| 215 | // Writes to one of the five protection bytes (if not already copy protected) or |
---|
| 216 | // to one of the User Bytes (if not copy protected). |
---|
| 217 | // baseaddr is the base address of the EEPROM device |
---|
| 218 | // ByteSelect: |
---|
| 219 | // 0: Protection Control Byte Page 0 |
---|
| 220 | // 1: Protection Control Byte Page 1 |
---|
| 221 | // 2: Protection Control Byte Page 2 |
---|
| 222 | // 3: Protection Control Byte Page 3 |
---|
| 223 | // 4: Copy Protection Byte |
---|
| 224 | // 5: User Byte #1 |
---|
| 225 | // 6: User Byte #2 |
---|
| 226 | // |
---|
| 227 | char WarpEEPROM_ControlByteWrite(unsigned int* baseaddr, char ByteSelect, char value2store); |
---|
| 228 | |
---|
| 229 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 230 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 231 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 232 | //*************************************************************************************************************// |
---|
| 233 | //*************************************************************************************************************// |
---|
| 234 | //*************************************************************************************************************// |
---|
| 235 | // THE ABOVE FUNCTION CAN BE USED TO WRITE TO THE WRITE PROTECTION BYTES AND THE TWO USER BYTES // |
---|
| 236 | // SOME WRITES CAN NEVER BE CHANGED. EVER. USE AT YOUR OWN RISK. // |
---|
| 237 | //*************************************************************************************************************// |
---|
| 238 | //*************************************************************************************************************// |
---|
| 239 | //*************************************************************************************************************// |
---|
| 240 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 241 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 242 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | #endif // EEPROM_L_H |
---|