分支自 DSP/ADSP21569/DSP-21569

graydon
2023-09-20 d40b58b3ecbfb79e015f55755127849335e289b7
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*****************************************************************************
 * dsp_core_Core1.c
 *****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <sys/platform.h>
#include <sys/adi_core.h>
#include <ctime>
#include <heapnew>
#include <matrix.h>
#include "adi_initialize.h"
#include "../drv/gpio.h"
#include "../drv/spi.h"
#include "config.h"
#include "../drv/board.h"
#include "../drv/sport.h"
#include "../drv/memory.h"
#include "messageproc.h"
#include "ModuleProAPI.h"
#include "queue.h"
#include "tob.h"
#include "f2f.h"
 
 
u32 g_level_report_interval = LEVEL_REPORT_TIME(200);
 
u8  mDspIndex = 0;
ubool  TopoLoading = ufalse;
ubool  HandShakeSuccesful = ufalse;
ubool  TopoRequest = ufalse;
u32 DMACount =0;
ufloat proc_secs;
static ufloat asyn_proc_secs;
 
ufloat cpu_utility()
{
    ufloat total_secs ;
 
    total_secs = asyn_proc_secs + proc_secs*(SAMPLE_RATE*0.01f)/SAMPLE_NUM ;//
 
    return total_secs*1000*100/10;
}
 
extern "C" uvoid AudioProcCallBack (uvoid)
{
    ToB* tob = ToB::GetInstance();
    ufloat clock_start,clock_stop;
 
    if(tob == NULL) return ;
 
    if(TopoLoading ){
        MuteOutput();
    } else {
        clock_start = clock();
        UpdateInput(DMACount&0x1);
        tob->toProc();
        UpdateOutput(DMACount&0x1);
 
        clock_stop = clock();
        proc_secs = ((ufloat) (clock_stop - clock_start))/ CLOCKS_PER_SEC;
        ModulesAsynSetInterval(proc_secs);
    }
    DMACount++;
}
 
 
int main(int argc, char *argv[])
{
    int result ;
 
    s32 ledOn = 0;
     uint32_t ledCount = 0;
    uint32_t levelCount = 0;
 
    extern u32 DMACount;
    extern  ufloat proc_secs;
    MSG msg;
 
    adi_initComponents();
 
    spu_config();
 
    pinmux_config();
    //result = DDR_config();
    sram_init();
 
    DAI_config();
 
    Message* spiMsg = new Message(12);
    spiMsg->Send(MsgType::MSG_REHANDSHAKE_REQ , 0 , 0);
 
    SPI2_Init();
 
    while(1) {
        asyn_proc_secs = ModulesAsynProcess();
 
        spiMsg->Proc();
 
        if(DMACount - ledCount > (SAMPLE_RATE/SAMPLE_NUM)) {
            ToB* tob = ToB::GetInstance();
            GPIO_SetOutPut(GPIOC, GPIO_Pin0, (GPIO_Level)ledOn);
            GPIO_SetOutPut(GPIOB, GPIO_Pin10, (GPIO_Level)ledOn);
            ledOn = 1-ledOn;
            ledCount = DMACount;
            spiMsg->DSPStatusProcess(&msg);
            if(tob) tob->GetModuleCPU(spiMsg, &msg);
        }
 
 
        if(DMACount - levelCount > g_level_report_interval) {
            ToB* tob = ToB::GetInstance();
            if(tob ) {
                tob->GetLevels(spiMsg, &msg);
            }
 
            if(TopoLoading ){
                GPIO_SetOutPut(GPIOC, GPIO_Pin0, (GPIO_Level)ledOn);
                GPIO_SetOutPut(GPIOB, GPIO_Pin10, (GPIO_Level)ledOn);
                 ledOn = 1-ledOn;
            }
            levelCount = DMACount;
        }
    }
 
}