Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * usbdefs.h
- *
- * Created: 11.9.2012 12:42:01
- * Author: Ondra
- */
- #ifndef USBDEFS_H_
- #define USBDEFS_H_
- #include "types.h"
- #include "../XBoot.h"
- #include "usb_cdc.h"
- #define byte unsigned char
- #define word uint16_t
- #define dword uint32_t
- struct usb_ram_t
- {
- uint16_t FIFO[(XBOOT_ENDPOINTS + 1) * 2];
- USB_EP_t endpoint[XBOOT_ENDPOINTS * 2];
- unsigned char payload[XBOOT_ENDPOINTS * 2][64];
- } ;
- typedef struct USB_DeviceRequest_t USB_DeviceRequest;
- #define bReqGET_STATUS 0
- #define bReqCLEAR_FEATURE 1
- #define bReqSET_FEATURE 3
- #define bReqSET_ADDRESS 5
- #define bReqGET_DESCRIPTOR 6
- #define bReqSET_DESCRIPTOR 7
- #define bReqGET_CONFIGURATION 8
- #define bReqSET_CONFIGURATION 9
- #define bReqGET_INTERFACE 10
- #define bReqSET_INTERFACE 11
- #define bReqSYNCH_FRAME 12
- #define DescriptorDEVICE 1
- #define DescriptorCONFIGURATION 2
- #define DescriptorSTRING 3
- #define DescriptorINTERFACE 4
- #define DescriptorENDPOINT 5
- #define DescriptorDEVICE_QUALIFIER 6
- #define DescriptorOTHER_SPEED_CONFIGURATION 7
- #define DescriptorINTERFACE_POWER 8
- #define CDC_CLASS_DEVICE 0x02
- #define XBOOT_VID 0x03EB
- #define XBOOT_PID 0x2404
- #define USB_STRING_LIST 0
- #define USB_STRING_MANUFACTURER 1
- #define USB_STRING_PRODUCT 2
- #define USB_STRING_SERIAL 3
- #define usb_ack_ctrl_in() LASR16(&usb_ram.endpoint[1].STATUS, USB_EP_BUSNACK0_bm);
- #define usb_ack_ctrl_out() LASR16(&usb_ram.endpoint[0].STATUS, USB_EP_BUSNACK0_bm);
- #define USB_STATE_DEFAULT 1
- #define USB_STATE_ADDRESS 2
- #define USB_STATE_CONFIGURED 3
- #define USB_STATE_POSTADDR 4
- #define USB_CONF_SELF_POWERED (1 << 6)
- #define USB_CONF_REMOTE_WAKEUP (1 << 5)
- #define USB_CONF_ALWAYSONE (1 << 7)
- enum usb_ep_type {
- USB_EP_TYPE_CONTROL = 0x00,
- USB_EP_TYPE_ISOCHRONOUS = 0x01,
- USB_EP_TYPE_BULK = 0x02,
- USB_EP_TYPE_INTERRUPT = 0x03,
- USB_EP_TYPE_MASK = 0x03,
- };
- #define XBOOT_MANUFACTURER L"XBoard"
- #define XBOOT_PRODUCT L"XBoard coco"
- #define XBOOT_SN L"0001"
- typedef struct Device_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- word bcdUSB;
- byte bDeviceClass;
- byte bDeviceSubClass;
- byte bDeviceProtocol;
- byte bMaxPacketSize0;
- word idVendor;
- word idProduct;
- word bcdDevice;
- byte iManufacturer;
- byte iProduct;
- byte iSerialNumber;
- byte bNumConfigurations;
- } Device_Descriptor_t;
- typedef struct Device_Qualifier_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- word bcdUSB;
- byte bDeviceClass;
- byte bDeviceSubClass;
- byte bDeviceProtocol;
- byte bMaxPacketSize0;
- byte bNumConfigurations;
- byte bReserved;
- } Device_Qualifier_Descriptor_t;
- typedef struct String_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- wchar_t bString[24];
- } String_Descriptor_t;
- typedef struct Configuration_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- word wTotalLength;
- byte bNumInterfaces;
- byte bConfigurationValue;
- byte iConfiguration;
- byte bmAttributes;
- byte bMaxPower;
- } Configuration_Descriptor_t;
- typedef struct Interface_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- byte bInterfaceNumber;
- byte bAlternateSetting;
- byte bNumEndpoints;
- byte bInterfaceClass;
- byte bInterfaceSubClass;
- byte bInterfaceProtocol;
- byte iInterface;
- } Interface_Descriptor_t;
- typedef struct Endpoint_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- byte bEndpointAddress;
- byte bmAttributes;
- word wMaxPacketSize;
- byte bInterval;
- } Endpoint_Descriptor_t;
- typedef struct Language_Descriptor_t
- {
- byte bLength;
- byte bDescriptorType;
- word wLANGID;
- } Language_Descriptor_t;
- typedef struct Get_Status_t
- {
- byte b1;
- byte b2;
- } Get_Status_t;
- typedef struct {
- byte bFunctionLength;
- byte bDescriptorType;
- byte bDescriptorSubtype;
- word bcdCDC;
- } CDC_Header_t;
- typedef struct {
- byte bFunctionLength;
- byte bDescriptorType;
- byte bDescriptorSubtype;
- byte bmCapabilities;
- } CDC_ACM_t;
- typedef struct {
- byte bFunctionLength;
- byte bDescriptorType;
- byte bDescriptorSubtype;
- byte bControlInterface;
- byte bMasterInterface;
- byte bSlaveInterface0;
- } CDC_Union_t;
- typedef struct {
- byte bFunctionLength;
- byte bDescriptorType;
- byte bDescriptorSubtype;
- byte bmCapabilities;
- byte bDataInterface;
- } CDC_Management_t;
- typedef struct {
- Interface_Descriptor_t Interface;
- CDC_Header_t Header;
- CDC_ACM_t ACM;
- CDC_Union_t Union;
- CDC_Management_t Management;
- Endpoint_Descriptor_t EndpointNotify;
- } USB_CDC_Descriptor_Communication_t;
- typedef struct {
- Interface_Descriptor_t Interface;
- Endpoint_Descriptor_t EndpointIn;
- Endpoint_Descriptor_t EndpointOut;
- } USB_CDC_Descriptor_Data_t;
- typedef struct Complete_Configuration_t
- {
- Configuration_Descriptor_t Configuration;
- USB_CDC_Descriptor_Communication_t Comm;
- USB_CDC_Descriptor_Data_t Data;
- } Complete_Configuration_t;
- typedef struct {
- Configuration_Descriptor_t Configuration;
- USB_CDC_Descriptor_Communication_t Communication;
- USB_CDC_Descriptor_Data_t Data;
- } UDC_Descriptor_t;
- typedef struct
- {
- byte bLength;
- byte bDescriptorType;
- word wTotalLength;
- byte bNumInterfaces;
- byte bConfigurationValue;
- byte iConfiguration;
- byte bmAttributes;
- byte bMaxPower;
- } Other_Speed_Configuration_t;
- Device_Descriptor_t Device_Descriptor = {
- .bLength = sizeof(Device_Descriptor_t),
- .bDescriptorType = DescriptorDEVICE,
- .bcdUSB = 0x0200, // 02 00 in LE
- .bDeviceClass = CDC_CLASS_DEVICE,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
- .bMaxPacketSize0 = XBOOT_DATASIZE,
- .idVendor = XBOOT_VID,
- .idProduct = XBOOT_PID,
- .bcdDevice = XBOOT_VERSION,
- .iManufacturer = USB_STRING_MANUFACTURER,
- .iProduct = USB_STRING_PRODUCT,
- .iSerialNumber = 0,
- .bNumConfigurations = 1
- };
- String_Descriptor_t String_Manufacturer = {
- .bLength = 2 + sizeof(XBOOT_MANUFACTURER) - 2,
- .bDescriptorType = DescriptorSTRING,
- .bString = XBOOT_MANUFACTURER
- };
- String_Descriptor_t String_Product = {
- .bLength = 2 + sizeof(XBOOT_PRODUCT) - 2,
- .bDescriptorType = DescriptorSTRING,
- .bString = XBOOT_PRODUCT
- };
- String_Descriptor_t String_SerialNumber = {
- .bLength = 2 + sizeof(XBOOT_SN) - 2,
- .bDescriptorType = DescriptorSTRING,
- .bString = XBOOT_SN
- };
- Device_Qualifier_Descriptor_t Device_Qualifier_Descriptor = {
- .bLength = sizeof(Device_Qualifier_Descriptor_t),
- .bDescriptorType = DescriptorDEVICE_QUALIFIER,
- .bcdUSB = 0x2000,
- .bDeviceClass = CDC_CLASS_DEVICE,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
- .bMaxPacketSize0 = XBOOT_DATASIZE,
- .bNumConfigurations = 1,
- .bReserved = 0
- };
- Language_Descriptor_t Language_Descriptor = {
- .bLength = 4,
- .bDescriptorType = DescriptorSTRING,
- .wLANGID = 0x0409
- };
- Complete_Configuration_t Complete_Configuration = {
- .Configuration = {
- .bLength = sizeof(Configuration_Descriptor_t),
- .bDescriptorType = DescriptorCONFIGURATION,
- .wTotalLength = sizeof(Complete_Configuration_t),
- .bNumInterfaces = 2,
- .bConfigurationValue = 1,
- .iConfiguration = 0,
- .bmAttributes = USB_CONF_ALWAYSONE,
- .bMaxPower = 500/2
- },
- .Comm = {
- .Interface = {
- .bLength = sizeof(Interface_Descriptor_t),
- .bDescriptorType = DescriptorINTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 0,
- .bNumEndpoints = 1,
- .bInterfaceClass = CDC_CLASS_DEVICE,
- .bInterfaceSubClass = USB_CDC_Subclass_AbstractControlModel,
- .bInterfaceProtocol = USB_CDC_Interface_Class_Protocol_ITU_T_V250,
- .iInterface = 0
- },
- .Header = {
- .bFunctionLength = sizeof(CDC_Header_t),
- .bDescriptorType = CDC_CS_INTERFACE,
- .bDescriptorSubtype = CDC_SCS_HEADER,
- .bcdCDC = 0x0110
- },
- .ACM = {
- .bFunctionLength = sizeof(CDC_ACM_t),
- .bDescriptorType = CDC_CS_INTERFACE,
- .bDescriptorSubtype = CDC_SCS_ACM,
- .bmCapabilities = CDC_ACM_SUPPORT_LINE_REQUESTS
- },
- .Union = {
- .bFunctionLength = sizeof(CDC_Union_t),
- .bDescriptorType = CDC_CS_INTERFACE,
- .bDescriptorSubtype = CDC_SCS_UNION
- },
- .Management = {
- .bFunctionLength = sizeof(CDC_Management_t),
- .bDescriptorType = CDC_CS_INTERFACE,
- .bDescriptorSubtype = CDC_SCS_CALL_MGMT,
- .bmCapabilities = CDC_CALL_MGMT_OVER_DCI | CDC_CALL_MGMT_SUPPORTED
- },
- .EndpointNotify = {
- .bLength = sizeof(Endpoint_Descriptor_t),
- .bDescriptorType = DescriptorENDPOINT,
- .bmAttributes = USB_EP_TYPE_INTERRUPT,
- .wMaxPacketSize = 64, // 64 bytes
- .bInterval = 0x10,
- .bEndpointAddress = 0x82
- }
- },
- .Data = {
- .Interface = {
- .bLength = sizeof(Interface_Descriptor_t),
- .bDescriptorType = DescriptorINTERFACE,
- .bAlternateSetting = 0,
- .bNumEndpoints = 2,
- .bInterfaceClass = CDC_CLASS_DEVICE,
- .bInterfaceSubClass = 0,
- .bInterfaceProtocol = 0,
- .bInterfaceNumber = 1,
- .iInterface = 0
- },
- .EndpointIn = {
- .bLength = sizeof(Endpoint_Descriptor_t),
- .bDescriptorType = DescriptorENDPOINT,
- .bmAttributes = USB_EP_TYPE_BULK,
- .bInterval = 2,
- .bEndpointAddress = 0x81,
- .wMaxPacketSize = 64
- },
- .EndpointOut = {
- .bLength = sizeof(Endpoint_Descriptor_t),
- .bDescriptorType = DescriptorENDPOINT,
- .bmAttributes = USB_EP_TYPE_BULK,
- .bInterval = 2,
- .bEndpointAddress = 0x02,
- .wMaxPacketSize = 64
- }
- }
- };
- Get_Status_t Get_Status_Reply = {
- .b1 = 0,
- .b2 = 0
- };
- #define USB_REQ_DIRECTION_MASK 0b1 << 7
- #define USB_REQ_TYPE_MASK 0b11 << 5
- #define USB_REQ_RECIPIENT_MASK 0b11111 << 0
- #define USB_REQ_DIRECTION_HOSTTODEVICE 0 << 7
- #define USB_REQ_DIRECTION_DEVICETOHOST 1 << 7
- #define USB_REQ_TYPE_STANDARD 0 << 5
- #define USB_REQ_TYPE_CLASS 1 << 5
- #define USB_REQ_TYPE_VENDOR 2 << 5
- #define USB_REQ_RECIPIENT_DEVICE 0 << 0
- #define USB_REQ_RECIPIENT_INTERFACE 1 << 0
- #define USB_REQ_RECIPIENT_ENDPOINT 2 << 0
- #define USB_REQ_RECIPIENT_OTHER 3 << 0
- CDC_Line_Coding_t CDC_Line_Coding = {
- .dwDTERate = 115200,
- .bCharFormat = 0, // 1 stop bit
- .bParityType = 0, // no parity
- .bDataBits = 8 // 8 bits per byte
- };
- #define LACR16(addr,msk) \
- __asm__ __volatile__ ( \
- "ldi r16, %1" "\n\t" \
- ".dc.w 0x9306" "\n\t"\
- ::"z" (addr), "M" (msk):"r16")
- /*#define LASR16(addr,msk) \
- __asm__ __volatile__ ( \
- "ldi r16, %1" "\n\t" \
- ".dc.w 0x9305" "\n\t"\
- ::"z" (addr), "M" (msk):"r16")
- */
- #define LASR16(addr,mask) *addr &= ~mask
- #endif /* USBDEFS_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement