⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scutest.c

📁 这是单板上DPRAM的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
static int MT8980LoopTest(TSTestStruct *ptt, TSTestStruct *pttr)
{
    volatile int rc;
    int i, j;
    SDCConfigTsStruct Cfg;
    
    if((ptt->ParamLen < sizeof(TSTestStruct)) | (pttr->ParamLen < sizeof(TSTestStruct)))
        return SDE_INVALID_ARG;
    
    for(i = 0; i < 3; i++){
        if(*(&(ptt->ts0) + i) == 1){
            Cfg.StreamIn = 2;
            Cfg.ChanIn = i;
            Cfg.StreamOut = 2;
            Cfg.ChanOut = i;
            rc = sd_cntrl(SDN_MT8980, SDC_CONFIG_TS, &Cfg, sizeof(SDCConfigTsStruct));
        }
    }    
    QMCTest(ptt, pttr);
    return SDE_OK;
}

static void QMCTest(TSTestStruct *ptt, TSTestStruct *pttr)
{
    volatile int rc, SendCount=0;
    int i, j, CurDev;
    SDCEventQueueStruct eq;
    
    for(i = 0; i < 3; i++){
        if(*(&(ptt->ts0) + i) == 1){
            CurDev = SDN_OM + i;
            rc = sd_cntrl(CurDev, SDC_SET_TEST_MODE, &eq, sizeof(SDCEventQueueStruct));
            tm_wkafter(5);
            for(j = 0; j < 16; j++){                           /* clear receive buffer */
                rc = sd_read(CurDev, pRecvBuf, MAX_TEST_BUF_LEN);
                if(rc == SDE_BUF_EMPTY) break;
            }
        }
    }
    
    for(i = 0; i < MAX_TEST_BUF_LEN; i++)
        pSendBuf[i] = (char)rand();
    
    SendCount = 0;
    for(i = 0; i < 3; i++){
        if(*(&(ptt->ts0) + i) == 0)
            continue;
        
        CurDev = SDN_OM + i;
        rc = sd_write(CurDev, pSendBuf, MAX_TEST_BUF_LEN);
        tm_wkafter(5);
        rc = sd_read(CurDev, pRecvBuf, MAX_TEST_BUF_LEN);
        if (memcmp(pSendBuf, pRecvBuf, MAX_TEST_BUF_LEN) == 0){
            *(&(pttr->ts0) + i) = SDE_OK;
        }
        else {
            i--;
            SendCount++;
            if(SendCount == MAX_SEND_TIMES){
                *(&(pttr->ts0) + i + 1) = SDE_FAIL;
                SendCount = 0;
                i++;
            }
        }
    }
    
    for(i = 0; i < 3; i++){
        if(*(&(ptt->ts0) + i) == 1){
            CurDev = SDN_OM + i;
            rc = sd_cntrl(CurDev, SDC_SET_UNTEST_MODE, &eq, sizeof(SDCEventQueueStruct));
        }
    }
}

static int NiuChipWRTest(NiuTestStruct *pnt, NiuTestStruct *pntr)
{
    int i, Slave, TestLen=32, ErrCount, temp1, MaxWaitTime=0x1ffffff;   /* wait 20s */
    ULONG TempNiuBase, TestBase, temp;
    char pReadBuf[32], pSendBuf[4];
    volatile int rc;
    
    if((pnt->ParamLen < sizeof(NiuTestStruct)) | (pntr->ParamLen < sizeof(NiuTestStruct)))
        return SDE_INVALID_ARG;
    
    if(    (sd_cntrl(SDN_MISC, SDC_NIU0_TYPE, 0, 0) == NIU_E1) \
        && (sd_cntrl(SDN_MISC, SDC_NIU1_TYPE, 0, 0) == NIU_E1)){
        for(Slave = 0; Slave < 2; Slave++){
            if(*(&(pnt->Niu0) + Slave) == 1){
                ErrCount = 0;
                TempNiuBase = (Slave==0)?BT8370_BASE:(BT8370_BASE+0x400);
                TestBase = TempNiuBase + 0x100;
                for(i = 0; i < TestLen; i++){
                    REG8(TestBase + i) = (char)rand();
                    pReadBuf[i] = REG8(TestBase + i);
                }
                if(memcmp(pReadBuf, &REG8(TestBase), TestLen) != 0)
                    ErrCount++;
                    
                TestBase = TempNiuBase + 0x180;
                for(i = 0; i < TestLen; i++){
                    REG8(TestBase + i) = (char)rand();
                    pReadBuf[i] = REG8(TestBase + i);
                }
                if(memcmp(pReadBuf, &REG8(TestBase), TestLen) != 0)
                    ErrCount++;
                    
                *(&(pntr->Niu0) + Slave)= (ErrCount==0)?SDE_OK:SDE_FAIL;
            }
        }
    }
    else if(  (sd_cntrl(SDN_MISC, SDC_NIU0_TYPE, 0, 0) == NIU_HDSL) \
           && (sd_cntrl(SDN_MISC, SDC_NIU1_TYPE, 0, 0) == NIU_HDSL)){
        for(Slave = 0; Slave < 2; Slave++){
            if(*(&(pnt->Niu0) + Slave) == 1){
                temp1 = (Slave==0)?4:23;
                temp=*(ULONG *)(CS7_BASE+8);
                if((temp & (1L<<(31-temp1))) != 0) {      /* check if NIU hardware alarm */
                    rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
                    rc = sd_cntrl(SDN_NIU, SDC_REINIT, NULL, 0);
                }
                tm_wkafter(100);
                for(i = 0; i < MaxWaitTime; i++){          /* wait for hardware */
                    temp=*(ULONG *)(CS7_BASE+8);
                    if((temp&(1L<<(31-temp1))) == 0) break;
                }
                if(i == MaxWaitTime)
                    *(&(pntr->Niu0) + Slave) = SDE_FAIL;
                else{
                    rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
                    pSendBuf[0] = 0xf3;     /* _CU_COMMON */
                    pSendBuf[1] = 0x09;     /* _CU_FRAME_FORMAT */
                    pSendBuf[2] = 0x01;     /* unframed: MSYNC ignors TMSYNC */
                    pSendBuf[3] = pSendBuf[0] ^ pSendBuf[1] ^ pSendBuf[2] ^ 0xAA;
                    rc=sd_write(SDN_NIU_UART, pSendBuf, 4);
                    for(i = 0; i < 20; i++){
                        rc=sd_read(SDN_NIU_UART, pRecvBuf, 4);
                        tm_wkafter(10);
                        if(rc > 0) break;
                    }
                    if(i == 20)
                        *(&(pntr->Niu0) + Slave) = SDE_FAIL;
                    else
                        *(&(pntr->Niu0) + Slave) = (memcmp(pRecvBuf,"\xff\xff\xff\x55",4)==0)?SDE_OK:SDE_FAIL;
                }
            }
        }
    }
    else
        return SDE_NIU_MODE_ERROR;
        
    return SDE_OK;
}

static int NiuLoopTest(NiuTestStruct *pnt, NiuTestStruct *pntr, int LoopMode)
{
    int i, j, Slave, temp1, OutChnnl, InChnnl, MaxWaitTime=0x1ffffff;        /* wait 20s */
    ULONG TempNiuBase, temp;
    volatile int rc, ErrCount;
    SDCConfigTsStruct Cfg;
    TSTestStruct tsc, tsr;
    
    if(pnt->ParamLen < sizeof(NiuTestStruct) || pntr->ParamLen < sizeof(NiuTestStruct))
        return SDE_INVALID_ARG;
    
    tsc.ts0 = 0;  
    tsc.ts1 = 1;
    tsc.ts2 = 1;
    tsc.ParamLen  = sizeof(TSTestStruct);
    
    if(    (sd_cntrl(SDN_MISC, SDC_NIU0_TYPE, 0, 0) == NIU_E1) \
        && (sd_cntrl(SDN_MISC, SDC_NIU1_TYPE, 0, 0) == NIU_E1)){
        for(Slave = 0; Slave < 2; Slave++){
            if(*(&(pnt->Niu0) + Slave) == 1){
                tsr.ts0 = tsr.ts1 = tsr.ts2 = -1;
                tsr.ParamLen  = sizeof(TSTestStruct);
                
                TempNiuBase = (Slave==0)?BT8370_BASE:(BT8370_BASE+0x400);
                OutChnnl = (Slave==0)?MT_STREAM_ABIS:MT_STREAM_NEXT;
                for(j = 0; j < 3; j++){
                    if(*(&(tsc.ts0) + j) == 1){
                        Cfg.StreamIn = MT_STREAM_860;
                        Cfg.ChanIn = j;
                        Cfg.StreamOut = OutChnnl;
                        Cfg.ChanOut = j;
                        rc = sd_cntrl(SDN_MT8980, SDC_CONFIG_2TS, &Cfg, sizeof(SDCConfigTsStruct));
                    }
                }
                rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
                rc = sd_cntrl(SDN_NIU, SDC_REINIT, NULL, 0);
                
                if(LoopMode == INLOOP) {
                    REG8(TempNiuBase + 0x0e1) = 0x11;
                    REG8(TempNiuBase + 0x0e2) = 0x11;
                }
                QMCTest(&tsc, &tsr);
                *(&(pntr->Niu0) + Slave) = ((tsr.ts1 == SDE_OK)&&(tsr.ts2 == SDE_OK))?SDE_OK:SDE_FAIL;
                
                rc = sd_cntrl(SDN_NIU, SDC_SET_NORMAL_MODE, NULL, 0);
            }
        }
    }
    else if(   (sd_cntrl(SDN_MISC, SDC_NIU0_TYPE, 0, 0) == NIU_HDSL) \
            && (sd_cntrl(SDN_MISC, SDC_NIU1_TYPE, 0, 0) == NIU_HDSL) \
            && (LoopMode == INLOOP)){
        for(Slave = 0; Slave < 2; Slave++){
            if(*(&(pnt->Niu0) + Slave) == 1){
                temp1 = (Slave==0)?4:23;
                temp=*(ULONG *)(CS7_BASE+8);
                if((temp & (1L<<(31-temp1))) != 0) {      /* check if NIU hardware alarm */
                    rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
                    rc = sd_cntrl(SDN_NIU, SDC_REINIT, NULL, 0);
                }
                tm_wkafter(100);
                for(i = 0; i < MaxWaitTime; i++){          /* wait for hardware */
                    temp=*(ULONG *)(CS7_BASE+8);
                    if((temp&(1L<<(31-temp1))) == 0) break;
                }
                if(i == MaxWaitTime)
                    *(&(pntr->Niu0) + Slave) = SDE_FAIL;
                else{
                    OutChnnl = (Slave==0)?MT_STREAM_ABIS:MT_STREAM_NEXT;
                    
                    tsr.ts0 = tsr.ts1 = tsr.ts2 = -1;
                    tsr.ParamLen  = sizeof(TSTestStruct);
                    
                    for(j = 0; j < 3; j++){
                        if(*(&(tsc.ts0) + j) == 1){
                            Cfg.StreamIn = MT_STREAM_860;
                            Cfg.ChanIn = j;
                            Cfg.StreamOut = OutChnnl;
                            Cfg.ChanOut = j;
                            rc = sd_cntrl(SDN_MT8980, SDC_CONFIG_2TS, &Cfg, sizeof(SDCConfigTsStruct));
                        }
                    }
                    rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
                    rc = sd_cntrl(SDN_NIU, SDC_ZIPSOCKET_NEAR_END_PCM_TO_PCM_LOOPBACK, 0, 0);
                    tm_wkafter(10);
                    QMCTest(&tsc, &tsr);
                    *(&(pntr->Niu0) + Slave) = ((tsr.ts1==SDE_OK)&&(tsr.ts2==SDE_OK))?SDE_OK:SDE_FAIL;
                    
                    rc = sd_cntrl(SDN_NIU, SDC_SET_NORMAL_MODE, 0, 0);
                }
            }
        }
    }
    else if(   (sd_cntrl(SDN_MISC, SDC_NIU0_TYPE, 0, 0) == NIU_HDSL) \
            && (sd_cntrl(SDN_MISC, SDC_NIU1_TYPE, 0, 0) == NIU_HDSL) \
            && (LoopMode == EXLOOP)){
        temp=*(ULONG *)(CS7_BASE+8);
        if(    ((temp & (1L<<(31-4)))  != 0) \
            || ((temp & (1L<<(31-23))) != 0)){           /* check if NIU hardware alarm */
            Slave = 0;
            rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
            rc = sd_cntrl(SDN_NIU, SDC_REINIT, NULL, 0);
            Slave = 1;
            rc = sd_cntrl(SDN_NIU, SDC_SEL_SLAVE, &Slave, sizeof(int));
            rc = sd_cntrl(SDN_NIU, SDC_REINIT, NULL, 0);
        }
        tm_wkafter(100);
        for(i = 0; i < MaxWaitTime; i++){                /* wait for hardware sync */
            temp=*(ULONG *)(CS7_BASE+8);
            if(    ((temp & (1L<<(31-2)))  != 0) \
                && ((temp & (1L<<(31-3)))  != 0) \
                && ((temp & (1L<<(31-21))) != 0) \
                && ((temp & (1L<<(31-22))) != 0))
                break;
        }
        if(i == MaxWaitTime){
            pntr->Niu0 = pntr->Niu1 = SDE_FAIL;
            return SDE_OK;
        }    
            
        for(Slave = 0; Slave < 2; Slave++){
            if(Slave == 0){
                OutChnnl = MT_STREAM_ABIS;
                InChnnl  = MT_STREAM_NEXT;
            }
            else{
                OutChnnl = MT_STREAM_NEXT;
                InChnnl  = MT_STREAM_ABIS;
            }

            ErrCount = 0;
            tsr.ts0 = tsr.ts1 = tsr.ts2 = -1;
            tsr.ParamLen  = sizeof(TSTestStruct);
            
            for(j = 0; j < 3; j++){
                if(*(&(tsc.ts0) + j) == 1){
                    Cfg.StreamIn = MT_STREAM_860;
                    Cfg.ChanIn = j;
                    Cfg.StreamOut = OutChnnl;
                    Cfg.ChanOut = j;
                    rc = sd_cntrl(SDN_MT8980, SDC_CONFIG_TS, &Cfg, sizeof(SDCConfigTsStruct));
                    
                    Cfg.StreamIn = InChnnl;
                    Cfg.ChanIn = j;
                    Cfg.StreamOut = MT_STREAM_860;
                    Cfg.ChanOut = j;
                    rc = sd_cntrl(SDN_MT8980, SDC_CONFIG_TS, &Cfg, sizeof(SDCConfigTsStruct));
                }
            }
            QMCTest(&tsc, &tsr);
            
            if((tsr.ts1==SDE_FAIL)||(tsr.ts2==SDE_FAIL)) ErrCount++;    
        }
        pntr->Niu0 = pntr->Niu1 = (ErrCount==0)?SDE_OK:SDE_FAIL;
    }
    else
        return SDE_NIU_MODE_ERROR;
    
    return SDE_OK;    
}

static void FlashTest(TestRsltStruct *ptr)
{
    int i, j, BytesToTest=20;
    SDCFlashAccessStruct FlashAccessWrite, FlashAccessRead;
    char *pReadBuf, pWriteBuf[20];
    volatile int rc, ErrCount=0;
        
    pReadBuf = (char *)malloc(BytesToTest);
    for(i = 0; i < BytesToTest; i++)
        pWriteBuf[i] = (char)rand();    
    
    for(i = 0; i < 2; i++){
        FlashAccessWrite.Offset = 4 + i * FLASH0_SIZE;
        FlashAccessWrite.Size = BytesToTest;
        FlashAccessWrite.Base = pWriteBuf;
        
        FlashAccessRead.Offset = 4+ i * FLASH0_SIZE;
        FlashAccessRead.Size = BytesToTest;
        FlashAccessRead.Base = pReadBuf;
        
        rc = sd_cntrl(SDN_FLASH, SDC_ERASE_SECTOR, &FlashAccessWrite.Offset, sizeof(ULONG)); 
        if(rc != 0) ptr->ErrInfo[ErrCount++] = SDE_FLASH0_ERASE_SECTOR_FAIL-i;
        rc = sd_cntrl(SDN_FLASH, SDC_WRITE_FLASH, &FlashAccessWrite, sizeof(SDCFlashAccessStruct));
        if(rc != 0) ptr->ErrInfo[ErrCount++] = SDE_FLASH0_WRITE_FAIL-i;
        rc = sd_cntrl(SDN_FLASH, SDC_READ_FLASH, &FlashAccessRead, sizeof(SDCFlashAccessStruct));
        if(rc != 0) ptr->ErrInfo[ErrCount++] = SDE_FLASH0_READ_FAIL-i;
        if(memcmp(FlashAccessWrite.Base, FlashAccessRead.Base, BytesToTest) != 0) ErrCount++;
    }
    ptr->TestRslt = (ErrCount==0)?SDE_OK:SDE_FAIL;

 /*   rc = sd_cntrl(SDN_FLASH, SDC_ERASE_CHIP, NULL, 0);*/
}

static void DS1620Test(TestRsltStruct *ptr)
{
    int i, j, ThSet=10, TlSet=3, Th, Tl, DevNo, ReadTemp, ErrCount=0, ErrCount0;
    volatile int rc;
    
    for(i = 0; i < 4; i++) {
        ErrCount0 = 0;
        
        DevNo = SDN_DS1620A + i;
        rc = sd_cntrl(DevNo, SDC_SET_UPPER_LIMIT, &ThSet, sizeof(int));
        tm_wkafter(1);
        rc = sd_cntrl(DevNo, SDC_SET_LOWER_LIMIT, &TlSet, sizeof(int));
        tm_wkafter(1);                       
        rc = sd_cntrl(DevNo, SDC_GET_UPPER_LIMIT, &Th, sizeof(int));
        rc = sd_cntrl(DevNo, SDC_GET_LOWER_LIMIT, &Tl, sizeof(int));
        if((Th != ThSet) || (Tl != TlSet))
            ErrCount0++;    
        rc = sd_read(DevNo, &ReadTemp, sizeof(int));
        if(rc != 0)
            ErrCount0++;
        
        if(ErrCount0 != 0)
            ptr->ErrInfo[ErrCount++] = SDE_DS1620A_FAIL - i;
    }
    ptr->TestRslt = (ErrCount==0)?SDE_OK:SDE_FAIL;
}

static void FNIsr(void)
{
    FNCount++;
    S_SiPendRegister |= 0x20000000;       /*  IRQ1_PENDING  */
}

static void FNTest(TestRsltStruct *ptr)
{
    int BeginFNCount, EndFNCount, TicksNum=100;
    volatile rc;
    
    FNCount=0;
    TicksCount=0;
    
    S_IntEdgeLvlMaskReg |= 0x20000000;    /*  IRQ1_MASK     */
    S_SiPendRegister    |= 0x20000000;    /*  IRQ1_PENDING  */
    S_SiMaskRegister    |= 0x20000000;    /*  IRQ1_MASK     */
    IsrAddHandler(V_SIU_IRQ1, (void *)FNIsr, NULL); 
    
    BeginFNCount = FNCount;
    tm_wkafter(TicksNum);
    EndFNCount = FNCount;
    
    ptr->TestRslt = 100 * (EndFNCount - BeginFNCount) / TicksNum;
    S_SiMaskRegister    &= ~0x20000000;    /*  IRQ1_MASK     */
    IsrAddHandler(V_SIU_IRQ1, NULL, NULL); 
}

static void AlarmsTest(TestRsltStruct *ptr)
{
    ULONG temp;
    int ErrCount=0;
    
    temp=*(ULONG *)(CS7_BASE+8);
    
    if((temp&(1L<<(31-0)))==0)
        ptr->ErrInfo[ErrCount++] = SDE_FCLK_FAIL;
    if((temp&(1L<<(31-1)))==0)
        ptr->ErrInfo[ErrCount++] = SDE_OBCLK_FAIL;
    ptr->TestRslt = (ErrCount==0)?SDE_OK:SDE_FAIL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -