#ifndef __dvoraj42__ #define __dvoraj42__ /******************************************************************************/ //includes #include #include "71x_lib.h" /******************************************************************************/ //EPnRs p. 293 //Ready - transmit buffer is ready - PC can read it // 0001 0010 0001 0000 = Stat RX toggle : set valid | EP type = 01: control | Stat TX toggle: set valid |EP 0 #define EPnR_READY 0x1210 //Transmitted - PC read data and set bit ´ // 0000 0010 0000 0000 = | EP type = 01: control | | EP0 #define EPnR_TRANSMITTED 0x200 //Recieved - tell PC that we read data // 0000 0010 0000 0000 = | EP type = 01: control | | EP0 #define EPnR_RECIEVED 0x200 /******************************************************************************/ //UART Buffer size + processor deadlock on waiting protection #define MAX_LOOP 10000 #define UART_BUFFER_SIZE 1024 /******************************************************************************/ //USB Structure pointer; USB PMA #define USB ((USB_TypeDef *) USB_BASE) #define USB_PMA (0xC0008000L) typedef struct { u32 USB_addr_tx; //transmit buffer u32 USB_count_tx; // size u32 USB_addr_rx; //recieve buffer u32 USB_count_rx; // size }EP_address; /******************************************************************************/ //String descriptor typedef struct { u8 bLength; u8 bDescriptorType; u16 wLangId01; //lang ID - I support only one lang }descriptor_string; //String info descriptor typedef struct { u8 bLength; u8 bDescriptorType; u8 b1; u8 b2; u8 b3; u8 b4; u8 b5; u8 b6; u8 b7; u8 b8; u8 b9; u8 b10; u8 b11; u8 b12; u8 b13; u8 b14; u8 b15; u8 b16; u8 b17; u8 b18; u8 b19; u8 b20; u8 b21; u8 b22; u8 b23; u8 b24; u8 b25; }descriptor_stringInfo; /******************************************************************************/ //Send message via UART functions void UARTSendMessage(u8 *msg); void UARTSendHexaNumber(u16 number); void UARTSendHexaLetter(u8 letter); void UARTSendBuffer(u8* start, int length); /******************************************************************************/ //Init functions void initPeripheries(); void initClockTiming(); void initUART(); void initInterrupts(); /******************************************************************************/ //Interrupts handling void interruptUART(); void interruptUSB(); void resetUSB(); void errorUSB(); void correctUSB(); void ledInterrupt(); /******************************************************************************/ //Data functions u16 getRecievedBytesCount(int endPoint); void readInputDataIntoBuffer(int endPoint, int length); void sendDataFromBuffer(int endPoint, int length, int EPnR); void copyDataToOutputBuffer(void* data, int length); void appendDataToOutputBuffer(void* data, int start, int length); /******************************************************************************/ //Other functions int swapBytes(int number); /******************************************************************************/ // STRUCTURES - Descriptors // http://measure.feld.cvut.cz/system/files/files/cs/vyuka/predmety/A4M38KRP/descriptor.pdf // http://www.beyondlogic.org/usbnutshell/usb5.shtml#DeviceDescriptors //Device descriptor typedef struct { u8 bLength; /* device descriptor je vzdy dlouhy 18 bytu */ u8 bDescriptorType; /* pro device descriptor je 0x01 */ u16 bcdUSB; /* 0xJJMM */ u8 bDeviceClass; /* trida zarizeni - 0xFF (vendor specified), 0x00 (interface specified), jinak validni trida */ u8 bDeviceSubClass; /* podtrida */ u8 bDeviceProtocol; /* protokol */ u8 bMaxPacketSize; u16 idVendor; /* id vyrobce - nemame, zvolime */ u16 idProduct; /* id vyrobku - nemame, zvolime */ u16 bcdDevice; /* verze zarizeni, stejny format jako bcdUSB */ u8 iManufacturer; /* index vyrobce ve string descriptoru, pokud nepouzijeme, volime 0 */ u8 iProduct; /* index produktu ve string descriptoru, pokud nepouzijeme, volime 0 */ u8 iSerialNumber; /* index serioveho cisla ve string descriptoru, pokud nepouzijeme, volime 0 */ u8 bNumConfigurations; /* pocet konfiguraci */ }descriptor_device; //Configuration descriptor typedef struct { u8 bLength; u8 bDescriptorType; /* pro configuration descriptor je 0x02 */ u16 wTotalLength; /* delka konfiguracniho, interface a endpoint deskriptoru teto konfigurace */ u8 bNumInterfaces; /* pocet interfacu */ u8 bConfigurationValue; /* identifikator interfacu, bude volano v requestu set_configuration */ u8 iConfiguration; /* index string deskriptoru teto konfigurace */ u8 bmAttributes; /* osmy bit vzdy 1, sedmy bit 1 pokud ma zarizeni vlastni napajeni */ u8 bMaxPower; /* pocet mA deleno dvema, ktere chceme ze sbernice odebirat - max USB1.1 je 500 mA */ }descriptor_configuration; //Interface descriptor typedef struct { u8 bLength; /* interface descriptor je vzdy dlouhy 9 bytu */ u8 bDescriptorType; /* pro interface descriptor je 0x04 */ u8 bInterfaceNumber; /* cislo interface - od nuly */ u8 bAlternativeSetting; u8 bNumEndpoints; /* pocet endpointu - nepocita se nulovy */ u8 bInterfaceClass; u8 bInterfaceSubClass; u8 bInterfaceProtocol; u8 iInterface; /* index string descriptoru */ }descriptor_interface; //End point descriptor typedef struct { u8 bLength; /* endpoint descriptor je vzdy dlouhy 7 bytu */ u8 bDescriptorType; /* pro endpoint descriptor je 0x04 */ u8 bEndpointAddress; /* cislo endpointu a smer komunikace (nejvyssi bit) */ u8 bmAttributes; /* typ endpointu */ u16 wMaxPacketSize; /* delka bufferu daneho endpointu */ u8 bInterval; /* pro bulk nema vyznam */ }descriptor_endpoint; /******************************************************************************/ #endif