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

📄 i2c.h

📁 基于ecos的redboot
💻 H
字号:
/* i2c.h
---------------------------------------------------------------------------
                 Copyright (c) 2002, 2003 Intel Corporation
						 All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. 
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. 
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      
---------------------------------------------------------------------------
system: IXDP2400
subsystem: BootMonitor
author: gvaddadi
revisions:
--------------------------------------------------------------------------
*/

#ifndef I2C_H
#define I2C_H

#include <cyg/hal/hal_platform_ints.h>

#define LOW 0
#define HIGH 1

/*write this POSR to drive the clock pin (GPIO pin 7)High and POCR for LOW*/
#define CLOCK	        0x80 

/*write this POSR to drive the data pin (gpio pin 6)High and POCR for LOW*/
#define DATA	        0x40 

/*This GPIO bit 2 has to be configured as output and drive a high to cause 
 *a pull up on the SDA line.
 */
#define I2C_INIT_BIT    0x04 

/*hal_delay_us() is defined in ixdp2400_misc.c*/
#define I2C_DELAY(n)                HAL_DELAY_US(n);
#define CLOCK_LOW_TIME	            3
#define CLOCK_HIGH_TIME	            3
#define START_CONDITION_HOLD_TIME   3
#define STOP_CONDITION_HOLD_TIME    3

#define I2C_ERROR  	1
#define I2C_NOERR	0
#define I2C_READ    0x01
#define I2C_WRITE   0x0

#define SLAVE_ADDR_0 0xa0 /*ie., a2,a1,a0 bits are 000*/
#define SLAVE_ADDR_1 0xa2 /*ie., a2,a1,a0 bits are 001*/
#define SLAVE_ADDR_2 0xa4 /*ie., a2,a1,a0 bits are 010*/
#define SLAVE_ADDR_3 0xa6 /*ie., a2,a1,a0 bits are 011*/
#define SLAVE_ADDR_4 0xa8 /*ie., a2,a1,a0 bits are 100*/
#define SLAVE_ADDR_5 0xaa /*ie., a2,a1,a0 bits are 101*/

#define NULL_DEV_ID		0x0
#define INVALID_DEV_ID	0xFF
#define KI_DEV_ID		0x1
#define BI_DEV_ID		0x2
#define MI_DEV_ID		0x3
#define BD_DEV_ID		0x4
#define BW_DEV_ID		0x5
#define PL_DEV_ID		0x6
#define TC_DEV_ID		0x7

/*
 *   slave address = DEV_TYPE | DEV_ADDR | MODE .  
 *   Device type is fixed to 1010 i.e., 0xa. 
 *   ___________________________________
 *   1 | 0 | 1 | 0 | A2 | A1 | A0| R/W|
 *   -----------------------------------
 * The LSB is r/W bit. if it is 1 the slave is in read mode and if it is 0 
 * the slave is in write mode.
 */

#define I2C_BUFSIZE	256

                
#define REG_WRITE(reg,data) \
        (*((volatile unsigned int *)(reg)) = (data))

#define REG_READ(reg) \
        (*((volatile unsigned int *)(reg)))

/*Function prototypes*/
int i2c_read(unsigned char slave, unsigned char word_address, unsigned char *x);
void i2c_write(unsigned char slave, unsigned char addr, unsigned char data);
int i2c_page_write(unsigned char slave, unsigned char addr, 
                 unsigned char * data, unsigned char count);
int i2c_seq_read(unsigned char slave, unsigned char addr, unsigned char * ptr,
                                                          unsigned char count);
#endif

⌨️ 快捷键说明

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