/*
|
* messageproc.c
|
*
|
* Created on: 2021Äê11ÔÂ1ÈÕ
|
* Author: graydon
|
*/
|
#include <string.h>
|
#include <stdlib.h>
|
#include <sru.h>
|
#include <def1802.h>
|
#include <cdef1802.h>
|
#include <heapnew>
|
#include "messageproc.h"
|
#include "../drv/spi.h"
|
#include "../drv/memory.h"
|
#include "queue.h"
|
#include "tob.h"
|
#include "F2F.h"
|
//#include "../drv/sru_dai.h"
|
#include "../drv/fir_acc.h"
|
#include <time.h>
|
//#include "convert.h"
|
#include "protocol.h"
|
#include "scene.h"
|
#include "ParamCtrl.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 )
|
{
|
return txQueue->Push(*pmsg);
|
}
|
|
|
s32 Message::LevelProcess(MSG* pmsg)
|
{
|
ToB* tob = ToB::GetInstance();
|
if(tob ) {
|
s16 buffer[1600];
|
u32 n = tob->GetLevels(buffer);
|
u32 data_len ;
|
u32 total_pkts = (n + SPI_DATA_LEN-1)/SPI_DATA_LEN;
|
|
//for(u32 i =0 ;i < n;i++) buffer[i] = i;
|
pmsg->totalPkts = total_pkts;
|
pmsg->msgIDLSB = n;
|
pmsg->msgIDMSB = 0;
|
|
for(u32 i=0; i< total_pkts; i++){
|
if(i == total_pkts-1){
|
data_len = n - i*SPI_DATA_LEN;
|
}
|
else{
|
data_len = SPI_DATA_LEN;
|
}
|
|
pmsg->pktNo = i;
|
pmsg->Enc(MsgType::MSG_LEVEL_GET_REQ, buffer+i*SPI_DATA_LEN, data_len<<1);
|
Send(pmsg) ;
|
}
|
}
|
return 0;
|
}
|
|
s32 Message::PresetProcess(MSG* pmsg)
|
{
|
// static u8* bin = NULL;
|
// extern ubool TopoLoading;
|
//
|
// if(pmsg->pktNo == 0 && bin != NULL ) {
|
// DDRFree(bin);
|
// bin = NULL;
|
// printf("PresetProcess pmsg->pktNo\n");
|
// }
|
// if(pmsg->pktNo == 0 && bin == NULL) {
|
// bin = (u8*)DDRMalloc(pmsg->totalPkts*MSG_DATA_LEN);
|
// dbg_printf("preset address %p.\n", bin);
|
// }
|
// if(bin == NULL) {
|
// printf("PresetProcess\n");
|
// 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;
|
//
|
// if(tob) tob->toCtrl(bin, size);
|
//
|
// DDRFree( bin);
|
// bin = NULL;
|
// TopoLoading = ufalse;
|
// Send(MsgType::MSG_PRESET_RES, 0 ,0) ;
|
// }
|
|
return 0;
|
}
|
|
s32 Message::PresetProcess(MSG* pmsg, int pad)
|
{
|
extern ubool TopoLoading;
|
s32 ret = 0;
|
|
ToB* tob = ToB::GetInstance();
|
tob->SetMute(utrue);
|
TopoLoading = utrue;
|
|
scene_cpy(pmsg->pktNo,(void*)pmsg->data,pmsg->dataLen);
|
|
if(pmsg->pktNo == pmsg->totalPkts -1) {
|
ret = TopoProcess();
|
|
TopoLoading = ufalse;
|
|
|
Send(MsgType::MSG_PRESET_RES, (u8*)&ret ,1) ;
|
}
|
|
return 0;
|
}
|
|
s32 Message::TopoProcess(MSG* pmsg)
|
{
|
// extern ubool TopoLoading;
|
// extern uvoid SetNumOfChannels(u16 rxNum, u16 txNum);
|
// static u8* bin = NULL;
|
// ToB* tob = ToB::GetInstance();
|
// u32 size =0;
|
//
|
// tob->SetMute(utrue);
|
// TopoLoading = utrue;
|
//
|
// if(pmsg->pktNo == 0 && bin != NULL ) {
|
// DDRFree(bin);
|
// bin = NULL;
|
// }
|
// if(pmsg->pktNo == 0 && bin == NULL) {
|
// bin = (u8*)DDRMalloc(pmsg->totalPkts*MSG_DATA_LEN);
|
// size =0 ;
|
// }
|
// if(bin == NULL) return -1;
|
//
|
// memcpy(bin+pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
|
// if(pmsg->pktNo == pmsg->totalPkts -1) {
|
// size = (pmsg->totalPkts -1)*MSG_DATA_LEN+pmsg->dataLen;
|
// SetNumOfChannels(0, 0);
|
// if(tob) {
|
// fir_acc_delete();
|
// tob->toClear();
|
// tob->CreateModule(bin, size);
|
// fir_acc_startup();
|
// }
|
// DDRFree( bin);
|
// bin = NULL;
|
//
|
// Send(MsgType::MSG_TOPO_RES, 0 ,0) ;
|
// }
|
|
return 0;
|
}
|
|
s32 Message::TopoProcess()
|
{
|
extern ubool TopoLoading;
|
extern uvoid SetNumOfChannels(u16 rxNum, u16 txNum);
|
char *bin = (char*)DDRMalloc(8*1024);//new char[8*1024];//
|
int size = 0;
|
int scene_size = 0;
|
|
ToB* tob = ToB::GetInstance();
|
|
//tob->SetMute(utrue);
|
//TopoLoading = utrue;
|
|
if(bin == NULL) return -1;
|
|
scene_type_update();
|
|
SetNumOfChannels(0, 0);
|
if(tob) {
|
fir_acc_delete();
|
tob->toClear();
|
SceneToDSPFlowchart(bin, &size);
|
tob->CreateModule((u8*)bin, size,NULL);
|
fir_acc_startup();
|
}
|
|
DDRFree(bin);
|
//delete[] bin;
|
bin = NULL;
|
|
return scene_size;
|
}
|
|
s32 Message::ParamCtrl(MSG* pmsg)
|
{
|
ToB* tob = ToB::GetInstance();
|
|
if(!ConfiGurable){
|
ptag_cmd pcmd = (ptag_cmd)pmsg->data;
|
if(tob != NULL){
|
tob->toCtrl(pcmd->proc_id, pcmd->cmd, pcmd->val);
|
dbg_printf("proc_id %d .\n", pcmd->proc_id);
|
}
|
|
return 0;
|
}
|
|
|
// if(pmsg->totalPkts > 1) {
|
// static s16* bin = NULL;
|
//
|
// if(pmsg->pktNo == 0 && bin != NULL) {
|
// delete[] bin; bin = NULL;
|
// }
|
// if(bin == NULL) {
|
// bin = new s16[pmsg->totalPkts*MSG_DATA_LEN];
|
// }
|
// memcpy(bin+ pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
|
// dbg_printf("ParamCtrl %d(%d).\n", pmsg->totalPkts,pmsg->pktNo);
|
// if(pmsg->pktNo == pmsg->totalPkts-1) {
|
// Param * ptr = (Param *)bin;
|
// s16 * data = (s16*)(bin+sizeof(Param));
|
//
|
// if(tob != NULL){
|
// tob->toCtrl(ptr->mID, ptr->pID, data, ptr->num);
|
// dbg_printf("PID %d num %d.\n", ptr->pID,ptr->num);
|
// }
|
// delete[] bin; bin = NULL;
|
// }
|
// }
|
// else {
|
// Param * ptr = (Param *)pmsg->data;
|
// s16 * data = (s16*)(pmsg->data+sizeof(Param));
|
//
|
// if(tob != NULL){
|
// tob->toCtrl(ptr->mID, ptr->pID, data, ptr->num);
|
// dbg_printf("PID %d num %u.\n", ptr->pID, ptr->num);
|
// }
|
// }
|
|
return 0;
|
}
|
|
#if 0
|
s32 Message::SystemConfigSetProcess(MSG* pmsg)
|
{
|
extern ubool HandShakeSuccesful;
|
extern u16 mDspIndex;
|
DSPConfig* conf = (DSPConfig*)pmsg->data;
|
|
if(HandShakeSuccesful == ufalse) {
|
SAMPLE_NUM = conf->mSampleNum;
|
SAMPLE_RATE = (conf->mSampleRateH<<16)|conf->mSampleRateL;
|
|
mDspIndex = conf->mDspIndex;
|
new ToB(conf->mDualDsp , conf->mDspIndex);
|
|
RouteConfig(conf->routes,conf->mRouteNum);
|
SportsConfig(conf->sports);
|
SRCsConfig(conf->srcs);
|
PCGsConfig(conf->pcgs);
|
|
SetCh(conf->mLocalRxNum, conf->mLocalTxNum, conf->mDanteRxNum, conf->mDanteTxNum);
|
HandShakeSuccesful = utrue;
|
}
|
|
Send(MsgType::MSG_HANDSHAKE_RES, 0 , 0);
|
|
return 0;
|
}
|
#else
|
s32 Message::SystemConfigSetProcess(MSG* pmsg)
|
{
|
extern ubool HandShakeSuccesful;
|
extern u16 mDspIndex;
|
|
extern int input_num_channels;
|
extern int output_num_channels;
|
|
extern int local_input_channels_num;
|
extern int local_output_channels_num;
|
extern int dante_input_channels_num;
|
extern int dante_output_channels_num;
|
|
if(HandShakeSuccesful == ufalse) {
|
ptag_hwconf p = (ptag_hwconf)pmsg->data;
|
|
local_input_channels_num = p->local_rx_num;
|
local_output_channels_num = p->local_tx_num;
|
dante_input_channels_num = p->dante_rx_num;
|
dante_output_channels_num = p->dante_tx_num;
|
|
input_num_channels = p->local_rx_num + p->dante_rx_num;
|
output_num_channels = p->local_tx_num + p->dante_tx_num;
|
|
p->scene_size = sizeof(tag_parameters);
|
|
mDspIndex = p->dsp_index;
|
new ToB(p->dual_dsp, p->dsp_index);
|
|
Audio_Config();
|
|
HandShakeSuccesful = utrue;
|
}
|
|
Send(MsgType::MSG_HANDSHAKE_RES, 0 , 0);
|
|
return 0;
|
}
|
#endif
|
|
s32 Message::PushDSPStatus(u16 ID, s16 value)
|
{
|
if(mDevStatusNum < 32) {
|
mDevStatus[mDevStatusNum].ID = ID;
|
mDevStatus[mDevStatusNum].value[0] = value;
|
mDevStatusNum++ ;
|
}
|
|
return 0;
|
}
|
s32 Message::DSPStatusProcess(MSG* pmsg)
|
{
|
s16* data = (s16*)pmsg->data;
|
u32 n = mDevStatusNum*sizeof(DeviceStatus);
|
|
if( n > 0) {
|
memcpy(data , mDevStatus , n);
|
pmsg->Enc(MsgType::MSG_DSP_STATUS_RES, 0 , n*2);
|
mDevStatusNum = 0;
|
Send(pmsg);
|
}
|
return n;
|
}
|
|
s32 Message::RxMessageHandler(MSG* pmsg)
|
{
|
if(pmsg->magic != 0x5aa5) {
|
return -1;
|
}
|
|
pmsg->dataLen = (pmsg->dataLen>>1);
|
switch(pmsg->msgType&0xff){
|
case MsgType::MSG_LEVEL_GET_REQ:
|
LevelProcess(pmsg);
|
break;
|
case MsgType::MSG_PRESET_REQ:
|
dbg_printf("preset %d(%d).\n", pmsg->totalPkts ,pmsg->pktNo);
|
//if(ConfiGurable) PresetProcess(pmsg);
|
break;
|
case MsgType::MSG_TOPO_REQ:
|
dbg_printf("topo %d(%d).\n", pmsg->totalPkts ,pmsg->pktNo);
|
if(ConfiGurable) TopoProcess(pmsg);
|
else PresetProcess(pmsg,0);
|
break;
|
case MsgType::MSG_PARMA_CTRL_REQ:
|
ParamCtrl(pmsg);
|
break;
|
case MsgType::MSG_HANDSHAKE_REQ:
|
SystemConfigSetProcess(pmsg);
|
break;
|
case MsgType::MSG_CHANNEL_COPY_REQ:
|
scene_channel_copy((ptag_channel_copy)pmsg->data);
|
break;
|
case MsgType::MSG_DSP_STATUS_REQ:
|
DSPStatusProcess(pmsg);
|
break;
|
default:
|
break;
|
}
|
|
return 0;
|
}
|
|
uvoid Message::Proc()
|
{
|
spi_status_e spi_status = spi_get_status();
|
|
if(spi_status == spi_completed){
|
//ÅжÏÊǽÓÊÕ»¹ÊÇ·¢ËÍÍê³É
|
spi_direction_e spi_dir = spi_get_direction();
|
MSG* spi_buffer = (MSG*)spi_get_buffer();
|
|
if(spi_dir == spi_rx){
|
//memcpy(&msg, spi_buffer, 512);
|
RxMessageHandler(spi_buffer);
|
}
|
|
//¸ù¾Ý·¢ËͶÓÁÐÅжÏÏÂÒ»°üÅäÖ÷¢ËÍ»¹ÊǽÓÊÕ
|
if(txQueue->Count() > 0){
|
txQueue->Pop(*spi_buffer);
|
spi_config_dma(spi_tx);
|
SRU(LOW,DPI_PB12_I);
|
}
|
else{
|
spi_config_dma(spi_rx);
|
SRU(HIGH,DPI_PB12_I);
|
}
|
SRU(HIGH,DPI_PB11_I);//֪ͨMCU SPI¿ÉÓÃ
|
}
|
}
|