1
0
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:
Adam Preble
2009-07-20 20:40:30 -04:00
11 changed files with 204 additions and 38 deletions

View File

@@ -37,6 +37,31 @@ Download and install [CMake](http://www.cmake.org/cmake/resources/software.html)
The CMakeLists.txt file is presently designed to be run from a directory inside the libpinproc directory. This will build both libpinproc and pinproctest. Binaries will be placed in the directory that make was run from.
#### Building in Windows with minGW/CMake
Download and install [ftd2xx for Windows](http://www.ftdichip.com/Drivers/D2XX.htm). It's recommended to use the [setup executable](http://www.ftdichip.com/Drivers/CDM/CDM%202.04.16.exe) for the driver install and the [zip file](http://www.ftdichip.com/Drivers/CDM/CDM%202.04.16%20WHQL%20Certified.zip) for the build source/dlls.
Download and install [CMake](http://www.cmake.org/cmake/resources/software.html).
Download and install [MinGW](http://sourceforge.net/projects/mingw/files/). (Tested with MinGW 5.1.4)
Follow directions above for building yaml-cpp with the following exception:
add '-G "MinGW Makefiles' to the cmake command line.
To build libpinproc:
edit CMakeLists.txt:
add "ftd2xx" to the target_link_libraries lines,
remove "usb" and "ftdi" from the target_link_libraries lines
Until an automatic build process/structure is worked out:
copy ftd2xx.h to libpinproc/src,
copy yaml header files to libpinproc/examples/pinproctest,
change libpinproc/examples/pinproctest/pinproctest.h to look for yaml.h locally
Follow instructions above for building libpinproc with cmake with the following exceptions:
add '-G "MinGW Makefiles' to the cmake command line,
use mingw-make instead of make
### License
Copyright (c) 2009 Gerry Stellenberg, Adam Preble

View File

@@ -36,6 +36,9 @@ void ConfigureDMD(PRHandle proc)
dmdConfig.numRows = kDMDRows;
dmdConfig.numColumns = kDMDColumns;
dmdConfig.numSubFrames = kDMDSubFrames;
dmdConfig.numFrameBuffers = kDMDFrameBuffers;
dmdConfig.autoIncBufferWrPtr = true;
dmdConfig.enableFrameEvents = true;
for (i = 0; i < kDMDSubFrames; i++)
{

View File

@@ -78,6 +78,7 @@ bool runLoopRun = true;
void RunLoop(PRHandle proc)
{
const int maxEvents = 16;
int i;
PREvent events[maxEvents];
// Create dot array using an array of bytes. Each byte holds 8 dots. Need
@@ -88,13 +89,22 @@ void RunLoop(PRHandle proc)
// Retrieve and store initial switch states.
LoadSwitchStates(proc);
uint32_t rdBuffer[1];
// Send 3 frames
for (i=0; i<3; i++)
{
// Create a dot pattern to test the DMD
UpdateDots(dots,dotOffset++);
PRDMDDraw(proc,dots);
}
while (runLoopRun)
{
PRDriverWatchdogTickle(proc);
// Create a dot pattern to test the DMD
UpdateDots(dots,dotOffset++);
PRDMDDraw(proc,dots);
//PRReadData(proc, 5, 0, 1, rdBuffer);
//printf("dmd config: %x\n",rdBuffer[0]);
int numEvents = PRGetEvents(proc, events, maxEvents);
for (int i = 0; i < numEvents; i++)
@@ -110,8 +120,25 @@ void RunLoop(PRHandle proc)
}
struct timeval tv;
gettimeofday(&tv, NULL);
printf("%d.%03d switch % 3d: %s\n", tv.tv_sec-startTime, tv.tv_usec/1000, event->value, stateText);
UpdateSwitchState( event );
switch (event->type)
{
case kPREventTypeSwitchOpenDebounced:
case kPREventTypeSwitchClosedDebounced:
case kPREventTypeSwitchOpenNondebounced:
case kPREventTypeSwitchClosedNondebounced:
{
printf("%d.%03d switch % 3d: %s\n", tv.tv_sec-startTime, tv.tv_usec/1000, event->value, stateText);
UpdateSwitchState( event );
break;
}
case kPREventTypeDMDFrameDisplayed:
{
UpdateDots(dots,dotOffset++);
PRDMDDraw(proc,dots);
break;
}
}
}
PRFlushWriteData(proc);
usleep(10*1000); // Sleep for 10ms so we aren't pegging the CPU.
@@ -168,6 +195,7 @@ int main(int argc, const char **argv)
return 1;
}
PRLogSetLevel (kPRLogInfo);
PRReset(proc, kPRResetFlagUpdateDevice); // Reset the device structs and write them into the device.
ConfigureDMD(proc);
@@ -177,7 +205,8 @@ int main(int argc, const char **argv)
// Pulse a coil for testing purposes.
//PRDriverPulse(proc, 53, 100);
// Schedule a feature lamp for testing purposes.
PRDriverSchedule(proc, 80, 0xFF00FF00, 0, 0);
//PRDriverSchedule(proc, 80, 0xFF00FF00, 0, 0);
PRDriverSchedule(proc, 0, 0xFF00AAAA, 1, 1);
// Pitter-patter a feature lamp for testing purposes.
//PRDriverPatter(proc, 84, 127, 127, 0);
PRFlushWriteData(proc);
@@ -188,6 +217,7 @@ int main(int argc, const char **argv)
// Clean up P-ROC.
printf("Disabling P-ROC drivers and switch rules...\n");
PRReset(proc, kPRResetFlagUpdateDevice); // Reset the device structs and write them into the device.
PRFlushWriteData(proc);

View File

@@ -49,6 +49,7 @@
#define kDMDColumns (128)
#define kDMDRows (32)
#define kDMDSubFrames (4) // For color depth of 16
#define kDMDFrameBuffers (3) // 3 is the max
void ConfigureDrivers(PRHandle proc, PRMachineType machineType, YAML::Node& yamlDoc);

View File

@@ -38,6 +38,7 @@ void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc)
// Configure switch controller registers (if the defaults aren't acceptable)
PRSwitchConfig switchConfig;
switchConfig.clear = false;
switchConfig.hostEventsEnable = true;
switchConfig.directMatrixScanLoopTime = 2; // milliseconds
switchConfig.pulsesBeforeCheckingRX = 10;
switchConfig.inactivePulsesAfterBurst = 12;

View File

@@ -268,12 +268,13 @@ typedef enum PREventType {
kPREventTypeSwitchOpenDebounced = 2, /**< The switch has gone from closed to open and the signal has been debounced. */
kPREventTypeSwitchClosedNondebounced = 3, /**< The switch has gone from open to closed and the signal has not been debounced. */
kPREventTypeSwitchOpenNondebounced = 4, /**< The switch has gone from closed to open and the signal has not been debounced. */
kPREventTypeDMDFrameDisplayed = 5, /**< A DMD frame has been displayed. */
kPREventTypetLast = kPREventTypeSwitchOpenNondebounced
} PREventType;
typedef struct PREvent {
PREventType type; /**< The type of event that has occurred. Usually a switch event at this point. */
uint32_t value; /**< For switch events, the switch number that has changed. */
uint32_t value; /**< For switch events, the switch number that has changed. For DMD events, the frame buffer that was just displayed. */
uint32_t time; /**< Time (in milliseconds) that this event occurred. */
} PREvent;
@@ -290,6 +291,7 @@ PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents);
typedef struct PRSwitchConfig {
bool_t clear; // Drive the clear output
bool_t hostEventsEnable; // Drive the clear output
uint8_t directMatrixScanLoopTime; // milliseconds
uint8_t pulsesBeforeCheckingRX;
uint8_t inactivePulsesAfterBurst;
@@ -373,6 +375,9 @@ typedef struct PRDMDConfig {
uint8_t numRows;
uint16_t numColumns;
uint8_t numSubFrames;
uint8_t numFrameBuffers;
bool_t autoIncBufferWrPtr;
bool_t enableFrameEvents;
bool_t enable;
uint8_t rclkLowCycles[8];
uint8_t latchHighCycles[8];

View File

@@ -73,6 +73,16 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
DriverLoadMachineTypeDefaults(machineType, resetFlags);
// Disable dmd events if updating the device.
#if 0
if (resetFlags & kPRResetFlagUpdateDevice)
{
PRDMDConfig *dmdConfig = &(this->dmdConfig);
dmdConfig->enableFrameEvents = false;
DMDUpdateConfig(dmdConfig);
}
#endif
// Make sure the free list is empty.
while (!freeSwitchRuleIndexes.empty()) freeSwitchRuleIndexes.pop();
@@ -121,11 +131,28 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
events[i].value = event_data & P_ROC_EVENT_SWITCH_NUM_MASK;
bool open = (event_data & P_ROC_EVENT_SWITCH_STATE_MASK) >> P_ROC_EVENT_SWITCH_STATE_SHIFT;
bool debounced = (event_data & P_ROC_EVENT_SWITCH_DEBOUNCED_MASK) >> P_ROC_EVENT_SWITCH_DEBOUNCED_SHIFT;
if (open)
events[i].type = debounced ? kPREventTypeSwitchOpenDebounced : kPREventTypeSwitchOpenNondebounced;
else
events[i].type = debounced ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchOpenNondebounced;
switch ((event_data & P_ROC_EVENT_TYPE_MASK) >> P_ROC_EVENT_TYPE_SHIFT)
{
case P_ROC_EVENT_TYPE_SWITCH:
{
bool debounced = (event_data & P_ROC_EVENT_SWITCH_DEBOUNCED_MASK) >> P_ROC_EVENT_SWITCH_DEBOUNCED_SHIFT;
if (open)
events[i].type = debounced ? kPREventTypeSwitchOpenDebounced : kPREventTypeSwitchOpenNondebounced;
else
events[i].type = debounced ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchOpenNondebounced;
break;
}
case P_ROC_EVENT_TYPE_DMD:
{
events[i].type = kPREventTypeDMDFrameDisplayed;
break;
}
default: events[i].type = kPREventTypeInvalid;
}
}
return i;
}
@@ -385,7 +412,7 @@ PRSwitchRuleInternal *PRDevice::GetSwitchRuleByIndex(uint16_t index)
PRResult PRDevice::SwitchUpdateConfig(PRSwitchConfig *switchConfig)
{
uint32_t rc;
const int burstWords = 2;
const int burstWords = 4;
uint32_t burst[burstWords];
this->switchConfig = *switchConfig;
@@ -602,25 +629,41 @@ PRResult PRDevice::DMDDraw(uint8_t * dots)
// The following code prints out the init lines for the 4 Xilinx BlockRAMs
// in the FPGA. It's used to make an image for the P-ROC to display on power-up.
//if (print_dots) {
//print_dots = false;
//for (i=0; i<4; i++) {
// std::cout << "For memory: "<< i << "\n";
// // Need 4 lines to get 1 frame (4*256*4 = 4096)
// // The rest will be all 0.
// for (y=0; y<4; y++) {
// std::cout << "defparam blockram.INIT_00 = 256'b";
// for (j=31; j>=0; j--) {
// for (x=7; x>=0; x--) {
// std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
// }
// }
// std::cout << ";\n";
// }
// std::cout << "\n\n\n";
//}
//}
#if 0
// This is the original version... needs to be deleted.
for (i=0; i<4; i++) {
std::cout << "For memory: "<< i << "\n";
// Need 4 lines to get 1 frame (4*256*4 = 4096)
// The rest will be all 0.
for (y=0; y<4; y++) {
std::cout << "defparam blockram.INIT_00 = 256'b";
for (j=31; j>=0; j--) {
for (x=7; x>=0; x--) {
std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
}
}
std::cout << ";\n";
}
std::cout << "\n\n\n";
}
#endif
#if 0
for (i=0; i<4; i++) {
std::cout << "For memory: "<< i << "\n";
// Need 4 lines to get 1 frame (4*256*4 = 4096)
// The rest will be all 0.
for (y=0; y<4; y++) {
std::cout << "defparam blockram.INIT_00 = 256'b";
for (j=8; j>=0; j--) {
for (x=31; x>=0; x--) {
std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
}
}
std::cout << ";\n";
}
std::cout << "\n\n\n";
}
#endif
}
PRResult PRDevice::PRJTAGDriveOutputs(PRJTAGOutputs * jtagOutputs, bool_t toggleClk)
@@ -674,12 +717,39 @@ PRResult PRDevice::PRJTAGGetStatus(PRJTAGStatus * status)
PRResult PRDevice::Open()
{
uint32_t temp_word;
PRResult res = PRHardwareOpen();
if (res == kPRSuccess)
{
// Try to verify the P-ROC IS in the FPGA before initializing the FPGA's FTDI interface
// just in case it was already initialized from a previous application execution.
DEBUG(PRLog(kPRLogInfo, "Verifying P-ROC ID: \n"));
// Attempt to turn off events. This is necessary if P-ROC wasn't shut down
// properly previously. If the P-ROC isn't initialized, this request will
// be ignored.
PRDMDConfig dmdConfig;
dmdConfig.numRows = 32; // Doesn't matter.
dmdConfig.numColumns = 128; // Doesn't matter
dmdConfig.numSubFrames = 4; // Doesn't matter
dmdConfig.numFrameBuffers = 3; // Doesn't matter
dmdConfig.autoIncBufferWrPtr = false;
dmdConfig.enableFrameEvents = false;
DMDUpdateConfig(&dmdConfig);
PRSwitchConfig switchConfig;
switchConfig.clear = false;
switchConfig.hostEventsEnable = false;
switchConfig.directMatrixScanLoopTime = 2; // milliseconds
switchConfig.pulsesBeforeCheckingRX = 10;
switchConfig.inactivePulsesAfterBurst = 12;
switchConfig.pulsesPerBurst = 6;
switchConfig.pulseHalfPeriodTime = 13; // milliseconds
SwitchUpdateConfig(&switchConfig);
// Flush read data to ensure VerifyChipID starts with clean buffer.
res = FlushReadBuffer();
if (VerifyChipID() == kPRFailure) {
// Since the FPGA didn't appear to be responding properly, send the FPGA's FTDI
// initialization sequence. This is a set of bytes the FPGA is waiting to receive
@@ -687,7 +757,7 @@ PRResult PRDevice::Open()
// in and wreaking havoc before software is up and running.
DEBUG(PRLog(kPRLogInfo, "Initializing P-ROC...\n"));
res = FlushReadBuffer();
uint32_t temp_word = P_ROC_INIT_PATTERN_A;
temp_word = P_ROC_INIT_PATTERN_A;
res = WriteData(&temp_word, 1);
temp_word = P_ROC_INIT_PATTERN_B;
res = WriteData(&temp_word, 1);
@@ -695,6 +765,7 @@ PRResult PRDevice::Open()
if (res == kPRFailure)
DEBUG(PRLog(kPRLogWarning, "Unable to read Chip ID - P-ROC could not be initialized.\n"));
}
else res = kPRSuccess;
}
return res;
@@ -914,10 +985,14 @@ PRResult PRDevice::FlushReadBuffer()
numBytes = CollectReadData();
k = 0;
//std::cout << "Flushing rd buffer of " << num_words << "words\n";
while (k < numBytes) {
rc = ReadData(rd_buffer, 1);
k++;
}
//while (k < numBytes) {
// rc = ReadData(rd_buffer, 1);
// k++;
//}
collected_bytes_rd_addr = 0;
collected_bytes_wr_addr = 0;
num_collected_bytes = 0;
return rc;
}

View File

@@ -157,6 +157,9 @@ int32_t CreateSwitchUpdateConfigBurst ( uint32_t * burst, PRSwitchConfig *switch
P_ROC_SWITCH_CONFIG_PULSES_PER_BURST_SHIFT) |
(switchConfig->pulseHalfPeriodTime <<
P_ROC_SWITCH_CONFIG_MS_PER_PULSE_HALF_PERIOD_SHIFT);
burst[2] = CreateBurstCommand (P_ROC_BUS_STATE_CHANGE_PROC_SELECT,
P_ROC_STATE_CHANGE_CONFIG_ADDR, 1 );
burst[3] = switchConfig->hostEventsEnable;
return kPRSuccess;
}
@@ -218,6 +221,9 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config)
addr = 0;
burst[0] = CreateBurstCommand (P_ROC_BUS_DMD_SELECT, addr, 1 );
burst[1] = (1 << P_ROC_DMD_ENABLE_SHIFT) |
(dmd_config->enableFrameEvents << P_ROC_DMD_ENABLE_FRAME_EVENTS_SHIFT) |
(dmd_config->autoIncBufferWrPtr << P_ROC_DMD_AUTO_INC_WR_POINTER_SHIFT) |
(dmd_config->numFrameBuffers << P_ROC_DMD_NUM_FRAME_BUFFERS_SHIFT) |
(dmd_config->numSubFrames << P_ROC_DMD_NUM_SUB_FRAMES_SHIFT) |
(dmd_config->numRows << P_ROC_DMD_NUM_ROWS_SHIFT) |
(dmd_config->numColumns << P_ROC_DMD_NUM_COLUMNS_SHIFT);

View File

@@ -110,6 +110,10 @@ const uint32_t P_ROC_JTAG_TDI_MEMORY_BASE_ADDR = 0x800;
const uint32_t P_ROC_SWITCH_CTRL_STATE_BASE_ADDR = 4;
const uint32_t P_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR = 11;
const uint32_t P_ROC_EVENT_TYPE_SWITCH = 0;
const uint32_t P_ROC_EVENT_TYPE_DMD = 1;
const uint32_t P_ROC_EVENT_TYPE_MASK = 0xC00;
const uint32_t P_ROC_EVENT_TYPE_SHIFT = 10;
const uint32_t P_ROC_EVENT_SWITCH_NUM_MASK = 0xFF;
const uint32_t P_ROC_EVENT_SWITCH_STATE_MASK = 0x100;
const uint32_t P_ROC_EVENT_SWITCH_STATE_SHIFT = 8;
@@ -176,9 +180,14 @@ const uint32_t P_ROC_SWITCH_RULE_LINK_ADDRESS_SHIFT = 11;
const uint32_t P_ROC_SWITCH_RULE_CHANGE_OUTPUT_SHIFT = 9;
const uint32_t P_ROC_SWITCH_RULE_DRIVER_NUM_SHIFT = 0;
const uint32_t P_ROC_STATE_CHANGE_CONFIG_ADDR = 0x1000;
const uint32_t P_ROC_DMD_NUM_COLUMNS_SHIFT = 0;
const uint32_t P_ROC_DMD_NUM_ROWS_SHIFT = 8;
const uint32_t P_ROC_DMD_NUM_SUB_FRAMES_SHIFT = 16;
const uint32_t P_ROC_DMD_NUM_FRAME_BUFFERS_SHIFT = 24;
const uint32_t P_ROC_DMD_AUTO_INC_WR_POINTER_SHIFT = 29;
const uint32_t P_ROC_DMD_ENABLE_FRAME_EVENTS_SHIFT = 30;
const uint32_t P_ROC_DMD_ENABLE_SHIFT = 31;
const uint32_t P_ROC_DMD_DOTCLK_HALF_PERIOD_SHIFT = 0;

View File

@@ -468,6 +468,8 @@ void xsvfTmsTransition( short tms )
jtagOutputs.tdoMask = 0;
jtagOutputs.tmsMask = 1;
jtagOutputs.tms = tms;
jtagOutputs.tdo = 0; // Unused but initialized.
jtagOutputs.tck = 0; // Unused but initialized.
PRJTAGDriveOutputs(proc, &jtagOutputs, true);
}
@@ -553,7 +555,8 @@ void waitTime(long microsec)
// Read the JTAG status register to exercise the USB bus
PRJTAGGetStatus(proc, &jtagStatus);
sleep( ( microsec - 2000L ) / 1000000L);
PRSleep( ( microsec - 2000L ) / 1000L);
//sleep( ( microsec - 2000L ) / 1000000L);
}
else /* Satisfy FPGA JTAG configuration, startup TCK cycles */
{
@@ -566,6 +569,7 @@ void waitTime(long microsec)
PRJTAGGetStatus(proc, &jtagStatus);
}
//{
//PRSleep( ( microsec + 19999L ) / 1000L );
//sleep( ( microsec + 19999L ) / 1000000L );
//sleep( 1 );
//pulseClock();

View File

@@ -13,6 +13,13 @@
#ifndef PINPROCFW_H
#define PINPROCFW_H
#if defined(__WIN32__)
#include <windows.h>
#define PRSleep(milliseconds) Sleep(milliseconds)
#else
#define PRSleep(milliseconds) sleep(milliseconds/1000)
#endif
/* Legacy error codes for xsvfExecute from original XSVF player v2.0 */
#define XSVF_LEGACY_SUCCESS 1
#define XSVF_LEGACY_ERROR 0