分支自 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * messageproc.c
 *
 *  Created on: 2021Äê11ÔÂ1ÈÕ
 *      Author: graydon
 */
#include <string.h>
#include <stdlib.h>
#include <SRU.h>
#include "messageproc.h"
#include "../drv/spi.h"
#include "../drv/gpio.h"
#include "../drv/memory.h"
#include "queue.h"
#include "tob.h"
#include "F2F.h"
#include "zlib.h"
#include "ModuleProAPI.h"
 
s32 Message::Send(MsgType msg_type, uvoidptr buffer, u32 len)
{
    MSG msg;
 
    msg.Enc(msg_type, buffer, len);
    return txQueue->Push(msg);
}
 
s32 Message::Send(MSG* pmsg )
{
    u32 ret=  txQueue->Push(*pmsg);
 
    return ret;
}
 
s32 Message::PresetProcess(MSG* pmsg)
{
    static u8* bin = NULL;
    extern ubool  TopoLoading ;
 
    if(pmsg->pktNo == 0 && bin != NULL ) {
        sram_free(SRAM_DDR, bin);
        bin = NULL;
    }
    if(pmsg->pktNo == 0 && bin == NULL) {
        bin = (u8*)sram_malloc(SRAM_DDR, mem_any ,pmsg->totalPkts*MSG_DATA_LEN);
    }
    if(bin == NULL) return -1;
 
    memcpy(bin+pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
    if(pmsg->pktNo == pmsg->totalPkts -1) {
        ToB* tob = ToB::GetInstance();
        u32 size = (pmsg->totalPkts -1)*MSG_DATA_LEN+pmsg->dataLen;
        uLongf realsize = size*10;
        Bytef* uncompress_ptr = (Bytef*)sram_malloc(SRAM_DDR, mem_any ,realsize);
 
        if(uncompress_ptr){
            if(tob && uncompress(uncompress_ptr, &realsize, (Bytef*)bin, size) == Z_OK) {
                tob->toCtrl(uncompress_ptr, realsize);
            }
            sram_free(SRAM_DDR, uncompress_ptr);
        }
 
        sram_free(SRAM_DDR, bin);
        bin = NULL;
        TopoLoading = ufalse;
        Send(MsgType::MSG_PRESET_RES, 0 ,0) ;
    }
 
    return 0;
}
 
s32 Message::TopoProcess(MSG* pmsg)
{
    static u8* bin = NULL;
    extern ubool  TopoRequest;
    extern ubool  TopoLoading ;
    u32 size =0;
 
    if(pmsg->pktNo == 0 && bin != NULL ) {
        sram_free(SRAM_DDR, bin);
        bin = NULL;
    }
    if(pmsg->pktNo == 0 && bin == NULL) {
        bin = (u8*)sram_malloc(SRAM_DDR, mem_any ,pmsg->totalPkts*MSG_DATA_LEN);
        size =0 ;
    }
    if(bin == NULL) return -1;
    TopoLoading = utrue;
    memcpy(bin+pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
    if(pmsg->pktNo == pmsg->totalPkts -1) {
        ToB* tob = ToB::GetInstance();
        size = (pmsg->totalPkts -1)*MSG_DATA_LEN+pmsg->dataLen;
 
        SetTxRxNullBufferPtr();
        SetNumOfChannels(0, 0);
 
        if(tob) {
            tob->toClear();
            tob->CreateModule(bin, size);
        }
        sram_free(SRAM_DDR, bin);
        bin = NULL;
 
        if(TopoRequest) {
            Send(MsgType::MSG_TOPO_RES, 0 ,0) ;
            TopoRequest = ufalse;
        }
    }
 
    return 0;
}
 
s32 Message::ParamCtrl(MSG* pmsg)
{
    ToB* tob = ToB::GetInstance();
    Param * ptr = (Param *)pmsg->data;
    const s16* val = (const s16*)(pmsg->data+sizeof(Param));
 
    if(tob != NULL)
        tob->toCtrl(ptr->mID, ptr->pID, val, ptr->num);
 
    return ptr->num;
}
 
 
 
s32 Message::SystemConfigSetProcess(MSG* pmsg)
{
    extern ubool  HandShakeSuccesful;
    extern ubool  TopoRequest;
    extern u16 mDspIndex;
    extern u32 g_level_report_interval;
    DSPConfig* conf = (DSPConfig*)pmsg->data;
 
    if(HandShakeSuccesful == ufalse) {
        //ĬÈÏÖµ¼ì²é
        if(conf->mLevelReportInt <50 || conf->mLevelReportInt >1000) {
            conf->mLevelReportInt = 200;
        }
        if(conf->mSampleNum <16 || conf->mSampleNum >64) {
            conf->mSampleNum = 64;
        }
        SAMPLE_NUM = conf->mSampleNum;
        mDspIndex = conf->mDspIndex;
        g_level_report_interval = LEVEL_REPORT_TIME(conf->mLevelReportInt);
        new ToB(conf->mDualDsp , conf->mDspIndex);
 
        ModuleLeveldBUSetting(conf->mConvertUnit);
        //Config(conf);
        RouteConfig(conf->routes,conf->mRouteNum);
        SRCsConfig(0 , conf->srcs);
        SRCsConfig(1 , &conf->srcs[4]);
        PCGsConfig(conf->pcgs);
        SportsConfig(conf->sports);
 
        HandShakeSuccesful = utrue;
        TopoRequest = utrue;
    }
 
    Send(MsgType::MSG_HANDSHAKE_RES, 0 , 0);
 
    return 0;
}
 
 
 
s32 Message::DSPStatusProcess(MSG* pmsg)
{
    struct DSPStatus* status = (struct DSPStatus*)pmsg->data;
    extern ufloat cpu_utility();
 
    status->mCpu =  cpu_utility()*100; //all modules execute time.;
    status->mInternalUnUsedMem = space_unused();
    status->mExternalUnUsedMem = sram_free_space(SRAM_DDR,mem_any);
    status->mDDRPassed = 1;
 
    pmsg->Enc(MsgType::MSG_DSP_STATUS_RES, 0, sizeof(struct DSPStatus));
 
    return Send(pmsg);
}
//int count = 0;
s32 Message::RxMessageHandler(MSG* pmsg)
{
    if(pmsg->magic != 0x5aa5) {
        //printf("magic error.\n");
        return -1;
    }
 
    switch(pmsg->msgType){
    case MsgType::MSG_PARMA_CTRL_REQ:
        //printf("pctl.\n");
        ParamCtrl(pmsg);
        break;
    case MsgType::MSG_LEVEL_GET_REQ:
        break;
    case MsgType::MSG_PRESET_REQ:
        //printf("preset.%d(%d)\n",pmsg->totalPkts,pmsg->pktNo);
        PresetProcess(pmsg);
        break;
    case MsgType::MSG_TOPO_REQ:
        //printf("topo.%d(%d)\n",pmsg->totalPkts,pmsg->pktNo);
        TopoProcess(pmsg);
        break;
    case MsgType::MSG_HANDSHAKE_REQ:
        //printf("handshake.\n");
        SystemConfigSetProcess(pmsg);
        break;
    case MsgType::MSG_DSP_STATUS_REQ:
        DSPStatusProcess(pmsg);
        break;
    default:
        break;
    }
 
    return 0;
}
 
 
 
uvoid Message::Proc()
{
    u32 status = 0;
 
    if(SPITxDone) {
        RxMessageHandler((MSG*)SPI_Rx_BUFFER);
        if(txQueue->Count() > 0) {
            txQueue->Pop(*(MSG*)SPI_Tx_BUFFER);
        }
        else {
            SPI_Tx_BUFFER[0] = 0;
        }
        SPI2_SetTransMode(SPIStatus::SPI_TRX);
    }
 
//    else {
//        if(SPIRxDone){
//            RxMessageHandler((MSG*)SPI_Rx_BUFFER);
//            status |= (u32)SPIStatus::SPI_RX;
//        }
//
//        if(SPITxDone && txQueue->Count() > 0){
//            txQueue->Pop(*(MSG*)SPI_Tx_BUFFER);
//            status |= (u32)SPIStatus::SPI_TX;
//        }
//        if(status ) {
//            SPI2_SetTransMode((SPIStatus)status);
//        }
//    }
}