diff --git a/examples/pinproctest/dmd.cpp b/examples/pinproctest/dmd.cpp index 536685a..221b464 100644 --- a/examples/pinproctest/dmd.cpp +++ b/examples/pinproctest/dmd.cpp @@ -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++) { diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 3d4d826..5b41521 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -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); diff --git a/examples/pinproctest/pinproctest.h b/examples/pinproctest/pinproctest.h index 4916fc6..ef1ad12 100644 --- a/examples/pinproctest/pinproctest.h +++ b/examples/pinproctest/pinproctest.h @@ -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); diff --git a/examples/pinproctest/switches.cpp b/examples/pinproctest/switches.cpp index 03feefb..d8e311a 100644 --- a/examples/pinproctest/switches.cpp +++ b/examples/pinproctest/switches.cpp @@ -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; diff --git a/include/pinproc.h b/include/pinproc.h index 1a8cc3d..c6451cf 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -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]; diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 83f3163..e01baa8 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -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; } diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 90da372..fb98f22 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -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); diff --git a/src/PRHardware.h b/src/PRHardware.h index 7465e10..910fc01 100644 --- a/src/PRHardware.h +++ b/src/PRHardware.h @@ -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;