summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2013-04-02 13:54:32 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2013-04-02 13:54:32 -0400
commit9b89d35a4afa2df4aea39a06381ed0dc3e075e27 (patch)
treee23f511f479d2082c39c0037c4af450e5a6ee291
parente05074567a9c883e9086e4cf39addd7de2414fb3 (diff)
switch to set_shiftreg_bits for better readability
-rw-r--r--device-functions.c184
1 files changed, 121 insertions, 63 deletions
diff --git a/device-functions.c b/device-functions.c
index da920d7..7dd2500 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -17,7 +17,48 @@
static void start_gate_override ();
static void stop_gate_override ();
-
+static void set_shiftreg_bits(int shiftreg, int start_at_bit, int numbits, int value);
+
+
+#define ONE_BIT 1
+#define TWO_BITS 2
+#define THREE_BITS 3
+#define FOUR_BITS 4
+#define FIVE_BITS 5
+#define SIX_BITS 6
+#define SEVEN_BITS 7
+#define EIGHT_BITS 8
+
+#define SR_0 0
+#define SR_1 1
+#define SR_2 2
+#define SR_3 3
+
+#define POS_0 0
+#define POS_1 1
+#define POS_2 2
+#define POS_3 3
+#define POS_4 4
+#define POS_5 5
+#define POS_6 6
+#define POS_7 7
+#define POS_8 8
+#define POS_9 9
+#define POS_10 10
+#define POS_11 11
+#define POS_12 12
+#define POS_13 13
+#define POS_14 14
+#define POS_15 15
+#define POS_16 16
+#define POS_17 17
+#define POS_18 18
+#define POS_19 19
+
+#define XTR_POS 14
+
+#define BIT_HIGH 1
+#define BIT_LOW 0
void idn_string(gchar** response)
{
@@ -264,35 +305,35 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w
if (!globals.Flash.ampl_ranges_for_ch2_only) {
if ((globals.Flash.ChanKey_amplitude?globals.Flash.channels:1)<=1) {
/* for regular, single-channel units use AMPL RANGE pins 0-4 */
- globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xff07f)) | ((long)(1<<(relay_range+7)));
+ set_shiftreg_bits(SR_3, POS_7, FIVE_BITS, 1<<relay_range);
} else {
/* for CH1 of dual-channel units, use AMPL RANGE pin 0-2 for CH1, and 3-4 for CH2 */
- globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xffc7f)) | ((long)(1<<(relay_range+7)));
+ set_shiftreg_bits(SR_3, POS_7, THREE_BITS, 1<<relay_range);
}
}
if ( (!actual_pol && globals.Flash.pol_relay_high_for_pos[channel])
|| (actual_pol && !globals.Flash.pol_relay_high_for_pos[channel]) ) {
- globals.Registers.shift_reg_out[3] |= (long)(0x02000); /* set O.POL line high to switch pol relay to +, normally */
+ set_shiftreg_bits(SR_3, POS_13, ONE_BIT, BIT_HIGH); /* set O.POL line high to switch pol relay to +, normally */
} else {
- globals.Registers.shift_reg_out[3] &= (long)(0xfffff-0x02000); /* set O.POL line low to switch pol relay to -, normally */
+ set_shiftreg_bits(SR_3, POS_13, ONE_BIT, BIT_LOW); /* set O.POL line low to switch pol relay to -, normally */
}
} else {
if (!globals.Flash.ampl_ranges_for_ch2_only) {
/* for CH2 of dual-channel units, use AMPL RANGE pin 2-3 */
- globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xff3ff)) | ((long)(1<<(relay_range+10)));
+ set_shiftreg_bits(SR_3, POS_10, TWO_BITS, 1<<relay_range);
} else {
/* sometimes CH2 can use pins 0-4 */
- globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xff07f)) | ((long)(1<<(relay_range+7)));
+ set_shiftreg_bits(SR_3, POS_7, FIVE_BITS, 1<<relay_range);
}
- long mask = ((long) 1) << (globals.Flash.polarity_xtra_rly[channel]+14);
+ int pol_bit = globals.Flash.polarity_xtra_rly[channel] + XTR_POS;
if (new_ampl<0.0) {
- globals.Registers.shift_reg_out[2] &= (long)(0xfffff-mask); /* set O.POL line low to switch pol relay to - */
+ set_shiftreg_bits(SR_2, pol_bit, ONE_BIT, BIT_LOW); /* set O.POL line low to switch pol relay to - */
} else {
- globals.Registers.shift_reg_out[2] |= mask; /* set O.POL line high to switch pol relay to + */
+ set_shiftreg_bits(SR_2, pol_bit, ONE_BIT, BIT_HIGH); /* set O.POL line high to switch pol relay to + */
}
}
@@ -387,9 +428,9 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
if (channel==0) {
if (globals.Flash.special_pw_range_minimum[channel] > 0.0) {
if (set_pw > globals.Flash.special_pw_range_minimum[channel]) {
- globals.Registers.shift_reg_out[2] = ((long) (globals.Registers.shift_reg_out[2] & 0xeffff)) | (long) 1<<16;
+ set_shiftreg_bits(SR_2, XTR_POS + 1, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[2] = ((long) (globals.Registers.shift_reg_out[2] & 0xeffff));
+ set_shiftreg_bits(SR_2, XTR_POS + 1, ONE_BIT, BIT_LOW);
}
}
@@ -397,7 +438,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
if (globals.Flash.volt_ctrl_pw[channel]) {
// reset PG B line (see below)
- globals.Registers.shift_reg_out[2] &= (long)0x7ffff;
+ set_shiftreg_bits(SR_2, XTR_POS + 5, ONE_BIT, BIT_LOW);
/* use DAC8420 to control PW in lowest PW range */
if (!relay_range) {
@@ -419,7 +460,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
cap_range_control=0;
// set XTRA RLY 5 high in this range for AVR-E3-B-R5-N-M5, and other
// units with PG A, B, and C. This corresponds to PG B.
- globals.Registers.shift_reg_out[2] |= (long)0x80000;
+ set_shiftreg_bits(SR_2, XTR_POS + 5, ONE_BIT, BIT_HIGH);
} else {
cap_range_control = 1 << (relay_range-2);
}
@@ -430,7 +471,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
set_dac(4,word_out);
/* set ranges */
- globals.Registers.shift_reg_out[3] = ((long)(globals.Registers.shift_reg_out[3] & 0xfff80)) | ((long)(cap_range_control));
+ set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
}
if (channel==1) {
@@ -443,7 +484,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
set_dac(globals.Flash.pw_dac[channel],word_out);
/* two ranges controlled by XTRA-RLY2 line */
- globals.Registers.shift_reg_out[2] = ((long) (globals.Registers.shift_reg_out[2] & 0xeffff)) | (long) (((long) (relay_range&1))<<16);
+ set_shiftreg_bits(SR_2, XTR_POS + 2, ONE_BIT, relay_range);
}
}
@@ -619,7 +660,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i
relay_range=0;
}
- globals.Registers.shift_reg_out[2] = ((long) (globals.Registers.shift_reg_out[2] & 0xc7fff)) | (long) (((long) (relay_range & 0x07))<<15);
+ set_shiftreg_bits(SR_2, XTR_POS + 1, THREE_BITS, relay_range);
if ((relay_range!=old_range) && (globals.ChannelState[channel].output_state==output_on)) {
globals.Flags.force_output_fully_off=YES;
@@ -634,7 +675,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i
}
set_dac(globals.Flash.freq_dac[channel],word_out);
- globals.Registers.shift_reg_out[2] = ((long)(globals.Registers.shift_reg_out[2] & 0xfff00)) | ((long)cap_range_control); /* bottom 8 bits of 20 bits */
+ set_shiftreg_bits(SR_2, POS_0, SEVEN_BITS, cap_range_control);
}
g_print_debug("freq range %d, word %d\n",relay_range,word_out);
@@ -724,7 +765,7 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c
if (channel==0) {
set_dac(globals.Flash.delay_dac[channel],word_out);
- globals.Registers.shift_reg_out[2] = ((long)(globals.Registers.shift_reg_out[2] & 0xf80ff)) | ((long)cap_range_control<<8);
+ set_shiftreg_bits(SR_2, POS_8, SEVEN_BITS, cap_range_control);
}
if (channel==1) {
@@ -757,11 +798,11 @@ int Set_Double(int channel,int new_setting)
}
if (new_setting == double_off) {
- globals.Registers.shift_reg_out[0] &= 0xdf; // turn double-pulse off
+ set_shiftreg_bits(SR_0, POS_5, ONE_BIT, BIT_LOW); // turn double-pulse off
Ctrl_PRF_Limiter (1); // normal prf limiting
} else {
- globals.Registers.shift_reg_out[0] |= 0x20; // turn double-pulse on
- Ctrl_PRF_Limiter (0); // disable prf limiter
+ set_shiftreg_bits(SR_0, POS_5, ONE_BIT, BIT_HIGH); // turn double-pulse on
+ Ctrl_PRF_Limiter (0); // disable prf limiter
}
globals.ChannelState[channel].double_pulse=new_setting;
@@ -774,9 +815,9 @@ int Set_Double(int channel,int new_setting)
void Ctrl_PRF_Limiter(int enable)
{
if (enable && globals.Flash.prf_limiter) {
- globals.Registers.shift_reg_out[0] |= 0x80; /* turn prf limiter on */
+ set_shiftreg_bits(SR_0, POS_7, ONE_BIT, BIT_HIGH); /* turn prf limiter on */
} else {
- globals.Registers.shift_reg_out[0] &= 0x7f; /* turn prf limiter off */
+ set_shiftreg_bits(SR_0, POS_7, ONE_BIT, BIT_LOW); /* turn prf limiter off */
}
Main_update_shift_registers();
@@ -807,7 +848,7 @@ void Set_Mux(int channel)
mux_out=6;
}
- globals.Registers.shift_reg_out[1] = (globals.Registers.shift_reg_out[1] & 0xf8) + mux_out;
+ set_shiftreg_bits(SR_1, POS_0, THREE_BITS, mux_out);
}
@@ -841,13 +882,16 @@ int Set_Func(int channel,int mode)
if (globals.Flash.is_func_gen[channel]) {
/* set sin, tri, squ lines */
- globals.Registers.shift_reg_out[3] = ((long) (globals.Registers.shift_reg_out[3] & 0x1ffff))
- | (long) (((long) (mode & 0x07))<<17);
+ set_shiftreg_bits(SR_3, POS_17, THREE_BITS, mode);
/* set amplify mode line */
-
- globals.Registers.shift_reg_out[2] = ((long) (globals.Registers.shift_reg_out[2] & 0xbffff))
- | (long) (((long) (mode & 0x08)) << (globals.Flash.ext_amplify_xtra_rly[channel]+11));
+
+ int amplify_bit = XTR_POS + globals.Flash.ext_amplify_xtra_rly[channel];
+ if (mode==amp_mode_on) {
+ set_shiftreg_bits(SR_2, amplify_bit, ONE_BIT, BIT_HIGH);
+ } else {
+ set_shiftreg_bits(SR_2, amplify_bit, ONE_BIT, BIT_LOW);
+ }
}
@@ -1021,19 +1065,19 @@ int Set_Trig_Source(int channel,int mode)
if (mode==source_internal) {
/* frequency is automatically lowered if pw or delay have been changed to conflicting */
/* settings while in a non-internal mode */
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xe3) | 0;
+ set_shiftreg_bits(SR_0, POS_2, THREE_BITS, 0x0);
} else if (mode==source_external) {
globals.ChannelState[channel].hold_setting=hold_width;
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xe3) | 3<<2;
+ set_shiftreg_bits(SR_0, POS_2, THREE_BITS, 0x3);
} else if (mode==source_manual) {
globals.ChannelState[channel].hold_setting=hold_width;
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xe3) | 1<<2;
+ set_shiftreg_bits(SR_0, POS_2, THREE_BITS, 0x1);
} else if (mode==source_hold) {
gate_mode=1;
} else if (mode==source_immediate) {
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xe3) | 4<<2;
+ set_shiftreg_bits(SR_0, POS_2, THREE_BITS, 0x4);
Main_update_shift_registers();
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xe3) | 7<<2;
+ set_shiftreg_bits(SR_0, POS_2, THREE_BITS, 0x7);
}
Main_update_shift_registers();
@@ -1051,9 +1095,9 @@ int Set_Gate_Sync(int channel,int mode)
}
if (mode==gate_sync) {
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xfe) | 0;
+ set_shiftreg_bits(SR_0, POS_0, ONE_BIT, BIT_LOW);
} else {
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xfe) | 1;
+ set_shiftreg_bits(SR_0, POS_0, ONE_BIT, BIT_HIGH);
}
globals.ChannelState[channel].gate_type=mode;
@@ -1071,9 +1115,9 @@ int Set_Gate_Level(int channel,int mode)
}
if (mode==0) {
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xfd) | 0x02;
+ set_shiftreg_bits(SR_0, POS_1, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[0] = (globals.Registers.shift_reg_out[0] & 0xfd) | 0;
+ set_shiftreg_bits(SR_0, POS_1, ONE_BIT, BIT_LOW);
}
globals.ChannelState[channel].gate_level=mode;
@@ -1122,18 +1166,18 @@ int Set_zout(int channel,int setting,int really_for_zout)
/* first channel uses dedicated Zout line */
if (channel==0) {
if (setting!=globals.Flash.zout_max[channel]) {
- globals.Registers.shift_reg_out[3] |= (long)0x01000; /* power zout relay */
+ set_shiftreg_bits(SR_3, POS_12, ONE_BIT, BIT_HIGH); /* power zout relay */
} else {
- globals.Registers.shift_reg_out[3] &= (long)0xfefff; /* de-power zout relay */
+ set_shiftreg_bits(SR_3, POS_12, ONE_BIT, BIT_LOW); /* de-power zout relay */
}
}
/* second channel uses dedicated xtra-rly2 line */
if (channel==1) {
if (setting!=globals.Flash.zout_max[channel]) {
- globals.Registers.shift_reg_out[2] |= (long)0x10000; /* power zout relay */
+ set_shiftreg_bits(SR_2, XTR_POS + 2, ONE_BIT, BIT_HIGH); /* power zout relay */
} else {
- globals.Registers.shift_reg_out[2] &= (long)0xeffff; /* de-power zout relay */
+ set_shiftreg_bits(SR_2, XTR_POS + 2, ONE_BIT, BIT_LOW); /* de-power zout relay */
}
}
@@ -1248,32 +1292,31 @@ int Set_EA(int channel,int mode)
if (globals.Flash.ea_enabled[channel]) {
- int ea_reg;
- long ea_mask;
+ int ea_reg, ea_bit;
if (!channel) {
- ea_mask = 0x10000;
+ ea_bit = 16;
ea_reg = 3;
} else {
- ea_mask = ((long) 1) << (globals.Flash.ea_xtra_rly[channel]+14);
+ ea_bit = globals.Flash.ea_xtra_rly[channel] + XTR_POS;
ea_reg = 2;
}
if (mode==amp_mode_ea) {
- globals.Registers.shift_reg_out[ea_reg] |= ea_mask;
+ set_shiftreg_bits(ea_reg, ea_bit, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[ea_reg] &= ((long)(0xfffff - ea_mask));
+ set_shiftreg_bits(ea_reg, ea_bit, ONE_BIT, BIT_LOW);
}
}
if (globals.Flash.ext_amplify_enabled[channel]) {
- long amplify_mask = ((long) 1) << (globals.Flash.ext_amplify_xtra_rly[channel]+14);
+ int amplify_bit = XTR_POS + globals.Flash.ext_amplify_xtra_rly[channel];
if (mode==amp_mode_amplify) {
- globals.Registers.shift_reg_out[2] |= amplify_mask;
+ set_shiftreg_bits(SR_2, amplify_bit, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[2] &= ((long)(0xfffff - amplify_mask));
+ set_shiftreg_bits(SR_2, amplify_bit, ONE_BIT, BIT_LOW);
}
}
@@ -1292,9 +1335,9 @@ int Set_EA(int channel,int mode)
int Set_AdvDel(int channel,int setting)
{
if (setting==to_Advance) {
- globals.Registers.shift_reg_out[0] |= 64L; /* turn advance on */
+ set_shiftreg_bits(SR_0, POS_6, ONE_BIT, BIT_HIGH); /* turn advance on */
} else {
- globals.Registers.shift_reg_out[0] &= 255L-64L; /* turn delay on */
+ set_shiftreg_bits(SR_0, POS_6, ONE_BIT, BIT_LOW); /* turn delay on */
}
Set_Update_Chans();
@@ -1511,21 +1554,20 @@ int Set_Mon_Calib(int channel,float meas_ampl)
int Set_Logic_Level(int channel,int mode)
{
- /* first channel uses dedicated Zout line */
if (channel==0) {
if (mode==logic_ecl) {
- globals.Registers.shift_reg_out[3] |= (long)0x04000; /* power zout relay */
+ set_shiftreg_bits(SR_3, POS_14, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[3] &= (long)0xfbfff; /* de-power zout relay */
+ set_shiftreg_bits(SR_3, POS_14, ONE_BIT, BIT_LOW);
}
}
/* second channel uses xtra-rly3 */
if (channel==1) {
if (mode==logic_ecl) {
- globals.Registers.shift_reg_out[2] |= (long)0x20000; /* power zout relay */
+ set_shiftreg_bits(SR_3, XTR_POS + 3, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[2] &= (long)0xdffff; /* de-power zout relay */
+ set_shiftreg_bits(SR_3, XTR_POS + 3, ONE_BIT, BIT_LOW);
}
}
@@ -1667,9 +1709,9 @@ int Set_Route(int channel, int module, int mode)
} else {
/* AVD-D2-B */
if (mode==2) {
- globals.Registers.shift_reg_out[2] |= (long)0x08000; /* power zout relay */
+ set_shiftreg_bits(SR_2, XTR_POS + 1, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[2] &= (long)0xf7fff; /* de-power zout relay */
+ set_shiftreg_bits(SR_2, XTR_POS + 1, ONE_BIT, BIT_LOW);
}
globals.ChannelState[channel].route_primary=mode;
}
@@ -1696,9 +1738,9 @@ int Set_EO(int channel,int mode)
}
if (mode) {
- globals.Registers.shift_reg_out[2] |= (long)0x40000;
+ set_shiftreg_bits(SR_2, XTR_POS + 4, ONE_BIT, BIT_HIGH);
} else {
- globals.Registers.shift_reg_out[2] &= ((long)(0xfffff - 0x40000));
+ set_shiftreg_bits(SR_2, XTR_POS + 4, ONE_BIT, BIT_LOW);
}
if (globals.ChannelState[channel].os_mode!=mode) {
@@ -4730,3 +4772,19 @@ int change_password(gchar *old_password, gchar *new_password)
return password_change_error;
}
}
+
+
+static void set_shiftreg_bits(int shiftreg, int start_at_bit, int numbits, int value)
+{
+ long used_bits = (1<<numbits) - 1;
+ long mask = 0xfffff - (used_bits << start_at_bit);
+
+ long shift_value = (value & used_bits) << start_at_bit;
+ long masked_reg = globals.Registers.shift_reg_out[shiftreg] & mask;
+
+ printf ("shiftreg %d, start_at_bit %d, numbits %d, value %x\n",shiftreg,start_at_bit,numbits,value);
+ printf (" in %lx\n", globals.Registers.shift_reg_out[shiftreg]);
+ globals.Registers.shift_reg_out[shiftreg] = masked_reg | shift_value;
+ printf ("out %lx\n", globals.Registers.shift_reg_out[shiftreg]);
+}
+