From ec47b8fac1b1451cc039915513924bd93da50ac8 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Wed, 20 May 2009 21:01:20 -0500 Subject: [PATCH] Added support for configuring and tickling the watchdog timer. --- examples/pinproctest/pinproctest.cpp | 18 +++++++++++++++--- include/pinproc.h | 10 +++++++--- src/PRDevice.cpp | 22 +++++++++++++++++++--- src/PRDevice.h | 1 + src/PRHardware.cpp | 16 +++++++++++++++- src/PRHardware.h | 6 ++++++ src/pinproc.cpp | 5 ++++- 7 files changed, 67 insertions(+), 11 deletions(-) diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 932d924..96abe3a 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -52,8 +52,11 @@ void ConfigureDrivers(PRHandle proc) globals.matrixRowEnableIndex1 = 12; globals.matrixRowEnableIndex0 = 6; globals.activeLowMatrixRows = true; - globals.tickleWatchdog = false; + globals.tickleSternWatchdog = false; globals.encodeEnables = false; + globals.watchdogExpired = false; + globals.watchdogEnable = true; + globals.watchdogResetTime = 1000; // milliseconds // 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: @@ -125,10 +128,15 @@ bool runLoopRun = true; void RunLoop(PRHandle proc) { + PRDriverGlobalConfig driverGlobals; + const int maxEvents = 16; PREvent events[maxEvents]; while (runLoopRun) { + // Tickle Watchdog by updating DriverGlobalConfig. + PRDriverWatchdogTickle(proc); + int numEvents = PRGetEvents(proc, events, maxEvents); for (int i = 0; i < numEvents; i++) { @@ -169,14 +177,18 @@ int main(const char **argv, int argc) printf("Configuring P-ROC...\n"); - ConfigureDrivers(proc); ConfigureSwitches(proc); + // Make Drivers the last thing to configure so watchdog doesn't expire + // before the RunLoop begins + ConfigureDrivers(proc); printf("Running. Hit Ctrl-C to exit.\n"); // Pulse a coil to test: // PRDriverDisable(proc, 80); -// PRDriverPulse(proc, 53, 100); + PRDriverPulse(proc, 53, 100); + PRDriverSchedule(proc, 80, 0xFF00FF00, 0, 0); + PRDriverPatter(proc, 84, 127, 127, 0); RunLoop(proc); diff --git a/include/pinproc.h b/include/pinproc.h index 7661e64..721590e 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -122,7 +122,10 @@ typedef struct PRDriverGlobalConfig { uint8_t matrixRowEnableIndex0; bool_t activeLowMatrixRows; bool_t encodeEnables; - bool_t tickleWatchdog; + bool_t tickleSternWatchdog; + bool_t watchdogExpired; + bool_t watchdogEnable; + uint16_t watchdogResetTime; } PRDriverGlobalConfig; typedef struct PRDriverGroupConfig { @@ -168,9 +171,10 @@ PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint16_t driverNum); PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint16_t driverNum, int milliseconds); /** Assigns a repeating schedule to the given driver. */ PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint16_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now); - +/** Assigns a pitter-patter schedule (repeating on/off) to the given driver. */ PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime); - +/** Tickle the watchdog timer. */ +PR_EXPORT PRResult PRDriverWatchdogTickle(PRHandle handle); // Switches diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index c458875..d51da33 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -120,10 +120,9 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents) return i; } - PRResult PRDevice::DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig) { - const int burstWords = 2; + const int burstWords = 4; uint32_t burst[burstWords]; int32_t rc; @@ -131,8 +130,12 @@ PRResult PRDevice::DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalCo this->driverGlobalConfig = *driverGlobalConfig; rc = CreateDriverUpdateGlobalConfigBurst(burst, driverGlobalConfig); + rc = CreateWatchdogConfigBurst(burst+2, driverGlobalConfig->watchdogExpired, + driverGlobalConfig->watchdogEnable, + driverGlobalConfig->watchdogResetTime); - DEBUG(PRLog("Words: %x %x\n", burst[0], burst[1])); + DEBUG(PRLog("Driver Global words: %x %x\n", burst[0], burst[1])); + DEBUG(PRLog("Watchdog words: %x %x\n", burst[2], burst[3])); return WriteData(burst, burstWords); } @@ -244,6 +247,19 @@ PRResult PRDevice::DriverPatter(uint16_t driverNum, uint16_t millisecondsOn, uin return DriverUpdateState(&driver); } +PRResult PRDevice::DriverWatchdogTickle() +{ + const int burstWords = 2; + uint32_t burst[burstWords]; + int32_t rc; + + rc = CreateWatchdogConfigBurst(burst, driverGlobalConfig.watchdogExpired, + driverGlobalConfig.watchdogEnable, + driverGlobalConfig.watchdogResetTime); + + return WriteData(burst, burstWords); +} + PRResult PRDevice::SwitchesUpdateRules(PRSwitchRule *rules, int numRules) { diff --git a/src/PRDevice.h b/src/PRDevice.h index af4086a..dd8c4b9 100644 --- a/src/PRDevice.h +++ b/src/PRDevice.h @@ -68,6 +68,7 @@ public: PRResult DriverPulse(uint16_t driverNum, int milliseconds); PRResult DriverSchedule(uint16_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool now); PRResult DriverPatter(uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime); + PRResult DriverWatchdogTickle(); PRResult SwitchesUpdateRules(PRSwitchRule *rules, int numRules); diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 829ff6b..341e3e6 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -72,8 +72,9 @@ int32_t CreateDriverUpdateGlobalConfigBurst ( uint32_t * burst, PRDriverGlobalCo P_ROC_DRIVER_GLOBAL_ACTIVE_LOW_MATRIX_ROWS_SHIFT) | (driver_globals->encodeEnables << P_ROC_DRIVER_GLOBAL_ENCODE_ENABLES_SHIFT) | - (driver_globals->tickleWatchdog << + (driver_globals->tickleSternWatchdog << P_ROC_DRIVER_GLOBAL_TICKLE_WATCHDOG_SHIFT) ); + return kPRSuccess; } @@ -125,6 +126,19 @@ int32_t CreateDriverUpdateBurst ( uint32_t * burst, PRDriverState *driver) { return kPRSuccess; } +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; +} + int32_t CreateSwitchesUpdateRulesBurst ( uint32_t * burst, PRSwitchRule *rule_record) { uint32_t addr; uint32_t driver_command[3]; diff --git a/src/PRHardware.h b/src/PRHardware.h index 875542b..e9de057 100644 --- a/src/PRHardware.h +++ b/src/PRHardware.h @@ -69,6 +69,10 @@ const uint32_t P_ROC_REG_VERSION_ADDR = 1; const uint32_t P_ROC_REG_WATCHDOG_ADDR = 2; const uint32_t P_ROC_REG_DIPSWITCH_ADDR = 3; +const uint32_t P_ROC_MANAGER_WATCHDOG_EXPIRED_SHIFT = 30; +const uint32_t P_ROC_MANAGER_WATCHDOG_ENABLE_SHIFT = 14; +const uint32_t P_ROC_MANAGER_WATCHDOG_RESET_TIME_SHIFT = 0; + const uint32_t P_ROC_EVENT_SWITCH_NUM_MASK = 0xFF; const uint32_t P_ROC_EVENT_SWITCH_STATE_MASK = 0x100; const uint32_t P_ROC_EVENT_SWITCH_STATE_SHIFT = 8; @@ -147,6 +151,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 CreateWatchdogConfigBurst ( uint32_t * burst, bool_t watchdogExpired, + bool_t watchdogEnable, uint16_t watchdogResetTime); int32_t CreateSwitchesUpdateRulesBurst ( uint32_t * burst, PRSwitchRule *rule_record); int32_t CreateDMDUpdateGlobalConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config); diff --git a/src/pinproc.cpp b/src/pinproc.cpp index a89b82d..bddf8e8 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -121,7 +121,10 @@ PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint16_t driverNum, uint16_t { return handleAsDevice->DriverPatter(driverNum, millisecondsOn, millisecondsOff, originalOnTime); } - +PR_EXPORT PRResult PRDriverWatchdogTickle(PRHandle handle) +{ + return handleAsDevice->DriverWatchdogTickle(); +} // Switches