summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/dsp/main.c
blob: 8dfd2b6e9f45038cc15f9ab660955986a6200595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2008 by Catalin Patulea
 *
 * 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.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "registers.h"
#include "arm.h"
#include "ipc.h"
#include "dma.h"
#include "audio.h"

void main(void) {
    TCR = 1 << 4; /* Stop the timer. */
    IMR = 0xffff; /* Unmask all interrupts. */
    IFR = IFR; /* Clear all pending interrupts. */
    PMST |= 1 << 2; /* Turn CLOCKOUT off to save power */
    asm("   rsbx INTM"); /* Globally enable interrupts. */

    audiohw_init();

    dma_init();

#if defined(HAVE_DEBUG)
    debugf("DSP inited...");
#endif

    for (;;) {
        asm("        IDLE 1");
        asm("        NOP");
    }
}

/* Obsoleted/testing snippets: */

#ifdef DATA_32_SINE
    for (i = 0; i < 32; i++) {
        double ratio = ((double)i)/32.0;
        double rad = 3.0*3.141592*ratio;
        double normal = sin(rad);
        double scaled = 32767.0*(normal);
        data[2*i + 0] = -(signed short)scaled;
        data[2*i + 1] = (signed short)scaled;
    }
#endif

#ifdef MANUAL_TRANSFER
    register signed short *p;

    debugf("starting write");

    i = 0;
    p = data;
    SPSA0 = 0x01;
    for (;;) {
        while ((SPSD0 & (1 << 1)) == 0);
        DXR20 = *p++; // left channel
        DXR10 = *p++; // right channel
        if (++i == 32) {
            p = data;
            i = 0;
        }
    }
#endif

#ifdef INIT_MSG
    /* Copy codec init data (before debugf, which clobbers status). */
    if (status.msg != MSG_INIT) {
        debugf("No init message (%04x: %04x %04x %04x %04x instead)",
            (unsigned short)&status,
            ((unsigned short *)&status)[0],
            ((unsigned short *)&status)[1],
            ((unsigned short *)&status)[2],
            ((unsigned short *)&status)[3]);
        return;
    }
    
    memcpy(&init, (void *)&status.payload.init, sizeof(init));
#endif
    
#ifdef IPC_SIZES
    debugf("sizeof(ipc_message)=%uw offset(ipc_message.payload)=%uw",
        sizeof(struct ipc_message), (int)&((struct ipc_message*)0)->payload);
#endif

#ifdef VERBOSE_INIT
    debugf("codec started with PCM at SDRAM offset %04x:%04x",
        sdem_addrh, sdem_addrl);
#endif

#ifdef SPIKE_DATA
    for (i = 0; i < 0x2000; i++) {
        data[2*i  ] = data[2*i+1] = ((i % 32) == 0) * 32767;
    }
#endif