Skip to content
Snippets Groups Projects
Commit b2ed27d9 authored by mfenner's avatar mfenner
Browse files

First Version for HYT

parent 668fe6a9
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ $(BIN): $(OBJ) ...@@ -27,7 +27,7 @@ $(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "proghyt.exe" $(LIBS) $(CPP) $(LINKOBJ) -o "proghyt.exe" $(LIBS)
main.o: main.c main.o: main.c
$(CC) -c main.c -o main.o $(CC) -c main.c -o main.o
proghyt_private.res: proghyt_private.rc proghyt_private.res: proghyt_private.rc
$(WINDRES) -i proghyt_private.rc --input-format=rc -o proghyt_private.res -O coff $(WINDRES) -i proghyt_private.rc --input-format=rc -o proghyt_private.res -O coff
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
/* Standard C libraries */ /* Standard C libraries */
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
#include <time.h>
/* OS specific libraries */ /* OS specific libraries */
#ifdef _WIN32 #ifdef _WIN32
#include<windows.h> #include<windows.h>
...@@ -47,17 +48,9 @@ ...@@ -47,17 +48,9 @@
encountered \n",__FILE__, __LINE__, __FUNCTION__);exit(1);}else{;}}; encountered \n",__FILE__, __LINE__, __FUNCTION__);exit(1);}else{;}};
/* Application specific macro definations */ /* Application specific macro definations */
#define I2C_DEVICE_ADDRESS_EEPROM 0x57 #define I2C_DEVICE_ADDRESS_HYT 0x50
#define I2C_DEVICE_BUFFER_SIZE 256 #define I2C_WRITE_COMPLETION_RETRY 10
#define I2C_WRITE_COMPLETION_RETRY 10 #define CHANNEL_TO_OPEN 0
#define START_ADDRESS_EEPROM 0x00 /*read/write start address inside the EEPROM*/
#define END_ADDRESS_EEPROM 0x10
#define RETRY_COUNT_EEPROM 10 /* number of retries if read/write fails */
#define CHANNEL_TO_OPEN 1 /*0 for first available channel, 1 for next... */
#define DATA_OFFSET 1
/******************************************************************************/ /******************************************************************************/
...@@ -67,7 +60,14 @@ uint32 channels; ...@@ -67,7 +60,14 @@ uint32 channels;
FT_HANDLE ftHandle; FT_HANDLE ftHandle;
ChannelConfig channelConf; ChannelConfig channelConf;
FT_STATUS status; FT_STATUS status;
uint8 buffer[I2C_DEVICE_BUFFER_SIZE]; uint8 buffer[10];
void waitFor (unsigned int secs) {
unsigned int retTime = time(0) + secs; // Get finishing time.
while (time(0) < retTime); // Loop until it arrives.
}
/******************************************************************************/ /******************************************************************************/
/* Public function definitions */ /* Public function definitions */
...@@ -97,8 +97,7 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data) ...@@ -97,8 +97,7 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data)
bytesTransfered=0; bytesTransfered=0;
buffer[bytesToTransfer++]=registerAddress; /* Byte addressed inside EEPROM */ buffer[bytesToTransfer++]=registerAddress; /* Byte addressed inside EEPROM */
buffer[bytesToTransfer++]=data; buffer[bytesToTransfer++]=data;
status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer, buffer, \ status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_STOP_BIT);
&bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_STOP_BIT);
/* poll to check completition */ /* poll to check completition */
while((writeComplete==0) && (retry<I2C_WRITE_COMPLETION_RETRY)) while((writeComplete==0) && (retry<I2C_WRITE_COMPLETION_RETRY))
...@@ -106,9 +105,7 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data) ...@@ -106,9 +105,7 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data)
bytesToTransfer=0; bytesToTransfer=0;
bytesTransfered=0; bytesTransfered=0;
buffer[bytesToTransfer++]=registerAddress; /* Addressed inside EEPROM */ buffer[bytesToTransfer++]=registerAddress; /* Addressed inside EEPROM */
status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer,\ status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_BREAK_ON_NACK);
buffer, &bytesTransfered, \
I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_BREAK_ON_NACK);
if((FT_OK == status) && (bytesToTransfer == bytesTransfered)) if((FT_OK == status) && (bytesToTransfer == bytesTransfered))
{ {
writeComplete=1; writeComplete=1;
...@@ -119,6 +116,37 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data) ...@@ -119,6 +116,37 @@ FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data)
return status; return status;
} }
FT_STATUS write_hyt(uint8 slaveAddress, uint8 commandByte, uint8 datah, uint8 datal)
{
uint32 bytesToTransfer = 0;
uint32 bytesTransfered;
bool writeComplete=0;
uint32 retry=0;
bytesToTransfer=0;
bytesTransfered=0;
buffer[bytesToTransfer++]=commandByte;
buffer[bytesToTransfer++]=datah;
buffer[bytesToTransfer++]=datal;
status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_STOP_BIT);
APP_CHECK_STATUS(status);
return status;
}
FT_STATUS read_hyt(uint8 slaveAddress, uint8 *data)
{
FT_STATUS status;
uint32 bytesToTransfer = 0;
uint32 bytesTransfered;
status |= I2C_DeviceRead(ftHandle, slaveAddress, 3, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT);
APP_CHECK_STATUS(status);
*data = buffer[0];
return status;
}
/*! /*!
* \brief Reads from EEPROM * \brief Reads from EEPROM
* *
...@@ -154,18 +182,7 @@ FT_STATUS read_byte(uint8 slaveAddress, uint8 registerAddress, uint8 *data) ...@@ -154,18 +182,7 @@ FT_STATUS read_byte(uint8 slaveAddress, uint8 registerAddress, uint8 *data)
return status; return status;
} }
/*!
* \brief Main function / Entry point to the sample application
*
* This function is the entry point to the sample application. It opens the channel, writes to the
* EEPROM and reads back.
*
* \param[in] none
* \return Returns 0 for success
* \sa
* \note
* \warning
*/
int main() int main()
{ {
FT_STATUS status; FT_STATUS status;
...@@ -174,9 +191,9 @@ int main() ...@@ -174,9 +191,9 @@ int main()
uint8 data; uint8 data;
int i,j; int i,j;
//#ifdef _MSC_VER #ifdef _MSC_VER
Init_libMPSSE(); Init_libMPSSE();
//#endif #endif
channelConf.ClockRate = I2C_CLOCK_FAST_MODE;/*i.e. 400000 KHz*/ channelConf.ClockRate = I2C_CLOCK_FAST_MODE;/*i.e. 400000 KHz*/
channelConf.LatencyTimer= 255; channelConf.LatencyTimer= 255;
//channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING; //channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING;
...@@ -205,37 +222,41 @@ int main() ...@@ -205,37 +222,41 @@ int main()
/* Open the first available channel */ /* Open the first available channel */
status = I2C_OpenChannel(CHANNEL_TO_OPEN,&ftHandle); status = I2C_OpenChannel(CHANNEL_TO_OPEN,&ftHandle);
APP_CHECK_STATUS(status); APP_CHECK_STATUS(status);
printf("\nhandle=0x%x status=%d\n",ftHandle,status); printf("%s\r\n",status);
printf("\nhandle=0x%x status=%d\n",ftHandle,status);
status = I2C_InitChannel(ftHandle,&channelConf); status = I2C_InitChannel(ftHandle,&channelConf);
APP_CHECK_STATUS(status); APP_CHECK_STATUS(status);
printf("%s\r\n",status);
for(address=START_ADDRESS_EEPROM;address<END_ADDRESS_EEPROM;address++)
{ printf("Setting GPIO Pin OFF.\r\n");
printf("writing address = %d data = %d", address, \ FT_WriteGPIO(ftHandle, 0x01, 0x00);
address+DATA_OFFSET); printf("%s\r\n",status);
status = write_byte(I2C_DEVICE_ADDRESS_EEPROM, address, \ waitFor(1);
address+DATA_OFFSET); printf("Setting GPIO Pin ON.\r\n");
for(j=0; ((j<RETRY_COUNT_EEPROM) && (FT_OK !=status)); j++) FT_WriteGPIO(ftHandle, 0x01, 0x01);
{ printf("%s\r\n",status);
printf("---- writing again to address = %d, data =%d\n", \
address, address+DATA_OFFSET); printf("Starting Command Mode.\r\n");
status = write_byte(I2C_DEVICE_ADDRESS_EEPROM, address, \ write_hyt(I2C_DEVICE_ADDRESS_HYT,0xA0,0x00,0x00);
address+DATA_OFFSET); printf("%s\r\n",status);
}
APP_CHECK_STATUS(status); printf("Request I2C Address.\r\n");
} write_hyt(I2C_DEVICE_ADDRESS_HYT,0x1C,0x00,0x00);
printf("\n"); printf("%s\r\n",status);
for(address=START_ADDRESS_EEPROM; address<END_ADDRESS_EEPROM; address++)
{ printf("Reading I2C Address.\r\n");
status = read_byte(I2C_DEVICE_ADDRESS_EEPROM,address, &data); read_hyt( I2C_DEVICE_ADDRESS_HYT, buffer);
for(j=0; ((j<RETRY_COUNT_EEPROM) && (FT_OK !=status)); j++) printf("%X %X %X\r\n", buffer[0], buffer[1], buffer[2]);
{
printf("read error... retrying \n"); printf("Leaving Command Mode.\r\n");
status = read_byte(I2C_DEVICE_ADDRESS_EEPROM,address, &data); write_hyt(I2C_DEVICE_ADDRESS_HYT,0x80,0x00,0x00);
} printf("%s\r\n",status);
printf("reading address %d data read=%d\n",address,data);
}
printf("Closing Handle\r\n");
status = I2C_CloseChannel(ftHandle); status = I2C_CloseChannel(ftHandle);
} }
...@@ -243,7 +264,5 @@ int main() ...@@ -243,7 +264,5 @@ int main()
Cleanup_libMPSSE(); Cleanup_libMPSSE();
#endif #endif
system("pause");
return 0; return 0;
} }
...@@ -6,17 +6,17 @@ LeftChar=1 ...@@ -6,17 +6,17 @@ LeftChar=1
[Editor_1] [Editor_1]
CursorCol=1 CursorCol=1
CursorRow=1 CursorRow=1
TopLine=119 TopLine=35
LeftChar=1 LeftChar=1
Open=1 Open=1
Top=1 Top=0
[Editors] [Editors]
Focused=1 Focused=0
Order=-1,0,1 Order=0,1
[Editor_0] [Editor_0]
Open=1 Open=1
Top=0 Top=1
CursorCol=5 CursorCol=31
CursorRow=161 CursorRow=259
TopLine=157 TopLine=216
LeftChar=1 LeftChar=1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment