#include "HX_SRIO_App.h"
static UINT8* gOBMsgBufTemp = NULL;
static UINT8* gOBAlignMsgBuf = NULL;
static UINT8* gIBMsgBufTemp = NULL;
static UINT8* gIBAlignMsgBuf = NULL;
static UINT8* gSendBufTemp = NULL;
static UINT8* gSendAlignMsgBuf = NULL;
static UINT8* gRecvBufTemp = NULL;
static UINT8 gSRIOInitFlag = FALSE;
static UINT32 gSendBufCount = 0;
static volatile MSG_Q_ID gSRIOSendMsgQueue = (MSG_Q_ID) NULL; /*消息队列*/
volatile SEM_ID gSRIOSendSemId = NULL;
volatile SEM_ID gSRIORecvSemId = NULL;
static UINT8 gSRIORecvTaskFlag = FALSE;
static UINT8 gSRIOSendTaskFlag = FALSE;
static UINT8 gSRIOErrorTaskFlag = FALSE;
static UINT32 gRecvAddrList[SRIO_RECV_CACHE_NUM] = {0};
UINT32 gRecvAddrCount = 0;
UINT32 gRecvBufCacheCount = 0;
UINT32 gRecvBufOutCount = 0;
UINT32 gCount = 0;
void InBMsgIntFunc(void)
{
VINT32 isr0 = 0;
UINT32 imfqdpar0 = 0;
SRIO_REG_READ((SRIOBA + RIO_IM0SR_OFFSET),isr0);
if(isr0 & ISR_MIQ_MASK)
{
SRIO_REG_READ((SRIOBA + RIO_IM0FQDPAR_OFFSET),imfqdpar0);
/*ib地址往后偏移*/
gRecvAddrList[gRecvAddrCount] = imfqdpar0;
gRecvAddrCount = (gRecvAddrCount + 1) % SRIO_RECV_CACHE_NUM;
semGive(gSRIORecvSemId);
gCount++;
SRIO_REG_READ((SRIOBA + RIO_IM0MR_OFFSET),isr0);
SRIO_REG_WRITE((SRIOBA + RIO_IM0MR_OFFSET),(isr0 | IMR_MI_MASK));
}
SRIO_REG_READ((SRIOBA + RIO_IM0SR_OFFSET), isr0);
SRIO_REG_WRITE((SRIOBA + RIO_IM0SR_OFFSET),isr0 | 0x01);
}
void OutBMsgIntFunc(void)
{
semGive(gSRIOSendSemId);
SRIO_REG_WRITE(SRIOBA + RIO_OM0SR_OFFSET,0x02);
}
void SRIOErrorMsgIntFunc(void)
{
logMsg("ERRORERRORERRORERRORERRORERRORERRORERRORERROR\r\n",0,0,0,0,0,0);
}
static STATUS SRIODataRecvTaskRun(void)
{
UINT8 *pDataTemp = NULL;
while(gSRIORecvTaskFlag)
{
semTake(gSRIORecvSemId, WAIT_FOREVER);
while(gRecvBufCacheCount != gRecvAddrCount)
{
pDataTemp = gRecvBufTemp + (gRecvBufCacheCount*SRIO_PER_RECV_NUM);
memcpy(pDataTemp,((UINT8*)gRecvAddrList[gRecvBufCacheCount]),SRIO_PER_RECV_NUM);
gRecvBufCacheCount = (gRecvBufCacheCount + 1) % SRIO_RECV_CACHE_NUM;
}
}
return OK;
}
static STATUS SRIODataSendTaskRun(void)
{
int lMsgLen = 0;
TSendSRIOStu tempSendMsg = {0};
int retrySend = 0;
while(gSRIOSendTaskFlag)
{
lMsgLen = msgQReceive(gSRIOSendMsgQueue, (char *)(&tempSendMsg), sizeof(TSendSRIOStu), WAIT_FOREVER);
if(lMsgLen != sizeof(TSendSRIOStu))
{
continue;
}
semTake(gSRIOSendSemId, WAIT_FOREVER);
retrySend = 0;
while(retrySend < SRIO_RETRY_SENDNUM)
{
if(SUCCESS == SRIO_Send_Msg(tempSendMsg.dest_id,tempSendMsg.bytecount,tempSendMsg.message))
{
break;
}
retrySend++;
}
if(retrySend >= SRIO_RETRY_SENDNUM)
{
retrySend = 0;
logMsg("FUNC<%s> Resending the message 10 times was not successful\r\n",__FUNCTION__,0,0,0,0,0);
continue;
}
}
return OK;
}
static STATUS SRIODataErrorTaskRun(void)
{
return OK;
}
STATUS interFaceInitSRIO(void)
{
UINT32 osr0 = 0,osar0 = 0;
UINT32 om0dqdpar = 0;
UINT32 frmsize = 0, qsize = 0;
UINT32 isr0 = 0,imr0 = 0;
UINT32 res = 0;
int srioRecvTaskID = 0;
int srioSendTaskID = 0;
int srioErrorTaskID = 0;
if(TRUE == gSRIOInitFlag)
{
return OK;
}
/*set SRIO0 host ID*/
SRIO_REG_READ((SRIOBA + RIO_BIDCSR),res);
res = res | (0x1<<20); // port1 target id 0x17
SRIO_REG_WRITE((SRIOBA + RIO_BIDCSR),res);
/*init outbound*/
gOBMsgBufTemp = (UINT8 *) malloc(sizeof(msg_desc) * OBMSG_CIRQ_SIZE + ADD_MSG_BUF_SIZE);
if(NULL == gOBMsgBufTemp)
{
logMsg("FUNC<%s> Malloc gOBMsgBufTemp is ERROR.\r\n",__FUNCTION__,0,0,0,0,0);
return ERROR;
}
gOBAlignMsgBuf = (UINT8 *)((UINT32) (gOBMsgBufTemp+ALINGN_MSG_BUF_SIZE) & (~(ALINGN_MSG_BUF_SIZE - 1)));
logMsg("FUNC<%s> gOBMsgBufTemp=0x%x,gOBAlignMsgBuf=0x%x\r\n",__FUNCTION__,gOBMsgBufTemp,gOBAlignMsgBuf,0,0,0);
if(SUCCESS != init_chaining_ob_msgs(gOBAlignMsgBuf))
{
return ERROR;
}
/*init inbound*/
gIBMsgBufTemp = (UINT8 *) malloc(sizeof(UINT8) * MAX_IBFRM_SIZE * MAX_IBCIRQ_SIZE + ADD_MSG_BUF_SIZE);
if(NULL == gIBMsgBufTemp)
{
logMsg("FUNC<%s> Malloc gIBMsgBufTemp is ERROR.\r\n",__FUNCTION__,0,0,0,0,0);
return ERROR;
}
gIBAlignMsgBuf = (UINT8 *)((UINT32) (gIBMsgBufTemp+ALINGN_MSG_BUF_SIZE) & (~(ALINGN_MSG_BUF_SIZE - 1)));
logMsg("FUNC<%s>gIBMsgBufTemp=0x%x,gIBAlignMsgBuf=0x%x\r\n",__FUNCTION__,gIBMsgBufTemp,gIBAlignMsgBuf,0,0,0);
if(SUCCESS != init_ib_msgs(gIBAlignMsgBuf,MAX_IBFRM_SIZE,MAX_IBCIRQ_SIZE))
{
return ERROR;
}
gSendBufTemp = (UINT8 *) malloc(sizeof(UINT8) * SRIO_SEND_BUF_NUM + ADD_MSG_BUF_SIZE);
if(NULL == gSendBufTemp)
{
logMsg("FUNC<%s> Malloc gSendBufTemp is ERROR.\r\n",__FUNCTION__,0,0,0,0,0);
return ERROR;
}
gSendAlignMsgBuf = (UINT8 *)((UINT32) (gSendBufTemp+ALINGN_MSG_BUF_SIZE) & (~(ALINGN_MSG_BUF_SIZE - 1)));
gRecvBufTemp = (UINT8 *) malloc(sizeof(UINT8) * SRIO_SEND_BUF_NUM);
if(NULL == gRecvBufTemp)
{
logMsg("FUNC<%s> Malloc gRecvBufTemp is ERROR.\r\n",__FUNCTION__,0,0,0,0,0);
return ERROR;
}
/*创建消息队列*/
gSRIOSendMsgQueue = msgQCreate(SRIO_SEND_CACHE_NUM, sizeof(TSendSRIOStu), MSG_Q_FIFO);
if(NULL == gSRIOSendMsgQueue)
{
logMsg("FUNC<%s> gSRIOSendMsgQueue creation failed..\n",(int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
gSRIOSendSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
if(NULL == gSRIOSendSemId)
{
logMsg("FUNC<%s>:Create gSRIOSendSemId Sem error...\n", (int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
semGive(gSRIOSendSemId);
gSRIORecvSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
if(NULL == gSRIORecvSemId)
{
logMsg("FUNC<%s>:Create gSRIORecvSemId Sem error...\n", (int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
gSRIORecvTaskFlag = TRUE;
srioSendTaskID = taskSpawn("SRIORecvTask", SRIO_RECV_PRIORTY, 0, 8*1024, SRIODataRecvTaskRun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if(ERROR == srioRecvTaskID)
{
logMsg("FUNC<%s> SRIOSendTask creation failed..\n", (int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
gSRIOSendTaskFlag = TRUE;
srioSendTaskID = taskSpawn("SRIOSendTask", SRIO_SEND_PRIORTY, 0, 8*1024, SRIODataSendTaskRun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if(ERROR == srioRecvTaskID)
{
logMsg("FUNC<%s> SRIOSendTask creation failed..\n", (int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
gSRIOErrorTaskFlag = TRUE;
srioErrorTaskID = taskSpawn("SRIOErrorTask", SRIO_ERROR_PRIORTY, 0, 8*1024, SRIODataErrorTaskRun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if(ERROR == srioRecvTaskID)
{
logMsg("FUNC<%s> SRIOSendTask creation failed..\n", (int) __FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
intDisable(SRIO1_OUTBINI_NUM);
intConnect(INUM_TO_IVEC(SRIO1_OUTBINI_NUM),(VOIDFUNCPTR)OutBMsgIntFunc,0);
intEnable(SRIO1_OUTBINI_NUM);
intDisable(SRIO1_INBINI_NUM);
intConnect(INUM_TO_IVEC(SRIO1_INBINI_NUM),(VOIDFUNCPTR)InBMsgIntFunc,0);
intEnable(SRIO1_INBINI_NUM);
// intDisable(SRIO_ERRORINI_NUM);
// intConnect(INUM_TO_IVEC(SRIO_ERRORINI_NUM),(VOIDFUNCPTR)SRIOErrorMsgIntFunc,0);
// intEnable(SRIO_ERRORINI_NUM);
gSRIOInitFlag = TRUE;
return OK;
}
STATUS interFaceSRIOSendMsg(UINT32 dest_id,UINT32 bytecount,UINT8 *message)
{
TSendSRIOStu tempSendMsg = {0};
UINT8* pTempMsg = NULL;
UINT8* pAlignMsg = NULL;
if((0 == dest_id) || (0 == bytecount) || (NULL == message) || (bytecount > SRIO_PER_SEND_NUM))
{
logMsg("FUNC<%s> Input parameter error.dest_id = %d,bytecount=%d\n",__FUNCTION__,dest_id,bytecount,0,0,0);
return ERROR;
}
if(0 != (bytecount&(bytecount-1)))
{
logMsg("FUNC<%s> The sending length=%d is not to the 2 power.\n",__FUNCTION__,bytecount,0,0,0,0);
return ERROR;
}
/*检查消息队列是否存在*/
if(NULL == gSRIOSendMsgQueue)
{
logMsg("FUNC<%s> gSRIOSendMsgQueue invalid.\n",__FUNCTION__, 0, 0, 0, 0, 0);
return ERROR;
}
if((gSendBufCount + bytecount) > SRIO_