File indexing completed on 2025-05-11 08:23:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <bsp.h>
0015 #include <rtems/bspIo.h> /* printk */
0016 #include <stdint.h> /* uint32_t */
0017 #include "bsp/GT64260TWSI.h"
0018
0019
0020
0021 static unsigned char I2cAddrPack(unsigned char busAddr,uint32_t offset)
0022 {
0023 return(busAddr | ((offset & 0x700) >> 7));
0024 }
0025
0026 static unsigned char I2cDevByteAddr(uint32_t devA2A1A0, unsigned char byteNum)
0027 {
0028 return(( devA2A1A0 >>(byteNum*8)) & 0xff);
0029 }
0030
0031
0032
0033 int I2Cread_eeprom(
0034 unsigned char I2cBusAddr,
0035 uint32_t devA2A1A0,
0036 uint32_t AddrBytes,
0037 unsigned char *pBuff,
0038 uint32_t numBytes
0039 )
0040 {
0041 int status=0, lastByte=0;
0042
0043 switch (AddrBytes) {
0044 case 1:
0045 if ((status=GT64260TWSIstart()) != -1) {
0046 if ((status=GT64260TWSIwrite(I2cAddrPack(I2cBusAddr,devA2A1A0)))!= -1){
0047 if ((status=GT64260TWSIwrite(devA2A1A0))!=-1){
0048 if ((status=GT64260TWSIstart())!=-1)
0049 status=GT64260TWSIwrite(I2cAddrPack((I2cBusAddr|0x01),devA2A1A0));
0050 }
0051 }
0052 }
0053 break;
0054 case 2:
0055 if ((status=GT64260TWSIstart())!=-1) {
0056 if ((status=GT64260TWSIwrite(I2cBusAddr))!= -1) {
0057 if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!=-1) {
0058 if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
0059 if ((status=GT64260TWSIstart()) != -1) {
0060 status = GT64260TWSIwrite((I2cBusAddr | 0x01));
0061 }
0062 }
0063 }
0064 }
0065 }
0066 break;
0067 case 3:
0068 if ((status = GT64260TWSIstart())!= -1) {
0069 if ((status = GT64260TWSIwrite(I2cBusAddr))!= -1) {
0070 if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,2)))!= -1){
0071 if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!= -1){
0072 if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
0073 if ((status=GT64260TWSIstart())!= -1) {
0074 status = GT64260TWSIwrite(I2cBusAddr | 0x01);
0075 }
0076 }
0077 }
0078 }
0079 }
0080 }
0081 break;
0082 default:
0083 status=-1;
0084 break;
0085 }
0086 if (status !=-1) {
0087 #ifdef I2C_DEBUG
0088 printk("\n");
0089 #endif
0090
0091 for ( ; numBytes > 0; numBytes-- ) {
0092 if ( numBytes == 1) lastByte=1;
0093 if (GT64260TWSIread(pBuff,lastByte) == -1) return (-1);
0094 #ifdef I2C_DEBUG
0095 printk("%2x ", *pBuff);
0096 if ( (numBytes % 20)==0 ) printk("\n");
0097 #endif
0098 pBuff++;
0099 }
0100 #ifdef I2C_DEBUG
0101 printk("\n");
0102 #endif
0103 if (GT64260TWSIstop() == -1) return (-1);
0104 }
0105 return (status);
0106 }
0107