示例#1
0
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 );
}
示例#2
0
/*! \brief Release a system mutex.
 *
 *  \param xSemaphore   A handle to the semaphore being released.
 *
 *  \return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
 */
portBASE_TYPE x_supervisor_SemaphoreGive( xSemaphoreHandle xSemaphore )
{
#ifdef USB_ENABLE
#if USB_DEVICE_FEATURE == true
   if( ( 0 != u8IsMaintenanceRequired ) && ( false == bOutOfMaintenance ) )
   {
      // If we have to enter in the maintenance mode, do not release the mutex.
      // => this mutex is now the property of the supervisor.
      u8IsMaintenanceRequired++;

      // If all mutexes have been acquired, switch to maintenance mode.
      if( ( SUPERVISOR_MAINTENANCE_NBMUTEX_TOTAKE +1 ) == u8IsMaintenanceRequired )
      {
         fat_cache_flush(); // Flush the FAT cache.
         nav_reset();       // Reset all file system navigators. We will mount
                            // the com1shell default drive when we'll leave the
                            // maintenance mode.
         // Switch to maintenance mode.
         xSemaphoreGive( xUSBMutex );

         // If the USB clock is frozen, unfreeze it so that we can write in the
         // USB registers. The USB clock is frozen if a "Device Suspend" event
         // occurred (no more USB activity detected) (cf. usb_general_interrupt()).
         if(true == Is_usb_clock_frozen())
         {
           Usb_unfreeze_clock();
         }
         // If it is not already detached, physically detach the USB device.
         if(false == Is_usb_detached())
         {
           Usb_detach();
         }
         vTaskDelay(500); // Wait 500ms
         Usb_attach();     // Reconnect the device.

         bIsInMaintenance = true;
         u8IsMaintenanceRequired = 0;
         TRACE_COM2( "Entering maintenance mode");
#ifdef MMILCD_ENABLE
         vMMI_SetUserMenuMode( eUserMenuWaitHost, pdTRUE );
#endif
      }
      return( pdTRUE );
   }
   else
#endif
#endif
      return( xSemaphoreGive( xSemaphore ) );
}
示例#3
0
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 );
}
示例#4
0
/*!
 *  \brief The switch-to-maintenance-mode command: initiate the process to \n
 *         switch to maintenance mode.
 *         Format: maintain
 *
 *  \note  This function must be of the type pfShellCmd defined by the shell module.
 *
 *  \param xModId         Input. The module that is calling this function.
 *  \param FsNavId        Ignored.
 *  \param ac             Ignored.
 *  \param av             Ignored.
 *  \param 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.
 *
 *  \return the status of the command execution.
 */
eExecStatus e_supervisor_switch_to_maintenance_mode( eModId xModId,
                              signed short FsNavId,
                              int ac, signed portCHAR *av[],
                              signed portCHAR **ppcStringReply )
{
   if( NULL != ppcStringReply )
      *ppcStringReply = NULL;

#ifdef USB_ENABLE
#if USB_DEVICE_FEATURE == true
   if( ( false == bIsInMaintenance )
       && ( 0 == u8IsMaintenanceRequired ) )
   {   // We're not in maintenance mode.
      // Initiate the process of switching to maintenance mode.
      if( 0 == u8IsMaintenanceRequired )   u8IsMaintenanceRequired++;

      // Take all maintenance mutex except the USB mutex.
      if( true == x_supervisor_SemaphoreTake( xLOGMutex, 0 ) )       u8IsMaintenanceRequired++;
#if NW_INTEGRATED_IN_CONTROL_PANEL
      if( true == x_supervisor_SemaphoreTake( xWEBMutex, 0 ) )       u8IsMaintenanceRequired++;
#endif
      if( true == x_supervisor_SemaphoreTake( xSHELLFSMutex, 0 ) )   u8IsMaintenanceRequired++;
      if( true == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) )       u8IsMaintenanceRequired++;

      // If all mutexes have been acquired, switch to maintenance mode.
      if( ( SUPERVISOR_MAINTENANCE_NBMUTEX_TOTAKE +1 ) == u8IsMaintenanceRequired )
      {
         fat_cache_flush(); // flush the FAT cache.
         nav_reset();       // Reset all file system navigators. We will mount
                            // the com1shell default drive when we'll leave the
                            // maintenance mode.
         // Switch to maintenance mode.
         xSemaphoreGive( xUSBMutex );

         // If the USB clock is frozen, unfreeze it so that we can write in the
         // USB registers.
         if(true == Is_usb_clock_frozen())
         {
           Usb_unfreeze_clock();
         }
         // If it is not akready detached, physically detach the USB device.
         if(false == Is_usb_detached())
         {
           Usb_detach();
         }
         vTaskDelay(500); // Wait 500ms
         Usb_attach();     // Reconnect the device.

         bIsInMaintenance = true;
         u8IsMaintenanceRequired = 0;
         TRACE_COM2( "Entering maintenance mode");
#ifdef MMILCD_ENABLE
         vMMI_SetUserMenuMode( eUserMenuWaitHost, pdTRUE );
#endif
      }
      // ELSE: we'll switch to maintenance mode in x_supervisor_SemaphoreGive()
      // (when the mutex(es) that we couldn't get will be released).
   }
   else
   {
      NAKED_TRACE_COM2( "Won't go to maintenance mode:"CRLF"bIsInMaintenance=%d u8CurrentUsbRole=%d u8IsMaintenanceRequired=%d", bIsInMaintenance, u8CurrentUsbRole, u8IsMaintenanceRequired );
   }
#endif
#endif

   return( SHELL_EXECSTATUS_OK );
}
void IBN_FileAccess (u8 nParamsGet_u8,u8 CMD_u8,u32 Param_u32)
{
	s32 FileID_s32;
	s32 Ret_s32;

//	testtt[1000] = 4;

	if (0 == nParamsGet_u8)
	{
		CI_LocalPrintf ("File access\r\n");
		CI_LocalPrintf (" 0 = Set lun 0\r\n");
		CI_LocalPrintf (" 1 = Mount\r\n");
    CI_LocalPrintf (" 2 = Show free space\r\n");
    CI_LocalPrintf ("11 = Set BUSY Lun 0\r\n");
    CI_LocalPrintf ("12 = Update contend lun X\r\n");
    CI_LocalPrintf ("16 = Copy test.txt to test1.txt\n\r");
    CI_LocalPrintf ("17 = Format LUN X\n\r");
		return;
	}

	switch (CMD_u8)
	{
   	   case 0 :
			fs_g_nav.u8_lun = 0;   // On chip RAM
			break;
#if LUN_2 == ENABLE
   	   case 1 :
			if (2 != nParamsGet_u8)
			{
				CI_LocalPrintf ("USAGE: fa 1 [lun]\r\n");
				break;
			}
			b_fsaccess_init ();

			fs_g_nav.u8_lun = Param_u32;   // On chip RAM

			virtual_test_unit_ready() ;

			if (TRUE == fat_mount ())
			{
				CI_LocalPrintf ("Mount LUN %d OK\r\n",Param_u32);
			}
			else
			{
				CI_LocalPrintf ("Mount LUN %d FAIL - %d - %s\r\n",Param_u32,fs_g_status, IBN_FileSystemErrorText(fs_g_status));
			}
//			nav_partition_mount ();
			break;
#endif
   	   case 2 :
			CI_LocalPrintf ("Free mem = %d sectors\r\n",fat_getfreespace());
   		    break;
   	   case 3 :

   		    FileID_s32 = open ("test.txt",O_CREAT|O_RDWR);
			CI_LocalPrintf ("Open  = %d - %d - %s\r\n",FileID_s32,fs_g_status, IBN_FileSystemErrorText(fs_g_status));

			Ret_s32 = write (FileID_s32,"Test\n",6);
			CI_LocalPrintf ("Write  = %d \r\n",Ret_s32);
/*
			if (TRUE == fat_cache_flush ())
			{
				CI_LocalPrintf ("fat_cache_flush OK\r\n");
			}
			else
			{
				CI_LocalPrintf ("fat_cache_flush FAIL - %d - %s\r\n",fs_g_status, IBN_FileSystemErrorText(fs_g_status));
			}
*/
			Ret_s32 = close (FileID_s32);
			CI_LocalPrintf ("Close  = %d \r\n",Ret_s32);

#if LUN_2 == ENABLE
			virtual_unit_state_e = CTRL_BUSY;    // only for ram disk
#endif
			sd_mmc_mci_unit_state_e = CTRL_BUSY;
			vTaskDelay (500);
#if LUN_2 == ENABLE
			virtual_unit_state_e = CTRL_GOOD;
#endif
      sd_mmc_mci_unit_state_e = CTRL_GOOD;

   		    break;
   	   case 4 :
			if (2 != nParamsGet_u8)
			{
				CI_LocalPrintf ("USAGE: fa 6 [lun]\r\n");
				break;
			}

   		    FAI_Write (Param_u32);
			break;

   	   case 5 :
			FAI_ShowDirContent ();
   		    break;
   	   case 6:
			if (2 != nParamsGet_u8)
			{
				CI_LocalPrintf ("USAGE: fa 6 [lun]\r\n");
				break;
			}
   		   FAI_mount(Param_u32);
		   break;
   	   case 7 :
   		   FAI_free_space(Param_u32);
   		   break;
   	   case 8 :
   		   FAI_nb_drive();
   		   break;
   	   case 9 :
   		   FAI_Dir (0);
   		   break;
   	   case 10 :
		   if (TRUE == nav_drive_set (Param_u32))
		   {
			   CI_LocalPrintf ("nav_drive_set OK\r\n");
		   }
		   else
		   {
			   CI_LocalPrintf ("nav_drive_set FAIL - %d - %s\r\n",fs_g_status, IBN_FileSystemErrorText(fs_g_status));
		   }
   		   break;
   	   case 11 :
#if LUN_2 == ENABLE
         CI_LocalPrintf ("Set LUN %d CTRL_BUSY\n\r",Param_u32);
         //virtual_unit_state_e = CTRL_BUSY;
         set_virtual_unit_busy ();
#endif
         break;
   	   case 12 :
         CI_LocalPrintf ("Update LUN %d\n\r",Param_u32);
   	    FAI_UpdateContend (Param_u32);;
   	    break;
   	   case 13 :
         CI_LocalPrintf ("fat_cache_flush\n\r");
   	     fat_cache_flush ();
         break;
   	   case 14 :
         CI_LocalPrintf ("fat_check_device\n\r");
   	     fat_check_device ();
   	     break;
       case 15 :
         CI_LocalPrintf ("fat_check_device\n\r");
        fat_read_dir ();
        break;
       case 16 :
         CI_LocalPrintf ("Copy test.txt to test1.txt\n\r");
         {
           u8 F1[10];
           u8 F2[10];

           strcpy ((char*)F1,"test.txt");
           strcpy ((char*)F2,"test1.txt");
           FAI_CopyFile (F1,F2);
         }
        break;
       case 17 :
         CI_LocalPrintf ("Format LUN %d\n\r",Param_u32);
         nav_drive_set(Param_u32);
         if( !nav_drive_format(FS_FORMAT_FAT) )
         {
           CI_LocalPrintf ("Format LUN %d - ERROR\n\r",Param_u32);
         }
         break;

	}
}