ARMEBS4  revision-26.06.2015
audio_dma.c
Go to the documentation of this file.
1 /************************************************************************//**
2  * \file heivs/audio_dma.c
3  * \brief ARMEBS4 audio
4  * \author marc dot pignat at hevs dot ch & Pascal Sartoretti (sap at hevs dot ch)
5  *
6  * This file has been split from audio.c so the buffer is not linked in when the
7  * functions are unused
8  ***************************************************************************/
9 
10 #include "heivs/audio.h"
11 #include "heivs/audio_stm32.h"
12 #include <string.h>
13 
14 static uint32_t buffer[2][512/sizeof(uint32_t)];
15 
16 struct tx_t
17 {
18  void (*done_handler)(const void *);
19  const void *data;
20  volatile uint32_t len;
21 };
22 
23 static struct tx_t tx;
24 
25 static void l_done_handler(const void *data)
26 {
27  size_t len = min(tx.len, sizeof(buffer[0]));
28  tx.len -= len;
29 
30  if (len == 0)
31  {
33  if (tx.done_handler)
34  {
35  tx.done_handler(tx.data);
36  }
37  }
38  else
39  {
40  AudioSTM32_Stream_Play(tx.data);
41  tx.data += len;
42  }
43 }
44 
45 status_e Audio_DMA_Play(const void *data, uint32_t length, void (*done)(const void *))
46 {
47  status_e status;
48  tx.done_handler = done;
49  tx.len = length;
50  tx.data = data;
51  status = Audio_Stream_Play_Init(sizeof(buffer[0]), &buffer[0], &buffer[1], l_done_handler);
52  if (status != NO_ERROR)
53  {
54  return status;
55  }
56 
57  return NO_ERROR;
58 }
59 
61 {
62  if (tx.len > 0)
63  {
64  return ERROR_AGAIN;
65  }
66 
67  return NO_ERROR;
68 }
ARMEBS4 audio.
status_e Audio_DMA_Play_Status(void)
Is Audio_DMA_Play finished?
Definition: audio_dma.c:60
status_e Audio_DMA_Play(const void *data, uint32_t length, void(*done)(const void *))
Play a sound (DMA version)
Definition: audio_dma.c:45
status_e Audio_Stream_Play_Stop(void)
Audio stream playing stop.
Definition: audio.c:102
status_e AudioSTM32_Stream_Play(const void *data)
Audio stream play buffer.
Definition: audio_stm32.c:479
status_e Audio_Stream_Play_Init(uint32_t length, void *buffer0, void *buffer1, void(*done)(const void *))
Audio stream play initialization.
Definition: audio.c:97
Retry later.
Definition: error.h:49
status_e
Known errors.
Definition: error.h:21
No error.
Definition: error.h:28