usbsys.c File Reference


Detailed Description

AVR32 UC3 Control Panel USB system module.

This module is in charge of :
* defining the USB objects * starting the USB tasks.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file usbsys.c.

#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "conf_usb.h"
#include "usb_drv.h"
#include "usb_task.h"
#include "device_mass_storage_task.h"
#include "host_mass_storage_task.h"
#include "shell.h"

Go to the source code of this file.

Defines

#define MSG_BUS_POWERED   "Device is bus-powered"CRLF
#define MSG_COPY_CFG_TO_LOCAL   "Copying the /CFG directory from the USB key"CRLF
#define MSG_COPY_LOGS_TO_KEY   "Copying the log files to the USB key"CRLF
#define MSG_COPY_WEB_TO_LOCAL   "Copying the /WEB directory from the USB key"CRLF
#define MSG_DEVICE_FULL_SPEED   "Device is full-speed"CRLF
#define MSG_DEVICE_LOW_SPEED   "Device is low-speed"CRLF
#define MSG_KO   "KO"CRLF
#define MSG_MOVE_LOGS_TO_KEY   "Moving the log files to the USB key"CRLF
#define MSG_NO_DEVICE   "No supported device connected"CRLF
#define MSG_OK   "OK"CRLF
#define MSG_REMOTE_WAKEUP_KO   "Device does not support remote wake-up"CRLF
#define MSG_REMOTE_WAKEUP_OK   "Device supports remote wake-up"CRLF
#define MSG_SELF_POWERED   "Device is self-powered"CRLF
#define MSG_USB_SUSPENDED   "USB is suspended!"CRLF

Functions

Bool b_usbsys_start (void)
eExecStatus e_usbsys_cp_cfg_to_local (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 In host mode, copy the /CFG directory content of the USB MS key to the Control Panel /CFG directory. No parameters. Format: cp_cfg_to_local.
eExecStatus e_usbsys_cp_logs_to_key (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 In host mode, copy the /LOG directory to the USB MS key. No parameters. Format: cp_logs_to_ukey.
eExecStatus e_usbsys_cp_web_to_local (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 In host mode, copy the /WEB directory content of the USB MS key to the Control Panel /WEB directory. No parameters. Format: cp_web_to_local.
eExecStatus e_usbsys_lsusb (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 In host mode, display basic low-level information about the connected device. The device should be supported by the host (configured). No parameters. Format: lsusb.
eExecStatus e_usbsys_mv_logs_to_key (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 In host mode, move the /LOG directory content to the USB MS key. No parameters. Format: mv_logs_to_ukey.
static eExecStatus prv_e_usbsys_sync_cp_ukey (eModId xModId, signed short FsNavId, signed portCHAR **ppcStringReply, signed portCHAR *pcStringMsgAction, U8 sync_direction, const char *pcdir_name, Bool bDeleteSrc)
 Common synchronization function between the Control Panel and a USB key.
int sprintf (char *out, const char *format,...)


Define Documentation

#define MSG_BUS_POWERED   "Device is bus-powered"CRLF

Definition at line 81 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_COPY_CFG_TO_LOCAL   "Copying the /CFG directory from the USB key"CRLF

Definition at line 90 of file usbsys.c.

Referenced by e_usbsys_cp_cfg_to_local().

#define MSG_COPY_LOGS_TO_KEY   "Copying the log files to the USB key"CRLF

Definition at line 88 of file usbsys.c.

Referenced by e_usbsys_cp_logs_to_key().

#define MSG_COPY_WEB_TO_LOCAL   "Copying the /WEB directory from the USB key"CRLF

Definition at line 91 of file usbsys.c.

Referenced by e_usbsys_cp_web_to_local().

#define MSG_DEVICE_FULL_SPEED   "Device is full-speed"CRLF

Definition at line 85 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_DEVICE_LOW_SPEED   "Device is low-speed"CRLF

Definition at line 86 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_KO   "KO"CRLF

Definition at line 84 of file usbsys.c.

Referenced by prv_e_usbsys_sync_cp_ukey().

#define MSG_MOVE_LOGS_TO_KEY   "Moving the log files to the USB key"CRLF

Definition at line 89 of file usbsys.c.

Referenced by e_usbsys_mv_logs_to_key().

#define MSG_NO_DEVICE   "No supported device connected"CRLF

Detailled description of the module: TODO

Definition at line 77 of file usbsys.c.

Referenced by e_usbsys_lsusb(), and prv_e_usbsys_sync_cp_ukey().

#define MSG_OK   "OK"CRLF

Definition at line 83 of file usbsys.c.

Referenced by prv_e_usbsys_sync_cp_ukey().

#define MSG_REMOTE_WAKEUP_KO   "Device does not support remote wake-up"CRLF

Definition at line 79 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_REMOTE_WAKEUP_OK   "Device supports remote wake-up"CRLF

Definition at line 78 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_SELF_POWERED   "Device is self-powered"CRLF

Definition at line 80 of file usbsys.c.

Referenced by e_usbsys_lsusb().

#define MSG_USB_SUSPENDED   "USB is suspended!"CRLF

Definition at line 82 of file usbsys.c.

Referenced by e_usbsys_lsusb().


Function Documentation

Bool b_usbsys_start ( void   ) 

Start the USB modules.

Returns:
TRUE upon success, else FALSE.

Definition at line 112 of file usbsys.c.

References device_mass_storage_task_init(), and host_mass_storage_task_init().

Referenced by portTASK_FUNCTION().

00113 {
00114    // Create the usb_tsk_semphr and launch the usb_task() task.
00115    usb_task_init();
00116 #if USB_DEVICE_FEATURE == ENABLED
00117   // Init the device Mass Storage module and
00118   // create the device_mass_storage_task() task
00119   device_mass_storage_task_init();
00120 #endif
00121 #if USB_HOST_FEATURE == ENABLED
00122   // Init the host Mass Storage module and
00123   // create the host_mass_storage_task() task
00124   host_mass_storage_task_init();
00125 #endif
00126 
00127    return( TRUE );
00128 }

eExecStatus e_usbsys_cp_cfg_to_local ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

In host mode, copy the /CFG directory content of the USB MS key to the Control Panel /CFG directory. No parameters. Format: cp_cfg_to_local.

Note:
This function must be of the type pfShellCmd defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use.
ac Input. The argument counter. Ignored.
av Input. The argument vector. Ignored
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string may be performed here; the caller must thus free this string.
Returns:
the status of the command execution. If the status is SHELL_EXECSTATUS_KO, the caller MUST NOT FREE the response string. If the status is SHELL_EXECSTATUS_OK and the response string is not NULL, the caller MUST free the response string.

Definition at line 307 of file usbsys.c.

References DEVICE_TO_HOST, MSG_COPY_CFG_TO_LOCAL, and prv_e_usbsys_sync_cp_ukey().

Referenced by b_USBHostCopyCfg().

00310 {
00311    return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply, 
00312                                       (signed portCHAR *)MSG_COPY_CFG_TO_LOCAL,
00313                                       DEVICE_TO_HOST, "CFG/", FALSE ) );
00314 }

eExecStatus e_usbsys_cp_logs_to_key ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

In host mode, copy the /LOG directory to the USB MS key. No parameters. Format: cp_logs_to_ukey.

Note:
This function must be of the type pfShellCmd defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use.
ac Input. The argument counter. Ignored.
av Input. The argument vector. Ignored
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string may be performed here; the caller must thus free this string.
Returns:
the status of the command execution. If the status is SHELL_EXECSTATUS_KO, the caller MUST NOT FREE the response string. If the status is SHELL_EXECSTATUS_OK and the response string is not NULL, the caller MUST free the response string.

Definition at line 246 of file usbsys.c.

References HOST_TO_DEVICE, MSG_COPY_LOGS_TO_KEY, and prv_e_usbsys_sync_cp_ukey().

Referenced by b_USBHostCopyLogs().

00249 {
00250    return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply, 
00251                                       (signed portCHAR *)MSG_COPY_LOGS_TO_KEY,
00252                                       HOST_TO_DEVICE, "LOG/", FALSE ) );
00253 }

eExecStatus e_usbsys_cp_web_to_local ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

In host mode, copy the /WEB directory content of the USB MS key to the Control Panel /WEB directory. No parameters. Format: cp_web_to_local.

Note:
This function must be of the type pfShellCmd defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use.
ac Input. The argument counter. Ignored.
av Input. The argument vector. Ignored
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string may be performed here; the caller must thus free this string.
Returns:
the status of the command execution. If the status is SHELL_EXECSTATUS_KO, the caller MUST NOT FREE the response string. If the status is SHELL_EXECSTATUS_OK and the response string is not NULL, the caller MUST free the response string.

Definition at line 339 of file usbsys.c.

References DEVICE_TO_HOST, MSG_COPY_WEB_TO_LOCAL, and prv_e_usbsys_sync_cp_ukey().

Referenced by b_USBHostCopyWeb().

00342 {
00343    return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply, 
00344                                       (signed portCHAR *)MSG_COPY_WEB_TO_LOCAL,
00345                                       DEVICE_TO_HOST, "WEB/", FALSE ) );
00346 }

eExecStatus e_usbsys_lsusb ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

In host mode, display basic low-level information about the connected device. The device should be supported by the host (configured). No parameters. Format: lsusb.

In host mode, display basic low-level information about the connected device. No parameters. Format: lsusb.

Note:
This function must be of the type pfShellCmd defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Ignored.
ac Input. The argument counter. Ignored.
av Input. The argument vector. Ignored
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns:
the status of the command execution.

Definition at line 150 of file usbsys.c.

References CRLF, MSG_BUS_POWERED, MSG_DEVICE_FULL_SPEED, MSG_DEVICE_LOW_SPEED, MSG_NO_DEVICE, MSG_REMOTE_WAKEUP_KO, MSG_REMOTE_WAKEUP_OK, MSG_SELF_POWERED, MSG_USB_SUSPENDED, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, SHELL_MAX_MSGOUT_LEN, sprintf(), and v_shell_Print_String_To_Requester_Stream().

00153 {
00154 #if USB_HOST_FEATURE == ENABLED
00155    signed portCHAR *pcStringToPrint;
00156    U8 i, j;
00157 
00158 
00159    if( NULL != ppcStringReply )
00160       *ppcStringReply = NULL;
00161 
00162    if (!Is_host_ready() && !Is_host_suspended())
00163    {
00164       v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00165       return SHELL_EXECSTATUS_KO;
00166    }
00167 
00168    pcStringToPrint = (signed portCHAR *)pvPortMalloc( SHELL_MAX_MSGOUT_LEN ); // Alloc
00169    if( NULL == pcStringToPrint )
00170    {
00171       return( SHELL_EXECSTATUS_KO );
00172    }
00173 
00174    if (Is_host_suspended())
00175    {
00176       v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_USB_SUSPENDED CRLF );
00177    }
00178 
00179    sprintf( (char *)pcStringToPrint, "VID: 0x%.4X, PID: 0x%.4X\r\n"
00180             "Device MaxPower is %d mA\r\n"
00181             "%s"
00182             "%s",
00183             Get_VID(), Get_PID(),
00184             2 * Get_maxpower(),
00185             Is_device_self_powered() ? MSG_SELF_POWERED : MSG_BUS_POWERED,
00186             Is_usb_full_speed_mode() ? MSG_DEVICE_FULL_SPEED : MSG_DEVICE_LOW_SPEED );
00187    v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00188    sprintf( (char *)pcStringToPrint, "%s"
00189             "Supported interface(s): %u",
00190             Is_device_supports_remote_wakeup() ? MSG_REMOTE_WAKEUP_OK : MSG_REMOTE_WAKEUP_KO,
00191             Get_nb_supported_interface() );
00192    v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00193 
00194    for (i = 0; i < Get_nb_supported_interface(); i++)
00195    {
00196       sprintf( (char *)pcStringToPrint, "\r\nInterface nb: %u, AltS nb: %u, Class: 0x%.2X,"
00197                " SubClass: 0x%.2X, Protocol: 0x%.2X\r\n" "\tAssociated Ep Nbrs:",
00198                Get_interface_number(i), Get_altset_nb(i), Get_class(i),
00199                Get_subclass(i), Get_protocol(i) );
00200       v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00201 
00202       if (Get_nb_ep(i))
00203       {
00204          for (j = 0; j < Get_nb_ep(i); j++)
00205          {
00206             sprintf( (char *)pcStringToPrint, " %u", (U16)Get_ep_nbr(i, j) );
00207             v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00208          }
00209       }
00210       else
00211       {
00212          v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)"None" );
00213       }
00214    }
00215 
00216    vPortFree( pcStringToPrint );
00217 
00218    v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)CRLF );
00219 #else
00220    v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00221 #endif
00222    return( SHELL_EXECSTATUS_OK );
00223 }

eExecStatus e_usbsys_mv_logs_to_key ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

In host mode, move the /LOG directory content to the USB MS key. No parameters. Format: mv_logs_to_ukey.

Note:
This function must be of the type pfShellCmd defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use.
ac Input. The argument counter. Ignored.
av Input. The argument vector. Ignored
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string may be performed here; the caller must thus free this string.
Returns:
the status of the command execution. If the status is SHELL_EXECSTATUS_KO, the caller MUST NOT FREE the response string. If the status is SHELL_EXECSTATUS_OK and the response string is not NULL, the caller MUST free the response string.

Definition at line 276 of file usbsys.c.

References HOST_TO_DEVICE, MSG_MOVE_LOGS_TO_KEY, and prv_e_usbsys_sync_cp_ukey().

Referenced by b_USBHostMoveLogs().

00279 {
00280    return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply, 
00281                                       (signed portCHAR *)MSG_MOVE_LOGS_TO_KEY,
00282                                       HOST_TO_DEVICE, "LOG/", TRUE ) );
00283 }

static eExecStatus prv_e_usbsys_sync_cp_ukey ( eModId  xModId,
signed short  FsNavId,
signed portCHAR **  ppcStringReply,
signed portCHAR *  pcStringMsgAction,
U8  sync_direction,
const char *  pcdir_name,
Bool  bDeleteSrc 
) [static]

Common synchronization function between the Control Panel and a USB key.

Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use.
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string may be performed here; the caller must thus free this string.
pcStringMsgAction Input. The message to display when performing the action.
sync_direction Input. The direction of the synchonization(DEVICE_TO_HOST or HOST_TO_DEVICE)
pcdir_name Input. The name of the directory to synchronize.
bDeleteSrc Input. Flag to perform a copy(FALSE) or a move(TRUE).
Returns:
the status of the command execution. If the status is SHELL_EXECSTATUS_KO, the caller MUST NOT FREE the response string. If the status is SHELL_EXECSTATUS_OK and the response string is not NULL, the caller MUST free the response string.

Definition at line 372 of file usbsys.c.

References host_mass_storage_task_sync_drives(), MSG_KO, MSG_NO_DEVICE, MSG_OK, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, and v_shell_Print_String_To_Requester_Stream().

Referenced by e_usbsys_cp_cfg_to_local(), e_usbsys_cp_logs_to_key(), e_usbsys_cp_web_to_local(), and e_usbsys_mv_logs_to_key().

00377 {
00378    if( NULL != ppcStringReply )
00379       *ppcStringReply = NULL;
00380 
00381 #if USB_HOST_FEATURE == ENABLED
00382    if (!Is_host_ready() && !Is_host_suspended())
00383    {
00384       v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00385       return SHELL_EXECSTATUS_KO;
00386    }
00387 
00388    v_shell_Print_String_To_Requester_Stream( xModId, pcStringMsgAction );
00389 
00390    if( FALSE == host_mass_storage_task_sync_drives( FsNavId, sync_direction, pcdir_name, bDeleteSrc ) )
00391    {
00392       v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_KO );
00393    }
00394    else
00395    {
00396       v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_OK );
00397    }
00398 
00399 #endif
00400    return( SHELL_EXECSTATUS_OK );
00401 }

int sprintf ( char *  out,
const char *  format,
  ... 
)

Definition at line 293 of file printf-stdarg.c.

References print().

00294 {
00295         va_list args;
00296         
00297         va_start( args, format );
00298         return print( &out, format, args );
00299 }


Generated on Fri Feb 19 02:22:48 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5