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

📄 cycle_u.c

📁 Utils and test SD card read write cycles
💻 C
字号:
#include "Cycle.h"

/*****************************************************************************
* Function name:  STATUS_T createBG_buffer(int *sector)
*
* Description : This function Evaluate a 512 buffer with BG pattern
* 
* Parameters:   sector: The buffer that included the pattern 
*
* Return:      STATUS_T
* 
****************************************************************************/ 

STATUS_T createBG_buffer(int *sector)
{
    unsigned int i;

    for (i = 0; i < SECTOR_SIZE; i++)
    {
        *sector++ = BG_PATTERN;
    }
    return OK;
}

/*****************************************************************************
* Function name:  STATUS_T createNUP_buffer(int *sector)
*
* Description : This function Evaluate a 512 buffer with NUP pattern
* 
* Parameters:   sector: The buffer that included the pattern 
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T createNUP_buffer(int *sector)
{
    unsigned int i;

    for (i = 0; i < (SECTOR_SIZE - 2); i += 5)
    {
        *sector++ = NUP_PATTERN_1;
        *sector++ = NUP_PATTERN_2;
        *sector++ = NUP_PATTERN_3;
        *sector++ = NUP_PATTERN_4;
        *sector++ = NUP_PATTERN_5;
    }
    *sector++ = NUP_PATTERN_1;
    *sector++ = NUP_PATTERN_2;
    return OK;
}

/*****************************************************************************
* Function name:  STATUS_T createBG_buffer(int *sector)
*
* Description : This function Evaluate a 512 buffer with BG pattern
* 
* Parameters:   sector: The buffer that included the pattern 
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T ProgramBG(int *phasecounter)
{
    unsigned int Overhead;
    unsigned int index;
    STATUS_T ret = OK;

    Overhead = 0;
    WRITE_BACK_PTR(Overhead, 0);
    createBG_buffer(cycBuffer_ref);

    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= WriteSector(&index, cycBuffer_ref, Overhead);
        if (ret)
        {
            ret |= RegisterCycError(index, ret, PROGRAM_BG, phasecounter);
            ret |= RegisterBBError(index, phasecounter);
        }
    }

    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= ReadSectorFromFlash(index, (unsigned char *)cycBuffer_read);
        ret |= CheckSector((unsigned int *) cycBuffer_ref, (unsigned int *) cycBuffer_read) ;
        if (ret)
        {
            ret |= RegisterCycError(index, ret, PROGRAM_BG, phasecounter);
        }
    }
    *phasecounter++;

    return OK;
}

/*****************************************************************************
* Function name:  STATUS_T Cycle(int statrtBlock, int NumberOfBlocks)
*
* Description : This function write read and verify NumberOfBlocks  
* 
* Parameters:  statrtBlock      - statrt Block 
*              NumberOfBlocks   - Number Of Blocks
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T  Cycle(int statrtBlock, int NumberOfBlocks, int *phasecounter)
{
    STATUS_T ret = OK;
    unsigned int Overhead = 0;
    int index;
    
    ret |= EraseBlocks(statrtBlock, NumberOfBlocks, phasecounter);
    for (index = statrtBlock; index < NumberOfBlocks; index++)
    {
        ret |= WriteSector(&index, cycBuffer_ref, Overhead);
        if (ret)
        {
            ret |= RegisterCycError(index, ret, CYCLE, phasecounter);
            ret |= RegisterBBError(index, phasecounter);
        }
    }

    for (index = statrtBlock; index < NumberOfBlocks; index++)
    {
        ret |= ReadSectorFromFlash(index, (unsigned char *)cycBuffer_read);
        ret |= CheckSector((unsigned int *) cycBuffer_ref, (unsigned int *) cycBuffer_read) ;
        if (ret)
        {
            ret |= RegisterCycError(index, ret, CYCLE, phasecounter);
        }

    }
    *phasecounter++;
    return ret;
}

/*****************************************************************************
* Function name:  STATUS_T Cycle25()
*
* Description : This function cycle 600 times 25% of the card capacity  
* 
* Parameters:   
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T Cycle25(int *phasecounter)
{
    int statrtBlock; 
    int NumberOfBlocks;
    int sector[SECTOR_SIZE_INT];
    int cycle_no;
    STATUS_T ret = OK;

    statrtBlock = 1;
    NumberOfBlocks = 1 << 15;
    createNUP_buffer(sector);
    for (cycle_no = 1; cycle_no <= 600; cycle_no++)
    {
        ret |= Cycle(0, NumberOfBlocks, &phasecounter);
        
        if (NumberOfSectors > (1 << 17))
        {
            ret |= Cycle(1 << 17, NumberOfBlocks, &phasecounter);
        }
        if (NumberOfSectors > (1 << 18))
        {
            ret |= Cycle(2 << 17, NumberOfBlocks, &phasecounter);
            ret |= Cycle(3 << 17, NumberOfBlocks, &phasecounter);
        }
        if (NumberOfSectors > (1 << 19))
        {
            ret |= Cycle(4 << 17, NumberOfBlocks, &phasecounter);
            ret |= Cycle(5 << 17, NumberOfBlocks, &phasecounter);
            ret |= Cycle(6 << 17, NumberOfBlocks, &phasecounter);
            ret |= Cycle(7 << 17, NumberOfBlocks, &phasecounter);
        }
    }
    return ret;
}


/*****************************************************************************
* Function name:  STATUS_T RternPre()
*
* Description : This function execute pre retention actions. 
*               It erase all the SD flash memory and write BG pattern on it.
* 
* Parameters:   
*
* Return:      STATUS_T
* 
****************************************************************************/ 

STATUS_T RternPre(int *phasecounter)
{
    int statrtBlock; 
    unsigned int index;
    unsigned int Overhead = 0;
    STATUS_T ret = OK;
    
    statrtBlock = 1;
    ret |= EraseBlocks(statrtBlock, NumberOfSectors, phasecounter);
    ret |= createBG_buffer(cycBuffer_ref);

    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= WriteSector(&index, cycBuffer_ref, Overhead);
        if (ret)
        {
            ret |= RegisterCycError(index, ret, RETEN_PRE, phasecounter);
            ret |= RegisterBBError(index, phasecounter);
        }

    }
    *phasecounter++;
    return ret;
}

/*****************************************************************************
* Function name:  STATUS_T RDAfterReten()
*
* Description : This function execute after retention actions. 
*               It read and check all the buffers on the SD flash memeory.
* 
* Parameters:   
*
* Return:      STATUS_T
* 
****************************************************************************/ 

STATUS_T RDAfterReten(int *phasecounter)
{
    unsigned int index;
    int raedSectorBuffer[SECTOR_SIZE_INT];
    unsigned int Overhead = 0;
    STATUS_T ret = OK;
    
    createBG_buffer(cycBuffer_ref);

    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= ReadSectorFromFlash(index, (unsigned char *)raedSectorBuffer);
        ret |= CheckSector((unsigned int *) raedSectorBuffer, (unsigned int *) cycBuffer_ref) ;
        if (ret)
        {
            ret |= RegisterCycError(index, ret, RETEN_PRE, phasecounter);
        }
    }
    *phasecounter++;
    return ret;
}

/*****************************************************************************
* Function name:  STATUS_T TestAfterReten()
*
* Description : This function test after retention actions. 
*               It write and check all the buffers on the SD flash memeory.
* 
* Parameters:   
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T TestAfterReten(int *phasecounter)
{
    int statrtBlock = 0; 
    unsigned int index;
    int raedSectorBuffer[SECTOR_SIZE_INT];
    unsigned int Overhead = 0;
    STATUS_T ret = OK;

    EraseBlocks(statrtBlock, NumberOfSectors, phasecounter);
    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= WriteSector(&index, cycBuffer_ref, Overhead);
        if (ret)
        {
            ret |= RegisterCycError(index, ret, RETEN_PRE, phasecounter);
            ret |= RegisterBBError(index, phasecounter);
        }
    }

    for (index = 1; index < NumberOfSectors; index++)
    {
        ret |= ReadSectorFromFlash(index, (unsigned char *)raedSectorBuffer);
        ret |= CheckSector((unsigned int *) raedSectorBuffer, (unsigned int *) cycBuffer_ref) ;
        if (ret)
        {
            ret |= RegisterCycError(index, ret, RETEN_PRE, phasecounter);
        }
    }
    *phasecounter++;
    return OK;
}

/*****************************************************************************
* Function name:  STATUS_T EraseFW()
*
* Description : This function erase all SD flash memory
* 
* Parameters:   
*
* Return:      STATUS_T
* 
****************************************************************************/ 
STATUS_T EraseFW(int *phasecounter)
{
    int statrtBlock = 0; 
    STATUS_T ret = OK;

    ret |= EraseBlocks(statrtBlock, NumberOfSectors, phasecounter);

    return ret;
}

⌨️ 快捷键说明

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