- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# host_ms_task.c

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00013
    00014 /* Copyright (c) 2007, 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  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
    00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00031  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00039  */
    00040
    00041 //_____  I N C L U D E S ___________________________________________________
    00042
    00043 #include "config.h"
    00044 #include "conf_usb.h"
    00045
    00046 #ifndef HOST_SYNC_MODE
    00047 #  warning HOST_SYNC_MODE not defined as ENABLE or DISABLE, using DISABLE...
    00048 #  define HOST_SYNC_MODE  DISABLE
    00049 #endif
    00050
    00051 #ifndef HOST_UPGRADE_MODE
    00052 #  warning HOST_UPGRADE_MODE not defined as ENABLE or DISABLE, using DISABLE...
    00053 #  define HOST_UPGRADE_MODE  DISABLE
    00054 #endif
    00055
    00056 // File system includes required for SYNC mode
    00057 #if (HOST_SYNC_MODE==ENABLE)
    00058    #include "modules/file_system/fat.h"
    00059    #include "modules/file_system/fs_com.h"
    00060    #include "modules/file_system/navigation.h"
    00061    #include "modules/file_system/file.h"
    00062    #include "modules/file_system/nav_utils.h"
    00063 #endif
    00064
    00065 #if (HOST_UPGRADE_MODE==ENABLE)
    00066    #include "firm_upgrade.h"
    00067 #endif
    00068
    00069 #include "host_ms_task.h"
    00070 #include "lib_mem/host_mem/host_mem.h"
    00071 #include "modules/usb/host_chap9/usb_host_task.h"
    00072
    00073
    00074 //_____ M A C R O S ________________________________________________________
    00075
    00076
    00077 //_____ D E C L A R A T I O N S ____________________________________________
    00078
    00080 volatile U8 host_cpt_sof;
    00081
    00082 #if (HOST_SYNC_MODE==ENABLE)
    00084    U8 code dir_usb_out_name[]=DIR_USB_OUT_NAME;
    00086    U8 code dir_usb_in_name[]=DIR_USB_IN_NAME;
    00088    U8 code dir_local_out_name[]=DIR_LOCAL_OUT_NAME;
    00090    U8 code dir_local_in_name[]=DIR_LOCAL_IN_NAME;
    00092    U8 sync_on_going=0;
    00094    U8 ms_str_ram[MAX_FILE_LENGHT];
    00095 #endif
    00096
    00097 #if (HOST_UPGRADE_MODE==ENABLE)
    00098    Bool b_new_msc_connected = FALSE;
    00099 #endif
    00100
    00103 void host_ms_task_init(void)
    00104 {
    00105    Leds_init();
    00106 #if (HOST_SYNC_MODE==ENABLE)
    00107    Joy_init();
    00108 #endif
    00109    host_mem_init();
    00110 }
    00111
    00112
    00115 void host_ms_task(void)
    00116 {
    00117    if( Is_host_ready() )
    00118    {
    00119       // Here, Enumeration successfull, device is operationnal
    00120       if(Is_new_device_connection_event())
    00121       {
    00122          // Update MS driver in case of
    00123 #if (HOST_UPGRADE_MODE==ENABLE)
    00124          if( host_mem_install() )
    00125             b_new_msc_connected = TRUE;
    00126 #else
    00127          host_mem_install();
    00128 #endif
    00129       }
    00130
    00131 #if (HOST_SYNC_MODE==ENABLE)  // Sync operating mode(if available)
    00132       if( 0 != host_mem_get_lun() )
    00133       {
    00134          if(Is_joy_right())   // Sync device to host stream
    00135          {
    00136             sync_on_going=1;
    00137             copy_dir( (U8 code *)dir_usb_out_name, (U8 code *)dir_local_in_name, 1 );
    00138             sync_on_going=0;
    00139             Led3_off();
    00140          }
    00141          if(Is_joy_left())    // Sync host to device stream
    00142          {
    00143             sync_on_going=1;
    00144             copy_dir( (U8 code *)dir_local_out_name, (U8 code *)dir_usb_in_name, 1 );
    00145             sync_on_going=0;
    00146             Led3_off();
    00147          }
    00148       }
    00149 #endif
    00150
    00151 #if (HOST_UPGRADE_MODE==ENABLE)
    00152       if( b_new_msc_connected )
    00153       {
    00154          // A new MSC is connected then start upgrade routine
    00155          b_new_msc_connected = FALSE;
    00156          firm_upgrade_run();
    00157       }
    00158 #endif
    00159
    00160    }
    00161
    00162    // Device disconnection...
    00163    if( Is_device_disconnection_event() )
    00164    {
    00165       // Update MS driver in case of
    00166       host_mem_uninstall();
    00167    }
    00168 }
    00169
    00170
    00174 void host_sof_action(void)
    00175 {
    00176    host_cpt_sof++;
    00177    #if (HOST_SYNC_MODE==ENABLE)
    00178    if(host_cpt_sof==0 &&sync_on_going) Led3_toggle();
    00179    #endif
    00180 }
    00181
    00182