1 //==========================================================================
5 // Cirrus CL7209 eval board CS4340 audio test
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: gthomas
46 // Description: Tool used to test AUDIO interface
47 //####DESCRIPTIONEND####
49 #include <pkgconf/kernel.h> // Configuration header
50 #include <cyg/kernel/kapi.h>
51 #include <cyg/infra/diag.h>
53 #include <cyg/hal/hal_edb7xxx.h> // Board definitions
55 #include <cyg/hal/hal_io.h> // IO macros
56 #include <cyg/hal/hal_arch.h> // Register state info
57 #include <cyg/hal/hal_diag.h>
58 #include <cyg/hal/hal_intr.h> // HAL interrupt macros
59 #include <cyg/hal/drv_api.h> // HAL ISR support
62 #include "long_audio_left.h"
63 #include "long_audio_right.h"
65 #include "short_audio_left.h"
66 #include "short_audio_right.h"
69 extern void i2s_FIQ(void); // Actually the FIQ handler
71 // Number of data samples to play
72 #define NUM_PCM_SAMPLES (sizeof(left_channel)/sizeof(left_channel[0]))
73 // Play the data in 8 "chunks", truncated to multiple of 4 samples
74 #define CHUNK_LENGTH (((NUM_PCM_SAMPLES/8)/4)*4)
76 // This structure is used by the assembly coded interrupt routine
82 volatile struct audio_buf cur_buf;
83 volatile struct audio_buf next_buf;
90 #define STACK_SIZE 4096
91 static char stack[STACK_SIZE];
92 static cyg_thread thread_data;
93 static cyg_handle_t thread_handle;
106 // Enable i2s interface instead of SSI#2
107 *(volatile cyg_uint32 *)SYSCON3 |= SYSCON3_I2SSEL | 0x200;
109 // Configure the i2s audio interface
110 // External clock, interrupt on right channel FIFO needs service
111 *(volatile cyg_uint32 *)I2S_CTL = I2S_CTL_FLAG | I2S_CTL_ECS | I2S_CTL_RCTM;
113 // Clear out status register
114 *(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF; // 1's reset
116 // Now enable the interface
117 *(volatile cyg_uint32 *)I2S_CTL |= I2S_CTL_EN;
120 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
121 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
122 *(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_RIGHT_ENABLE;
123 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
124 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
125 *(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_LEFT_ENABLE;
126 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
127 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
129 // Clear out status register
130 *(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF; // 1's reset
133 *(volatile cyg_uint32 *)INTMR3 |= INTSR3_I2SINT;
139 // Turn off the FIFOs
140 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
141 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
142 *(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_RIGHT_DISABLE;
143 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
144 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
145 *(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_LEFT_DISABLE;
146 while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
147 *(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
150 *(volatile cyg_uint32 *)INTMR3 &= ~INTSR3_I2SINT;
152 // Disable the interface
153 *(volatile cyg_uint32 *)I2S_CTL = 0;
163 audio_exercise(cyg_addrword_t p)
168 diag_printf("AUDIO test here!\n");
170 // Enable my special FIQ handler
171 HAL_VSR_SET(CYGNUM_HAL_VECTOR_FIQ, i2s_FIQ, NULL);
174 diag_printf("... Starting over\n");
183 while (sample != NUM_PCM_SAMPLES) {
184 if (next_buf.length == 0) {
185 // Move some data into the "next" buffer
186 next_buf.left_chan_ptr = &left_channel[sample];
187 next_buf.right_chan_ptr = &right_channel[sample];
188 len = NUM_PCM_SAMPLES - sample;
189 if (len > CHUNK_LENGTH) len = CHUNK_LENGTH;
190 next_buf.length = len;
196 // Initialize audio interface
203 // Wait for all data to be sent
204 while (cur_buf.length != 0) {
207 // Shut off audio interface
211 diag_printf("All done!\n");
218 // Create a main thread, so we can run the scheduler and have time 'pass'
219 cyg_thread_create(11, // Priority - just a number
220 audio_exercise, // entry
221 0, // initial parameter
222 "AUDIO_thread", // Name
225 &thread_handle, // Handle
226 &thread_data // Thread data structure
228 cyg_thread_resume(thread_handle); // Start it
230 cyg_scheduler_start();
231 } // cyg_package_start()