host_ms_task.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 HOST_SYNC_MODE
00050 #  warning HOST_SYNC_MODE not defined as ENABLE or DISABLE, using DISABLE...
00051 #  define HOST_SYNC_MODE  DISABLE
00052 #endif
00053 
00054 #ifndef HOST_UPGRADE_MODE
00055 #  warning HOST_UPGRADE_MODE not defined as ENABLE or DISABLE, using DISABLE...
00056 #  define HOST_UPGRADE_MODE  DISABLE
00057 #endif
00058 
00059 // File system includes required for SYNC mode
00060 #if (HOST_SYNC_MODE==ENABLE)
00061    #include "modules/file_system/fat.h"
00062    #include "modules/file_system/fs_com.h"
00063    #include "modules/file_system/navigation.h"
00064    #include "modules/file_system/file.h"
00065    #include "modules/file_system/nav_utils.h"
00066 #endif
00067 
00068 #if (HOST_UPGRADE_MODE==ENABLE)
00069    #include "firm_upgrade.h"
00070 #endif
00071 
00072 #include "host_ms_task.h"
00073 #include "lib_mem/host_mem/host_mem.h"
00074 #include "modules/usb/host_chap9/usb_host_task.h"
00075 
00076 
00077 //_____ M A C R O S ________________________________________________________
00078 
00079 
00080 //_____ D E C L A R A T I O N S ____________________________________________
00081 
00083 volatile U8 host_cpt_sof;
00084 
00085 #if (HOST_SYNC_MODE==ENABLE)
00087    U8 code dir_usb_out_name[]=DIR_USB_OUT_NAME;
00089    U8 code dir_usb_in_name[]=DIR_USB_IN_NAME;
00091    U8 code dir_local_out_name[]=DIR_LOCAL_OUT_NAME;
00093    U8 code dir_local_in_name[]=DIR_LOCAL_IN_NAME;
00095    U8 sync_on_going=0;
00097    U8 ms_str_ram[MAX_FILE_LENGHT];
00098 #endif
00099 
00100 #if (HOST_UPGRADE_MODE==ENABLE)
00101    Bool b_new_msc_connected = FALSE;
00102 #endif
00103 
00106 void host_ms_task_init(void)
00107 {
00108    Leds_init();
00109 #if (HOST_SYNC_MODE==ENABLE)
00110    Joy_init();
00111 #endif
00112    host_mem_init();
00113 }
00114 
00115 
00118 void host_ms_task(void)
00119 {
00120    if( Is_host_ready() )   
00121    {
00122       // Here, Enumeration successfull, device is operationnal
00123       if(Is_new_device_connection_event())
00124       {
00125          // Update MS driver in case of
00126          if( host_mem_install() )
00127          {
00128 #if (HOST_UPGRADE_MODE==ENABLE)
00129             b_new_msc_connected = TRUE;
00130 #endif
00131             Led1_on();
00132          }
00133       }
00134 
00135 #if (HOST_SYNC_MODE==ENABLE)  // Sync operating mode(if available)
00136       if( 0 != host_mem_get_lun() )
00137       {
00138          if(Is_joy_right())   // Sync device to host stream
00139          {
00140             Led0_on();
00141             sync_on_going=1;
00142             copy_dir( (U8 code *)dir_usb_out_name, (U8 code *)dir_local_in_name, 1 );
00143             sync_on_going=0;
00144             Led3_off();
00145             Led0_off();
00146          }
00147          if(Is_joy_left())    // Sync host to device stream
00148          {
00149             Led0_on();
00150             sync_on_going=1;
00151             copy_dir( (U8 code *)dir_local_out_name, (U8 code *)dir_usb_in_name, 1 );
00152             sync_on_going=0;
00153             Led0_off();
00154             Led3_off();
00155          }
00156       }
00157 #endif
00158 
00159 #if (HOST_UPGRADE_MODE==ENABLE)
00160       if( b_new_msc_connected )
00161       {
00162          // A new MSC is connected then start upgrade routine
00163          b_new_msc_connected = FALSE;
00164          firm_upgrade_run();
00165       }
00166 #endif
00167    }
00168 
00169    // Device disconnection...
00170    if( Is_device_disconnection_event() )
00171    {
00172       // Update MS driver in case of
00173       host_mem_uninstall();
00174       Led1_off();
00175    }
00176 }
00177 
00178 
00182 void host_sof_action(void)
00183 {
00184    host_cpt_sof++;
00185    #if (HOST_SYNC_MODE==ENABLE)
00186    if(host_cpt_sof==0 &&sync_on_going) Led3_toggle();
00187    #endif
00188 }
00189 

Generated on Wed Sep 23 09:37:10 2009 for ATMEL by  doxygen 1.5.3