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

📄 fts.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
//*--------------------------------------------------------------------------------------
//*      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           : fts.c
//* Object              : Functionnal Test Software of AT91EB63 Evaluation Board
//* Translator          : ARM Software Development Toolkit V2.5
//
//* Exported resources  : BootFts
//* Imported resources  :
//
//* 1.0 00/00/00 JLV    : Creation
//* 2.0 18/08/00 PF     : Clean up
//* 2.1 06/10/00 PF     : Clean up
//* 2.2 29/01/02 PFi    : Clean up
//*--------------------------------------------------------------------------------------
#include "parts/m63200/lib_m63200.h"
#include "targets/eb63/eb63.h"
#include "drivers/serial_periph_1/serial_periph_1.h"
#include "dataflash.h"
#include "drivers/lib_i2c/lib_i2c.h"
#include "at24c512.h"
#include "drivers/wait/wait.h"

/* ------------------------- */
/* Serial Data Flash Memory  */
/* ------------------------- */
#define SPI_CONFIG          (SP_CPOL |(50<<8) | (80<<16) | (0<<24) )

#define DB161_BUF1_READ         0x54        /* Buffer 1 read */
#define DB161_BUF2_READ         0x56        /* Buffer 2 read */
#define DB161_BUF1_WRITE        0x84        /* Buffer 1 write */
#define DB161_BUF2_WRITE        0x87        /* Buffer 2 write */
#define DB161_STATUS            0x57        /* Status Register */

/* ------------------------- */
/* Serial Data Flash Memory  */
/* ------------------------- */
/* 32Kbytes buffer to read and write */
/* Global variables */
u_char  buffer_data_flash1[128] ;
u_char  buffer_data_flash2[128] ;

/* --------------------- */
/* Serial EEPROM Memory  */
/* --------------------- */
/* buffer to read and write */
u_char  txBuffer[AT24C512_PAGE_LENGTH] ;
u_char  rxBuffer[AT24C512_PAGE_LENGTH] ;


/* ----------------------- */
/* USART CONFIG AND MODE   */
/* ----------------------- */
#define USART_RESET     (US_RSTSTA | US_RSTTX | US_RSTRX)
#define USART_ENABLE    (US_RXEN | US_TXEN)
#define BAUD_RATE       (25000000 / (16 * 115200))    //* CD = 14


extern StructEBI   *const PtEBIBase ;
extern u_int ram_test ( u_int *base, u_int size );
extern u_short *relocate ( u_short *base, u_short *dest, u_int size );
extern WaitDesc wait_desc ;


//*--------------------------------------------------------------------------------------
//* Function Name       : internal_ram_test
//* Object              :
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    :
//*--------------------------------------------------------------------------------------
u_int internal_ram_test( void )
//* Begin
{
    return ( ram_test ( 0, 2*1024 )) ;
}
//* End

//*--------------------------------------------------------------------------------------
//* Function Name       : external_ram_test
//* Object              : External RAM
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    :
//*--------------------------------------------------------------------------------------
u_int external_ram_test( void )
//* Begin
{
    typedef u_int (type_fct(u_int *base, u_int size)) ;
    type_fct    *fct ;

    fct = (type_fct *) relocate ( (u_short *)ram_test, (u_short *)0x100, 0x100) ;
    return ( fct ( (u_int *)0x2000000, 512*1024 )) ;
}
//* End

//*--------------------------------------------------------------------------------------
//* Function Name       : mpi_test
//* Object              :
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    :
//*--------------------------------------------------------------------------------------
u_int mpi_test( void )
//* Begin
{
    return ( ram_test ( (u_int *)MPI_BASE, 1*1024 )) ;
}
//* End

//*----------------------------------------------------------------------------
//* Function Name       : ext_flash_test
//* Object              : Read the Manufacturer Code and check it.
//* Input Parameters    : None
//* Output Parameters   : TRUE or FALSE
//* Functions called    : at91_flash_identify
//*----------------------------------------------------------------------------
u_int ext_flash_test( void )
//* Begin
{
    flash_word flash_data ;
    flash_word *address = (flash_word*)0x1000000 ;

    if ( (flash_data = *address) != (flash_word)0xFFFF )
        return ( TRUE ) ;

    else
        return ( FALSE ) ;
}
//* End

//*--------------------------------------------------------------------------------------
//* Function Name       : spi_dataflash_test
//* Object              : Write/Read Test by SPI port
//* Input Parameters    : None
//* Output Parameters   : TRUE or FALSE
//* Functions called    : dataflash_open, dataflash_write_buffer, dataflash_read_buffer
//*--------------------------------------------------------------------------------------
u_int spi_dataflash_test( void )
//* Begin
{
    u_int       type_flash ;
    u_int       i ;


    if (dataflash_open() != TRUE)
    return FALSE;

    type_flash = dataflash_open() ;

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


    dataflash_write_buffer ( buffer_data_flash1, 0x0, 128) ;

    dataflash_read_buffer ( 0x0, buffer_data_flash2, 128) ;

    for ( i=0; i<128; i++ )
    {
        buffer_data_flash1[i] = (u_char)(i&0xFF) ;
        if ( buffer_data_flash2[i] != buffer_data_flash1[i] )
        {
            return ( FALSE ) ;
        }
    }

    dataflash_close () ;

    return ( TRUE ) ;
}
//* End

//*--------------------------------------------------------------------------------
//* Function Name       : serial_eeprom_test
//* Object              : Test the Serial EEPROM connection with serial I2C memory
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    :
//*---------------------------------------------------------------------------------
u_int serial_eeprom_test( void )
//* Begin
{

    u_int i ;
    u_short eeprom_address = 0x0 ;
    u_int i2c_speed = ((MCK/4)/5000) ;         // Communication speed is set to 5KHz

    // Open the communication with the two-wire EEPROM
    at24_Init( i2c_speed ) ;

    // Initialization of the buffer to transmit
    for (i=0; i <=AT24C512_PAGE_LENGTH; i++ )
    {
        txBuffer[i]=i;
    }

    // We wait for any previous transfert to end
    at24_TransfertEnd();

    // We write the txBuffer in the EEPROM at address 0
    at24_Write(eeprom_address, txBuffer, AT24C512_PAGE_LENGTH ) ;

    // We wait for any previous transfert to end
    at24_TransfertEnd();

    // The buffer we wrote is reading back from EEPROM, and stored in rxBuffer
    at24_Read( eeprom_address, rxBuffer, AT24C512_PAGE_LENGTH ) ;

    // Checking
    for ( i=0 ; i < AT24C512_PAGE_LENGTH ; i++)
    {
        if ( rxBuffer[i] != txBuffer[i])
        {
            at24_TransfertEnd();
            return (FALSE);
        }
    }

    at24_TransfertEnd();

    return ( TRUE ) ;
}
//* End

⌨️ 快捷键说明

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