Skip to content

Commit cd31d3b

Browse files
committed
Partial cleanup to reduce ADC overhead
1 parent e975816 commit cd31d3b

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

hw/arm/prusa/parts/heater.c

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static void heater_reset(DeviceState *dev)
185185
s->thermalMass = ((float)s->mass10x)/10.f;
186186
s->ambientTemp = 18.f;
187187
s->currentTemp = s->ambientTemp;
188+
qemu_set_irq(s->temp_out, s->currentTemp*256.f);
188189
}
189190

190191
static int heater_process_action(P404ScriptIF *obj, unsigned int action, script_args args) {

hw/arm/prusa/parts/thermistor.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ static int map(long x, long in_min, long in_max, long out_min, long out_max) {
6969
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
7070
}
7171

72-
static void thermistor_read_request(void *opaque, int n, int level) {
73-
if (!level) {
74-
return;
75-
}
76-
ThermistorState *s = opaque;
72+
static void thermistor_update_output(ThermistorState *s) {
7773
float value = s->use_custom ? s->custom_temp : s->temperature;
7874
qemu_set_irq(s->temp_out, 256U*value);
7975
if (s->table_index==0) {
@@ -122,7 +118,7 @@ static void thermistor_temp_in(void *opaque, int n, int level)
122118
ThermistorState *s = opaque;
123119
float fv = (float)(level) / 256.f;
124120
s->temperature = fv;
125-
qemu_set_irq(s->temp_out, level);
121+
thermistor_update_output(s);
126122
}
127123

128124
static int thermistor_process_action(P404ScriptIF *obj, unsigned int action, script_args args)
@@ -152,6 +148,7 @@ static int thermistor_process_action(P404ScriptIF *obj, unsigned int action, scr
152148
return ScriptLS_Unhandled;
153149

154150
}
151+
thermistor_update_output(s);
155152
return ScriptLS_Finished;
156153
}
157154

@@ -206,14 +203,14 @@ static void thermistor_set_table(ThermistorState *s) {
206203
s->table_length = 0;
207204
break;
208205
}
206+
thermistor_update_output(s);
209207
}
210208

211209
static void thermistor_reset(DeviceState *dev)
212210
{
213211
ThermistorState *s = THERMISTOR(dev);
214212
s->temperature = s->start_temp;
215213
thermistor_set_table(s);
216-
qemu_set_irq(s->temp_out, 256U*s->temperature);
217214
}
218215

219216
OBJECT_DEFINE_TYPE_SIMPLE_WITH_INTERFACES(ThermistorState, thermistor, THERMISTOR, SYS_BUS_DEVICE, {TYPE_P404_SCRIPTABLE}, {NULL});
@@ -232,7 +229,7 @@ static void thermistor_init(Object *obj)
232229

233230
qdev_init_gpio_out_named(DEVICE(obj), &s->temp_out, "temp_out_256x", 1);
234231

235-
qdev_init_gpio_in_named(DEVICE(obj),thermistor_read_request, "thermistor_read_request", 1);
232+
// qdev_init_gpio_in_named(DEVICE(obj),thermistor_read_request, "thermistor_read_request", 1);
236233
qdev_init_gpio_in_named(DEVICE(obj),thermistor_temp_in, "thermistor_set_temperature", 1);
237234

238235
s->oversampling = OVERSAMPLENR;

hw/arm/prusa/prusa-mk4.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static void mk4_init(MachineState *machine)
581581
qdev_prop_set_uint16(dev, "temp",cfg.temps.ambient[i]);
582582
qdev_prop_set_uint16(dev, "table_no", cfg.temps.table[i]);
583583
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
584-
qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, cfg.temps.adc[i]),"adc_read", cfg.temps.channel[i], qdev_get_gpio_in_named(dev, "thermistor_read_request",0));
584+
//qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, cfg.temps.adc[i]),"adc_read", cfg.temps.channel[i], qdev_get_gpio_in_named(dev, "thermistor_read_request",0));
585585
qdev_connect_gpio_out_named(dev, "thermistor_value",0, qdev_get_gpio_in_named(stm32_soc_get_periph(dev_soc, cfg.temps.adc[i]),"adc_data_in",cfg.temps.channel[i]));
586586
if (i==T_NOZ)
587587
{
@@ -689,7 +689,7 @@ static void mk4_init(MachineState *machine)
689689
DeviceState* vdev = qdev_new("powersource");
690690
qdev_prop_set_uint32(vdev,"mV",23900);
691691
sysbus_realize(SYS_BUS_DEVICE(vdev),&error_fatal);
692-
qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_read", 3, qdev_get_gpio_in_named(vdev, "adc_read_request",0));
692+
// qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_read", 3, qdev_get_gpio_in_named(vdev, "adc_read_request",0));
693693
qdev_connect_gpio_out_named(vdev, "v_sense",0,qdev_get_gpio_in_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_data_in",3));
694694
qdev_connect_gpio_out_named(vdev, "panic",0, qdev_get_gpio_in(stm32_soc_get_periph(dev_soc, STM32_P_GPIOG), 0));
695695

@@ -704,15 +704,15 @@ static void mk4_init(MachineState *machine)
704704
qdev_prop_set_uint32(vdev,"mA",currents[i]);
705705
sysbus_realize(SYS_BUS_DEVICE(vdev),&error_fatal);
706706
qdev_connect_gpio_out_named(vdev, "a_sense",0,qdev_get_gpio_in_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC3),"adc_data_in",channels[i]));
707-
qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC3),"adc_read", channels[i], qdev_get_gpio_in_named(vdev, "adc_read_request",0));
707+
//qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC3),"adc_read", channels[i], qdev_get_gpio_in_named(vdev, "adc_read_request",0));
708708
}
709709
}
710710

711711
// Bed V, always on.
712712
vdev = qdev_new("powersource");
713713
qdev_prop_set_uint32(vdev,"mV",24000);
714714
sysbus_realize(SYS_BUS_DEVICE(vdev),&error_fatal);
715-
qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_read", 5, qdev_get_gpio_in_named(vdev, "adc_read_request",0));
715+
// qdev_connect_gpio_out_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_read", 5, qdev_get_gpio_in_named(vdev, "adc_read_request",0));
716716
qdev_connect_gpio_out_named(vdev, "v_sense",0,qdev_get_gpio_in_named(stm32_soc_get_periph(dev_soc, STM32_P_ADC1),"adc_data_in",5));
717717
//qdev_connect_gpio_out_named(vdev, "v_sense",0,qdev_get_gpio_in_named(dev,"1Y",0));
718718
// qdev_connect_gpio_out_named(vdev, "a_sense",0,qdev_get_gpio_in_named(dev,"2Y",1));

hw/arm/prusa/stm32f407/stm32f4xx_adc.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ static void stm32f4xx_adc_reset(DeviceState *dev)
207207
s->defs.HT = 0xFFF;
208208

209209
memset(&s->adc_sequence,0,ADC_NUM_REG_CHANNELS);
210-
memset(&s->adc_data,0,ADC_NUM_REG_CHANNELS*sizeof(int));
210+
// We can't reset the data here because it might
211+
// clear the initial stuff sent by other device resets.
212+
213+
214+
//memset(&s->adc_data,0,ADC_NUM_REG_CHANNELS*sizeof(int));
211215
s->adc_sequence_position = 0;
212216
s->adc_next_seq_pos = 0;
213217

@@ -241,7 +245,7 @@ static uint32_t stm32f4xx_adc_get_value(STM32F4XXADCState *s)
241245
static void stm32f4xx_adc_data_in(void *opaque, int n, int level){
242246
STM32F4XXADCState *s = opaque;
243247
s->adc_data[n] = level;
244-
// printf("ADC: Ch %d new data: %d\n",n, level);
248+
// printf("%s: Ch %d new data: %d\n", _PERIPHNAMES[s->parent.periph], n, level);
245249
}
246250

247251
static void stm32f4xx_adc_recalc_times(STM32F4XXADCState *s) {

0 commit comments

Comments
 (0)