⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dev_i2c_io.c

📁 i2c总线接口驱动程序
💻 C
字号:
/*===========================================================================    Copyright 2000, 2001 Holley Communications. All rights reserved.*//***************************************************************************** * * DEV_I2C_IO.C - I2C Interface: Hardware Interface * * PURPOSE: *    To provide hardware control of the low-level Inter-IC (I2C) signalling. *    This file provides functions to set and read the state of the two I2C *    control signals SCL (serial clock) and SDA (serial data). * * HISTORY: *    V 1.00 - Sep 25, 1997 - E.Schmidt    *             Creation *           - Apr 22, 1998 - G.Catt       *             Updated for use on the CDMA+ platform. *           - May 06, 1998 - G.Catt       *             Removed remnants of the I/O-mapped version. *           - May 11, 1998 - G.Catt       *             Initialized SDA and SCL output states to 'low' values *             and ensure pull-up 'high' is performed by switching to *             GPIO input mode. *             Reversed change because it didn't work. *           - May 12, 1998 - G.Catt       *             Removed extraneous code. *           - May 25, 1998 - G.Catt       *             Added logic to the signal initialization to set the SCL *             and SDA GPIO line directions to the output state prior setting *             their respective data latches to the '0' state for all time. *           - May 26, 1998 - G.Catt       *             Restored the logic to set the GPIO data latches to '0' *             when asserting either SDA or SCL because it is not possible *             to read the value of the data latch when the port is in *             input mode. * * GLOBAL FUNCTIONS: *    None * * LOCAL FUNCTIONS: *    'dev_i2c_io_initialize' - I2C I/O Signal Initialization *    'dev_i2c_io_scllow'   - Drive SCL Signal Low *    'dev_i2c_io_scltristate' - Tri-state the SCL Signal *    'dev_i2c_io_sdalow'   - Drive SDA Signal Low *    'dev_i2c_io_sdatristate' - Tri-state the SDA Signal *    'dev_i2c_io_sclstate' - Get SCL Signal State *    'dev_i2c_io_sdastate' - Get SDA Signal State * * INTERNAL FUNCTIONS: *    None * * NOTE: *    The I2C signalling relies on the application of external pull-up *    resistors to ensure that the slave devices see 'high' levels when *    this logic tri-states a specific signal. * * *****************************************************************************//* ------------------ D e f i n i t i o n   F i l e s --------------------- */#include "main_system.h"            /* System Environment */#include "main_config.h"#include "main_io_cdmap.h"#include "pub_PIO.h"#include "dev_I2c_Global.h"             /* Global definitions */#include "dev_i2c_local.h"              /* Local definitions */#include "dev_i2c_io.h"                 /* Internal definitions *//* ------------------------ L o c a l   D a t a --------------------------- *//* --------------------- I n t e r n a l   D a t a ------------------------ *//***************************************************************************** * * DEV_I2C_IO_INITIALIZE - I2C I/O Signal Initialization * * PURPOSE: *    To initialize the initial hardware state of the I2C signalling *    subsystem. Both control signal lines (SDA and SCL) are tri-stated *    to allow the initial bus state to be analyzed. * * PARAMETERS: *    None * * RETURNS: *    DEV_I2C_RETCODE_SUCCESS   => I2C signals are ready for use *    DEV_I2C_RETCODE_IOINITERR => I/O line initialization error (not used) * * NOTE: *    The signal data port latches are pre-initialized to the 'zero' *    (asserted) state. This ensures that in order to assert either the *    SCL or the SDA signal in subsequent signalling operations only *    the respective GPIO direction register bit needs to be set to *    the output state. * *****************************************************************************/void dev_i2c_io_initialize ( void ){    /*--- Pre-set the GPIO data port latches with zeroes ---*/    /* Ensure that the SCL GPIO line is an output */    SET_DIR_SCL(PIO_OUTPUT);       /* Pre-set the serial clock line (SCL) output value to 'Low' */    WRITE_SCL(PIO_LOW);       /* Ensure that the SDA GPIO line is an output */    SET_DIR_SDA(PIO_OUTPUT);       /* Pre-set the serial data line (SDA) output value 'Low' */    WRITE_SDA(PIO_LOW);       /* Ensure that the serial clock line (SCL) is an input (tri-stated) */    dev_i2c_io_scltristate ();    /* Ensure that the serial data line  (SDA) is an input (tri-stated) */    dev_i2c_io_sdatristate ();#if BOARD_PHOENIX    /* Ensure that the SLAVE_I2C_MUTE GPIO line is an input */    DEV_PIO_SetInput(UIM_SLAVE_I2C_MUTE);      #if UIM_ENABLED    DEV_PIO_SetOutput(UIM_WAKEUP_SLAVE);       DEV_PIO_WRITE_HIGH(UIM_WAKEUP_SLAVE);    DEV_PIO_SetOutput(UIM_SHUTDOWN);       DEV_PIO_WRITE_HIGH(UIM_SHUTDOWN);#else    DEV_PIO_SetInput(UIM_WAKEUP_SLAVE);       DEV_PIO_SetOutput(UIM_SHUTDOWN);       DEV_PIO_WRITE_LOW(UIM_SHUTDOWN);#endif#endif} /***************************************************************************** * * DEV_I2C_IO_SCLSTATE - Get SCL Signal State * * PURPOSE: *    To determine the current state of the serial clock signal (SCL). The *    I/O line is first tri-stated and then its value is read via the GPIO *    data port. * * PARAMETERS: *    None * * RETURNS: *    DEV_I2C_SIGNAL_INACTIVE => SCL signal is not being driven *    DEV_I2C_SIGNAL_ASSERT   => SCL signal is asserted * * NOTE: *    Once the signal is tri-stated it will be pulled high by external *    resistors if not driven low by a slave device. *     *****************************************************************************/Bool dev_i2c_io_sclstate ( void ){   /* Tri-state the SCL line */   dev_i2c_io_scltristate ();   /* If the SCL line is high */   if ( READ_SCL() )   {      /* ... the signal is inactive */      return ( DEV_I2C_SIGNAL_INACTIVE );   }   else   {      /* ... the signal is asserted */      return ( DEV_I2C_SIGNAL_ASSERT );   }}/***************************************************************************** * * DEV_I2C_IO_SDASTATE - Get SDA Signal State * * PURPOSE: *    To determine the current state of the serial data line (SDA). The *    I/O line is first tri-stated and then its value is read via the GPIO *    data port. * * PARAMETERS: *    None * * RETURNS: *    DEV_I2C_SIGNAL_INACTIVE => SDA signal is not being driven *    DEV_I2C_SIGNAL_ASSERT   => SDA signal is asserted * * NOTE: *    Once the signal is tri-stated it will be pulled high by external *    resistors if not driven low by a slave device. *     *****************************************************************************/Bool dev_i2c_io_sdastate ( void ){   /* Tri-state the SDA line */   dev_i2c_io_sdatristate ();   /* If the SDA line is high */   if ( READ_SDA() )   {      /* ... the signal is inactive */      return ( DEV_I2C_SIGNAL_INACTIVE );   }   else   {      /* ... the signal is asserted */      return ( DEV_I2C_SIGNAL_ASSERT );   }}/***************************************************************************** * * DEV_SLAVE_I2C_MUTE_STATE - Get SLAVE_I2C_MUTE Signal State * * PURPOSE: * * PARAMETERS: *    None * * RETURNS: *    DEV_I2C_SIGNAL_INACTIVE => SLAVE_I2C_MUTE signal is not being driven *    DEV_I2C_SIGNAL_ASSERT   => SLAVE_I2C_MUTE signal is asserted * * NOTE: *****************************************************************************/Bool dev_slave_i2c_mute_state ( void ){   if ( READ_I2C_SLAVE_MUTE() )   {      /* ... the signal is inactive */      return ( DEV_I2C_SIGNAL_INACTIVE );   }   else   {      /* ... the signal is asserted */      return ( DEV_I2C_SIGNAL_ASSERT );   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -