Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

Secure Digital test.

// Built with BFTC Rev. 1.0.0, mar 19 agosto 2014 09:46:37

/*
    Copyright 2014 Digital Technology Art SRL
    This file is part of Blackfin Toolchain (BFTC) project.

    BFTC is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BFTC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Nome-Programma.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "main.h"

#define ST st = Get_TimerCounter(TIMER_0)
#define ET et = Get_TimerCounter(TIMER_0)

#define TIMEBASE 0xFFFFFFFF
#define NSECT   128     // 128 * 512 = 65536

unsigned randx(unsigned val)
{
    return Get_TimerCounter(TIMER_0) * 0x1961957 + val;
}

void display(const char * header, unsigned int et, unsigned int st)
{
    unsigned tx;
    if(st > et) tx = TIMEBASE - st + et;
    else tx = et - st;
    printf("%s Test, Elapsed time: %4ums, %5uKB/s\n", header, tx / 100000, (NSECT * 512 * 1000) / (tx / 100000) / 1024);
}

int main(void)
{
    unsigned long       st, et;
    int                         i, er;
    struct SD_Info      info;
    unsigned char       wbuf[512];
    unsigned char       rbuf[512];
    unsigned long       offset;
    
    Set_PLL(16, 4);     // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz
    Set_Port();         // Set the port according to project set
    Set_Uart0(115200);  // printf is redirected to UART0
    Set_TimerCounter(TIMER_0);
    Set_TimerEnable(TIMER_0, true);
    
    while(1)            // Main loop
    {
        printf("Press any key to start the test\n");
        GetChar_Uart0();
        SD_Power(true);
        DelayUs(100000);        // 100 ms power up
        er = SD_Init();
        if(er == SD_STS_OK)
        {
            printf("MMC/SD Init OK\n");
            SD_GetInfo(&info);
            printf("Manufacturer        = %d\n",                        (int) info.manufacturer);
            printf("OEM                 = %c%c%c\n",            (int) info.oem[0], (int) info.oem[1], (int) info.oem[2]);
            printf("Product             = %c%c%c%c%c%c\n",      (int) info.product[0], (int) info.product[1], (int) info.product[2], (int) info.product[3], (int) info.product[4], (int) info.product[5]);
            printf("Revision            = %d\n",                        (int) info.revision);
            printf("Serial              = %u\n",                        info.serial);
            printf("Manufacturing year  = %d\n",                        2000 + info.manufacturing_year);
            printf("Manufacturing month = %d\n",                        (int) info.manufacturing_month);
            printf("Capacity            = %u Kbyte\n",          (int) (info.capacity / 1024));
            printf("\n");
            printf("Writing %d bytes ... ", NSECT * 512);
            for(i = 0; i < 512; i++)
                wbuf[i] = randx(i);
            ST;
            for(i = 0; i < NSECT; i++)
            {
                SD_Write(offset, wbuf, 512);
                offset += 512;
            }
            ET; display("Writing", et, st);
            
            printf("Reading %d bytes ... ", NSECT * 512);
            offset = 0;
            ST;
            for(i = 0; i < NSECT; i++)
            {
                SD_Read(offset, rbuf, 512);
                offset += 512;
            }
            ET; display("Reading", et, st);
            
            // Verify last read
            for(i = 0; i < 512; i++)
                if(wbuf[i] != rbuf[i])
                    break;
            if(i < 512)
                printf("Compare error at %d, read %d instead of %d\n", i, rbuf[i], wbuf[i]);
            else
                printf("Done, test OK\n");
            printf("Test finished. Remove SD\n");
            
            // Turn off
            SD_Power(false);
        }
        else
        {
            switch(er)
            {
                case SD_STS_NOCARD:     
                    printf("MMC/SD not inserted\n");
                    break;
                default:                        
                    printf("MMC/SD Unknown error [%d]!\n", er);
            }
            SD_Power(false);
            Set_SPI(SPI_PP);
            printf("PB port status %02x\n", Get_Controls());
        }
    }
    return 0;
}

Generated on Tue Apr 7 20:07:44 2015 for BF592A Library by doxygen 1.3.1