📄 fts.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 : fts.c
//* Object : Functionnal Test Software for AT91EB55 Evaluation Board
//* Translator : ARM Software Development Toolkit V2.5
//
//* Exported resources : BootFts
//* Imported resources :
//
//* 1.0 17/07/00 PF : Creation
//*-----------------------------------------------------------------------------
#include "parts/m55800/lib_m55800.h"
#include "drivers/serial_periph_1/serial_periph_1.h"
#include "dataflash.h"
#include "drivers/lib_i2c/lib_i2c.h"
#include "targets/eb55/eb55.h"
#include "drivers/wait/wait.h"
#include "drivers/time_rtc/time_rtc.h"
#include "at24c512.h"
#include "at25256.h"
#include "flash_16x4.h"
#include "rtc_utility.h"
#define PIO_BASE PIOB_BASE
/* ----------------------- */
/* USART CONFIG AND MODE */
/* ----------------------- */
#define BAUD_RATE (32000000 / (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)
/* ------------------------- */
/* Serial Data Flash Memory */
/* ------------------------- */
/* Global variables */
/* 32Kbytes buffer to read and write */
u_char buffer_data_flash1[128] ;
u_char buffer_data_flash2[128] ;
/* ------------------- */
/* SPI EEPROM Memory */
/* ------------------- */
#define SPI_CONFIG (SP_CPOL |(50<<8) | (80<<16) | (0<<24) )
//* -------------------------------------
//* SPI EEPROM Descriptor Initialization
//* -------------------------------------
SerialPeriph1DataDesc spi_eeprom_data ;
SerialPeriph1Desc spi_eeprom_desc =
{
&SPI_DESC, /* SPI Descriptor */
&spi_eeprom_data, /* SPI Data Descriptor */
(SP_MSTR | SP_PS_FIXED | SP_PCS3 | (8<<24)), /* SPI Mode : SP_MR */
SP_CPOL | (255 << 16) | (50 << 8) | (2<<24), /* Peripheral Chip Select Register Configuration : SP_CSR */
SPI_NPCS3_USED, /* SPI Chip Select Line used */
at91_default_irq_handler, /* Assembler Handler */
0x3 /* SPI EEPROM connected on NPCS3 */
};
/* ------------------------- */
/* Serial EEPROM Memory */
/* ------------------------- */
u_char rxBuffer [AT24C512_PAGE_LENGTH];
u_char txBuffer [AT24C512_PAGE_LENGTH];
/* ----------------------------- */
/* VDDCORE Voltage range test */
/* ----------------------------- */
#define LOW_VOLTAGE_LEVEL (0x15e)
#define HIGH_VOLTAGE_LEVEL (0x30d)
#define AVERAGE_FACTOR (0x30)
#define PRESCALER_MASK (0x10)
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 : Write 0xBEEF and Read Back the value @ 0x01080000
//* Input Parameters : None
//* Output Parameters : TRUE or FALSE
//* Functions called : at91_write_flash, at91_erase_sector
//*----------------------------------------------------------------------------
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 :
//*--------------------------------------------------------------------------------------
u_int spi_dataflash_test( void )
//* Begin
{
u_int i ;
/* Necessary if external decoder is used to select dataflash */
/* Enable PIOA Clock */
at91_clock_open ( PIOA_ID ) ;
at91_pio_close (&PIOA_DESC,PA26) ;
at91_pio_open ( &PIOA_DESC, (PA27 | PA28 | PA29) , PIO_OUTPUT) ;
at91_pio_write (&PIOA_DESC, (PA27 | PA28 | PA29), PIO_CLEAR_OUT ) ;
if (dataflash_open() != TRUE)
return FALSE;
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 ;
}
at91_pio_close (&PIOA_DESC,PA26) ;
at91_pio_open ( &PIOA_DESC, (PA27 | PA28 | PA29) , PIO_OUTPUT) ;
at91_pio_write (&PIOA_DESC, (PA27 | PA28 | PA29), PIO_CLEAR_OUT ) ;
dataflash_write_buffer ( buffer_data_flash1, 0x0, 128) ;
at91_pio_close (&PIOA_DESC,PA26) ;
at91_pio_open ( &PIOA_DESC, (PA27 | PA28 | PA29) , PIO_OUTPUT) ;
at91_pio_write (&PIOA_DESC, (PA27 | PA28 | PA29), PIO_CLEAR_OUT ) ;
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 = (u_char*)0x2030000 ;
//* Force the SPI Chip Select Decoder
at91_clock_open ( PIOA_ID ) ;
at91_pio_open ( &PIOA_DESC, (PA26 | PA27 | PA28), PIO_OUTPUT ) ;
at91_pio_write ( &PIOA_DESC, PA28, PIO_SET_OUT ) ;
at91_pio_write ( &PIOA_DESC, (PA26 | PA27), PIO_CLEAR_OUT ) ;
//* 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 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -