void ushell_cmd_perform_extaccess( bool b_sens_write, Fs_file_segment seg ) { uint16_t u16_trans; uint32_t u32_tmp, u32_time; uint8_t u8_nb_trans_usb=0; fat_cache_flush(); fat_cache_reset(); u32_time = Get_sys_count(); u16_trans=0; while( seg.u16_size!=0 ) { if( 0 == (seg.u32_addr % SIZE_OF_EXT_BUFFER) ) { u8_nb_trans_usb = SIZE_OF_EXT_BUFFER; }else{ u8_nb_trans_usb = SIZE_OF_EXT_BUFFER - (seg.u32_addr % SIZE_OF_EXT_BUFFER); // to align access with usual memory mapping } if (u8_nb_trans_usb > seg.u16_size) u8_nb_trans_usb = seg.u16_size; if( b_sens_write ) { if( CTRL_GOOD != host_write_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) { printf( "Transfer error\r\n"); return; } }else{ if( CTRL_GOOD != host_read_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) { printf( "Transfer error\r\n"); return; } } seg.u16_size -= u8_nb_trans_usb; u16_trans += u8_nb_trans_usb; seg.u32_addr += u8_nb_trans_usb; if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) ) { // Stop access after 8s break; } } u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz); u32_tmp = ((uint32_t)u16_trans*(1000000/2))/u32_time; if( b_sens_write ) printf( "Transfer rate - WRITE %4luKB/s\r\n", u32_tmp); else printf( "Transfer rate - READ %4luKB/s\r\n", u32_tmp ); }
void ushell_cmd_perform_access( bool b_sens_write, Fs_file_segment seg ) { uint16_t u16_trans; uint32_t u32_tmp, u32_time; fat_cache_flush(); fat_cache_reset(); u32_time = Get_sys_count(); for( u16_trans=0; u16_trans<seg.u16_size; u16_trans++ ) { if( b_sens_write ) { if( CTRL_GOOD != ram_2_memory( seg.u8_lun , seg.u32_addr , fs_g_sector )) { printf( "Transfer error\r\n"); return; } }else{ if( CTRL_GOOD != memory_2_ram( seg.u8_lun , seg.u32_addr , fs_g_sector )) { printf( "Transfer error\r\n"); return; } } seg.u32_addr++; if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) ) { // Stop access after 8s break; } } u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz); u32_tmp = ((uint32_t)u16_trans*(1000000/2))/u32_time; if( b_sens_write ) printf( "Transfer rate - WRITE %4luKB/s\r\n", u32_tmp ); else printf( "Transfer rate - READ %4luKB/s\r\n", u32_tmp ); }
static void record_events(void) { uint16_t i=0; while(1) { while (!main_events) { sleepmgr_enter_sleep(); \ } if (i < NB_EVENTS) { // Register events irqflags_t flags = cpu_irq_save(); list_event[i].event = main_events; list_event[i++].timestamp = cpu_cy_2_us(Get_system_register(AVR32_COUNT),sysclk_get_cpu_hz()); main_events=0; cpu_irq_restore(flags); } } }
/** \brief This function returns the current timestamp counter value. * * The timestamp facility is implemented in terms of the XMEGA or UC3 * timer and clock function APIs. * * \return The current counter value (microseconds). */ uint32_t sensor_timestamp(void) { uint32_t tsc = 0; #if UC3 /** \todo * * Implement this interface in terms of XMEGA and UC3 timer/counter (TC) * facilities exposed through ASF drivers. A free running counter with * microsecond resolution is desirable. Ideally, the counter value * should be updated without using interrupts and attached to a clock *that * will be available while the MCU is in lower power modes. */ tsc = cpu_cy_2_us(Get_system_register(AVR32_COUNT), sysclk_get_cpu_hz()); #endif return tsc; }
void ushell_cmd_perform_transfer( Fs_file_segment seg_src, Fs_file_segment seg_dest ) { uint8_t id_trans_memtomem; Ctrl_status status_stream; uint16_t u16_i, u16_trans_max; uint32_t u32_tmp, u32_time; u16_trans_max = ( seg_src.u16_size < seg_dest.u16_size )? seg_src.u16_size : seg_dest.u16_size; for( u16_i=2; u16_i<=u16_trans_max; u16_i*=10 ) { u32_time = Get_sys_count(); id_trans_memtomem = stream_mem_to_mem( seg_src.u8_lun , seg_src.u32_addr , seg_dest.u8_lun , seg_dest.u32_addr , u16_i ); if( ID_STREAM_ERR == id_trans_memtomem ) { printf( "Transfer error\r\n"); return; } while(1) { status_stream = stream_state( id_trans_memtomem ); if( CTRL_BUSY == status_stream ) continue; if( CTRL_GOOD == status_stream ) break; if( CTRL_FAIL == status_stream ) { printf( "Transfer error\r\n"); return; } } u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz ); u32_tmp = ((uint32_t)u16_i*(1000000/2))/u32_time; printf( "Transfer rate %4luKB/s - stream size %4iKB\r\n", u32_tmp, u16_i/2 ); if( (8000000) < u32_time ) { // The test time must be inferior at 8s break; } } }
/*! \brief Main function. */ int main(void) { bool valid_block_found[NF_N_DEVICES]; U32 u32_nf_ids, i_dev, i_block; U8 maker_id, device_id, byte3; U32 i, time_s, time_e; U8 data; // start init sysclk_init(); // Enable clock for require module sysclk_enable_hsb_module(SYSCLK_EBI); sysclk_enable_pbb_module(SYSCLK_SMC_REGS); sysclk_enable_pbb_module(SYSCLK_HMATRIX); // Initialize the board. // The board-specific conf_board.h file contains the configuration of the board // initialization. board_init(); init_stdio(); #ifdef NF_ADDON // addon nandflash board for EVK1104 (not mounted by default) // Unselect NF on board gpio_set_gpio_pin(AVR32_PIN_PX53); gpio_set_gpio_pin(AVR32_PIN_PX52); #endif nf_init(sysclk_get_cpu_hz()); nf_unprotect(); printf("\x0C"); printf("Nand Flash example.\r\n===================\r\n\r\n"); // - Simple test of the NF communication through the SMC. // - Find all bad blocks. // - Find a valid block for the remaining tests. nf_reset_nands(NF_N_DEVICES); printf("\tDetecting Nand Flash device(s).\r\n"); for( i_dev=0 ; i_dev<NF_N_DEVICES ; i_dev++ ) { // Performs some init here... valid_block_found[i_dev] = false; // Test Maker and Device ids u32_nf_ids = nf_read_id( NF_READ_ID_CMD, i_dev ); maker_id = MSB0(u32_nf_ids); device_id = MSB1(u32_nf_ids); byte3 = MSB3(u32_nf_ids); printf("\t\tNF %ld: [Maker=0x%02x] [Device=0x%02x] [byte3=0x%02x]\r\n", i_dev, maker_id, device_id, byte3); if( maker_id==M_ID_MICRON ) { printf("\t\t Micron chip"); if( (device_id==0xDA) && (byte3==0x15) ) printf("- MT29F2G08AACWP device\r\n"); else if( (device_id==0xDA) && (byte3==0x95) ) printf("- MT29F2G08AADWP device\r\n"); else { printf("- *** Error: unexpected chip detected. Please check the board settings and hardware.\r\n"); return -1; } } else { printf("\t\t *** Error: unexpected chip detected. Please check the board settings and hardware.\r\n"); return -1; } } printf("\r\n\tTesting bad blocks.\r\n"); for( i_dev=0 ; i_dev<NF_N_DEVICES ; i_dev++ ) { printf("\t\tNF %ld:\r\n", i_dev); nf_select(i_dev); for( i_block=0 ; i_block<G_N_BLOCKS ; i_block++ ) { nf_open_page_read( nf_block_2_page(i_block), NF_SPARE_POS + G_OFST_BLK_STATUS ); if( (nf_rd_data()!=0xFF) ) { // The block is bad. printf("\t\t\tBlock %ld (0x%lx) is bad.\r\n", i_block, i_block); } else { if( !valid_block_found[i_dev] ) { valid_block_found[i_dev]= true; valid_block_addr[i_dev] = i_block; printf("\t\t\tFirst valid block is at address %ld (0x%lx).\r\n", i_block, i_block); } } } } for( i_dev=0 ; i_dev<NF_N_DEVICES ; i_dev++ ) if( !valid_block_found[i_dev] ) { printf("Error %d\r\n", __LINE__); return 0; } // - Ensure good NF behaviour through simple commands. // Erase, Program, Read // - Measures NF timings. printf("\r\n\tMeasuring NF timings.\r\n"); for( i_dev=0 ; i_dev<NF_N_DEVICES ; i_dev++ ) { printf("\t\tNF %ld:\r\n", i_dev); nf_select(i_dev); nf_erase_block( nf_block_2_page(valid_block_addr[0]), false); time_s = Get_sys_count(); nf_wait_busy(); time_e = Get_sys_count(); // Verify that the block is erased. nf_open_page_read( nf_block_2_page(valid_block_addr[0]), 0); for( i= 0; i<2048 ; i++ ) { data = nf_rd_data(); if( data!=0xFF ) { printf("\tError: offset %d is not erased (read %d).\r\n", (U8)i, data); return 0; } } printf("\t\t\tTime to erase a page:%ld cy (%ld us)\r\n", time_e-time_s, cpu_cy_2_us(time_e-time_s, sysclk_get_cpu_hz())); nf_open_page_write( nf_block_2_page(valid_block_addr[0]), 0); for( i=0 ; i<2048 ; i++ ) nf_wr_data(i%256); nf_wr_cmd(NF_PAGE_PROGRAM_CMD); time_s = Get_sys_count(); nf_wait_busy(); time_e = Get_sys_count(); printf("\t\t\tTime to program a page:%ld cy (%ld us)\r\n", time_e-time_s, cpu_cy_2_us(time_e-time_s, sysclk_get_cpu_hz())); time_s = Get_sys_count(); nf_open_page_read( nf_block_2_page(valid_block_addr[0]), 0); time_e = Get_sys_count(); printf("\t\t\tTime to access to a page:%ld cy (%ld us)\r\n", time_e-time_s, cpu_cy_2_us(time_e-time_s, sysclk_get_cpu_hz())); for( i= 0; i<2048 ; i++ ) { data = nf_rd_data(); if( data!= i%256) { printf("\tError: expect %d, read %d\r\n", (U8)i, data); return 0; } } } printf("Example DONE\r\n"); return 0; }