diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-24 12:53:31 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-24 12:53:31 -0400 |
commit | badac819cb07b684197295f2b516a023a4725a62 (patch) | |
tree | 92989e7901e734944826ad5af9841400ec0732c6 | |
parent | fa97b5d1fadca8fc6ef0a95e6a6b35e756f9434e (diff) |
variable scope reductions
-rw-r--r-- | device-functions.c | 73 | ||||
-rw-r--r-- | parser.c | 2 |
2 files changed, 33 insertions, 42 deletions
diff --git a/device-functions.c b/device-functions.c index 958c2cf..338fce7 100644 --- a/device-functions.c +++ b/device-functions.c @@ -143,13 +143,9 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w { int word_out; /* what is sent to the DAC */ int relay_range,old_range,old_actual_pol; /* selects relay range */ - int i; - int error_num; int UseNegData; /* if polarity is negative and separate piece-wise linear data is available for neg */ int point_found; - long mask; int entry; - int status; int actual_pol; if (globals.Flash.enable_avrq_extra_ampls && channel) { @@ -198,6 +194,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w } if (!check_possible_only) { + int i, error_num; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -223,6 +220,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w actual_pol=pol_override; } else { /* set the amplitude controls now. */ + int status; if ((status=Set_VI_Control(pwl_ampl_values,channel,new_ampl,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -281,7 +279,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xff07f)) | ((long)(1<<(relay_range+7))); } - mask = ((long) 1) << (globals.Flash.polarity_xtra_rly[channel]+14); + long mask = ((long) 1) << (globals.Flash.polarity_xtra_rly[channel]+14); if (new_ampl<0.0) { globals.Registers.shift_reg_out[2] &= (long)(0xfffff-mask); /* set O.POL line low to switch pol relay to - */ } else { @@ -321,8 +319,6 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan int word_out; /* what is sent to the DAC */ int cap_range_control; int point_found,relay_range,UseNegData,entry; - int i; - int check_valid; int status,actual_pol; /* abandon if high channel selected by user but not enabled by firmware */ @@ -340,6 +336,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan } if (!check_possible_only) { + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -462,11 +459,9 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan int Set_Offset(int check_possible_only,int override_on,int word_override,int range_override,int channel,float new_offset) { int word_out; /* what is sent to the DAC */ - int i; - int error_num; int point_found; int entry,dummy1,dummy2,dummy3; - int status,actual_pol; + int actual_pol; int old_range,relay_range; if (!globals.Flash.voltage_offset_enabled[channel] && !globals.Flash.current_offset_enabled[channel]) { @@ -482,6 +477,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran point_found = 0; if (!check_possible_only) { + int i, error_num; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -499,6 +495,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran relay_range=range_override; word_out=word_override; } else { + int status; if ((status=Set_VI_Control(pwl_os_values,channel,new_offset,&point_found, &relay_range,&dummy2,&entry,&word_out,&actual_pol))) { return status; @@ -544,11 +541,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran int Set_frequency(int check_possible_only,int word_override,int range_override,int channel,float set_freq) { - int cap_range_control; /* what's actually sent to SR */ - int i; - int check_valid; float new_pw; - int status; int point_found,relay_range,UseNegData,entry,actual_pol,old_range; int word_out; /* what is sent to the DAC */ @@ -567,6 +560,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i } if (!check_possible_only) { + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -588,6 +582,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i relay_range=range_override; } else { /* set the amplitude controls now. */ + int status; if ((status=Set_VI_Control(pwl_period_values,channel,1.0/set_freq,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -620,9 +615,9 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i } else { - if (relay_range==0) { - cap_range_control=0; - } else { + int cap_range_control = 0; + + if (relay_range) { cap_range_control = 1 << (relay_range-1); } @@ -650,9 +645,6 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c int word_out; /* what is sent to the DAC */ int cap_range_control; /* what is actually sent to shift register */ float setting; - int i; - int check_valid; - int status; int point_found,relay_range,UseNegData,entry,actual_pol; /* abandon if high channel selected by user but not enabled by firmware */ @@ -661,6 +653,7 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c } if (!check_possible_only) { + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -699,6 +692,7 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c relay_range=range_override; } else { /* set the amplitude controls now. */ + int status; if ((status=Set_VI_Control(pwl_delay_values,channel,setting,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -984,8 +978,6 @@ int Set_Output_State(int channel,int mode) int Set_Trig_Source(int channel,int mode) { int gate_mode; - int i; - int error_num; int use_ab_mode; int reset_freq; float use_freq; @@ -1000,6 +992,7 @@ int Set_Trig_Source(int channel,int mode) reset_freq = 0; if (globals.ChannelState[channel].trigger_source!=mode) { + int i, error_num; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -1244,7 +1237,6 @@ int Set_Load(int channel, float value) int Set_EA(int channel,int mode) { - long amplify_mask, ea_mask; char set_DAC_to_zero; /* abandon if high channel selected by user but not enabled by firmware */ @@ -1287,6 +1279,7 @@ int Set_EA(int channel,int mode) if (globals.Flash.ea_enabled[channel]) { int ea_reg; + long ea_mask; if (!channel) { ea_mask = 0x10000; @@ -1305,7 +1298,7 @@ int Set_EA(int channel,int mode) if (globals.Flash.ext_amplify_enabled[channel]) { - amplify_mask = ((long) 1) << (globals.Flash.ext_amplify_xtra_rly[channel]+14); + long amplify_mask = ((long) 1) << (globals.Flash.ext_amplify_xtra_rly[channel]+14); if (mode==amp_mode_amplify) { globals.Registers.shift_reg_out[2] |= amplify_mask; @@ -3350,7 +3343,6 @@ int control_pcb107(int address, int dac, int word, int range) int Set_Burst_Count(int channel,int count,float new_burst_time) { int check_valid; - int hextext_out; if (globals.Flash.max_burst_count[channel]<=1) { return Unrecognized; @@ -3384,6 +3376,8 @@ int Set_Burst_Count(int channel,int count,float new_burst_time) /* Update pulse separation at the same time. This routine does the actual changes. */ Set_Burst_Time(0,0,0,channel,new_burst_time); } else { + int hextext_out; + /* reset all lines */ I2C_Write(PCF8574+Second_PW_Port,0); @@ -3417,10 +3411,8 @@ int Set_Burst_Count(int channel,int count,float new_burst_time) int Set_Burst_Time(int check_possible_only,int word_override,int range_override,int channel,float new_burst_time) { - int check_valid; int count_word_out; - int hextext_out; - int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out; if (globals.Flash.max_burst_count[channel]<=1) { return Unrecognized; @@ -3433,7 +3425,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, if (!check_possible_only) { /* check duty cycle */ - int i; + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -3451,6 +3443,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, word_out=word_override; relay_range=range_override; } else { + int status; if ((status=Set_VI_Control(pwl_burst_values,channel,new_burst_time,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -3477,7 +3470,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, I2C_Write(PCF8574+Second_PW_Port,0); /* send first hextet */ - hextext_out=count_word_out & 0x003f; + int hextext_out=count_word_out & 0x003f; I2C_Write(PCF8574+Second_PW_Port, hextext_out); /* load hextet */ @@ -3515,8 +3508,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, int Set_rise_time(int check_possible_only,int word_override,int range_override,int channel,float new_rise_time) { - int check_valid; - int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out; char range_control; if (globals.Flash.fixed_rise_time[channel]) { @@ -3530,7 +3522,7 @@ int Set_rise_time(int check_possible_only,int word_override,int range_override,i if (!check_possible_only) { /* check duty cycle */ - int i; + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -3545,6 +3537,7 @@ int Set_rise_time(int check_possible_only,int word_override,int range_override,i word_out=word_override; relay_range=range_override; } else { + int status; if ((status=Set_VI_Control(pwl_rise_time_values,channel,new_rise_time,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -3651,7 +3644,6 @@ int Set_rise_time(int check_possible_only,int word_override,int range_override,i int Set_current_limit(int check_possible_only,int channel,float new_adj_current_limit) { - int check_valid; float limit; int word_out; @@ -3665,7 +3657,7 @@ int Set_current_limit(int check_possible_only,int channel,float new_adj_current_ } if (!check_possible_only) { - int i; + int i, check_valid; for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -3701,10 +3693,7 @@ int Set_current_limit(int check_possible_only,int channel,float new_adj_current_ int Set_avrq_res(int check_possible_only,int word_override,int range_override,int channel,float new_res) { - int check_valid; - int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out; - - float compensated_new_res; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out; if (!globals.Flash.switchable_load[channel]) { return Unrecognized; @@ -3716,7 +3705,8 @@ int Set_avrq_res(int check_possible_only,int word_override,int range_override,in } if (!check_possible_only) { - int i; + int i, check_valid; + for (i=0; i<max_channels; ++i) { TestState[i]=globals.ChannelState[i]; } @@ -3735,12 +3725,15 @@ int Set_avrq_res(int check_possible_only,int word_override,int range_override,in CH2 = opto VCC Calibrate res at 3.0V Compensate for >3.0V */ + float compensated_new_res; + if (globals.ChannelState[0].vcc2 > 0.0) { compensated_new_res = new_res * 3.0/globals.ChannelState[0].vcc2; } else { return amplitude_lower_limit; } + int status; if ((status=Set_VI_Control(pwl_load_type_values,channel,compensated_new_res,&point_found, &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; @@ -3268,7 +3268,6 @@ static int Go_routeclose_78(gchar** response, int channel, char *parameter,char static int Parse_chan_list(int channel,char *parameter,int *primary_selected, int *secondary_selected,gchar** response) { - // FIXME - update with g_str functions int i; int n; int pointer; @@ -3564,7 +3563,6 @@ static int Go_amp_pnt_83(gchar** response, int channel, char *parameter,char *un int Handle_Curr_Slew_Unit(float *new_val,char *units); int Handle_Curr_Slew_Unit(float *new_val,char *units) { - // FIXME - update with g_str functions char *slash; float tmp1, tmp2; |