示例#1
0
/*
** Sets the Time and Calender in the RTC. This is a blocking call. 
** The time and date are entered through UART.
*/
void RtcTimeCalSet(void)
{
    unsigned int time = 0; 
    unsigned int cal = 0;
    unsigned int temp = 0; 
 
    UARTPuts("\n\rEnter Hours (0 to 23):", -1);
    temp = UARTGetNum();

    while(temp > 23)
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    time = (((temp / 10) << 4) << SHIFT_HOUR)
            | ((temp % 10) << SHIFT_HOUR);

    UARTPuts("\n\rEnter Minutes (0 to 59):", -1);
    temp = UARTGetNum();

    while(temp > 59)
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    time |= (((temp / 10) << 4) << SHIFT_MIN)
            | ((temp % 10) << SHIFT_MIN);
 
    UARTPuts("\n\rEnter Seconds (0 to 59):", -1);
    temp = UARTGetNum();

    while(temp > 59)
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    time |= (((temp / 10) << 4) << SHIFT_SEC)
             | ((temp % 10) << SHIFT_SEC);

    UARTPuts("\n\rEnter Date (1 to 31):", -1);
    temp = UARTGetNum();

    while((temp > 31) || (0 == temp))
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    cal = (((temp / 10) << 4) << SHIFT_DAY)
           | ((temp % 10) << SHIFT_DAY);

    UARTPuts("\n\rEnter Month (1 to 12):", -1);
    temp = UARTGetNum();

    while((temp > 12) || (0 == temp))
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    cal |= (((temp / 10) << 4) << SHIFT_MON)
            | ((temp % 10) << SHIFT_MON);

    UARTPuts("\n\rEnter Year (0 to 99):", -1);
    temp = UARTGetNum();
    while(temp > 99)
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    cal |= (((temp / 10) << 4) << SHIFT_YEAR)
            | ((temp % 10) << SHIFT_YEAR);

    UARTPuts("\n\rEnter Day Of the week (0 for Sunday...6 for Saturday):", -1);
    temp = UARTGetNum();

    while(temp > 6)
    {
        UARTPuts("\n\rValue entered is invalid. Enter value:", -1);
        temp = UARTGetNum();
    }

    cal |= (((temp / 10) << 4)) | ((temp % 10));
 
    /* Set the calendar registers of RTC with received calendar information.*/
    RTCCalendarSet(SOC_RTC_0_REGS, cal);

    /* Set the time registers of RTC with the received time information.*/
    RTCTimeSet(SOC_RTC_0_REGS, time);

    /* Run the RTC. The seconds tick from now on.*/
    RTCRun(SOC_RTC_0_REGS);
 
    UARTPuts("\n\rThe Time and Date are set successfully! \n\n\r", -1);

    rtcSetFlag = TRUE;
}
示例#2
0
/******************************************************************************
*                                                                             *
* \brief  Main Function.\n                                                    *
*                                                                             *
******************************************************************************/
int main(void)
{
    int blkNum;
    int pageNum;
    int numOfPages;
    unsigned int retVal;
    unsigned int eraseBlkFlg;

    /* NAND structure allocations for this application */
    NandInfo_t              nandInfo;
    NandCtrlInfo_t          nandCtrlInfo;
    NandEccInfo_t           nandEccInfo;
    NandDmaInfo_t           nandDmaInfo;
    EMIFANANDTimingInfo_t   nandTimingInfo;

    /* Initializing the UART instance for serial communication.  */
    UARTStdioInit();

    UARTPuts("\r\n ************* StarterWare NAND Application ************"
             "\r\n\r\n", -1);
    
    /* Pin mux and clock setting */
    EMIFAClkConfig();
    NANDPinMuxSetup();
             
    /* Initialize the nandInfo struct */
    nandCtrlInfo.hNandTimingInfo = (void *) &nandTimingInfo;    
    nandInfo.hNandCtrlInfo = &nandCtrlInfo;
    nandInfo.hNandEccInfo = &nandEccInfo;
    nandInfo.hNandDmaInfo = &nandDmaInfo;
    NANDInfoInit(&nandInfo, NAND_CHIP_SELECT);

    /* Open the NAND device */
    retVal = NANDOpen(&nandInfo);
    if (retVal & NAND_STATUS_FAILED)
    {
        UARTPuts("\r\n*** ERROR : NAND Open Failed... ",-1);
        while(1);    
    }
    else if (retVal & NAND_STATUS_WAITTIMEOUT)
    {
        UARTPuts("\r\n*** ERROR : Device Is Not Ready...!!!\r\n", -1);
        while(1);
    }
    else if (retVal & NAND_STATUS_NOT_FOUND)
    {
        UARTPuts("\r\n*** ERROR : DEVICE MAY NOT BE ACCESSABLE OR NOT PRESENT."
                 "\r\n", -1);
        while(1);
    }
    else if(nandInfo.devId != NAND_DEVICE_ID)
    {
        /* Check if detected ID matches supplied ID */
        UARTPuts("\r\n*** ERROR : INVALID DEVICE ID.", -1);
        while(1);
    }
    else
    {
        /* Print The Device ID info */
        NANDDeviceIdInfoPrint(&nandInfo);
    }
    
#ifdef NAND_DATAINTEGRITY_TEST_WITH_FIXED_ADDR
    /* Do read/write for predefined address */
    pageNum = NAND_DEFAULT_START_PAGE;
    blkNum = NAND_DEFAULT_BLK;
    numOfPages = NAND_DEFAULT_NMBR_OF_PAGES;   
#else
    /* Take the read/write address from the user */
    UARTPuts("\r\n Please Enter The Block Number(0 - ", -1);
    UARTPutNum((unsigned int)(NAND_NUMOF_BLK - 1));
    UARTPuts(")\r\n", -1);
    blkNum = UARTGetNum();
    UARTPuts("\r\n Please Enter The Page Start Page Number(0 - ", -1);
    UARTPutNum((unsigned int)(nandInfo.pagesPerBlk - 1));
    UARTPuts(")\r\n", -1);
    pageNum = UARTGetNum();
    UARTPuts("\r\n Please Enter The Number Of Pages To Write\r\n", -1);
    numOfPages = UARTGetNum();
#endif
    eraseBlkFlg = 1;
    
    if( (pageNum < 0 ) || (pageNum > (nandInfo.pagesPerBlk - 1))
        || (blkNum < 0 || blkNum  > (NAND_NUMOF_BLK - 1)) || (numOfPages <= 0) )
    {
        UARTPuts("\r\n *** ERROR : Wrong Input(s) Entered...!!!\r\n", -1);
        while(1);
    }
    else if( ( blkNum * (nandInfo.pagesPerBlk )
              + pageNum + numOfPages ) >
              ( NAND_NUMOF_BLK * nandInfo.pagesPerBlk))
    {
        UARTPuts("\r\n *** ERROR : Requsted Page(s) For Read/Write Does Not"
                 " Exist...!!!\r\n", -1);
        while(1);
    }    
   
    while( numOfPages > 0 )
    {
        if( eraseBlkFlg )
        {
            retVal = NANDBadBlockCheck(&nandInfo, blkNum);
            if(retVal == NAND_BLOCK_BAD)
            {
                UARTPuts("\r\n Block Is Bad, Can't Continue ...!!! ",-1);
                while(1);
            }
            if(retVal == NAND_BLOCK_SPARE_AREA_READ_FAILED)
            {
                UARTPuts("\r\n Spare Area Read Failed While Checking ", -1);
                UARTPuts(" For Bad Block ", -1);
                while(1);
            }

            UARTPuts("\r\n Erasing The Block ", -1);
            UARTPutNum((unsigned int)blkNum);
            UARTPuts("                         :", -1);

            retVal = NANDBlockErase(&nandInfo, blkNum);
            if( retVal == NAND_STATUS_PASSED )
            {
                UARTPuts(" Succeeded.",-1);
            }
            else
            {
                UARTPuts(" Failed.", -1);
                UARTPuts("\r\n Marking The Block As Bad.\r\n Read/Write Test", -1);
                UARTPuts(" Will Be Continued On Next block. ", -1);
                NANDMarkBlockAsBad(&nandInfo, blkNum);
                blkNum++;
                pageNum = 0;
                eraseBlkFlg = 1;
                continue;
            }
            eraseBlkFlg = 0;
        }

        NANDBuffersInit();
        UARTPuts("\r\n Writing To Page ", -1);
        UARTPutNum((unsigned int)pageNum);
        UARTPuts(" Of Block ", -1);
        UARTPutNum((unsigned int)blkNum);
        UARTPuts("                :", -1);

        retVal = NANDPageWrite(&nandInfo, blkNum, pageNum, &txData[0],
                               &eccData[0]);
        if( (retVal & NAND_STATUS_WAITTIMEOUT) )
        {
            UARTPuts(" Failed.(Device Is Busy).", -1);
            while(1);
        }
        else if( (retVal & NAND_STATUS_DEVWRPROTECT) )
        {
            UARTPuts(" Failed.(Device Is Write Protected).", -1);
            while(1);
        }
        else if( (retVal & NAND_STATUS_READWRITE_DMA_FAIL) )
        {
            UARTPuts(" Failed.(EDMA Transfer Failed.).", -1);
            while(1);
        }
        else
        {
            UARTPuts(" Succeeded.", -1);
        }

        /* As eccData, is filled by NANDPageWrite fun, reinit the same */
        NANDBuffersInit();

        UARTPuts("\r\n Reading From Page ", -1);
        UARTPutNum((unsigned int)pageNum);
        UARTPuts(" Of Block ", -1);
        UARTPutNum((unsigned int)blkNum);
        UARTPuts("              :", -1);
        retVal= NANDPageRead(&nandInfo, blkNum, pageNum, &rxData[0],
                             &eccData[0]);

        if( (retVal & NAND_STATUS_READ_ECC_ERROR_CORRECTED) )
        {
            UARTPuts(" Succeeded With ECC Errors And Corrected.", -1);
        }
        else if( (retVal & NAND_STATUS_READ_ECC_UNCORRECTABLE_ERROR) )
        {
            UARTPuts(" Failed.(Uncorrectable ECC errors) ", -1);
            while(1);
        }
        else if( (retVal & NAND_STATUS_READWRITE_DMA_FAIL) )
        {
            UARTPuts(" Failed.(EDMA Transfer Failed.)", -1);
            while(1);
        }
        else
        {
            UARTPuts(" Succeeded.",-1);
        }

        UARTPuts("\r\n NAND Data Integrity Test                    :", -1);
        retVal = NANDDataIntegrityCheck();
        if(retVal == NAND_DATA_INTEGRITY_PASS)
        {
            UARTPuts(" Passed\r\n", -1);
        }
        else
        {
            UARTPuts(" Failed....!!!\r\n", -1);
        }

        pageNum++;
        numOfPages--;
        if( pageNum == ((nandInfo.pagesPerBlk) ) )
        {
            pageNum = 0;
            eraseBlkFlg = 1;
            blkNum++;
        }
    }

    UARTPuts("\r\n ****************************************************** ", -1);
    while(1);    
}