@ -32,7 +32,7 @@
# include "sdkconfig.h"
# ifndef SDK_CONFIG_H__
# warning "Please include sdkconfig.h"
# warning "Please include sdkconfig.h"
# endif
# include "fio_mux.h"
@ -41,7 +41,7 @@
# include "fgeneric_timer.h"
# define RX_TX_LENGTH_MAX (1024 * 512) /*512KB*/
# define SYS_TICKRATE_HZ 100
# define SYS_TICKRATE_HZ 100
# ifdef CONFIG_ENABLE_FDDMA
# include "fparameters_comm.h"
@ -81,12 +81,9 @@ static volatile boolean tx_dma_done = FALSE;
# endif
# define EN_TEST TRUE
# define EN_TEST TRUE
# define FSPIM_DELAY_MS 50000 /*timer Delay in milli-seconds */
# define FSPIM_DELAY_MS 100000 /*timer Delay in milli-seconds */
enum
{
@ -115,8 +112,6 @@ static boolean rx_done = FALSE;
static u8 tx_buff [ RX_TX_LENGTH_MAX ] = { 0 } ;
static u8 rx_buff [ RX_TX_LENGTH_MAX ] = { 0 } ;
# if defined(CONFIG_D2000_TEST_BOARD) || defined(CONFIG_FT2004_DSK_BOARD)
# include "fgpio.h"
/* D2000/FT2000-4 使用GPIO引脚控制片选信号 */
@ -179,10 +174,10 @@ static int compare_tx_rx(u32 trans_size)
}
static void SetupSystick ( void )
{
{
GenericTimerStop ( GENERIC_TIMER_ID0 ) ;
GenericTimerSetTimerValue ( GENERIC_TIMER_ID0 , GenericTimerFrequecy ( ) / SYS_TICKRATE_HZ ) ;
GenericTimerStart ( GENERIC_TIMER_ID0 ) ;
GenericTimerSetTimerValue ( GENERIC_TIMER_ID0 , GenericTimerFrequecy ( ) / SYS_TICKRATE_HZ ) ;
GenericTimerStart ( GENERIC_TIMER_ID0 ) ;
}
static inline u64 FSpimGetTick ( void )
@ -197,7 +192,7 @@ static inline u32 FSpimTickCastSeconds(u64 tick)
static inline u32 FSpimTickCastMilliSec ( u64 tick )
{
return ( u32 ) ( tick % ( u64 ) GenericTimerFrequecy ( ) / ( ( ( u64 ) GenericTimerFrequecy ( ) * 1 + 999 ) / 1000 ) ) ;
return ( u32 ) ( tick % ( u64 ) GenericTimerFrequecy ( ) / ( ( ( u64 ) GenericTimerFrequecy ( ) * 1 + 999 ) / 1000 ) ) ;
}
static int FSpimClearConfig ( FSpim * spim_p )
@ -217,6 +212,25 @@ static int FSpimClearConfig(FSpim *spim_p)
return FSPIM_OPS_OK ;
}
static int FSpimIntrWaitRxDone ( int timeout )
{
while ( TRUE ! = rx_done )
{
fsleep_microsec ( 2 ) ;
if ( 0 > = - - timeout )
{
break ;
}
}
if ( 0 > = timeout )
{
FSPIM_ERROR ( " Wait for rx timeout " ) ;
return FSPIM_OPS_TRANS_TIMEOUT ;
}
return FSPIM_OPS_OK ;
}
static void FSpimSendRxDoneEvent ( void * instance_p , void * param )
{
@ -464,7 +478,7 @@ static FError FSpimSetupConfig(FSpimTransWay trans_way)
spim_config . cpha = FSPIM_CPHA_2_EDGE ;
spim_config . cpol = FSPIM_CPOL_LOW ;
spim_config . n_bytes = FSPIM_1_BYTE ;
spim_config . freq_hz = 25000000 ;
spim_config . sclk_hz = FSPI_DEFAULT_SCLK ;
spim_config . trans_way = trans_way ;
ret = FSpimCfgInitialize ( spim_p , & spim_config ) ;
if ( FSPIM_SUCCESS ! = ret )
@ -493,18 +507,16 @@ static void printProgressBar(int progress, int total)
fflush ( stdout ) ;
}
int FSpimPressureTest ( void )
{
FError ret = 0 ;
FSpim * spim_instance = & spim ;
u32 trans_size = RX_TX_LENGTH_MAX ; ;
u32 trans_size = RX_TX_LENGTH_MAX ;
u32 total_times = 50 ;
int current_times = 0 ;
int poll_success_flag = 0 ;
int intr_success_flag = 0 ;
int ddma_success_flag = 1 ;
@ -517,7 +529,7 @@ int FSpimPressureTest(void)
/* POLL 模式下的持续压力测试,总共执行total_times次 */
FSpimSetupConfig ( TRANS_WAY_POLL ) ;
SetupSystick ( ) ;
printf ( " Spim pressure test start (poll). \r \n " ) ;
@ -533,7 +545,7 @@ int FSpimPressureTest(void)
total_ticks_poll + = FSpimGetTick ( ) - start_ticks ;
ret + = compare_tx_rx ( trans_size ) ;
current_times + + ;
if ( current_times % 10 = = 0 )
if ( current_times % 10 = = 0 )
{
printProgressBar ( current_times , total_times ) ;
}
@ -548,13 +560,12 @@ int FSpimPressureTest(void)
{
poll_success_flag + + ;
printf ( " Poll mode: spend time: %d.%03ds for transfering %d times. every time transfer %d bytes. \r \n " ,
FSpimTickCastSeconds ( total_ticks_poll ) ,
FSpimTickCastMilliSec ( total_ticks_poll ) ,
total_times ,
trans_size ) ;
FSpimTickCastSeconds ( total_ticks_poll ) ,
FSpimTickCastMilliSec ( total_ticks_poll ) ,
total_times ,
trans_size ) ;
}
/* 中断模式下的持续压力测试,总共执行total_times次 */
current_times = 0 ;
@ -562,7 +573,6 @@ int FSpimPressureTest(void)
FSpimSetupConfig ( TRANS_WAY_INTERRUPT ) ;
printf ( " Spim pressure test start (interrupt). \r \n " ) ;
FSpimCsOnOff ( TRUE ) ;
@ -570,19 +580,31 @@ int FSpimPressureTest(void)
while ( current_times < total_times )
{
FSpimSetupInterrupt ( spim_instance ) ;
InitRxTxBuff ( trans_size ) ;
start_ticks = FSpimGetTick ( ) ;
ret + = FSpimTransferByInterrupt ( spim_instance , tx_buff , rx_buff , trans_size ) ;
while ( FALSE = = rx_done ) ;
if ( FSPIM_OPS_OK ! = FSpimIntrWaitRxDone ( FSPIM_DELAY_MS ) )
{
FSPIM_DEBUG ( " Wait for rx timeout !!! " ) ;
ret = FSPIM_OPS_TRANS_TIMEOUT ;
goto exit ;
}
total_ticks_intr + = FSpimGetTick ( ) - start_ticks ;
ret + = compare_tx_rx ( trans_size ) ;
current_times + + ;
if ( current_times % 10 = = 0 )
if ( current_times % 10 = = 0 )
{
printProgressBar ( current_times , total_times ) ;
}
}
exit :
if ( ret ! = FT_SUCCESS )
{
printf ( " %s@%d: Spim (interrupt mode) pressure test [failure]. \r \n " , __func__ , __LINE__ ) ;
@ -590,20 +612,20 @@ int FSpimPressureTest(void)
else
{
intr_success_flag + + ;
printf ( " Interrupt mode: spend time: %d.%03ds for transfering %d times. every time transfer %d bytes. \r \n " ,
FSpimTickCastSeconds ( total_ticks_intr ) ,
FSpimTickCastMilliSec ( total_ticks_intr ) ,
total_times ,
trans_size ) ;
FSpimTickCastSeconds ( total_ticks_intr ) ,
FSpimTickCastMilliSec ( total_ticks_intr ) ,
total_times ,
trans_size ) ;
}
FSpimCsOnOff ( FALSE ) ;
FSpimClearConfig ( spim_instance ) ;
# ifdef CONFIG_ENABLE_FDDMA
u64 total_ticks_ddma = 0 ;
ddma_success_flag = 0 ;
u32 timeout = 100000 ;
/* DDMA 模式下的持续压力测试,总共执行total_times次 */
current_times = 0 ;
ret = 0 ;
@ -623,12 +645,42 @@ int FSpimPressureTest(void)
ret + = FSpimTransferDMA ( spim_instance ) ;
FDdmaStart ( & ddma_instance ) ;
while ( ! tx_dma_done | | ! rx_dma_done ) ;
while ( FALSE = = tx_dma_done )
{
if ( - - timeout < = 0 )
{
break ;
}
fsleep_millisec ( 1 ) ;
}
if ( 0 > = timeout )
{
FSPIM_ERROR ( " Wait DDMA TX end timeout %d! " , timeout ) ;
}
timeout = 100000 ;
while ( FALSE = = rx_dma_done )
{
if ( - - timeout < = 0 )
{
break ;
}
fsleep_millisec ( 1 ) ;
}
if ( 0 > = timeout )
{
FSPIM_ERROR ( " Wait DDMA RX end timeout %d! " , timeout ) ;
}
total_ticks_ddma + = FSpimGetTick ( ) - start_ticks ;
ret + = compare_dma_tx_rx ( trans_size ) ;
current_times + + ;
if ( current_times % 10 = = 0 )
if ( current_times % 10 = = 0 )
{
printProgressBar ( current_times , total_times ) ;
}
@ -647,15 +699,13 @@ int FSpimPressureTest(void)
{
ddma_success_flag + + ;
printf ( " Ddma mode: spend time: %d.%03ds for transfering %d times. every time transfer %d bytes. \r \n " ,
FSpimTickCastSeconds ( total_ticks_ddma ) ,
FSpimTickCastMilliSec ( total_ticks_ddma ) ,
total_times ,
trans_size ) ;
FSpimTickCastSeconds ( total_ticks_ddma ) ,
FSpimTickCastMilliSec ( total_ticks_ddma ) ,
total_times ,
trans_size ) ;
}
# endif
if ( poll_success_flag & & intr_success_flag & & ddma_success_flag )
{
printf ( " %s@%d: Spim pressure test [success]. \r \n " , __func__ , __LINE__ ) ;
@ -665,5 +715,4 @@ int FSpimPressureTest(void)
printf ( " %s@%d: Spim pressure test [failure]. \r \n " , __func__ , __LINE__ ) ;
}
return FT_SUCCESS ;
}