@ -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"
@ -81,12 +81,9 @@ static volatile boolean tx_dma_done = FALSE;
# endif
# 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引脚控制片选信号 */
@ -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 ;
@ -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 ) ;
}
@ -554,7 +566,6 @@ int FSpimPressureTest(void)
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__ ) ;
@ -600,10 +622,10 @@ int FSpimPressureTest(void)
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 ) ;
}
@ -654,8 +706,6 @@ int FSpimPressureTest(void)
}
# 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 ;
}