1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// i2s_audio_test.c
|
4 |
|
|
//
|
5 |
|
|
// Cirrus CL7209 eval board CS4340 audio test
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): gthomas
|
43 |
|
|
// Contributors: gthomas
|
44 |
|
|
// Date: 2000-01-03
|
45 |
|
|
// Description: Tool used to test AUDIO interface
|
46 |
|
|
//####DESCRIPTIONEND####
|
47 |
|
|
|
48 |
|
|
#include <pkgconf/kernel.h> // Configuration header
|
49 |
|
|
#include <cyg/kernel/kapi.h>
|
50 |
|
|
#include <cyg/infra/diag.h>
|
51 |
|
|
|
52 |
|
|
#include <cyg/hal/hal_edb7xxx.h> // Board definitions
|
53 |
|
|
|
54 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
55 |
|
|
#include <cyg/hal/hal_arch.h> // Register state info
|
56 |
|
|
#include <cyg/hal/hal_diag.h>
|
57 |
|
|
#include <cyg/hal/hal_intr.h> // HAL interrupt macros
|
58 |
|
|
#include <cyg/hal/drv_api.h> // HAL ISR support
|
59 |
|
|
|
60 |
|
|
#if 1
|
61 |
|
|
#include "long_audio_left.h"
|
62 |
|
|
#include "long_audio_right.h"
|
63 |
|
|
#else
|
64 |
|
|
#include "short_audio_left.h"
|
65 |
|
|
#include "short_audio_right.h"
|
66 |
|
|
#endif
|
67 |
|
|
|
68 |
|
|
extern void i2s_FIQ(void); // Actually the FIQ handler
|
69 |
|
|
|
70 |
|
|
// Number of data samples to play
|
71 |
|
|
#define NUM_PCM_SAMPLES (sizeof(left_channel)/sizeof(left_channel[0]))
|
72 |
|
|
// Play the data in 8 "chunks", truncated to multiple of 4 samples
|
73 |
|
|
#define CHUNK_LENGTH (((NUM_PCM_SAMPLES/8)/4)*4)
|
74 |
|
|
|
75 |
|
|
// This structure is used by the assembly coded interrupt routine
|
76 |
|
|
struct audio_buf {
|
77 |
|
|
void *left_chan_ptr;
|
78 |
|
|
void *right_chan_ptr;
|
79 |
|
|
int length;
|
80 |
|
|
};
|
81 |
|
|
volatile struct audio_buf cur_buf;
|
82 |
|
|
volatile struct audio_buf next_buf;
|
83 |
|
|
|
84 |
|
|
#ifndef FALSE
|
85 |
|
|
#define FALSE 0
|
86 |
|
|
#define TRUE 1
|
87 |
|
|
#endif
|
88 |
|
|
|
89 |
|
|
#define STACK_SIZE 4096
|
90 |
|
|
static char stack[STACK_SIZE];
|
91 |
|
|
static cyg_thread thread_data;
|
92 |
|
|
static cyg_handle_t thread_handle;
|
93 |
|
|
|
94 |
|
|
// FUNCTIONS
|
95 |
|
|
|
96 |
|
|
static void
|
97 |
|
|
cyg_test_exit(void)
|
98 |
|
|
{
|
99 |
|
|
while (TRUE) ;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
static void
|
103 |
|
|
I2Sreset(void)
|
104 |
|
|
{
|
105 |
|
|
// Enable i2s interface instead of SSI#2
|
106 |
|
|
*(volatile cyg_uint32 *)SYSCON3 |= SYSCON3_I2SSEL | 0x200;
|
107 |
|
|
|
108 |
|
|
// Configure the i2s audio interface
|
109 |
|
|
// External clock, interrupt on right channel FIFO needs service
|
110 |
|
|
*(volatile cyg_uint32 *)I2S_CTL = I2S_CTL_FLAG | I2S_CTL_ECS | I2S_CTL_RCTM;
|
111 |
|
|
|
112 |
|
|
// Clear out status register
|
113 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF; // 1's reset
|
114 |
|
|
|
115 |
|
|
// Now enable the interface
|
116 |
|
|
*(volatile cyg_uint32 *)I2S_CTL |= I2S_CTL_EN;
|
117 |
|
|
|
118 |
|
|
// Turn on the FIFOs
|
119 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
120 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
121 |
|
|
*(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_RIGHT_ENABLE;
|
122 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
123 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
124 |
|
|
*(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_LEFT_ENABLE;
|
125 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
126 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
127 |
|
|
|
128 |
|
|
// Clear out status register
|
129 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF; // 1's reset
|
130 |
|
|
|
131 |
|
|
// Enable interrupt
|
132 |
|
|
*(volatile cyg_uint32 *)INTMR3 |= INTSR3_I2SINT;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
static void
|
136 |
|
|
I2Sdisable(void)
|
137 |
|
|
{
|
138 |
|
|
// Turn off the FIFOs
|
139 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
140 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
141 |
|
|
*(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_RIGHT_DISABLE;
|
142 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
143 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
144 |
|
|
*(volatile cyg_uint32 *)I2S_FIFO_CTL = I2S_FIFO_CTL_LEFT_DISABLE;
|
145 |
|
|
while ((*(volatile cyg_uint32 *)I2S_STAT & I2S_STAT_FIFO) == 0) ; // Wait
|
146 |
|
|
*(volatile cyg_uint32 *)I2S_STAT = I2S_STAT_FIFO; // Reset flag
|
147 |
|
|
|
148 |
|
|
// Disable interrupt
|
149 |
|
|
*(volatile cyg_uint32 *)INTMR3 &= ~INTSR3_I2SINT;
|
150 |
|
|
|
151 |
|
|
// Disable the interface
|
152 |
|
|
*(volatile cyg_uint32 *)I2S_CTL = 0;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
static void
|
156 |
|
|
idle(void)
|
157 |
|
|
{
|
158 |
|
|
// Do nothing
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
static void
|
162 |
|
|
audio_exercise(cyg_addrword_t p)
|
163 |
|
|
{
|
164 |
|
|
int sample, len;
|
165 |
|
|
bool started;
|
166 |
|
|
|
167 |
|
|
diag_printf("AUDIO test here!\n");
|
168 |
|
|
|
169 |
|
|
// Enable my special FIQ handler
|
170 |
|
|
HAL_VSR_SET(CYGNUM_HAL_VECTOR_FIQ, i2s_FIQ, NULL);
|
171 |
|
|
|
172 |
|
|
while (TRUE) {
|
173 |
|
|
diag_printf("... Starting over\n");
|
174 |
|
|
|
175 |
|
|
// Set up pointers
|
176 |
|
|
cur_buf.length = 0;
|
177 |
|
|
next_buf.length = 0;
|
178 |
|
|
sample = 0;
|
179 |
|
|
started = false;
|
180 |
|
|
|
181 |
|
|
// Send out the data
|
182 |
|
|
while (sample != NUM_PCM_SAMPLES) {
|
183 |
|
|
if (next_buf.length == 0) {
|
184 |
|
|
// Move some data into the "next" buffer
|
185 |
|
|
next_buf.left_chan_ptr = &left_channel[sample];
|
186 |
|
|
next_buf.right_chan_ptr = &right_channel[sample];
|
187 |
|
|
len = NUM_PCM_SAMPLES - sample;
|
188 |
|
|
if (len > CHUNK_LENGTH) len = CHUNK_LENGTH;
|
189 |
|
|
next_buf.length = len;
|
190 |
|
|
|
191 |
|
|
idle();
|
192 |
|
|
|
193 |
|
|
if (!started) {
|
194 |
|
|
started = true;
|
195 |
|
|
// Initialize audio interface
|
196 |
|
|
I2Sreset();
|
197 |
|
|
}
|
198 |
|
|
sample += len;
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
// Wait for all data to be sent
|
203 |
|
|
while (cur_buf.length != 0) {
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
// Shut off audio interface
|
207 |
|
|
I2Sdisable();
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
diag_printf("All done!\n");
|
211 |
|
|
cyg_test_exit();
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
externC void
|
215 |
|
|
cyg_start( void )
|
216 |
|
|
{
|
217 |
|
|
// Create a main thread, so we can run the scheduler and have time 'pass'
|
218 |
|
|
cyg_thread_create(11, // Priority - just a number
|
219 |
|
|
audio_exercise, // entry
|
220 |
|
|
0, // initial parameter
|
221 |
|
|
"AUDIO_thread", // Name
|
222 |
|
|
&stack[0], // Stack
|
223 |
|
|
STACK_SIZE, // Size
|
224 |
|
|
&thread_handle, // Handle
|
225 |
|
|
&thread_data // Thread data structure
|
226 |
|
|
);
|
227 |
|
|
cyg_thread_resume(thread_handle); // Start it
|
228 |
|
|
// Let 'em fly...
|
229 |
|
|
cyg_scheduler_start();
|
230 |
|
|
} // cyg_package_start()
|
231 |
|
|
|