Maurus Cuelenaere | ac67d70 | 2008-05-16 21:16:01 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2008 by Catalin Patulea |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Maurus Cuelenaere | ac67d70 | 2008-05-16 21:16:01 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include "registers.h" |
| 23 | #include "arm.h" |
| 24 | #include "ipc.h" |
| 25 | #include "dma.h" |
| 26 | #include "audio.h" |
| 27 | #include <math.h> |
| 28 | |
| 29 | void main(void) { |
| 30 | register int i; |
| 31 | register signed short *p; |
| 32 | |
| 33 | TCR = 1 << 4; /* Stop the timer. */ |
| 34 | IMR = 0xffff; /* Unmask all interrupts. */ |
| 35 | IFR = IFR; /* Clear all pending interrupts. */ |
| 36 | asm(" rsbx INTM"); /* Globally enable interrupts. */ |
| 37 | |
| 38 | audiohw_init(); |
| 39 | |
| 40 | dma_init(); |
| 41 | |
| 42 | audiohw_postinit(); |
| 43 | |
| 44 | #if 0 |
| 45 | for (i = 0; i < 32; i++) |
| 46 | { |
| 47 | double ratio = ((double)i)/32.0; |
| 48 | double rad = 3.0*3.141592*ratio; |
| 49 | double normal = sin(rad); |
| 50 | double scaled = 32767.0*(normal); |
| 51 | data[2*i + 0] = -(signed short)scaled; |
| 52 | data[2*i + 1] = (signed short)scaled; |
| 53 | } |
| 54 | |
| 55 | debugf("starting write"); |
| 56 | |
| 57 | i = 0; |
| 58 | p = data; |
| 59 | SPSA0 = 0x01; |
| 60 | for (;;) { |
| 61 | while ((SPSD0 & (1 << 1)) == 0); |
| 62 | DXR20 = *p++; // left channel |
| 63 | DXR10 = *p++; // right channel |
| 64 | if (++i == 32) |
| 65 | { |
| 66 | p = data; |
| 67 | i = 0; |
| 68 | } |
| 69 | } |
| 70 | #endif |
| 71 | debugf("DSP inited..."); |
| 72 | |
| 73 | for (;;) { |
| 74 | asm(" IDLE 1"); |
| 75 | asm(" NOP"); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* Obsoleted/testing snippets: */ |
| 80 | #ifdef REMAP_VECTORS |
| 81 | /* Remap vectors to 0x3F80 (set in linker.cmd). */ |
| 82 | PMST = (PMST & 0x7f) | 0x3F80; |
| 83 | |
| 84 | /* Make sure working interrupts aren't a fluke. */ |
| 85 | memset((unsigned short *)0x7f80, 0, 0x80); |
| 86 | #endif |
| 87 | |
| 88 | #ifdef DATA_32_SINE |
| 89 | for (i = 0; i < 32; i++) { |
| 90 | double ratio = ((double)i)/32.0; |
| 91 | double rad = 3.0*3.141592*ratio; |
| 92 | double normal = sin(rad); |
| 93 | double scaled = 32767.0*(normal); |
| 94 | data[2*i + 0] = -(signed short)scaled; |
| 95 | data[2*i + 1] = (signed short)scaled; |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #ifdef MANUAL_TRANSFER |
| 100 | register signed short *p; |
| 101 | |
| 102 | debugf("starting write"); |
| 103 | |
| 104 | i = 0; |
| 105 | p = data; |
| 106 | SPSA0 = 0x01; |
| 107 | for (;;) { |
| 108 | while ((SPSD0 & (1 << 1)) == 0); |
| 109 | DXR20 = *p++; // left channel |
| 110 | DXR10 = *p++; // right channel |
| 111 | if (++i == 32) { |
| 112 | p = data; |
| 113 | i = 0; |
| 114 | } |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | #ifdef INIT_MSG |
| 119 | /* Copy codec init data (before debugf, which clobbers status). */ |
| 120 | if (status.msg != MSG_INIT) { |
| 121 | debugf("No init message (%04x: %04x %04x %04x %04x instead)", |
| 122 | (unsigned short)&status, |
| 123 | ((unsigned short *)&status)[0], |
| 124 | ((unsigned short *)&status)[1], |
| 125 | ((unsigned short *)&status)[2], |
| 126 | ((unsigned short *)&status)[3]); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | memcpy(&init, (void *)&status.payload.init, sizeof(init)); |
| 131 | #endif |
| 132 | |
| 133 | #ifdef IPC_SIZES |
| 134 | debugf("sizeof(ipc_message)=%uw offset(ipc_message.payload)=%uw", |
| 135 | sizeof(struct ipc_message), (int)&((struct ipc_message*)0)->payload); |
| 136 | #endif |
| 137 | |
| 138 | #ifdef VERBOSE_INIT |
| 139 | debugf("codec started with PCM at SDRAM offset %04x:%04x", |
| 140 | sdem_addrh, sdem_addrl); |
| 141 | #endif |
| 142 | |
| 143 | #ifdef SPIKE_DATA |
| 144 | for (i = 0; i < 0x2000; i++) { |
| 145 | data[2*i ] = data[2*i+1] = ((i % 32) == 0) * 32767; |
| 146 | } |
| 147 | #endif |