sysI2CDrv.c
资源名称:idt438.rar [点击查看]
上传用户:yingyi0918
上传日期:2022-06-26
资源大小:214k
文件大小:25k
源码类别:
VxWorks
开发平台:
C/C++
- /* sysI2CDrv.c - I2C driver */
- /* Copyright 1984-2002 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- * This file has been developed or significantly modified by the
- * MIPS Center of Excellence Dedicated Engineering Staff.
- * This notice is as per the MIPS Center of Excellence Master Partner
- * Agreement, do not remove this notice without checking first with
- * WR/Platforms MIPS Center of Excellence engineering management.
- */
- /*
- modification history
- --------------------
- 01c,18sep02,slk Cleanup for refgen use on file
- 01b,25jun02,d_c Further cleanup
- 01a,19Jun02,d_c Code from IDT modified to approach C of E standards.
- */
- /*
- DESCRIPTION
- This module contains the functions to access the 24AA64 EEPROM via the I2C
- interface on the IDT79EB355, and IDT79RP355 boards.
- INCLUDE FILES : sysI2CDrv.h
- */
- /* includes */
- #include "sysI2CDrv.h"
- /* defines */
- #undef I2C_DEBUG /* Enable debug routines if defined */
- /*
- * uSecs to wait for I2C done condition.
- *
- * NOTE: If you change this value, you must also change function
- * documentation for sysI2CInit and sysI2CAckPollOnWrite.
- */
- #define I2C_DONE_TIMEOUT 3000000
- /* Number of bits required to address a page - used to allign
- * data on page boundaries.
- */
- #define I2C_EEPROM_PAGE_BITS (I2C_EEPROM_PAGE_SIZE - 1)
- /* typedefs */
- /* globals */
- /* locals */
- /* forward declaration */
- /******************************************************************************
- *
- * sysI2CInit - initialize the I2C interface.
- *
- * This routine initializes I2C interface & GPIO pins.
- *
- * RETURNS: N/A
- */
- void sysI2CInit (void)
- {
- /* Enable Master interface */
- I2C.i2cc = I2CC_MEN;
- I2C.i2ccp = I2C_CPP;
- /* Mask off the I2C interrupts : Master/ Slave */
- I2C.i2cmsm = I2C_MASTER_INT_MASK;
- I2C.i2cssm = I2C_SLAVE_INT_MASK;
- sysWbFlush ();
- }
- /*****************************************************************************
- *
- * sysI2CChkDone - check if the I2C device has done condition
- *
- * This function polls the I2C command status register to check if the DONE
- * bit is set.
- *
- * RETURNS: OK if acknowledged within 500 milliseconds, ERROR otherwise
- */
- STATUS sysI2CChkDone (void)
- {
- unsigned int devStatus = 0; /* device status */
- UINT32 startCount; /* Starting count for timeout */
- /* Wait for Acknowledge from the Device */
- startCount = sysUSecTimoutStart ();
- while (!sysUSecTimoutExpired (startCount, I2C_DONE_TIMEOUT))
- {
- devStatus = I2C.i2cms;
- /* Check DONE status - return OK if done */
- if ((devStatus & I2CMS_MASK) == I2CMS_D)
- return (OK);
- }
- /* Timeout expired */
- return ERROR;
- }
- /*****************************************************************************
- *
- * sysI2CStart - issue a start command to the I2C slave device
- *
- * This routine Issues a start command to the I2C slave device. It
- * is used to initiate reads and writes to an I2C device.
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CStart (void)
- {
- I2C.i2cmcmd = I2CMCMD_CMD (START);
- sysWbFlush ();
- return sysI2CChkDone ();
- }
- /*****************************************************************************
- *
- * sysI2CByteWrite - write a byte into the I2C EEPROM device
- *
- * This function writes <byte> into the I2C EEPROM at <address>.
- *
- * RETURNS: OK on completion, ERROR otherwise.
- */
- STATUS sysI2CByteWrite
- (
- unsigned short address, /* I2C Address */
- unsigned char byte /* data to write */
- )
- {
- STATUS status; /* used to check the I2C Status state */
- /* Issue a Start command to I2C */
- status = sysI2CStart ();
- if (status == ERROR)
- return (ERROR);
- /* Write Control Byte */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - upper bits */
- I2C.i2cdo = (unsigned int) ((address >> I2CDO_DATA_WIDTH)
- & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - lower bits */
- I2C.i2cdo = (unsigned int) (address & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Write Data */
- I2C.i2cdo = byte;
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Generate Stop Command to make the write byte to
- * written internally. Wait for some time to let this
- * internal operation finish
- */
- status = sysI2CStop ();
- if (status != OK)
- return (ERROR);
- /* Wait for some time for the internal operation to finish */
- sysUSecDelay (I2C_DELAY_MULT * 40000);
- return (OK);
- }
- /****************************************************************************
- *
- * sysI2CPageWriteOpen - open a 32-byte page in I2C EEPROM
- *
- * This function initiates a page write operation to I2C EEPROM at <address>.
- * It may be followed by upto 32 sysI2CInPageWrite() operations and terminated
- * with the sysI2CStop() command.
- *
- * RETURNS: OK on completion, ERROR otherwise
- *
- * SEE ALSO: sysI2CInPageWrite(), sysI2CStop()
- */
- STATUS sysI2CPageWriteOpen
- (
- unsigned short address /* I2C Address */
- )
- {
- STATUS status; /* used to check the I2C Status state */
- /* Send a Start command */
- status = sysI2CStart ();
- if (status == ERROR)
- return (ERROR);
- /* Write Control Byte */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - upper 8 bits */
- I2C.i2cdo = (unsigned int) ((address >> I2CDO_DATA_WIDTH)
- & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - lower 8 bits */
- I2C.i2cdo = (unsigned int) (address & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- return (OK);
- }
- /******************************************************************************
- *
- * sysI2CInPageWrite - write a byte to an already opened I2C EEPROM page
- *
- * This function writes <byte> to a I2C page that has already been opened
- * by sysI2CPageWriteOpen(). The address is maintained and automatically
- * incremented by I2C.
- *
- * RETURNS: OK on completion, ERROR otherwise
- */
- STATUS sysI2CInPageWrite
- (
- unsigned char byte /* data to be written */
- )
- {
- STATUS status; /* used to check the I2C Status state */
- /* Write Data */
- I2C.i2cdo = byte;
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- sysUSecDelay (I2C_DELAY_MULT * 600);
- return (OK);
- }
- /*****************************************************************************
- *
- * sysI2CStop - Issue a stop command to the I2C bus interface
- *
- * This function issues a stop command to the I2C bus bus interface. It is
- * used to complete writes to the I2C EEPROM.
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CStop (void)
- {
- unsigned int devStatus; /* I2C device status */
- STATUS status; /* I2C module status state */
- /* Issue Stop Command */
- I2C.i2cmcmd = I2CMCMD_CMD (STOP);
- sysWbFlush ();
- sysUSecDelay (I2C_DELAY_MULT * 5000);
- /* Check the I2C device status */
- devStatus = I2C.i2cms;
- if (((devStatus & I2CMS_MASK) == I2CMS_D)
- || ((devStatus & I2CMS_MASK) == (I2CMS_D | I2CMS_NACK)))
- {
- return OK;
- }
- else
- {
- /* Check for Error Condition */
- if ((devStatus & I2CMS_ERR))
- {
- /* Clear Error Condition by Start Command */
- status = sysI2CStart ();
- if (status != OK)
- {
- /* Something really bad, should'nt happen
- * Try starting once again & return with error
- */
- sysI2CStart ();
- return (ERROR);
- }
- }
- /* Okay we could start but caller should still be returned Error */
- return (ERROR);
- }
- }
- /******************************************************************************
- *
- * sysI2CAckPollOnWrite - Wait for acknowledge from the I2C EEPROM.
- *
- * This routine waits for a Done/Acknowledge from the I2C EEPROM. It is
- * used to determine the completion of an internal EEPROM write
- * operation after a stop command has been issued.
- *
- * RETURNS: OK if acknowledged within 500 milliseconds, ERROR otherwise
- *
- * SEE ALSO: sysI2CStop()
- */
- STATUS sysI2CAckPollOnWrite (void)
- {
- unsigned int devStatus; /* I2C device status */
- UINT32 startCount; /* Starting count for timeout */
- /* Wait for Acknowledge from the Device */
- startCount = sysUSecTimoutStart ();
- while (!sysUSecTimoutExpired (startCount, I2C_DONE_TIMEOUT))
- {
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- /* Send a start command & wait for Ack */
- I2C.i2cmcmd = I2CMCMD_CMD (START);
- sysWbFlush ();
- /* Read the status register */
- devStatus = I2C.i2cms;
- if ((devStatus & I2CMS_MASK) == I2CMS_D) /* Done, Ack & no errors */
- return OK;
- } /* end of for loop of iterative checks on the status */
- /* I2C is taking quite some time to complete internal writes,
- * return ERROR
- */
- return (ERROR);
- }
- /******************************************************************************
- *
- * sysI2CByteRead - Read a byte from the specified location in the I2C EEPROM
- *
- * This routine reads a byte from the location in the I2C EEPROM
- * specified by <address>.
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CByteRead
- (
- unsigned short address, /* I2C Address from where byte is read */
- int * byte /* pointer to location for returned byte */
- )
- {
- STATUS status; /* used to check the I2C status state */
- unsigned int devStatus; /* I2C device status */
- /* Send a Start Command */
- status = sysI2CStart ();
- if (status == ERROR)
- return (ERROR);
- /* Write Control Byte */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - upper 8 bits */
- I2C.i2cdo = (unsigned int) ((address >> I2CDO_DATA_WIDTH)
- & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - lower 8 bits */
- I2C.i2cdo = (unsigned int) (address & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Send Start command once again */
- sysI2CStart ();
- /* Send the Read Command Control Byte */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE | I2C_24LC64_RD_EN);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Read data */
- I2C.i2cmcmd = I2CMCMD_CMD (RD);
- sysWbFlush ();
- devStatus = I2C.i2cms;
- if (!(devStatus & I2CMS_D))
- {
- /* Should have been done. Give some more time */
- sysUSecDelay (I2C_DELAY_MULT * 2500);
- devStatus = I2C.i2cms;
- if (!(devStatus & I2CMS_D))
- {
- /* waited long enough return ERROR */
- return (ERROR);
- }
- }
- /* Return the byte read */
- *byte = (int) I2C.i2cdi;
- return (OK);
- }
- /*****************************************************************************
- *
- * sysI2CSeqReadStart - Start a sequential read of I2C EEPROM.
- *
- * This function starts a bulk read from I2C EEPROM from the location
- * specified by <address>. Typically the call to this function would
- * be followed by up to (I2C Memory space in bytes - starting address)
- * reads. Its left to the caller to ensure that no rollover (reading
- * beyond the capacity of I2C) occurs.
- *
- * RETURNS: OK on success, ERROR otherwise
- *
- * SEE ALSO: sysI2CSeqRead(), sysI2CSeqReadLast()
- */
- STATUS sysI2CSeqReadStart
- (
- unsigned short address /* address of I2C beginning address */
- )
- {
- STATUS status; /* used to check the I2C status state */
- /* Send a Start command to I2C */
- status = sysI2CStart ();
- if (status == ERROR)
- return (ERROR);
- /* Write Control Byte */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - upper 8 bits */
- I2C.i2cdo = (unsigned int) ((address >> I2CDO_DATA_WIDTH)
- & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Address - lower 8 bits */
- I2C.i2cdo = (unsigned int) (address & I2CDO_DATA_MASK);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- /* Send another start command */
- status = sysI2CStart ();
- if (status == ERROR)
- return (ERROR);
- /* Read Command */
- I2C.i2cdo = (unsigned int) (I2C_24LC64_CNTL_BYTE | I2C_24LC64_RD_EN);
- I2C.i2cmcmd = I2CMCMD_CMD (WD);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- return (OK);
- }
- /*****************************************************************************
- *
- * sysI2CSeqRead - Read a sequential byte from I2C EEPROM
- *
- * This function reads a byte from the I2C internally maintained
- * address. A call to this function is part of sequential bulk data read
- * from I2C, beginning at an address specified by the previous call to
- * the sysI2CSeqReadStart() function.
- *
- * RETURNS: OK on success, ERROR otherwise
- *
- * SEE ALSO: sysI2CSeqReadStart(), sysI2CSeqReadLast()
- */
- STATUS sysI2CSeqRead
- (
- int * byte /* pointer to location for returned byte */
- )
- {
- STATUS status; /* used to check the I2C status state */
- /* Read data */
- I2C.i2cmcmd = I2CMCMD_CMD (RDACK);
- sysWbFlush ();
- status = sysI2CChkDone ();
- if (status == ERROR)
- return (ERROR);
- sysUSecDelay (I2C_DELAY_MULT * 600);
- *byte = (int) I2C.i2cdi;
- return (OK);
- }
- /******************************************************************************
- *
- * sysI2CSeqReadLast - Perform last sequential read from I2C EEPROM
- *
- * This function reads the last byte in a sequential read from I2C.
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CSeqReadLast
- (
- int * byte /* Pointer to location for returned byte */
- )
- {
- unsigned int devStatus; /* I2C device status */
- UINT32 startCount; /* Starting count for timeout */
- /* Read data */
- I2C.i2cmcmd = I2CMCMD_CMD (RD);
- sysWbFlush ();
- /* Check if Done flag is set in I2C Status, Please note that the slave
- * would not send the Ack for RD command
- */
- startCount = sysUSecTimoutStart ();
- while (!sysUSecTimoutExpired (startCount, I2C_DONE_TIMEOUT))
- {
- devStatus = I2C.i2cms;
- if (devStatus & I2CMS_D)
- {
- *byte = (int) I2C.i2cdi;
- return (OK);
- }
- }
- /* timed out */
- return (ERROR);
- }
- /******************************************************************************
- *
- * sysI2CPageWrite - Write a 32-byte page of data to I2C EEPROM
- *
- * This function writes a 32-bytes to the I2C at the specified address.
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CPageWrite
- (
- unsigned short address, /* address in the I2C to write */
- unsigned char * buffer /* pointer to a 32-byte buffer */
- )
- {
- STATUS status; /* used to check the status of I2C */
- int iCount; /* loop count */
- status = sysI2CPageWriteOpen (address);
- if (status != OK)
- return (ERROR);
- for (iCount = 0; iCount < I2C_EEPROM_PAGE_SIZE; iCount++)
- {
- status = sysI2CInPageWrite (buffer[iCount]);
- if (status != OK)
- return (ERROR);
- sysUSecDelay (I2C_DELAY_MULT * 5000);
- }
- /* Generate Stop to allow writing of data from the I2C internal
- * buffer to the EEPROM
- */
- sysI2CStop ();
- /* Perform Write Acknowledge Poll */
- sysUSecDelay (I2C_DELAY_MULT * 60000);
- return (OK);
- }
- /*****************************************************************************
- *
- * sysI2CByteWrite - Write up to 32 bytes to I2C EEPROM
- *
- * This function writes up to 32 bytes to the specified I2C EEPROM
- * location (<address>).
- *
- * RETURNS: OK on success, ERROR otherwise
- */
- STATUS sysI2CByteWrites
- (
- unsigned short address, /* address of I2C */
- unsigned char * buffer, /* input buffer, <numBytes> in length */
- unsigned int numBytes /* number of bytes to be written */
- )
- {
- STATUS status; /* Used to check the status of I2C */
- int iCount; /* loop count */
- status = sysI2CPageWriteOpen (address);
- if (status != OK)
- return (ERROR);
- for (iCount = 0;
- (iCount < numBytes) && (iCount < I2C_EEPROM_PAGE_SIZE);
- iCount++)
- {
- status = sysI2CInPageWrite (buffer[iCount]);
- if (status != OK)
- return (ERROR);
- sysUSecDelay (I2C_DELAY_MULT * 5000);
- }
- /* Generate Stop to allow writing of data from the I2C internal
- * buffer to the Eeprom
- */
- sysI2CStop ();
- sysUSecDelay (I2C_DELAY_MULT * 60000);
- return (OK);
- }
- /******************************************************************************
- *
- * sysI2CStringRead - Read a string from I2C EEPROM
- *
- * This function reads a string of length <numBytes> from the specified
- * <address> in I2C EEPROM, and adds an EOS to the return <string>. The
- * return <string> must be at least <numBytes> + 1 in length.
- *
- * RETURNS: OK on success, ERROR otherwise
- *
- * SEE ALSO: sysI2CStringWrite() */
- STATUS sysI2CStringRead
- (
- unsigned short address, /* address of I2C */
- UINT8 * string, /* output string */
- unsigned int numBytes /* number of bytes to read */
- )
- {
- STATUS status; /* used to check the status of I2C */
- int iCount; /* loop count */
- int byte; /* byte read */
- /* Sanity check */
- if (numBytes < 1) /* At least 1 byte must be read */
- return (ERROR);
- if (string == NULL) /* Null input string */
- return (ERROR);
- /* Check address range */
- if ((address + (UINT16) numBytes) > (UINT16) I2C_MEM_SIZE)
- return (ERROR);
- status = sysI2CSeqReadStart (address);
- /* check the returned status */
- if (status != OK)
- return (ERROR);
- for (iCount = 0; iCount < (numBytes - 1); iCount++)
- {
- status = sysI2CSeqRead (&byte);
- if (status != OK)
- return (ERROR);
- string[iCount] = byte;
- }
- sysUSecDelay (I2C_DELAY_MULT * 5000);
- /* Perform the last read operation */
- status = sysI2CSeqReadLast (&byte);
- if (status != OK)
- return (ERROR);
- string [numBytes - 1] = (char) byte;
- /* Append End of String */
- string [numBytes] = EOS;
- return (OK);
- }
- /******************************************************************************
- *
- * sysI2CStringWrite - Write a string to I2C EEPROM
- *
- * This function writes a string of length <numBytes> to the specified
- * <address> in I2C EEPROM. The EOS character is not written.
- *
- * RETURNS : OK on success, ERROR otherwise
- *
- * SEE ALSO: sysI2CStringRead()
- */
- STATUS sysI2CStringWrite
- (
- unsigned short address, /* address of I2C */
- UINT8 * string, /* input string */
- unsigned int numBytes /* number of bytes */
- )
- {
- STATUS status; /* Used to check the status of I2C */
- int iCount; /* loop count */
- unsigned int numOfPages; /* To determine no of pages */
- unsigned int numOfRemWrites;/* remaining byte writes */
- unsigned int memI2CRef = 0; /* To reference I2C memory */
- unsigned int pageAlign; /* used for data page aligning */
- unsigned int numOfPageAlignWrites = 0;
- status = ERROR;
- /* Sanity check */
- if (string == NULL) /* Null input string */
- return (ERROR);
- /* Check address */
- if (address > (UINT16) I2C_MEM_SIZE)
- return (ERROR);
- /* Check address range */
- if ((address + numBytes) > (UINT16) I2C_MEM_SIZE)
- return (ERROR);
- /* Align the input data correctly on page boundary */
- pageAlign = (unsigned int) (address & I2C_EEPROM_PAGE_BITS);
- numOfPageAlignWrites = I2C_EEPROM_PAGE_SIZE - pageAlign;
- if (numOfPageAlignWrites > numBytes)
- {
- /* call writeBytes and return*/
- status = sysI2CByteWrites (address, &string[0], numBytes);
- return (status);
- }
- else
- {
- /* first write numOfPageAlign bytes */
- status = sysI2CByteWrites (address, &string[0],
- numOfPageAlignWrites);
- /* bump up I2C memory address reference */
- memI2CRef += numOfPageAlignWrites;
- }
- /* Proceed with the remaining writes */
- numOfPages = (numBytes - numOfPageAlignWrites) / I2C_EEPROM_PAGE_SIZE;
- numOfRemWrites = (numBytes - numOfPageAlignWrites)
- % I2C_EEPROM_PAGE_SIZE;
- /* Start writing the pages first */
- for (iCount = 0; iCount < numOfPages; iCount++)
- {
- status = sysI2CPageWrite ((address + memI2CRef),&string[memI2CRef]);
- if (status != OK)
- {
- return (ERROR);
- }
- memI2CRef += I2C_EEPROM_PAGE_SIZE;
- }
- /* Now write the remaining bytes */
- if (numOfRemWrites)
- {
- status = sysI2CByteWrites ((address + memI2CRef),
- (&string[memI2CRef]), numOfRemWrites);
- }
- return (status);
- }
- #ifdef I2C_DEBUG
- /*****************************************************************************
- *
- * i2cTestSingleWrites - Perform single byte writes to I2C EEPROM
- *
- * This routine performs single bytes writes. Used to test atomic
- * writes to I2C.
- *
- * RETURNS : N/A
- *
- * NOMANUAL
- */
- void testSingleWrites
- (
- unsigned short address, /* I2C Address to write to */
- unsigned char * string, /* String data for writes */
- unsigned int numBytes /* number of bytes */
- )
- {
- STATUS status; /* to check I2C Status */
- int iCount; /* loop count */
- for (iCount = 0; iCount < numBytes; iCount++)
- {
- status = sysI2CByteWrite (address,string[iCount]);
- if (status != OK)
- {
- printf (" Single Write test failed !!! n");
- break;
- }
- printf (" Wrote character %dn", iCount);
- address += 1;
- }/* end of for loop */
- }
- /****************************************************************************
- *
- * i2cTestSingleRead - Perform single byte reads from I2C EEPROM.
- *
- * This routine performs single bytes reads. Used to test atomic reads to I2C
- *
- * RETURNS: N/A
- *
- * NOMANUAL
- */
- void testSingleReads
- (
- unsigned short address, /* I2C Address to write to */
- unsigned char * string, /* String data for writes */
- unsigned int numBytes /* number of bytes */
- )
- {
- STATUS status; /* to check I2C Status */
- int iCount; /* loop count */
- int byte; /* byte read */
- for (iCount = 0; iCount < numBytes; iCount++)
- {
- status = sysI2CByteRead (address, &byte);
- if (status == ERROR)
- {
- printf (" Single Read test failed !!! n");
- break;
- }
- string[iCount] = (char) byte;
- address += 1;
- } /* end of for loop */
- }
- #endif /* I2C_DEBUG */