⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ms_rbc.c

📁 ATMEL公司的demo程序,USB驱动程序,与识别片上flash,并进行枚举和操作.
💻 C
📖 第 1 页 / 共 2 页
字号:
//  ----------------------------------------------------------------------------
//          ATMEL Microcontroller Software Support  -  ROUSSET  -
//  ----------------------------------------------------------------------------
//  DISCLAIMER:  CONDITIONS AS PER SIGNED LIMITED LICENSE AGREEMENT (AT91
//  SOFTWARE AND USER DOCUMENTATION)
//  ALL SOFTWARE IS PROVIDED AS IS, WITH ALL FAULTS, AND WITH NO WARRANTY
//  WHATSOEVER.  ATMEL EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED,
//  OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.
//  ----------------------------------------------------------------------------
// File Name           : ms_rbc.c
// Object              : Reduced Block commands
//                       Ref: rbc-r10a.pdf, NCITS-330 T10/1240-D,
//                       revision 10a, August 18,1999
// Creation            : JCB 15/apr/2005
// Modif               :
// ----------------------------------------------------------------------------
#include "po_types.h"
#include "trace.h"
#include "bfsa_flash.h"
#include "fw_usb.h"
#include "po_kernel.h"
#include "ms_device.h"
#include "ms_rbc.h"

#define VALUE_32(p1,p2,p3,p4) ((p1)|(p2<<8)|(p3<<16)|(p4<<24))


/*****************************************************************
*
* ROUTINE : rbc_inquiry
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc inquiry command
*
* Input Parameters  : Structure defining the inquiry command
*
* Output Parameters : status of the operation.
*
*****************************************************************/
USBMS_RETURN rbc_inquiry(USBMS_INQUIRY *inquiry)
{
  USBMS_RETURN  _status = USBMS_OK;
  USHORT        _size;

  /* define in ms_plugInit */
  if( (inquiry->enable_vpd==0) && (inquiry->page_code==0) )
  {
    usbms_context.usb_lun[usbms_context.current_lun].cur_request.current_block    = 0;
    usbms_context.usb_lun[usbms_context.current_lun].cur_request.buffer_size      = 0;
    usbms_context.usb_lun[usbms_context.current_lun].cur_request.command_size     = 0;
    usbms_context.usb_lun[usbms_context.current_lun].cur_request.transferred_size = 0;
    usbms_context.usb_lun[usbms_context.current_lun].fail_reason  = GOOD_STATUS;

    /* standard inquiry data are required  */
    _size = (inquiry->length_0)+((inquiry->length_1)<<8);
    if( _size == usb_send((char*)&usbms_context.inquiry_data, _size) )
    {
      _status = USBMS_OK;
    }
    else
    {
      _status = USBMS_ERROR;
    }
  }
  else
  {
    _status = USBMS_ERROR;
  }
  return _status;
}


/*****************************************************************
*
* ROUTINE : rbc_mode_select
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc MODE_SELECT command
*
* Input Parameters  : Structure defining the MODE_SELECT command
*
* Output Parameters : status of the operation
*
*****************************************************************/
USBMS_RETURN rbc_mode_select(void)
{
  return USBMS_OK;
}


/*****************************************************************
*
* ROUTINE : rbc_mode_sense
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc MODE_SENSE command
*
* Input Parameters  : Structure defining the MODE_SENSE command
*
* Output Parameters : status of the operation
*
*****************************************************************/
USBMS_RETURN rbc_mode_sense(USBMS_MODE_SENSE *mode_sense)
{
  /* Fill the structure */
  if (mode_sense->allocation_length < sizeof(MODE_SENSE_PARAMETER))
  {
    usbms_context.mode_parameter_sense.mode_parameter_head.mode_data_length = (UCHAR)(mode_sense->allocation_length-sizeof(usbms_context.mode_parameter_sense.mode_parameter_head.mode_data_length));
  }
  else
  {
    usbms_context.mode_parameter_sense.mode_parameter_head.mode_data_length = (UCHAR)(sizeof(MODE_SENSE_PARAMETER)-sizeof(usbms_context.mode_parameter_sense.mode_parameter_head.mode_data_length));
  }

  usbms_context.mode_parameter_sense.mode_parameter_head.medium_type = 0;
  usbms_context.mode_parameter_sense.mode_parameter_head.device_specific_parameter=0;
  usbms_context.mode_parameter_sense.mode_parameter_head.block_descriptor_length=0;

  if( (mode_sense->page_code == 0x06)   /* Reserved */
    ||(mode_sense->page_code == 0x3F) ) /* Return all pages */
  {
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.pageCode       = 0x06;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.reserved1      = 0x01;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.pageLength     = 0x0b;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.writeCacheDisable = 0x01; /* entire command is treated */

    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.logicalBlockSize[0] = (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].BlockSize);
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.logicalBlockSize[1] = (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].BlockSize>>8);

    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[0] =
                                                        (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].TotBlockNumber>1)?
                                                        (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].TotBlockNumber-1):0;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[1] = (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].TotBlockNumber>>8);
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[2] = (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].TotBlockNumber>>16);
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[3] = (UCHAR)(usbms_context.usb_lun[usbms_context.current_lun].TotBlockNumber>>24);
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[4] = 0x00;

    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.powerPerformance  = 0x00; /* 0x00 energie, 0xFF perf */
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.lockd   = 0x00;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.formatd = 0x00;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.writed  = 0x00;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.readd   = 0x00;
    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.reserved4 = 0x00;

    /* Send the Mode Sense data, always the same zeroed struct */
    usb_send((char *)&usbms_context.mode_parameter_sense, min(sizeof(MODE_SENSE_PARAMETER),mode_sense->allocation_length));

    /* update the CSW structure */
    if (mode_sense->allocation_length<sizeof(MODE_SENSE_PARAMETER))
    {
      ms_computeCSW(GOOD_STATUS,0);
    }
    else
    {
      ms_computeCSW(GOOD_STATUS,mode_sense->allocation_length-sizeof(MODE_SENSE_PARAMETER));
    }
    /* update the state */
    usbms_context.state = USB_SEND_NO_FLASH;
  }
  else
  {
    usb_send((char *)&usbms_context.mode_parameter_sense.mode_parameter_head, sizeof(USBMS_MODE_PARAMETER_HEAD));
    /* We return an empty structure */
    /* Update the CSW */
    ms_computeCSW(GOOD_STATUS, mode_sense->allocation_length);
    /* update the state */
    usbms_context.state = USB_SEND_NO_FLASH;
  }

  TRACE_DEBUG_L( "blo 0 0x%X \n\r",    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.logicalBlockSize[0]);
  TRACE_DEBUG_L( "blo 1 0x%X \n\r",    usbms_context.mode_parameter_sense.mode_rbc_device_param_page.logicalBlockSize[1]);
  TRACE_DEBUG_L( "nu lb 0  0x%X \n\r", usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[0]);
  TRACE_DEBUG_L( "nu lb 1  0x%X \n\r", usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[1]);
  TRACE_DEBUG_L( "nu lb 2  0x%X \n\r", usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[2]);
  TRACE_DEBUG_L( "nu lb 3  0x%X \n\r", usbms_context.mode_parameter_sense.mode_rbc_device_param_page.numberOfLogicalBlocks[3]);

  return USBMS_OK;
}


/*****************************************************************
*
* ROUTINE : rbc_prevent_allow_removal
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc PREVENT_ALLOW_REMOVAL command
*
* Input Parameters  : Structure defining the PREVENT_ALLOW_REMOVAL command
*                     NO EFFECT
*
* Output Parameters : status of the operation
*
*****************************************************************/
USBMS_RETURN rbc_prevent_allow_removal(void)
{
  /* storing the removal capability  */
  /* usbms_context.usb_lun[usbms_context.current_lun].media_state = media_removal->prevent; */
  return USBMS_OK;
}


/*****************************************************************
*
* ROUTINE : rbc_start_stop_unit
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc START_STOP_UNIT command
*
* Input Parameters  : Structure defining the START_STOP_UNIT command
*
* Output Parameters : status of the operation
*
*****************************************************************/
USBMS_RETURN rbc_start_stop_unit( USBMS_START_STOP_UNIT* start_stop_unit )
{
  USBMS_RETURN status = USBMS_ERROR;

  if( start_stop_unit->Flags.bits0.Power_Conditions == 0 )
  {
    /* Table 9 - START STOP control bit definitions, rbc-r10a.pdf */
    /*   Power    Load/Eject START  Description            */
    /* Conditions                                          */
    /*   1 - 7       X         X    LOEJ and START ignored */
    /*     0         0         0    Stop the medium    */
    /*     0         0         1    Make medium ready  */
    /*     0         1         0    Unload medium      */
    /*     0         1         1    Load medium        */
    if( start_stop_unit->Flags.bits0.Start == 0 )
    {
      if( start_stop_unit->Flags.bits0.Load_Eject == 0 )
      {
        /* Stop the medium */
      }
      else
      {
        /* Make medium ready */
      }
    }
    else
    {
      if( start_stop_unit->Flags.bits0.Load_Eject == 0 )
      {
        /* Unload medium */
      }
      else
      {
        /* Load medium */
      }
    }
  }
  else
  {
    if( start_stop_unit->Flags.bits0.Power_Conditions == POWCOND_ACTIVE )
    {
      /* M No change in power condition. */
    }
    else
    {
      if( ( start_stop_unit->Flags.bits0.Power_Conditions == POWCOND_IDLE )
       || ( start_stop_unit->Flags.bits0.Power_Conditions == POWCOND_STDBY )
       || ( start_stop_unit->Flags.bits0.Power_Conditions == POWCOND_SLEEP ) )
      {
        /* lower power */
      }
      else
      {
        /* Reserved or Device Control */
      }
    }
  }
  status = USBMS_OK;
  return status;
}


/*****************************************************************
*
* ROUTINE : rbc_read_capacity
*
*-----------------------------------------------------------------
*
* Purpose : processes the rbc READ_CAPACITY command
*
* Input Parameters  : Structure defining the READ_CAPACITY command
*
* Output Parameters : status of the operation
*
*****************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -