1
0
mirror of https://github.com/preble/libpinproc synced 2026-04-13 23:25:24 +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)
endif()
# allow relative paths in LINK_DIRECTORIES
if(POLICY CMP0081)
cmake_policy(SET CMP0081 OLD)
endif()
###
### Project settings
###
project(PINPROC)
set (CMAKE_CXX_STANDARD 11)
set(PINPROC_VERSION_MAJOR "2")
set(PINPROC_VERSION_MINOR "0")
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_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
@@ -69,8 +76,15 @@ if(VERBOSE)
endif()
# 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)
link_directories(${EXTRA_LINK} /usr/local/lib)
endif()
set(YAML_CPP_LIB "yaml-cpp")
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_DBG "${YAML_CPP_LIB}d")
endif()
else()
# make sure executable files are standalone
SET(CMAKE_EXE_LINKER_FLAGS "-static")
endif()

View File

@@ -10,7 +10,6 @@ LIBPINPROC_DYLIB = bin/libpinproc.dylib
SRCS = src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp
OBJS := $(SRCS:.cpp=.o)
INCLUDES = include/pinproc.h src/PRCommon.h src/PRDevice.h src/PRHardware.h
LIBS = usb ftdi
.PHONY: libpinproc
libpinproc: $(LIBPINPROC) $(LIBPINPROC_DYLIB)
@@ -20,7 +19,7 @@ $(LIBPINPROC): $(OBJS)
$(RANLIB) $@
$(LIBPINPROC_DYLIB): $(OBJS)
g++ -dynamiclib -o $@ /usr/local/lib/libftdi.dylib $(LDFLAGS) $(OBJS)
g++ -dynamiclib -o $@ `pkg-config --libs libftdi1` $(LDFLAGS) $(OBJS)
.cpp.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.
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 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);
return kPRFailure;
}
YAML::Parser parser(fin);
while(parser)
{
parser.GetNextDocument(yamlDoc);
}
yamlDoc = YAML::Load(fin);
}
// catch (YAML::ParserException& ex)
// {
@@ -341,8 +337,7 @@ int main(int argc, const char **argv)
return 1;
}
std::string machineTypeString;
yamlDoc["PRGame"]["machineType"] >> machineTypeString;
std::string machineTypeString = yamlDoc["PRGame"]["machineType"].as<std::string>();
if (machineTypeString == "wpc")
machineType = kPRMachineWPC;
else if (machineTypeString == "wpc95")

View File

@@ -142,36 +142,34 @@ void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc)
// WPC Flippers
std::string numStr;
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;
std::string flipperName;
*flippersIt >> flipperName;
std::string flipperName = flippersIt->as<std::string>();
if (machineType == kPRMachineWPC)
{
yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField] >> numStr; coilHold = PRDecode(machineType, numStr.c_str());
numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as<std::string>(); swNum = PRDecode(machineType, numStr.c_str());
numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as<std::string>(); coilMain = 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);
}
else if (machineType == kPRMachineSternWhitestar || machineType == kPRMachineSternSAM)
{
printf("hi\n");
yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str());
numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as<std::string>(); swNum = 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);
}
}
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;
// WPC Slingshots
std::string bumperName;
*bumpersIt >> bumperName;
yamlDoc[kSwitchesSection][bumperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str());
yamlDoc[kCoilsSection][bumperName][kNumberField] >> numStr; coilNum = PRDecode(machineType, numStr.c_str());
std::string bumperName = bumpersIt->as<std::string>();
numStr = yamlDoc[kSwitchesSection][bumperName][kNumberField].as<std::string>(); swNum = PRDecode(machineType, numStr.c_str());
numStr = yamlDoc[kCoilsSection][bumperName][kNumberField].as<std::string>(); coilNum = PRDecode(machineType, numStr.c_str());
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). */
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. */
PINPROC_API PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer);

View File

@@ -71,15 +71,15 @@ PRDevice* PRDevice::Create(PRMachineType machineType)
if (machineType != kPRMachineCustom && machineType != kPRMachinePDB &&
// Don't accept if requested type is WPC/WPC95 but read machine is not.
( (((machineType == kPRMachineWPC) ||
( (((machineType == kPRMachineWPC) ||
(machineType == kPRMachineWPC95) ||
(machineType == kPRMachineWPCAlphanumeric)) &&
(readMachineType != kPRMachineWPC &&
(machineType == kPRMachineWPCAlphanumeric)) &&
(readMachineType != kPRMachineWPC &&
readMachineType != kPRMachineWPC95 &&
readMachineType != kPRMachineWPCAlphanumeric)) ||
// Also don't accept if the requested is not WPC/WPC95 but the P-ROC is.
(machineType != kPRMachineWPC &&
machineType != kPRMachineWPC95 &&
(machineType != kPRMachineWPC &&
machineType != kPRMachineWPC95 &&
machineType != kPRMachineWPCAlphanumeric &&
readMachineType == kPRMachineWPC) ) )
{
@@ -95,7 +95,7 @@ PRDevice* PRDevice::Create(PRMachineType machineType)
PRResult PRDevice::Reset(uint32_t resetFlags)
{
int i;
// Initialize buffer pointers
collected_bytes_rd_addr = 0;
collected_bytes_wr_addr = 0;
@@ -106,12 +106,12 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
while (!requestedDataQueue.empty()) requestedDataQueue.pop();
num_collected_bytes = 0;
numPreparedWriteWords = 0;
if (machineType != kPRMachineCustom && machineType != kPRMachinePDB) DriverLoadMachineTypeDefaults(machineType, resetFlags);
// Disable dmd events if updating the device.
#if 0
if (resetFlags & kPRResetFlagUpdateDevice)
if (resetFlags & kPRResetFlagUpdateDevice)
{
PRDMDConfig *dmdConfig = &(this->dmdConfig);
dmdConfig->enableFrameEvents = false;
@@ -121,9 +121,9 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
// Make sure the free list is empty.
while (!freeSwitchRuleIndexes.empty()) freeSwitchRuleIndexes.pop();
memset(switchRules, 0x00, sizeof(PRSwitchRuleInternal) * maxSwitchRules);
for (i = 0; i < kPRSwitchRulesCount; i++)
{
PRSwitchRuleInternal *switchRule = &switchRules[i];
@@ -137,15 +137,15 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
// However, some of the switches are always optos and don't need to be debounced.
// So the debounced rule resources for those switches are available for linked rules.
if (switchRule->switchNum >= kPRSwitchNeverDebounceFirst &&
(switchRule->eventType == kPREventTypeSwitchClosedDebounced ||
switchRule->eventType == kPREventTypeSwitchOpenDebounced))
(switchRule->eventType == kPREventTypeSwitchClosedDebounced ||
switchRule->eventType == kPREventTypeSwitchOpenDebounced))
freeSwitchRuleIndexes.push(ruleIndex);
}
// Create empty switch rule for clearing the rules in the device.
PRSwitchRule emptySwitchRule;
PRSwitchRule emptySwitchRule;
memset(&emptySwitchRule, 0x00, sizeof(PRSwitchRule));
for (i = 0; i < kPRSwitchCount; i++)
{
// Send blank rule for each event type to Device if necessary
@@ -166,7 +166,7 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
if (SortReturningData() != kPRSuccess)
{
PRSetLastErrorText("GetEvents ERROR: Error in CollectReadData");
return -1;
return -1;
}
// The unrequestedDataQueue only has unrequested switch event data. Pop
@@ -177,7 +177,7 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
uint32_t event_data = unrequestedDataQueue.front();
unrequestedDataQueue.pop();
int type;
int type;
bool open, debounced;
if (version >= 2) {
@@ -205,7 +205,7 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
events[i].type = debounced ? kPREventTypeSwitchOpenDebounced : kPREventTypeSwitchOpenNondebounced;
else
events[i].type = debounced ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchClosedNondebounced;
break;
break;
}
case P_ROC_EVENT_TYPE_DMD:
@@ -219,7 +219,7 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
//fprintf(stderr, "\nBurst event");
if (open) events[i].type = kPREventTypeBurstSwitchOpen;
else events[i].type = kPREventTypeBurstSwitchClosed;
break;
break;
}
case P_ROC_EVENT_TYPE_ACCELEROMETER:
@@ -255,8 +255,8 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
}
default: events[i].type = kPREventTypeInvalid;
}
}
}
return i;
}
@@ -265,10 +265,9 @@ PRResult PRDevice::ManagerUpdateConfig(PRManagerConfig *managerConfig)
{
const int burstWords = 2;
uint32_t burst[burstWords];
int32_t rc;
DEBUG(PRLog(kPRLogInfo, "Setting Manager Config Register\n"));
this->managerConfig = *managerConfig;
rc = CreateManagerUpdateConfigBurst(burst, managerConfig);
CreateManagerUpdateConfigBurst(burst, managerConfig);
return PrepareWriteData(burst, burstWords);
}
@@ -276,15 +275,14 @@ PRResult PRDevice::DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalCo
{
const int burstWords = 4;
uint32_t burst[burstWords];
int32_t rc;
DEBUG(PRLog(kPRLogInfo, "Installing driver globals\n"));
this->driverGlobalConfig = *driverGlobalConfig;
rc = CreateDriverUpdateGlobalConfigBurst(burst, driverGlobalConfig);
rc = CreateWatchdogConfigBurst(burst+2, driverGlobalConfig->watchdogExpired,
driverGlobalConfig->watchdogEnable,
driverGlobalConfig->watchdogResetTime);
CreateDriverUpdateGlobalConfigBurst(burst, driverGlobalConfig);
CreateWatchdogConfigBurst(burst+2, driverGlobalConfig->watchdogExpired,
driverGlobalConfig->watchdogEnable,
driverGlobalConfig->watchdogResetTime);
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]));
@@ -301,11 +299,10 @@ PRResult PRDevice::DriverUpdateGroupConfig(PRDriverGroupConfig *driverGroupConfi
{
const int burstWords = 2;
uint32_t burst[burstWords];
int32_t rc;
driverGroups[driverGroupConfig->groupNum] = *driverGroupConfig;
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]));
return PrepareWriteData(burst, burstWords);
@@ -321,10 +318,9 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *driverState)
{
const int burstWords = 3;
uint32_t burst[burstWords];
int32_t rc;
// 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.
// TODO: Create some constants that are used both here and in DriverLoadMachineTypeDefaults.
DEBUG(PRLog(kPRLogInfo, "Updating driver #%d\n", driverState->driverNum));
@@ -337,7 +333,7 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *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]));
return PrepareWriteData(burst, burstWords);
@@ -347,10 +343,10 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
{
int i;
PRResult res = kPRSuccess;
//const int WPCDriverLoopTime = 4; // milliseconds
//const int SternDriverLoopTime = 2; // milliseconds
const int mappedWPCDriverGroupEnableIndex[] = {0, 0, 0, 0, 0, 2, 4, 3, 1, 5, 7, 7, 7, 7, 7, 7, 7, 7, 8, 0, 0, 0, 0, 0, 0, 0};
const int mappedSternDriverGroupEnableIndex[] = {0, 0, 0, 0, 1, 0, 2, 3, 0, 0, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9};
const bool mappedWPCDriverGroupPolarity[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0};
@@ -361,9 +357,9 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
const int mappedSternDriverGroupSlowTime[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400};
const int mappedWPCDriverGroupActivateIndex[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0};
const int mappedSternDriverGroupActivateIndex[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
const int watchdogResetTime = 1000; // milliseconds
int mappedDriverGroupEnableIndex[kPRDriverGroupsMax];
bool mappedDriverGroupPolarity[kPRDriverGroupsMax];
int mappedDriverGroupSlowTime[kPRDriverGroupsMax];
@@ -380,51 +376,51 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
int rowEnableSelect;
int lastCoilDriverGroup;
switch (machineType)
switch (machineType)
{
case kPRMachineWPC:
case kPRMachineWPC95:
case kPRMachineWPCAlphanumeric:
case kPRMachineWPC:
case kPRMachineWPC95:
case kPRMachineWPCAlphanumeric:
{
memcpy(mappedDriverGroupEnableIndex,mappedWPCDriverGroupEnableIndex,
sizeof(mappedDriverGroupEnableIndex));
memcpy(mappedDriverGroupPolarity,mappedWPCDriverGroupPolarity,
sizeof(mappedDriverGroupPolarity));
memcpy(mappedDriverGroupEnableIndex,mappedWPCDriverGroupEnableIndex,
sizeof(mappedDriverGroupEnableIndex));
memcpy(mappedDriverGroupPolarity,mappedWPCDriverGroupPolarity,
sizeof(mappedDriverGroupPolarity));
rowEnableIndex1 = 6; // Unused in WPC
rowEnableIndex0 = 6;
tickleSternWatchdog = false;
globalPolarity = false;
activeLowMatrixRows = true;
driverLoopTime = 4; // milliseconds
memcpy(mappedDriverGroupSlowTime,mappedWPCDriverGroupSlowTime,
sizeof(mappedDriverGroupSlowTime));
memcpy(mappedDriverGroupActivateIndex,mappedWPCDriverGroupActivateIndex,
sizeof(mappedDriverGroupActivateIndex));
memcpy(mappedDriverGroupSlowTime,mappedWPCDriverGroupSlowTime,
sizeof(mappedDriverGroupSlowTime));
memcpy(mappedDriverGroupActivateIndex,mappedWPCDriverGroupActivateIndex,
sizeof(mappedDriverGroupActivateIndex));
numMatrixGroups = 8;
encodeEnables = false;
rowEnableSelect = 0;
lastCoilDriverGroup = lastWPCCoilDriverGroup;
break;
}
case kPRMachineSternWhitestar:
case kPRMachineSternSAM:
case kPRMachineSternWhitestar:
case kPRMachineSternSAM:
{
memcpy(mappedDriverGroupEnableIndex,mappedSternDriverGroupEnableIndex,
sizeof(mappedDriverGroupEnableIndex));
memcpy(mappedDriverGroupPolarity,mappedSternDriverGroupPolarity,
sizeof(mappedDriverGroupPolarity));
memcpy(mappedDriverGroupEnableIndex,mappedSternDriverGroupEnableIndex,
sizeof(mappedDriverGroupEnableIndex));
memcpy(mappedDriverGroupPolarity,mappedSternDriverGroupPolarity,
sizeof(mappedDriverGroupPolarity));
rowEnableIndex1 = 6; // Unused in Stern
rowEnableIndex0 = 10;
tickleSternWatchdog = true;
globalPolarity = true;
activeLowMatrixRows = false;
driverLoopTime = 1; // milliseconds
memcpy(mappedDriverGroupSlowTime,mappedSternDriverGroupSlowTime,
sizeof(mappedDriverGroupSlowTime));
memcpy(mappedDriverGroupActivateIndex,mappedSternDriverGroupActivateIndex,
sizeof(mappedDriverGroupActivateIndex));
memcpy(mappedDriverGroupSlowTime,mappedSternDriverGroupSlowTime,
sizeof(mappedDriverGroupSlowTime));
memcpy(mappedDriverGroupActivateIndex,mappedSternDriverGroupActivateIndex,
sizeof(mappedDriverGroupActivateIndex));
numMatrixGroups = 16;
encodeEnables = true;
rowEnableSelect = 0;
@@ -439,7 +435,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
return kPRSuccess;
}
memset(&driverGlobalConfig, 0x00, sizeof(PRDriverGlobalConfig));
for (i = 0; i < kPRDriverCount; i++)
{
@@ -448,7 +444,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
driver->driverNum = i;
driver->polarity = mappedDriverGroupPolarity[i/8];
DEBUG(PRLog(kPRLogInfo,"\nDriver Polarity for Driver: %d is %x.", i,driver->polarity));
if (resetFlags & kPRResetFlagUpdateDevice)
if (resetFlags & kPRResetFlagUpdateDevice)
res = DriverUpdateState(driver);
}
for (i = 0; i < kPRDriverGroupsMax; i++)
@@ -458,11 +454,11 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
group->groupNum = i;
group->polarity = mappedDriverGroupPolarity[i];
}
// Configure the groups. Each group corresponds to 8 consecutive drivers, starting
// with driver #32. The following 6 groups are configured for coils/flashlamps.
PRDriverGroupConfig group;
for (i = 4; i <= lastCoilDriverGroup; i++)
{
@@ -475,7 +471,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
group.polarity = mappedDriverGroupPolarity[i];
group.active = 1;
group.disableStrobeAfter = false;
if (resetFlags & kPRResetFlagUpdateDevice) {
res = DriverUpdateGroupConfig(&group);
DEBUG(PRLog(kPRLogInfo,"\nDriver Polarity for Group: %d is %x.", i,group.polarity));
@@ -484,7 +480,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
driverGroups[i] = group;
}
// The following 8 groups are configured for the feature lamp matrix.
for (i = 10; i < 10 + numMatrixGroups; i++) {
DriverGetGroupConfig(i, &group);
@@ -496,7 +492,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
group.polarity = mappedDriverGroupPolarity[i];
group.active = 1;
group.disableStrobeAfter = mappedDriverGroupSlowTime[i] != 0;
if (resetFlags & kPRResetFlagUpdateDevice) {
res = DriverUpdateGroupConfig(&group);
DEBUG(PRLog(kPRLogInfo,"\nDriver Polarity for Group: %d is %x.", i,group.polarity));
@@ -517,7 +513,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
group.polarity = mappedDriverGroupPolarity[i];
group.active = 1;
group.disableStrobeAfter = false;
if (resetFlags & kPRResetFlagUpdateDevice) {
res = DriverUpdateGroupConfig(&group);
DEBUG(PRLog(kPRLogInfo,"\nDriver Polarity for Group: %d is %x.\n", i,group.polarity));
@@ -540,16 +536,16 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
globals.watchdogExpired = false;
globals.watchdogEnable = true;
globals.watchdogResetTime = watchdogResetTime;
// We want to start up safely, so we'll update the global driver config twice.
// When we toggle enableOutputs like this P-ROC will reset the polarity:
// Enable now without the outputs enabled:
if (resetFlags & kPRResetFlagUpdateDevice)
res = DriverUpdateGlobalConfig(&globals);
else
driverGlobalConfig = globals;
// Now enable the outputs to protect against the polarity being driven incorrectly:
globals.enableOutputs = true;
if (resetFlags & kPRResetFlagUpdateDevice)
@@ -559,7 +555,7 @@ PRResult PRDevice::DriverLoadMachineTypeDefaults(PRMachineType machineType, uint
// If WPCAlphanumeric, select Aux functionality for the dual-purpose Aux/DMD
// pins.
managerConfig.reuse_dmd_data_for_aux = (machineType == kPRMachineWPCAlphanumeric);
managerConfig.invert_dipswitch_1 = false;
ManagerUpdateConfig(&managerConfig);
@@ -598,12 +594,11 @@ PRResult PRDevice::DriverWatchdogTickle()
{
const int burstWords = 2;
uint32_t burst[burstWords];
int32_t rc;
rc = CreateWatchdogConfigBurst(burst, driverGlobalConfig.watchdogExpired,
driverGlobalConfig.watchdogEnable,
driverGlobalConfig.watchdogResetTime);
CreateWatchdogConfigBurst(burst, driverGlobalConfig.watchdogExpired,
driverGlobalConfig.watchdogEnable,
driverGlobalConfig.watchdogResetTime);
return PrepareWriteData(burst, burstWords);
}
@@ -635,8 +630,8 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
// Updates a single rule with the associated linked driver state changes.
const int burstSize = 4;
uint32_t burst[burstSize];
// If more the base rule will link to others, ensure free indexes exists for
// If more the base rule will link to others, ensure free indexes exists for
// the links.
if (numDrivers > 0 && freeSwitchRuleIndexes.size() < (uint32_t)(numDrivers-1)) // -1 because the first switch rule holds the first driver.
{
@@ -646,46 +641,46 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
PRResult res = kPRSuccess;
uint32_t newRuleIndex = CreateSwitchRuleIndex(switchNum, eventType);
// Because we're redefining the rule chain, we need to remove all previously existing links and return the indexes to the free list.
PRSwitchRuleInternal *oldRule = GetSwitchRuleByIndex(newRuleIndex);
uint16_t oldLinkIndex;
while (oldRule->linkActive)
{
// Save old link index so it can freed after the linked rule is retrieved.
oldLinkIndex = oldRule->linkIndex;
oldLinkIndex = oldRule->linkIndex;
oldRule = GetSwitchRuleByIndex(oldRule->linkIndex);
freeSwitchRuleIndexes.push(oldLinkIndex);
if (freeSwitchRuleIndexes.size() > 128) // Detect a corrupted link-related values before it eats up all of the memory.
{
PRSetLastErrorText("Too many free switch rule indicies!");
return kPRFailure;
}
}
// Create a pointer for new rules.
PRSwitchRuleInternal *newRule;
// Process each driver who's state should change in response to the switch event.
if (numDrivers > 0)
if (numDrivers > 0)
{
uint32_t ruleIndex, savedRuleIndex;
// Need to program the main rule last just in case drive_outputs_now is true.
// Otherwise, the hardware could try to access the linked rules before they're
// programmed. So, program the rules in reverse order.
// Move to last driver
linkedDrivers += (numDrivers - 1);
linkedDrivers += (numDrivers - 1);
int totalNumDrivers = numDrivers;
while (numDrivers > 0)
{
if (numDrivers > 1)
{
ruleIndex = freeSwitchRuleIndexes.front();
ruleIndex = freeSwitchRuleIndexes.front();
freeSwitchRuleIndexes.pop();
newRule = GetSwitchRuleByIndex(ruleIndex);
newRule->driver = linkedDrivers[0];
@@ -741,7 +736,7 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
DEBUG(PRLog(kPRLogError, "Failed to disable.\n"));
return res;
}
linkedDrivers--;
numDrivers--;
}
@@ -762,20 +757,19 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
// Write the rule:
res = PrepareWriteData(burst, burstSize);
}
return res;
}
PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwitches )
{
uint32_t rc;
uint32_t stateWord, debounceWord;
uint8_t i, j;
PREventType eventType;
// Request one state word and one debounce word at a time. Could make more efficient
// use of the USB bus by requesting a burst of state words and then a burst of debounce
// words, but doing one word at a time makes it easier to process each switch when the
// words, but doing one word at a time makes it easier to process each switch when the
// data returns. Also, this function shouldn't be called during timing sensitive
// situations; so the inefficiencies are acceptable.
for (i = 0; i < numSwitches / 32; i++)
@@ -783,44 +777,46 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
if (chip_id == P_ROC_CHIP_ID)
{
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
if (combinedVersionRevision < P_ROC_VER_REV_FIXED_SWITCH_STATE_READS) {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_OLD_DEBOUNCE_BASE_ADDR + i, 1);
RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_OLD_DEBOUNCE_BASE_ADDR + i, 1);
}
else {
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1);
RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
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,
P3_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P3_ROC_SWITCH_CTRL_STATE_BASE_ADDR + i, 1);
rc = RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P3_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1);
RequestData(P_ROC_BUS_SWITCH_CTRL_SELECT,
P3_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR + i, 1);
}
}
// Expect 4 words for each 32 switches. The state and debounce words,
// Expect 4 words for each 32 switches. The state and debounce words,
// and the address words for both.
uint16_t numWords = 4 * (numSwitches / 32);
uint16_t numWords = 4 * (numSwitches / 32);
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.
while (requestedDataQueue.size() < numWords && i++ < 10)
while (requestedDataQueue.size() < numWords && i++ < 10)
{
PRSleep (10); // 10 milliseconds should be plenty of time.
if (SortReturningData() != kPRSuccess)
{
return kPRFailure;
}
}
// Make sure all of the requested words are available before processing them.
// Too many words is just as bad as not enough words.
// Too many words is just as bad as not enough words.
// If too many come back, can they be trusted?
if (requestedDataQueue.size() == numWords)
{
@@ -829,10 +825,10 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
{
requestedDataQueue.pop(); // Ignore address word. TODO: Verify this address word.
stateWord = requestedDataQueue.front(); // This is the switch state word.
requestedDataQueue.pop();
requestedDataQueue.pop();
requestedDataQueue.pop(); // Ignore address word. TODO: Verify this address word.
debounceWord = requestedDataQueue.front(); // This is the debounce word.
requestedDataQueue.pop();
requestedDataQueue.pop();
// Loop through each bit of the words, combining them into an eventType
for (j = 0; j < 32; j++)
@@ -851,7 +847,11 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit
}
return kPRSuccess;
}
else return kPRFailure;
else
{
PRSetLastErrorText("Switch response length does not match.");
return kPRFailure;
}
}
int32_t PRDevice::DMDUpdateConfig(PRDMDConfig *dmdConfig)
@@ -993,8 +993,8 @@ PRResult PRDevice::Open()
// 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.
// be ignored.
PRDMDConfig dmdConfig;
dmdConfig.numRows = 32; // Doesn't matter.
dmdConfig.numColumns = 128; // Doesn't matter
@@ -1016,7 +1016,7 @@ PRResult PRDevice::Open()
switchConfig.pulseHalfPeriodTime = 13; // milliseconds
SwitchUpdateConfig(&switchConfig);
// Flush read data to ensure VerifyChipID starts with clean buffer.
// Flush read data to ensure VerifyChipID starts with clean buffer.
// It's possible the P-ROC has a lot of data stored up in internal buffers. So if
// the verify still fails, do a bunch of flushes.
res = FlushReadBuffer();
@@ -1074,7 +1074,7 @@ PRResult PRDevice::VerifyChipID()
max_count = 0;
// Wait for data to return. Give it 10 loops before giving up.
while (requestedDataQueue.size() < 5 && max_count++ < max_count_limit)
while (requestedDataQueue.size() < 5 && max_count++ < max_count_limit)
{
PRSleep (10); // 10 milliseconds should be plenty of time.
if (SortReturningData() != kPRSuccess)
@@ -1088,11 +1088,12 @@ PRResult PRDevice::VerifyChipID()
buffer[i] = requestedDataQueue.front();
requestedDataQueue.pop(); // Ignore address word. TODO: Verify the address.
}
if (buffer[1] != P_ROC_CHIP_ID && buffer[1] != P3_ROC_CHIP_ID)
if (buffer[1] != P_ROC_CHIP_ID && buffer[1] != P3_ROC_CHIP_ID)
{
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]));
PRSetLastErrorText("Chip ID does not match.");
rc = kPRFailure;
}
else rc = kPRSuccess;
@@ -1110,14 +1111,16 @@ PRResult PRDevice::VerifyChipID()
else readMachineType = kPRMachineWPC; // Choose WPC or WPC95, doesn't matter.
}
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;
}
}
else
else
{
// Return failure without logging; calling function must log.
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;
}
return (rc);
@@ -1132,7 +1135,7 @@ PRResult PRDevice::RequestData(uint32_t module_select, uint32_t start_addr, int3
PRResult PRDevice::PrepareWriteData(uint32_t * words, int32_t numWords)
{
if (numWords > maxWriteWords)
{
{
PRSetLastErrorText("%d words Exceeds write capabilities. Restrict write requests to %d words.", numWords, maxWriteWords);
return kPRFailure;
}
@@ -1179,10 +1182,6 @@ PRResult PRDevice::WriteData(uint32_t * words, int32_t numWords)
wr_buffer[(j*4)+k] = (uint8_t)(temp_word & 0x000000ff);
temp_word = temp_word >> 8;
}
// for (k=0; k<4; k++)
// {
// item = wr_buffer[(j*4)+k];
// }
}
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 res;
@@ -1214,17 +1226,16 @@ 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)
{
uint32_t rc;
uint32_t i;
int32_t i;
// 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
// Wait for data to return. Give it 10 loops before giving up.
// Expect numReadWords + 1 word with the address.
while (requestedDataQueue.size() < (uint32_t)((numReadWords + 1)) && i++ < 10)
while (requestedDataQueue.size() < (uint32_t)((numReadWords + 1)) && i++ < 10)
{
PRSleep (10); // 10 milliseconds should be plenty of time.
if (SortReturningData() != kPRSuccess)
@@ -1232,19 +1243,23 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int
}
// Make sure all of the requested words are available before processing them.
// Too many words is just as bad as not enough words.
// Too many words is just as bad as not enough words.
// If too many come back, can they be trusted?
if (requestedDataQueue.size() == (uint32_t)(numReadWords + 1))
{
requestedDataQueue.pop(); // Ignore address word. TODO: Verify the address.
for (i = 0; i < numReadWords; i++)
{
readBuffer[i] = requestedDataQueue.front();
requestedDataQueue.pop();
readBuffer[i] = requestedDataQueue.front();
requestedDataQueue.pop();
}
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;
}
else {
PRSetLastErrorText("Read length did not match.");
rc = 0;
}
DEBUG(PRLog(kPRLogVerbose, "Read num bytes: %d\n", rc));
@@ -1281,12 +1297,11 @@ int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words)
PRResult PRDevice::FlushReadBuffer()
{
int32_t numBytes,rc=0,k;
int32_t numBytes,rc=0;
//uint32_t rd_buffer[3];
numBytes = CollectReadData();
k = 0;
DEBUG(PRLog(kPRLogError, "Flushing Read Buffer: %d bytes trashed\n", numBytes));
//while (k < numBytes) {
// rc = ReadData(rd_buffer, 1);
// k++;
@@ -1320,7 +1335,7 @@ int32_t PRDevice::CollectReadData()
PRResult PRDevice::SortReturningData()
{
int32_t num_bytes, num_words, rc;
int32_t num_bytes, num_words;
uint32_t rd_buffer[FTDI_BUFFER_SIZE/4];
num_bytes = CollectReadData();
@@ -1332,7 +1347,7 @@ PRResult PRDevice::SortReturningData()
num_words = num_collected_bytes/4;
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]));
switch ( (rd_buffer[0] & P_ROC_COMMAND_MASK) >> P_ROC_COMMAND_SHIFT)

View File

@@ -60,6 +60,7 @@ public:
PRResult FlushWriteData();
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 ManagerUpdateConfig(PRManagerConfig *managerConfig);
@@ -108,7 +109,7 @@ protected:
// Raw write and read methods
//
/** Schedules data to be written to the P-ROC. */
PRResult PrepareWriteData(uint32_t * buffer, int32_t numWords);
@@ -174,7 +175,7 @@ protected:
PRDriverGroupConfig driverGroups[maxDriverGroups];
PRDriverState drivers[maxDrivers];
PRDMDConfig dmdConfig;
PRSwitchConfig switchConfig;
PRSwitchRuleInternal switchRules[maxSwitchRules];
queue<uint32_t> freeSwitchRuleIndexes; /**< Indexes of available switch rules. */

View File

@@ -33,9 +33,9 @@
#include "PRCommon.h"
bool_t IsStern (uint32_t hardware_data) {
// if ( ((hardware_data & P_ROC_BOARD_VERSION_MASK) >> P_ROC_BOARD_VERSION_SHIFT) == 0x1)
// if ( ((hardware_data & P_ROC_BOARD_VERSION_MASK) >> P_ROC_BOARD_VERSION_SHIFT) == 0x1)
// return ( ((hardware_data & P_ROC_AUTO_STERN_DETECT_MASK) >> P_ROC_AUTO_STERN_DETECT_SHIFT) == P_ROC_AUTO_STERN_DETECT_VALUE);
// else
// else
return ( ((hardware_data & P_ROC_MANUAL_STERN_DETECT_MASK) >> P_ROC_MANUAL_STERN_DETECT_SHIFT) == P_ROC_MANUAL_STERN_DETECT_VALUE);
}
@@ -59,11 +59,11 @@ int32_t CreateManagerUpdateConfigBurst ( uint32_t * burst, PRManagerConfig *mana
addr = P_ROC_REG_DIPSWITCH_ADDR;
burst[0] = CreateBurstCommand (P_ROC_MANAGER_SELECT, addr, 1 );
burst[1] = ( (manager_config->reuse_dmd_data_for_aux <<
burst[1] = ( (manager_config->reuse_dmd_data_for_aux <<
P_ROC_MANAGER_REUSE_DMD_DATA_FOR_AUX_SHIFT) |
(manager_config->invert_dipswitch_1 <<
(manager_config->invert_dipswitch_1 <<
P_ROC_MANAGER_INVERT_DIPSWITCH_1_SHIFT) );
return kPRSuccess;
}
@@ -181,7 +181,7 @@ uint32_t CreateDriverAuxCommand ( PRDriverAuxCommand command) {
}
break;
default : {
return (false << P_ROC_DRIVER_AUX_ENTRY_ACTIVE_SHIFT);
return (false << P_ROC_DRIVER_AUX_ENTRY_ACTIVE_SHIFT);
}
}
}
@@ -189,13 +189,13 @@ uint32_t CreateDriverAuxCommand ( PRDriverAuxCommand command) {
int32_t CreateWatchdogConfigBurst ( uint32_t * burst, bool_t watchdogExpired,
bool_t watchdogEnable, uint16_t watchdogResetTime) {
uint32_t addr;
addr = P_ROC_REG_WATCHDOG_ADDR;
burst[0] = CreateBurstCommand (P_ROC_MANAGER_SELECT, addr, 1 );
burst[1] = ( (watchdogExpired << P_ROC_MANAGER_WATCHDOG_EXPIRED_SHIFT) |
(watchdogEnable << P_ROC_MANAGER_WATCHDOG_ENABLE_SHIFT) |
(watchdogResetTime << P_ROC_MANAGER_WATCHDOG_RESET_TIME_SHIFT) );
return kPRSuccess;
}
@@ -206,39 +206,39 @@ int32_t CreateSwitchUpdateConfigBurst ( uint32_t * burst, PRSwitchConfig *switch
addr = 0;
burst[0] = CreateBurstCommand (P_ROC_BUS_SWITCH_CTRL_SELECT, addr, 1 );
burst[1] = (switchConfig->clear << P_ROC_SWITCH_CONFIG_CLEAR_SHIFT) |
(switchConfig->directMatrixScanLoopTime <<
(switchConfig->directMatrixScanLoopTime <<
P_ROC_SWITCH_CONFIG_MS_PER_DM_SCAN_LOOP_SHIFT) |
(switchConfig->pulsesBeforeCheckingRX <<
(switchConfig->pulsesBeforeCheckingRX <<
P_ROC_SWITCH_CONFIG_PULSES_BEFORE_CHECKING_RX_SHIFT) |
(switchConfig->inactivePulsesAfterBurst <<
(switchConfig->inactivePulsesAfterBurst <<
P_ROC_SWITCH_CONFIG_INACTIVE_PULSES_AFTER_BURST_SHIFT) |
(switchConfig->pulsesPerBurst <<
(switchConfig->pulsesPerBurst <<
P_ROC_SWITCH_CONFIG_PULSES_PER_BURST_SHIFT) |
(switchConfig->pulseHalfPeriodTime <<
(switchConfig->pulseHalfPeriodTime <<
P_ROC_SWITCH_CONFIG_MS_PER_PULSE_HALF_PERIOD_SHIFT) |
(switchConfig->use_column_8 <<
(switchConfig->use_column_8 <<
P_ROC_SWITCH_CONFIG_USE_COLUMN_8) |
(switchConfig->use_column_9 <<
(switchConfig->use_column_9 <<
P_ROC_SWITCH_CONFIG_USE_COLUMN_9);
burst[2] = CreateBurstCommand (P_ROC_BUS_STATE_CHANGE_PROC_SELECT,
burst[2] = CreateBurstCommand (P_ROC_BUS_STATE_CHANGE_PROC_SELECT,
P_ROC_STATE_CHANGE_CONFIG_ADDR, 1 );
burst[3] = switchConfig->hostEventsEnable;
return kPRSuccess;
}
int16_t CreateSwitchRuleIndex(uint8_t switchNum, PREventType eventType)
int16_t CreateSwitchRuleIndex(uint8_t switchNum, PREventType eventType)
{
uint32_t debounce = (eventType == kPREventTypeSwitchOpenDebounced) || (eventType == kPREventTypeSwitchClosedDebounced) ? 1 : 0;
uint32_t state = (eventType == kPREventTypeSwitchOpenDebounced) || (eventType == kPREventTypeSwitchOpenNondebounced) ? 1 : 0;
uint32_t index = ((debounce << P_ROC_SWITCH_RULE_NUM_DEBOUNCE_SHIFT) |
(state << P_ROC_SWITCH_RULE_NUM_STATE_SHIFT) |
(switchNum << P_ROC_SWITCH_RULE_NUM_SWITCH_NUM_SHIFT) );
return index;
}
int32_t CreateSwitchRuleAddr(uint8_t switchNum, PREventType eventType, bool_t drive_outputs_now)
int32_t CreateSwitchRuleAddr(uint8_t switchNum, PREventType eventType, bool_t drive_outputs_now)
{
uint16_t number = CreateSwitchRuleIndex( switchNum, eventType );
uint32_t addr = (number << P_ROC_SWITCH_RULE_NUM_TO_ADDR_SHIFT) |
@@ -291,7 +291,7 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config)
(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);
(dmd_config->numColumns << P_ROC_DMD_NUM_COLUMNS_SHIFT);
addr = 8;
burst[2] = CreateBurstCommand (P_ROC_BUS_DMD_SELECT, addr, 4 );
@@ -311,12 +311,12 @@ int32_t CreateJTAGForceOutputsBurst ( uint32_t * burst, PRJTAGOutputs *jtagOutpu
burst[1] = 1 << P_ROC_JTAG_CMD_START_SHIFT |
1 << P_ROC_JTAG_CMD_OE_SHIFT |
P_ROC_JTAG_CMD_SET_PORTS << P_ROC_JTAG_CMD_CMD_SHIFT |
jtagOutputs->tckMask << P_ROC_JTAG_TRANSITION_TCK_MASK_SHIFT |
jtagOutputs->tdoMask << P_ROC_JTAG_TRANSITION_TDO_MASK_SHIFT |
jtagOutputs->tmsMask << P_ROC_JTAG_TRANSITION_TMS_MASK_SHIFT |
jtagOutputs->tck << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tdo << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tms << P_ROC_JTAG_TRANSITION_TCK_SHIFT;
jtagOutputs->tckMask << P_ROC_JTAG_TRANSITION_TCK_MASK_SHIFT |
jtagOutputs->tdoMask << P_ROC_JTAG_TRANSITION_TDO_MASK_SHIFT |
jtagOutputs->tmsMask << P_ROC_JTAG_TRANSITION_TMS_MASK_SHIFT |
jtagOutputs->tck << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tdo << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tms << P_ROC_JTAG_TRANSITION_TCK_SHIFT;
return kPRSuccess;
}
@@ -326,10 +326,10 @@ int32_t CreateJTAGLatchOutputsBurst ( uint32_t * burst, PRJTAGOutputs *jtagOutpu
burst[1] = 1 << P_ROC_JTAG_CMD_START_SHIFT |
1 << P_ROC_JTAG_CMD_OE_SHIFT |
P_ROC_JTAG_CMD_TRANSITION << P_ROC_JTAG_CMD_CMD_SHIFT |
jtagOutputs->tdoMask << P_ROC_JTAG_TRANSITION_TDO_MASK_SHIFT |
jtagOutputs->tmsMask << P_ROC_JTAG_TRANSITION_TMS_MASK_SHIFT |
jtagOutputs->tdo << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tms << P_ROC_JTAG_TRANSITION_TMS_SHIFT;
jtagOutputs->tdoMask << P_ROC_JTAG_TRANSITION_TDO_MASK_SHIFT |
jtagOutputs->tmsMask << P_ROC_JTAG_TRANSITION_TMS_MASK_SHIFT |
jtagOutputs->tdo << P_ROC_JTAG_TRANSITION_TCK_SHIFT |
jtagOutputs->tms << P_ROC_JTAG_TRANSITION_TMS_SHIFT;
return kPRSuccess;
}
@@ -340,7 +340,7 @@ int32_t CreateJTAGShiftTDODataBurst ( uint32_t * burst, uint16_t numBits, bool_t
1 << P_ROC_JTAG_CMD_OE_SHIFT |
P_ROC_JTAG_CMD_SHIFT << P_ROC_JTAG_CMD_CMD_SHIFT |
dataBlockComplete << P_ROC_JTAG_SHIFT_EXIT_SHIFT |
numBits << P_ROC_JTAG_SHIFT_NUM_BITS_SHIFT;
numBits << P_ROC_JTAG_SHIFT_NUM_BITS_SHIFT;
return kPRSuccess;
}
@@ -385,18 +385,19 @@ PRResult PRHardwareOpen()
ftHandles[i] = NULL;
}
pcBufLD[MAX_DEVICES] = NULL;
ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER);
if(ftStatus != FT_OK) {
PRSetLastErrorText("FT_ListDevices(%d)\n", ftStatus);
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]));
}
@@ -404,34 +405,39 @@ PRResult PRHardwareOpen()
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));
PRSetLastErrorText("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)
if (iDevicesOpen > 0)
{
FT_ResetDevice(ftHandle);
DEBUG(PRLog(kPRLogInfo,"FTDI Device Opened\n"));
return kPRSuccess;
}
else return kPRFailure;
else
{
PRSetLastErrorText("No FTDI device found.");
return kPRFailure;
}
}
void PRHardwareClose()
{
int i;
@@ -447,14 +453,14 @@ void PRHardwareClose()
int PRHardwareRead(uint8_t *buffer, int maxBytes)
{
FT_STATUS ftStatus;
FT_STATUS ftStatus;
DWORD bytesToRead;
DWORD bytesRead;
int i;
ftStatus = FT_GetQueueStatus(ftHandle,&bytesToRead);
if (ftStatus != FT_OK) return 0;
if ((DWORD)maxBytes < bytesToRead) bytesToRead = maxBytes;
ftStatus = FT_Read(ftHandle, buffer, bytesToRead, &bytesRead);
if (ftStatus == FT_OK) {
@@ -469,13 +475,13 @@ int PRHardwareRead(uint8_t *buffer, int maxBytes)
int PRHardwareWrite(uint8_t *buffer, int bytes)
{
FT_STATUS ftStatus=0;
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)
if (ftStatus == FT_OK)
{
DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes:\n",bytesWritten));
if (bytesWritten != DWORD(bytes)) DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes, should have written %d bytes",bytesWritten,bytes));
@@ -503,23 +509,23 @@ PRResult PRHardwareOpen()
PRResult rc;
struct ftdi_device_list *devlist, *curdev;
char manufacturer[128], description[128];
ftdiInitialized = false;
// Open the FTDI device
if (ftdi_init(&ftdic) != 0)
{
PRSetLastErrorText("Failed to initialize FTDI.");
return kPRFailure;
}
// Find all FTDI devices
// This is very basic and really only expects to see 1 device. It needs to be
// smarter. At the very least, it should check some register on the P-ROC versus
// an input parameter to ensure the software is set up for the same architecture as
// the P-ROC (Stern vs WPC). Otherwise, it's possible to drive the coils the wrong
// polarity and blow fuses or fry transistors and all other sorts of badness.
// We first enumerate all of the devices:
int numDevices = ftdi_usb_find_all(&ftdic, &devlist, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID);
if (numDevices <=0) numDevices = ftdi_usb_find_all(&ftdic, &devlist, FTDI_VENDOR_ID, FTDI_FT240X_PRODUCT_ID);
@@ -530,7 +536,7 @@ PRResult PRHardwareOpen()
}
else {
DEBUG(PRLog(kPRLogInfo, "Number of FTDI devices found: %d\n", numDevices));
for (curdev = devlist; curdev != NULL; i++) {
DEBUG(PRLog(kPRLogInfo, "Checking device %d\n", i));
if ((rc = (int32_t)ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) {
@@ -543,12 +549,12 @@ PRResult PRHardwareOpen()
}
curdev = curdev->next;
}
}
// Don't need the device list anymore
ftdi_list_free (&devlist);
if (((rc = (int32_t)ftdi_usb_open(&ftdic, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID)) < 0) && ((rc = (int32_t)ftdi_usb_open(&ftdic, FTDI_VENDOR_ID, FTDI_FT240X_PRODUCT_ID)) < 0))
{
PRSetLastErrorText("Unable to open ftdi device: %d: %s", rc, ftdi_get_error_string(&ftdic));

View File

@@ -51,7 +51,7 @@ void PRLog(PRLogLevel level, const char *format, ...)
{
if (level < logLevel)
return;
char line[MAX_TEXT];
va_list ap;
va_start(ap, format);
@@ -119,12 +119,18 @@ PRResult PRFlushWriteData(PRHandle handle)
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)
{
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. */
PRResult PRReadData(PRHandle handle, uint32_t moduleSelect, uint32_t startingAddr, int32_t numReadWords, uint32_t * readBuffer)
{
@@ -358,8 +364,8 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
else if ( strlen(str) == 4)
x = (str[2]-'0') * 10 + (str[3]-'0');
else return atoi(str);
if ((machineType == kPRMachineWPC) ||
if ((machineType == kPRMachineWPC) ||
(machineType == kPRMachineWPC95) ||
(machineType == kPRMachineWPCAlphanumeric))
{
@@ -381,7 +387,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
case 'm':
return 32;
default:
return 33;
return 33;
}
default:
switch (str[3])
@@ -390,7 +396,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
case 'm':
return 34;
default:
return 35;
return 35;
}
}
default:
@@ -404,7 +410,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
case 'm':
return 36;
default:
return 37;
return 37;
}
default:
switch (str[3])
@@ -413,7 +419,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
case 'm':
return 38;
default:
return 39;
return 39;
}
}
}
@@ -432,7 +438,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
if (machineType == kPRMachineWPC95)
//return x + 7;
return x + 31;
else
else
return x + 107; // WPC 37-44 use 8-driver board (mapped to drivers 144-151)
}
else return x + 108;
@@ -473,7 +479,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
{
case 'D':
case 'd':
if (strlen(str) == 3)
if (strlen(str) == 3)
return (str[2]-'0') + 7;
else return x + 7;
default:
@@ -502,7 +508,7 @@ uint16_t PRDecode(PRMachineType machineType, const char *str)
{
case 'D':
case 'd':
if (strlen(str) == 3)
if (strlen(str) == 3)
return (str[2]-'0') + 7;
else return x + 7;
default:

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" );
return 1;
}
void writeP3ROCImage()
@@ -2134,13 +2136,10 @@ int processFile()
endClock = clock();
fclose( in );
// Destroy the P-ROC device handle:
PRDelete(proc);
proc = kPRHandleInvalid;
return iErrorCode;
}
int checkPROCFile() {
uint32_t checkPROCFile() {
uint32_t checksum=0, file_checksum, file_board_id, header_checksum;
unsigned char data;
int i=0,file_i=0;
@@ -2176,10 +2175,20 @@ int checkPROCFile() {
PRReadData(proc, 0, 0, 4, readdata);
board_id = readdata[0];
board_rev = readdata[3];
board_rev = (board_rev & 0x80) >> 7 |
(board_rev & 0x40) >> 5 |
(board_rev & 0x20) >> 3 |
(board_rev & 0x10) >> 1;
if (board_id == P3_ROC_CHIP_ID) {
board_rev = (board_rev & 0x800) >> 11 |
(board_rev & 0x400) >> 10 |
(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) {
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;
}
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) {
fprintf(stderr, "\nERROR: This image is not compatible with the P-ROC board (rev: %x)", board_id);
return 0;
@@ -2303,8 +2320,12 @@ int main( int argc, char** argv )
processP3ROCFile();
break;
default:
fprintf(stderr, "Failed to parse file.\n");
break;
}
}
// Destroy the P-ROC device handle created by openPROC()
PRDelete(proc);
proc = kPRHandleInvalid;
}
}
}