OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [edb7xxx/] [v2_0/] [misc/] [i2s_audio_test.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 Red Hat, 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 version.
16
//
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
20
// for more details.
21
//
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.
25
//
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.
32
//
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.
35
//
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####
42
//
43
// Author(s):     gthomas
44
// Contributors:  gthomas
45
// Date:          2000-01-03
46
// Description:   Tool used to test AUDIO interface
47
//####DESCRIPTIONEND####
48
 
49
#include <pkgconf/kernel.h>   // Configuration header
50
#include <cyg/kernel/kapi.h>
51
#include <cyg/infra/diag.h>
52
 
53
#include <cyg/hal/hal_edb7xxx.h>  // Board definitions
54
 
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
60
 
61
#if 1
62
#include "long_audio_left.h"
63
#include "long_audio_right.h"
64
#else
65
#include "short_audio_left.h"
66
#include "short_audio_right.h"
67
#endif
68
 
69
extern void i2s_FIQ(void);  // Actually the FIQ handler
70
 
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)
75
 
76
// This structure is used by the assembly coded interrupt routine
77
struct audio_buf {
78
    void *left_chan_ptr;
79
    void *right_chan_ptr;
80
    int   length;
81
};
82
volatile struct audio_buf cur_buf;
83
volatile struct audio_buf next_buf;
84
 
85
#ifndef FALSE
86
#define FALSE 0
87
#define TRUE  1
88
#endif
89
 
90
#define STACK_SIZE 4096
91
static char stack[STACK_SIZE];
92
static cyg_thread thread_data;
93
static cyg_handle_t thread_handle;
94
 
95
// FUNCTIONS
96
 
97
static void
98
cyg_test_exit(void)
99
{
100
    while (TRUE) ;
101
}
102
 
103
static void
104
I2Sreset(void)
105
{
106
    // Enable i2s interface instead of SSI#2
107
    *(volatile cyg_uint32 *)SYSCON3 |= SYSCON3_I2SSEL | 0x200;
108
 
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;
112
 
113
    // Clear out status register
114
    *(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF;  // 1's reset
115
 
116
    // Now enable the interface
117
    *(volatile cyg_uint32 *)I2S_CTL |= I2S_CTL_EN;
118
 
119
    // Turn on the FIFOs
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
128
 
129
    // Clear out status register
130
    *(volatile cyg_uint32 *)I2S_STAT = 0xFFFFFFFF;  // 1's reset
131
 
132
    // Enable interrupt
133
    *(volatile cyg_uint32 *)INTMR3 |= INTSR3_I2SINT;
134
}
135
 
136
static void
137
I2Sdisable(void)
138
{
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
148
 
149
    // Disable interrupt
150
    *(volatile cyg_uint32 *)INTMR3 &= ~INTSR3_I2SINT;
151
 
152
    // Disable the interface
153
    *(volatile cyg_uint32 *)I2S_CTL = 0;
154
}
155
 
156
static void
157
idle(void)
158
{
159
    // Do nothing
160
}
161
 
162
static void
163
audio_exercise(cyg_addrword_t p)
164
{
165
    int sample, len;
166
    bool started;
167
 
168
    diag_printf("AUDIO test here!\n");
169
 
170
    // Enable my special FIQ handler
171
    HAL_VSR_SET(CYGNUM_HAL_VECTOR_FIQ, i2s_FIQ, NULL);
172
 
173
    while (TRUE) {
174
        diag_printf("... Starting over\n");
175
 
176
        // Set up pointers
177
        cur_buf.length = 0;
178
        next_buf.length = 0;
179
        sample = 0;
180
        started = false;
181
 
182
        // Send out the data
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;
191
 
192
                idle();
193
 
194
                if (!started) {
195
                    started = true;
196
                    // Initialize audio interface
197
                    I2Sreset();
198
                }
199
                sample += len;
200
            }
201
        }
202
 
203
        // Wait for all data to be sent
204
        while (cur_buf.length != 0) {
205
        }
206
 
207
        // Shut off audio interface
208
        I2Sdisable();
209
    }
210
 
211
    diag_printf("All done!\n");
212
    cyg_test_exit();
213
}
214
 
215
externC void
216
cyg_start( void )
217
{
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
223
                      &stack[0],         // Stack
224
                      STACK_SIZE,        // Size
225
                      &thread_handle,    // Handle
226
                      &thread_data       // Thread data structure
227
            );
228
    cyg_thread_resume(thread_handle);  // Start it
229
    // Let 'em fly...
230
    cyg_scheduler_start();
231
} // cyg_package_start()
232
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.