📄 i2capi.c
字号:
//============================================================================// File Name: i2capi.c//// (c) Copyright [2002] Cirrus Logic Inc. All rights reserved//// This source code is Cirrus Logic, Inc. proprietary and confidential// information//// Description:// This unit provides generic functions to manipulate the I2C pins. The// I/O pins are board specific and are defined in this unit.//// Modification History:// $Id: i2capi.c,v 1.6 2004/10/14 18:11:26 bchow Exp $// $Log: i2capi.c,v $// Revision 1.6 2004/10/14 18:11:26 bchow// Bug 27549// Fix "warning: no newline at end of file" from new compiler//// Revision 1.5 2004/08/16 17:33:53 yingc// Replace SONATA_APP with RECORD_APP//// Revision 1.4 2003/11/26 01:21:32 anup// cdb98200 target build//// Revision 1.3 2003/11/20 21:32:17 matthieu// Remove the //Perl skip lines...//// Revision 1.2 2003/11/20 08:42:09 akipnis// Renamed CLASI functions and responses to follow naming conventions//// Revision 1.1 2003/09/11 00:55:02 matthieu// Initial Sonata 2 tree//// Revision 1.1.1.1 2003/06/27 03:14:12 jalves// initial check in//// Revision 1.1.1.1 2003/06/06 20:59:06 matthieu// LG code// Initial code from sonata tree with tag : MATT_20030606//// Revision 1.4 2003/05/14 01:32:46 matthieu// Merge to DVDev_2-4-8//// Revision 1.3 2003/03/06 20:28:34 matthieu// to get the dvd code (target cdb98200) to compile...//// Revision 1.2 2003/01/29 18:37:27 matthieu// merging branch with Y14_20030103 code (new atapi driver)//// Revision 1.1.2.2 2003/01/11 02:01:33 jsu// disable and remove SW I2C APIs (used by at24c01 and at24c02 eeprom)//// Revision 1.1.2.1 2003/01/09 01:49:35 matthieu// merging Y14 code up to Y14-20021115 tag// has got audio and stability issues//// Revision 1.2 2002/11/15 22:28:29 jtodd// Integration of Bug #182 and #234.//// Revision 1.1.2.1 2002/11/14 13:41:16 mlese// Initial check in for board specific control of I2C bus.////============================================================================#if (BSP_CDB98200 != 1)/* keep a stub here to allow compile */void i2capi_stub(){}// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX// Below is a version of the software I2C driver, DO NOT USE for Sonata// it conflicts with the HW I2C driver we are using. This means at24c01// and at24c02 are NOT supported by Sonata because these drivers were written// to use the SW I2C driver. The m24c16 driver is written to use the HW// I2C driver.// jsu 01-08-2003//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#else#include "dvhw32.h"#include "hw_alloc.h"#include "i2capi.h"#include "i2creg.h" // board specific register declarations//-----------------------------------------------------------------------------// External definitions//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Local definitions//-----------------------------------------------------------------------------#define AT_SCL GetI2C_ClkBitPosition()#define AT_SDA GetI2C_DataBitPosition()#define I2C_MODE_REGISTER GetI2C_ModeRegister()#define I2C_READ_DATA_REGISTER GetI2C_ReadDataRegister()#define I2C_WRITE_DATA_REGISTER GetI2C_WriteDataRegister()#define I2C_TRI_STATE_REGISTER GetI2C_TriStateRegister()//-----------------------------------------------------------------------------// Local variables//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Local functions//---------------------------------------------------------------------------//-----------------------------------------------------------------------------// Function:void I2C_SetClkBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_SetGPIOBits( I2C_WRITE_DATA_REGISTER, AT_SCL ); // Uint32 newValue = DV_ReadREG(I2C_WRITE_DATA_REGISTER) | AT_SCL;// DV_WriteREG(I2C_WRITE_DATA_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_SetDataBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_SetGPIOBits( I2C_WRITE_DATA_REGISTER, AT_SDA ); // Uint32 newValue = DV_ReadREG(I2C_WRITE_DATA_REGISTER) | AT_SDA;// DV_WriteREG(I2C_WRITE_DATA_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_SetClkTriStateEnableBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_SetGPIOBits( I2C_TRI_STATE_REGISTER, AT_SCL ); // Uint32 newValue = DV_ReadREG(I2C_TRI_STATE_REGISTER) | AT_SCL;// DV_WriteREG(I2C_TRI_STATE_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_SetDataTriStateEnableBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_SetGPIOBits( I2C_TRI_STATE_REGISTER, AT_SDA ); // Uint32 newValue = DV_ReadREG(I2C_TRI_STATE_REGISTER) | AT_SDA;// DV_WriteREG(I2C_TRI_STATE_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_ClearClkBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_ClearGPIOBits( I2C_WRITE_DATA_REGISTER, AT_SCL ); // Uint32 newValue = DV_ReadREG(I2C_WRITE_DATA_REGISTER) & ~AT_SCL;// DV_WriteREG(I2C_WRITE_DATA_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_ClearDataBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_ClearGPIOBits( I2C_WRITE_DATA_REGISTER, AT_SDA ); // Uint32 newValue = DV_ReadREG(I2C_WRITE_DATA_REGISTER) & ~AT_SDA;// DV_WriteREG(I2C_WRITE_DATA_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_ClearClkTriStateEnableBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_ClearGPIOBits( I2C_TRI_STATE_REGISTER, AT_SCL ); // Uint32 newValue = DV_ReadREG(I2C_TRI_STATE_REGISTER) & ~AT_SCL;// DV_WriteREG(I2C_TRI_STATE_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:void I2C_ClearDataTriStateEnableBit(//// Description://// Notes://// Parameters: void)//// Returns:////-----------------------------------------------------------------------------{ DV_ClearGPIOBits( I2C_TRI_STATE_REGISTER, AT_SDA ); // Uint32 newValue = DV_ReadREG(I2C_TRI_STATE_REGISTER) & ~AT_SDA;// DV_WriteREG(I2C_TRI_STATE_REGISTER, newValue);}//-----------------------------------------------------------------------------// Function:Boolean I2C_GetClkBit(//// Description://// Notes://// Parameters: void)//// Returns:// The value of the clock bit.////-----------------------------------------------------------------------------{ return ((DV_ReadREG(I2C_READ_DATA_REGISTER) & AT_SCL) == AT_SCL);}//-----------------------------------------------------------------------------// Function:Boolean I2C_GetDataBit(//// Description://// Notes://// Parameters: void)//// Returns:// The value of the data bit.////-----------------------------------------------------------------------------{ return ((DV_ReadREG(I2C_READ_DATA_REGISTER) & AT_SDA) == AT_SDA);}//-----------------------------------------------------------------------------// Function:void I2C_ProtectionStart(void)//// Description:// Waits for the EEPROM semaphore to be cleared then sets it.// Parameters://// Returns:// n/a////----------------------------------------------------------------------------{ // mvl 05 JUN 2002 while (!HW_SemRead(eepromSemId)); HW_SemWrite(eepromSemId, 0);} // end ProtectionStart//-----------------------------------------------------------------------------// Function:void I2C_ProtectionEnd(void)//// Description:// Clears the EEPROM semaphore.//// Parameters://// Returns:// n/a////----------------------------------------------------------------------------{ // mvl 05 JUN 2002 HW_SemWrite(eepromSemId, 1);} // end ProtectionEnd//-----------------------------------------------------------------------------// Function:Uint32 I2C_GetModeRegister(//// Description://// Notes://// Parameters: void)//// Returns:// The value of the 32-bit register if the mode register is used, else// 0xffffffff is returned.////-----------------------------------------------------------------------------{ Uint32 modeValue = 0xffffffff; if ( I2C_UsesModeRegister() == TRUE ) { modeValue = DV_ReadREG(I2C_MODE_REGISTER); } return modeValue;}//-----------------------------------------------------------------------------// Function:Boolean I2C_UsesModeRegister(//// Description:// This function returns TRUE if I2C requires configuration of the MODE// register. The user must call I2C_ConfigurePort(TRUE) at least once,// if the mode register is being used.//// Parameters: void)//// Returns:// TRUE if the mode register is used, FALSE otherwise.////----------------------------------------------------------------------------{ return IsI2C_ModeRegisterUsed();}//-----------------------------------------------------------------------------// Function:void I2C_ConfigurePort(//// Description:// On some boards, the pins used for I2C have alternate use. This// function configures the port for I2C if the argument is TRUE, else is// sets the port to its default configuration. This function may be// called for any configuration, but only has an effect when the MODE// register is in use.//// Parameters: Boolean bForI2C)//// Returns:// n/a////----------------------------------------------------------------------------{ // Configure only if a mode register is used. if ( I2C_UsesModeRegister() == TRUE ) {// Uint32 mode = DV_ReadREG(I2C_MODE_REGISTER); if ( TRUE == bForI2C ) { // configure for I2C// DV_WriteREG(I2C_MODE_REGISTER, mode | (AT_SCL | AT_SDA)); DV_SetGPIOBits( I2C_MODE_REGISTER, ( AT_SCL | AT_SDA ) ); } else { // configure for default// DV_WriteREG(I2C_MODE_REGISTER, mode & ~(AT_SCL | AT_SDA)); DV_ClearGPIOBits( I2C_MODE_REGISTER, ( AT_SCL | AT_SDA ) ); } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -