/* * protocol.c * Description: * * Created on: 2014-10-11 * Author: Graydon * Modify: */ #include #include #include #include #include #include "drv/board_sru.h" #include "drv/global.h" #include "drv/spi.h" #include "drv/hmem.h" #include "drv/sport.h" #include "protocol.h" #include "queue.h" #include "scene.h" #include "f2f.h" #include "execute.h" #include "sport.h" int scene_loading= 1; void* htx_que; int input_num_channels = 16; int output_num_channels = 16; int local_input_channels_num =8; int local_output_channels_num =8; int dante_input_channels_num =8; int dante_output_channels_num =8; int dual_dsp =0; int dsp_index =0; int hardware_ver = 0; int usb_master = 0; int handshake_successful =0; int clock_ok = 0; int hardware_type =0; int module_list =0; extern int dsp_status; extern void* netvoice_handle[4]; int topo_state = PRESET_NONE; //0-no preset,1-preset loading,2-preset done. static int ClockConfig = 0; void msg_send_level(void) { int i; int data_len; short* ptr; int size = GetLevelPtr(&ptr); int ntotals=(size+SPI_DATA_LEN-1)/SPI_DATA_LEN; extern short cpu_ulitily ; extern short mem_ulitily; tag_msg msg; //size = sizeof(Meter); msg.magic = 0x5aa5; msg.ctype = MSG_GET_LEVEL; msg.pkt_total_num = ntotals; msg.request_id_lsb = size; msg.request_id_msb = 0; //·Ö°ü for(i=0;ihardware_type; module_list = p->modulelist; //ÌØÊâ´¦Àí,32x32Dante ¸Ä³É16Ä£Äâ+16Dante,¶ÔDSPÎÞÓ°Ïì¡£ if(p->dante_rx_num == 32 && p->dante_tx_num == 32 && p->local_rx_num == 0 && p->local_tx_num == 0){ local_input_channels_num = 16; local_output_channels_num = 16; dante_input_channels_num = 16; dante_output_channels_num = 16; } else{ 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 = local_input_channels_num+dante_input_channels_num; output_num_channels = local_output_channels_num+dante_output_channels_num; if(input_num_channels>32){ input_num_channels = 32; } if(output_num_channels>32){ output_num_channels = 32; } dual_dsp = p->dual_dsp; dsp_index = p->dsp_index; hardware_ver = p->hardware_ver; usb_master = p->usb_master; p->scene_size = sizeof(tag_parameters); p->level_num = 0; //12x8, == 12x12+12x8 if(dual_dsp==1 && dsp_index == 0 ){ local_output_channels_num = local_input_channels_num; output_num_channels = local_output_channels_num+dante_output_channels_num; } if(ClockConfig == 0){ if(hardware_ver == HARDWARE_NX){ AudioConfigNx(dual_dsp, dsp_index, usb_master); InitSRC(); InitSPORT(0x03,RATE_SAMPLES); interruptcb(SIG_SP1, sport_isr); interruptcb(SIG_SP3, sport3_isr); interruptcb(SIG_SP5, sport_usb_isr); //interrupts(SIG_SP1, sport_isr); //interrupts(SIG_SP3, sport3_isr); //interrupts(SIG_SP5, sport_usb_isr); } else{ AudioConfigRule(dual_dsp, dsp_index, p->external_clock); InitSRC(); InitSPORT(0x03,RATE_SAMPLES); interruptcb(SIG_SP1, sport_isr); interruptcb(SIG_SP5, sport_usb_isr); } ClockConfig = 1; } handshake_successful = 1; return 1; } int msg_dispatch(ptag_msg pmsg) { int i; int data_len; int np,ntotals; static int on =0; static int error=0; if(pmsg->magic!=0x5aa5){ // =========FOR DEBUG============ if(on){ SRU(LOW, DPI_PB14_I); } else{ SRU(HIGH,DPI_PB14_I); } error++; if((error&0xf)==0){ on=!on; } //=============================== return -1; } data_len=(pmsg->len>>1); np=pmsg->pkt_no&0xffff; ntotals =pmsg->pkt_total_num&0xffff; switch(pmsg->ctype&0xff){ case MSG_PARAM_CTRL: pmsg->data[2]=NORMALIZE(pmsg->data[2]); pmsg->data[3]=NORMALIZE(pmsg->data[3]); scene_ctrl(pmsg->data[0],pmsg->data[1],(int*)&pmsg->data[2],1); //queue_push(htx_que,pmsg,SPI_PKT_SIZE); break; case MSG_GET_LEVEL: if(scene_loading == 0 && clock_ok == 1){ msg_send_level(); } else{ LevelEmpty(); } break; case MSG_NETVOICE_CHANNEL_REQ: if(pmsg->request_id_lsb == 0){ // alg_netvoice_put_frame(netvoice_handle[0], pmsg->data, data_len); } if(pmsg->request_id_lsb == 1){ // alg_netvoice_put_frame(netvoice_handle[2], pmsg->data, data_len); } break; case MSG_PARAM_CONFIG: scene_loading = 1; scene_cpy(np,(void*)pmsg->data,data_len); case MSG_PARAM_COMPLETED: if(np == ntotals-1){ scene_destroy(); scene_analyze(); topo_state = PRESET_DONE; scene_loading = 0; } break; case MSG_ACK_REQ: if(msg_handshake_ack((ptag_hwconf)pmsg->data)){ queue_push(htx_que,pmsg,SPI_PKT_SIZE); } break; case MSG_CHANNEL_COPY_REQ: scene_channel_copy((ptag_channel_copy)pmsg->data); break; case MSG_DSP_STATUS_REQ: pmsg->data[0] = dsp_status; pmsg->ctype = MSG_DSP_STATUS_RES; queue_push(htx_que,pmsg,SPI_PKT_SIZE); break; default: break; } return 0; } void msg_process() { spi_status_e spi_status = spi_get_status(); //tag_msg msg; if(spi_status == spi_completed){ //ÅжÏÊǽÓÊÕ»¹ÊÇ·¢ËÍÍê³É spi_direction_e spi_dir = spi_get_direction(); void* spi_buffer = spi_get_buffer(); if(spi_dir == spi_rx){ //memcpy(&msg, spi_buffer, 512); msg_dispatch(spi_buffer); } //¸ù¾Ý·¢ËͶÓÁÐÅжÏÏÂÒ»°üÅäÖ÷¢ËÍ»¹ÊǽÓÊÕ if(queue_count(htx_que)>=SPI_PKT_SIZE){ queue_pop(htx_que,spi_buffer,SPI_PKT_SIZE); 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¿ÉÓà } }