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

📄 i2cdriver.c

📁 mpc860 i2c driver for vxworks
💻 C
字号:
/* I2cDriver.c -  MPC860 I2c driver functions * *  Copyright  (c)  2002  UTStarcom, Inc. *          All Rights Reserved. * *  Subsystem:		VDSL *  File:     		ppc860I2c.c *  Created By:   	DQXie *  Created On:     25/2/2002 *   *  Purpose:  *    This file contains I2C driver functions called by applications. */#include "copyright_wrs.h"#include "vxWorks.h"#include "config.h"#include "vxLib.h"#include "iv.h"#include "intLib.h"#include "semLib.h"#include "sysLib.h"/*	#include "logLib.h"*/#include "taskLib.h"#include "cacheLib.h"#include "stdio.h"#include "drv/sio/ppc860Sio.h"#include "drv/multi/ppc860Cpm.h"#include "drv/intrCtl/ppc860Intr.h"#include "I2cDriver.h"#include "ppc860I2c.h"#include "string.h"/* Local value defines *//******************************************************** * I2cDriverInit: to init I2C * parameters: *  I2cMode:	0 --- slave *        		1 --- master *	eventFunc --- an event handling function pointer * * returns: *	OK    --- init success; *	ERROR --- init fail; */STATUS I2cDriverInit(char mode, VOIDFUNCPTR eventFunc){	VPFUNCPTR	I2cAlloc;	FUNCPTR		I2cFree;	if (ppc860I2cHwInit(mode) != I2COK)	{		I2CPRINT("I2cDriverInit: init failed!\n");		return ERROR;	}		I2cAlloc = cacheDmaMalloc;	I2cFree  = cacheDmaFree;#if 0#ifdef	INCLUDE_CACHE_SUPPORT	I2cAlloc = cacheDmaMalloc;	I2cFree  = cacheDmaFree;#else	/* cache is disabled */	I2cAlloc = (VPFUNCPTR)malloc;	I2cFree  = (FUNCPTR)free;#endif	/* I2C_CACHE_ENABLE */#endif	if (ppc860I2cOpen(eventFunc, I2cAlloc, I2cFree) != I2COK)	{		I2CPRINT("I2cDriverInit: open failed!\n");		return ERROR;	}	I2CPRINT("I2cDriverInit: OK!\n");	return OK;}/******************************************************** * I2cDriverWrite: transmit I2C data * NOTE: if mpc860 acts as an I2C master, the data  *   length should not be larger than (I2C_DATA_SZ_MAX - 1) * * parameters: *	pData  --- point to the data buffer containing the  *             data to be transmitted. *	length --- the byte number of the data in the buffer *             pData points to. * returns: *	length		--- success. *	ERROR(-1)	--- failed. */int I2cDriverWrite(char* pData, UINT16 length){	if (pData == NULL || length == 0)	{		I2CPRINT("I2CDriverWrite: data pointer is NULL or NO data in data buffer!\n");		return ERROR;	}	if (length > I2C_DATA_SZ_MAX)	{		I2CPRINT("I2CDriverWrite: data length(=%d) is too large!\n", length);		I2CPRINT("\tMax data length is defined as %d\n", I2C_DATA_SZ_MAX);		return ERROR;	}	if (ppc860I2cWrite(pData, length) == I2CERROR)	{/*		I2CPRINT("I2cDriverWrite: failed!\n");*/		return ERROR;	}/*	I2CPRINT("I2cDriverWrite: write buffer OK!\n");*/	return length;}/******************************************************** * I2cDriverRead: read I2C data (I2C master mode) * * parameters: * * returns: *	ERROR(-1)	--- failed. */STATUS I2CDriverRead(void){	char data = (char)((MPC860_I2C_SLAVE_ADDR << 1) + 1);	UINT16 dataLength = 1;	if (ppc860I2cWrite(&data, dataLength) != I2COK)	{		I2CPRINT("I2cDriverWrite: failed!\n");		return ERROR;	}	return OK;}

⌨️ 快捷键说明

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