📄 usbd_mass.c
字号:
/* * A EEEE SSSS OOO PPPP * A A E S O O P P * AAAAA EEEE SSSS O O PPPP * A A E S O O P * A A EEEE SSSS OOO P * * An Entertainment Solution On a Platform (AESOP) is a completely Open Source * based graphical user environment and suite of applications for PDAs and other * devices running Linux. It is included in various embedded Linux distributions * such as OpenZaurus - http://www.aesop-embedded.org * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * Title : usbd_mass.c * Author : * Created date : 2005. 06. 26. 23:10:33 KST * Description : * * $Revision: 1.2 $ * $Log: usbd_mass.c,v $ * Revision 1.2 2005/07/05 14:16:41 jeenspa * usbdmass fixup, nand, mkyaffs * * Revision 1.1.1.1 2005/06/27 17:04:30 linuxpark * Initial import. * * * */ #ident "@(*) $Header: /cvsroot/aesop-embedded/u-boot-aesop/board/aesop2440/usbd_mass.c,v 1.2 2005/07/05 14:16:41 jeenspa Exp $"/* * Copyright (c) 2005 * Junyoung Song, kernelproject.org <jun0song@kornet.net> * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */#if 0#define DEBUGJY 3#endif#include <common.h>#ifdef CONFIG_AESOP_USBDMASS#include <s3c2440.h>#include <asm/types.h>#include "usbd_common.h"#include "usbd_24x0.h"#include "usbd_mass.h"#include "usbd_scsi.h"#include "usbd_media.h"#if 1#define USE_SERIAL#endif/********************************************************************* * * Global Variables * ********************************************************************//* * Descriptors */static u8 wstrLang[4] = {4,USB_DT_STRING,0x9,0x4};static u8 wstrManufacturer[2 + 2*(sizeof(CONFIG_USBD_MANUFACTURER)-1)];static u8 wstrProduct[2 + 2*(sizeof(CONFIG_USBD_PRODUCT_NAME)-1)];static u8 wstrConfiguration[2 + 2*(sizeof(CONFIG_USBD_CONFIGURATION_STR)-1)];static u8 wstrInterface[2 + 2*(sizeof(CONFIG_USBD_INTERFACE_STR)-1)];static u8 wstrSerial[2 + 2*(sizeof(CONFIG_USBD_SERIAL_STR) - 1)];/* * Serial number */static char serial_number[16];static struct usb_string_descriptor *usbdmass_string_table[] = { (struct usb_string_descriptor*)wstrLang, (struct usb_string_descriptor*)wstrManufacturer, (struct usb_string_descriptor*)wstrProduct, (struct usb_string_descriptor*)wstrConfiguration, (struct usb_string_descriptor*)wstrInterface, (struct usb_string_descriptor*)wstrSerial};static usb_config_descriptor_all config_descriptor_all = { config_descriptor: { bLength: sizeof(struct usb_config_descriptor), bDescriptorType: USB_DT_CONFIG,/* wTotalLength: sizeof(struct usb_config_descriptor) + \ sizeof(struct usb_interface_descriptor) + \ sizeof(struct usb_endpoint_descriptor) * NUM_ENDPOINTS,*/ wTotalLength: sizeof(struct usb_config_descriptor_all), bNumInterfaces: NUM_INTERFACES, bConfigurationValue: 1, iConfiguration: STR_CONFIG, bmAttributes: BMATTRIBUTE_SELF_POWERED | BMATTRIBUTE_RESERVED, bMaxPower: USBDMASS_MAXPOWER, },/* interface descriptor */ interface_descriptor: { bLength: sizeof(struct usb_interface_descriptor), bDescriptorType: USB_DT_INTERFACE, bInterfaceNumber: 0, bAlternateSetting: 0, bNumEndpoints: NUM_ENDPOINTS, bInterfaceClass: USBDMASS_INTERFACE_CLASS, bInterfaceSubClass: USBDMASS_INTERFACE_SUBCLASS, bInterfaceProtocol: USBDMASS_INTERFACE_PROTOCOL, iInterface: STR_INTERFACE },/* endpoint descriptors */ endpoint_descriptor: { { bLength: sizeof(struct usb_endpoint_descriptor), bDescriptorType: USB_DT_ENDPOINT, bEndpointAddress: CONFIG_USBD_MASS_IN_ENDPOINT | USB_DIR_IN, bmAttributes: USB_ENDPOINT_XFER_BULK, wMaxPacketSize: CONFIG_USBD_MASS_IN_PKTSIZE, bInterval: 0 }, { bLength: sizeof(struct usb_endpoint_descriptor), bDescriptorType: USB_DT_ENDPOINT, bEndpointAddress: CONFIG_USBD_MASS_OUT_ENDPOINT | USB_DIR_OUT, bmAttributes: USB_ENDPOINT_XFER_BULK, wMaxPacketSize: CONFIG_USBD_MASS_OUT_PKTSIZE, bInterval: 0 } }};static usb_endpoint_descriptor *ep_descriptor_ptrs[NUM_ENDPOINTS] = { &(config_descriptor_all.endpoint_descriptor[0]), &(config_descriptor_all.endpoint_descriptor[1]),};static usb_device_descriptor device_descriptor = { bLength: sizeof(struct usb_device_descriptor), bDescriptorType: USB_DT_DEVICE, bcdUSB: USB_BCD_VERSION, bDeviceClass: USBDMASS_DEVICE_CLASS, bDeviceSubClass: USBDMASS_DEVICE_SUBCLASS, bDeviceProtocol: USBDMASS_DEVICE_PROTOCOL, bMaxPacketSize0: EP0_MAX_PACKET_SIZE, idVendor: CONFIG_USBD_VENDORID, idProduct: CONFIG_USBD_PRODUCTID, bcdDevice: USBDMASS_BCD_DEVICE, iManufacturer: STR_MANUFACTURER, iProduct: STR_PRODUCT,#ifdef USE_SERIAL iSerialNumber: STR_SERIAL,#else iSerialNumber: 0, /* Not use serial no. */#endif bNumConfigurations: NUM_CONFIGS};static usbd_ep0_instance ep0;static usbd_mass_instance ma;/********************************************************************* * * USB Device Mass-Storage Main * ********************************************************************/int usbdmass (char *string){ S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); printf ("USB Device Mass-storage Class Handler\n"); ma.media.status = ABSENT; if ((strcmp(string, "SD") == 0) | (strcmp(string, "sd") == 0)) ma.media.type = SD; else if ((strcmp(string, "NAND") == 0) | (strcmp(string, "nand") == 0)) ma.media.type = NAND; else if ((strcmp(string, "RAM") == 0) | (strcmp(string, "ram") == 0)) ma.media.type = RAM; else { printf ("Invalid media type \"%s\"\n", string); return -1; } usbd_media_probe(&ma); if (ma.media.status == ABSENT) { printf("Media is not ready\n"); return -1; } if (!usbd_24x0_init_usb()) { printf("USB not connected\n"); return -1; } debugvs (1, "%s : %s - USBD VBUS Check OK\n", __FILE__, __FUNCTION__); #ifdef USE_SERIAL { unsigned char *sn; int snlen; if (!(sn = getenv("serial#"))) { sn = "000178506999"; } snlen = strlen(sn); if (snlen > sizeof(serial_number) - 1) { printf ("Warning: serial number %s is too long (%d > %d)\n", sn, snlen, sizeof(serial_number) - 1); snlen = sizeof(serial_number) - 1; } memcpy (serial_number, sn, snlen); serial_number[snlen] = '\0'; }#endif usbdmass_init_strings(); usbdmass_class_init(); usbd_scsi_init(&ma); ep0.state = IDLE; ma.usb_reset = FALSE; usbd_24x0_connect(); while (TRUE) { ma.usb_reset = FALSE; led1_off(); if (usbdmass_check_control_int() & USBD_INT_EP2) usbdmass_isr_ep2(); if (ctrlc()) { printf ("User interrupt\n"); break; } } usbd_24x0_disconnect(); debug_display(); printf ("usbdmass command terminated\n"); return 0;}/* USBDevice control interrupt check & process */int usbdmass_check_control_int(void){ int value; value = usbd_24x0_chk_int(); if (value != 0) { if (value & USBD_INT_RESET) usbdmass_isr_reset(); if (value & USBD_INT_EP0) usbdmass_isr_ep0(); } return value; }/* USBDevice reset interrupt handler */void usbdmass_isr_reset(void){ debugvs(2, "%s : %s - USBD RESET Interrupt\n", __FILE__, __FUNCTION__); usbd_24x0_init_usb_reset(); ep0.state = IDLE; usbdmass_class_init(); usbd_scsi_init(&ma);}/********************************************************************* * * USB Device Mass-Storage Init. Functions * ********************************************************************//* Init Strings (Ch.9) */void usbdmass_init_strings (void){ struct usb_string_descriptor *string; string = (struct usb_string_descriptor *) wstrManufacturer; string->bLength = sizeof (wstrManufacturer); string->bDescriptorType = USB_DT_STRING; str2wide (CONFIG_USBD_MANUFACTURER, string->wData); string = (struct usb_string_descriptor *) wstrProduct; string->bLength = sizeof (wstrProduct); string->bDescriptorType = USB_DT_STRING; str2wide (CONFIG_USBD_PRODUCT_NAME, string->wData); string = (struct usb_string_descriptor *) wstrSerial; string->bLength = 2 + 2*strlen(serial_number); string->bDescriptorType = USB_DT_STRING; str2wide (serial_number, string->wData); string = (struct usb_string_descriptor *) wstrConfiguration; string->bLength = sizeof (wstrConfiguration); string->bDescriptorType = USB_DT_STRING; str2wide (CONFIG_USBD_CONFIGURATION_STR, string->wData); string = (struct usb_string_descriptor *) wstrInterface; string->bLength = sizeof (wstrInterface); string->bDescriptorType = USB_DT_STRING; str2wide (CONFIG_USBD_INTERFACE_STR, string->wData);}void usbdmass_class_init(void){ ma.state = WAIT_CBW; ma.stall = NONE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -