mirror of
https://github.com/preble/libpinproc
synced 2026-02-24 18:25:23 +01:00
Merge branch 'master' of git@github.com:preble/P-ROC
This commit is contained in:
@@ -39,7 +39,9 @@
|
|||||||
#if defined(PR_BUILDING_PR)
|
#if defined(PR_BUILDING_PR)
|
||||||
#define PR_EXPORT __declspec(dllexport) extern
|
#define PR_EXPORT __declspec(dllexport) extern
|
||||||
#else
|
#else
|
||||||
#define PR_EXPORT __declspec(dllimport) extern
|
// TODO: Decide what to do here:
|
||||||
|
//#define PR_EXPORT __declspec(dllimport) extern
|
||||||
|
#define PR_EXPORT
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -115,9 +117,15 @@ PR_EXPORT PRResult PRReset(PRHandle handle, uint32_t resetFlags);
|
|||||||
|
|
||||||
// I/O
|
// 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);
|
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
|
// Drivers
|
||||||
/** @defgroup drivers Driver Manipulation
|
/** @defgroup drivers Driver Manipulation
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
|
|||||||
// Wait for data to return. Give it 10 loops before giving up.
|
// Wait for data to return. Give it 10 loops before giving up.
|
||||||
while (requestedDataQueue.size() < numWords && i++ < 10)
|
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();
|
SortReturningData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,7 +677,7 @@ PRResult PRDevice::VerifyChipID()
|
|||||||
max_count = 0;
|
max_count = 0;
|
||||||
//std::cout << "Waiting for read data ";
|
//std::cout << "Waiting for read data ";
|
||||||
while (num_collected_bytes < (bufferWords*4) && max_count < 10) {
|
while (num_collected_bytes < (bufferWords*4) && max_count < 10) {
|
||||||
sleep(.01);
|
PRSleep(10);
|
||||||
//std::cout << ". ";
|
//std::cout << ". ";
|
||||||
rc = CollectReadData();
|
rc = CollectReadData();
|
||||||
max_count++;
|
max_count++;
|
||||||
@@ -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)
|
||||||
|
{
|
||||||
|
PRSleep (10); // 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)
|
int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words)
|
||||||
{
|
{
|
||||||
@@ -834,7 +879,7 @@ int32_t PRDevice::CollectReadData()
|
|||||||
{
|
{
|
||||||
int32_t rc,i;
|
int32_t rc,i;
|
||||||
rc = PRHardwareRead(collect_buffer, FTDI_BUFFER_SIZE-num_collected_bytes);
|
rc = PRHardwareRead(collect_buffer, FTDI_BUFFER_SIZE-num_collected_bytes);
|
||||||
for (i=0; i<rc; i=i++) {
|
for (i=0; i<rc; i++) {
|
||||||
collected_bytes_fifo[collected_bytes_wr_addr] = collect_buffer[i];
|
collected_bytes_fifo[collected_bytes_wr_addr] = collect_buffer[i];
|
||||||
if (collected_bytes_wr_addr == (FTDI_BUFFER_SIZE-1))
|
if (collected_bytes_wr_addr == (FTDI_BUFFER_SIZE-1))
|
||||||
collected_bytes_wr_addr = 0;
|
collected_bytes_wr_addr = 0;
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public:
|
|||||||
int GetEvents(PREvent *events, int maxEvents);
|
int GetEvents(PREvent *events, int maxEvents);
|
||||||
|
|
||||||
PRResult FlushWriteData();
|
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 DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig);
|
||||||
PRResult DriverGetGroupConfig(uint8_t groupNum, PRDriverGroupConfig *driverGroupConfig);
|
PRResult DriverGetGroupConfig(uint8_t groupNum, PRDriverGroupConfig *driverGroupConfig);
|
||||||
@@ -86,9 +88,7 @@ protected:
|
|||||||
/** Schedules data to be written to the P-ROC. */
|
/** Schedules data to be written to the P-ROC. */
|
||||||
PRResult PrepareWriteData(uint32_t * buffer, int32_t numWords);
|
PRResult PrepareWriteData(uint32_t * buffer, int32_t numWords);
|
||||||
|
|
||||||
/** Writes data to P-ROC.
|
/** Writes data to the P-ROC immediately. */
|
||||||
* Returns #kPFailure if the number of words read does not match the number requested.
|
|
||||||
*/
|
|
||||||
PRResult WriteData(uint32_t * buffer, int32_t numWords);
|
PRResult WriteData(uint32_t * buffer, int32_t numWords);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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.
|
* 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(__WIN32__)
|
||||||
#define USE_LIBFTDI 1
|
#define USE_D2XX 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(USE_D2XX)
|
||||||
|
#define USE_LIBFTDI 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_LIBFTDI
|
#if USE_LIBFTDI
|
||||||
@@ -346,3 +350,134 @@ int PRHardwareWrite(uint8_t *buffer, int bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_LIBFTDI
|
#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 <MAX_DEVICES) && (i < iNumDevs) ); i++) {
|
||||||
|
DEBUG(PRLog(kPRLogInfo,"Device %d Serial Number - %s\n", i, cBufLD[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ) ; i++) {
|
||||||
|
/* Setup */
|
||||||
|
if((ftStatus = FT_OpenEx(cBufLD[i], FT_OPEN_BY_SERIAL_NUMBER, &ftHandles[i])) != FT_OK){
|
||||||
|
/*
|
||||||
|
This can fail if the ftdi_sio driver is loaded
|
||||||
|
use lsmod to check this and rmmod ftdi_sio to remove
|
||||||
|
also rmmod usbserial
|
||||||
|
*/
|
||||||
|
DEBUG(PRLog(kPRLogInfo,"Error FT_OpenEx(%d), device\n", ftStatus, i));
|
||||||
|
return kPRFailure;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG(PRLog(kPRLogInfo,"Opened device %s\n", cBufLD[i]));
|
||||||
|
ftHandle = ftHandles[i];
|
||||||
|
|
||||||
|
if((ftStatus = FT_SetBaudRate(ftHandles[i], 1228800)) != FT_OK) {
|
||||||
|
DEBUG(PRLog(kPRLogInfo,"Error FT_SetBaudRate(%d), cBufLD[i] = %s\n", ftStatus, cBufLD[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
iDevicesOpen++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iDevicesOpen > 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<bytesRead; i++) {
|
||||||
|
DEBUG(PRLog(kPRLogVerbose,"Read byte: %x\n",buffer[i]));
|
||||||
|
}
|
||||||
|
return (int)bytesRead;
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PRHardwareWrite(uint8_t *buffer, int bytes)
|
||||||
|
{
|
||||||
|
FT_STATUS ftStatus=0;
|
||||||
|
DWORD bytesWritten=0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
DEBUG(PRLog(kPRLogVerbose,"Writing %d bytes:\n",bytes));
|
||||||
|
ftStatus = FT_Write(ftHandle, buffer, (DWORD)bytes, &bytesWritten);
|
||||||
|
if (ftStatus == FT_OK)
|
||||||
|
{
|
||||||
|
DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes:\n",bytesWritten));
|
||||||
|
if (bytesWritten != bytes) DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes, should have written %d bytes",bytesWritten,bytes));
|
||||||
|
else {
|
||||||
|
for (i=0; i<bytesWritten; i++) {
|
||||||
|
DEBUG(PRLog(kPRLogVerbose,"Wrote byte: %x\n",buffer[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (int)bytesWritten;
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // D2XX
|
||||||
|
|||||||
@@ -29,6 +29,13 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../include/pinproc.h"
|
#include "../include/pinproc.h"
|
||||||
|
|
||||||
|
#if defined(__WIN32__)
|
||||||
|
#include <windows.h>
|
||||||
|
#define PRSleep(milliseconds) Sleep(milliseconds)
|
||||||
|
#else
|
||||||
|
#define PRSleep(milliseconds) sleep(milliseconds/1000)
|
||||||
|
#endif
|
||||||
|
|
||||||
const int32_t FTDI_VENDOR_ID = 0x0403;
|
const int32_t FTDI_VENDOR_ID = 0x0403;
|
||||||
const int32_t FTDI_FT245RL_PRODUCT_ID = 0x6001;
|
const int32_t FTDI_FT245RL_PRODUCT_ID = 0x6001;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "../include/pinproc.h"
|
#include "../include/pinproc.h"
|
||||||
#include "PRDevice.h"
|
#include "PRDevice.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define MAX_TEXT (1024)
|
#define MAX_TEXT (1024)
|
||||||
|
|
||||||
@@ -110,6 +111,18 @@ PR_EXPORT PRResult PRFlushWriteData(PRHandle handle)
|
|||||||
return handleAsDevice->FlushWriteData();
|
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
|
// Events
|
||||||
|
|
||||||
/** Get all of the available events that have been received. */
|
/** Get all of the available events that have been received. */
|
||||||
|
|||||||
Reference in New Issue
Block a user