eeprom.c (161193) | eeprom.c (165399) |
---|---|
1/****************************************************************************** 2 * 3 * Filename: eeprom.c 4 * 5 * Instantiation of eeprom routines 6 * 7 * Revision information: 8 * --- 4 unchanged lines hidden (view full) --- 13 * No warranty, expressed or implied, is included with this software. It is 14 * provided "AS IS" and no warranty of any kind including statutory or aspects 15 * relating to merchantability or fitness for any purpose is provided. All 16 * intellectual property rights of others is maintained with the respective 17 * owners. This software is not copyrighted and is intended for reference 18 * only. 19 * END_BLOCK 20 * | 1/****************************************************************************** 2 * 3 * Filename: eeprom.c 4 * 5 * Instantiation of eeprom routines 6 * 7 * Revision information: 8 * --- 4 unchanged lines hidden (view full) --- 13 * No warranty, expressed or implied, is included with this software. It is 14 * provided "AS IS" and no warranty of any kind including statutory or aspects 15 * relating to merchantability or fitness for any purpose is provided. All 16 * intellectual property rights of others is maintained with the respective 17 * owners. This software is not copyrighted and is intended for reference 18 * only. 19 * END_BLOCK 20 * |
21 * $FreeBSD: head/sys/boot/arm/at91/libat91/eeprom.c 161193 2006-08-10 18:03:50Z imp $ | 21 * $FreeBSD: head/sys/boot/arm/at91/libat91/eeprom.c 165399 2006-12-20 18:19:52Z imp $ |
22 *****************************************************************************/ 23 24#include "at91rm9200_lowlevel.h" 25#include "at91rm9200.h" 26#include "lib.h" 27 28/******************************* GLOBALS *************************************/ 29 --- 47 unchanged lines hidden (view full) --- 77/* 78 * .KB_C_FN_DEFINITION_START 79 * void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size) 80 * This global function reads data from the eeprom at ee_addr storing data 81 * to data_addr for size bytes. Assume the TWI has been initialized. 82 * This function does not utilize the page read mode to simplify the code. 83 * .KB_C_FN_DEFINITION_END 84 */ | 22 *****************************************************************************/ 23 24#include "at91rm9200_lowlevel.h" 25#include "at91rm9200.h" 26#include "lib.h" 27 28/******************************* GLOBALS *************************************/ 29 --- 47 unchanged lines hidden (view full) --- 77/* 78 * .KB_C_FN_DEFINITION_START 79 * void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size) 80 * This global function reads data from the eeprom at ee_addr storing data 81 * to data_addr for size bytes. Assume the TWI has been initialized. 82 * This function does not utilize the page read mode to simplify the code. 83 * .KB_C_FN_DEFINITION_END 84 */ |
85void | 85int |
86ReadEEPROM(unsigned ee_off, char *data_addr, unsigned size) 87{ 88 const AT91PS_TWI twiPtr = AT91C_BASE_TWI; 89 unsigned int status; | 86ReadEEPROM(unsigned ee_off, char *data_addr, unsigned size) 87{ 88 const AT91PS_TWI twiPtr = AT91C_BASE_TWI; 89 unsigned int status; |
90 unsigned int count; |
|
90 91 status = twiPtr->TWI_SR; 92 status = twiPtr->TWI_RHR; 93 94 // Set the TWI Master Mode Register 95 twiPtr->TWI_MMR = (TWSI_EEPROM_ADDRESS << 16) | 96 AT91C_TWI_IADRSZ_2_BYTE | AT91C_TWI_MREAD; 97 98 // Set TWI Internal Address Register 99 twiPtr->TWI_IADR = ee_off; 100 101 // Start transfer 102 twiPtr->TWI_CR = AT91C_TWI_START; 103 104 status = twiPtr->TWI_SR; 105 106 while (size-- > 1){ | 91 92 status = twiPtr->TWI_SR; 93 status = twiPtr->TWI_RHR; 94 95 // Set the TWI Master Mode Register 96 twiPtr->TWI_MMR = (TWSI_EEPROM_ADDRESS << 16) | 97 AT91C_TWI_IADRSZ_2_BYTE | AT91C_TWI_MREAD; 98 99 // Set TWI Internal Address Register 100 twiPtr->TWI_IADR = ee_off; 101 102 // Start transfer 103 twiPtr->TWI_CR = AT91C_TWI_START; 104 105 status = twiPtr->TWI_SR; 106 107 while (size-- > 1){ |
107 | |
108 // Wait RHR Holding register is full | 108 // Wait RHR Holding register is full |
109 while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY)) | 109 count = 1000000; 110 while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY) && --count > 0) |
110 continue; | 111 continue; |
112 if (count <= 0) 113 return -1; |
|
111 112 // Read byte 113 *(data_addr++) = twiPtr->TWI_RHR; 114 } 115 116 twiPtr->TWI_CR = AT91C_TWI_STOP; 117 118 status = twiPtr->TWI_SR; 119 120 // Wait transfer is finished 121 while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP)) 122 continue; 123 124 // Read last byte 125 *data_addr = twiPtr->TWI_RHR; | 114 115 // Read byte 116 *(data_addr++) = twiPtr->TWI_RHR; 117 } 118 119 twiPtr->TWI_CR = AT91C_TWI_STOP; 120 121 status = twiPtr->TWI_SR; 122 123 // Wait transfer is finished 124 while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP)) 125 continue; 126 127 // Read last byte 128 *data_addr = twiPtr->TWI_RHR; |
129 return 0; |
|
126} 127 128 129/* 130 * .KB_C_FN_DEFINITION_START 131 * void WriteEEPROM(unsigned ee_off, char *data_addr, unsigned size) 132 * This global function writes data to the eeprom at ee_off using data 133 * from data_addr for size bytes. Assume the TWI has been initialized. --- 48 unchanged lines hidden --- | 130} 131 132 133/* 134 * .KB_C_FN_DEFINITION_START 135 * void WriteEEPROM(unsigned ee_off, char *data_addr, unsigned size) 136 * This global function writes data to the eeprom at ee_off using data 137 * from data_addr for size bytes. Assume the TWI has been initialized. --- 48 unchanged lines hidden --- |