/* * Copyright (c) 2013-2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== Server.c ======== * */ /* this define must precede inclusion of any xdc header file */ #define Registry_CURDESC Test__Desc #define MODULE_NAME "Server" /* xdctools header files */ #include #include #include #include #include #include #include /* package header files */ #include #include #include #include #include #include "ti/osal/SemaphoreP.h" /* local header files */ #include "../shared/AppCommon.h" /* module header file */ #include "Server.h" #define VIRT1 (-0x90000000U) /* PA 0xA0000000<->VA 0x10000000, see RSC table */ /* module structure */ typedef struct { UInt16 hostProcId; // host processor id MessageQ_Handle slaveQue; // created locally } Server_Module; /* private data */ Registry_Desc Registry_CURDESC; static Server_Module Module; #define TEST_PORT 0 UInt32 *pRxPkt; extern UInt32 packetLength; UInt32 *pGoosePara; UInt32 bGooseFilter = 1; extern void Goose_para_config(); extern void *icssRxSem; extern void icss_rx(); extern void icss_tx(); extern void icss_tx_mpu(UInt32 *PTxPacket, Int TxPacketLen); /* * ======== Server_init ======== */ Void Server_init(Void) { Registry_Result result; /* register with xdc.runtime to get a diags mask */ result = Registry_addModule(&Registry_CURDESC, MODULE_NAME); Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL); /* initialize module object state */ Module.hostProcId = MultiProc_getId("HOST"); } /* * ======== Server_create ======== */ Int Server_create() { Int status = 0; MessageQ_Params msgqParams; char msgqName[32]; /* enable some log events */ Diags_setMask(MODULE_NAME"+EXF"); /* create local message queue (inbound messages) */ MessageQ_Params_init(&msgqParams); sprintf(msgqName, App_SlaveMsgQueName, MultiProc_getName(MultiProc_self())); Module.slaveQue = MessageQ_create(msgqName, &msgqParams); if (Module.slaveQue == NULL) { status = -1; goto leave; } Log_print0(Diags_INFO,"Server_create: server is ready"); leave: Log_print1(Diags_EXIT, "<-- Server_create: %d", (IArg)status); return (status); } /* * ======== Server_exec ======== */ Int Server_exec() { Int status; Bool running = TRUE; App_Msg * msg; MessageQ_QueueId queId; UInt32 *pRxPkt0, *pRxPkt1; #ifdef TX_FROM_A15 UInt32 *pTxPkt0, *pTxPkt1; #endif Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_exec:"); while (running) { /* wait for inbound message */ status = MessageQ_get(Module.slaveQue, (MessageQ_Msg *)&msg, MessageQ_FOREVER); if (status < 0) { goto leave; } if (msg->cmd == App_CMD_GOOSE_DISABLE) bGooseFilter = 0; if (msg->cmd == App_CMD_CMEMBUF) { pRxPkt0 = (UInt32 *)(msg->RxPhysAddr[TEST_PORT][0] + VIRT1); pRxPkt1 = (UInt32 *)(msg->RxPhysAddr[TEST_PORT][1] + VIRT1); pRxPkt = pRxPkt0; #ifdef TX_FROM_A15 pTxPkt0 = (UInt32 *)(msg->TxPhysAddr[TEST_PORT][0] + VIRT1); pTxPkt1 = (UInt32 *)(msg->TxPhysAddr[TEST_PORT][1] + VIRT1); #endif pGoosePara = (UInt32 *)(msg->GooseParaPhysAddr + VIRT1); Goose_para_config(); } if (msg->cmd == App_CMD_SHUTDOWN) { running = FALSE; } /* process the message */ Log_print1(Diags_INFO, "Server_exec: processed cmd=0x%x", msg->cmd); /* send message back */ queId = MessageQ_getReplyQueue(msg); /* type-cast not needed */ if(msg->cmd == App_CMD_PACKET) { #ifdef TX_FROM_A15 /* send packets from host A15 */ numBuf = msg->nTxBuf; TxPktLen = msg->TxPktLen[TEST_PORT][numBuf]; if(TxPktLen != 0 ) { if(numBuf == 0) { icss_tx_mpu(pTxPkt0, TxPktLen); } else { icss_tx_mpu(pTxPkt1, TxPktLen); } } #endif icss_tx(); icss_rx(); if (pRxPkt == pRxPkt0) { pRxPkt = pRxPkt1; msg->RxPktLen[TEST_PORT][0] = packetLength; msg->nRxBuf = 0; } else { pRxPkt = pRxPkt0; msg->RxPktLen[TEST_PORT][1] = packetLength; msg->nRxBuf = 1; } #ifdef MONITOR_RECV_PACKET /* log received packets */ for(j=0; jport = TEST_PORT; } MessageQ_put(queId, (MessageQ_Msg)msg); } /* while (running) */ leave: Log_print1(Diags_EXIT, "<-- Server_exec: %d", (IArg)status); return(status); } /* * ======== Server_delete ======== */ Int Server_delete() { Int status; Log_print0(Diags_ENTRY, "--> Server_delete:"); /* delete the video message queue */ status = MessageQ_delete(&Module.slaveQue); if (status < 0) { goto leave; } leave: if (status < 0) { Log_error1("Server_finish: error=0x%x", (IArg)status); } /* disable log events */ Log_print1(Diags_EXIT, "<-- Server_delete: %d", (IArg)status); Diags_setMask(MODULE_NAME"-EXF"); return(status); } /* * ======== Server_exit ======== */ Void Server_exit(Void) { /* Note that there isn't a Registry_removeModule() yet: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=315448 * * ... but this is where we'd call it. */ }