iicps_v3_0: Modified the examples for iic.
This patch modifies the examples for iicps so that it will work for both zynq and Alto. Signed-off-by: P L Sai Krishna <lakshmis@xilinx.com>
This commit is contained in:
parent
3f029f1c87
commit
94f296d809
3 changed files with 156 additions and 118 deletions
|
@ -77,6 +77,7 @@
|
|||
#include "xscugic.h"
|
||||
#include "xil_exception.h"
|
||||
#include "xil_printf.h"
|
||||
#include "xplatform_info.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
@ -114,7 +115,7 @@
|
|||
* The AddressType should be u8 as the address pointer in the on-board
|
||||
* EEPROM is 1 byte.
|
||||
*/
|
||||
typedef u8 AddressType;
|
||||
typedef u16 AddressType;
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
@ -133,6 +134,7 @@ static void Handler(void *CallBackRef, u32 Event);
|
|||
|
||||
XIicPs IicInstance; /* The instance of the IIC device. */
|
||||
XScuGic InterruptController; /* The instance of the Interrupt Controller. */
|
||||
u32 Platform;
|
||||
|
||||
/*
|
||||
* Write buffer for writing a page.
|
||||
|
@ -195,6 +197,7 @@ int IicPsEepromIntrExample(void)
|
|||
int Status;
|
||||
XIicPs_Config *ConfigPtr; /* Pointer to configuration data */
|
||||
AddressType Address = EEPROM_START_ADDRESS;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Initialize the IIC driver so that it is ready to use.
|
||||
|
@ -232,49 +235,13 @@ int IicPsEepromIntrExample(void)
|
|||
XIicPs_SetSClk(&IicInstance, IIC_SCLK_RATE);
|
||||
|
||||
/*
|
||||
* Set the channel value in IIC Mux.
|
||||
* Set the channel value in IIC Mux if
|
||||
* it is Zynq platform
|
||||
*/
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(Address) + Index] = 0xFF;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(Address) + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from the EEPROM.
|
||||
*/
|
||||
Status = EepromReadData(ReadBuffer, PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
|
||||
Platform = XGetPlatform_Info();
|
||||
if(Platform == XPLAT_ZYNQ) {
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -282,22 +249,24 @@ int IicPsEepromIntrExample(void)
|
|||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(Address) + Index] = Index + 10;
|
||||
WriteBuffer[WrBfrOffset + Index] = 0xFF;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(Address) + PAGE_SIZE);
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
@ -314,7 +283,49 @@ int IicPsEepromIntrExample(void)
|
|||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[WrBfrOffset + Index] = Index + 10;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from the EEPROM.
|
||||
*/
|
||||
Status = EepromReadData(ReadBuffer, PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -387,19 +398,21 @@ int EepromReadData(u8 *BufferPtr, u16 ByteCount)
|
|||
{
|
||||
int Status;
|
||||
AddressType Address = EEPROM_START_ADDRESS;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Position the Pointer in EEPROM.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
}
|
||||
else {
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
Status = EepromWriteData(sizeof(Address));
|
||||
Status = EepromWriteData(WrBfrOffset);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
#include "sleep.h"
|
||||
#include "xiicps.h"
|
||||
#include "xil_printf.h"
|
||||
#include "xplatform_info.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
@ -110,7 +111,7 @@
|
|||
* The AddressType should be u8 as the address pointer in the on-board
|
||||
* EEPROM is 1 bytes.
|
||||
*/
|
||||
typedef u8 AddressType;
|
||||
typedef u16 AddressType;
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
@ -124,6 +125,7 @@ int EepromReadData(u8 *BufferPtr, u16 ByteCount);
|
|||
/************************** Variable Definitions *****************************/
|
||||
|
||||
XIicPs IicInstance; /* The instance of the IIC device. */
|
||||
u32 Platform;
|
||||
|
||||
/*
|
||||
* Write buffer for writing a page.
|
||||
|
@ -182,6 +184,7 @@ int IicPsEepromPolledExample(void)
|
|||
int Status;
|
||||
XIicPs_Config *ConfigPtr; /* Pointer to configuration data */
|
||||
AddressType Address = EEPROM_START_ADDRESS;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Initialize the IIC driver so that it is ready to use.
|
||||
|
@ -203,49 +206,13 @@ int IicPsEepromPolledExample(void)
|
|||
XIicPs_SetSClk(&IicInstance, IIC_SCLK_RATE);
|
||||
|
||||
/*
|
||||
* Set the channel value in IIC Mux.
|
||||
* Set the channel value in IIC Mux if
|
||||
* it is Zynq platform
|
||||
*/
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(Address) + Index] = 0xFF;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(Address) + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from the EEPROM.
|
||||
*/
|
||||
Status = EepromReadData(ReadBuffer, PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
|
||||
Platform = XGetPlatform_Info();
|
||||
if(Platform == XPLAT_ZYNQ) {
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -253,22 +220,24 @@ int IicPsEepromPolledExample(void)
|
|||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(Address) + Index] = Index + 10;
|
||||
WriteBuffer[WrBfrOffset + Index] = 0xFF;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(Address) + PAGE_SIZE);
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
@ -285,7 +254,49 @@ int IicPsEepromPolledExample(void)
|
|||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[WrBfrOffset + Index] = Index + 10;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from the EEPROM.
|
||||
*/
|
||||
Status = EepromReadData(ReadBuffer, PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the data read against the data written.
|
||||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
if (ReadBuffer[Index] != WriteBuffer[Index + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -348,19 +359,21 @@ int EepromReadData(u8 *BufferPtr, u16 ByteCount)
|
|||
{
|
||||
int Status;
|
||||
AddressType Address = EEPROM_START_ADDRESS;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Position the Pointer in EEPROM.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
}
|
||||
else {
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
Status = EepromWriteData(sizeof(Address));
|
||||
Status = EepromWriteData(WrBfrOffset);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include "sleep.h"
|
||||
#include "xiicps.h"
|
||||
#include "xil_printf.h"
|
||||
#include "xplatform_info.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
@ -106,7 +107,7 @@
|
|||
* The AddressType should be u8 as the address pointer in the on-board
|
||||
* EEPROM is 1 bytes.
|
||||
*/
|
||||
typedef u8 AddressType;
|
||||
typedef u16 AddressType;
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
@ -120,6 +121,7 @@ int EepromReadDataRepStart(u8 *BufferPtr, u16 ByteCount);
|
|||
/************************** Variable Definitions *****************************/
|
||||
|
||||
XIicPs IicInstance; /* The instance of the IIC device. */
|
||||
u32 Platform;
|
||||
|
||||
/*
|
||||
* Write buffer for writing a page.
|
||||
|
@ -183,6 +185,7 @@ int IicPsRepeatedStartExample(void)
|
|||
AddressType AddressTemp;
|
||||
int PageCnt;
|
||||
int NumPages = 16;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Initialize the IIC driver so that it is ready to use.
|
||||
|
@ -206,9 +209,12 @@ int IicPsRepeatedStartExample(void)
|
|||
/*
|
||||
* Set the channel value in IIC Mux.
|
||||
*/
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
Platform = XGetPlatform_Info();
|
||||
if(Platform == XPLAT_ZYNQ) {
|
||||
Status = MuxInit();
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
AddressTemp = Address;
|
||||
|
@ -216,22 +222,24 @@ int IicPsRepeatedStartExample(void)
|
|||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(AddressTemp) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (AddressTemp);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (AddressTemp >> 8);
|
||||
WriteBuffer[1] = (u8) (AddressTemp);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(AddressTemp) + Index] = 0xFF;
|
||||
WriteBuffer[WrBfrOffset + Index] = 0xFF;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(AddressTemp) + PAGE_SIZE);
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
@ -252,7 +260,7 @@ int IicPsRepeatedStartExample(void)
|
|||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE*NumPages; Index++) {
|
||||
if (ReadBuffer[Index] !=
|
||||
WriteBuffer[Index%PAGE_SIZE + sizeof(Address)]) {
|
||||
WriteBuffer[Index%PAGE_SIZE + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -264,22 +272,24 @@ int IicPsRepeatedStartExample(void)
|
|||
/*
|
||||
* Initialize the data to write and the read buffer.
|
||||
*/
|
||||
if (sizeof(AddressTemp) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (AddressTemp);
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (AddressTemp >> 8);
|
||||
WriteBuffer[1] = (u8) (AddressTemp);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PAGE_SIZE; Index++) {
|
||||
WriteBuffer[sizeof(AddressTemp) + Index] = Index + 10;
|
||||
WriteBuffer[WrBfrOffset + Index] = Index + 10;
|
||||
ReadBuffer[Index] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the EEPROM.
|
||||
*/
|
||||
Status = EepromWriteData(sizeof(AddressTemp) + PAGE_SIZE);
|
||||
Status = EepromWriteData(WrBfrOffset + PAGE_SIZE);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
@ -299,7 +309,7 @@ int IicPsRepeatedStartExample(void)
|
|||
*/
|
||||
for (Index = 0; Index < PAGE_SIZE*NumPages; Index++) {
|
||||
if (ReadBuffer[Index] !=
|
||||
WriteBuffer[Index%PAGE_SIZE + sizeof(Address)]) {
|
||||
WriteBuffer[Index%PAGE_SIZE + WrBfrOffset]) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -366,6 +376,7 @@ int EepromReadDataRepStart(u8 *BufferPtr, u16 ByteCount)
|
|||
{
|
||||
int Status;
|
||||
AddressType Address = EEPROM_START_ADDRESS;
|
||||
int WrBfrOffset;
|
||||
|
||||
/*
|
||||
* Enable repeated start option.
|
||||
|
@ -377,15 +388,16 @@ int EepromReadDataRepStart(u8 *BufferPtr, u16 ByteCount)
|
|||
/*
|
||||
* Position the Pointer in EEPROM.
|
||||
*/
|
||||
if (sizeof(Address) == 1) {
|
||||
if (Platform == XPLAT_ZYNQ) {
|
||||
WriteBuffer[0] = (u8) (Address);
|
||||
}
|
||||
else {
|
||||
WrBfrOffset = 1;
|
||||
} else {
|
||||
WriteBuffer[0] = (u8) (Address >> 8);
|
||||
WriteBuffer[1] = (u8) (Address);
|
||||
WrBfrOffset = 2;
|
||||
}
|
||||
|
||||
Status = EepromWriteData(sizeof(Address));
|
||||
Status = EepromWriteData(WrBfrOffset);
|
||||
if (Status != XST_SUCCESS) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue