// Built with BFTC Rev. 1.0.0, gio 14 agosto 2014 16:19: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"

 

unsigned char buff_r[512];

unsigned char buff_w[512];

int main(void)

{

    unsigned char flag;

    int i, s;

    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_SPI(SPI_PP);

    Set_ExpansionPort(0xFF);    // PA all in input

    do

    {

        printf("Press any key to start the test ...\n");

        GetChar_Uart0();

        if(MMC_Open())

        {

            printf("MMC Card enabled, test started ...\n");

            for(i = 0; i < 512; i++)

                buff_w[i] = i;

            flag = 1;

            for(s = 0; s < 1024; s++)

            {

                MMC_WriteSector(s, buff_w);

                MMC_ReadSector(s, buff_r);

                for(i = 0; i < 512; i++)

                {

                    if(buff_w[i] != buff_r[i])

                    {

                        flag = 0;

                        break;

                    }

                }

                if(flag)

                    printf("[%4d] MMC Test OK\n", s);

                else

                {

                    printf("[%4d] MMC Test Fail\n", s);

                    break;

                }

            }

            MMC_Close();

        }

        else

        {

            MMC_Close();

            printf("MMC Card error\n");

        }

    }while(1);

    return 0;

}