prod_test.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of Atmel may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 //_____  I N C L U D E S ___________________________________________________
00045 
00046 #include "config.h"
00047 #include "conf_usb.h"
00048 
00049 #ifndef PROD_TEST
00050 #  define PROD_TEST  DISABLE
00051 #endif
00052 
00053 // File system includes required for SYNC mode
00054 #if (PROD_TEST==ENABLE)
00055 
00056 #  ifndef __ICCAVR__
00057 #  error PROD_TEST feature run only under IAR
00058 #  endif
00059 
00060 #  if TARGET_BOARD != USBKEY
00061 #  error PROD_TEST feature run only under USBKEY
00062 #  endif
00063 
00064 #include "modules/file_system/navigation.h"
00065 #include "modules/control_access/ctrl_access.h"
00066 #include "lib_mcu/flash/flash_lib.h"
00067 #include "lib_system\memory\memory.h"
00068 //#include "string.h"
00069 
00070 //_____ M A C R O S ________________________________________________________
00071  
00072 #define  TEST_FLAG_ADDR       0x500
00073    
00074 
00075 //_____ D E C L A R A T I O N S ____________________________________________
00076 
00077 // This array allocs a byte in flash (=code)
00078 // which will upgraded after test done
00079 code char g_prd_test At(TEST_FLAG_ADDR);  // By default = at first startup = 0x00
00080 
00081 static void launch_test( void );
00082 
00085 void prod_test( void )
00086 {
00087    if( 0x00 != g_prd_test )
00088       return; // Test already done
00089    
00090    launch_test();
00091    while(1);
00092 }
00093 
00094 static void launch_test( void )
00095 {
00096    volatile U16 u16_tmp;
00097    U8 flag, save_int;
00098    char name_first_file[] = "USBKEY.tmp";
00099    
00100    // Init interface board
00101    Joy_init();
00102    Leds_init();
00103    Hwb_button_init();
00104    
00105    // Check joystick
00106    while( !Is_btn_middle() );
00107    while( !Is_joy_right() );
00108    while( !Is_joy_left() );
00109    while( !Is_joy_up() );
00110    while( !Is_joy_down() );
00111    
00112    // Format DataFlash
00113    nav_reset();
00114    if( !nav_drive_set( 0 ) )
00115       return;  // Test Error
00116    
00117    // Write in four sectors
00118    memset( fs_g_sector , 0x55 , FS_CACHE_SIZE );
00119    if (CTRL_GOOD != ram_2_memory( 0 , 16+0 , fs_g_sector ))
00120       return;  // Test Error
00121    if (CTRL_GOOD != ram_2_memory( 0 , 16+2 , fs_g_sector ))
00122       return;  // Test Error
00123    memset( fs_g_sector , 0xAA , FS_CACHE_SIZE );
00124    if (CTRL_GOOD != ram_2_memory( 0 , 16+1 , fs_g_sector ))
00125       return;  // Test Error
00126    if (CTRL_GOOD != ram_2_memory( 0 , 16+3 , fs_g_sector ))
00127       return;  // Test Error
00128 
00129    // Check value in sectors
00130    if (CTRL_GOOD != memory_2_ram( 0 , 16+0 , fs_g_sector ))
00131       return;  // Test Error
00132    for( u16_tmp=0; u16_tmp<FS_CACHE_SIZE; u16_tmp++) {
00133       if( fs_g_sector[u16_tmp] != 0x55 ) 
00134          return;  // Test Error
00135    }
00136    if (CTRL_GOOD != memory_2_ram( 0 , 16+2 , fs_g_sector ))
00137       return;  // Test Error
00138    for( u16_tmp=0; u16_tmp<FS_CACHE_SIZE; u16_tmp++) {
00139       if( fs_g_sector[u16_tmp] != 0x55 ) 
00140          return;  // Test Error
00141    }
00142    if (CTRL_GOOD != memory_2_ram( 0 , 16+1 , fs_g_sector ))
00143       return;  // Test Error
00144    for( u16_tmp=0; u16_tmp<FS_CACHE_SIZE; u16_tmp++) {
00145       if( fs_g_sector[u16_tmp] != 0xAA ) 
00146          return;  // Test Error
00147    }
00148    if (CTRL_GOOD != memory_2_ram( 0 , 16+3 , fs_g_sector ))
00149       return;  // Test Error
00150    for( u16_tmp=0; u16_tmp<FS_CACHE_SIZE; u16_tmp++) {
00151       if( fs_g_sector[u16_tmp] != 0xAA ) 
00152          return;  // Test Error
00153    }
00154    
00155    if( !nav_drive_format( FS_FORMAT_DEFAULT ) )
00156       return;  // Test Error
00157    
00158    // Create a temporary file on DataFlash
00159    if( !nav_file_create(name_first_file ))
00160       return;  // Test Error
00161 
00162    // Update status test flag
00163    if( !flash_lib_check() )
00164       return;  // Test Error
00165    save_int=Get_interrupt_state();
00166    Disable_interrupt();
00167    flag = TRUE;
00168    flash_wr_block( &flag, TEST_FLAG_ADDR, 1 );
00169    // Restore interrupt state
00170    if(save_int) { Enable_interrupt(); }
00171 
00172    // Display Led OK
00173    while( 1 )
00174    {
00175       // Blink led green
00176       Led1_toggle();
00177       Led2_toggle();
00178       for( u16_tmp=0; u16_tmp<0xFFFF; u16_tmp++ );
00179    }
00180 }
00181 
00182 #endif // (PROD_TEST==ENABLE)
00183 

Generated on Wed Sep 23 09:49:34 2009 for ATMEL by  doxygen 1.5.3