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

📄 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 for AT91EB42 Evaluation Board
//* Translator          : ARM Developper Suite v1.1
//
//* Exported resources  : BootFts
//* Imported resources  :
//*
//* 1.0 17/10/01   PFi  : Creation
//* 2.0 29/01/02   PFi  : Clean up. serial_eeprom_test adapted for new lib_i2c dirvers.
//*                     : New version : 1.02
//*----------------------------------------------------------------------------------------------

#include "parts/m42800/lib_m42800.h"
#include "drivers/serial_periph_1/serial_periph_1.h"
#include "dataflash.h"
#include "drivers/lib_i2c/lib_i2c.h"
#include "targets/eb42/eb42.h"
#include "drivers/wait/wait.h"
#include "at24c512.h"
#include "at25256.h"
#include "flash_16x4.h"

#define PIO_BASE        PIOB_BASE

/* ----------------------- */
/* USART CONFIG AND MODE   */
/* ----------------------- */
#define BAUD_RATE       (32768000 / (16 * 115200))  //* CD = 17

#define USART_MODE      US_CHMODE_NORMAL + \
                        US_NBSTOP_1 + \
                        US_PAR_NO + \
                        US_CHRL_8 + \
                        US_CLKS_MCK

#define USART_RESET     (US_RSTSTA | US_RSTTX | US_RSTRX)
#define USART_ENABLE    (US_RXEN | US_TXEN)


/* Global variables */
/* buffer to read and write */
u_char  txBuffer[AT24C512_PAGE_LENGTH] ;
u_char  rxBuffer[AT24C512_PAGE_LENGTH] ;

/* ------------------- */
/* SPI EEPROM  Memory  */
/* ------------------- */
#define SPIA_CONFIG         (SP_CPOL |(50<<8) | (80<<16) | (0<<24) )
//* -------------------------------------
//* SPI EEPROM Descriptor Initialization
//* -------------------------------------

SerialPeriph1DataDesc    spi_eeprom_data ;

SerialPeriph1Desc   spi_eeprom_desc =
{
    &SPIA_DESC,                                         /* SPI Descriptor */
    &spi_eeprom_data,                                   /* SPI Data Descriptor */
    (SP_MSTR | SP_PS_FIXED | SP_PCS1 | (8<<24)),        /* SPI Mode : SP_MR */
    SP_CPOL | (255 << 16) | (50 << 8) | (2<<24),        /* Peripheral Chip Select Register Configuration : SP_CSR */
    SPI_NPCS1_USED,                                     /* SPI Chip Select Line used */
    at91_default_irq_handler,                           /* Assembler Handler */
    0x1                                                 /* SPI EEPROM connected on NPCS3 */
};

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


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              : Internal RAM Test
//* Input Parameters    : None
//* Output Parameters   : None
//* Functions called    :
//*----------------------------------------------------------------------------
u_int internal_ram_test( void )
//* Begin
{
    return ( ram_test ( 0, 8*1024 )) ;
}
//* End

//*----------------------------------------------------------------------------
//* Function Name       : external_ram_test
//* Object              : External RAM Test
//* 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       : 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       : 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


//*--------------------------------------------------------------------------------------
//* Function Name       : spi_dataflash_test
//* Object              : Write/Read Test by SPI port
//* Input Parameters    : None
//* Output Parameters   : TRUE or FALSE
//* Functions called    : db321_open, db321_close, db321,write_buffer, db321_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       : spi_eeprom_test
//* Object              : Write/Read Test with the SPI EEPROM
//* Input Parameters    : None
//* Output Parameters   : TRUE or FALSE
//* Functions called    :
//*----------------------------------------------------------------------------
u_int spi_eeprom_test( void )
//* Begin
{
    u_char  *read_value ;

    //* Enable Writing to the Memory  : WREN Instruction
    if ( at25_open ()!= TRUE )
        return ( FALSE ) ;

    //* Writing data 0x5 to Address 0 of the SPI EEPROM
    at25_write_byte ( 0x0, 0x05 ) ;

    //* Reading Address 0 of the SPI EEPROM
    at25_read_byte ( 0x0, read_value ) ;

    //* We compare
    if ( *read_value != 0x05 )
        return ( FALSE ) ;

    return (TRUE ) ;
}
//* End

⌨️ 快捷键说明

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