1
0
mirror of https://github.com/preble/libpinproc synced 2026-04-15 23:35:23 +02:00

Merge pull request #11 from tomlogic/dev

Merge outstanding commits to `dev`
This commit is contained in:
Gerry Stellenberg
2020-07-20 17:41:36 -05:00
committed by GitHub
11 changed files with 301 additions and 240 deletions

View File

@@ -13,12 +13,18 @@ if(POLICY CMP0015)
cmake_policy(SET CMP0015 OLD) cmake_policy(SET CMP0015 OLD)
endif() endif()
# allow relative paths in LINK_DIRECTORIES
if(POLICY CMP0081)
cmake_policy(SET CMP0081 OLD)
endif()
### ###
### Project settings ### Project settings
### ###
project(PINPROC) project(PINPROC)
set (CMAKE_CXX_STANDARD 11)
set(PINPROC_VERSION_MAJOR "2") set(PINPROC_VERSION_MAJOR "2")
set(PINPROC_VERSION_MINOR "0") set(PINPROC_VERSION_MINOR "0")
set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}") set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}")
@@ -45,6 +51,7 @@ option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON) option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF) option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF)
option(CROSS_ROOT "Cross-compilation root path" OFF)
### ###
### Sources, headers, directories and libs ### Sources, headers, directories and libs
@@ -69,8 +76,15 @@ if(VERBOSE)
endif() endif()
# use -DEXTRA_INC="<path>;<path>" and -DEXTRA_LINK="<path>;<path>" # use -DEXTRA_INC="<path>;<path>" and -DEXTRA_LINK="<path>;<path>"
set(EXTRA_INC "" CACHE STRING "Extra include directories separated by ;")
set(EXTRA_LINK "" CACHE STRING "Extra link directories separated by ;")
if(CROSS_ROOT)
include_directories(${PINPROC_SOURCE_DIR}/include ${EXTRA_INC} ${CROSS_ROOT}/usr/local/include)
link_directories(${EXTRA_LINK} ${CROSS_ROOT}/usr/local/lib)
else()
include_directories(${PINPROC_SOURCE_DIR}/include ${EXTRA_INC} /usr/local/include) include_directories(${PINPROC_SOURCE_DIR}/include ${EXTRA_INC} /usr/local/include)
link_directories(${EXTRA_LINK} /usr/local/lib) link_directories(${EXTRA_LINK} /usr/local/lib)
endif()
set(YAML_CPP_LIB "yaml-cpp") set(YAML_CPP_LIB "yaml-cpp")
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}") set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}")
@@ -161,6 +175,9 @@ if(MSVC)
set(YAML_CPP_LIB "${CMAKE_STATIC_LIBRARY_PREFIX}${YAML_CPP_LIB}${LIB_RT_SUFFIX}") set(YAML_CPP_LIB "${CMAKE_STATIC_LIBRARY_PREFIX}${YAML_CPP_LIB}${LIB_RT_SUFFIX}")
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d") set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d")
endif() endif()
else()
# make sure executable files are standalone
SET(CMAKE_EXE_LINKER_FLAGS "-static")
endif() endif()

View File

@@ -10,7 +10,6 @@ LIBPINPROC_DYLIB = bin/libpinproc.dylib
SRCS = src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp SRCS = src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp
OBJS := $(SRCS:.cpp=.o) OBJS := $(SRCS:.cpp=.o)
INCLUDES = include/pinproc.h src/PRCommon.h src/PRDevice.h src/PRHardware.h INCLUDES = include/pinproc.h src/PRCommon.h src/PRDevice.h src/PRHardware.h
LIBS = usb ftdi
.PHONY: libpinproc .PHONY: libpinproc
libpinproc: $(LIBPINPROC) $(LIBPINPROC_DYLIB) libpinproc: $(LIBPINPROC) $(LIBPINPROC_DYLIB)
@@ -20,7 +19,7 @@ $(LIBPINPROC): $(OBJS)
$(RANLIB) $@ $(RANLIB) $@
$(LIBPINPROC_DYLIB): $(OBJS) $(LIBPINPROC_DYLIB): $(OBJS)
g++ -dynamiclib -o $@ /usr/local/lib/libftdi.dylib $(LDFLAGS) $(OBJS) g++ -dynamiclib -o $@ `pkg-config --libs libftdi1` $(LDFLAGS) $(OBJS)
.cpp.o: .cpp.o:
$(CC) $(LIBPINPROC_CFLAGS) $(CFLAGS) -o $@ $< $(CC) $(LIBPINPROC_CFLAGS) $(CFLAGS) -o $@ $<

View File

@@ -12,7 +12,7 @@ libpinproc requires:
- [libftdi-0.16](http://www.intra2net.com/en/developer/libftdi/): Install with the default /usr/local prefix. - [libftdi-0.16](http://www.intra2net.com/en/developer/libftdi/): Install with the default /usr/local prefix.
The pinproctest example requires [yaml-cpp](http://code.google.com/p/yaml-cpp/). Follow the build instructions, creating the build subdirectory. After building, from the main source directory, run the following commands to manually install it: The pinproctest example requires [yaml-cpp](https://github.com/jbeder/yaml-cpp). Follow the build instructions, creating the build subdirectory. After building, from the main source directory, run the following commands to manually install it:
sudo cp lib/libyaml-cpp.a /usr/local/lib/ sudo cp lib/libyaml-cpp.a /usr/local/lib/
sudo mkdir /usr/local/include/yaml-cpp sudo mkdir /usr/local/include/yaml-cpp

View File

@@ -46,12 +46,8 @@ PRResult LoadConfiguration(YAML::Node& yamlDoc, const char *yamlFilePath)
fprintf(stderr, "YAML file not found: %s\n", yamlFilePath); fprintf(stderr, "YAML file not found: %s\n", yamlFilePath);
return kPRFailure; return kPRFailure;
} }
YAML::Parser parser(fin);
while(parser) yamlDoc = YAML::Load(fin);
{
parser.GetNextDocument(yamlDoc);
}
} }
// catch (YAML::ParserException& ex) // catch (YAML::ParserException& ex)
// { // {
@@ -341,8 +337,7 @@ int main(int argc, const char **argv)
return 1; return 1;
} }
std::string machineTypeString; std::string machineTypeString = yamlDoc["PRGame"]["machineType"].as<std::string>();
yamlDoc["PRGame"]["machineType"] >> machineTypeString;
if (machineTypeString == "wpc") if (machineTypeString == "wpc")
machineType = kPRMachineWPC; machineType = kPRMachineWPC;
else if (machineTypeString == "wpc95") else if (machineTypeString == "wpc95")

View File

@@ -142,36 +142,34 @@ void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc)
// WPC Flippers // WPC Flippers
std::string numStr; std::string numStr;
const YAML::Node& flippers = yamlDoc[kFlippersSection]; const YAML::Node& flippers = yamlDoc[kFlippersSection];
for (YAML::Iterator flippersIt = flippers.begin(); flippersIt != flippers.end(); ++flippersIt) for (YAML::const_iterator flippersIt = flippers.begin(); flippersIt != flippers.end(); ++flippersIt)
{ {
int swNum, coilMain, coilHold; int swNum, coilMain, coilHold;
std::string flipperName; std::string flipperName = flippersIt->as<std::string>();
*flippersIt >> flipperName;
if (machineType == kPRMachineWPC) if (machineType == kPRMachineWPC)
{ {
yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as<std::string>(); swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as<std::string>(); coilMain = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField] >> numStr; coilHold = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField].as<std::string>(); coilHold = PRDecode(machineType, numStr.c_str());
ConfigureWPCFlipperSwitchRule (proc, swNum, coilMain, coilHold, kFlipperPulseTime); ConfigureWPCFlipperSwitchRule (proc, swNum, coilMain, coilHold, kFlipperPulseTime);
} }
else if (machineType == kPRMachineSternWhitestar || machineType == kPRMachineSternSAM) else if (machineType == kPRMachineSternWhitestar || machineType == kPRMachineSternSAM)
{ {
printf("hi\n"); printf("hi\n");
yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as<std::string>(); swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as<std::string>(); coilMain = PRDecode(machineType, numStr.c_str());
ConfigureSternFlipperSwitchRule (proc, swNum, coilMain, kFlipperPulseTime, kFlipperPatterOnTime, kFlipperPatterOffTime); ConfigureSternFlipperSwitchRule (proc, swNum, coilMain, kFlipperPulseTime, kFlipperPatterOnTime, kFlipperPatterOffTime);
} }
} }
const YAML::Node& bumpers = yamlDoc[kBumpersSection]; const YAML::Node& bumpers = yamlDoc[kBumpersSection];
for (YAML::Iterator bumpersIt = bumpers.begin(); bumpersIt != bumpers.end(); ++bumpersIt) for (YAML::const_iterator bumpersIt = bumpers.begin(); bumpersIt != bumpers.end(); ++bumpersIt)
{ {
int swNum, coilNum; int swNum, coilNum;
// WPC Slingshots // WPC Slingshots
std::string bumperName; std::string bumperName = bumpersIt->as<std::string>();
*bumpersIt >> bumperName; numStr = yamlDoc[kSwitchesSection][bumperName][kNumberField].as<std::string>(); swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kSwitchesSection][bumperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); numStr = yamlDoc[kCoilsSection][bumperName][kNumberField].as<std::string>(); coilNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][bumperName][kNumberField] >> numStr; coilNum = PRDecode(machineType, numStr.c_str());
ConfigureBumperRule (proc, swNum, coilNum, kBumperPulseTime); ConfigureBumperRule (proc, swNum, coilNum, kBumperPulseTime);
} }
} }

View File

@@ -138,6 +138,9 @@ PINPROC_API PRResult PRFlushWriteData(PRHandle handle);
/** Write data out to the P-ROC immediately (does not require a call to PRFlushWriteData). */ /** Write data out to the P-ROC immediately (does not require a call to PRFlushWriteData). */
PINPROC_API PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer); PINPROC_API PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer);
/** Write data buffered to P-ROC (does require a call to PRFlushWriteData). */
PINPROC_API PRResult PRWriteDataUnbuffered(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer);
/** Read data from the P-ROC. */ /** Read data from the P-ROC. */
PINPROC_API PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer); PINPROC_API PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer);

View File

@@ -166,7 +166,7 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
if (SortReturningData() != kPRSuccess) if (SortReturningData() != kPRSuccess)
{ {
PRSetLastErrorText("GetEvents ERROR: Error in CollectReadData"); PRSetLastErrorText("GetEvents ERROR: Error in CollectReadData");
return -1; return -1;
} }
// The unrequestedDataQueue only has unrequested switch event data. Pop // The unrequestedDataQueue only has unrequested switch event data. Pop
@@ -265,10 +265,9 @@ PRResult PRDevice::ManagerUpdateConfig(PRManagerConfig *managerConfig)
{ {
const int burstWords = 2; const int burstWords = 2;
uint32_t burst[burstWords]; uint32_t burst[burstWords];
int32_t rc;
DEBUG(PRLog(kPRLogInfo, "Setting Manager Config Register\n")); DEBUG(PRLog(kPRLogInfo, "Setting Manager Config Register\n"));
this->managerConfig = *managerConfig; this->managerConfig = *managerConfig;
rc = CreateManagerUpdateConfigBurst(burst, managerConfig); CreateManagerUpdateConfigBurst(burst, managerConfig);
return PrepareWriteData(burst, burstWords); return PrepareWriteData(burst, burstWords);
} }
@@ -276,15 +275,14 @@ PRResult PRDevice::DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalCo
{ {
const int burstWords = 4; const int burstWords = 4;
uint32_t burst[burstWords]; uint32_t burst[burstWords];
int32_t rc;
DEBUG(PRLog(kPRLogInfo, "Installing driver globals\n")); DEBUG(PRLog(kPRLogInfo, "Installing driver globals\n"));
this->driverGlobalConfig = *driverGlobalConfig; this->driverGlobalConfig = *driverGlobalConfig;
rc = CreateDriverUpdateGlobalConfigBurst(burst, driverGlobalConfig); CreateDriverUpdateGlobalConfigBurst(burst, driverGlobalConfig);
rc = CreateWatchdogConfigBurst(burst+2, driverGlobalConfig->watchdogExpired, CreateWatchdogConfigBurst(burst+2, driverGlobalConfig->watchdogExpired,
driverGlobalConfig->watchdogEnable, driverGlobalConfig->watchdogEnable,
driverGlobalConfig->watchdogResetTime); driverGlobalConfig->watchdogResetTime);
DEBUG(PRLog(kPRLogVerbose, "Driver Global words: %x %x\n", burst[0], burst[1])); DEBUG(PRLog(kPRLogVerbose, "Driver Global words: %x %x\n", burst[0], burst[1]));
DEBUG(PRLog(kPRLogVerbose, "Watchdog words: %x %x\n", burst[2], burst[3])); DEBUG(PRLog(kPRLogVerbose, "Watchdog words: %x %x\n", burst[2], burst[3]));
@@ -301,11 +299,10 @@ PRResult PRDevice::DriverUpdateGroupConfig(PRDriverGroupConfig *driverGroupConfi
{ {
const int burstWords = 2; const int burstWords = 2;
uint32_t burst[burstWords]; uint32_t burst[burstWords];
int32_t rc;
driverGroups[driverGroupConfig->groupNum] = *driverGroupConfig; driverGroups[driverGroupConfig->groupNum] = *driverGroupConfig;
DEBUG(PRLog(kPRLogInfo, "Installing driver group\n")); DEBUG(PRLog(kPRLogInfo, "Installing driver group\n"));
rc = CreateDriverUpdateGroupConfigBurst(burst, driverGroupConfig); CreateDriverUpdateGroupConfigBurst(burst, driverGroupConfig);
DEBUG(PRLog(kPRLogVerbose, "Words: %x %x\n", burst[0], burst[1])); DEBUG(PRLog(kPRLogVerbose, "Words: %x %x\n", burst[0], burst[1]));
return PrepareWriteData(burst, burstWords); return PrepareWriteData(burst, burstWords);
@@ -321,7 +318,6 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *driverState)
{ {
const int burstWords = 3; const int burstWords = 3;
uint32_t burst[burstWords]; uint32_t burst[burstWords];
int32_t rc;
// Don't allow Constant Pulse (non-schedule with time = 0) for known high current drivers. // Don't allow Constant Pulse (non-schedule with time = 0) for known high current drivers.
// Note, the driver numbers depend on the driver group settings from DriverLoadMachineTypeDefaults. // Note, the driver numbers depend on the driver group settings from DriverLoadMachineTypeDefaults.
@@ -337,7 +333,7 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *driverState)
drivers[driverState->driverNum] = *driverState; drivers[driverState->driverNum] = *driverState;
rc = CreateDriverUpdateBurst(burst, &drivers[driverState->driverNum]); CreateDriverUpdateBurst(burst, &drivers[driverState->driverNum]);
DEBUG(PRLog(kPRLogVerbose, "Words: %x %x %x\n", burst[0], burst[1], burst[2])); DEBUG(PRLog(kPRLogVerbose, "Words: %x %x %x\n", burst[0], burst[1], burst[2]));
return PrepareWriteData(burst, burstWords); return PrepareWriteData(burst, burstWords);
@@ -598,11 +594,10 @@ PRResult PRDevice::DriverWatchdogTickle()
{ {
const int burstWords = 2; const int burstWords = 2;
uint32_t burst[burstWords]; uint32_t burst[burstWords];
int32_t rc;
rc = CreateWatchdogConfigBurst(burst, driverGlobalConfig.watchdogExpired, CreateWatchdogConfigBurst(burst, driverGlobalConfig.watchdogExpired,
driverGlobalConfig.watchdogEnable, driverGlobalConfig.watchdogEnable,
driverGlobalConfig.watchdogResetTime); driverGlobalConfig.watchdogResetTime);
return PrepareWriteData(burst, burstWords); return PrepareWriteData(burst, burstWords);
} }
@@ -768,7 +763,6 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwitches ) PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwitches )
{ {
uint32_t rc;
uint32_t stateWord, debounceWord; uint32_t stateWord, debounceWord;
uint8_t i, j; uint8_t i, j;
PREventType eventType; PREventType eventType;
@@ -783,25 +777,25 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
if (chip_id == P_ROC_CHIP_ID) if (chip_id == P_ROC_CHIP_ID)
{ {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT, RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1); P_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
if (combinedVersionRevision < P_ROC_VER_REV_FIXED_SWITCH_STATE_READS) { if (combinedVersionRevision < P_ROC_VER_REV_FIXED_SWITCH_STATE_READS) {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT, RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_OLD_DEBOUNCE_BASE_ADDR + i, 1); P_ROC_SWITCH_CTRL_OLD_DEBOUNCE_BASE_ADDR + i, 1);
} }
else { else {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT, RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1); P_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1);
} }
} }
else // chip == P3_ROC_CHIP_ID) else // chip == P3_ROC_CHIP_ID)
{ {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT, RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P3_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1); P3_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT, RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P3_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1); P3_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1);
} }
} }
@@ -816,7 +810,9 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
{ {
PRSleep (10); // 10 milliseconds should be plenty of time. PRSleep (10); // 10 milliseconds should be plenty of time.
if (SortReturningData() != kPRSuccess) if (SortReturningData() != kPRSuccess)
{
return kPRFailure; return kPRFailure;
}
} }
// Make sure all of the requested words are available before processing them. // Make sure all of the requested words are available before processing them.
@@ -851,7 +847,11 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
} }
return kPRSuccess; return kPRSuccess;
} }
else return kPRFailure; else
{
PRSetLastErrorText("Switch response length does not match.");
return kPRFailure;
}
} }
int32_t PRDevice::DMDUpdateConfig(PRDMDConfig *dmdConfig) int32_t PRDevice::DMDUpdateConfig(PRDMDConfig *dmdConfig)
@@ -1093,6 +1093,7 @@ PRResult PRDevice::VerifyChipID()
DEBUG(PRLog(kPRLogError, "Error in VerifyID(): Dumping buffer\n")); DEBUG(PRLog(kPRLogError, "Error in VerifyID(): Dumping buffer\n"));
for (i = 0; i < bufferWords; i++) for (i = 0; i < bufferWords; i++)
DEBUG(PRLog(kPRLogError, "buffer[%d]: 0x%x\n", i, buffer[i])); DEBUG(PRLog(kPRLogError, "buffer[%d]: 0x%x\n", i, buffer[i]));
PRSetLastErrorText("Chip ID does not match.");
rc = kPRFailure; rc = kPRFailure;
} }
else rc = kPRSuccess; else rc = kPRSuccess;
@@ -1110,7 +1111,8 @@ PRResult PRDevice::VerifyChipID()
else readMachineType = kPRMachineWPC; // Choose WPC or WPC95, doesn't matter. else readMachineType = kPRMachineWPC; // Choose WPC or WPC95, doesn't matter.
} }
else { else {
DEBUG(PRLog(kPRLogError, "Error reading Chip IP and Version. Read %d words instead of 5. The first 2 were: 0x%x and 0x%x.\n", requestedDataQueue.size(), buffer[0], buffer[1])); DEBUG(PRLog(kPRLogError, "Error reading Chip IP and Version. Read %d words instead of 5. The first 2 were: 0x%x and 0x%x.\n", requestedDataQueue.size(), buffer[0], buffer[1]));
PRSetLastErrorText("Error reading Chip IP and Version. Read %d words instead of 5. The first 2 were: 0x%x and 0x%x.", requestedDataQueue.size(), buffer[0], buffer[1]);
rc = kPRFailure; rc = kPRFailure;
} }
} }
@@ -1118,6 +1120,7 @@ PRResult PRDevice::VerifyChipID()
{ {
// Return failure without logging; calling function must log. // Return failure without logging; calling function must log.
DEBUG(PRLog(kPRLogError, "Verify Chip ID took too long to receive data\n")); DEBUG(PRLog(kPRLogError, "Verify Chip ID took too long to receive data\n"));
PRSetLastErrorText("Verify Chip ID took too long to receive data");
rc = kPRFailure; rc = kPRFailure;
} }
return (rc); return (rc);
@@ -1179,10 +1182,6 @@ PRResult PRDevice::WriteData(uint32_t * words, int32_t numWords)
wr_buffer[(j*4)+k] = (uint8_t)(temp_word & 0x000000ff); wr_buffer[(j*4)+k] = (uint8_t)(temp_word & 0x000000ff);
temp_word = temp_word >> 8; temp_word = temp_word >> 8;
} }
// for (k=0; k<4; k++)
// {
// item = wr_buffer[(j*4)+k];
// }
} }
int bytesToWrite = numWords * 4; int bytesToWrite = numWords * 4;
@@ -1199,6 +1198,19 @@ PRResult PRDevice::WriteData(uint32_t * words, int32_t numWords)
} }
} }
PRResult PRDevice::WriteDataRawUnbuffered(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer)
{
PRResult res;
uint32_t * buffer;
buffer = (uint32_t *)malloc((numWriteWords * 4) + 4);
buffer[0] = CreateBurstCommand(moduleSelect, startingAddr, numWriteWords);
memcpy(buffer+1, writeBuffer, numWriteWords * 4);
res = PrepareWriteData(buffer, numWriteWords + 1);
free (buffer);
return res;
}
PRResult PRDevice::WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer) PRResult PRDevice::WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer)
{ {
PRResult res; PRResult res;
@@ -1214,11 +1226,10 @@ PRResult PRDevice::WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, in
PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer) PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer)
{ {
uint32_t rc; int32_t i;
uint32_t i;
// Send out the request. // Send out the request.
rc = RequestData(moduleSelect, startingAddr, numReadWords); RequestData(moduleSelect, startingAddr, numReadWords);
i = 0; // Reset i so it can be used to prevent an infinite loop below i = 0; // Reset i so it can be used to prevent an infinite loop below
@@ -1244,7 +1255,11 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int
} }
return kPRSuccess; return kPRSuccess;
} }
else return kPRFailure; else
{
PRSetLastErrorText("Response length did not match.");
return kPRFailure;
}
} }
@@ -1273,6 +1288,7 @@ int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words)
rc = num_words; rc = num_words;
} }
else { else {
PRSetLastErrorText("Read length did not match.");
rc = 0; rc = 0;
} }
DEBUG(PRLog(kPRLogVerbose, "Read num bytes: %d\n", rc)); DEBUG(PRLog(kPRLogVerbose, "Read num bytes: %d\n", rc));
@@ -1281,10 +1297,9 @@ int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words)
PRResult PRDevice::FlushReadBuffer() PRResult PRDevice::FlushReadBuffer()
{ {
int32_t numBytes,rc=0,k; int32_t numBytes,rc=0;
//uint32_t rd_buffer[3]; //uint32_t rd_buffer[3];
numBytes = CollectReadData(); numBytes = CollectReadData();
k = 0;
DEBUG(PRLog(kPRLogError, "Flushing Read Buffer: %d bytes trashed\n", numBytes)); DEBUG(PRLog(kPRLogError, "Flushing Read Buffer: %d bytes trashed\n", numBytes));
//while (k < numBytes) { //while (k < numBytes) {
@@ -1320,7 +1335,7 @@ int32_t PRDevice::CollectReadData()
PRResult PRDevice::SortReturningData() PRResult PRDevice::SortReturningData()
{ {
int32_t num_bytes, num_words, rc; int32_t num_bytes, num_words;
uint32_t rd_buffer[FTDI_BUFFER_SIZE/4]; uint32_t rd_buffer[FTDI_BUFFER_SIZE/4];
num_bytes = CollectReadData(); num_bytes = CollectReadData();
@@ -1332,7 +1347,7 @@ PRResult PRDevice::SortReturningData()
num_words = num_collected_bytes/4; num_words = num_collected_bytes/4;
while (num_words >= 2) { while (num_words >= 2) {
rc = ReadData(rd_buffer, 1); ReadData(rd_buffer, 1);
DEBUG(PRLog(kPRLogVerbose, "New returning word: 0x%x\n", rd_buffer[0])); DEBUG(PRLog(kPRLogVerbose, "New returning word: 0x%x\n", rd_buffer[0]));
switch ( (rd_buffer[0] & P_ROC_COMMAND_MASK) >> P_ROC_COMMAND_SHIFT) switch ( (rd_buffer[0] & P_ROC_COMMAND_MASK) >> P_ROC_COMMAND_SHIFT)

View File

@@ -60,6 +60,7 @@ public:
PRResult FlushWriteData(); PRResult FlushWriteData();
PRResult WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * buffer); PRResult WriteDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * buffer);
PRResult WriteDataRawUnbuffered(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 ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer);
PRResult ManagerUpdateConfig(PRManagerConfig *managerConfig); PRResult ManagerUpdateConfig(PRManagerConfig *managerConfig);

View File

@@ -389,6 +389,7 @@ PRResult PRHardwareOpen()
ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER); ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER);
if(ftStatus != FT_OK) { if(ftStatus != FT_OK) {
PRSetLastErrorText("FT_ListDevices(%d)\n", ftStatus);
DEBUG(PRLog(kPRLogInfo,"Error: FT_ListDevices(%d)\n", ftStatus)); DEBUG(PRLog(kPRLogInfo,"Error: FT_ListDevices(%d)\n", ftStatus));
return kPRFailure; return kPRFailure;
} }
@@ -410,6 +411,7 @@ PRResult PRHardwareOpen()
also rmmod usbserial also rmmod usbserial
*/ */
DEBUG(PRLog(kPRLogInfo,"Error FT_OpenEx(%d), device\n", ftStatus, i)); DEBUG(PRLog(kPRLogInfo,"Error FT_OpenEx(%d), device\n", ftStatus, i));
PRSetLastErrorText("Error FT_OpenEx(%d), device\n", ftStatus, i);
return kPRFailure; return kPRFailure;
} }
@@ -429,7 +431,11 @@ PRResult PRHardwareOpen()
DEBUG(PRLog(kPRLogInfo,"FTDI Device Opened\n")); DEBUG(PRLog(kPRLogInfo,"FTDI Device Opened\n"));
return kPRSuccess; return kPRSuccess;
} }
else return kPRFailure; else
{
PRSetLastErrorText("No FTDI device found.");
return kPRFailure;
}
} }
void PRHardwareClose() void PRHardwareClose()

View File

@@ -119,12 +119,18 @@ 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 */ /** Write data out to the P-ROC immediately (does not require a call to PRFlushWriteData). */
PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer) PRResult PRWriteData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer)
{ {
return handleAsDevice->WriteDataRaw(moduleSelect, startingAddr, numWriteWords, writeBuffer); return handleAsDevice->WriteDataRaw(moduleSelect, startingAddr, numWriteWords, writeBuffer);
} }
/** Write data buffered to P-ROC (does require a call to PRFlushWriteData). */
PRResult PRWriteDataUnbuffered(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numWriteWords, uint32_t * writeBuffer)
{
return handleAsDevice->WriteDataRawUnbuffered(moduleSelect, startingAddr, numWriteWords, writeBuffer);
}
/** Read data from the P-ROC. */ /** Read data from the P-ROC. */
PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer) PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer)
{ {

View File

@@ -2051,6 +2051,8 @@ int verifyP3ROCImage()
} }
XSVFDBG_PRINTF( 0, "\n\nSUCCESS - Operation completed successfully. Cycle P3-ROC power to activate any changes.\n" ); XSVFDBG_PRINTF( 0, "\n\nSUCCESS - Operation completed successfully. Cycle P3-ROC power to activate any changes.\n" );
return 1;
} }
void writeP3ROCImage() void writeP3ROCImage()
@@ -2134,13 +2136,10 @@ int processFile()
endClock = clock(); endClock = clock();
fclose( in ); fclose( in );
// Destroy the P-ROC device handle:
PRDelete(proc);
proc = kPRHandleInvalid;
return iErrorCode; return iErrorCode;
} }
int checkPROCFile() { uint32_t checkPROCFile() {
uint32_t checksum=0, file_checksum, file_board_id, header_checksum; uint32_t checksum=0, file_checksum, file_board_id, header_checksum;
unsigned char data; unsigned char data;
int i=0,file_i=0; int i=0,file_i=0;
@@ -2176,10 +2175,20 @@ int checkPROCFile() {
PRReadData(proc, 0, 0, 4, readdata); PRReadData(proc, 0, 0, 4, readdata);
board_id = readdata[0]; board_id = readdata[0];
board_rev = readdata[3]; board_rev = readdata[3];
board_rev = (board_rev & 0x80) >> 7 | if (board_id == P3_ROC_CHIP_ID) {
(board_rev & 0x40) >> 5 | board_rev = (board_rev & 0x800) >> 11 |
(board_rev & 0x20) >> 3 | (board_rev & 0x400) >> 10 |
(board_rev & 0x10) >> 1; (board_rev & 0x200) >> 9 |
(board_rev & 0x100) >> 8;
fprintf(stderr, "\nReading P3-ROC board_rev: %d", board_rev);
}
else {
board_rev = (board_rev & 0x80) >> 7 |
(board_rev & 0x40) >> 6 |
(board_rev & 0x20) >> 5 |
(board_rev & 0x10) >> 4;
fprintf(stderr, "\nReading P-ROC board_rev: %d", board_rev);
}
if (proc_file_version != 0) { if (proc_file_version != 0) {
fprintf(stderr, "\nERROR: Unsupported .p-roc file version: %x. Check for an updated version of this tool.\n\n", proc_file_version); fprintf(stderr, "\nERROR: Unsupported .p-roc file version: %x. Check for an updated version of this tool.\n\n", proc_file_version);
@@ -2197,6 +2206,14 @@ int checkPROCFile() {
return 0; return 0;
} }
else fprintf(stderr, "\nBoard ID verified"); else fprintf(stderr, "\nBoard ID verified");
if (board_rev > max_board_rev) {
fprintf(stderr, "\nERROR: board_rev %d > max_board_rev %d", board_rev, max_board_rev);
}
if (board_rev < min_board_rev) {
fprintf(stderr, "\nERROR: board_rev < min_board_rev");
}
if (board_rev > max_board_rev || board_rev < min_board_rev) { if (board_rev > max_board_rev || board_rev < min_board_rev) {
fprintf(stderr, "\nERROR: This image is not compatible with the P-ROC board (rev: %x)", board_id); fprintf(stderr, "\nERROR: This image is not compatible with the P-ROC board (rev: %x)", board_id);
return 0; return 0;
@@ -2303,8 +2320,12 @@ int main( int argc, char** argv )
processP3ROCFile(); processP3ROCFile();
break; break;
default: default:
fprintf(stderr, "Failed to parse file.\n");
break; break;
} }
// Destroy the P-ROC device handle created by openPROC()
PRDelete(proc);
proc = kPRHandleInvalid;
} }
} }
} }