📄 qmcen.c
字号:
/*-----Init BD -------------------*/
temp_bufdes=pData->pBaseRecvBD
=(BuffDescType *)(pGCfg->BDTable+scpm[pCfg->ch].rbase);
for(i=0;i<pData->MaxRecvBD;i++)
{
SPLX(pFreeBuffLnk=LinkGetBuf(&(pGCfg->FreeLink)););
if(pData==NULL) continue;
temp_bufdes[i].status=BD_EMPTY|BD_INTR;
temp_bufdes[i].length=0;
temp_bufdes[i].address=pFreeBuffLnk->Data;
}
if(i>0)temp_bufdes[i-1].status|=BD_WRAP;
/* tx */
temp_bufdes=pData->pBaseSendBD
=(BuffDescType *)(pGCfg->BDTable+scpm[pCfg->ch].tbase);
for(i=0;i<pData->MaxSendBD;i++)
{
SPLX(pFreeBuffLnk=LinkGetBuf(&(pGCfg->FreeLink)););
if(pData==NULL) continue;
temp_bufdes[i].status=BD_INTR|BD_LAST|HDLC_TX_CRC;
temp_bufdes[i].length=pData->MaxBufLen-2;
temp_bufdes[i].address=pFreeBuffLnk->Data;
}
if(i>0)temp_bufdes[i-1].status|=BD_WRAP;
pGCfg->IsrParam[pCfg->ch]=pDataBuf;
LinkInit(&(pCfg->TxLink));
QmcStartOp(pCfg);
}
static void InitLink(QmcGlobalCfgStruct *pGCfg)
{
int i;
SPLX(LinkInit(&(pGCfg->FreeLink)););
for(i=0;i<pGCfg->MaxBufNum;i++)
{
#if 0
LinkBufStruct *buf=(LinkBufStruct *)((ULONG)(pGCfg->UncachedBuffer)
+(sizeof(LinkBufStruct)-LINK_DATA_BUF_LEN
+pGCfg->MaxBufLen)*i);
#endif
LinkBufStruct *buf=(LinkBufStruct *)((ULONG)(pGCfg->UncachedBuffer)
+(sizeof(LinkBufStruct)-LINK_DATA_BUF_LEN+4
+pGCfg->MaxBufLen)*i);
SPLX(LinkAppendBuf(&(pGCfg->FreeLink), buf););
memmove(((char *)buf)-4,"abcd",4);
}
}
void QmcGlobalInit(void *pDataBuf, QmcGlobalCfgStruct *cfg)
{
unsigned long i;
QmcGlobalCfgStruct *pCfg =(QmcGlobalCfgStruct *)(pDataBuf);
PDA *pda =(PDA *)(GetIMMR() & IO_MAP_MASK);
QmcGlobalParamStruct *gmp =(QmcGlobalParamStruct *)((GetIMMR()&IO_MAP_MASK)+0x3C00+0x100*cfg->ch);
memmove(pCfg,cfg,sizeof(*cfg));
memset(gmp,0,sizeof(QmcGlobalParamStruct));
if(pCfg->MaxRecvTSAEntry==0)pCfg->MaxRecvTSAEntry=pCfg->MaxSubChanNum;
if(pCfg->MaxSendTSAEntry==0)pCfg->MaxSendTSAEntry=pCfg->MaxSubChanNum;
/* add switch protocols*/
regs(pCfg->ch).scc_gsmra=0x0;
CPM_CMD((pCfg->ch)<<(2+4)); /* INIT_RX_TX_PARAMS */
if(pCfg->InitTDM!=NULL)pCfg->InitTDM();
pCfg->ch=(pCfg->ch&0x3);
SPLX(pda->cpmi_cimr&=(~(EN_SCC1 >> pCfg->ch));)/* disable scc interrutp */
pCfg->IntTablePtr=pCfg->IntTable;
pda->Scc_regs[pCfg->ch].scc_gsmra &= 0xffffffcf; /*disable rx & tx */
SPLX(pda->si_sicr &= (~( (0x000000ff)<<(pCfg->ch*8) ));)
SPLX(pda->si_sicr |= ( (0x00000040)<<(pCfg->ch*8) );)
SPLX(pda->si_sigmr|=(0x04)<<(pCfg->UseTDM-1);) /*enable static TDM */
/* init Grobal Params*/
gmp->mcbase=(unsigned long)pCfg->BDTable;/* point to the start of BD table*/
gmp->mrblr=pCfg->MaxBufLen-8; /* set the MAX buffer length*/
gmp->intbase=(unsigned long)pCfg->IntTable;/*point to the start of int tab*/
gmp->grfthr=1; /* 1 receive frame to interrupt*/
gmp->grfcnt=1; /* 1 receive frame to interrupt*/
gmp->cmask32=0xdebb20e3; /*32 bit crc constant */
gmp->cmask16=0xf0b8; /*16 bit crc constant */
gmp->intptr=gmp->intbase;
for (i=0;i<32;i++) /*init receive time slot table*/
{
gmp->tsatr[i].w=0;
gmp->tsatr[i].chp=0; /* init one slot to one channel */
gmp->tsatr[i].mask0_1 =0; /* no subchannel */
gmp->tsatr[i].mask2_7 =0;
gmp->tsatr[i].v=0;
}
for (i=0;i<pCfg->MaxRecvTSAEntry;i++)
{
if(pCfg->IsSuperChan==1)
{
gmp->tsatr[i].w=0; /* init config slots to channels */
gmp->tsatr[i].chp=pCfg->RecvTsTable[i];
gmp->tsatr[i].mask0_1 =0x3; /* no subchannel */
gmp->tsatr[i].mask2_7 =0x3f;
gmp->tsatr[i].v=1;
}
else
{
gmp->tsatr[i].w=0; /* init one slot to one channel */
gmp->tsatr[i].chp=i+(pCfg->SubChParamOffset>>6);
gmp->tsatr[i].mask0_1 =0x3; /* no subchannel */
gmp->tsatr[i].mask2_7 =0x3f;
gmp->tsatr[i].v=1;
}
}
gmp->tsatr[i-1].w=1;
for (i=0;i<32;i++) /* init transmit time slot table */
{
gmp->tsatt[i].w=0;
gmp->tsatt[i].chp=0;
gmp->tsatt[i].mask0_1 =0;
gmp->tsatt[i].mask2_7 =0;
gmp->tsatt[i].v=0;
}
for (i=0;i<pCfg->MaxSendTSAEntry;i++) /* init transmit time slot table */
{
if(pCfg->IsSuperChan==1)
{
gmp->tsatt[i].w=0; /* init config slots to channels */
gmp->tsatt[i].chp=pCfg->SendTsTable[i];
gmp->tsatt[i].mask0_1 =0x3; /* no subchannel */
gmp->tsatt[i].mask2_7 =0x3f;
gmp->tsatt[i].v=1;
}
else
{
gmp->tsatt[i].w=0; /* init one slot to one channel */
gmp->tsatt[i].chp=i+(pCfg->SubChParamOffset>>6);
gmp->tsatt[i].mask0_1 =0x3;
gmp->tsatt[i].mask2_7 =0x3f;
gmp->tsatt[i].v=1;
}
}
gmp->tsatt[i-1].w=1;
gmp->rx_s_ptr=0x3C00+0x100*pCfg->ch+0x20; /* init pointer to rsatr */
gmp->tx_s_ptr=0x3C00+0x100*pCfg->ch+0x60; /* init pointer to tsatr */
gmp->rxptr=gmp->rx_s_ptr;
gmp->txptr=gmp->tx_s_ptr;
gmp->qmcstate=0x8000;
/* init the interrupt table */
for(i=0;i<pCfg->IntTableLen;i++)
pCfg->IntTable[i].Word16=0;
if(i>=1)pCfg->IntTable[i-1].Bit.w=1;
InitLink(pCfg);
SPLX(CpmIsrAddHandler(V_SCC1-pCfg->ch,QmcIsr,(void *)pDataBuf); )
}
int QmcCntrl(void *pDataBuf, int cmd, void *pParam, int maxlen)
{
int i;
ULONG temp_ulong;
PDA *pda= (PDA *)(GetIMMR() & IO_MAP_MASK);
DataBufStruct *pData=(DataBufStruct *)pDataBuf;
QmcSubChanCfgStruct *pCfg =(QmcSubChanCfgStruct *)(pData+1);
QmcGlobalCfgStruct *pGCfg=pCfg->pGCfg;
QmcSupChanTsCfgStruct *pQmcTsCfg;
QmcGlobalParamStruct *gmp;
int ret=BDCntrl(pDataBuf, cmd, pParam, maxlen);
if(ret!=SDE_UNKNOW_CMD)return ret;
switch(cmd)
{
case SDC_REINIT: /* WARN!!! This is cmd will effect other subch!! */
for(i=0;i<pGCfg->MaxSubChanNum;i++)
{
QmcStopOp( (QmcSubChanCfgStruct*)((DataBufStruct *)
(pGCfg->IsrParam[i+pGCfg->SubChParamOffset/64])+1) );
}
QmcGlobalInit(pCfg->pGCfg,pCfg->pGCfg);
for(i=0;i<pGCfg->MaxSubChanNum;i++)
{
memset((pGCfg->IsrParam)[i+pGCfg->SubChParamOffset/64],0,
sizeof(DataBufStruct));
QmcSubChanInit((DataBufStruct *)(pGCfg->IsrParam
[i+pGCfg->SubChParamOffset/64]),(QmcSubChanCfgStruct*)
((DataBufStruct *)(pGCfg->IsrParam[i+pGCfg->SubChParamOffset/64])+1) );
}
QmcInitEnd(pCfg->pGCfg);
break;
case SDC_SET_TSA_LOOPBACK_MODE: /* WARN!!! effect other subch!! */
if(pCfg->pGCfg->UseTDM==0)return SDE_UNKNOW_CMD;
if(pCfg->pGCfg->UseTDM==1)SPLX(pda->si_simode|=0x00000c00;)
if(pCfg->pGCfg->UseTDM==2)SPLX(pda->si_simode|=0x0c000000;)
break;
case SDC_SET_NORMAL_MODE: /* WARN!!! effect other subch!! */
if(pCfg->pGCfg->UseTDM==0)return SDE_UNKNOW_CMD;
if(pCfg->pGCfg->UseTDM==1)SPLX(pda->si_simode&=0xfffff3ff;)
if(pCfg->pGCfg->UseTDM==2)SPLX(pda->si_simode&=0xf3ffffff;)
break;
case SDC_SET_TX_NO_CRC_MODE:
QmcStopOp(pCfg);
QmcResetSubChan(pData,pCfg);
for(i=0;i<pData->MaxSendBD;i++)
pData->pBaseSendBD[i].status &= (~HDLC_TX_CRC);
QmcStartOp(pCfg);
break;
case SDC_SET_TS_MAP:
if(maxlen!=sizeof(QmcSupChanTsCfgStruct))
return SDE_INVALID_ARG;
pQmcTsCfg=(QmcSupChanTsCfgStruct*)pParam;
for(i=0;i<pGCfg->MaxRecvTSAEntry;i++)
if((pQmcTsCfg->RecvTsTable[i]>=pGCfg->MaxSubChanNum+(pGCfg->SubChParamOffset>>6) )
||(pQmcTsCfg->RecvTsTable[i]<(pGCfg->SubChParamOffset>>6)) )
return SDE_INVALID_ARG;
for(i=0;i<pGCfg->MaxSendTSAEntry;i++)
if((pQmcTsCfg->SendTsTable[i]>=pGCfg->MaxSubChanNum+(pGCfg->SubChParamOffset>>6))
||(pQmcTsCfg->SendTsTable[i]<(pGCfg->SubChParamOffset>>6))
)
return SDE_INVALID_ARG;
memmove(pGCfg->RecvTsTable,pQmcTsCfg,sizeof(QmcSupChanTsCfgStruct));
pGCfg->IsSuperChan=1;
gmp =(QmcGlobalParamStruct *)((GetIMMR()&IO_MAP_MASK)+0x3C00+0x100*pGCfg->ch);
for (i=0;i<32;i++) /*init receive time slot table*/
{
gmp->tsatr[i].v=0;
gmp->tsatr[i].chp=0; /* init one slot to one channel */
gmp->tsatr[i].mask0_1 =0; /* no subchannel */
gmp->tsatr[i].mask2_7 =0;
}
for (i=0;i<pGCfg->MaxRecvTSAEntry;i++)
{
gmp->tsatr[i].chp=pQmcTsCfg->RecvTsTable[i];
gmp->tsatr[i].mask0_1 =0x3; /* no subchannel */
gmp->tsatr[i].mask2_7 =0x3f;
gmp->tsatr[i].v=1;
}
gmp->tsatr[i-1].w=1;
for (i=0;i<32;i++) /* init transmit time slot table */
{
gmp->tsatt[i].v=0;
gmp->tsatt[i].chp=0;
gmp->tsatt[i].mask0_1 =0;
gmp->tsatt[i].mask2_7 =0;
}
for (i=0;i<pGCfg->MaxSendTSAEntry;i++) /* init transmit time slot table */
{
gmp->tsatt[i].chp=pQmcTsCfg->SendTsTable[i];
gmp->tsatt[i].mask0_1 =0x3; /* no subchannel */
gmp->tsatt[i].mask2_7 =0x3f;
gmp->tsatt[i].v=1;
}
gmp->tsatt[i-1].w=1;
break;
case SDC_SET_SUBCH_LOOP:
if(pGCfg->SetSubChLoop==NULL) return SDE_SET_SUBCH_LOOP_FAULSE;
ret=pGCfg->SetSubChLoop(pCfg,1);
if(ret<0) return SDE_SET_SUBCH_LOOP_FAULSE;
break;
case SDC_SET_SUBCH_UNLOOP:
if(pGCfg->SetSubChLoop==NULL) return SDE_SET_SUBCH_LOOP_FAULSE;
ret=pGCfg->SetSubChLoop(pCfg,0);
if(ret<0) return SDE_SET_SUBCH_LOOP_FAULSE;
break;
case SDC_LIMITE_REINIT:
QmcLimitReInit(pGCfg);
break;
case SDC_SET_EXCHANG_MAP:
{
QMCChanMapStruct* pQmcChMapCfg;
DataBufStruct* pDataSrc;
QmcSubChanCfgStruct* pCfgSrc;
if(maxlen!=sizeof(QMCChanMapStruct))
return SDE_INVALID_ARG;
pQmcChMapCfg=(QMCChanMapStruct*)pParam;
if((pQmcChMapCfg->ChanIn>64)||(pQmcChMapCfg->ChanIn<0))return SDE_INVALID_ARG;
if(((pQmcChMapCfg->ChanOut>64)||(pQmcChMapCfg->ChanOut<0)) && pQmcChMapCfg->ChanOut!=0xff)
return SDE_INVALID_ARG;
pDataSrc=(DataBufStruct*)(pGCfg->IsrParam[pQmcChMapCfg->ChanIn]);
pCfgSrc =(QmcSubChanCfgStruct *)(pDataSrc+1);
SPLX(
if(pQmcChMapCfg->ChanOut==0xff)pCfgSrc->subchatt=0;
else pCfgSrc->subchatt=QMC_SUBCH_ATT_EXCHANG;
pCfgSrc->ExchangSubCh=pQmcChMapCfg->ChanOut;
);
}
break;
default:
return SDE_UNKNOW_CMD;
}/* end of switch(cmd) */
return SDE_OK;
}
/* allocate memory for Qmc */
char *QmcBspGlobalInit(char *FreeMemPtr, QmcGlobalCfgStruct *pGCfg,
QmcGlobalCfgStruct **id)
{
#if 0
pGCfg->UncachedBuffer
=(char*)AllocUncachedBuffer(pGCfg->MaxBufNum
*(sizeof(LinkBufStruct)+pGCfg->MaxBufLen-LINK_DATA_BUF_LEN),64);
#endif
pGCfg->UncachedBuffer
=(char*)AllocUncachedBuffer(pGCfg->MaxBufNum
*(sizeof(LinkBufStruct)+pGCfg->MaxBufLen-LINK_DATA_BUF_LEN+4),64)
+4;
pGCfg->BDTable
=AllocUncachedBuffer((pGCfg->MaxRecvBD+pGCfg->MaxSendBD)
*pGCfg->MaxSubChanNum*BD_LEN,64);
pGCfg->IntTable
=(IntEntryStruct*)AllocUncachedBuffer(pGCfg->IntTableLen*2,64);
QmcGlobalInit(FreeMemPtr,pGCfg);
if(id)*id=(QmcGlobalCfgStruct*)FreeMemPtr;
FreeMemPtr += sizeof(QmcGlobalCfgStruct);
memcpy(FreeMemPtr,"**QmcDat",8);
FreeMemPtr += 8;
return FreeMemPtr;
}
/* allocate memory for Qmc' SubChan , id, return from QmcGlobalBspInit */
char *QmcBspSubChanInit(int DEV, char *FreeMemPtr,
QmcSubChanCfgStruct *pCfg, QmcGlobalCfgStruct *pGCfg)
{
pCfg->pGCfg=pGCfg;
InstallSD(DEV,QmcRead,QmcWrite,QmcCntrl,FreeMemPtr);
memset(FreeMemPtr, 0, sizeof(DataBufStruct));
QmcSubChanInit(FreeMemPtr, pCfg);
pGCfg->IsrParam[pCfg->ch]=FreeMemPtr;
FreeMemPtr += sizeof(DataBufStruct)+sizeof(QmcSubChanCfgStruct);
memcpy(FreeMemPtr,"**QmcSub",8);
FreeMemPtr += 8;
return FreeMemPtr;
}
void QmcInitEnd(QmcGlobalCfgStruct* pGCfg)
{
PDA *pda= (PDA *)(GetIMMR() & IO_MAP_MASK);
regs(pGCfg->ch).scc_gsmrb=0x780;
regs(pGCfg->ch).scc_gsmra=0x0a; /* enable QMC*/
regs(pGCfg->ch).scc_scce=0xffff;
regs(pGCfg->ch).scc_sccm=0x000f; /*enable all */
SPLX(pda->cpmi_cimr|=(EN_SCC1 >> pGCfg->ch);)
SPLX(pda->cpmi_cipr|=(CLR_SCC1 >> pGCfg->ch);)
SPLX(pda->cpmi_cisr|=(CLR_SCC1 >> pGCfg->ch);)
SPLX(pda->cpmi_cicr|=CPM_EN_INTS|0x1b0000;)
regs(pGCfg->ch).scc_gsmra|=0x00000030;/* Enable tx and rx */
}
static void QmcLimitReInit(QmcGlobalCfgStruct *pGCfg)
{
int i;
for(i=0;i<pGCfg->MaxSubChanNum;i++)
{
QmcStopOp( (QmcSubChanCfgStruct*)((DataBufStruct *)
(pGCfg->IsrParam[i+pGCfg->SubChParamOffset/64])+1) );
}
QmcGlobalInit(pGCfg,pGCfg);
for(i=0;i<pGCfg->MaxSubChanNum;i++)
{
QmcSubChanInit((DataBufStruct *)(pGCfg->IsrParam
[i+pGCfg->SubChParamOffset/64]),(QmcSubChanCfgStruct*)
((DataBufStruct *)(pGCfg->IsrParam[i+pGCfg->SubChParamOffset/64])+1) );
}
QmcInitEnd(pGCfg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -