summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-06-07 21:37:09 -0400
committerDan Halbert <halbert@halwitz.org>2018-06-08 08:23:52 -0400
commit218930d18b5d6c4fbe67c87cec4771b39cc69d1f (patch)
tree87d417f8cc63b977373cb01ae6d2e8af51232ee9 /ports
parentba7e0e2f86c8691a5664550db37233a705793756 (diff)
Check for PDMIn DMA getting stuck.
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 5502fcd81..f16b17770 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -392,7 +392,18 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
break;
}
// Wait for the next buffer to fill
+ uint32_t wait_counts = 0;
+ #ifdef SAMD21
+ #define MAX_WAIT_COUNTS 1000
+ #endif
+ #ifdef SAMD51
+ #define MAX_WAIT_COUNTS 6000
+ #endif
while (!event_interrupt_active(event_channel)) {
+ if (wait_counts++ > MAX_WAIT_COUNTS) {
+ // Buffer has stopped filling; DMA may have missed an I2S trigger event.
+ break;
+ }
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP
#endif