📄 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 AT91EB40A Evaluation Board
//* Translator : ARM Developper Suite v1.1
//
//* Exported resources : BootFts
//* Imported resources :
//
//* 1.0 06/11/01 PFi : Creation
//* 1.1 21/01/01 PFi : I2C test clean-up
//*-----------------------------------------------------------------------------
#include "parts/r40008/lib_r40008.h"
#include "targets/eb40a/eb40a.h"
#include "drivers/lib_i2c/lib_i2c.h"
#include "drivers/wait/wait.h"
#include "at24c512.h"
#include "flash_16x4.h"
/* ----------------------- */
/* USART CONFIG AND MODE */
/* ----------------------- */
#define BAUD_RATE (66000000 / (16 * 115200)) //* CD = 36
#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)
//* Define ON_BOARD_EXT_SRAM at TRUE if External SRAM is present
#define ON_BOARD_EXT_SRAM FALSE
/* ------------------------- */
/* Serial EEPROM Memory */
/* ------------------------- */
u_char rxBuffer [AT24C512_PAGE_LENGTH];
u_char txBuffer [AT24C512_PAGE_LENGTH];
/* External function declaration */
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
{
u_int march_lr_result_1 = *(u_int*)0x20000;
u_int march_lr_result_2 = *(u_int*)0x20004;
if ( (march_lr_result_1 == (u_int)0x0000BEAD) & (march_lr_result_2 == (u_int)0x0000BEAD) )
return ( TRUE ) ;
else
return ( FALSE ) ;
}
//* End
//*----------------------------------------------------------------------------
//* Function Name : external_ram_test
//* Object : External RAM Test
//* Input Parameters : None
//* Output Parameters : None
//* Functions called : relocate, ram_test
//*----------------------------------------------------------------------------
u_int external_ram_test( void )
//* Begin
{
u_int ext_sram_on = ON_BOARD_EXT_SRAM ;
u_int *sram_base_addr = (u_int *)0x2000000 ;
if ( ext_sram_on == TRUE )
return ( (ram_test ( sram_base_addr, (u_int)EXT_SRAM_SIZE ) ) ) ;
return ( TRUE ) ;
}
//* End
//*----------------------------------------------------------------------------
//* Function Name : ext_flash_test
//* Object : Read the Device code and the Manufacturer code
//* Input Parameters : None
//* Output Parameters : Device code and the Manufacturer code
//* Functions called : None
//*----------------------------------------------------------------------------
u_int ext_flash_test( void )
//* Begin
{
flash_word *id_code, *man_code ;
at91_flash_identify ( (flash_word*)0x01000000, man_code, id_code ) ;
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
//*---------------------------------------------------------------------------------------
//* Function Name : usart_test
//* Object : Test beetwen USART0 and USART1 with loopback and external cable
//* Input Parameters : None
//* Output Parameters : None
//* Functions called : at91_usart_open, at91_trig_cmd, at91_usart_close
//* : at91_usart_write, at91_usart_read
//*------------------------------------------------------------------------------------------
int usart_test (void)
//* Begin
{
StructUSART *us0_pt = USART0_BASE ;
StructUSART *us1_pt = USART1_BASE ;
u_int *pt_us_char = (u_int*)0x20200 ;
u_int val_read ;
int error = 0 ;
int count = 0 ;
//* -- Configure Serial ports 0 and 1 for internal loopback test
//*-------------------------------------------------------------
at91_usart_open ( &USART0_DESC , (USART_MODE | US_CHMODE_LOCAL_LOOPBACK) , BAUD_RATE , 0x0 ) ;
us0_pt->US_IDR = 0x3FF ;
us0_pt->US_RTOR = 0x0 ;
at91_usart_trig_cmd ( &USART0_DESC , USART_RESET ) ;
at91_usart_trig_cmd ( &USART0_DESC , USART_ENABLE ) ;
at91_usart_open ( &USART1_DESC , (USART_MODE | US_CHMODE_LOCAL_LOOPBACK) , BAUD_RATE , 0x0 ) ;
us1_pt->US_IDR = 0x3FF ;
us1_pt->US_RTOR = 0x0 ;
at91_usart_trig_cmd ( &USART1_DESC , USART_RESET ) ;
at91_usart_trig_cmd ( &USART1_DESC , USART_ENABLE ) ;
/* -- Test 1 - send from Serial A to Serial A (loopback) -- */
at91_usart_write (&USART0_DESC, 0x0031);
while (((us0_pt->US_CSR & 0x1)!=0x1) & (count != 2000))
{
//* -- Wait the RXRDY flag high
count++;
}
at91_usart_read (&USART0_DESC, pt_us_char ) ;
val_read = *pt_us_char ;
if ( val_read != 0x0031)
error++ ;
/* -- Test 2 - send from Serial B to Serial B (loopback) -- */
at91_usart_write (&USART1_DESC, 0x0032) ;
count = 0 ;
while (((us1_pt->US_CSR & 0x1)!=0x1) & (count != 2000))
{
//* -- Wait the RXRDY flag high
count++;
}
at91_usart_read (&USART1_DESC, pt_us_char ) ;
val_read = *pt_us_char ;
if ( val_read != 0x0032)
error++ ;
//* -- Configure Serial ports for external cable test
//* --------------------------------------------------
/* -- Normal loopback, 1 stop bit, no parity, async., 8 bit character, MCK -- */
at91_usart_open ( &USART0_DESC , USART_MODE , BAUD_RATE , 0x0 ) ;
/* Normal loopback, 1 stop bit, no parity, async., 8 bit character, MCK */
at91_usart_open ( &USART1_DESC , USART_MODE , BAUD_RATE , 0x0 ) ;
//* -- Test 3 - send from Serial A to Serial B (external cable)
at91_usart_write (&USART0_DESC, 0x0033) ;
count = 0 ;
while (((us1_pt->US_CSR & 0x1)!=0x1) & (count != 2000))
{
//* -- Wait the RXRDY flag high
count++;
}
at91_usart_read (&USART1_DESC, pt_us_char ) ;
val_read = *pt_us_char ;
if ( val_read != 0x0033)
error++ ;
//* -- Test 4 - send from Serial B to Serial A (external cable)
at91_usart_write (&USART1_DESC, 0x0034) ;
count = 0 ;
while (((us0_pt->US_CSR & 0x1)!=0x1) & (count != 2000))
{
//* -- Wait the RXRDY flag high
count++;
}
at91_usart_read (&USART0_DESC, pt_us_char ) ;
val_read = *pt_us_char ;
if ( val_read != 0x0034)
error++ ;
if (error > 0 )
return ( FALSE );
else return ( TRUE );
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : show_ok
//* Object : Light on the test led during 200ms and return
//* Input Parameters : <mask> = led showing the test in progress
//* Output Parameters : None
//* Functions called : at91_tc_wait_open, at91_pio_write
//*----------------------------------------------------------------------------
void show_ok ( u_int mask )
//* Begin
{
//* Wait 200 msec
wait_desc.period = 200000 ;
at91_wait_open ( &wait_desc );
//* Switch off the corresponding led
at91_pio_write (&PIO_DESC, mask, LED_OFF );
//* Wait 200 msec
at91_wait_open ( &wait_desc );
}
//* End
//*----------------------------------------------------------------------------
//* Function Name : show_error
//* Object :
//* Input Parameters : None
//* Output Parameters : None
//* Functions called :
//*----------------------------------------------------------------------------
void show_error ( void )
//* Begin
{
//* Wait 200 msec
wait_desc.period = 1000000 ;
at91_wait_open ( &wait_desc ) ;
//* Light up all the leds
at91_pio_write (&PIO_DESC, LED_MASK, LED_ON ) ;
//* Wait 1 sec
at91_wait_open ( &wait_desc );
//* Switch off all the leds
at91_pio_write (&PIO_DESC, LED_MASK, LED_OFF ) ;
//* Wait 200 msec
wait_desc.period = 200000 ;
at91_wait_open ( &wait_desc );
//* Light up all the leds
at91_pio_write (&PIO_DESC, LED_MASK, LED_ON ) ;
//* Wait 1 sec
wait_desc.period = 1000000 ;
at91_wait_open ( &wait_desc );
//* Switch off all the leds
at91_pio_write (&PIO_DESC, LED_MASK, LED_OFF ) ;
}
//* End
//*----------------------------------------------------------------------------
//* Function Name : BootFts
//* Object : expect an user action, and start the test
//* Input Parameters : None
//* Output Parameters : None
//* Functions called :
//*----------------------------------------------------------------------------
void BootFts (void )
//* Begin
{
//* Light off all the LEDs
at91_pio_write (&PIO_DESC, LED_MASK, LED_OFF ) ;
//* Repeat for ever
for (;;)
{
//*------------------
//* Light on the LED1
//*------------------
at91_pio_write (&PIO_DESC, LED1, LED_ON ) ;
//* Internal RAM Test
if ( internal_ram_test () == TRUE )
show_ok (LED1) ;
else
show_error () ;
//*------------------
//* Light on the LED2
//*------------------
at91_pio_write (&PIO_DESC, LED2, LED_ON ) ;
//* External RAM Test
if ( external_ram_test () == TRUE )
show_ok (LED2) ;
else
show_error () ;
//*------------------
//* Light on the LED3
//*------------------
at91_pio_write (&PIO_DESC, LED3, LED_ON ) ;
//* Flash AT49BV1614 Test
if ( ext_flash_test () == TRUE )
show_ok (LED3) ;
else
show_error () ;
//*------------------
//* Light on the LED4
//*------------------
at91_pio_write (&PIO_DESC, LED4, LED_ON ) ;
//* Serial EEPROM Test
if ( serial_eeprom_test () == TRUE )
show_ok (LED4) ;
else
show_error () ;
//*------------------
//* Light on the LED5
//*------------------
at91_pio_write (&PIO_DESC, LED5, LED_ON ) ;
//* Usart Test
if ( usart_test() == TRUE )
show_ok (LED5) ;
else
show_error () ;
}//* EndRepeat
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -