2002-04-20 23:18:14 +00:00
|
|
|
/***************************************************************************
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* __________ __ ___.
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* \/ \/ \/ \/ \/
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* $Id$
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
* KIND, either express or implied.
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
*
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
****************************************************************************/
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
#include <stdio.h>
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
#include <stdlib.h>
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#include <stdbool.h>
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
#include <string.h>
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
#include "i2c.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2010-10-31 21:09:34 +00:00
|
|
|
#include "mas35xx.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2010-10-31 21:09:34 +00:00
|
|
|
#include "dac3550a.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
#include "sh7034.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#include "system.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
#include "debug.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
#include "kernel.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#include "thread.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
#include "ata.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
#include "disk.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
#include "fat.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
#include "file.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
#include "dir.h"
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#include "panic.h"
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#ifndef MIN
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#define MIN(a, b) (((a)<(b))?(a):(b))
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#endif
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MPEG_PLAY 1
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MPEG_STOP 2
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MPEG_PAUSE 3
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MPEG_RESUME 4
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MPEG_NEED_DATA 100
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MP3_LOW_WATER 0x30000
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
#define MP3_CHUNK_SIZE 0x20000
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
unsigned int bass_table[] =
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x800, /* 1dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x10000, /* 2dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x17c00, /* 3dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x1f800, /* 4dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x27000, /* 5dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x2e400, /* 6dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x35800, /* 7dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x3c000, /* 8dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x42800, /* 9dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x48800, /* 10dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x4e400, /* 11dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x53800, /* 12dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x58800, /* 13dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x5d400, /* 14dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x61800 /* 15dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
};
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
unsigned int treble_table[] =
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x5400, /* 1dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0xac00, /* 2dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x10400, /* 3dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x16000, /* 4dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x1c000, /* 5dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x22400, /* 6dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x28400, /* 7dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x2ec00, /* 8dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x35400, /* 9dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x3c000, /* 10dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x42c00, /* 11dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x49c00, /* 12dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x51800, /* 13dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x58400, /* 14dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
0x5f800 /* 15dB */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
};
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
unsigned char fliptable[] =
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
};
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
extern unsigned int stack[];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
/* Place the MP3 data right after the stack */
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
#define MP3BUF_LEN 0x100000 /* 1 Mbyte */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
unsigned char *mp3buf = (unsigned char *)stack;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
char *tracks[100];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
int num_tracks;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
int mp3buf_write;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
int mp3buf_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
int last_dma_chunk_size;
|
2002-05-06 19:25:40 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
bool dma_on; /* The DMA is active */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
bool playing; /* We are playing an MP3 stream */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
bool filling; /* We are filling the buffer with data from disk */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
struct event_queue mpeg_queue SHAREDBSS_ATTR;
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
static void mas_poll_start(unsigned int interval_in_ms);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
void mpeg_thread(void);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
void reset_mp3_buffer(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_read = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_write = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
void setup_sci0(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 22:16:31 +00:00
|
|
|
/* PB15 is I/O, PB14 is IRQ6, PB12 is SCK0 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 22:16:31 +00:00
|
|
|
PBCR1 = (PBCR1 & 0x0cff) | 0x1200;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-03 13:13:54 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 22:16:31 +00:00
|
|
|
/* Set PB12 to output */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
PBIOR |= 0x1000;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* Disable serial port */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
SCR0 = 0x00;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 22:16:31 +00:00
|
|
|
/* Synchronous, no prescale */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
SMR0 = 0x80;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* Set baudrate 1Mbit/s */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
BRR0 = 0x03;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* use SCK as serial clock output */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
SCR0 = 0x01;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* Clear FER and PER */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
SSR0 &= 0xe7;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
/* Set interrupt ITU2 and SCI0 priority to 0 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
IPRD &= 0x0ff0;
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* set IRQ6 and IRQ7 to edge detect */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
ICR |= 0x03;
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* set PB15 and PB14 to inputs */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
PBIOR &= 0x7fff;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
PBIOR &= 0xbfff;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* set IRQ6 prio 8 and IRQ7 prio 0 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
IPRB = ( IPRB & 0xff00 ) | 0x0080;
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
/* Enable End of DMA interrupt at prio 8 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
IPRC = (IPRC & 0xf0ff) | 0x0800;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
/* Enable Tx (only!) */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
SCR0 |= 0x20;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-02 23:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
void init_dma(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
SAR3 = (unsigned int) mp3buf + mp3buf_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
DAR3 = 0x5FFFEC3;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
CHCR3 &= ~0x0002; /* Clear interrupt */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
CHCR3 = 0x1504; /* Single address destination, TXI0, IE=1 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
last_dma_chunk_size = MIN(65536, mp3buf_write - mp3buf_read);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
DTCR3 = last_dma_chunk_size & 0xffff;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
DMAOR = 0x0001; /* Enable DMA */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
CHCR3 |= 0x0001; /* Enable DMA IRQ */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
void start_dma(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
SCR0 |= 0x80;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
dma_on = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
void stop_dma(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
SCR0 &= 0x7f;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
dma_on = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-05 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
void dma_tick(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Start DMA if it isn't running */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(playing && !dma_on)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if(PBDR & 0x4000)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if(!(SCR0 & 0x80))
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
start_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
void bitswap(unsigned char *data, int length)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
int i;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
for(i = 0;i < length;i++)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
data[i] = fliptable[data[i]];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
int main(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
char buf[40];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
char str[32];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
int i=0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
DIR *d;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
struct dirent *dent;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
char *tmp;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
int volume, bass, treble;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
unsigned short frame_count;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
/* Clear it all! */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
/* This enables the serial Rx interrupt, to be able to exit into the
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
debugger when you hit CTRL-C */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
SCR1 |= 0x40;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
SCR1 &= ~0x80;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
IPRE |= 0xf000; /* Highest priority */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i2c_init();
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
dma_on = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
kernel_init();
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2008-03-26 01:50:41 +00:00
|
|
|
enable_irq();
|
2002-05-06 19:25:40 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
setup_sci0();
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i=mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if (i) {
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("Error - mas_readmem() returned %d\n", i);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
while(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i = buf[0] | buf[1] << 8;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("MAS version: %x\n", i);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i = buf[4] | buf[5] << 8;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("MAS revision: %x\n", i);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i=mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if (i) {
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("Error - mas_readmem() returned %d\n", i);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
while(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
for(i = 0;i < 7;i++)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
str[i*2+1] = buf[i*4];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
str[i*2] = buf[i*4+1];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
str[i*2] = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("Description: %s\n", str);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i=mas_writereg(0x3b, 0x20);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if (i < 0) {
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("Error - mas_writereg() returned %d\n", i);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
while(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
i = mas_run(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
if (i < 0) {
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
debugf("Error - mas_run() returned %d\n", i);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
while(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2002-04-20 23:18:14 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
i = ata_init();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
debugf("ata_init() returned %d\n", i);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
i = disk_init();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
debugf("disk_init() returned %d\n", i);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
debugf("part[0] starts at sector %d\n", part[0].start);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2013-08-17 16:18:22 +00:00
|
|
|
i = fat_mount(IF_MV(0,) IF_MD(0,) part[0].start);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
debugf("fat_mount() returned %d\n", i);
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
num_tracks = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
if((d = opendir("/")))
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
while((dent = readdir(d)))
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
debugf("%s\n", dent->d_name);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
i = strlen(dent->d_name);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
tmp = dent->d_name + i - 4;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
debugf("%s\n", tmp);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(!stricmp(tmp, ".mp3"))
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
tmp = malloc(i+1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(tmp)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
debugf("Adding track %s\n", dent->d_name);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
snprintf(tmp, i+1, "/%s", dent->d_name);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
tracks[num_tracks++] = tmp;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
else
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
panicf("Out of memory\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
closedir(d);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-09 23:03:36 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
debugf("Number of tracks: %d\n");
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_init(&mpeg_queue);
|
2002-05-09 23:03:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2007-10-16 01:25:17 +00:00
|
|
|
create_thread(mpeg_thread, stack - 0x2000, 0x4000, 0);
|
2002-05-09 23:03:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mas_poll_start(2);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
debugf("let's play...\n");
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_post(&mpeg_queue, MPEG_PLAY, 0);
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
volume = 0x2c;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(dac_config(0x04) < 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
debugf("DAC write failed\n");
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(dac_volume(volume) < 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
debugf("DAC write failed\n");
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
bass = 12;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
treble = 8;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
mas_writereg(MAS_REG_KBASS, bass_table[bass]);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
while(1)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
sleep(HZ*4);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2002-05-02 23:02:36 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2006-04-26 20:22:27 +00:00
|
|
|
void IRQ6(void) __attribute__((interrupt_handler));
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
void IRQ6(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
stop_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2006-04-26 20:22:27 +00:00
|
|
|
void DEI3(void) __attribute__((interrupt_handler));
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
void DEI3(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
int unplayed_space_left;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
int space_until_end_of_buffer;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(playing)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_read += last_dma_chunk_size;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(mp3buf_read >= MP3BUF_LEN)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_read = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
unplayed_space_left = mp3buf_write - mp3buf_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(unplayed_space_left < 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
unplayed_space_left = MP3BUF_LEN + unplayed_space_left;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
space_until_end_of_buffer = MP3BUF_LEN - mp3buf_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(!filling && unplayed_space_left < MP3_LOW_WATER)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(unplayed_space_left)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
last_dma_chunk_size = MIN(65536, unplayed_space_left);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
last_dma_chunk_size = MIN(last_dma_chunk_size, space_until_end_of_buffer);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
DTCR3 = last_dma_chunk_size & 0xffff;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
SAR3 = (unsigned int)mp3buf + mp3buf_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
else
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("No more MP3 data. Stopping.\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
CHCR3 = 0; /* Stop DMA interrupt */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-06 19:25:40 +00:00
|
|
|
}
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
CHCR3 &= ~0x0002; /* Clear DMA interrupt */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-04-20 23:18:14 +00:00
|
|
|
}
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
static void mas_poll_start(unsigned int interval_in_ms)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
unsigned int count;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
count = FREQ / 1000 / 8 * interval_in_ms;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
if(count > 0xffff)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
panicf("Error! The MAS poll interval is too long (%d ms)\n",
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
interval_in_ms);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
return;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
/* We are using timer 1 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TSTR &= ~0x02; /* Stop the timer */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TSNC &= ~0x02; /* No synchronization */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TMDR &= ~0x02; /* Operate normally */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TCNT1 = 0; /* Start counting at 0 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
GRA1 = count;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
/* Enable interrupt on level 2 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
IPRC = (IPRC & ~0x000f) | 0x0002;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TSR1 &= ~0x02;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TIER1 = 0xf9; /* Enable GRA match interrupt */
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TSTR |= 0x02; /* Start timer 2 */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2006-04-26 20:22:27 +00:00
|
|
|
void IMIA1(void) __attribute__((interrupt_handler));
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
void IMIA1(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
dma_tick();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
TSR1 &= ~0x01;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-11 21:39:57 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
int track_index = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
char *peek_next_track(int index)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(track_index < num_tracks)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
return tracks[track_index+index];
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
else
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
return NULL;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
}
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
void next_track(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
track_index++;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
int mpeg_file = -1;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
int new_file(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
char *trackname;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
trackname = peek_next_track(0);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("playing %s\n", trackname);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mpeg_file = open(trackname, O_RDONLY);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(mpeg_file < 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("Couldn't open file\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
return -1;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
return 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
void mpeg_thread(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2007-10-16 01:25:17 +00:00
|
|
|
struct queue_event ev;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
int len;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
int free_space_left;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
int amount_to_read;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
bool play_pending;
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
play_pending = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = false;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
while(1)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("S\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_wait(&mpeg_queue, &ev);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
switch(ev.id)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
case MPEG_PLAY:
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Stop the current stream */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
play_pending = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
stop_dma();
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
reset_mp3_buffer();
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
new_file();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Make it read more data */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
filling = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
/* Tell the file loading code that we want to start playing
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
as soon as we have some data */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
play_pending = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
break;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
case MPEG_STOP:
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Stop the current stream */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
stop_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
break;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
case MPEG_PAUSE:
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Stop the current stream */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
stop_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
break;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
case MPEG_RESUME:
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Stop the current stream */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
start_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
break;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
case MPEG_NEED_DATA:
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
free_space_left = mp3buf_read - mp3buf_write;
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
/* We interpret 0 as "empty buffer" */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(free_space_left <= 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
free_space_left = MP3BUF_LEN + free_space_left;
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(free_space_left <= MP3_CHUNK_SIZE)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("0\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
ata_spindown(-1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
filling = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2009-03-04 18:15:06 +00:00
|
|
|
break;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
amount_to_read = MIN(MP3_CHUNK_SIZE, free_space_left);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
amount_to_read = MIN(MP3BUF_LEN - mp3buf_write, amount_to_read);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Read in a few seconds worth of MP3 data. We don't want to
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
read too large chunks because the bitswapping will take
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
too much time. We must keep the DMA happy and also give
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
the other threads a chance to run. */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("R\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(len)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("B\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
bitswap(mp3buf + mp3buf_write, len);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_write += len;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(mp3buf_write >= MP3BUF_LEN)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_write = 0;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("W\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Tell ourselves that we want more data */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
/* And while we're at it, see if we have startet playing
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
yet. If not, do it. */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
if(play_pending)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
play_pending = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
playing = true;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
init_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
start_dma();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
else
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
close(mpeg_file);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Make sure that the write pointer is at a word
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
boundary */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
mp3buf_write &= 0xfffffffe;
|
2002-05-16 21:11:21 +00:00
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-16 21:11:21 +00:00
|
|
|
next_track();
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
if(new_file() < 0)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* No more data to play */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("Finished playing\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
playing = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
ata_spindown(-1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
filling = false;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
else
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Tell ourselves that we want more data */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
break;
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 22:16:07 +00:00
|
|
|
|
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
/* Newlib trap honeypot */
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
void __trap34(void)
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
{
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
debugf("newlib trap34\n");
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
while(1);
|
2004-12-28 22:16:07 +00:00
|
|
|
|
2002-05-13 22:44:07 +00:00
|
|
|
}
|
2004-12-28 22:16:07 +00:00
|
|
|
|