···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ * $Id$
99+ *
1010+ * Copyright (C) 2008 by Catalin Patulea
1111+ *
1212+ * All files in this archive are subject to the GNU General Public License.
1313+ * See the file COPYING in the source tree root for full license agreement.
1414+ *
1515+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1616+ * KIND, either express or implied.
1717+ *
1818+ ****************************************************************************/
1919+2020+#include "registers.h"
2121+#include "arm.h"
2222+#include "ipc.h"
2323+#include "dma.h"
2424+#include "audio.h"
2525+#include <math.h>
2626+2727+void main(void) {
2828+ register int i;
2929+ register signed short *p;
3030+3131+ TCR = 1 << 4; /* Stop the timer. */
3232+ IMR = 0xffff; /* Unmask all interrupts. */
3333+ IFR = IFR; /* Clear all pending interrupts. */
3434+ asm(" rsbx INTM"); /* Globally enable interrupts. */
3535+3636+ audiohw_init();
3737+3838+ dma_init();
3939+4040+ audiohw_postinit();
4141+4242+#if 0
4343+ for (i = 0; i < 32; i++)
4444+ {
4545+ double ratio = ((double)i)/32.0;
4646+ double rad = 3.0*3.141592*ratio;
4747+ double normal = sin(rad);
4848+ double scaled = 32767.0*(normal);
4949+ data[2*i + 0] = -(signed short)scaled;
5050+ data[2*i + 1] = (signed short)scaled;
5151+ }
5252+5353+ debugf("starting write");
5454+5555+ i = 0;
5656+ p = data;
5757+ SPSA0 = 0x01;
5858+ for (;;) {
5959+ while ((SPSD0 & (1 << 1)) == 0);
6060+ DXR20 = *p++; // left channel
6161+ DXR10 = *p++; // right channel
6262+ if (++i == 32)
6363+ {
6464+ p = data;
6565+ i = 0;
6666+ }
6767+ }
6868+#endif
6969+ debugf("DSP inited...");
7070+7171+ for (;;) {
7272+ asm(" IDLE 1");
7373+ asm(" NOP");
7474+ }
7575+}
7676+7777+/* Obsoleted/testing snippets: */
7878+#ifdef REMAP_VECTORS
7979+ /* Remap vectors to 0x3F80 (set in linker.cmd). */
8080+ PMST = (PMST & 0x7f) | 0x3F80;
8181+8282+ /* Make sure working interrupts aren't a fluke. */
8383+ memset((unsigned short *)0x7f80, 0, 0x80);
8484+#endif
8585+8686+#ifdef DATA_32_SINE
8787+ for (i = 0; i < 32; i++) {
8888+ double ratio = ((double)i)/32.0;
8989+ double rad = 3.0*3.141592*ratio;
9090+ double normal = sin(rad);
9191+ double scaled = 32767.0*(normal);
9292+ data[2*i + 0] = -(signed short)scaled;
9393+ data[2*i + 1] = (signed short)scaled;
9494+ }
9595+#endif
9696+9797+#ifdef MANUAL_TRANSFER
9898+ register signed short *p;
9999+100100+ debugf("starting write");
101101+102102+ i = 0;
103103+ p = data;
104104+ SPSA0 = 0x01;
105105+ for (;;) {
106106+ while ((SPSD0 & (1 << 1)) == 0);
107107+ DXR20 = *p++; // left channel
108108+ DXR10 = *p++; // right channel
109109+ if (++i == 32) {
110110+ p = data;
111111+ i = 0;
112112+ }
113113+ }
114114+#endif
115115+116116+#ifdef INIT_MSG
117117+ /* Copy codec init data (before debugf, which clobbers status). */
118118+ if (status.msg != MSG_INIT) {
119119+ debugf("No init message (%04x: %04x %04x %04x %04x instead)",
120120+ (unsigned short)&status,
121121+ ((unsigned short *)&status)[0],
122122+ ((unsigned short *)&status)[1],
123123+ ((unsigned short *)&status)[2],
124124+ ((unsigned short *)&status)[3]);
125125+ return;
126126+ }
127127+128128+ memcpy(&init, (void *)&status.payload.init, sizeof(init));
129129+#endif
130130+131131+#ifdef IPC_SIZES
132132+ debugf("sizeof(ipc_message)=%uw offset(ipc_message.payload)=%uw",
133133+ sizeof(struct ipc_message), (int)&((struct ipc_message*)0)->payload);
134134+#endif
135135+136136+#ifdef VERBOSE_INIT
137137+ debugf("codec started with PCM at SDRAM offset %04x:%04x",
138138+ sdem_addrh, sdem_addrl);
139139+#endif
140140+141141+#ifdef SPIKE_DATA
142142+ for (i = 0; i < 0x2000; i++) {
143143+ data[2*i ] = data[2*i+1] = ((i % 32) == 0) * 32767;
144144+ }
145145+#endif
+93
firmware/target/arm/tms320dm320/dsp/registers.h
···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ * $Id$
99+ *
1010+ * Copyright (C) 2008 by Catalin Patulea
1111+ *
1212+ * All files in this archive are subject to the GNU General Public License.
1313+ * See the file COPYING in the source tree root for full license agreement.
1414+ *
1515+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1616+ * KIND, either express or implied.
1717+ *
1818+ ****************************************************************************/
1919+2020+#ifndef REGISTERS_H
2121+#define REGISTERS_H
2222+2323+#define C5409_REG(addr) (*(volatile unsigned short *)(addr))
2424+2525+/* This is NOT good for reading, only for writing. */
2626+#define BANKED_REG(spsa, spsd, subaddr) spsa = (subaddr), spsd
2727+2828+#define IMR C5409_REG(0x00)
2929+#define IFR C5409_REG(0x01)
3030+3131+#define PMST C5409_REG(0x1D)
3232+3333+#define TCR C5409_REG(0x26)
3434+3535+/* McBSP 0 (SPRU302 Chapter 2) */
3636+#define DXR20 C5409_REG(0x22)
3737+#define DXR10 C5409_REG(0x23)
3838+#define SPSA0 C5409_REG(0x38)
3939+#define SPSD0 C5409_REG(0x39)
4040+#define SPCR10 BANKED_REG(SPSA0, SPSD0, 0x00)
4141+#define SPCR20 BANKED_REG(SPSA0, SPSD0, 0x01)
4242+#define RCR10 BANKED_REG(SPSA0, SPSD0, 0x02)
4343+#define RCR20 BANKED_REG(SPSA0, SPSD0, 0x03)
4444+#define XCR10 BANKED_REG(SPSA0, SPSD0, 0x04)
4545+#define XCR20 BANKED_REG(SPSA0, SPSD0, 0x05)
4646+#define SRGR10 BANKED_REG(SPSA0, SPSD0, 0x06)
4747+#define SRGR20 BANKED_REG(SPSA0, SPSD0, 0x07)
4848+#define PCR0 BANKED_REG(SPSA0, SPSD0, 0x0e)
4949+5050+/* McBSP 1 */
5151+#define DXR21 C5409_REG(0x42)
5252+#define DXR11 C5409_REG(0x43)
5353+#define SPSA1 C5409_REG(0x48)
5454+#define SPSD1 C5409_REG(0x49)
5555+#define SPCR11 BANKED_REG(SPSA1, SPSD1, 0x00)
5656+#define SPCR21 BANKED_REG(SPSA1, SPSD1, 0x01)
5757+#define XCR11 BANKED_REG(SPSA1, SPSD1, 0x04)
5858+#define XCR21 BANKED_REG(SPSA1, SPSD1, 0x05)
5959+#define PCR1 BANKED_REG(SPSA1, SPSD1, 0x0e)
6060+6161+/* DMA */
6262+#define DMPREC C5409_REG(0x54)
6363+#define DMSA C5409_REG(0x55)
6464+#define DMSDI C5409_REG(0x56)
6565+#define DMSDN C5409_REG(0x57)
6666+#define DMSRC0 BANKED_REG(DMSA, DMSDN, 0x00)
6767+#define DMDST0 BANKED_REG(DMSA, DMSDN, 0x01)
6868+#define DMCTR0 BANKED_REG(DMSA, DMSDN, 0x02)
6969+#define DMSFC0 BANKED_REG(DMSA, DMSDN, 0x03)
7070+#define DMMCR0 BANKED_REG(DMSA, DMSDN, 0x04)
7171+7272+7373+/* DM320 */
7474+ioport unsigned short port280;
7575+#define CP_INTC port280
7676+ioport unsigned short port8000;
7777+#define SDEM_ADDRL port8000
7878+ioport unsigned short port8001;
7979+#define SDEM_ADDRH port8001
8080+ioport unsigned short port8002;
8181+#define DSP_ADDRL port8002
8282+ioport unsigned short port8003;
8383+#define DSP_ADDRH port8003
8484+ioport unsigned short port8004;
8585+#define DMA_SIZE port8004
8686+ioport unsigned short port8005;
8787+#define DMA_CTRL port8005
8888+ioport unsigned short port8006;
8989+#define DMA_TRG port8006
9090+ioport unsigned short port8007;
9191+#define DMA_REST port8007
9292+9393+#endif
+40
firmware/target/arm/tms320dm320/dsp/tsc2100.c
···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ * $Id$
99+ *
1010+ * Copyright (C) 2008 by Catalin Patulea
1111+ *
1212+ * All files in this archive are subject to the GNU General Public License.
1313+ * See the file COPYING in the source tree root for full license agreement.
1414+ *
1515+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1616+ * KIND, either express or implied.
1717+ *
1818+ ****************************************************************************/
1919+2020+#include "audio.h"
2121+#include "registers.h"
2222+2323+void audiohw_init(void)
2424+{
2525+ /* Configure McBSP */
2626+ SPCR10 = 0; /* Receiver reset */
2727+ SPCR20 = 3 << 4; /* Rate gen disabled, RINT=XSYNCERR, TX disabled for now */
2828+ PCR0 = 1 << 1; /* Serial port pins, external frame sync, external clock,
2929+ frame sync FSX is active-high,
3030+ TX data sampled on falling clock */
3131+ XCR10 = 0x00a0; /* 1 word per frame, 32 bits per word */
3232+ XCR20 = 0; /* Single-phase, unexpected frame pulse restarts xfer,
3333+ 0-bit data delay */
3434+}
3535+3636+void audiohw_postinit(void)
3737+{
3838+ /* Trigger first XEVT0 */
3939+ SPCR20 |= 1;
4040+}
+143
firmware/target/arm/tms320dm320/dsp/vectors.asm
···11+;* Copyright (c) 2007, C.P.R. Baaij
22+;* All rights reserved.
33+;*
44+;* Redistribution and use in source and binary forms, with or without
55+;* modification, are permitted provided that the following conditions are met:
66+;* * Redistributions of source code must retain the above copyright
77+;* notice, this list of conditions and the following disclaimer.
88+;* * Redistributions in binary form must reproduce the above copyright
99+;* notice, this list of conditions and the following disclaimer in the
1010+;* documentation and/or other materials provided with the distribution.
1111+;*
1212+;* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1313+;* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1414+;* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1515+;* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1616+;* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1717+;* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1818+;* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1919+;* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2020+;* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2121+;* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222+2323+;*-----------------------------------------------------------------------------*
2424+;* Interrupt Vectors *
2525+;*-----------------------------------------------------------------------------*
2626+ .mmregs
2727+2828+ ; External Functions
2929+ .global _handle_int0
3030+ .global _c_int00
3131+ .global _handle_dma0
3232+ .global _handle_dmac
3333+3434+ .sect ".vectors"
3535+; Reset Interrupt
3636+RS_V: BD _c_int00
3737+ NOP
3838+ NOP
3939+4040+; Non-Maskable Interrupt
4141+NMI_V: RETE
4242+ NOP
4343+ NOP
4444+ NOP
4545+4646+; Software Interrupts
4747+SINt17_V: .space 4*16
4848+SINt18_V: .space 4*16
4949+SINt19_V: .space 4*16
5050+SINt20_V: .space 4*16
5151+SINt21_V: .space 4*16
5252+SINt22_V: .space 4*16
5353+SINt23_V: .space 4*16
5454+SINt24_V: .space 4*16
5555+SINt25_V: .space 4*16
5656+SINt26_V: .space 4*16
5757+SINt27_V: .space 4*16
5858+SINt28_V: .space 4*16
5959+SINt29_V: .space 4*16
6060+SINt30_V: .space 4*16
6161+; INT0 - ARM Interrupting DSP via HPIB
6262+INT0_V: BD _handle_int0
6363+ NOP
6464+ NOP
6565+; INT1 - Interrupt is generated based on the settings of DSP_SYNC_STATE and
6666+; DSP_SYNC_MASK register of the coprocessor subsystem or when DSPINT1 bit in
6767+; CP_INTC is set.
6868+INT1_V: RETE
6969+ NOP
7070+ NOP
7171+ NOP
7272+; INT2 - Interrupt is generated when DSPINT2 bit in CP_INTC register of the
7373+; coprocessor subsystem is set.
7474+INT2_V: RETE
7575+ NOP
7676+ NOP
7777+ NOP
7878+; Timer Interrupt
7979+TINT_V: RETE
8080+ NOP
8181+ NOP
8282+ NOP
8383+; McBSP0 receive interrupt
8484+BRINT0_V: RETE
8585+ NOP
8686+ NOP
8787+ NOP
8888+; McBSP0 transmit interrupt
8989+BXINT0_V: RETE
9090+ NOP
9191+ NOP
9292+ NOP
9393+; DMA Channel-0 interrupt
9494+DMAC0_V: BD _handle_dma0
9595+ NOP
9696+ NOP
9797+; DMA Channel-1 interrupt
9898+DMAC1_V: RETE
9999+ NOP
100100+ NOP
101101+ NOP
102102+; INT3 - Interrupt is generated when DSPINT3 bit in CP_INTC register of the
103103+; coprocessor subsystem is set or on write of any value to BRKPT_TRG
104104+INT3_V: RETE
105105+ NOP
106106+ NOP
107107+ NOP
108108+; HPIB HINT to DSP
109109+HINT_V: RETE
110110+ NOP
111111+ NOP
112112+ NOP
113113+; BRINT1/DMAC2 McBSP1 receive interrupt
114114+BRINT1_V: RETE
115115+ NOP
116116+ NOP
117117+ NOP
118118+; BXINT1/DMAC3 McBSP1 transmit interrupt
119119+BXINT1_V: RETE
120120+ NOP
121121+ NOP
122122+ NOP
123123+; DMA Channel-4 interrupt
124124+DMAC4_V: RETE
125125+ NOP
126126+ NOP
127127+ NOP
128128+; DMA Channel-5 interrupt
129129+DMAC5_V: RETE
130130+ NOP
131131+ NOP
132132+ NOP
133133+; HPIB DMAC interrupt
134134+HPIB_DMA_V: BD _handle_dmac
135135+ NOP
136136+ NOP
137137+138138+; EHIF interrupt to DSP
139139+EHIV_V: RETE
140140+ NOP
141141+ NOP
142142+ NOP
143143+ .end