summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-24 14:04:56 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-24 14:04:56 -0400
commitb3c38cf2f99e387359653fc9f9530239c38c381d (patch)
tree781cd5ea77c24a7344bfa4d1d68151c61223143b
parent37715d8b1b2a6465f1bb8232df8ae9c73efc743b (diff)
fix writeUserBlock usage, and fix non-obvious rcl values
-rw-r--r--device-functions.c27
-rw-r--r--flash.c57
-rw-r--r--flash.h1
-rw-r--r--globals.c4
-rw-r--r--instr-daemon.c16
-rw-r--r--parser.c36
6 files changed, 98 insertions, 43 deletions
diff --git a/device-functions.c b/device-functions.c
index f2d7aec..db36caf 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -6,6 +6,7 @@
#include "i2c.h"
#include "bus.h"
#include "lcd.h"
+#include "flash.h"
#include <math.h>
#include <glib.h>
@@ -1502,7 +1503,7 @@ int Set_Amp_Calib(int channel,float meas_ampl)
}
eprom_loc = (char *) &(globals.Flash.ampl_pwl_amp) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.ampl_pwl_amp));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.ampl_pwl_amp));
return status;
}
@@ -1538,7 +1539,7 @@ int Set_Mon_Calib(int channel,float meas_ampl)
globals.Flash.mon_vi_ratio[channel][relay_range][UseNegData]=globals.Flash.mon_vi_ratio[channel][relay_range][UseNegData]/change_ratio;
eprom_loc = (char *) &(globals.Flash.mon_vi_ratio) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.mon_vi_ratio));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.mon_vi_ratio));
return OK;
}
@@ -1607,7 +1608,7 @@ int Set_OS_Calib(int channel,float meas_ampl)
}
eprom_loc = (char *) &(globals.Flash.os_pwl_amp) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.os_pwl_amp));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.os_pwl_amp));
return status;
}
@@ -1647,7 +1648,7 @@ int Set_PW_shift(int channel,float new_shift)
}
eprom_loc = (char *) &(globals.Flash.pulse_width_pol_tweak[channel][UseNegData]) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.pulse_width_pol_tweak[channel][UseNegData]));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.pulse_width_pol_tweak[channel][UseNegData]));
return Set_Pw(0,0,0,channel,globals.ChannelState[channel].pw,0);
}
@@ -1822,10 +1823,10 @@ int Set_Dly_Shr_Cal(int channel,int calibration_point_number,float cal_point)
globals.Flash.delay_shrink[channel]=( (150e-9)-delay1+delay2)/2;
eprom_loc = (char *) &(globals.Flash.propagation_delay) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.propagation_delay));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.propagation_delay));
eprom_loc = (char *) &(globals.Flash.delay_shrink) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.delay_shrink));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.delay_shrink));
return OK;
}
@@ -2235,7 +2236,7 @@ int Set_VI_Cal_Pnt(int parameter,int channel,int calibration_point_number,float
Menu_Update_Display();
eprom_loc = (char *) (&pwl_amp[index]) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(nom_ampl));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(nom_ampl));
globals.Flags.extended_ampl_min_max=NO;
return status;
@@ -2398,10 +2399,10 @@ int Set_VI_Del_Cal(int parameter,int channel,int calibration_point_number)
Menu_Update_Display();
eprom_loc = (char *) pointer_short1 - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,size_of_short1);
+ writeUserBlock(&globals.Flash, eprom_loc, size_of_short1);
eprom_loc = (char *) pointer_float1 - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,size_of_float1);
+ writeUserBlock(&globals.Flash, eprom_loc, size_of_float1);
return status;
}
@@ -3063,10 +3064,10 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point)
}
eprom_loc = (char *) pointer_x_short - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,size_of_x_short);
+ writeUserBlock(&globals.Flash, eprom_loc, size_of_x_short);
eprom_loc = (char *) pointer_y_float - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,size_of_y_float);
+ writeUserBlock(&globals.Flash, eprom_loc, size_of_y_float);
globals.Flags.extended_ampl_min_max=NO;
@@ -4192,9 +4193,9 @@ int do_full_self_cal(CalStruct *caldata)
strcat (caldata->response, string);
eprom_loc = (char *) &(globals.Flash.self_cal_typical_time_min) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.self_cal_typical_time_min));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.self_cal_typical_time_min));
eprom_loc = (char *) &(globals.Flash.self_cal_typical_time_sec) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.self_cal_typical_time_sec));
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.self_cal_typical_time_sec));
if (caldata->total_errors) {
return SelfCalError;
diff --git a/flash.c b/flash.c
index 89c9c65..f670fa3 100644
--- a/flash.c
+++ b/flash.c
@@ -762,9 +762,9 @@ void initFlash(FlashStruct *mem, gboolean reset_to_defaults, int starting_locati
if ( (read_size == 0) ||
(mem->fully_programmed == Not_Programmed) ||
- (reset_to_defaults &&
- (starting_location >= 0) &&
- (starting_location < sizeof(*mem))) ) {
+ (reset_to_defaults &&
+ (starting_location >= 0) &&
+ (starting_location < sizeof(*mem))) ) {
g_print_debug ("initializing flash memory\n");
LCD_write(0,0,"Initialize Flash Memory ...");
@@ -787,3 +787,54 @@ void initFlash(FlashStruct *mem, gboolean reset_to_defaults, int starting_locati
}
}
+
+void fixFlash(FlashStruct *mem)
+{
+ int i, fix_initial_constants;
+ float composite_min_burst_time[max_channels];
+
+ for (i=0; i<max_channels; i++) {
+
+ composite_min_burst_time[i]=mem->min_burst_gap[i];
+ if ((mem->min_burst_per[i] - mem->min_pw[i]) > composite_min_burst_time[i]) {
+ composite_min_burst_time[i] = mem->min_burst_per[i] - mem->min_pw[i];
+ }
+
+ int j;
+ for (j=0; j<max_stored_settings; j++) {
+ if (mem->rcl_burst_time[i][j] < composite_min_burst_time[i]) {
+ mem->rcl_burst_time[i][j]=composite_min_burst_time[i];
+ ++fix_initial_constants;
+ }
+ if (mem->rcl_rise_time[i][j] < mem->min_rise_time[i]) {
+ mem->rcl_rise_time[i][j]=mem->min_rise_time[i];
+ ++fix_initial_constants;
+ }
+ if (mem->rcl_slew[i][j] < mem->min_slew[i]) {
+ mem->rcl_slew[i][j]=mem->min_slew[i];
+ ++fix_initial_constants;
+ }
+ if (mem->rcl_soft_current_limit[i][j] < mem->min_soft_current_limit[i]) {
+ mem->rcl_soft_current_limit[i][j]=mem->max_soft_current_limit[i];
+ ++fix_initial_constants;
+ }
+ }
+ }
+
+ if (fix_initial_constants) {
+ int eprom_loc;
+
+ eprom_loc = (char *) &(mem->rcl_burst_time) - (char *) &(mem->flash_start);
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(mem->rcl_burst_time));
+
+ eprom_loc = (char *) &(mem->rcl_rise_time) - (char *) &(mem->flash_start);
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(mem->rcl_rise_time));
+
+ eprom_loc = (char *) &(mem->rcl_slew) - (char *) &(mem->flash_start);
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(mem->rcl_slew));
+
+ eprom_loc = (char *) &(mem->rcl_soft_current_limit) - (char *) &(mem->flash_start);
+ writeUserBlock(&globals.Flash, eprom_loc, sizeof(mem->rcl_soft_current_limit));
+ }
+
+}
diff --git a/flash.h b/flash.h
index d4658ee..739fefa 100644
--- a/flash.h
+++ b/flash.h
@@ -7,6 +7,7 @@
void initFlash(FlashStruct *mem, gboolean reset_to_defaults, int starting_location);
int readUserBlock(FlashStruct *mem);
void writeUserBlock(FlashStruct *mem, int addr, int numbytes);
+void fixFlash(FlashStruct *mem);
#endif
diff --git a/globals.c b/globals.c
index 88bf547..c0be662 100644
--- a/globals.c
+++ b/globals.c
@@ -9,8 +9,8 @@ GlobalStruct globals = {
.Registers.last_rise_time_relay_setting = 99,
.Registers.last_relay_driver_settings[0] = -1,
- .Registers.last_relay_driver_settings[1] = -1,
- .Registers.last_relay_driver_settings[2] = -1
+ .Registers.last_relay_driver_settings[1] = -1,
+ .Registers.last_relay_driver_settings[2] = -1
};
diff --git a/instr-daemon.c b/instr-daemon.c
index b8a24c7..ec4e27e 100644
--- a/instr-daemon.c
+++ b/instr-daemon.c
@@ -237,17 +237,19 @@ int main(int argc, char **argv)
initFlash (&globals.Flash, FALSE, 0);
- // count startups
- if (globals.Flash.self_cal) {
- ++globals.Flash.self_cal_startups;
- int eprom_loc = (char *) &(globals.Flash.self_cal_startups) - (char *) &(globals.Flash.flash_start);
- writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.self_cal_startups));
- }
-
gchar *message = g_strdup_printf ("%s, S/N %s", globals.Flash.model_num, globals.Flash.serial_num);
LCD_display_extended_message (message, 0);
g_free (message);
+ fixFlash(&globals.Flash);
+
+ // count startups
+ if (globals.Flash.self_cal) {
+ ++globals.Flash.self_cal_startups;
+ int eprom_loc = (char *) &(globals.Flash.self_cal_startups) - (char *) &(globals.Flash.flash_start);
+ writeUserBlock(eprom_loc,&globals.Flash.flash_start + eprom_loc,sizeof(globals.Flash.self_cal_startups));
+ }
+
nicinfo info;
strcpy(info.ip,"-");
nicutils_infofordefaultroute(&info);
diff --git a/parser.c b/parser.c
index be84e8f..4b64ab3 100644
--- a/parser.c
+++ b/parser.c
@@ -347,8 +347,8 @@ static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
id_code = 106;
} else if (!strcmp(id_me,"all") ) {
id_code = 107;
- } else if (!strcmp(id_me,"reset") || !strcmp(id_me,"res")) {
- id_code = 108;
+ } else if (!strcmp(id_me,"reset") || !strcmp(id_me,"res")) {
+ id_code = 108;
} else {
id_code = 9999;
}
@@ -1047,9 +1047,9 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
case 101:
error_num=Go_cal_interval_101(&response,channel,parameter,units,command_type);
break;
- case 102:
- error_num=Go_eprom_reset_102(&response,channel,parameter,units,command_type);
- break;
+ case 102:
+ error_num=Go_eprom_reset_102(&response,channel,parameter,units,command_type);
+ break;
case 9999:
// was only whitespace, ignore
@@ -3724,24 +3724,24 @@ static int Go_eprom_reset_102(gchar** response, int channel, char *parameter,cha
{
int status, value;
- if (channel) {
- return InvalidChannel;
- }
+ if (channel) {
+ return InvalidChannel;
+ }
- switch (command_type) {
- case command_withparam:
+ switch (command_type) {
+ case command_withparam:
if (status = process_int_range (parameter, &value, 0, sizeof(globals.Flash)-1)) {
- return status;
- }
+ return status;
+ }
initFlash(&globals.Flash, TRUE, value);
Main_Rst();
- return OK;
- break;
+ return OK;
+ break;
- default:
- return SyntaxError;
- break;
- }
+ default:
+ return SyntaxError;
+ break;
+ }
}