atmel-sam: Factor out find_sync_event_channel_raise

This commit is contained in:
Jeff Epler 2021-04-20 13:33:11 -05:00
parent 4dcbdac97e
commit d50feebd2c
3 changed files with 12 additions and 9 deletions

View File

@ -45,6 +45,14 @@ static volatile bool audio_dma_pending[AUDIO_DMA_CHANNEL_COUNT];
static bool audio_dma_allocated[AUDIO_DMA_CHANNEL_COUNT];
uint8_t find_sync_event_channel_raise() {
uint8_t event_channel = find_sync_event_channel();
if (event_channel >= EVSYS_SYNCH_NUM) {
mp_raise_RuntimeError(translate("All sync event channels in use"));
}
return event_channel;
}
uint8_t audio_dma_allocate_channel(void) {
uint8_t channel;
for (channel = 0; channel < AUDIO_DMA_CHANNEL_COUNT; channel++) {
@ -230,11 +238,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
// We're likely double buffering so set up the block interrupts.
turn_on_event_system();
dma->event_channel = find_sync_event_channel();
if (dma->event_channel >= EVSYS_SYNCH_NUM) {
mp_raise_RuntimeError(translate("All sync event channels in use"));
}
dma->event_channel = find_sync_event_channel_raise();
init_event_channel_interrupt(dma->event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel);
// We keep the audio_dma_t for internal use and the sample as a root pointer because it

View File

@ -97,4 +97,6 @@ bool audio_dma_get_paused(audio_dma_t *dma);
void audio_dma_background(void);
uint8_t find_sync_event_channel_raise(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H

View File

@ -368,10 +368,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* self,
uint16_t* output_buffer, uint32_t output_buffer_length) {
uint8_t dma_channel = audio_dma_allocate_channel();
uint8_t event_channel = find_sync_event_channel();
if (event_channel >= EVSYS_SYNCH_NUM) {
mp_raise_RuntimeError(translate("All sync event channels in use"));
}
uint8_t event_channel = find_sync_event_channel_raise();
// We allocate two buffers on the stack to use for double buffering.
const uint8_t samples_per_buffer = SAMPLES_PER_BUFFER;