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. */