Ejemplo n.º 1
0
static int scsi_cmd_request_sense()
{
    union {
        uint_8 cmd[6];
        uint_8 resp[18];
    } data;
    int err;


    data.cmd[0]=SCSI_CMD_REQUEST_SENSE;
    data.cmd[1]=0<<5;
    data.cmd[2]=data.cmd[3]=0; 
    data.cmd[4]=18;            
    data.cmd[5]=0;            

    err=(*transfer)(6, &data.cmd[0], DIR_IN, 18, &data.resp[0]);
    if (err)
    {
        switch(err)
        {
            case ERR_IO_NONE: 
                break;
            case ERR_IO_CHECK: 
            case ERR_IO_REMOVED:
                lun.error_code=LERR_CRITICAL_ERROR;
                return(1);
            case ERR_IO_READ:
                lun.error_code=LERR_IOREAD_ERROR;
                return(1);
            case ERR_IO_WRITE:
                lun.error_code=LERR_IOWRITE_ERROR;
                return(1);
        }
    }

    CMX_ASSERT(data.resp[0] == 0x70);

    if (data.resp[0] == 0x70)
    {
        lun.sense_key = data.resp[2];
        lun.sense_data = data.resp[12];
        lun.sense_qualifyer = data.resp[13];
        lun.sense_info = (uint_32)(((uint_32)data.resp[3]) << 24 | ((uint_32)data.resp[4]) << 16
                             |((uint_32)data.resp[5]) << 8 |((uint_32)data.resp[6]) << 0);//RD_BE32(&data.resp[3]);
    }
    else
    {
        CMX_ASSERT(0);   
    }
    return(0);
}
Ejemplo n.º 2
0
int scsi_open_device(rw_func_t *f)
{ 
    int r=0;
  
    CMX_ASSERT(f != 0);
  
    transfer=f;
    r=scsi_reset_lun();
    return(r);
}
Ejemplo n.º 3
0
void cdc_process(void)
{
  /* See if USB is in usable state. */    
  if (usb_get_state() == USBST_CONFIGURED)
  {    
    /*  If endpoint is not busy, and receive buffer is empty */
    if (!usb_ep_is_busy(CDC_RX_EP_NO) && (rx_length <= rx_ndx))
    {
      /* Read out error status of endpoint. The reception may be aborted due
         to a status change on the USB (disconnect, sleep, etc..) or due to
         an error (CRC, bit stuffing, etc...). In both case wee need to restart
         reception if possible.  */
      switch(usb_ep_error(CDC_RX_EP_NO))
      {
      case USBEPERR_NONE: /* Reception finished with no error. */
        /* If received bytes are not yet handled. */
        if (rx_length == 0)
        {          
          /* Read out number of received bytes. This will make us to return
             received characters for the next call. Note: the transfer may
             contain 0 characters, so we return the first character only when
             the next call is made. */
          rx_length=(hcc_u8)usb_get_done(CDC_RX_EP_NO);
          rx_ndx=0;
          /* If we did not received any data, then we need to start a new receive. */
          if (rx_length)
          {
            break;          
          }
        }
      case USBEPERR_PROTOCOL_ERROR:
        /* restart the reception */
        rx_length=0;
        usb_receive(CDC_RX_EP_NO, (void *) 0, (void *) rx_buffer, sizeof(rx_buffer));
        break;      
      case USBEPERR_HOST_ABORT:        
        /* This error can only be detected if error happens after execution of thefirst if
           in this function and before the switch. This is unlikely to happen. On the other
           hand this error meand usb has been disconnected or put to low power mode and thus
           we may safely ignore it. */
        break;
      case USBEPERR_USER_ABORT:
      case USBEPERR_TO_MANY_DATA:
      default:
        /* Upps! unexpected error. Stop here. */
        CMX_ASSERT(0);
      }
    }

    /* If tx buffer is not empty, start transmission. */
    if (!usb_ep_is_busy(CDC_TX_EP_NO) && (tx_ndx != 0))
    {
      /* Check the status of the next transfer. */
      switch (usb_ep_error(CDC_TX_EP_NO))
      {
      case USBEPERR_PROTOCOL_ERROR:   /* Ignore error, send next chunk. */
      case USBEPERR_HOST_ABORT:
      case USBEPERR_NONE: /* Finished with no error. */
        /* Start sending next chunk. */
        usb_send(CDC_TX_EP_NO, (void *) 0, (void *) cur_tx_buffer, tx_ndx, tx_ndx);
        /* Switch buffer. */
        tx_ndx=0;
        cur_tx_buffer = (hcc_u8*)((cur_tx_buffer == (hcc_u8*)tx_buffer1) ? tx_buffer2 : tx_buffer1);
        break;
      case USBEPERR_USER_ABORT:
      case USBEPERR_TO_MANY_DATA:
      default:
        /* Upps! unexpected error. Stop here. */
        CMX_ASSERT(0);
      }
    }
  }
}