ECE 486 Support Libraries
sample486.h
Go to the documentation of this file.
1 /*!
2  * @file
3  *
4  * @brief ECE 486 Interface fuctions to manipulate blocks of sampled data
5  * @author Don Hummels
6  * @date Jan 2016
7  *
8  * Interface routines that users call to handle data samples which are being
9  * streamed from the ADC and back to the DAC.
10  *
11  * @defgroup ECE486_Sample ECE 486 user interface functions to handle streamed ADC/DAC data
12  * @{
13  */
14 
15 #ifndef __SAMPLE_486__
16 #define __SAMPLE_486__
17 
18 /*!
19  * @defgroup Sample_Buffers Sample buffers for data transfers to/from ADC/DAC
20  * @{
21  */
22 
23 #define DEFAULT_BLOCKSIZE 100 //!< Default # samples per block of streamed ADC/DAC data
24 
25 extern uint32_t ADC_Block_Size; //!< Number of samples user accesses per data block
26 extern uint32_t ADC_Buffer_Size; //!< Total buffer size being filled by DMA for ADC/DAC
27 extern volatile int Lower_Ready; //!< Flag to indicate which half of ADC buffer may be processed
28 
29 
30 /*!
31  * @brief Buffer to store samples transfered from the ADC by a DMA.
32  *
33  * The DMA is configured to continually transfer samples from the ADC(s) into the
34  * ADC_Input_Buffer. When the buffer is half-full or full, an interrupt is generated
35  * to allow the valid samples to be translated into float values and handed to the user.
36  *
37  * In Mono input mode, samples are 12-bits, left-aligned in the least significant 16 bits of each
38  * word of the buffer. In Stereo input mode, the least significant 16 bits holds channel 1,
39  * and the most significant 16 bits holds the channel 2 data.
40  */
41 extern volatile uint32_t *ADC_Input_Buffer;
42 
43 /*!
44  * @brief Buffer to hold samples to be transfered to the DAC(s) by a DMA.
45  *
46  * A DMA is configured to continually transfer samples from DAC_Output_Buffer to the
47  * DAC(s).
48  *
49  * In Mono input mode, samples are 12-bits, left-aligned in the least significant 16 bits of each
50  * word of the buffer. In Stereo input mode, the least significant 16 bits holds channel 1,
51  * and the most significant 16 bits holds the channel 2 data.
52  */
53 extern volatile uint32_t *DAC_Output_Buffer;
54 
55 /*!
56  * @} End Sample_Buffers group
57  */
58 
59 /*!
60  * @brief keep track of whether a user is working on a buffer, or waiting for the next buffer
61  */
63  STARTUP, //!< User is not ready for data yet.
64  PROCESS_BUFFER, //!< User is working on a buffer of data
65  WAIT_FOR_NEXT_BUFFER //!< User is done working... waiting for the next buffer
66 };
67 
68 extern enum Processor_Task volatile Sampler_Status;
69 
70 /*!
71  * @defgroup ECE486_Sample_Functions User interface functions for sampled data
72  * @{
73  */
74 
75 /*!
76  * @brief Return the number of samples that the user should expect to process per block
77  *
78  * Users should call getblocksize() once to determine the required number of samples which
79  * must be handled on each call to getblock() or getblockstereo(). Typically, the result is
80  * used to allocate required memory to handle the data
81  *
82  * @return The number of ADC samples supplied per data request
83  */
84 int getblocksize(void);
85 
86 /*!
87  * @brief Set the number of samples that the user should expect to process per block
88  *
89  * setblocksize() may be called before calling initialize() to specify
90  * the number of samples which should be delivered to the user on each
91  * call to getblock() or getblockstereo().
92  *
93  * If setblocksize() is not called, the default block size of #DEFAULT_BLOCKSIZE
94  * is used for data transfers. Using a smaller block size (down to a limit of
95  * one sample) can reduced the latency between the input and output stream, at
96  * the cost of some efficiency in handling the data.
97  *
98  * @attention setblocksize() must be called before calling initialize().
99  *
100  */
101 void setblocksize(
102  uint32_t blksiz //!< Number of samples per block of ADC/DAC data processed
103 );
104 
105 
106 /*!
107  * @brief Request a block of data from the ADC sample stream
108  *
109  * For one input channel (MONO_IN), getblock() is called by the user to request the
110  * next input data block. getblock() will wait until the ADC/DMA completes filling
111  * the requested block of samples. The binary data is then converted to float values
112  * and returned to the user.
113  *
114  * Output samples will range from -1.0 to +1.0 to cover
115  * the range of the ADC input voltages. The converter is
116  * a 12-bit device, so the resolution of the output samples
117  * is roughly 2/4096 = 0.000488.
118  *
119  * Assuming the original voltage range of the ADC is 0 to 3.0 volts,
120  * the conversion between the returned sample value and the input voltage is:
121  * Vin = 1.5 + (sample*1.5).
122  * (A zero sample value indicates the ADC is mid-scale, at 1.5 volts)
123  * For a 0-3 V ADC range, the ADC resolution is 3/4096 = 732 uV.
124  *
125  * @return On return, the memory block pointed to by @a working will be filled with the
126  * requested data block.
127  *
128  * @attention The user is responsible for allocating enough memory to hold the requested array
129  * of float values. The number of samples required may be obtained by calling getblocksize()
130  *
131  * @sa getblocksize(), getblockstereo()
132  */
133 void getblock(
134  float * working //!< [in,out] pointer to an array of floats (large enough to hold one buffer)
135 );
136 
137 
138 /*!
139  * @brief Request a block of data from the two ADC sample streams (Stereo input case)
140  *
141  * For two input channel (STEREO_IN), getblockstero() is called by the user to request the
142  * next input data blocks. getblockstereo() will wait until the ADCs/DMA completes filling
143  * the requested block of samples. The binary data is then converted to float values
144  * and returned to the user.
145  *
146  * Output samples will range from -1.0 to +1.0 to cover
147  * the range of the ADC input voltages. The converter is
148  * a 12-bit device, so the resolution of the output samples
149  * is roughly 2/4096 = 0.000488.
150  *
151  * Assuming the original voltage range of the ADC is 0 to 3.0 volts,
152  * the conversion between the returned sample value and the input voltage is:
153  * Vin = 1.5 + (sample*1.5).
154  * (A zero sample value indicates the ADC is mid-scale, at 1.5 volts)
155  * For a 0-3 V ADC range, the ADC resolution is 3/4096 = 732 uV.
156  *
157  * @return On return, the memory blocks pointed to by @a chan1 and @a chan2 will be filled with the
158  * requested data blocks. Samples are normalized to range from -1.0 to 1.0 to cover the
159  * entire range of the ADC.
160  *
161  * @attention The user is responsible for allocating enough memory to hold the requested arrays
162  * of float values. The number of samples required for each array may be obtained by
163  * calling getblocksize()
164  *
165  * @sa getblocksize(), getblockstereo()
166  */
167 void getblockstereo(
168  float * chan1, //!< [in,out] pointer to an array of floats for the main ADC channel
169  float * chan2 //!< [in,out] pointer to an array of floats for the stereo ADC channel
170 );
171 
172 /*!
173  * @brief Send a buffer of data to the DAC output stream
174  *
175  * For one output stream (MONO_OUT), putblock() is called by the user when they've finished
176  * processing a block of data and are ready to stream the data to the DAC output. Samples passed
177  * to putblock() are assumed to range from -1.0 to 1.0 to cover the entire output range of the
178  * DAC.
179  *
180  * @attention The number of output samples required can be determined by calling getblocksize()
181  */
182 void putblock(
183  float * working //!< [in] Array of output samples
184 );
185 
186 /*!
187  * @brief Send two buffers of data to the DACs for stereo output
188  *
189  * For two output streams (STEREO_OUT), putblockstereo() is called by the user when they've finished
190  * processing a block of data and are ready to stream the data to the DACs. Samples passed
191  * to putblock() are assumed to range from -1.0 to 1.0 to cover the entire output range of the
192  * DAC.
193  *
194  * @attention The number of output samples required can be determined by calling getblocksize()
195  */
196 void putblockstereo(
197  float * chan1, //!< [in] Array of output samples for the main output channel
198  float * chan2 //!< [in] Array of output samples for the stereo output channel
199 );
200 
201 /*! @} End of ECE486_Sample_Functions
202  * @} End of ECE486_Sample group
203  */
204 
205 #endif
volatile uint32_t * ADC_Input_Buffer
Buffer to store samples transfered from the ADC by a DMA.
Definition: sample486.c:21
volatile int Lower_Ready
Flag to indicate which half of ADC buffer may be processed.
Definition: sample486.c:44
enum Processor_Task volatile Sampler_Status
Definition: sample486.c:36
User is working on a buffer of data.
Definition: sample486.h:64
void getblockstereo(float *chan1, float *chan2)
Request a block of data from the two ADC sample streams (Stereo input case)
Definition: sample486.c:182
volatile uint32_t * DAC_Output_Buffer
Buffer to hold samples to be transfered to the DAC(s) by a DMA.
Definition: sample486.c:22
void setblocksize(uint32_t blksiz)
Set the number of samples that the user should expect to process per block.
Definition: sample486.c:68
uint32_t ADC_Buffer_Size
Total buffer size being filled by DMA for ADC/DAC.
Definition: sample486.c:28
void getblock(float *working)
Request a block of data from the ADC sample stream.
Definition: sample486.c:103
User is done working... waiting for the next buffer.
Definition: sample486.h:65
void putblock(float *working)
Send a buffer of data to the DAC output stream.
Definition: sample486.c:143
Processor_Task
keep track of whether a user is working on a buffer, or waiting for the next buffer ...
Definition: sample486.h:62
int getblocksize(void)
Return the number of samples that the user should expect to process per block.
Definition: sample486.c:59
uint32_t ADC_Block_Size
Number of samples user accesses per data block.
Definition: sample486.c:27
void putblockstereo(float *chan1, float *chan2)
Send two buffers of data to the DACs for stereo output.
Definition: sample486.c:158
User is not ready for data yet.
Definition: sample486.h:63