From 0f4976c5e54dc04fc31f683eb8dceb044d6c4875 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Mon, 25 May 2009 22:27:50 -0500 Subject: [PATCH] Implemented PRSwitchUpdateConfig --- examples/pinproctest/pinproctest.cpp | 20 +++++++++++++++----- include/pinproc.h | 28 ++++++++++++++++++++-------- src/PRDevice.cpp | 26 +++++++++++++++++++++----- src/PRDevice.h | 4 +++- src/PRHardware.cpp | 24 +++++++++++++++++++++++- src/PRHardware.h | 24 ++++++++++++++++-------- src/pinproc.cpp | 9 +++++++-- 7 files changed, 105 insertions(+), 30 deletions(-) diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 5249554..e70fbc9 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -135,13 +135,23 @@ void ConfigureSwitches(PRHandle proc) { int i; + // Configure switch controller registers (if the defaults aren't acceptable) + PRSwitchConfig switchConfig; + switchConfig.clear = false; + switchConfig.directMatrixScanLoopTime = 2; // milliseconds + switchConfig.pulsesBeforeCheckingRX = 10; + switchConfig.inactivePulsesAfterBurst = 12; + switchConfig.pulsesPerBurst = 6; + switchConfig.pulseHalfPeriodTime = 13; // milliseconds + PRSwitchUpdateConfig(proc, &switchConfig); + // Configures rules to notify the host for every debounced switch event. for (i = 0; i <= kPRSwitchPhysicalLast; i++) { PRSwitchRule sw; sw.notifyHost = true; - PRSwitchesUpdateRule(proc, i, kPREventTypeSwitchClosedDebounced, &sw, NULL, 0); - PRSwitchesUpdateRule(proc, i, kPREventTypeSwitchOpenDebounced, &sw, NULL, 0); + PRSwitchUpdateRule(proc, i, kPREventTypeSwitchClosedDebounced, &sw, NULL, 0); + PRSwitchUpdateRule(proc, i, kPREventTypeSwitchOpenDebounced, &sw, NULL, 0); } } @@ -157,7 +167,7 @@ void ConfigureWPCFlipperSwitchRule (PRHandle proc, int swNum, int mainCoilNum, i PRDriverGetState(proc, holdCoilNum, &drivers[1]); PRDriverStatePulse(&drivers[1],0); // Turn on indefintely (set pulse for 0ms) sw.notifyHost = false; - PRSwitchesUpdateRule(proc,swNum, kPREventTypeSwitchClosedNondebounced, &sw, drivers, numDriverRules); + PRSwitchUpdateRule(proc,swNum, kPREventTypeSwitchClosedNondebounced, &sw, drivers, numDriverRules); // Flipper off rules PRDriverGetState(proc, mainCoilNum, &drivers[0]); @@ -165,7 +175,7 @@ void ConfigureWPCFlipperSwitchRule (PRHandle proc, int swNum, int mainCoilNum, i PRDriverGetState(proc, holdCoilNum, &drivers[1]); PRDriverStateDisable(&drivers[1]); // Disable hold coil sw.notifyHost = false; - PRSwitchesUpdateRule(proc,swNum, kPREventTypeSwitchOpenNondebounced, &sw, drivers, numDriverRules); + PRSwitchUpdateRule(proc,swNum, kPREventTypeSwitchOpenNondebounced, &sw, drivers, numDriverRules); } void ConfigureBumperRule (PRHandle proc, int swNum, int coilNum, int pulseTime) @@ -178,7 +188,7 @@ void ConfigureBumperRule (PRHandle proc, int swNum, int coilNum, int pulseTime) PRDriverGetState(proc, coilNum, &drivers[0]); PRDriverStatePulse(&drivers[0],pulseTime); // Pulse coil for 34ms. sw.notifyHost = false; - PRSwitchesUpdateRule(proc,swNum, kPREventTypeSwitchClosedNondebounced, &sw, drivers, numDriverRules); + PRSwitchUpdateRule(proc,swNum, kPREventTypeSwitchClosedNondebounced, &sw, drivers, numDriverRules); } void ConfigureSwitchRules(PRHandle proc) diff --git a/include/pinproc.h b/include/pinproc.h index c0aacac..71a56a2 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -178,25 +178,25 @@ PR_EXPORT PRResult PRDriverWatchdogTickle(PRHandle handle); /** * Changes the given #PRDriverState to reflect a disabled state. - * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect. + * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. */ PR_EXPORT void PRDriverStateDisable(PRDriverState *driverState); /** * Changes the given #PRDriverState to reflect a pulse state. * @param milliseconds Number of milliseconds to pulse the driver for. - * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect. + * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. */ PR_EXPORT void PRDriverStatePulse(PRDriverState *driverState, int milliseconds); /** * Changes the given #PRDriverState to reflect a scheduled state. * Assigns a repeating schedule to the given driver. - * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect. + * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. */ PR_EXPORT void PRDriverStateSchedule(PRDriverState *driverState, uint32_t schedule, uint8_t cycleSeconds, bool_t now); /** * @brief Changes the given #PRDriverState to reflect a pitter-patter schedule state. * Assigns a pitter-patter schedule (repeating on/off) to the given driver. - * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect. + * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. * * Use originalOnTime to pulse the driver for a number of milliseconds before the pitter-patter schedule begins. */ @@ -236,10 +236,22 @@ PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents); #define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */ #define kPRSwitchVirtualLast (255) /**< Switch number of the last virtual switch. */ +typedef struct PRSwitchConfig { + bool_t clear; // Drive the clear output + uint8_t directMatrixScanLoopTime; // milliseconds + uint8_t pulsesBeforeCheckingRX; + uint8_t inactivePulsesAfterBurst; + uint8_t pulsesPerBurst; + uint8_t pulseHalfPeriodTime; // milliseconds +} PRSwitchConfig; + typedef struct PRSwitchRule { bool_t notifyHost; /**< If true this switch change event will provided to the user via PRGetEvents(). */ } PRSwitchRule; +/** Update the switch controller configurion registers */ +PR_EXPORT PRResult PRSwitchUpdateConfig(PRHandle handle, PRSwitchConfig *switchConfig); + /** * @brief Configures the handling of switch rules within P-ROC. * @@ -264,7 +276,7 @@ typedef struct PRSwitchRule { * @code * PRSwitchRule rule; * rule.notifyHost = true; - * PRSwitchesUpdateRule(handle, switchNum, kPREventTypeSwitchOpenDebounced, &rule, NULL, 0); + * PRSwitchUpdateRule(handle, switchNum, kPREventTypeSwitchOpenDebounced, &rule, NULL, 0); * @endcode * * Configuring a pop bumper switch to pulse the coil and a flash lamp for 50ms each: @@ -277,11 +289,11 @@ typedef struct PRSwitchRule { * PRDriverGetState(handle, drvFlashLamp1, &drivers[1]); * PRDriverStatePulse(&drivers[0], 50); * PRDriverStatePulse(&drivers[1], 50); - * PRSwitchesUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedNondebounced, + * PRSwitchUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedNondebounced, * &rule, drivers, 2); * // Now configure a switch rule to process scoring in software: * rule.notifyHost = true; - * PRSwitchesUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedDebounced, + * PRSwitchUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedDebounced, * &rule, NULL, 0); * @endcode * @@ -292,7 +304,7 @@ typedef struct PRSwitchRule { * @param linkedDrivers An array of #PRDriverState structures describing the driver state changes to be made when this switch rule is triggered. May be NULL if numDrivers is 0. * @param numDrivers Number of elements in the linkedDrivers array. May be zero or more. */ -PR_EXPORT PRResult PRSwitchesUpdateRule(PRHandle handle, uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers); +PR_EXPORT PRResult PRSwitchUpdateRule(PRHandle handle, uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers); /** @} */ // End of Switches & Events diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 4ca579f..e09f343 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -211,7 +211,23 @@ PRSwitchRuleInternal *PRDevice::GetSwitchRuleByIndex(uint16_t index) return &switchRules[index]; } -PRResult PRDevice::SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers) +PRResult PRDevice::SwitchUpdateConfig(PRSwitchConfig *switchConfig) +{ + uint32_t rc; + const int burstWords = 2; + uint32_t burst[burstWords]; + + this->switchConfig = *switchConfig; + CreateSwitchUpdateConfigBurst(burst, switchConfig); + + DEBUG(PRLog("Configuring Switch Logic")); + DEBUG(PRLog("Words: %x %x\n",burst[0],burst[1])); + + rc = WriteData(burst, burstWords); + return rc; +} + +PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers) { // Updates a single rule with the associated linked driver state changes. const int burstSize = 4; @@ -265,7 +281,7 @@ PRResult PRDevice::SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, newRule->linkIndex = freeSwitchRuleIndexes.front(); freeSwitchRuleIndexes.pop(); - CreateSwitchesUpdateRulesBurst(burst, newRule); + CreateSwitchUpdateRulesBurst(burst, newRule); // Prepare for the next rule: newRule = GetSwitchRuleByIndex(newRule->linkIndex); @@ -273,7 +289,7 @@ PRResult PRDevice::SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, else { newRule->linkActive = false; - CreateSwitchesUpdateRulesBurst(burst, newRule); + CreateSwitchUpdateRulesBurst(burst, newRule); } DEBUG(PRLog("Rule Words: %x %x %x %x\n", burst[0],burst[1],burst[2],burst[3])); @@ -285,7 +301,7 @@ PRResult PRDevice::SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, newRule = GetSwitchRuleByIndex(firstRuleIndex); newRule->changeOutput = false; newRule->linkActive = false; - CreateSwitchesUpdateRulesBurst(burst, newRule); + CreateSwitchUpdateRulesBurst(burst, newRule); if (WriteData(burst, burstSize) == kPRSuccess) DEBUG(PRLog("Disabled successfully.\n")); else @@ -299,7 +315,7 @@ PRResult PRDevice::SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, } else { - CreateSwitchesUpdateRulesBurst(burst, newRule); + CreateSwitchUpdateRulesBurst(burst, newRule); DEBUG(PRLog("Rule Words: %x %x %x %x\n", burst[0],burst[1],burst[2],burst[3])); // Write the rule: diff --git a/src/PRDevice.h b/src/PRDevice.h index b4117b2..5eb05c5 100644 --- a/src/PRDevice.h +++ b/src/PRDevice.h @@ -64,7 +64,8 @@ public: PRResult DriverGetState(uint8_t driverNum, PRDriverState *driverState); PRResult DriverUpdateState(PRDriverState *driverState); - PRResult SwitchesUpdateRule(uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers); + PRResult SwitchUpdateConfig(PRSwitchConfig *switchConfig); + PRResult SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers); PRResult DriverWatchdogTickle(); @@ -137,6 +138,7 @@ protected: PRDriverState drivers[maxDrivers]; PRDMDConfig dmdConfig; + PRSwitchConfig switchConfig; PRSwitchRuleInternal switchRules[maxSwitchRules]; queue freeSwitchRuleIndexes; /**< Indexes of available switch rules. */ PRSwitchRuleInternal *GetSwitchRuleByIndex(uint16_t index); diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index ca46741..2bcf7d6 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -139,6 +139,28 @@ int32_t CreateWatchdogConfigBurst ( uint32_t * burst, bool_t watchdogExpired, return kPRSuccess; } +int32_t CreateSwitchUpdateConfigBurst ( uint32_t * burst, PRSwitchConfig *switchConfig) +{ + uint32_t addr; + uint32_t i; + + 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 << + P_ROC_SWITCH_CONFIG_MS_PER_DM_SCAN_LOOP_SHIFT) | + (switchConfig->pulsesBeforeCheckingRX << + P_ROC_SWITCH_CONFIG_PULSES_BEFORE_CHECKING_RX_SHIFT) | + (switchConfig->inactivePulsesAfterBurst << + P_ROC_SWITCH_CONFIG_INACTIVE_PULSES_AFTER_BURST_SHIFT) | + (switchConfig->pulsesPerBurst << + P_ROC_SWITCH_CONFIG_PULSES_PER_BURST_SHIFT) | + (switchConfig->pulseHalfPeriodTime << + P_ROC_SWITCH_CONFIG_MS_PER_PULSE_HALF_PERIOD_SHIFT); + + return kPRSuccess; +} + int16_t CreateSwitchRuleIndex(uint8_t switchNum, PREventType eventType) { uint32_t debounce = (eventType == kPREventTypeSwitchOpenDebounced) || (eventType == kPREventTypeSwitchClosedDebounced) ? 1 : 0; @@ -169,7 +191,7 @@ void ParseSwitchRuleIndex(uint16_t index, uint8_t *switchNum, PREventType *event *eventType = debounce ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchClosedNondebounced; } -int32_t CreateSwitchesUpdateRulesBurst ( uint32_t * burst, PRSwitchRuleInternal *rule_record) { +int32_t CreateSwitchUpdateRulesBurst ( uint32_t * burst, PRSwitchRuleInternal *rule_record) { uint32_t addr = CreateSwitchRuleAddr(rule_record->switchNum, rule_record->eventType); uint32_t driver_command[3]; diff --git a/src/PRHardware.h b/src/PRHardware.h index 657b847..5f7709c 100644 --- a/src/PRHardware.h +++ b/src/PRHardware.h @@ -121,14 +121,21 @@ const uint32_t P_ROC_DRIVER_CONFIG_PATTER_ENABLE_SHIFT = 30; const uint32_t P_ROC_DRIVER_CONFIG_TABLE_DRIVER_NUM_SHIFT = 1; -const uint32_t P_ROC_SWITCH_RULE_NUM_DEBOUNCE_SHIFT = 9; -const uint32_t P_ROC_SWITCH_RULE_NUM_STATE_SHIFT = 8; -const uint32_t P_ROC_SWITCH_RULE_NUM_SWITCH_NUM_SHIFT = 0; -const uint32_t P_ROC_SWITCH_RULE_NUM_TO_ADDR_SHIFT = 2; +const uint32_t P_ROC_SWITCH_CONFIG_CLEAR_SHIFT = 31; +const uint32_t P_ROC_SWITCH_CONFIG_MS_PER_DM_SCAN_LOOP_SHIFT = 24; +const uint32_t P_ROC_SWITCH_CONFIG_PULSES_BEFORE_CHECKING_RX_SHIFT = 18; +const uint32_t P_ROC_SWITCH_CONFIG_INACTIVE_PULSES_AFTER_BURST_SHIFT = 12; +const uint32_t P_ROC_SWITCH_CONFIG_PULSES_PER_BURST_SHIFT = 6; +const uint32_t P_ROC_SWITCH_CONFIG_MS_PER_PULSE_HALF_PERIOD_SHIFT = 0; -const uint32_t P_ROC_SWITCH_RULE_NOTIFY_HOST_SHIFT = 23; -const uint32_t P_ROC_SWITCH_RULE_LINK_ACTIVE_SHIFT = 10; -const uint32_t P_ROC_SWITCH_RULE_LINK_ADDRESS_SHIFT = 11; +const uint32_t P_ROC_SWITCH_RULE_NUM_DEBOUNCE_SHIFT = 9; +const uint32_t P_ROC_SWITCH_RULE_NUM_STATE_SHIFT = 8; +const uint32_t P_ROC_SWITCH_RULE_NUM_SWITCH_NUM_SHIFT = 0; +const uint32_t P_ROC_SWITCH_RULE_NUM_TO_ADDR_SHIFT = 2; + +const uint32_t P_ROC_SWITCH_RULE_NOTIFY_HOST_SHIFT = 23; +const uint32_t P_ROC_SWITCH_RULE_LINK_ACTIVE_SHIFT = 10; +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; @@ -160,7 +167,8 @@ uint32_t CreateBurstCommand ( uint32_t select, uint32_t addr, uint32_t num_words int32_t CreateDriverUpdateGlobalConfigBurst ( uint32_t * burst, PRDriverGlobalConfig *driver_globals); int32_t CreateDriverUpdateGroupConfigBurst ( uint32_t * burst, PRDriverGroupConfig *driver_group); int32_t CreateDriverUpdateBurst ( uint32_t * burst, PRDriverState *driver); -int32_t CreateSwitchesUpdateRulesBurst ( uint32_t * burst, PRSwitchRuleInternal *rule_record); +int32_t CreateSwitchUpdateConfigBurst ( uint32_t * burst, PRSwitchConfig *switchConfig); +int32_t CreateSwitchUpdateRulesBurst ( uint32_t * burst, PRSwitchRuleInternal *rule_record); int32_t CreateWatchdogConfigBurst ( uint32_t * burst, bool_t watchdogExpired, bool_t watchdogEnable, uint16_t watchdogResetTime); int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config); diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 9dddd1e..91fc8f5 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -181,9 +181,14 @@ PR_EXPORT void PRDriverStatePatter(PRDriverState *driver, uint16_t millisecondsO // Switches -PR_EXPORT PRResult PRSwitchesUpdateRule(PRHandle handle, uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers) +PR_EXPORT PRResult PRSwitchUpdateConfig(PRHandle handle, PRSwitchConfig *switchConfig) { - return handleAsDevice->SwitchesUpdateRule(switchNum, eventType, rule, linkedDrivers, numDrivers); + return handleAsDevice->SwitchUpdateConfig(switchConfig); +} + +PR_EXPORT PRResult PRSwitchUpdateRule(PRHandle handle, uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers) +{ + return handleAsDevice->SwitchUpdateRule(switchNum, eventType, rule, linkedDrivers, numDrivers); } PR_EXPORT int32_t PRDMDUpdateConfig(PRHandle handle, PRDMDConfig *dmdConfig)