/*
|
* 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 "F2F.h"
|
#include "ModuleProAPI.h"
|
#include "tg/tg_adapter.h"
|
#include "tg/tg_scene.h"
|
#include "var_state.h"
|
#include "tob.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;
|
}
|
|
uvoid Message::ReportDspStatus(MSG* pmsg)
|
{
|
s32 size = dsp_status_q.get_device_status_ptr(pmsg->data,MSG_DATA_LEN);
|
if(size > 0) {
|
pmsg->Enc(MsgType::MSG_DSP_STATUS_REPORT, 0, size);
|
txQueue->Push(*pmsg);
|
}
|
}
|
|
s32 Message::ParamCtrl(MSG* pmsg)
|
{
|
#define PCTL_MAX_PKT 5
|
#pragma section("seg_ext_pmda")
|
static s8 buffer[MSG_DATA_LEN*PCTL_MAX_PKT];
|
struct ParamCtrl * ptr = (struct ParamCtrl *)buffer;
|
ToB* tob = ToB::GetInstance();
|
|
if(pmsg->totalPkts > PCTL_MAX_PKT || pmsg->pktNo >= pmsg->totalPkts) {
|
return -1 ;
|
}
|
memcpy(buffer + pmsg->pktNo*MSG_DATA_LEN , pmsg->data, pmsg->dataLen);
|
|
if(tob != NULL && pmsg->pktNo == pmsg->totalPkts - 1) {
|
VarState& var = VarState::GetInstance();
|
u32 type = tob->GetModuleType(ptr->mid);
|
s32 data_num = (pmsg->totalPkts-1)*MSG_DATA_LEN+pmsg->dataLen;
|
|
s16* data = (s16*)(ptr + 1);
|
|
data_num = (data_num - sizeof(struct ParamCtrl))/sizeof(s16);
|
|
ptr->mid = var.pscene->get_module_id(ptr->mid, type, ptr->cmd) ;
|
tob->toCtrl(ptr->mid, ptr->cmd, data, data_num);
|
}
|
|
return 0;
|
}
|
|
s32 Message::PresetProcess(MSG* pmsg)
|
{
|
VarState& var = VarState::GetInstance();
|
static u8* bin = NULL;
|
|
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;
|
var.TopoLoading = utrue;
|
memcpy(bin+pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
|
if(pmsg->pktNo == pmsg->totalPkts -1) {
|
u32 size = (pmsg->totalPkts -1)*MSG_DATA_LEN+pmsg->dataLen;
|
|
if(var.pscene) {
|
ToB* tob = ToB::GetInstance();
|
|
SetTxRxNullBufferPtr();
|
for(s32 i =0 ;i < IntDataType::COUNT;i++){
|
SetNumOfChannels(static_cast<IntDataType>(i) , 0, 0);
|
}
|
if(var.pscene->set_parameters_content(bin, size) != 0){
|
//fail
|
var.TopoStatus = PRESET_STA::PRESET_ERR;
|
}
|
else if(tob){
|
s8* content = (s8*)sram_malloc(SRAM_DDR, mem_any ,16*1024);
|
s32 size ;
|
|
var.pscene->update_module();
|
size = var.pscene->convert_to_bin(content);
|
|
tob->toClear();
|
tob->toAnalysis(bin, size);
|
|
sram_free(SRAM_DDR, content);
|
var.TopoStatus = PRESET_STA::PRESET_DONE;
|
}
|
}
|
sram_free(SRAM_DDR, bin); bin = NULL;
|
var.TopoLoading =0 ;
|
}
|
|
return 0;
|
}
|
|
s32 Message::HandshakeMessageProcess(MSG* pmsg)
|
{
|
VarState& var = VarState::GetInstance();
|
|
ptag_device_config device_config = (ptag_device_config)pmsg->data;
|
struct DSPConfig dspconfig ;
|
|
if(var.HandShakeSuccesful == ufalse) {
|
//¿ÉÒÔ¸ù¾Ýptag_device_config.hardware_type¶¯Ì¬ÊÊÅäÐͺÅ.
|
if(var.pscene){
|
delete var.pscene;
|
var.pscene = NULL;
|
}
|
|
hw_adapter_t* _adapter = new tg_hw_adapter_t(device_config->dual_dsp,device_config->dsp_index
|
,device_config->local_rx_num,device_config->local_tx_num
|
,device_config->dante_rx_num,device_config->dante_tx_num);
|
var.pscene = new tgScene(_adapter);
|
|
_adapter->config_board(&dspconfig);
|
|
SAMPLE_NUM = dspconfig.mSampleNum;
|
var.master_intr = dspconfig.mIntrNo;
|
var.g_level_report_interval = LEVEL_REPORT_TIME(dspconfig.mLevelReportInt);
|
|
ModuleLeveldBUSetting(dspconfig.mConvertUnit);
|
//Config(conf);
|
RouteConfig(dspconfig.routes,dspconfig.mRouteNum);
|
SRCsConfig(0 , &dspconfig.srcs[0]);
|
SRCsConfig(1 , &dspconfig.srcs[4]);
|
PCGsConfig(dspconfig.pcgs);
|
SportsConfig(dspconfig.sports);
|
//LinportConfig(dspconfig.linkport);
|
|
var.HandShakeSuccesful = utrue;
|
}
|
|
Send(MsgType::MSG_ACK_REQ, 0 , 0);
|
|
return 0;
|
}
|
|
s32 Message::RxMessageHandler(MSG* pmsg)
|
{
|
extern ubool systemMute;
|
if(pmsg->magic != 0x5aa5) {
|
//printf("magic error.\n");
|
return -1;
|
}
|
|
switch(pmsg->msgType){
|
case MsgType::MSG_PARAM_CTRL:
|
ParamCtrl(pmsg);
|
break;
|
case MsgType::MSG_GET_LEVEL:
|
break;
|
case MsgType::MSG_PARAM_CONFIG:
|
case MsgType::MSG_PARAM_COMPLETED:
|
PresetProcess(pmsg);
|
break;
|
case MsgType::MSG_ACK_REQ:
|
HandshakeMessageProcess(pmsg);
|
break;
|
default:
|
break;
|
}
|
|
return 0;
|
}
|
|
|
|
uvoid Message::Proc()
|
{
|
u32 status = 0;
|
|
if(SPIRxDone) {
|
RxMessageHandler((MSG*)SPI_Rx_BUFFER);
|
if(txQueue->Count() > 0) {
|
txQueue->Pop(*(MSG*)SPI_Tx_BUFFER);
|
GPIO_SetOutPut(GPIOA, GPIO_Pin12, GPIO_LOW);
|
}
|
else {
|
SPI_Tx_BUFFER[0] = 0;
|
GPIO_SetOutPut(GPIOA, GPIO_Pin12, GPIO_HIGH);
|
}
|
SPI2_SetTransMode(SPIStatus::SPI_TRX);
|
GPIO_SetOutPut(GPIOA, GPIO_Pin13, GPIO_HIGH);
|
}
|
}
|