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

FLASH test.

// Built with BFTC Rev. 1.0.0, ven 22 agosto 2014 14:14:29

/*
    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/>.
*/

// Warning for this test X8 must be populated with a M25P32!
//
#include "main.h"

#define TIMEBASE 0xFFFFFFFF
#define ST st = Get_TimerCounter(TIMER_0)
#define ET et = Get_TimerCounter(TIMER_0)

unsigned char wbuf[1024];
unsigned char rbuf[1024];

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

void display(const char * header, unsigned int et, unsigned int st)
{
    double tx;
    if(st > et) tx = TIMEBASE - st + et;
    else tx = et - st;
    printf("%s Test, Elapsed time: %10.3f ms\n", header, tx / 100000.0);
}

int main(void)
{
    unsigned    st, et;
    int             address = 0, i, er;
    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);
    Set_SPI(SPI_MEM_2); // X8
    while(1)                    // Main loop
    {
        printf("Press any key to start the test\n");
        GetChar_Uart0();
        // Fill the buffer with random values
        for(i = 0; i < 1024; i++)
            wbuf[i] = randx(i);
        // Erase selected sector
        ST;
        er = FLSH_EraseBlock(address);
        ET; display("Erase", et, st);
        if(er == FLSH_NO_ERR)
        {
            ST;
            er = FLSH_WriteData(address * 1024, 1024, wbuf);
            ET; display("Writing", et, st);
            if(er == FLSH_NO_ERR)
            {
                ST;
                er = FLSH_ReadData(address * 1024, 1024, rbuf);
                ET; display("Reading", et, st);
                if(er == FLSH_NO_ERR)
                {
                    for(i = 0; i < 1024; i++)
                        if(wbuf[i] != rbuf[i])
                        {
                            printf("Compare error at %d, read %d instead of %d\n", i, rbuf[i], wbuf[i]);
                            break;
                        }
                    if(i == 1024)
                        printf("Test OK\n");
                }
                else printf("READ Error = %d\n", er);
            }
            else printf("WRITE Error = %d\n", er);
        }
        else printf("ERASE Error = %d\n", er);
        address++;
    }
    return 0;
}

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