qipp
2025-11-07 744722688187eb4991c72464e2bb5e06b244fee7
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <stdio.h>
#include <string.h>
#include <sru.h>
#include <time.h>
#include <math.h>
#include <sysreg.h>
#include <alg.h>
#include "drv/global.h"
#include "drv/pll.h"
#include "drv/board_sru.h"
#include "drv/ad1939.h"
#include "drv/sport.h"
#include "drv/hmem.h"
#include "drv/spi.h"
#include "drv/fft.h"
#include "f2f.h"
#include "execute.h"
#include "queue.h"
#include "jitter.h"
#include "report.h"
 
extern double proc_secs;///////////////////////////////////////////////////////
extern void* hans,* haec, *hafc;
double cpu_get_process_ulitity(void);
 
#pragma section("scene_mem")
static   int mem_test = 0xefbcdda5;
 
 
//jitter_mem* pusb_input_jitter =0;
//jitter_mem* pusb_output_jitter =0;
 
 
static short cpu_cal_ulitily(void)
{    
    double aec_secs = alg_aec_get_ulitily(haec);
    double ans_secs = alg_ans_get_ulitily(hans);
    
    double total_secs;
    
    total_secs = proc_secs*7.5+ (aec_secs+ans_secs);
    proc_secs = 0 ;
    
    return (total_secs*100000/10);
 
}
 
 
void main()
{
 
    int i ;
    int led_on=0;
    int led_count=0;
    int loop_cnt=0;
    
    short value;
    unsigned short size;////////////////////////////////////////////////
    extern int clock_ok ;
    
    extern  int sp_flag ;
    extern  int inputcnt; 
    extern  int dma_count;
    extern  void* htx_que;
    extern  int msg_process(void);
    extern  int dsp_index  ;
    extern int dsp_status;
    extern  int handshake_successful;
 
      initPLL_SDRAM();  //Initialize the PLL and SDRAM controller
          
    InitDAI();
 
    //float t = NORMALIZE(0x0000b32f)*(1.0f/0x7fff);
    
    i = sizeof(tag_parameters);
    
    SRU(DPI_PB06_O, FLAG6_I);
    sysreg_bit_set(sysreg_FLAGS, FLG6);
    dsp_index = sysreg_bit_tst(sysreg_FLAGS , FLG6);
    
    //GPIO 
    SRU(HIGH, DPI_PBEN11_I); //0-busy,1-idle
    SRU(HIGH, DPI_PBEN12_I); //0-send, 1-recva
    SRU(LOW,DPI_PB11_I);
    SRU(LOW,DPI_PB12_I);
    
 
//    test_dft();
    
    SRU(HIGH,DPI_PBEN13_I);//led
    SRU(HIGH,DPI_PBEN14_I);
    for(i=0;i<3;i++){
        SRU(LOW,DPI_PB13_I);
        SRU(LOW,DPI_PB14_I);
        Delay(1000000);
        SRU(HIGH,DPI_PB13_I);
        SRU(HIGH,DPI_PB14_I);
        Delay(1000000);
    }
    
 
    hmem_init();
    
    spi_init(DEVICE_DMA);
 
    
       // hrx_que = queue_create(8*16);
    htx_que = queue_create(SPI_PKT_SIZE*2);
    //pusb_input_jitter = jitter_create(512);
//    pusb_output_jitter = jitter_create(512);
    
    //sdram check help find problem
    if( mem_test != 0xefbcdda5){
        dsp_status = dsp_mem_err;
        //֪ͨMCUÆô¶¯Íê³É
        SRU(HIGH,DPI_PB11_I);
        SRU(HIGH,DPI_PB12_I);
        while(1){
            loop_cnt++;
            if(loop_cnt>=1000000){
                if(led_on){
                    SRU(HIGH,DPI_PB13_I);
                }
                else{
                    SRU(LOW,DPI_PB13_I);
                }    
                led_on = !led_on;
                loop_cnt =0;    
            }    
            msg_process();
        }
    }
 
    alg_lib_init();
    
    //fft_init();
 
    output_empty();
    
    InitSRC();
    InitSPORT(0x3,RATE_SAMPLES);
    //InitSRC();
    //interrupts(SIG_SP1, sport_isr);
    interruptcb(SIG_SP1, sport_isr);
    
    //usb
    interruptcb(SIG_SP5, sport_usb_isr);
 
    
    //debug״̬ÇëÇóMCUÖØÐ·¢ËÍÊý¾Ý
    device_status_report(DSP_EMULATE_DEBUG,0, 0);
    msg_report_dsp_status(MSG_DSP_STATUS_REPORT);
    
    
    //֪ͨMCUÆô¶¯Íê³É
    SRU(HIGH,DPI_PB11_I);
    SRU(HIGH,DPI_PB12_I);
        
    #define LED_PERIOD (1000*RATE_SAMPLES/(NUM_SAMPLES*1000))
 
    //main loop 
    while(1){
        if(haec != NULL ){
            alg_aec_process_asy(haec);
        }
 
        if(hans != NULL){
            alg_ans_process_asy(hans);
        }
        
 
        msg_process();
            
 
        if(dma_count-led_count>LED_PERIOD){
            if(led_on){
                SRU(LOW,DPI_PB13_I);
            }
            else{
                SRU(HIGH,DPI_PB13_I);
            }
 
            size =  hmem_perused(SRAM_AUTO);        
            device_status_report(DSP_MEM_UTILITY,(short*)&size, 1);
            
            value = cpu_cal_ulitily();
            device_status_report(DSP_CPU_UTILITY,&value , 1);
            device_status_report(DSP_RUNNING_STATUS,(short*)&dsp_status ,1);
            
            msg_report_dsp_status(MSG_DSP_STATUS_REPORT);
            led_on=!led_on;
            led_count = dma_count;
            loop_cnt =0;
        }
        loop_cnt++;
        if(loop_cnt>10000000){
            dsp_status = dsp_no_clock;
            loop_cnt =0;    
        }
            
        if(clock_ok == 0 && dsp_status==dsp_running_ok && handshake_successful){
            //DSP²úÉúʱÖÓÉϱ¨MCUÕý³£ÔË×÷
            device_status_report(DSP_CLOCK_STATUS,0 ,0 );
            clock_ok = 1;    
        }
    }
}