stm32/adc: Optimise read_timed_multi() by caching buffer pointers.
This commit is contained in:
parent
4f40fa5cf4
commit
aebd9701a7
|
@ -125,9 +125,10 @@ Methods
|
|||
|
||||
The maximum rate depends on factors including the data width and the
|
||||
number of ADC's being read. In testing two ADC's were sampled at a timer
|
||||
rate of 140KHz without overrun. Samples were missed at 180KHz. At high
|
||||
sample rates disabling interrupts for the duration can reduce the risk
|
||||
of sporadic data loss.
|
||||
rate of 210kHz without overrun. Samples were missed at 215kHz. For three
|
||||
ADC's the limit is around 140kHz, and for four it is around 110kHz.
|
||||
At high sample rates disabling interrupts for the duration can reduce the
|
||||
risk of sporadic data loss.
|
||||
|
||||
The ADCAll Object
|
||||
-----------------
|
||||
|
|
|
@ -475,12 +475,14 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
|
|||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf_array[0], &bufinfo, MP_BUFFER_WRITE);
|
||||
size_t typesize = mp_binary_get_size('@', bufinfo.typecode, NULL);
|
||||
void *bufptrs[nbufs];
|
||||
for (uint array_index = 0; array_index < nbufs; array_index++) {
|
||||
mp_buffer_info_t bufinfo_curr;
|
||||
mp_get_buffer_raise(buf_array[array_index], &bufinfo_curr, MP_BUFFER_WRITE);
|
||||
if ((bufinfo.len != bufinfo_curr.len) || (bufinfo.typecode != bufinfo_curr.typecode)) {
|
||||
mp_raise_ValueError("size and type of buffers must match");
|
||||
}
|
||||
bufptrs[array_index] = bufinfo_curr.buf;
|
||||
}
|
||||
|
||||
// Use the supplied timer object as the sampling time base
|
||||
|
@ -541,9 +543,7 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
|
|||
if (typesize == 1) {
|
||||
value >>= 4;
|
||||
}
|
||||
mp_buffer_info_t bufinfo_curr; // Get buf for current ADC
|
||||
mp_get_buffer_raise(buf_array[array_index], &bufinfo_curr, MP_BUFFER_WRITE);
|
||||
mp_binary_set_val_array_from_int(bufinfo_curr.typecode, bufinfo_curr.buf, elem_index, value);
|
||||
mp_binary_set_val_array_from_int(bufinfo.typecode, bufptrs[array_index], elem_index, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue