use of net.sourceforge.usbdm.deviceEditor.model.Status in project usbdm-eclipse-plugins by podonoghue.
the class SimValidateMKL_lite method validateIndexVariables.
/**
* Updates
* - sim_sopt2_pllfllsel[x]
* - system_peripheral_clock[x]
* - system_core_clock[x]
* - system_bus_clock[x]
* - system_flexbus_clock[x]
* - system_flash_clock[x]
* - sim_clkdiv1_outdiv1[x]
* - sim_clkdiv1_outdiv2[x]
* - sim_clkdiv1_outdiv3[x]
* - sim_clkdiv1_outdiv4[x]
*
* @param variable
* @throws Exception
*/
void validateIndexVariables(Variable variable) throws Exception {
// ======================================
final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
// Core & System Clock
// ===========================================
// Attempt to find acceptable divisor
final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return frequency <= MAX_CORE_CLOCK_FREQ;
}
};
Severity severity = Severity.OK;
StringBuilder sb = new StringBuilder();
if (variable == system_core_clockVar) {
// Clock variable changed - replace with nearest value if found
if (coreDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setValue(coreDivisor.nearestTargetFrequency);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((coreDivisor.divisor == 0) || (system_core_clockVar.getValueAsLong() != (coreDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
}
// Bus & Flash Clock
// ===========================================
// Attempt to find acceptable divisor
final long coreFrequency = system_core_clockVar.getValueAsLong();
inputFrequency = coreFrequency;
final FindDivisor flashDivisor = new FindDivisor(inputFrequency, system_bus_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
}
};
severity = Severity.OK;
sb = new StringBuilder();
if (variable == system_bus_clockVar) {
// Clock variable changed - replace with nearest value if found
if (flashDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
}
}
use of net.sourceforge.usbdm.deviceEditor.model.Status in project usbdm-eclipse-plugins by podonoghue.
the class SimValidate_fll method validateIndexVariables.
/**
* Updates
* - system_peripheral_clock[x]
* - system_core_clock[x]
* - system_bus_clock[x]
* - system_flexbus_clock[x]
* - system_flash_clock[x]
* - sim_clkdiv1_outdiv1[x]
* - sim_clkdiv1_outdiv2[x]
* - sim_clkdiv1_outdiv3[x]
* - sim_clkdiv1_outdiv4[x]
*
* @param variable
* @throws Exception
*/
void validateIndexVariables(Variable variable) throws Exception {
// ======================================
final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
// Core & System Clock
// ===========================================
// Attempt to find acceptable divisor
final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return frequency <= MAX_CORE_CLOCK_FREQ;
}
};
Severity severity = Severity.OK;
StringBuilder sb = new StringBuilder();
if (variable == system_core_clockVar) {
// Clock variable changed - replace with nearest value if found
if (coreDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setValue(coreDivisor.nearestTargetFrequency);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((coreDivisor.divisor == 0) || (system_core_clockVar.getValueAsLong() != (coreDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
}
// Bus & Flash Clock
// ===========================================
// Attempt to find acceptable divisor
final long coreFrequency = system_core_clockVar.getValueAsLong();
inputFrequency = coreFrequency;
final FindDivisor flashDivisor = new FindDivisor(inputFrequency, system_bus_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
}
};
severity = Severity.OK;
sb = new StringBuilder();
if (variable == system_bus_clockVar) {
// Clock variable changed - replace with nearest value if found
if (flashDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
}
}
use of net.sourceforge.usbdm.deviceEditor.model.Status in project usbdm-eclipse-plugins by podonoghue.
the class OscValidate method validate.
/**
* Class to determine oscillator settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// OSC
// =================================
BooleanVariable osc_cr_erclkenVar = getBooleanVariable("osc_cr_erclken");
BooleanVariable mcg_c2_erefs0Var = getBooleanVariable("/MCG/mcg_c2_erefs0");
BooleanVariable mcg_c2_hgo0Var = getBooleanVariable("/MCG/mcg_c2_hgo0");
ChoiceVariable osc_cr_scpVar = getChoiceVariable("osc_cr_scp");
Variable osc_cr_erefstenVar = getVariable("osc_cr_erefsten");
Variable oscillatorRangeVar = getVariable("oscillatorRange");
LongVariable system_oscer_undiv_clockVar = safeGetLongVariable("oscer_undiv_clock");
LongVariable system_oscer_clockVar = null;
if (system_oscer_undiv_clockVar == null) {
system_oscer_undiv_clockVar = getLongVariable("oscer_clock");
} else {
system_oscer_clockVar = getLongVariable("oscer_clock");
}
ChoiceVariable osc_div_erpsVar = safeGetChoiceVariable("osc_div_erps");
LongVariable osc32k_clockVar = getLongVariable("osc32k_clock");
LongVariable osc_clockVar = getLongVariable("osc_clock");
LongVariable osc_input_freqVar = getLongVariable("osc_input_freq");
// Check if RTC has control of oscillator pins
boolean rtcForcing = getVariable("/SIM/rtcSharesPins").getValueAsBoolean() && getBooleanVariable("/RTC/rtc_cr_osce").getValueAsBoolean();
String rangeOrigin = "Unused";
int range = UNCONSTRAINED_RANGE;
if (rtcForcing) {
// RTC controlling XTAL pins
Status rtcInUseMessage = new Status("Feature is controlled by RTC which shares XTAL/EXTAL pins", Severity.WARNING);
oscillatorRangeVar.enable(false);
oscillatorRangeVar.setStatus(rtcInUseMessage);
osc_cr_erclkenVar.enable(false);
osc_cr_erclkenVar.setStatus(rtcInUseMessage);
osc_cr_erefstenVar.enable(false);
osc_cr_erefstenVar.setStatus(rtcInUseMessage);
osc_cr_scpVar.enable(false);
osc_cr_scpVar.setStatus(rtcInUseMessage);
mcg_c2_erefs0Var.enable(false);
mcg_c2_erefs0Var.setStatus(rtcInUseMessage);
mcg_c2_hgo0Var.enable(false);
mcg_c2_hgo0Var.setStatus(rtcInUseMessage);
rangeOrigin = "Determined by RTC";
range = 0;
} else {
// OSC controlling XTAL pins
oscillatorRangeVar.enable(true);
oscillatorRangeVar.clearStatus();
osc_cr_erclkenVar.enable(true);
osc_cr_erclkenVar.clearStatus();
osc_cr_erefstenVar.enable(osc_cr_erclkenVar.getValueAsBoolean());
osc_cr_erefstenVar.clearStatus();
mcg_c2_erefs0Var.enable(true);
mcg_c2_erefs0Var.clearStatus();
osc_input_freqVar.clearStatus();
String oscclk_clockOrg;
Status oscclk_clockStatus = null;
boolean oscillatorInUse = mcg_c2_erefs0Var.getValueAsBoolean();
long osc_input_freq = osc_input_freqVar.getValueAsLong();
if (oscillatorInUse) {
// Using oscillator - range is chosen to suit crystal frequency (or forced by RTC)
if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE1_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE1_MAX)) {
oscclk_clockOrg = "OSCCLK (low range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 0;
} else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE2_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE2_MAX)) {
oscclk_clockOrg = "OSCCLK (high range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 1;
} else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE3_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE3_MAX)) {
oscclk_clockOrg = "OSCCLK (very high range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 2;
} else {
// Not suitable as OSC Crystal frequency
oscclk_clockOrg = "OSCCLK (invalid range)";
oscclk_clockStatus = FLL_CLOCK_ERROR_MSG;
range = UNCONSTRAINED_RANGE;
}
} else {
// Using external clock
oscclk_clockOrg = "OSCCLK (External clock)";
// Range has no effect on Oscillator
range = UNCONSTRAINED_RANGE;
// Check suitable clock range
if (osc_input_freq > EXTERNAL_CLOCK_MAX) {
// Not suitable as external clock
oscclk_clockStatus = CLOCK_RANGE_ERROR_MSG;
}
}
osc_cr_scpVar.enable(oscillatorInUse);
osc_cr_scpVar.clearStatus();
mcg_c2_hgo0Var.enable(oscillatorInUse);
mcg_c2_hgo0Var.clearStatus();
boolean oscclkOK = (oscclk_clockStatus == null) || oscclk_clockStatus.getSeverity().lessThan(Severity.WARNING);
osc_clockVar.setOrigin(oscclk_clockOrg);
osc_clockVar.setStatus(oscclk_clockStatus);
osc_clockVar.setValue(oscclkOK ? osc_input_freq : 0);
osc_clockVar.enable(oscclkOK);
}
oscillatorRangeVar.setValue(range);
oscillatorRangeVar.setOrigin(rangeOrigin);
// Check suitability of OSC for OSC32KCLK
// =========================================
// Initially assume suitable
long osc32kclk_clockFreq = osc_clockVar.getValueAsLong();
Status osc32kclk_clockStatus = osc_clockVar.getStatus();
String osc32kclk_clockOrg = osc_clockVar.getOrigin();
if ((osc32kclk_clockFreq < EXTERNAL_EXTAL_RANGE1_MIN) || (osc32kclk_clockFreq > EXTERNAL_EXTAL_RANGE1_MAX)) {
if ((osc32kclk_clockStatus == null) || osc32kclk_clockStatus.lessThan(Severity.ERROR)) {
osc32kclk_clockStatus = new Status(OSCCLK32K_CLOCK_MSG, Severity.WARNING);
}
osc32kclk_clockOrg = osc32kclk_clockOrg + "(invalid range)";
}
osc32k_clockVar.setValue((osc32kclk_clockStatus != null) ? 0 : osc32kclk_clockFreq);
osc32k_clockVar.setStatus(osc32kclk_clockStatus);
osc32k_clockVar.setOrigin(osc32kclk_clockOrg);
// Determine OSCERCLK, OSCERCLK_UNDIV
// ==================================
long osc_clockFreq = osc_clockVar.getValueAsLong();
String osc_clockOrg = osc_clockVar.getOrigin();
if (osc_cr_erclkenVar.getValueAsBoolean()) {
// Oscillator/clock enabled
system_oscer_undiv_clockVar.setValue(osc_clockFreq);
system_oscer_undiv_clockVar.setStatus(osc_clockVar.getFilteredStatus());
system_oscer_undiv_clockVar.setOrigin(osc_clockVar.getOrigin());
system_oscer_undiv_clockVar.enable(true);
long system_oscerclk = osc_clockFreq;
if (osc_div_erpsVar != null) {
// If divider exists
system_oscerclk /= 1 << osc_div_erpsVar.getValueAsLong();
osc_clockOrg += "/osc_div_erps";
system_oscer_clockVar.setValue(system_oscerclk);
system_oscer_clockVar.setStatus(osc_clockVar.getFilteredStatus());
system_oscer_clockVar.setOrigin(osc_clockVar.getOrigin());
system_oscer_clockVar.enable(true);
osc_div_erpsVar.enable(true);
}
} else {
Status osc_crMessage = new Status("Disabled by osc_cr_erclken", Severity.OK);
// Oscillator/clock disabled
// system_oscerclk_undiv_clockVar.setValue(0);
system_oscer_undiv_clockVar.setStatus(osc_crMessage);
system_oscer_undiv_clockVar.setOrigin(osc_clockOrg);
system_oscer_undiv_clockVar.enable(false);
if (osc_div_erpsVar != null) {
// system_oscer_clockVar.setValue(0);
system_oscer_clockVar.setStatus(osc_crMessage);
system_oscer_clockVar.setOrigin(osc_clockOrg);
system_oscer_clockVar.enable(false);
osc_div_erpsVar.enable(false);
}
}
// Warn if EXTAL and XTAL signals not mapped
validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
}
use of net.sourceforge.usbdm.deviceEditor.model.Status in project usbdm-eclipse-plugins by podonoghue.
the class PllConfigure method validate.
protected void validate(Variable mcg_erc_clockNode, Variable pllInputFrequencyNode, Variable system_mcgpllclk_clockVar, Variable mcg_c5_prdiv0Node, Variable mcg_c6_vdiv0Node) {
// Main clock used by FLL
long mcg_erc_clock = mcg_erc_clockNode.getValueAsLong();
long pllTargetFrequency = system_mcgpllclk_clockVar.getRawValueAsLong();
// System.err.println(String.format("\nPllClockValidater.validate(): mcg_erc_clock = %d, pllTargetFrequency = %d", mcg_erc_clock, pllTargetFrequency));
int mcg_prdiv = PRDIV_MIN;
int mcg_vdiv = VDIV_MIN;
boolean pllInputValid = false;
boolean pllOutputValid = false;
Set<Long> pllFrequencies = new TreeSet<Long>();
StringBuilder sb = new StringBuilder();
long nearest_PllOutFrequency = Long.MAX_VALUE;
// Try each prescale value
for (int mcg_prdiv_probe = PRDIV_MIN; mcg_prdiv_probe <= PRDIV_MAX; mcg_prdiv_probe++) {
if (sb.length() > 0) {
// System.err.println(sb.toString());
sb = new StringBuilder();
}
double pllInFrequency = mcg_erc_clock / mcg_prdiv_probe;
sb.append(String.format("(prdiv = %d, pllIn=%f) => ", mcg_prdiv_probe, pllInFrequency));
if (pllInFrequency > PLL_IN_MAX) {
// Invalid as input to PLL
sb.append("too high");
continue;
}
if (pllInFrequency < PLL_IN_MIN) {
// Invalid as input to PLL
sb.append("too low");
break;
}
pllInputValid = true;
// Try each multiplier value
for (int mcg_vdiv_probe = VDIV_MIN; mcg_vdiv_probe <= VDIV_MAX; mcg_vdiv_probe++) {
long pllOutFrequency = Math.round((mcg_vdiv_probe * pllInFrequency) / PLL_POST_DIV);
sb.append(pllOutFrequency);
if (pllOutFrequency < PLL_OUT_MIN) {
sb.append("<, ");
continue;
}
if (pllOutFrequency > PLL_OUT_MAX) {
sb.append(">, ");
break;
}
sb.append("*,");
pllFrequencies.add(pllOutFrequency);
// Best so far
if (Math.abs(pllOutFrequency - pllTargetFrequency) < Math.abs(nearest_PllOutFrequency - pllTargetFrequency)) {
nearest_PllOutFrequency = pllOutFrequency;
mcg_prdiv = mcg_prdiv_probe;
mcg_vdiv = mcg_vdiv_probe;
}
// Accept value within ~2.5% of desired
if (Math.abs(pllOutFrequency - pllTargetFrequency) < (pllTargetFrequency / 50)) {
sb.append("=");
pllOutputValid = true;
}
}
if (sb.length() > 0) {
sb = new StringBuilder();
}
}
// Update with 'best value' - irrespective of whether they are acceptable
mcg_c5_prdiv0Node.setValue(mcg_prdiv);
mcg_c6_vdiv0Node.setValue(mcg_vdiv);
pllInputFrequencyNode.setValue(mcg_erc_clock / mcg_prdiv);
pllInputFrequencyNode.setOrigin("(" + mcg_erc_clockNode.getOrigin() + " via MCG_ERC)/PRDIV");
system_mcgpllclk_clockVar.setOrigin(mcg_erc_clockNode.getOrigin() + " via PLL");
if (!pllInputValid) {
String msg = String.format("PLL not usable with input clock frequency %sHz\nRange: [%s,%s]", EngineeringNotation.convert(mcg_erc_clock, 3), EngineeringNotation.convert(PLL_IN_MIN, 3), EngineeringNotation.convert(PLL_IN_MAX, 3));
Status status = new Status(msg, Severity.WARNING);
pllInputFrequencyNode.setStatus(status);
pllStatus = status;
} else {
// PLL in is valid
pllInputFrequencyNode.setStatus((Status) null);
// Check PLL out
StringBuilder status = new StringBuilder();
Status.Severity severity = Severity.OK;
if (!pllOutputValid) {
// PLL Output invalid
status.append("Not possible to generate desired PLL frequency from input clock\n");
severity = Severity.WARNING;
// Update PLL in case it was approximated
} else {
// PLL Output valid
if (pllTargetFrequency != nearest_PllOutFrequency) {
// Update PLL as it was approximated
pllTargetFrequency = nearest_PllOutFrequency;
if (system_mcgpllclk_clockVar.isEnabled()) {
system_mcgpllclk_clockVar.setValue(pllTargetFrequency);
}
}
}
status.append("Possible values = \n");
boolean needComma = false;
int lineCount = -1;
for (Long freq : pllFrequencies) {
if (needComma) {
status.append(", ");
}
if (lineCount++ >= 10) {
status.append("\n");
lineCount = 0;
}
needComma = true;
status.append(EngineeringNotation.convert(freq, 3) + "Hz");
}
pllStatus = new Status(status.toString(), severity);
}
}
use of net.sourceforge.usbdm.deviceEditor.model.Status in project usbdm-eclipse-plugins by podonoghue.
the class RtcValidate method validate.
/**
* Class to determine RTC oscillator settings
*
* Outputs rtcclk_clock, rtcclk_gated_clock,
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
// Indicates RTC uses main oscillator XTAL/EXTAL pins
Variable rtcSharesPinsVar = safeGetVariable("/SIM/rtcSharesPins");
boolean rtcSharesPins = (safeGetVariable("/SIM/rtcSharesPins") != null) && rtcSharesPinsVar.getValueAsBoolean();
super.validate(variable);
// RTC
// =================================
BooleanVariable rtc_cr_osceVar = getBooleanVariable("rtc_cr_osce");
ChoiceVariable rtc_cr_scpVar = getChoiceVariable("rtc_cr_scp");
Variable rtc_cr_umVar = getVariable("rtc_cr_um");
Variable rtc_cr_supVar = getVariable("rtc_cr_sup");
Variable rtc_cr_wpeVar = getVariable("rtc_cr_wpe");
LongVariable rtc_1hz_clockVar = getLongVariable("rtc_1hz_clock");
long osc_input_freq = 0;
LongVariable osc_input_freqVar = null;
LongVariable osc_clockVar = null;
Status status = null;
String origin = "RTCCLK";
if (rtcSharesPins) {
// RTC uses main oscillator XTAL/EXTAL pins
// ===================================================
String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
osc_input_freqVar = getLongVariable(osc0_peripheral + "/osc_input_freq");
osc_clockVar = getLongVariable(osc0_peripheral + "/osc_clock");
origin = "RTCCLK";
rtc_cr_osceVar.setToolTip("Enable main oscillator as 32kHz RTC oscillator\n" + "Note: this disables OSC control by MCG");
} else {
// RTC uses separate XTAL32/EXTAL32 pins
// ===================================================
osc_input_freqVar = getLongVariable("osc_input_freq");
osc_clockVar = getLongVariable("osc_clock");
origin = "RTCCLK";
rtc_cr_osceVar.setToolTip("Enable 32kHz RTC oscillator");
// Warn if SCL and SDA signals not mapped
validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
}
osc_input_freq = osc_input_freqVar.getValueAsLong();
// =========================================
// Check input clock/oscillator ranges
//
long rtcClockFrequency = osc_input_freq;
if ((osc_input_freq < RtcValidate.EXTERNAL_EXTAL_RANGE_MIN) || (osc_input_freq > RtcValidate.EXTERNAL_EXTAL_RANGE_MAX)) {
status = OSCCLK32K_CLOCK_WARNING_MSG;
origin = origin + " (invalid range)";
rtcClockFrequency = 0L;
rtc_cr_osceVar.setValue(false);
rtc_cr_osceVar.setStatus(status);
if (!rtcSharesPins) {
osc_input_freqVar.setStatus(status);
}
} else {
rtc_cr_osceVar.setStatus((Status) null);
if (!rtcSharesPins) {
osc_input_freqVar.setStatus((Status) null);
}
if (!rtc_cr_osceVar.getValueAsBoolean()) {
status = new Status("Disabled by rtc_cr_osce", Severity.WARNING);
origin = origin + " (disabled)";
rtcClockFrequency = 0L;
}
}
// =========================================
// Check and propagate enabled
//
boolean rtc_cr_osce = rtc_cr_osceVar.isEnabled() && rtc_cr_osceVar.getValueAsBoolean();
rtc_cr_scpVar.enable(rtc_cr_osce);
rtc_cr_umVar.enable(rtc_cr_osce);
rtc_cr_supVar.enable(rtc_cr_osce);
rtc_cr_wpeVar.enable(rtc_cr_osce);
osc_clockVar.enable(rtc_cr_osce);
rtc_1hz_clockVar.enable(rtc_cr_osce);
if (!rtcSharesPins || rtc_cr_osce) {
// Only update if owned by RTC
osc_clockVar.setValue(rtcClockFrequency);
osc_clockVar.setStatus(status);
osc_clockVar.setOrigin(origin);
}
rtc_1hz_clockVar.setValue((rtcClockFrequency > 0) ? 1 : 0);
rtc_1hz_clockVar.setStatus(status);
rtc_1hz_clockVar.setOrigin(origin);
// RTC Clocks
// ==============================
// Check if gating option
BooleanVariable rtc_cr_clkoVar = getBooleanVariable("rtc_cr_clko");
LongVariable rtcclk_gated_clockVar = getLongVariable("rtcclk_gated_clock");
rtc_cr_clkoVar.enable(rtc_cr_osce);
if (rtc_cr_clkoVar.isEnabled() && rtc_cr_clkoVar.getValueAsBoolean()) {
rtcclk_gated_clockVar.setValue(rtcClockFrequency);
rtcclk_gated_clockVar.setStatus(status);
rtcclk_gated_clockVar.setOrigin(origin);
rtcclk_gated_clockVar.enable(rtc_cr_osce);
} else {
rtcclk_gated_clockVar.setValue(0L);
rtcclk_gated_clockVar.setStatus(new Status("Disabled by rtc_cr_clko", Severity.WARNING));
rtcclk_gated_clockVar.setOrigin("RTCCLK (disabled)");
rtcclk_gated_clockVar.enable(false);
}
}
Aggregations