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

📄 test_data_flash_eb63.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
字号:
//*--------------------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*---------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*---------------------------------------------------------------------------
//* File Name           : test_data_flash_eb63.c
//* Object              : Data Flash Test Program.
//*
//* 1.0 20/09/99 JCZ    : Creation
//* 1.1 07/09/00 PF     : Clean up
//*---------------------------------------------------------------------------

#include    "parts/m63200/lib_m63200.h"
#include    "targets/eb63/eb63.h"
#include    "at45db161.h"
#include    <stdio.h>

/* Global variables */
/* 32Kbytes buffer to read and write */
u_char  buffer_data_flash1[528] ;
u_char  buffer_data_flash2[528] ;

//*---------------------------------------------------------------------------
//* Function Name       : display_buffer
//* Object              : Displaying the buffer
//* Input Parameters    : <*buffer> : Buffer to display
//*                     : <size>    : Number of data to display
//* Output Parameters   : None
//* Functions called    :
//*---------------------------------------------------------------------------
void display_buffer ( u_char *buffer, int size )
{
    u_int address = 0 ;

    while ( size > 0 )
    {
        if (( address & 0x7 ) == 0 )
            printf ( "0x%04X :", address ) ;

        printf ( " %02X", *buffer ) ;
        address ++ ;
        size -- ;
        buffer ++ ;
        if (( address & 0x7 ) == 0 )
            printf ("\n") ;
    }
    printf ("\n\n") ;
}

//*---------------------------------------------------------------------------
//* Function Name       : Main
//* Object              : Test communication beetwen Serial Data flash and SPI
//* 					  AT91 port
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    : db161_open, db161_close, db161_write_buffer,
//*                       db161_read_buffer
//*---------------------------------------------------------------------------
int main ( void )
//* Begin
{
    u_int type_flash ;
    u_int i ;

    for (;;)
    {
    for ( i=0; i<528; i++ )
    {
        buffer_data_flash1[i] = (u_char)(i&0xFF) ;
    }

    for ( i=0; i<528; i++ )
    {
        buffer_data_flash2[i] = 0xFF ;
    }


    at91_pio_open (&PIOB_DESC, LED_MASK, PIO_OUTPUT) ;
    at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF) ;

    type_flash = db161_open () ;
    printf ("Type de Data Flash = 0x%08X\n", type_flash ) ;


#ifndef AT91_DEBUG_NONE

    printf ("\nDisplaying Buffer 1 before writing to Data Flash\n" ) ;
    display_buffer ( buffer_data_flash1, 528 ) ;

    printf ("Displaying Buffer 2 before writing to Data Flash\n" ) ;
    display_buffer ( buffer_data_flash2, 528 ) ;

#endif

    at91_pio_write (&PIOB_DESC, LED1, LED_ON) ;
    db161_write_buffer ( buffer_data_flash1, 0x0, 528) ;

    at91_pio_write (&PIOB_DESC, LED1, LED_OFF) ;
    at91_pio_write (&PIOB_DESC, LED2, LED_ON) ;
    db161_read_buffer ( 0x0, buffer_data_flash2, 528) ;

#ifndef AT91_DEBUG_NONE

    printf ("Displaying Buffer 2 after reading Data Flash\n" ) ;
    display_buffer ( buffer_data_flash2, 528 ) ;
#endif


    for ( i=0; i<528; i++ )
    {
        buffer_data_flash1[i] = (u_char)(i&0xFF) ;
        if ( buffer_data_flash2[i] != buffer_data_flash1[i] )
        {
#ifndef AT91_DEBUG_NONE

            printf ("Test Serial DataFlash AT45DB161 Failed !\n" ) ;
#endif
            at91_pio_write (&PIOB_DESC, LED1, LED_OFF) ;
            at91_pio_write (&PIOB_DESC, LED8, LED_ON) ;
            return ( FALSE ) ;
        }
    }

#ifndef AT91_DEBUG_NONE

    printf ("Test Serial DataFlash AT45DB161 OK !\n" ) ;
#endif
    db161_close () ;

    at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF) ;
    at91_pio_write (&PIOB_DESC, LED1|LED3|LED5|LED7, LED_ON) ;

   }

    return ( TRUE ) ;
}
//* End

⌨️ 快捷键说明

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