📄 xiic_slave.c
字号:
/* $Id: xiic_slave.c,v 1.1 2007/12/03 15:44:58 meinelte Exp $ *//******************************************************************************** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"* AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND* SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,* OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,* APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION* THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,* AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE* FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY* WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE* IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR* REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF* INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS* FOR A PARTICULAR PURPOSE.** (c) Copyright 2002 Xilinx Inc.* All rights reserved.*******************************************************************************//*****************************************************************************//**** @file xiic_slave.c** Contains slave functions for the XIic component. This file is necessary when* slave operations, sending and receiving data as a slave on the IIC bus,* are desired.** <pre>* MODIFICATION HISTORY:** Ver Who Date Changes* ----- --- ------- -----------------------------------------------* 1.01b jhl 3/26/02 repartioned the driver* 1.01c ecm 12/05/02 new rev* 1.13a wgr 03/22/07 Converted to new coding style.* </pre>*****************************************************************************//***************************** Include Files *******************************/#include "xiic.h"#include "xiic_i.h"#include "xio.h"/************************** Constant Definitions ***************************//**************************** Type Definitions *****************************//***************** Macros (Inline Functions) Definitions *******************//************************** Function Prototypes ****************************/static void AddrAsSlaveHandler(XIic * InstancePtr);static void NotAddrAsSlaveHandler(XIic * InstancePtr);static void RecvSlaveData(XIic * InstancePtr);static void SendSlaveData(XIic * InstancePtr);/************************** Variable Definitions **************************//******************************************************************************* This function includes slave code such that slave events will be processsed.* It is necessary to allow slave code to be optional to reduce the size of* the driver. This function may be called at any time but must be prior to* being selected as a slave on the IIC bus. This function may be called prior* to the Initialize() function and must be called before any functions in the* file are called.*******************************************************************************/void XIic_SlaveInclude(){ XIic_AddrAsSlaveFuncPtr = AddrAsSlaveHandler; XIic_NotAddrAsSlaveFuncPtr = NotAddrAsSlaveHandler; XIic_RecvSlaveFuncPtr = RecvSlaveData; XIic_SendSlaveFuncPtr = SendSlaveData;}/******************************************************************************* This function sends data as a slave on the IIC bus and should not be called* until an event has occurred that indicates the device has been selected by* a master attempting read from the slave (XII_MASTER_READ_EVENT).*** @param InstancePtr is a pointer to the XIic instance to be worked on.* @param TxMsgPtr is a pointer to the data to be transmitted* @param ByteCount is the number of message bytes to be sent** @return** - XST_SUCCESS indicates the message transmission has been initiated.* - XST_IIC_NOT_SLAVE indicates the device has not been selected to be a slave* on the IIC bus such that data cannot be sent.*******************************************************************************/int XIic_SlaveSend(XIic * InstancePtr, u8 *TxMsgPtr, int ByteCount){ u8 IntrStatus; u8 Status; /* If the device is not a slave on the IIC bus then indicate an error * because data cannot be sent on the bus */ Status = XIo_In8(InstancePtr->BaseAddress + XIIC_SR_REG_OFFSET); if ((Status & XIIC_SR_ADDR_AS_SLAVE_MASK) == 0) { return XST_IIC_NOT_SLAVE; } XIic_mEnterCriticalRegion(InstancePtr->BaseAddress); /* Save message state and invalidate the receive buffer pointer to indicate * the direction of transfer is sending */ InstancePtr->SendByteCount = ByteCount; InstancePtr->SendBufferPtr = TxMsgPtr; InstancePtr->RecvBufferPtr = NULL; /* Start sending the specified data and then interrupt processing will * complete it */ XIic_TransmitFifoFill(InstancePtr, XIIC_SLAVE_ROLE); /* Clear any pending Tx empty, Tx Error and interrupt then enable them. * The Tx error interrupt indicates when the message is complete. * If data remaining to be sent, clear and enable Tx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -