1
0
mirror of https://github.com/preble/libpinproc synced 2026-02-24 18:25:23 +01:00

Implemented PRSwitchUpdateConfig

This commit is contained in:
gstellenberg
2009-05-25 22:27:50 -05:00
parent 179125367b
commit 0f4976c5e5
7 changed files with 105 additions and 30 deletions

View File

@@ -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:

View File

@@ -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<uint32_t> freeSwitchRuleIndexes; /**< Indexes of available switch rules. */
PRSwitchRuleInternal *GetSwitchRuleByIndex(uint16_t index);

View File

@@ -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];

View File

@@ -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);

View File

@@ -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)