@@ -30,8 +30,6 @@ static audio_dma_t *audio_dma_state[AUDIO_DMA_CHANNEL_COUNT];
3030// This cannot be in audio_dma_state because it's volatile.
3131static volatile bool audio_dma_pending [AUDIO_DMA_CHANNEL_COUNT ];
3232
33- static bool audio_dma_allocated [AUDIO_DMA_CHANNEL_COUNT ];
34-
3533uint8_t find_sync_event_channel_raise () {
3634 uint8_t event_channel = find_sync_event_channel ();
3735 if (event_channel >= EVSYS_SYNCH_NUM ) {
@@ -40,24 +38,6 @@ uint8_t find_sync_event_channel_raise() {
4038 return event_channel ;
4139}
4240
43- uint8_t dma_allocate_channel (void ) {
44- uint8_t channel ;
45- for (channel = 0 ; channel < AUDIO_DMA_CHANNEL_COUNT ; channel ++ ) {
46- if (!audio_dma_allocated [channel ]) {
47- audio_dma_allocated [channel ] = true;
48- return channel ;
49- }
50- }
51- return channel ; // i.e., return failure
52- }
53-
54- void dma_free_channel (uint8_t channel ) {
55- assert (channel < AUDIO_DMA_CHANNEL_COUNT );
56- assert (audio_dma_allocated [channel ]);
57- audio_dma_disable_channel (channel );
58- audio_dma_allocated [channel ] = false;
59- }
60-
6141void audio_dma_disable_channel (uint8_t channel ) {
6242 if (channel >= AUDIO_DMA_CHANNEL_COUNT ) {
6343 return ;
@@ -191,7 +171,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
191171 bool output_signed ,
192172 uint32_t output_register_address ,
193173 uint8_t dma_trigger_source ) {
194- uint8_t dma_channel = dma_allocate_channel ();
174+ uint8_t dma_channel = dma_allocate_channel (true );
195175 if (dma_channel >= AUDIO_DMA_CHANNEL_COUNT ) {
196176 return AUDIO_DMA_DMA_BUSY ;
197177 }
@@ -342,8 +322,7 @@ void audio_dma_reset(void) {
342322 for (uint8_t i = 0 ; i < AUDIO_DMA_CHANNEL_COUNT ; i ++ ) {
343323 audio_dma_state [i ] = NULL ;
344324 audio_dma_pending [i ] = false;
345- audio_dma_allocated [i ] = false;
346- audio_dma_disable_channel (i );
325+ dma_free_channel (i );
347326 dma_descriptor (i )-> BTCTRL .bit .VALID = false;
348327 MP_STATE_PORT (playing_audio )[i ] = NULL ;
349328 }
0 commit comments