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

📄 cdc_enumerate.lst

📁 关于usb的一段程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
    192          
    193          #define NUM_INTERFACES   1
    194          #define NUM_ENDPOINTS    2
    195          
    196          #define USB_MAIN_OUT            0b00000010      /* endpoint address (OUT,2) */
    197          #define USB_MAIN_IN             0b10000010      /* endpoint address (IN,2) */
    198          
    199          
    200          #define USB_DESC_CONFIG_SIZE 9  /* bytes*/
    201          
    202          
    203          #define USB_DESC_INTERFACE_SIZE 9  /* bytes*/
    204          
    205          
    206          #define USB_DESC_ENDPOINT_SIZE 7  /* bytes*/
    207          
    208          /* the configuration descriptor of our printer has one interface,
    209           * which itself has two endpoints (main IN and OUT)
    210           * the following array lays down the whole configuration descriptor
    211           * which will be sent as a whole upon a GET_DESCRIPTOR device
    212           * request */
    213          
    214          #define USB_TOTAL_LENGTH                        \
    215             USB_DESC_CONFIG_SIZE +                       \
    216             USB_DESC_INTERFACE_SIZE*NUM_INTERFACES +     \
    217             USB_DESC_ENDPOINT_SIZE*NUM_ENDPOINTS
    218          /*
    219              USB_TOTAL_LENGTH = 9 + 9 * 1 + 7 * 2 = 32
    220          */
    221          
    222          const char cfgDescriptor[] = {
   \                     cfgDescriptor:
   \   00000014   090220000101       DC8 9, 2, 32, 0, 1, 1, 0, 192, 0, 9, 4, 0, 0, 2, 7, 1, 2, 0, 5, 36, 0
   \              00C000090400
   \              000207010200
   \              052400      
   \   00000029   100104240200       DC8 16, 1, 4, 36, 2, 0, 5, 36, 6, 0, 1, 5, 36, 1, 0, 1, 7, 5, 131, 3, 8
   \              052406000105
   \              240100010705
   \              830308      
   \   0000003E   00FF09040100       DC8 0, 255, 9, 4, 1, 0, 2, 10, 0, 0, 0, 7, 5, 1, 2, 64, 0, 0, 7, 5, 130
   \              020A00000007
   \              050102400000
   \              070582      
   \   00000053   0240000000         DC8 2, 64, 0, 0, 0
    223          	/* ============== CONFIGURATION 1 =========== */
    224          	/* Configuration 1 descriptor */
    225          	USB_DESC_CONFIG_SIZE,   // CbLength
    226          	USB_DESC_CONFIG,   // CbDescriptorType
    227              0x20,   // /* total length of config desc */
    228          	0x00,
    229          	NUM_INTERFACES,   // CbNumInterfaces
    230          	0x01,   // CbConfigurationValue
    231          	0x00,   // CiConfiguration
    232          	0xC0,   // CbmAttributes 0xA0  /* self-powered device */
    233          	0x00,   // CMaxPower
    234          
    235          	/* Communication Class Interface Descriptor Requirement */
    236          	USB_DESC_INTERFACE_SIZE, // bLength
    237          	USB_DESC_INTERFACE, // bDescriptorType
    238          	0x00, // bInterfaceNumber
    239          	0x00, // bAlternateSetting
    240          	NUM_ENDPOINTS, // bNumEndpoints
    241          	0x07, // bInterfaceClass ; class code (printer)
    242          	0x01, // bInterfaceSubclass
    243          	0x02, // bInterfaceProtocol
    244          	0x00, // iInterface
    245          
    246          	/* Header Functional Descriptor */
    247          	0x05, // bFunction Length
    248          	0x24, // bDescriptor type: CS_INTERFACE
    249          	0x00, // bDescriptor subtype: Header Func Desc
    250          	0x10, // bcdCDC:1.1
    251          	0x01,
    252          
    253          	/* ACM Functional Descriptor */
    254          	0x04, // bFunctionLength
    255          	0x24, // bDescriptor Type: CS_INTERFACE
    256          	0x02, // bDescriptor Subtype: ACM Func Desc
    257          	0x00, // bmCapabilities
    258          
    259          	/* Union Functional Descriptor */
    260          	0x05, // bFunctionLength
    261          	0x24, // bDescriptorType: CS_INTERFACE
    262          	0x06, // bDescriptor Subtype: Union Func Desc
    263          	0x00, // bMasterInterface: Communication Class Interface
    264          	0x01, // bSlaveInterface0: Data Class Interface
    265          
    266          	/* Call Management Functional Descriptor */
    267          	0x05, // bFunctionLength
    268          	0x24, // bDescriptor Type: CS_INTERFACE
    269          	0x01, // bDescriptor Subtype: Call Management Func Desc
    270          	0x00, // bmCapabilities: D1 + D0
    271          	0x01, // bDataInterface: Data Class Interface 1
    272          
    273          	/* Endpoint 1 descriptor */
    274          	0x07,   // bLength
    275          	0x05,   // bDescriptorType
    276          	0x83,   // bEndpointAddress, Endpoint 03 - IN
    277          	0x03,   // bmAttributes      INT
    278          	0x08,   // wMaxPacketSize
    279          	0x00,
    280          	0xFF,   // bInterval
    281          
    282          	/* Data Class Interface Descriptor Requirement */
    283          	0x09, // bLength
    284          	0x04, // bDescriptorType
    285          	0x01, // bInterfaceNumber
    286          	0x00, // bAlternateSetting
    287          	0x02, // bNumEndpoints
    288          	0x0A, // bInterfaceClass
    289          	0x00, // bInterfaceSubclass
    290          	0x00, // bInterfaceProtocol
    291          	0x00, // iInterface
    292          
    293          	/* First alternate setting */
    294          	/* Endpoint 1 descriptor */
    295          	0x07,   // bLength
    296          	0x05,   // bDescriptorType
    297          	0x01,   // bEndpointAddress, Endpoint 01 - OUT
    298          	0x02,   // bmAttributes      BULK
    299          	AT91C_EP_OUT_SIZE,   // wMaxPacketSize
    300          	0x00,
    301          	0x00,   // bInterval
    302          
    303          	/* Endpoint 2 descriptor */
    304          	0x07,   // bLength
    305          	0x05,   // bDescriptorType
    306          	0x82,   // bEndpointAddress, Endpoint 02 - IN
    307          	0x02,   // bmAttributes      BULK
    308          	AT91C_EP_IN_SIZE,   // wMaxPacketSize
    309          	0x00,
    310          	0x00    // bInterval
    311          };
    312          
    313          #endif
    314          
    315          
    316          
    317          
    318          /* USB standard request code */
    319          #define STD_GET_STATUS_ZERO           0x0080
    320          #define STD_GET_STATUS_INTERFACE      0x0081
    321          #define STD_GET_STATUS_ENDPOINT       0x0082
    322          
    323          #define STD_CLEAR_FEATURE_ZERO        0x0100
    324          #define STD_CLEAR_FEATURE_INTERFACE   0x0101
    325          #define STD_CLEAR_FEATURE_ENDPOINT    0x0102
    326          
    327          #define STD_SET_FEATURE_ZERO          0x0300
    328          #define STD_SET_FEATURE_INTERFACE     0x0301
    329          #define STD_SET_FEATURE_ENDPOINT      0x0302
    330          
    331          #define STD_SET_ADDRESS               0x0500
    332          #define STD_GET_DESCRIPTOR            0x0680
    333          #define STD_SET_DESCRIPTOR            0x0700
    334          #define STD_GET_CONFIGURATION         0x0880
    335          #define STD_SET_CONFIGURATION         0x0900
    336          #define STD_GET_INTERFACE             0x0A81
    337          #define STD_SET_INTERFACE             0x0B01
    338          #define STD_SYNCH_FRAME               0x0C82
    339          
    340          /* CDC Class Specific Request Code */
    341          #define GET_LINE_CODING               0x21A1
    342          #define SET_LINE_CODING               0x2021
    343          #define SET_CONTROL_LINE_STATE        0x2221
    344          
    345          
    346          typedef struct {
    347          	unsigned int dwDTERRate;
    348          	char bCharFormat;
    349          	char bParityType;
    350          	char bDataBits;
    351          } AT91S_CDC_LINE_CODING, *AT91PS_CDC_LINE_CODING;
    352          

   \                                 In segment DATA_I, align 4, align-sorted
    353          AT91S_CDC_LINE_CODING line = {
   \                     line:
   \   00000000                      DS8 8
   \   00000008                      REQUIRE `?<Initializer for line>`
    354          	115200, // baudrate
    355          	0,      // 1 Stop Bit
    356          	0,      // None Parity
    357          	8};     // 8 Data bits
    358          

   \                                 In segment DATA_I, align 4, align-sorted
    359          uint currentReceiveBank = AT91C_UDP_RX_DATA_BK0;
   \                     currentReceiveBank:
   \   00000000                      DS8 4
   \   00000004                      REQUIRE `?<Initializer for currentReceiveBank>`
    360          
    361          
    362          static uchar AT91F_UDP_IsConfigured(AT91PS_CDC pCdc);
    363          static uint AT91F_UDP_Read(AT91PS_CDC pCdc, char *pData, uint length);
    364          static uint AT91F_UDP_Write(AT91PS_CDC pCdc, const char *pData, uint length);
    365          static void AT91F_CDC_Enumerate(AT91PS_CDC pCdc);
    366          
    367          
    368          //*----------------------------------------------------------------------------
    369          //* \fn    AT91F_CDC_Open
    370          //* \brief
    371          //*----------------------------------------------------------------------------

   \                                 In segment CODE, align 4, keep-with-next
    372          AT91PS_CDC AT91F_CDC_Open(AT91PS_CDC pCdc, AT91PS_UDP pUdp)
    373          {
    374          	pCdc->pUdp = pUdp;
   \                     AT91F_CDC_Open:
   \   00000000   0160               STR         R1,[R0, #+0]
    375          	pCdc->currentConfiguration = 0;
   \   00000002   0021               MOV         R1,#+0
   \   00000004   0171               STRB        R1,[R0, #+4]
    376          	pCdc->currentConnection    = 0;
   \   00000006   4171               STRB        R1,[R0, #+5]
    377          	pCdc->currentRcvBank       = AT91C_UDP_RX_DATA_BK0;
   \   00000008   0221               MOV         R1,#+2
   \   0000000A   8160               STR         R1,[R0, #+8]
    378          	pCdc->IsConfigured = AT91F_UDP_IsConfigured;
   \   0000000C   0349               LDR         R1,??AT91F_CDC_Open_0  ;; AT91F_UDP_IsConfigured
   \   0000000E   C160               STR         R1,[R0, #+12]
    379          	pCdc->Write        = AT91F_UDP_Write;
   \   00000010   0349               LDR         R1,??AT91F_CDC_Open_0+0x4  ;; AT91F_UDP_Write
   \   00000012   0161               STR         R1,[R0, #+16]
    380          	pCdc->Read         = AT91F_UDP_Read;
   \   00000014   0349               LDR         R1,??AT91F_CDC_Open_0+0x8  ;; AT91F_UDP_Read
   \   00000016   4161               STR         R1,[R0, #+20]
    381          	return pCdc;
   \   00000018   7047               BX          LR                 ;; return
   \   0000001A   C046               NOP         
   \                     ??AT91F_CDC_Open_0:
   \   0000001C   ........           DC32        AT91F_UDP_IsConfigured
   \   00000020   ........           DC32        AT91F_UDP_Write
   \   00000024   ........           DC32        AT91F_UDP_Read
    382          }
    383          
    384          //*----------------------------------------------------------------------------

⌨️ 快捷键说明

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