diff options
author | Mike <mjc@avtechpulse.com> | 2000-01-01 04:12:49 +0900 |
---|---|---|
committer | Mike <mjc@avtechpulse.com> | 2000-01-01 04:12:49 +0900 |
commit | 5571023fbc58f88976dd3387ce92616996d53551 (patch) | |
tree | 5a50f728403e61352d59d562595e0a87884cc98e | |
parent | 551010eb696952159e2c827893abfb3642d8dc31 (diff) |
most error checks now used rationalized limit-check functions
-rw-r--r-- | error_utils.c | 309 | ||||
-rw-r--r-- | globals.h | 1 |
2 files changed, 100 insertions, 210 deletions
diff --git a/error_utils.c b/error_utils.c index 026e6dc..1fa3b3a 100644 --- a/error_utils.c +++ b/error_utils.c @@ -44,7 +44,6 @@ void set_gpib_error_flags (int error_num) case obsolete_feature: case config_too_large: case config_cant_be_negative: - case invalid_error_check: GPIB_Set_Command_Error(); break; case query_error_interrupted: @@ -605,10 +604,6 @@ void get_error_text(gchar **response, int error_num) format_error_text(response,-200,"Invalid execution path. Programming error."); break; - case invalid_error_check: - format_error_text(response,-200,"Invalid error checking. Needs programming fix."); - break; - case Startup_Not_Finished: format_error_text(response,-300,"Not ready for commands yet. Still booting up."); break; @@ -632,46 +627,39 @@ void get_error_text(gchar **response, int error_num) } -void check_starting_pos_max_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { - +void check_initial_min_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { *running_limit = test_limit; - if (proposed_value > (*running_limit * 1.001)) { + if ( ((test_limit >= 0.0) && (proposed_value < (*running_limit * 0.999))) || + ((test_limit < 0.0) && (proposed_value < (*running_limit * 1.001)))) { *actual_error = possible_error; } - - if (test_limit < 0.0) { - *actual_error = invalid_error_check; - } } -void check_another_pos_max_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { - - if (test_limit < *running_limit) { - check_starting_pos_max_value (test_limit, running_limit, proposed_value, possible_error, actual_error); +void check_another_min_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { + if (test_limit > *running_limit) { + check_initial_min_value (test_limit, running_limit, proposed_value, possible_error, actual_error); } } -void check_starting_pos_min_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { + +void check_initial_max_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { *running_limit = test_limit; - if (proposed_value < (*running_limit * 0.999)) { + if ( ((test_limit >= 0.0) && (proposed_value > (*running_limit * 1.001))) || + ((test_limit < 0.0) && (proposed_value > (*running_limit * 0.999)))) { *actual_error = possible_error; } - - if (test_limit < 0.0) { - *actual_error = invalid_error_check; - } } -void check_another_pos_min_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { - - if (test_limit > *running_limit) { - check_starting_pos_min_value (test_limit, running_limit, proposed_value, possible_error, actual_error); +void check_another_max_value (float test_limit, float *running_limit, float proposed_value, int possible_error, int *actual_error) { + if (test_limit < *running_limit) { + check_initial_max_value (test_limit, running_limit, proposed_value, possible_error, actual_error); } } + int Error_check(ChannelStruct ChannelStateToTest[max_channels]) { static GStaticMutex mutex = G_STATIC_MUTEX_INIT; @@ -883,117 +871,112 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check minimum frequency --- */ - check_starting_pos_min_value (globals.Flash.min_freq[i], &globals.Constraints.err_min_freq[i], ChannelStateToTest[i].frequency, freq_lower_limit, &report_error); + check_initial_min_value (globals.Flash.min_freq[i], &globals.Constraints.err_min_freq[i], ChannelStateToTest[i].frequency, freq_lower_limit, &report_error); /* ------------------------------- */ /* --- check maximum frequency --- */ - check_starting_pos_max_value (globals.Flash.max_freq[i], &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, freq_upper_limit, &report_error); + check_initial_max_value (globals.Flash.max_freq[i], &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, freq_upper_limit, &report_error); if ((globals.Flash.max_freq_for_high_ot[i] > 0.0) && (fabs(ChannelStateToTest[i].offset) > globals.Flash.high_ot[i])) { - check_another_pos_max_value (globals.Flash.max_freq_for_high_ot[i], &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, PRF_limited_by_offset, &report_error); + check_another_max_value (globals.Flash.max_freq_for_high_ot[i], &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, PRF_limited_by_offset, &report_error); } - check_another_pos_max_value (0.95/fabs(ChannelStateToTest[i].delay), &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Delay_Exceeds_95Period, &report_error); + check_another_max_value (0.95/fabs(ChannelStateToTest[i].delay), &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Delay_Exceeds_95Period, &report_error); if (globals.Flash.min_pw[i] > 0.0) { - check_another_pos_max_value (1/ChannelStateToTest[i].pw, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, PW_Exceeds_Period, &report_error); + check_another_max_value (1/ChannelStateToTest[i].pw, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, PW_Exceeds_Period, &report_error); if ( (ChannelStateToTest[i].burst_count>1) && (globals.Flash.max_burst_count[i]>1) && !globals.Flash.burst_func[i]) { - check_another_pos_max_value (1/(ChannelStateToTest[i].burst_count * (ChannelStateToTest[i].pw+ChannelStateToTest[i].burst_time)), + check_another_max_value (1/(ChannelStateToTest[i].burst_count * (ChannelStateToTest[i].pw+ChannelStateToTest[i].burst_time)), &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Burst_Exceeds_Period, &report_error); } - check_another_pos_max_value ((1/ChannelStateToTest[i].pw)*(ampl_fixed_max_duty/duty_scale), + check_another_max_value ((1/ChannelStateToTest[i].pw)*(ampl_fixed_max_duty/duty_scale), &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, duty_cycle_upper_limit, &report_error); if (ChannelStateToTest[i].double_pulse==double_on) { // pulse sep must be less than one half-period - check_another_pos_max_value (0.5 / ChannelStateToTest[i].delay, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Double_Separation_Too_Large, &report_error); + check_another_max_value (0.5 / ChannelStateToTest[i].delay, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Double_Separation_Too_Large, &report_error); } if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { temp=100.0 * globals.Flash.max_avg_ampl[i] / (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw * duty_scale); - check_another_pos_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Average_Amplitude_Too_High, &report_error); + check_another_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, Average_Amplitude_Too_High, &report_error); } if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].pw > 0.0)) { temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw); - check_another_pos_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, HVPS_Current_Too_High, &report_error); + check_another_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, HVPS_Current_Too_High, &report_error); } if (globals.Flash.max_avg_power[i] > 0.0) { temp = (globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type) / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw); - check_another_pos_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, average_power_limit, &report_error); + check_another_max_value (temp, &globals.Constraints.err_max_freq[i], ChannelStateToTest[i].frequency, average_power_limit, &report_error); } } /* ------------------------------- */ /* --- check minimum pulse width --- */ - globals.Constraints.err_min_pw[i]=globals.Flash.min_pw[i]; - - if ( (globals.Constraints.err_min_pw[i]>=0.0 && ChannelStateToTest[i].pw<(0.999*globals.Constraints.err_min_pw[i])) - || (globals.Constraints.err_min_pw[i]<0.0 && ChannelStateToTest[i].pw<(1.001*globals.Constraints.err_min_pw[i])) ) { - report_error=pw_lower_limit; - } + check_initial_min_value (globals.Flash.min_pw[i], &globals.Constraints.err_min_pw[i], ChannelStateToTest[i].pw, pw_lower_limit, &report_error); /* ------------------------------- */ /* --- check maximum pw ---------- */ - check_starting_pos_max_value (globals.Flash.max_pw[i], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); + check_initial_max_value (globals.Flash.max_pw[i], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); /* polarity overrides */ if ((ChannelStateToTest[i].amplitude >= 0.0) && (globals.Flash.max_pw_pol[i][0] > 0.0)) { - check_another_pos_max_value (globals.Flash.max_pw_pol[i][0], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); + check_another_max_value (globals.Flash.max_pw_pol[i][0], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); } else if ((ChannelStateToTest[i].amplitude <0.0) && (globals.Flash.max_pw_pol[i][1] > 0.0)) { - check_another_pos_max_value (globals.Flash.max_pw_pol[i][1], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); + check_another_max_value (globals.Flash.max_pw_pol[i][1], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_upper_limit, &report_error); } // RC limit, as per AVR-8F-B - check_another_pos_max_value (globals.Flash.cap_for_pw_rc_limit[i] * ChannelStateToTest[i].load_type, + check_another_max_value (globals.Flash.cap_for_pw_rc_limit[i] * ChannelStateToTest[i].load_type, &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, pw_rc_limit, &report_error); if (ChannelStateToTest[i].double_pulse==double_on) { - check_another_pos_max_value ((ChannelStateToTest[i].delay - globals.Flash.double_pulse_extra_deadtime[i]) / (1.0 + globals.Flash.double_pulse_extra_pw_margin[i]), + check_another_max_value ((ChannelStateToTest[i].delay - globals.Flash.double_pulse_extra_deadtime[i]) / (1.0 + globals.Flash.double_pulse_extra_pw_margin[i]), &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, Double_Separation_Too_Small, &report_error); if (ChannelStateToTest[i].burst_count>1) { report_error=Cant_Do_Burst_and_Double; } } - check_another_pos_max_value ((1/ChannelStateToTest[i].frequency) - globals.Flash.dead_time[i], + check_another_max_value ((1/ChannelStateToTest[i].frequency) - globals.Flash.dead_time[i], &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, Dead_Time_Error, &report_error); - check_another_pos_max_value (1/ChannelStateToTest[i].frequency, &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, PW_Exceeds_Period, &report_error); + check_another_max_value (1/ChannelStateToTest[i].frequency, &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, PW_Exceeds_Period, &report_error); if ( (ChannelStateToTest[i].burst_count>1) && (globals.Flash.max_burst_count[i]>1) && !globals.Flash.burst_func[i]) { - check_another_pos_max_value ((1/ChannelStateToTest[i].frequency)/ChannelStateToTest[i].burst_count - ChannelStateToTest[i].burst_time, + check_another_max_value ((1/ChannelStateToTest[i].frequency)/ChannelStateToTest[i].burst_count - ChannelStateToTest[i].burst_time, &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, Burst_Exceeds_Period, &report_error); } - check_another_pos_max_value ((1/ChannelStateToTest[i].frequency)*(ampl_fixed_max_duty/duty_scale), + check_another_max_value ((1/ChannelStateToTest[i].frequency)*(ampl_fixed_max_duty/duty_scale), &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, duty_cycle_upper_limit, &report_error); if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { - check_another_pos_max_value (100.0 * globals.Flash.max_avg_ampl[i] / (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency * duty_scale), + check_another_max_value (100.0 * globals.Flash.max_avg_ampl[i] / (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency * duty_scale), &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, Average_Amplitude_Too_High, &report_error); } if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].frequency > 0.0)) { - check_another_pos_max_value ((100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / + check_another_max_value ((100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency), &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, HVPS_Current_Too_High, &report_error); } if (globals.Flash.max_avg_power[i] > 0.0) { - check_another_pos_max_value (globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / + check_another_max_value (globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].frequency), &globals.Constraints.err_max_pw[i], ChannelStateToTest[i].pw, average_power_limit, &report_error); } @@ -1003,81 +986,40 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check minimum delay ------- */ if (globals.Flash.min_delay[i] != 0.0) { /* use programmed limit, if non-zero */ - globals.Constraints.err_min_delay[i]=globals.Flash.min_delay[i]; + temp=globals.Flash.min_delay[i]; } else { /* otherwise, assume delay has equal +/- range */ - globals.Constraints.err_min_delay[i]=-globals.Flash.max_delay[i]; + temp=-globals.Flash.max_delay[i]; /* for dual-delay units, positive delay only for second channel */ if ((globals.Flash.ChanKey_delay?globals.Flash.channels:1)>1) { if (i>0) { - globals.Constraints.err_min_delay[i]=0.0; + temp=0.0; } } } + check_initial_min_value (temp, &globals.Constraints.err_min_delay[i], ChannelStateToTest[i].delay, delay_lower_limit, &report_error); - if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) - || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { - report_error=delay_lower_limit; - } - - temp=-0.95/ChannelStateToTest[i].frequency; - if (temp>globals.Constraints.err_min_delay[i]) { - globals.Constraints.err_min_delay[i]=temp; - if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) - || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { - report_error=Delay_Exceeds_95Period; - } - } + check_another_min_value (-0.95/ChannelStateToTest[i].frequency, &globals.Constraints.err_min_delay[i], ChannelStateToTest[i].delay, Delay_Exceeds_95Period, &report_error); if (ChannelStateToTest[i].double_pulse==double_on) { - temp=globals.Flash.double_pulse_min_sep[i]; - if (temp>globals.Constraints.err_min_delay[i]) { - globals.Constraints.err_min_delay[i]=temp; - if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) - || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { - report_error=Double_Separation_Too_Small; - } - } - temp=ChannelStateToTest[i].pw * (1.0 + globals.Flash.double_pulse_extra_pw_margin[i]) + globals.Flash.double_pulse_extra_deadtime[i]; - if (temp>globals.Constraints.err_min_delay[i]) { - globals.Constraints.err_min_delay[i]=temp; - if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) - || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { - report_error=Double_Separation_Too_Small; - } - } + check_another_min_value (globals.Flash.double_pulse_min_sep[i], + &globals.Constraints.err_min_delay[i], ChannelStateToTest[i].delay, Double_Separation_Too_Small, &report_error); + + check_another_min_value (ChannelStateToTest[i].pw * (1.0 + globals.Flash.double_pulse_extra_pw_margin[i]) + globals.Flash.double_pulse_extra_deadtime[i], + &globals.Constraints.err_min_delay[i], ChannelStateToTest[i].delay, Double_Separation_Too_Small, &report_error); } /* ------------------------------- */ /* --- check maximum delay ------- */ - globals.Constraints.err_max_delay[i]=globals.Flash.max_delay[i]; - - if ( (globals.Constraints.err_max_delay[i]>=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) - || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { - report_error=delay_upper_limit; - } + check_initial_max_value (globals.Flash.max_delay[i], &globals.Constraints.err_max_delay[i], ChannelStateToTest[i].delay, delay_upper_limit, &report_error); - temp=0.95/ChannelStateToTest[i].frequency; - if (temp<globals.Constraints.err_max_delay[i]) { - globals.Constraints.err_max_delay[i]=temp; - if ( (globals.Constraints.err_max_delay[i]>=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) - || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { - report_error=Delay_Exceeds_95Period; - } - } + check_another_max_value (0.95/ChannelStateToTest[i].frequency, &globals.Constraints.err_max_delay[i], ChannelStateToTest[i].delay, Delay_Exceeds_95Period, &report_error); if (ChannelStateToTest[i].double_pulse==double_on) { // one half-period - temp = 0.5 / ChannelStateToTest[i].frequency; - if (temp<globals.Constraints.err_max_delay[i]) { - globals.Constraints.err_max_delay[i]=temp; - if ( (globals.Constraints.err_max_delay[i]>=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) - || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { - report_error=Double_Separation_Too_Large; - } - } + check_another_max_value (0.5 / ChannelStateToTest[i].frequency, &globals.Constraints.err_max_delay[i], ChannelStateToTest[i].delay, Double_Separation_Too_Large, &report_error); } /* ------------------------------- */ @@ -1116,24 +1058,14 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check minimum amplitude --- */ if (uses_fixed_ampl && (min_fixed_ampl > globals.Flash.min_ampl[i])) { - globals.Constraints.err_min_ampl[i]=min_fixed_ampl; + temp = min_fixed_ampl; } else { - globals.Constraints.err_min_ampl[i]=globals.Flash.min_ampl[i]; + temp = globals.Flash.min_ampl[i]; } + check_initial_min_value (temp, &globals.Constraints.err_min_ampl[i], ChannelStateToTest[i].amplitude, amplitude_lower_limit, &report_error); - if ( (globals.Constraints.err_min_ampl[i]>=0.0 && ChannelStateToTest[i].amplitude<(0.999*globals.Constraints.err_min_ampl[i])) - || (globals.Constraints.err_min_ampl[i]<0.0 && ChannelStateToTest[i].amplitude<(1.001*globals.Constraints.err_min_ampl[i])) ) { - report_error=amplitude_lower_limit; - } - - temp=globals.Flash.min_vout[i]-ChannelStateToTest[i].offset; - if (temp>globals.Constraints.err_min_ampl[i]) { - globals.Constraints.err_min_ampl[i]=temp; - if ( (globals.Constraints.err_min_ampl[i]>=0.0 && ChannelStateToTest[i].amplitude<(0.999*globals.Constraints.err_min_ampl[i])) - || (globals.Constraints.err_min_ampl[i]<0.0 && ChannelStateToTest[i].amplitude<(1.001*globals.Constraints.err_min_ampl[i])) ) { - report_error=ampl_plus_os_lower_limit; - } - } + check_another_min_value (globals.Flash.min_vout[i]-ChannelStateToTest[i].offset, + &globals.Constraints.err_min_ampl[i], ChannelStateToTest[i].amplitude, ampl_plus_os_lower_limit, &report_error); /* ------------------------------- */ @@ -1141,70 +1073,49 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check maximum amplitude --- */ if (uses_fixed_ampl && (max_fixed_ampl < globals.Flash.max_ampl[i])) { - globals.Constraints.err_max_ampl[i]=max_fixed_ampl; + temp = max_fixed_ampl; } else { - globals.Constraints.err_max_ampl[i]=globals.Flash.max_ampl[i]; + temp = globals.Flash.max_ampl[i]; } + check_initial_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, amplitude_upper_limit, &report_error); - if ( (globals.Constraints.err_max_ampl[i]>=0.0 && ChannelStateToTest[i].amplitude>(1.001*globals.Constraints.err_max_ampl[i])) - || (globals.Constraints.err_max_ampl[i]<0.0 && ChannelStateToTest[i].amplitude>(0.999*globals.Constraints.err_max_ampl[i])) ) { - report_error=amplitude_upper_limit; - } + check_another_max_value (globals.Flash.max_vout[i]-ChannelStateToTest[i].offset, + &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, ampl_plus_os_upper_limit, &report_error); - temp = sqrt(globals.Flash.max_peak_power[i] * ChannelStateToTest[i].load_type); - // FIXME? - if ((temp > 0.0) && (temp < globals.Constraints.err_max_ampl[i])) { - globals.Constraints.err_max_ampl[i] = temp; - if (-temp > globals.Constraints.err_min_ampl[i]) { - globals.Constraints.err_min_ampl[i] = -temp; - } + if (globals.Flash.max_peak_power[i] > 0.0) { + temp = sqrt(globals.Flash.max_peak_power[i] * ChannelStateToTest[i].load_type); + // temp is positive at this point + check_another_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, peak_power_limit, &report_error); - if ((1.001*globals.Constraints.err_max_ampl[i]) < fabs(ChannelStateToTest[i].amplitude)) { - report_error=peak_power_limit; - } + temp = temp * -1.0; // check negative possibility + check_another_min_value (temp, &globals.Constraints.err_min_ampl[i], ChannelStateToTest[i].amplitude, peak_power_limit, &report_error); } if (globals.Flash.max_avg_power[i] > 0.0) { temp = sqrt(globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency)); // temp is positive at this point - check_another_pos_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, average_power_limit, &report_error); + check_another_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, average_power_limit, &report_error); temp = temp * -1.0; // check negative possibility - if (temp > globals.Constraints.err_min_ampl[i]) { - globals.Constraints.err_min_ampl[i]=temp; - if (ChannelStateToTest[i].amplitude<(1.001*globals.Constraints.err_min_ampl[i])) { - report_error=average_power_limit; - } - } - } - - temp=globals.Flash.max_vout[i]-ChannelStateToTest[i].offset; - if (temp<globals.Constraints.err_max_ampl[i]) { - globals.Constraints.err_max_ampl[i]=temp; - if ( (globals.Constraints.err_max_ampl[i]>=0.0 && ChannelStateToTest[i].amplitude>(1.001*globals.Constraints.err_max_ampl[i])) - || (globals.Constraints.err_max_ampl[i]<0.0 && ChannelStateToTest[i].amplitude>(0.999*globals.Constraints.err_max_ampl[i])) ) { - report_error=ampl_plus_os_upper_limit; - } + check_another_min_value (temp, &globals.Constraints.err_min_ampl[i], ChannelStateToTest[i].amplitude, average_power_limit, &report_error); } if (globals.Flash.min_pw[i] > 0.0) { /* Check average amplitude */ - if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { - temp=100.0 * globals.Flash.max_avg_ampl[i] / (ChannelStateToTest[i].frequency * ChannelStateToTest[i].pw * duty_scale); - if (temp<globals.Constraints.err_max_ampl[i]) { - globals.Constraints.err_max_ampl[i]=temp; - if ( (globals.Constraints.err_max_ampl[i]>=0.0 && ChannelStateToTest[i].amplitude>(1.001*globals.Constraints.err_max_ampl[i])) - || (globals.Constraints.err_max_ampl[i]<0.0 && ChannelStateToTest[i].amplitude>(0.999*globals.Constraints.err_max_ampl[i])) ) { - report_error=Average_Amplitude_Too_High; - } - } + if (globals.Flash.max_avg_ampl[i] > 0.0) { + temp = 100.0 * globals.Flash.max_avg_ampl[i] / (ChannelStateToTest[i].frequency * ChannelStateToTest[i].pw * duty_scale); + // temp is positive at this point + check_another_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, Average_Amplitude_Too_High, &report_error); + + temp = temp * -1.0; // check negative possibility + check_another_min_value (temp, &globals.Constraints.err_min_ampl[i], ChannelStateToTest[i].amplitude, Average_Amplitude_Too_High, &report_error); } if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].frequency) > 0.0) && (ChannelStateToTest[i].pw > 0.0)) { temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].frequency * ChannelStateToTest[i].pw); // temp is positive at this point - check_another_pos_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, HVPS_Current_Too_High, &report_error); + check_another_max_value (temp, &globals.Constraints.err_max_ampl[i], ChannelStateToTest[i].amplitude, HVPS_Current_Too_High, &report_error); temp = temp * -1.0; // check negative possibility if (temp > globals.Constraints.err_min_ampl[i]) { @@ -1219,6 +1130,7 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) if (duty_cycle>(100.0*ampl_fixed_max_duty/duty_scale)) /* set at crossover voltage */ { + // FIXME to use check_ functions temp=globals.Flash.duty_ampl[i]; if (temp<globals.Constraints.err_max_ampl[i]) { @@ -1240,23 +1152,14 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) if ((globals.Flash.voltage_offset_enabled[i]) || (globals.Flash.current_offset_enabled[i])) { /* --- check minimum offset ------ */ - globals.Constraints.err_min_offset[i]=globals.Flash.min_offset[i]; - - if ( (globals.Constraints.err_min_offset[i]>=0.0 && ChannelStateToTest[i].offset<(0.999*globals.Constraints.err_min_offset[i])) - || (globals.Constraints.err_min_offset[i]<0.0 && ChannelStateToTest[i].offset<(1.001*globals.Constraints.err_min_offset[i])) ) { - report_error=offset_lower_limit; - } + check_initial_min_value (globals.Flash.min_offset[i], + &globals.Constraints.err_min_offset[i], ChannelStateToTest[i].offset, offset_lower_limit, &report_error); - temp=globals.Flash.min_vout[i]-ChannelStateToTest[i].amplitude; - if (temp>globals.Constraints.err_min_offset[i]) { - globals.Constraints.err_min_offset[i]=temp; - if ( (globals.Constraints.err_min_offset[i]>=0.0 && ChannelStateToTest[i].offset<(0.999*globals.Constraints.err_min_offset[i])) - || (globals.Constraints.err_min_offset[i]<0.0 && ChannelStateToTest[i].offset<(1.001*globals.Constraints.err_min_offset[i])) ) { - report_error=ampl_plus_os_lower_limit; - } - } + check_another_min_value (globals.Flash.min_vout[i]-ChannelStateToTest[i].amplitude, + &globals.Constraints.err_min_offset[i], ChannelStateToTest[i].offset, ampl_plus_os_lower_limit, &report_error); /* 1011 models: high level of PG-P output must remain positive */ + // FIXME use new check_ functions? if (globals.Flash.ampl_coupled_to_os[i]) { if (ChannelStateToTest[i].amplitude>globals.Flash.ampl_zero_equiv[i]) { temp=-ChannelStateToTest[i].amplitude; @@ -1285,21 +1188,11 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check maximum offset ------ */ - globals.Constraints.err_max_offset[i]=globals.Flash.max_offset[i]; - - if ( (globals.Constraints.err_max_offset[i]>=0.0 && ChannelStateToTest[i].offset>(1.001*globals.Constraints.err_max_offset[i])) - || (globals.Constraints.err_max_offset[i]<0.0 && ChannelStateToTest[i].offset>(0.999*globals.Constraints.err_max_offset[i])) ) { - report_error=offset_upper_limit; - } + check_initial_max_value (globals.Flash.max_offset[i], + &globals.Constraints.err_max_offset[i], ChannelStateToTest[i].offset, offset_upper_limit, &report_error); - temp=globals.Flash.max_vout[i]-ChannelStateToTest[i].amplitude; - if (temp<globals.Constraints.err_max_offset[i]) { - globals.Constraints.err_max_offset[i]=temp; - if ( (globals.Constraints.err_max_offset[i]>=0.0 && ChannelStateToTest[i].offset>(1.001*globals.Constraints.err_max_offset[i])) - || (globals.Constraints.err_max_offset[i]<0.0 && ChannelStateToTest[i].offset>(0.999*globals.Constraints.err_max_offset[i])) ) { - report_error=ampl_plus_os_upper_limit; - } - } + check_another_max_value (globals.Flash.max_vout[i]-ChannelStateToTest[i].amplitude, + &globals.Constraints.err_max_offset[i], ChannelStateToTest[i].offset, ampl_plus_os_upper_limit, &report_error); /* 1011 models: low level of PG-N output must remain negative */ if (globals.Flash.ampl_coupled_to_os[i]) { @@ -1447,54 +1340,52 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } } - check_starting_pos_min_value (globals.Flash.min_rise_time[i], &globals.Constraints.err_min_rise_time[i], ChannelStateToTest[i].rise_time, min_rise_time_error, &report_error); - check_starting_pos_max_value (globals.Flash.max_rise_time[i], &globals.Constraints.err_max_rise_time[i], ChannelStateToTest[i].rise_time, max_rise_time_error, &report_error); + check_initial_min_value (globals.Flash.min_rise_time[i], &globals.Constraints.err_min_rise_time[i], ChannelStateToTest[i].rise_time, min_rise_time_error, &report_error); + check_initial_max_value (globals.Flash.max_rise_time[i], &globals.Constraints.err_max_rise_time[i], ChannelStateToTest[i].rise_time, max_rise_time_error, &report_error); } /* --- check slew settings --- */ /* disable amplitude checks if calibration is in progress */ if (globals.Flash.curr_slew[i]) if (!globals.Flags.extended_ampl_min_max) { - check_starting_pos_min_value (globals.Flash.min_slew[i], &globals.Constraints.err_min_slew[i], ChannelStateToTest[i].slew, min_slew_error, &report_error); - check_starting_pos_max_value (globals.Flash.max_slew[i], &globals.Constraints.err_max_slew[i], ChannelStateToTest[i].slew, max_slew_error, &report_error); + check_initial_min_value (globals.Flash.min_slew[i], &globals.Constraints.err_min_slew[i], ChannelStateToTest[i].slew, min_slew_error, &report_error); + check_initial_max_value (globals.Flash.max_slew[i], &globals.Constraints.err_max_slew[i], ChannelStateToTest[i].slew, max_slew_error, &report_error); } /* --- check resistance settings --- */ if (globals.Flash.switchable_load[i]) { - // FIXME to use new check_ functions - globals.Constraints.err_min_load_type[i]=globals.Flash.low_load_type[i]; + check_initial_min_value (globals.Flash.low_load_type[i], &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, min_load_type_error, &report_error); + if (duty_cycle > max_duty_this_ampl) { - globals.Constraints.err_min_load_type[i] *= duty_cycle / max_duty_this_ampl; - } - if (ChannelStateToTest[i].load_type<(0.999*globals.Constraints.err_min_load_type[i])) { - report_error=min_load_type_error; + check_another_min_value (globals.Flash.low_load_type[i] * duty_cycle / max_duty_this_ampl, + &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, min_load_type_error, &report_error); } } if (globals.Flash.cap_for_pw_rc_limit[i] > 0.0) { - check_another_pos_min_value (ChannelStateToTest[i].pw / globals.Flash.cap_for_pw_rc_limit[i], + check_another_min_value (ChannelStateToTest[i].pw / globals.Flash.cap_for_pw_rc_limit[i], &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, pw_rc_limit, &report_error); } if (globals.Flash.hvps_avg_curr_limit[i] > 0.0) { - check_another_pos_min_value ((duty_scale / 100.0) * fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency / + check_another_min_value ((duty_scale / 100.0) * fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency / globals.Flash.hvps_avg_curr_limit[i], &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, HVPS_Current_Too_High, &report_error); } if (globals.Flash.max_peak_power[i] > 0.0) { - check_another_pos_min_value (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude / globals.Flash.max_peak_power[i], + check_another_min_value (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude / globals.Flash.max_peak_power[i], &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, peak_power_limit, &report_error); } if (globals.Flash.max_avg_power[i] > 0.0) { - check_another_pos_min_value ((ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency) / + check_another_min_value ((ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency) / globals.Flash.max_avg_power[i], &globals.Constraints.err_min_load_type[i], ChannelStateToTest[i].load_type, average_power_limit, &report_error); } - check_starting_pos_max_value (globals.Flash.high_load_type[i], &globals.Constraints.err_max_load_type[i], ChannelStateToTest[i].load_type, max_load_type_error, &report_error); + check_initial_max_value (globals.Flash.high_load_type[i], &globals.Constraints.err_max_load_type[i], ChannelStateToTest[i].load_type, max_load_type_error, &report_error); /* --- check soft_current_limit settings --- */ if (globals.Flash.soft_current_limit_enabled[i]) { @@ -110,7 +110,6 @@ #define Between_0_and_10_Volts 96 #define pw_rc_limit 97 #define HVPS_Current_Too_High 98 -#define invalid_error_check 99 #define YES 1 #define NO 0 |