]> begriffs open source - freertos/blob - Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.h
Add new demo files.
[freertos] / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / peripherals / ac97c / ac97c.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 //------------------------------------------------------------------------------\r
31 /// \unit\r
32 ///\r
33 /// !!!Purpose\r
34 /// \r
35 /// This module provides definitions and functions for using the AC'97\r
36 /// controller (AC97C).\r
37 /// \r
38 /// !!!Usage\r
39 /// \r
40 /// -# Enable the AC'97 interface pins (see pio & board.h).\r
41 /// -# Configure the AC'97 controller using AC97C_Configure\r
42 /// -# Assign the input and output slots to channels, and the data size used to\r
43 ///    transfer AC97 data stream.\r
44 ///    - Three functions can be used:\r
45 ///       - AC97C_AssignInputSlots: set slots for AC'97 data in, recording.\r
46 ///       - AC97C_AssignOutputSlots: set slots for AC'97 data out, playing.\r
47 ///       - AC97C_SetChannelSize: set data sizes in bits for AC'97 data stream.\r
48 ///    - Three different channels can be configured:\r
49 ///       - AC97C_CHANNEL_CODEC: AC'97 register access channel, its size is\r
50 ///         fixed and #must not# change by AC97C_SetChannelSize\r
51 ///       - AC97C_CHANNEL_A: AC'97 stream channel, with PDC support.\r
52 ///       - AC97C_CHANNEL_B: AC'97 data channel, without PDC support.\r
53 /// -# Configure the used AC97 channel with AC97C_ConfigureChannel, to enable\r
54 ///    the channel.\r
55 /// -# Then you can operate the connected AC'97 codec:\r
56 ///    - AC97C_ReadCodec / AC97C_WriteCodec: Read / Write codec register.\r
57 ///    - AC97C_Transfer: Transfer through AC97C channels to setup codec register\r
58 ///     or transfer %audio data stream.\r
59 ///       - AC97C_CODEC_TRANSFER: access the codec register.\r
60 ///       - AC97C_CHANNEL_A_RECEIVE, AC97C_CHANNEL_B_RECEIVE: start reading.\r
61 ///       - AC97C_CHANNEL_A_TRANSMIT, AC97C_CHANNEL_B_TRANSMIT: start writing.\r
62 ///    Normally you can initialize a set of AC'97 codec registers to initialize\r
63 ///    the codec for %audio playing and recording.\r
64 /// -# Example code for playing & recording:\r
65 ///    - General process:\r
66 ///       -# Configure the codec registers for the %audio settings and formats;\r
67 ///       -# Setup the channel size if necessery;\r
68 ///       -# Start %audio stream transfer.\r
69 ///    - Audio playing sample:\r
70 /// \code\r
71 ///    // Configure sample rate of codec\r
72 ///    AC97C_WriteCodec(AD1981B_PMC_DAC, expectedSampleRate);\r
73 ///    // Set channel size\r
74 ///    AC97C_SetChannelSize(AC97C_CHANNEL_A, bitsPerSample);\r
75 ///    // Start channel A transfer\r
76 ///    AC97C_Transfer(AC97C_CHANNEL_A_TRANSMIT, \r
77 ///                   (unsigned char *) (pointerToAudioDataBuffer),\r
78 ///                   numberOfSamplesToSend,\r
79 ///                   (Ac97Callback) PlayingFinished, \r
80 ///                   0);\r
81 /// \endcode\r
82 ///    - Audio recording sample:\r
83 /// \code\r
84 ///    // Enable recording\r
85 ///    AC97C_WriteCodec(AD1981B_REC_SEL, 0);\r
86 ///    // Set sample rate\r
87 ///    AC97C_WriteCodec(AD1981B_PMC_ADC, 7000);\r
88 ///    // Always use 16-bits recording\r
89 ///    AC97C_SetChannelSize(AC97C_CHANNEL_A, 16);\r
90 ///    // Start recording\r
91 ///    AC97C_Transfer(AC97C_CHANNEL_A_RECEIVE, \r
92 ///                   (unsigned char *) RECORD_ADDRESS,\r
93 ///                   MAX_RECORD_SIZE,\r
94 ///                   (Ac97Callback) RecordFinished,\r
95 ///                   0);\r
96 /// \endcode\r
97 //------------------------------------------------------------------------------\r
98 \r
99 #ifndef AC97C_H\r
100 #define AC97C_H\r
101 \r
102 //------------------------------------------------------------------------------\r
103 //         Constants\r
104 //------------------------------------------------------------------------------\r
105 \r
106 /// The channel is already busy with a transfer.\r
107 #define AC97C_ERROR_BUSY            1\r
108 /// The transfer has been stopped by the user.\r
109 #define AC97C_ERROR_STOPPED         2\r
110 \r
111 /// Codec channel index.\r
112 #define AC97C_CHANNEL_CODEC         0\r
113 /// Channel A index.\r
114 #define AC97C_CHANNEL_A             1\r
115 /// Channel B index.\r
116 #define AC97C_CHANNEL_B             2\r
117 \r
118 /// Codec transmit/receive transfer index.\r
119 #define AC97C_CODEC_TRANSFER        0\r
120 /// Channel A receive transfer index.\r
121 #define AC97C_CHANNEL_A_RECEIVE     1\r
122 /// Channel A transmit transfer index.\r
123 #define AC97C_CHANNEL_A_TRANSMIT    2\r
124 /// Channel B receive transfer index.\r
125 #define AC97C_CHANNEL_B_RECEIVE     3\r
126 /// Channel B transmit transfer index.\r
127 #define AC97C_CHANNEL_B_TRANSMIT    4\r
128 \r
129 //------------------------------------------------------------------------------\r
130 //         Types\r
131 //------------------------------------------------------------------------------\r
132 \r
133 /// AC97C transfer callback function.\r
134 typedef void (*Ac97Callback)(void *pArg,\r
135                              unsigned char status,\r
136                              unsigned int remaining);\r
137 \r
138 //------------------------------------------------------------------------------\r
139 //         Exported functions\r
140 //------------------------------------------------------------------------------\r
141 \r
142 extern void AC97C_Configure();\r
143 \r
144 extern void AC97C_ConfigureChannel(unsigned char channel, unsigned int cfg);\r
145 \r
146 extern void AC97C_AssignInputSlots(unsigned char channel, unsigned int slots);\r
147 \r
148 extern void AC97C_AssignOutputSlots(unsigned char channel, unsigned int slots);\r
149 \r
150 extern unsigned char AC97C_Transfer(\r
151                 unsigned char channel,\r
152                 unsigned char *pBuffer,\r
153                 unsigned int numSamples,\r
154                 Ac97Callback callback,\r
155                 void *pArg);\r
156 \r
157 extern unsigned char AC97C_IsFinished(unsigned char channel);\r
158 \r
159 extern void AC97C_WriteCodec(unsigned char address, unsigned short data);\r
160 \r
161 extern unsigned short AC97C_ReadCodec(unsigned char address);\r
162 \r
163 extern void AC97C_SetChannelSize(unsigned char channel, unsigned char size);\r
164 \r
165 extern void AC97C_CancelTransfer(unsigned char channel);\r
166 \r
167 #endif //#ifndef AC97C_H\r
168 \r