blob: f2d1101aef60c9fdd1d810bcd83ccbf0e3a59cc9 [file] [log] [blame]
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00001/***************************************************************************
Jörg Hohensohnda848572004-12-28 22:16:07 +00002
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00003 * __________ __ ___.
Jörg Hohensohnda848572004-12-28 22:16:07 +00004
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00005 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
Jörg Hohensohnda848572004-12-28 22:16:07 +00006
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00007 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
Jörg Hohensohnda848572004-12-28 22:16:07 +00008
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00009 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
Jörg Hohensohnda848572004-12-28 22:16:07 +000010
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000011 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
Jörg Hohensohnda848572004-12-28 22:16:07 +000012
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000013 * \/ \/ \/ \/ \/
Jörg Hohensohnda848572004-12-28 22:16:07 +000014
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000015 * $Id$
Jörg Hohensohnda848572004-12-28 22:16:07 +000016
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000017 *
Jörg Hohensohnda848572004-12-28 22:16:07 +000018
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000019 * Copyright (C) 2002 by Linus Nielsen Feltzing
Jörg Hohensohnda848572004-12-28 22:16:07 +000020
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000021 *
Jörg Hohensohnda848572004-12-28 22:16:07 +000022
Jörg Hohensohnda848572004-12-28 22:16:07 +000023
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000024 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation; either version 2
27 * of the License, or (at your option) any later version.
Jörg Hohensohnda848572004-12-28 22:16:07 +000028
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000029 *
Jörg Hohensohnda848572004-12-28 22:16:07 +000030
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000031 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
Jörg Hohensohnda848572004-12-28 22:16:07 +000032
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000033 * KIND, either express or implied.
Jörg Hohensohnda848572004-12-28 22:16:07 +000034
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000035 *
Jörg Hohensohnda848572004-12-28 22:16:07 +000036
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000037 ****************************************************************************/
Jörg Hohensohnda848572004-12-28 22:16:07 +000038
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +000039#include <stdio.h>
Jörg Hohensohnda848572004-12-28 22:16:07 +000040
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +000041#include <stdlib.h>
Jörg Hohensohnda848572004-12-28 22:16:07 +000042
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000043#include <stdbool.h>
Jörg Hohensohnda848572004-12-28 22:16:07 +000044
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +000045#include <string.h>
Jörg Hohensohnda848572004-12-28 22:16:07 +000046
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000047#include "i2c.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000048
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000049#include "mas.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000050
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +000051#include "dac.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000052
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000053#include "sh7034.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000054
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +000055#include "system.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000056
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000057#include "debug.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000058
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +000059#include "kernel.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000060
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000061#include "thread.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000062
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +000063#include "ata.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000064
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +000065#include "disk.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000066
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +000067#include "fat.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000068
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +000069#include "file.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000070
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +000071#include "dir.h"
Jörg Hohensohnda848572004-12-28 22:16:07 +000072
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +000073#include "panic.h"
74
Jörg Hohensohnda848572004-12-28 22:16:07 +000075
76
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +000077#ifndef MIN
Jörg Hohensohnda848572004-12-28 22:16:07 +000078
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +000079#define MIN(a, b) (((a)<(b))?(a):(b))
Jörg Hohensohnda848572004-12-28 22:16:07 +000080
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +000081#endif
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000082
Jörg Hohensohnda848572004-12-28 22:16:07 +000083
84
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000085#define MPEG_PLAY 1
Jörg Hohensohnda848572004-12-28 22:16:07 +000086
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000087#define MPEG_STOP 2
Jörg Hohensohnda848572004-12-28 22:16:07 +000088
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000089#define MPEG_PAUSE 3
Jörg Hohensohnda848572004-12-28 22:16:07 +000090
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000091#define MPEG_RESUME 4
Jörg Hohensohnda848572004-12-28 22:16:07 +000092
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000093#define MPEG_NEED_DATA 100
94
Jörg Hohensohnda848572004-12-28 22:16:07 +000095
96
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000097#define MP3_LOW_WATER 0x30000
Jörg Hohensohnda848572004-12-28 22:16:07 +000098
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +000099#define MP3_CHUNK_SIZE 0x20000
100
Jörg Hohensohnda848572004-12-28 22:16:07 +0000101
102
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000103unsigned int bass_table[] =
Jörg Hohensohnda848572004-12-28 22:16:07 +0000104
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000105{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000106
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000107 0,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000108
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000109 0x800, /* 1dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000110
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000111 0x10000, /* 2dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000112
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000113 0x17c00, /* 3dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000114
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000115 0x1f800, /* 4dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000116
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000117 0x27000, /* 5dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000118
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000119 0x2e400, /* 6dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000120
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000121 0x35800, /* 7dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000122
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000123 0x3c000, /* 8dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000124
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000125 0x42800, /* 9dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000126
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000127 0x48800, /* 10dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000128
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000129 0x4e400, /* 11dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000130
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000131 0x53800, /* 12dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000132
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000133 0x58800, /* 13dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000134
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000135 0x5d400, /* 14dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000136
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000137 0x61800 /* 15dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000138
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000139};
140
Jörg Hohensohnda848572004-12-28 22:16:07 +0000141
142
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000143unsigned int treble_table[] =
Jörg Hohensohnda848572004-12-28 22:16:07 +0000144
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000145{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000146
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000147 0,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000148
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000149 0x5400, /* 1dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000150
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000151 0xac00, /* 2dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000152
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000153 0x10400, /* 3dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000154
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000155 0x16000, /* 4dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000156
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000157 0x1c000, /* 5dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000158
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000159 0x22400, /* 6dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000160
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000161 0x28400, /* 7dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000162
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000163 0x2ec00, /* 8dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000164
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000165 0x35400, /* 9dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000166
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000167 0x3c000, /* 10dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000168
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000169 0x42c00, /* 11dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000170
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000171 0x49c00, /* 12dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000172
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000173 0x51800, /* 13dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000174
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000175 0x58400, /* 14dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000176
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000177 0x5f800 /* 15dB */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000178
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000179};
180
Jörg Hohensohnda848572004-12-28 22:16:07 +0000181
182
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000183unsigned char fliptable[] =
Jörg Hohensohnda848572004-12-28 22:16:07 +0000184
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000185{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000186
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000187 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000188
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000189 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000190
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000191 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000192
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000193 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000194
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000195 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000196
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000197 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000198
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000199 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000200
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000201 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000202
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000203 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000204
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000205 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000206
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000207 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000208
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000209 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000210
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000211 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000212
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000213 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000214
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000215 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000216
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000217 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000218
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000219 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000220
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000221 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000222
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000223 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000224
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000225 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000226
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000227 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000228
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000229 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000230
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000231 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000232
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000233 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000234
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000235 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000236
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000237 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000238
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000239 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000240
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000241 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000242
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000243 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000244
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000245 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000246
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000247 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
Jörg Hohensohnda848572004-12-28 22:16:07 +0000248
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000249 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
Jörg Hohensohnda848572004-12-28 22:16:07 +0000250
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000251};
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000252
Jörg Hohensohnda848572004-12-28 22:16:07 +0000253
254
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000255extern unsigned int stack[];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000256
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000257/* Place the MP3 data right after the stack */
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000258
Jörg Hohensohnda848572004-12-28 22:16:07 +0000259
260
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000261#define MP3BUF_LEN 0x100000 /* 1 Mbyte */
262
Jörg Hohensohnda848572004-12-28 22:16:07 +0000263
264
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000265unsigned char *mp3buf = (unsigned char *)stack;
266
Jörg Hohensohnda848572004-12-28 22:16:07 +0000267
268
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000269char *tracks[100];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000270
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000271int num_tracks;
272
Jörg Hohensohnda848572004-12-28 22:16:07 +0000273
274
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000275int mp3buf_write;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000276
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000277int mp3buf_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000278
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000279int last_dma_chunk_size;
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000280
Jörg Hohensohnda848572004-12-28 22:16:07 +0000281
282
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000283bool dma_on; /* The DMA is active */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000284
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000285bool playing; /* We are playing an MP3 stream */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000286
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000287bool filling; /* We are filling the buffer with data from disk */
288
Jörg Hohensohnda848572004-12-28 22:16:07 +0000289
290
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000291struct event_queue mpeg_queue;
292
Jörg Hohensohnda848572004-12-28 22:16:07 +0000293
294
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000295static void mas_poll_start(unsigned int interval_in_ms);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000296
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000297void mpeg_thread(void);
298
Jörg Hohensohnda848572004-12-28 22:16:07 +0000299
300
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000301void reset_mp3_buffer(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000302
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000303{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000304
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000305 mp3buf_read = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000306
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000307 mp3buf_write = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000308
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000309}
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000310
Jörg Hohensohnda848572004-12-28 22:16:07 +0000311
312
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000313void setup_sci0(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000314
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000315{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000316
Linus Nielsen Feltzing5993f562002-05-06 22:16:31 +0000317 /* PB15 is I/O, PB14 is IRQ6, PB12 is SCK0 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000318
Linus Nielsen Feltzing5993f562002-05-06 22:16:31 +0000319 PBCR1 = (PBCR1 & 0x0cff) | 0x1200;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000320
Linus Nielsen Feltzing3b3e7bd2002-05-03 13:13:54 +0000321
Jörg Hohensohnda848572004-12-28 22:16:07 +0000322
Linus Nielsen Feltzing5993f562002-05-06 22:16:31 +0000323 /* Set PB12 to output */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000324
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000325 PBIOR |= 0x1000;
326
Jörg Hohensohnda848572004-12-28 22:16:07 +0000327
328
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000329 /* Disable serial port */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000330
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000331 SCR0 = 0x00;
332
Jörg Hohensohnda848572004-12-28 22:16:07 +0000333
334
Linus Nielsen Feltzing5993f562002-05-06 22:16:31 +0000335 /* Synchronous, no prescale */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000336
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000337 SMR0 = 0x80;
338
Jörg Hohensohnda848572004-12-28 22:16:07 +0000339
340
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000341 /* Set baudrate 1Mbit/s */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000342
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000343 BRR0 = 0x03;
344
Jörg Hohensohnda848572004-12-28 22:16:07 +0000345
346
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000347 /* use SCK as serial clock output */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000348
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000349 SCR0 = 0x01;
350
Jörg Hohensohnda848572004-12-28 22:16:07 +0000351
352
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000353 /* Clear FER and PER */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000354
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000355 SSR0 &= 0xe7;
356
Jörg Hohensohnda848572004-12-28 22:16:07 +0000357
358
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000359 /* Set interrupt ITU2 and SCI0 priority to 0 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000360
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000361 IPRD &= 0x0ff0;
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000362
Jörg Hohensohnda848572004-12-28 22:16:07 +0000363
364
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000365 /* set IRQ6 and IRQ7 to edge detect */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000366
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000367 ICR |= 0x03;
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000368
Jörg Hohensohnda848572004-12-28 22:16:07 +0000369
370
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000371 /* set PB15 and PB14 to inputs */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000372
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000373 PBIOR &= 0x7fff;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000374
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000375 PBIOR &= 0xbfff;
376
Jörg Hohensohnda848572004-12-28 22:16:07 +0000377
378
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000379 /* set IRQ6 prio 8 and IRQ7 prio 0 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000380
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000381 IPRB = ( IPRB & 0xff00 ) | 0x0080;
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000382
Jörg Hohensohnda848572004-12-28 22:16:07 +0000383
384
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000385 /* Enable End of DMA interrupt at prio 8 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000386
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000387 IPRC = (IPRC & 0xf0ff) | 0x0800;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000388
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000389
Jörg Hohensohnda848572004-12-28 22:16:07 +0000390
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000391 /* Enable Tx (only!) */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000392
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000393 SCR0 |= 0x20;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000394
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000395}
396
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000397
Jörg Hohensohnda848572004-12-28 22:16:07 +0000398
399
400
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000401void init_dma(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000402
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000403{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000404
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000405 SAR3 = (unsigned int) mp3buf + mp3buf_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000406
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000407 DAR3 = 0x5FFFEC3;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000408
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000409 CHCR3 &= ~0x0002; /* Clear interrupt */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000410
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000411 CHCR3 = 0x1504; /* Single address destination, TXI0, IE=1 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000412
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000413 last_dma_chunk_size = MIN(65536, mp3buf_write - mp3buf_read);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000414
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000415 DTCR3 = last_dma_chunk_size & 0xffff;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000416
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000417 DMAOR = 0x0001; /* Enable DMA */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000418
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000419 CHCR3 |= 0x0001; /* Enable DMA IRQ */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000420
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000421}
422
Jörg Hohensohnda848572004-12-28 22:16:07 +0000423
424
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000425void start_dma(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000426
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000427{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000428
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000429 SCR0 |= 0x80;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000430
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000431 dma_on = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000432
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000433}
434
Jörg Hohensohnda848572004-12-28 22:16:07 +0000435
436
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000437void stop_dma(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000438
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000439{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000440
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000441 SCR0 &= 0x7f;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000442
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000443 dma_on = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000444
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000445}
446
Jörg Hohensohnda848572004-12-28 22:16:07 +0000447
448
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000449void dma_tick(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000450
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000451{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000452
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000453 /* Start DMA if it isn't running */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000454
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000455 if(playing && !dma_on)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000456
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000457 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000458
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000459 if(PBDR & 0x4000)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000460
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000461 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000462
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000463 if(!(SCR0 & 0x80))
Jörg Hohensohnda848572004-12-28 22:16:07 +0000464
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000465 start_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +0000466
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000467 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000468
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000469 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000470
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000471}
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000472
Jörg Hohensohnda848572004-12-28 22:16:07 +0000473
474
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000475void bitswap(unsigned char *data, int length)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000476
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000477{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000478
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000479 int i;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000480
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000481 for(i = 0;i < length;i++)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000482
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000483 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000484
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000485 data[i] = fliptable[data[i]];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000486
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000487 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000488
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000489}
490
Jörg Hohensohnda848572004-12-28 22:16:07 +0000491
492
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000493int main(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000494
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000495{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000496
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000497 char buf[40];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000498
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000499 char str[32];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000500
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000501 int i=0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000502
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000503 DIR *d;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000504
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000505 struct dirent *dent;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000506
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000507 char *tmp;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000508
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000509 int volume, bass, treble;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000510
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000511 unsigned short frame_count;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000512
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000513
Jörg Hohensohnda848572004-12-28 22:16:07 +0000514
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000515 /* Clear it all! */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000516
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000517 SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
518
Jörg Hohensohnda848572004-12-28 22:16:07 +0000519
520
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000521 /* This enables the serial Rx interrupt, to be able to exit into the
Jörg Hohensohnda848572004-12-28 22:16:07 +0000522
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000523 debugger when you hit CTRL-C */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000524
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000525 SCR1 |= 0x40;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000526
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000527 SCR1 &= ~0x80;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000528
Jörg Hohensohnda848572004-12-28 22:16:07 +0000529
530
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000531 IPRE |= 0xf000; /* Highest priority */
532
Jörg Hohensohnda848572004-12-28 22:16:07 +0000533
534
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000535 i2c_init();
536
Jörg Hohensohnda848572004-12-28 22:16:07 +0000537
538
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000539 dma_on = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000540
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000541
Jörg Hohensohnda848572004-12-28 22:16:07 +0000542
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000543 kernel_init();
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000544
Jörg Hohensohnda848572004-12-28 22:16:07 +0000545
546
Michael Sevakisaf395f42008-03-26 01:50:41 +0000547 enable_irq();
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000548
Jörg Hohensohnda848572004-12-28 22:16:07 +0000549
550
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000551 setup_sci0();
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000552
Jörg Hohensohnda848572004-12-28 22:16:07 +0000553
554
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000555 i=mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000556
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000557 if (i) {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000558
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000559 debugf("Error - mas_readmem() returned %d\n", i);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000560
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000561 while(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000562
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000563 }
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000564
Jörg Hohensohnda848572004-12-28 22:16:07 +0000565
566
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000567 i = buf[0] | buf[1] << 8;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000568
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000569 debugf("MAS version: %x\n", i);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000570
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000571 i = buf[4] | buf[5] << 8;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000572
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000573 debugf("MAS revision: %x\n", i);
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000574
Jörg Hohensohnda848572004-12-28 22:16:07 +0000575
576
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000577 i=mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000578
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000579 if (i) {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000580
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000581 debugf("Error - mas_readmem() returned %d\n", i);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000582
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000583 while(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000584
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000585 }
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000586
Jörg Hohensohnda848572004-12-28 22:16:07 +0000587
588
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000589 for(i = 0;i < 7;i++)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000590
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000591 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000592
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000593 str[i*2+1] = buf[i*4];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000594
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000595 str[i*2] = buf[i*4+1];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000596
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000597 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000598
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000599 str[i*2] = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000600
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000601 debugf("Description: %s\n", str);
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000602
Jörg Hohensohnda848572004-12-28 22:16:07 +0000603
604
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000605 i=mas_writereg(0x3b, 0x20);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000606
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000607 if (i < 0) {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000608
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000609 debugf("Error - mas_writereg() returned %d\n", i);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000610
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000611 while(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000612
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000613 }
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000614
Jörg Hohensohnda848572004-12-28 22:16:07 +0000615
616
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000617 i = mas_run(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000618
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000619 if (i < 0) {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000620
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000621 debugf("Error - mas_run() returned %d\n", i);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000622
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000623 while(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000624
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000625 }
Linus Nielsen Feltzing46f54612002-05-02 23:02:36 +0000626
Jörg Hohensohnda848572004-12-28 22:16:07 +0000627
628
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000629 i = ata_init();
Jörg Hohensohnda848572004-12-28 22:16:07 +0000630
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000631 debugf("ata_init() returned %d\n", i);
632
Jörg Hohensohnda848572004-12-28 22:16:07 +0000633
634
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000635 i = disk_init();
Jörg Hohensohnda848572004-12-28 22:16:07 +0000636
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000637 debugf("disk_init() returned %d\n", i);
638
Jörg Hohensohnda848572004-12-28 22:16:07 +0000639
640
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000641 debugf("part[0] starts at sector %d\n", part[0].start);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000642
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000643
Jörg Hohensohnda848572004-12-28 22:16:07 +0000644
645 i = fat_mount(IF_MV2(0,) IF_MV2(0,) part[0].start);
646
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000647 debugf("fat_mount() returned %d\n", i);
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000648
Jörg Hohensohnda848572004-12-28 22:16:07 +0000649
650
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000651 num_tracks = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000652
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000653 if((d = opendir("/")))
Jörg Hohensohnda848572004-12-28 22:16:07 +0000654
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000655 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000656
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000657 while((dent = readdir(d)))
Jörg Hohensohnda848572004-12-28 22:16:07 +0000658
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000659 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000660
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000661 debugf("%s\n", dent->d_name);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000662
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000663 i = strlen(dent->d_name);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000664
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000665 tmp = dent->d_name + i - 4;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000666
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000667 debugf("%s\n", tmp);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000668
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000669 if(!stricmp(tmp, ".mp3"))
Jörg Hohensohnda848572004-12-28 22:16:07 +0000670
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000671 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000672
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000673 tmp = malloc(i+1);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000674
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000675 if(tmp)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000676
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000677 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000678
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000679 debugf("Adding track %s\n", dent->d_name);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000680
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000681 snprintf(tmp, i+1, "/%s", dent->d_name);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000682
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000683 tracks[num_tracks++] = tmp;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000684
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000685 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000686
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000687 else
Jörg Hohensohnda848572004-12-28 22:16:07 +0000688
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000689 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000690
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000691 panicf("Out of memory\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +0000692
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000693 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000694
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000695 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000696
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000697 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000698
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000699 closedir(d);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000700
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000701 }
702
Jörg Hohensohnda848572004-12-28 22:16:07 +0000703
704
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000705 debugf("Number of tracks: %d\n");
706
Jörg Hohensohnda848572004-12-28 22:16:07 +0000707
708
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000709 queue_init(&mpeg_queue);
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000710
Jörg Hohensohnda848572004-12-28 22:16:07 +0000711
712
Michael Sevakisa9b2fb52007-10-16 01:25:17 +0000713 create_thread(mpeg_thread, stack - 0x2000, 0x4000, 0);
Linus Nielsen Feltzing2990ed22002-05-09 23:03:36 +0000714
Jörg Hohensohnda848572004-12-28 22:16:07 +0000715
716
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000717 mas_poll_start(2);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000718
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000719
Jörg Hohensohnda848572004-12-28 22:16:07 +0000720
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000721 debugf("let's play...\n");
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000722
Jörg Hohensohnda848572004-12-28 22:16:07 +0000723
724
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000725 queue_post(&mpeg_queue, MPEG_PLAY, 0);
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000726
Jörg Hohensohnda848572004-12-28 22:16:07 +0000727
728
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000729 volume = 0x2c;
730
Jörg Hohensohnda848572004-12-28 22:16:07 +0000731
732
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000733 if(dac_config(0x04) < 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000734
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000735 debugf("DAC write failed\n");
736
Jörg Hohensohnda848572004-12-28 22:16:07 +0000737
738
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000739 if(dac_volume(volume) < 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000740
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000741 debugf("DAC write failed\n");
742
Jörg Hohensohnda848572004-12-28 22:16:07 +0000743
744
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000745 bass = 12;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000746
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000747 treble = 8;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000748
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000749
Jörg Hohensohnda848572004-12-28 22:16:07 +0000750
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000751 mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000752
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000753 mas_writereg(MAS_REG_KBASS, bass_table[bass]);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000754
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000755 mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000756
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000757
Jörg Hohensohnda848572004-12-28 22:16:07 +0000758
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000759 while(1)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000760
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000761 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000762
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000763 sleep(HZ*4);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000764
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000765 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000766
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000767}
Linus Nielsen Feltzing55fec172002-05-05 22:13:00 +0000768
Jörg Hohensohnda848572004-12-28 22:16:07 +0000769
770
Jens Arnolda7c20ac2006-04-26 20:22:27 +0000771void IRQ6(void) __attribute__((interrupt_handler));
Jörg Hohensohnda848572004-12-28 22:16:07 +0000772
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000773void IRQ6(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000774
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000775{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000776
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000777 stop_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +0000778
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000779}
780
Jörg Hohensohnda848572004-12-28 22:16:07 +0000781
782
Jens Arnolda7c20ac2006-04-26 20:22:27 +0000783void DEI3(void) __attribute__((interrupt_handler));
Jörg Hohensohnda848572004-12-28 22:16:07 +0000784
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000785void DEI3(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000786
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000787{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000788
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000789 int unplayed_space_left;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000790
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000791 int space_until_end_of_buffer;
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000792
Jörg Hohensohnda848572004-12-28 22:16:07 +0000793
794
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000795 if(playing)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000796
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000797 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000798
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000799 mp3buf_read += last_dma_chunk_size;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000800
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000801 if(mp3buf_read >= MP3BUF_LEN)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000802
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000803 mp3buf_read = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000804
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000805
Jörg Hohensohnda848572004-12-28 22:16:07 +0000806
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000807 unplayed_space_left = mp3buf_write - mp3buf_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000808
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000809 if(unplayed_space_left < 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000810
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000811 unplayed_space_left = MP3BUF_LEN + unplayed_space_left;
812
Jörg Hohensohnda848572004-12-28 22:16:07 +0000813
814
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000815 space_until_end_of_buffer = MP3BUF_LEN - mp3buf_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000816
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000817
Jörg Hohensohnda848572004-12-28 22:16:07 +0000818
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000819 if(!filling && unplayed_space_left < MP3_LOW_WATER)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000820
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000821 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000822
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000823 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000824
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000825 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000826
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000827
Jörg Hohensohnda848572004-12-28 22:16:07 +0000828
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000829 if(unplayed_space_left)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000830
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000831 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000832
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000833 last_dma_chunk_size = MIN(65536, unplayed_space_left);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000834
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000835 last_dma_chunk_size = MIN(last_dma_chunk_size, space_until_end_of_buffer);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000836
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000837 DTCR3 = last_dma_chunk_size & 0xffff;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000838
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000839 SAR3 = (unsigned int)mp3buf + mp3buf_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000840
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000841 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000842
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000843 else
Jörg Hohensohnda848572004-12-28 22:16:07 +0000844
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000845 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000846
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000847 debugf("No more MP3 data. Stopping.\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +0000848
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000849 CHCR3 = 0; /* Stop DMA interrupt */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000850
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000851 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000852
Linus Nielsen Feltzingdba731f2002-05-06 19:25:40 +0000853 }
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000854
Jörg Hohensohnda848572004-12-28 22:16:07 +0000855
856
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000857 CHCR3 &= ~0x0002; /* Clear DMA interrupt */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000858
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000859}
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000860
Jörg Hohensohnda848572004-12-28 22:16:07 +0000861
862
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000863static void mas_poll_start(unsigned int interval_in_ms)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000864
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000865{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000866
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000867 unsigned int count;
868
Jörg Hohensohnda848572004-12-28 22:16:07 +0000869
870
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000871 count = FREQ / 1000 / 8 * interval_in_ms;
872
Jörg Hohensohnda848572004-12-28 22:16:07 +0000873
874
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000875 if(count > 0xffff)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000876
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000877 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000878
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000879 panicf("Error! The MAS poll interval is too long (%d ms)\n",
Jörg Hohensohnda848572004-12-28 22:16:07 +0000880
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000881 interval_in_ms);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000882
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000883 return;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000884
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000885 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000886
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000887
Jörg Hohensohnda848572004-12-28 22:16:07 +0000888
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000889 /* We are using timer 1 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000890
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000891
Jörg Hohensohnda848572004-12-28 22:16:07 +0000892
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000893 TSTR &= ~0x02; /* Stop the timer */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000894
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000895 TSNC &= ~0x02; /* No synchronization */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000896
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000897 TMDR &= ~0x02; /* Operate normally */
898
Jörg Hohensohnda848572004-12-28 22:16:07 +0000899
900
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000901 TCNT1 = 0; /* Start counting at 0 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000902
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000903 GRA1 = count;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000904
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000905 TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */
906
Jörg Hohensohnda848572004-12-28 22:16:07 +0000907
908
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000909 /* Enable interrupt on level 2 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000910
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000911 IPRC = (IPRC & ~0x000f) | 0x0002;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000912
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000913
Jörg Hohensohnda848572004-12-28 22:16:07 +0000914
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000915 TSR1 &= ~0x02;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000916
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000917 TIER1 = 0xf9; /* Enable GRA match interrupt */
918
Jörg Hohensohnda848572004-12-28 22:16:07 +0000919
920
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000921 TSTR |= 0x02; /* Start timer 2 */
Jörg Hohensohnda848572004-12-28 22:16:07 +0000922
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000923}
924
Jörg Hohensohnda848572004-12-28 22:16:07 +0000925
926
Jens Arnolda7c20ac2006-04-26 20:22:27 +0000927void IMIA1(void) __attribute__((interrupt_handler));
Jörg Hohensohnda848572004-12-28 22:16:07 +0000928
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000929void IMIA1(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000930
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000931{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000932
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000933 dma_tick();
Jörg Hohensohnda848572004-12-28 22:16:07 +0000934
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000935 TSR1 &= ~0x01;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000936
Linus Nielsen Feltzingbb69a592002-05-11 21:39:57 +0000937}
938
Jörg Hohensohnda848572004-12-28 22:16:07 +0000939
940
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000941int track_index = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000942
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000943char *peek_next_track(int index)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000944
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000945{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000946
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000947 if(track_index < num_tracks)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000948
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000949 return tracks[track_index+index];
Jörg Hohensohnda848572004-12-28 22:16:07 +0000950
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000951 else
Jörg Hohensohnda848572004-12-28 22:16:07 +0000952
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000953 return NULL;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000954
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000955}
956
Jörg Hohensohnda848572004-12-28 22:16:07 +0000957
958
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000959void next_track(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000960
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000961{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000962
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +0000963 track_index++;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000964
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000965}
966
Jörg Hohensohnda848572004-12-28 22:16:07 +0000967
968
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000969int mpeg_file = -1;
970
Jörg Hohensohnda848572004-12-28 22:16:07 +0000971
972
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000973int new_file(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000974
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000975{
Jörg Hohensohnda848572004-12-28 22:16:07 +0000976
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000977 char *trackname;
978
Jörg Hohensohnda848572004-12-28 22:16:07 +0000979
980
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000981 trackname = peek_next_track(0);
982
Jörg Hohensohnda848572004-12-28 22:16:07 +0000983
984
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000985 debugf("playing %s\n", trackname);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000986
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000987 mpeg_file = open(trackname, O_RDONLY);
Jörg Hohensohnda848572004-12-28 22:16:07 +0000988
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000989 if(mpeg_file < 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +0000990
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000991 {
Jörg Hohensohnda848572004-12-28 22:16:07 +0000992
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000993 debugf("Couldn't open file\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +0000994
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000995 return -1;
Jörg Hohensohnda848572004-12-28 22:16:07 +0000996
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000997 }
Jörg Hohensohnda848572004-12-28 22:16:07 +0000998
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +0000999 return 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001000
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001001}
1002
Jörg Hohensohnda848572004-12-28 22:16:07 +00001003
1004
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001005void mpeg_thread(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001006
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001007{
Jörg Hohensohnda848572004-12-28 22:16:07 +00001008
Michael Sevakisa9b2fb52007-10-16 01:25:17 +00001009 struct queue_event ev;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001010
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001011 int len;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001012
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001013 int free_space_left;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001014
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001015 int amount_to_read;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001016
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001017 bool play_pending;
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001018
Jörg Hohensohnda848572004-12-28 22:16:07 +00001019
1020
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001021 play_pending = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001022
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001023 playing = false;
1024
Jörg Hohensohnda848572004-12-28 22:16:07 +00001025
1026
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001027 while(1)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001028
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001029 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001030
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001031 debugf("S\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001032
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001033 queue_wait(&mpeg_queue, &ev);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001034
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001035 switch(ev.id)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001036
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001037 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001038
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001039 case MPEG_PLAY:
Jörg Hohensohnda848572004-12-28 22:16:07 +00001040
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001041 /* Stop the current stream */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001042
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001043 play_pending = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001044
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001045 playing = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001046
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001047 stop_dma();
1048
Jörg Hohensohnda848572004-12-28 22:16:07 +00001049
1050
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001051 reset_mp3_buffer();
1052
Jörg Hohensohnda848572004-12-28 22:16:07 +00001053
1054
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001055 new_file();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001056
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001057
Jörg Hohensohnda848572004-12-28 22:16:07 +00001058
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001059 /* Make it read more data */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001060
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001061 filling = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001062
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001063 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
1064
Jörg Hohensohnda848572004-12-28 22:16:07 +00001065
1066
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001067 /* Tell the file loading code that we want to start playing
Jörg Hohensohnda848572004-12-28 22:16:07 +00001068
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001069 as soon as we have some data */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001070
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001071 play_pending = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001072
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001073 break;
1074
Jörg Hohensohnda848572004-12-28 22:16:07 +00001075
1076
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001077 case MPEG_STOP:
Jörg Hohensohnda848572004-12-28 22:16:07 +00001078
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001079 /* Stop the current stream */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001080
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001081 playing = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001082
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001083 stop_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001084
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001085 break;
1086
Jörg Hohensohnda848572004-12-28 22:16:07 +00001087
1088
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001089 case MPEG_PAUSE:
Jörg Hohensohnda848572004-12-28 22:16:07 +00001090
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001091 /* Stop the current stream */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001092
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001093 playing = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001094
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001095 stop_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001096
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001097 break;
1098
Jörg Hohensohnda848572004-12-28 22:16:07 +00001099
1100
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001101 case MPEG_RESUME:
Jörg Hohensohnda848572004-12-28 22:16:07 +00001102
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001103 /* Stop the current stream */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001104
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001105 playing = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001106
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001107 start_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001108
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001109 break;
1110
Jörg Hohensohnda848572004-12-28 22:16:07 +00001111
1112
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001113 case MPEG_NEED_DATA:
Jörg Hohensohnda848572004-12-28 22:16:07 +00001114
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001115 free_space_left = mp3buf_read - mp3buf_write;
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001116
Jörg Hohensohnda848572004-12-28 22:16:07 +00001117
1118
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001119 /* We interpret 0 as "empty buffer" */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001120
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001121 if(free_space_left <= 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001122
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001123 free_space_left = MP3BUF_LEN + free_space_left;
1124
Jörg Hohensohnda848572004-12-28 22:16:07 +00001125
1126
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001127 if(free_space_left <= MP3_CHUNK_SIZE)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001128
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001129 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001130
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001131 debugf("0\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001132
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001133 ata_spindown(-1);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001134
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001135 filling = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001136
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001137 break;;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001138
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001139 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001140
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001141
Jörg Hohensohnda848572004-12-28 22:16:07 +00001142
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001143 amount_to_read = MIN(MP3_CHUNK_SIZE, free_space_left);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001144
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001145 amount_to_read = MIN(MP3BUF_LEN - mp3buf_write, amount_to_read);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001146
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001147
Jörg Hohensohnda848572004-12-28 22:16:07 +00001148
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001149 /* Read in a few seconds worth of MP3 data. We don't want to
Jörg Hohensohnda848572004-12-28 22:16:07 +00001150
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001151 read too large chunks because the bitswapping will take
Jörg Hohensohnda848572004-12-28 22:16:07 +00001152
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001153 too much time. We must keep the DMA happy and also give
Jörg Hohensohnda848572004-12-28 22:16:07 +00001154
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001155 the other threads a chance to run. */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001156
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001157 debugf("R\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001158
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001159 len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001160
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001161 if(len)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001162
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001163 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001164
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001165 debugf("B\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001166
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001167 bitswap(mp3buf + mp3buf_write, len);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001168
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001169
Jörg Hohensohnda848572004-12-28 22:16:07 +00001170
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001171 mp3buf_write += len;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001172
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001173 if(mp3buf_write >= MP3BUF_LEN)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001174
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001175 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001176
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001177 mp3buf_write = 0;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001178
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001179 debugf("W\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001180
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001181 }
1182
Jörg Hohensohnda848572004-12-28 22:16:07 +00001183
1184
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001185 /* Tell ourselves that we want more data */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001186
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001187 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001188
Jörg Hohensohnda848572004-12-28 22:16:07 +00001189
1190
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001191 /* And while we're at it, see if we have startet playing
Jörg Hohensohnda848572004-12-28 22:16:07 +00001192
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001193 yet. If not, do it. */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001194
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001195 if(play_pending)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001196
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001197 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001198
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001199 play_pending = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001200
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001201 playing = true;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001202
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001203
Jörg Hohensohnda848572004-12-28 22:16:07 +00001204
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001205 init_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001206
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001207 start_dma();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001208
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001209 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001210
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001211 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001212
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001213 else
Jörg Hohensohnda848572004-12-28 22:16:07 +00001214
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001215 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001216
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001217 close(mpeg_file);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001218
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001219
Jörg Hohensohnda848572004-12-28 22:16:07 +00001220
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001221 /* Make sure that the write pointer is at a word
Jörg Hohensohnda848572004-12-28 22:16:07 +00001222
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001223 boundary */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001224
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001225 mp3buf_write &= 0xfffffffe;
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001226
Jörg Hohensohnda848572004-12-28 22:16:07 +00001227
1228
Linus Nielsen Feltzing2f544012002-05-16 21:11:21 +00001229 next_track();
Jörg Hohensohnda848572004-12-28 22:16:07 +00001230
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001231 if(new_file() < 0)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001232
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001233 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001234
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001235 /* No more data to play */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001236
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001237 debugf("Finished playing\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001238
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001239 playing = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001240
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001241 ata_spindown(-1);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001242
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001243 filling = false;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001244
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001245 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001246
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001247 else
Jörg Hohensohnda848572004-12-28 22:16:07 +00001248
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001249 {
Jörg Hohensohnda848572004-12-28 22:16:07 +00001250
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001251 /* Tell ourselves that we want more data */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001252
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001253 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001254
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001255 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001256
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001257 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001258
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001259 break;
Jörg Hohensohnda848572004-12-28 22:16:07 +00001260
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001261 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001262
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001263 }
Jörg Hohensohnda848572004-12-28 22:16:07 +00001264
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001265}
1266
Jörg Hohensohnda848572004-12-28 22:16:07 +00001267
1268
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001269/* Newlib trap honeypot */
Jörg Hohensohnda848572004-12-28 22:16:07 +00001270
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001271void __trap34(void)
Jörg Hohensohnda848572004-12-28 22:16:07 +00001272
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001273{
Jörg Hohensohnda848572004-12-28 22:16:07 +00001274
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001275 debugf("newlib trap34\n");
Jörg Hohensohnda848572004-12-28 22:16:07 +00001276
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001277 while(1);
Jörg Hohensohnda848572004-12-28 22:16:07 +00001278
Linus Nielsen Feltzingbbdeba62002-05-13 22:44:07 +00001279}
Jörg Hohensohnda848572004-12-28 22:16:07 +00001280