Skip to content

Commit bd10666

Browse files
update dma code to use new allocation interface
1 parent c06f9e1 commit bd10666

5 files changed

Lines changed: 5 additions & 29 deletions

File tree

ports/atmel-samd/audio_dma.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ static audio_dma_t *audio_dma_state[AUDIO_DMA_CHANNEL_COUNT];
5050
// This cannot be in audio_dma_state because it's volatile.
5151
static volatile bool audio_dma_pending[AUDIO_DMA_CHANNEL_COUNT];
5252

53-
static bool audio_dma_allocated[AUDIO_DMA_CHANNEL_COUNT];
54-
5553
uint8_t find_sync_event_channel_raise() {
5654
uint8_t event_channel = find_sync_event_channel();
5755
if (event_channel >= EVSYS_SYNCH_NUM) {
@@ -60,24 +58,6 @@ uint8_t find_sync_event_channel_raise() {
6058
return event_channel;
6159
}
6260

63-
uint8_t dma_allocate_channel(void) {
64-
uint8_t channel;
65-
for (channel = 0; channel < AUDIO_DMA_CHANNEL_COUNT; channel++) {
66-
if (!audio_dma_allocated[channel]) {
67-
audio_dma_allocated[channel] = true;
68-
return channel;
69-
}
70-
}
71-
return channel; // i.e., return failure
72-
}
73-
74-
void dma_free_channel(uint8_t channel) {
75-
assert(channel < AUDIO_DMA_CHANNEL_COUNT);
76-
assert(audio_dma_allocated[channel]);
77-
audio_dma_disable_channel(channel);
78-
audio_dma_allocated[channel] = false;
79-
}
80-
8161
void audio_dma_disable_channel(uint8_t channel) {
8262
if (channel >= AUDIO_DMA_CHANNEL_COUNT) {
8363
return;
@@ -211,7 +191,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
211191
bool output_signed,
212192
uint32_t output_register_address,
213193
uint8_t dma_trigger_source) {
214-
uint8_t dma_channel = dma_allocate_channel();
194+
uint8_t dma_channel = dma_allocate_channel(true);
215195
if (dma_channel >= AUDIO_DMA_CHANNEL_COUNT) {
216196
return AUDIO_DMA_DMA_BUSY;
217197
}
@@ -362,8 +342,7 @@ void audio_dma_reset(void) {
362342
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
363343
audio_dma_state[i] = NULL;
364344
audio_dma_pending[i] = false;
365-
audio_dma_allocated[i] = false;
366-
audio_dma_disable_channel(i);
345+
dma_free_channel(i);
367346
dma_descriptor(i)->BTCTRL.bit.VALID = false;
368347
MP_STATE_PORT(playing_audio)[i] = NULL;
369348
}

ports/atmel-samd/audio_dma.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ uint8_t audiosample_channel_count(mp_obj_t sample_obj);
6868
void audio_dma_init(audio_dma_t *dma);
6969
void audio_dma_reset(void);
7070

71-
uint8_t dma_allocate_channel(void);
72-
void dma_free_channel(uint8_t channel);
73-
7471
// This sets everything up but doesn't start the timer.
7572
// Sample is the python object for the sample to play.
7673
// loop is true if we should loop the sample.

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
384384
// output_buffer_length is the number of slots, not the number of bytes.
385385
uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t *self,
386386
uint16_t *output_buffer, uint32_t output_buffer_length) {
387-
uint8_t dma_channel = dma_allocate_channel();
387+
uint8_t dma_channel = dma_allocate_channel(true);
388388
pdmin_event_channel = find_sync_event_channel_raise();
389389
pdmin_dma_block_done = false;
390390

ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void common_hal_imagecapture_parallelimagecapture_singleshot_capture(imagecaptur
155155
mp_buffer_info_t bufinfo;
156156
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_RW);
157157

158-
uint8_t dma_channel = dma_allocate_channel();
158+
uint8_t dma_channel = dma_allocate_channel(true);
159159

160160
uint32_t *dest = bufinfo.buf;
161161
size_t count = bufinfo.len / 4; // PCC receives 4 bytes (2 pixels) at a time

ports/atmel-samd/peripherals

0 commit comments

Comments
 (0)