From 7543c30881da88aa6d3a6c98a0ab842e5d8d830f Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Sun, 31 May 2009 17:32:29 -0500 Subject: [PATCH 1/6] Added public PRWriteData and PRReadData for low level debug --- include/pinproc.h | 8 +++++++- src/PRDevice.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/PRDevice.h | 6 +++--- src/pinproc.cpp | 12 ++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/include/pinproc.h b/include/pinproc.h index 9fc5076..abcea6a 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -115,9 +115,15 @@ PR_EXPORT PRResult PRReset(PRHandle handle, uint32_t resetFlags); // I/O -/** Flush all pending write data out to the P-ROC */ +/** Flush all pending write data out to the P-ROC. */ PR_EXPORT PRResult PRFlushWriteData(PRHandle handle); +/** Write data out to the P-ROC immediately (does not require a call to PRFlushWriteData). */ +PR_EXPORT PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer); + +/** Read data from the P-ROC. */ +PR_EXPORT PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer); + // Drivers /** @defgroup drivers Driver Manipulation * @{ diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index b67c4e2..73e6191 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -784,6 +784,51 @@ PRResult PRDevice::WriteData(uint32_t * words, int32_t numWords) } } +PRResult PRDevice::WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer) +{ + uint32_t * buffer; + + buffer = (uint32_t *)malloc((numWriteWords * 4) + 1); + buffer[0] = CreateBurstCommand(moduleSelect, startingAddr, numWriteWords); + memcpy(buffer+1, writeBuffer, numWriteWords * 4); + WriteData(buffer, numWriteWords + 1); + free (buffer); +} + +PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer) +{ + uint32_t rc; + uint8_t i; + + // Send out the request. + rc = RequestData(moduleSelect, startingAddr, numReadWords); + + i = 0; // Reset i so it can be used to prevent an infinite loop below + + // Wait for data to return. Give it 10 loops before giving up. + // Expect numReadWords + 1 word with the address. + while (requestedDataQueue.size() < (numReadWords + 1) && i++ < 10) + { + sleep (.01); // 10 milliseconds should be plenty of time. + SortReturningData(); + } + + // Make sure all of the requested words are available before processing them. + // Too many words is just as bad as not enough words. + // If too many come back, can they be trusted? + if (requestedDataQueue.size() == numReadWords + 1) + { + requestedDataQueue.pop(); // Ignore address word. TODO: Verify the address. + for (i = 0; i < numReadWords; i++) + { + readBuffer[i] = requestedDataQueue.front(); + requestedDataQueue.pop(); + } + return kPRSuccess; + } + else return kPRFailure; +} + int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words) { diff --git a/src/PRDevice.h b/src/PRDevice.h index 3c0737a..2e32363 100644 --- a/src/PRDevice.h +++ b/src/PRDevice.h @@ -54,6 +54,8 @@ public: int GetEvents(PREvent *events, int maxEvents); PRResult FlushWriteData(); + PRResult WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * buffer); + PRResult ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer); PRResult DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig); PRResult DriverGetGroupConfig(uint8_t groupNum, PRDriverGroupConfig *driverGroupConfig); @@ -86,9 +88,7 @@ protected: /** Schedules data to be written to the P-ROC. */ PRResult PrepareWriteData(uint32_t * buffer, int32_t numWords); - /** Writes data to P-ROC. - * Returns #kPFailure if the number of words read does not match the number requested. - */ + /** Writes data to the P-ROC immediately. */ PRResult WriteData(uint32_t * buffer, int32_t numWords); /** diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 671eea0..e62ff94 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -110,6 +110,18 @@ PR_EXPORT PRResult PRFlushWriteData(PRHandle handle) return handleAsDevice->FlushWriteData(); } +/** Write data out to the P-ROC immediately (does not require a call to PRFlushWriteData */ +PR_EXPORT PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer) +{ + return handleAsDevice->WriteDataRaw(moduleSelect, startingAddr, numWriteWords, writeBuffer); +} + +/** Read data from the P-ROC. */ +PR_EXPORT PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer) +{ + return handleAsDevice->ReadDataRaw(moduleSelect, startingAddr, numReadWords, readBuffer); +} + // Events /** Get all of the available events that have been received. */ From 419269a60de7cfd3915e290a1bb436c71461baf4 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Mon, 1 Jun 2009 11:07:56 -0500 Subject: [PATCH 2/6] Added D2XX support --- src/PRHardware.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 3460012..9d2b35f 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -240,7 +240,7 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config) * As we add support for other drivers (such as D2xx on Windows), we will add more implementations of the PRHardware*() functions here. */ -#if !defined(USE_LIBFTDI) +#if !defined(USE_D2XX) #define USE_LIBFTDI 1 #endif @@ -346,3 +346,134 @@ int PRHardwareWrite(uint8_t *buffer, int bytes) } #endif // USE_LIBFTDI + +#if USE_D2XX +#include "ftd2xx.h" + +#define BUF_SIZE 16 +#define MAX_DEVICES 1 + +// Globals +static FT_HANDLE ftHandles[MAX_DEVICES]; +static FT_HANDLE ftHandle; + +PRResult PRHardwareOpen() +{ + char cBufWrite[BUF_SIZE]; + char * pcBufLD[MAX_DEVICES + 1]; + char cBufLD[MAX_DEVICES][64]; + FT_STATUS ftStatus; + int iNumDevs = 0; + int i, j; + int iDevicesOpen = 0; + + for(i = 0; i < MAX_DEVICES; i++) { + pcBufLD[i] = cBufLD[i]; + ftHandles[i] = NULL; + } + pcBufLD[MAX_DEVICES] = NULL; + + ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER); + + if(ftStatus != FT_OK) { + DEBUG(PRLog(kPRLogInfo,"Error: FT_ListDevices(%d)\n", ftStatus)); + return kPRFailure; + } + + for(j = 0; j < BUF_SIZE; j++) { + cBufWrite[j] = j; + } + + for(i = 0; ( (i 0) + { + FT_ResetDevice(ftHandle); + DEBUG(PRLog(kPRLogInfo,"FTDI Device Opened\n")); + return kPRSuccess; + } + else return kPRFailure; +} + +void PRHardwareClose() +{ + int i; + + for(i = 0; i < MAX_DEVICES; i++) { + if(ftHandles[i] != NULL) { + FT_Close(ftHandles[i]); + ftHandles[i] = NULL; + DEBUG(PRLog(kPRLogInfo,"Closed device\n")); + } + } +} + +int PRHardwareRead(uint8_t *buffer, int maxBytes) +{ + FT_STATUS ftStatus; + DWORD bytesToRead; + DWORD bytesRead; + int i; + + ftStatus = FT_GetQueueStatus(ftHandle,&bytesToRead); + if (ftStatus != FT_OK) return 0; + + if (maxBytes < bytesToRead) bytesToRead = maxBytes; + ftStatus = FT_Read(ftHandle, buffer, bytesToRead, &bytesRead); + if (ftStatus == FT_OK) { + DEBUG(PRLog(kPRLogVerbose,"Read %d bytes:\n",bytesRead)); + for (i=0; i Date: Fri, 12 Jun 2009 09:47:43 -0500 Subject: [PATCH 3/6] Resolved a number of build issues with WIN32 builds --- include/pinproc.h | 4 +++- src/PRDevice.cpp | 6 +++--- src/PRHardware.h | 7 +++++++ src/pinproc.cpp | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/pinproc.h b/include/pinproc.h index 5daec12..fbbf097 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -39,7 +39,9 @@ #if defined(PR_BUILDING_PR) #define PR_EXPORT __declspec(dllexport) extern #else - #define PR_EXPORT __declspec(dllimport) extern + // TODO: Decide what to do here: + //#define PR_EXPORT __declspec(dllimport) extern + #define PR_EXPORT #endif #endif diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 73e6191..5b1a230 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -525,7 +525,7 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit // Wait for data to return. Give it 10 loops before giving up. while (requestedDataQueue.size() < numWords && i++ < 10) { - sleep (.01); // 10 milliseconds should be plenty of time. + PRSleep (10); // 10 milliseconds should be plenty of time. SortReturningData(); } @@ -677,7 +677,7 @@ PRResult PRDevice::VerifyChipID() max_count = 0; //std::cout << "Waiting for read data "; while (num_collected_bytes < (bufferWords*4) && max_count < 10) { - sleep(.01); + PRSleep(10); //std::cout << ". "; rc = CollectReadData(); max_count++; @@ -809,7 +809,7 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int // Expect numReadWords + 1 word with the address. while (requestedDataQueue.size() < (numReadWords + 1) && i++ < 10) { - sleep (.01); // 10 milliseconds should be plenty of time. + PRSleep (10); // 10 milliseconds should be plenty of time. SortReturningData(); } diff --git a/src/PRHardware.h b/src/PRHardware.h index bbcee7d..6329f20 100644 --- a/src/PRHardware.h +++ b/src/PRHardware.h @@ -29,6 +29,13 @@ #include #include "../include/pinproc.h" +#if defined(__WIN32__) + #include + #define PRSleep(milliseconds) Sleep(milliseconds) +#else + #define PRSleep(milliseconds) sleep(milliseconds/1000) +#endif + const int32_t FTDI_VENDOR_ID = 0x0403; const int32_t FTDI_FT245RL_PRODUCT_ID = 0x6001; diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 593f81e..0c92ac6 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -31,6 +31,10 @@ #include "../include/pinproc.h" #include "PRDevice.h" +#if defined(__WIN32__) + #include +#endif + #define MAX_TEXT (1024) typedef void (*PRLogCallback)(PRLogLevel level, const char *text); From b1ce47989c72febb865a5a2cd8ed0dffa3d0f628 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Fri, 12 Jun 2009 09:57:00 -0500 Subject: [PATCH 4/6] Resolved a number of build issues with WIN32 builds --- src/PRDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 5b1a230..84fbe0b 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -879,7 +879,7 @@ int32_t PRDevice::CollectReadData() { int32_t rc,i; rc = PRHardwareRead(collect_buffer, FTDI_BUFFER_SIZE-num_collected_bytes); - for (i=0; i Date: Fri, 12 Jun 2009 10:00:20 -0500 Subject: [PATCH 5/6] Resolved a number of build issues with WIN32 builds --- src/pinproc.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 0c92ac6..d9191dc 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -30,10 +30,7 @@ #include "../include/pinproc.h" #include "PRDevice.h" - -#if defined(__WIN32__) - #include -#endif +#include #define MAX_TEXT (1024) From 3926fbb84eae798cad422ecd5c1ba23f1321a7aa Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Fri, 12 Jun 2009 10:03:18 -0500 Subject: [PATCH 6/6] Resolved a number of build issues with WIN32 builds --- src/PRHardware.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 9d2b35f..c698e7c 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -240,8 +240,12 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config) * As we add support for other drivers (such as D2xx on Windows), we will add more implementations of the PRHardware*() functions here. */ +#if defined(__WIN32__) + #define USE_D2XX 1 +#endif + #if !defined(USE_D2XX) -#define USE_LIBFTDI 1 + #define USE_LIBFTDI 1 #endif #if USE_LIBFTDI