![]() |
SyterKit 0.4.0.x
SyterKit is a bare-metal framework
|
#include "reg/reg-usb.h"

Go to the source code of this file.
Classes | |
| struct | usb_endpoint_descriptor |
| struct | usb_interface_descriptor |
| struct | usb_configuration_descriptor |
| struct | usb_device_descriptor |
| struct | usb_qualifier_descriptor |
| struct | usb_string_descriptor |
| struct | usb_generic_descriptor |
| struct | usb_device_request |
| struct | sunxi_udc |
| struct | sunxi_ubuf |
| struct | sunxi_usb_setup_req_s |
Macros | |
| #define | USB_DT_DEVICE 0x01 |
| #define | USB_DT_CONFIG 0x02 |
| #define | USB_DT_STRING 0x03 |
| #define | USB_DT_INTERFACE 0x04 |
| #define | USB_DT_ENDPOINT 0x05 |
| #define | USB_DT_DEVICE_QUALIFIER 0x06 |
| #define | USB_DT_HID (USB_TYPE_CLASS | 0x01) |
| #define | USB_DT_REPORT (USB_TYPE_CLASS | 0x02) |
| #define | USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03) |
| #define | USB_DT_HUB (USB_TYPE_CLASS | 0x09) |
| #define | USB_DT_DEVICE_SIZE 18 |
| #define | USB_DT_CONFIG_SIZE 9 |
| #define | USB_DT_INTERFACE_SIZE 9 |
| #define | USB_DT_ENDPOINT_SIZE 7 |
| #define | USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ |
| #define | USB_DT_HUB_NONVAR_SIZE 7 |
| #define | USB_DT_HID_SIZE 9 |
| #define | SUNXI_USB_DEVICE_DETECT (1) |
| #define | SUNXI_USB_DEVICE_MASS (2) |
| #define | sunxi_usb_module_init(name, state_init, state_exit, state_reset, standard_req_op, nonstandard_req_op, state_loop, dma_rx_isr, dma_tx_isr) sunxi_usb_setup_req_t setup_req_##name = {state_init, state_exit, state_reset, standard_req_op, nonstandard_req_op, state_loop, dma_rx_isr, dma_tx_isr}; |
| #define | sunxi_usb_module_reg(name) sunxi_udev_active = &setup_req_##name |
| #define | sunxi_usb_module_ext(name) extern sunxi_usb_setup_req_t setup_req_##name |
| #define | usb_get_bit8(bp, reg) (read8(reg) & (1 << (bp))) |
| #define | usb_get_bit16(bp, reg) (read16(reg) & (1 << (bp))) |
| #define | usb_get_bit32(bp, reg) (read32(reg) & (1 << (bp))) |
| #define | usb_set_bit8(bp, reg) (write8((reg), (read8(reg) | (1 << (bp))))) |
| #define | usb_set_bit16(bp, reg) (write16((reg), (read16(reg) | (1 << (bp))))) |
| #define | usb_set_bit32(bp, reg) (write32((reg), (read32(reg) | (1 << (bp))))) |
| #define | usb_clear_bit8(bp, reg) (write8((reg), (read8(reg) & (~(1 << (bp)))))) |
| #define | usb_clear_bit16(bp, reg) (write16((reg), (read16(reg) & (~(1 << (bp)))))) |
| #define | usb_clear_bit32(bp, reg) (write32((reg), (read32(reg) & (~(1 << (bp)))))) |
| #define | SUNXI_USB_REQ_SUCCESSED (0) |
| #define | SUNXI_USB_REQ_DEVICE_NOT_SUPPORTED (-1) |
| #define | SUNXI_USB_REQ_UNKNOWN_COMMAND (-2) |
| #define | SUNXI_USB_REQ_UNMATCHED_COMMAND (-3) |
| #define | SUNXI_USB_REQ_DATA_HUNGRY (-4) |
| #define | SUNXI_USB_REQ_OP_ERR (-5) |
Typedefs | |
| typedef struct sunxi_udc | sunxi_udc_t |
| typedef struct sunxi_ubuf | sunxi_ubuf_t |
| typedef struct sunxi_usb_setup_req_s | sunxi_usb_setup_req_t |
Enumerations | |
| enum | usb_device_speed { USB_SPEED_LOW , USB_SPEED_FULL , USB_SPEED_HIGH , USB_SPEED_RESERVED } |
Functions | |
| struct usb_endpoint_descriptor | __attribute__ ((packed)) |
| sunxi_usb_module_ext (SUNXI_USB_DEVICE_DETECT) | |
| sunxi_usb_module_ext (SUNXI_USB_DEVICE_MASS) | |
| void | sunxi_usb_attach_module (uint32_t device_type) |
| Attach a module to the USB controller. | |
| int | sunxi_usb_init () |
| Initialize the USB controller. | |
| void | sunxi_usb_dump (uint32_t usbc_base, uint32_t ep_index) |
| Dump the USB controller registers for a specific endpoint. | |
| void | sunxi_usb_ep_reset () |
| Reset all endpoints of the USB controller. | |
| void | sunxi_usb_irq () |
| Handle the USB interrupt. | |
| void | sunxi_usb_attach () |
| Attach the USB device to the USB controller. | |
| int | sunxi_usb_extern_loop () |
| Run the USB device state machine loop once. | |
| void | sunxi_usb_bulk_ep_reset () |
| Reset the bulk endpoints of the USB controller. | |
| int | sunxi_usb_start_recv_by_dma (void *mem_base, uint32_t length) |
| Start receiving data by DMA. | |
| void | sunxi_usb_send_setup (uint32_t length, void *buffer) |
| Send a setup packet. | |
| int | sunxi_usb_set_address (uint32_t address) |
| Set USB device address. | |
| int | sunxi_usb_send_data (void *buffer, uint32_t buffer_size) |
| Send data over USB. | |
| int | sunxi_usb_get_ep_max (void) |
| Get the maximum number of endpoints. | |
| int | sunxi_usb_get_ep_in_type (void) |
| Get the IN endpoint type. | |
| int | sunxi_usb_get_ep_out_type (void) |
| Get the OUT endpoint type. | |
| #define SUNXI_USB_DEVICE_DETECT (1) |
| #define SUNXI_USB_DEVICE_MASS (2) |
| #define sunxi_usb_module_ext | ( | name | ) | extern sunxi_usb_setup_req_t setup_req_##name |
| #define sunxi_usb_module_init | ( | name, | |
| state_init, | |||
| state_exit, | |||
| state_reset, | |||
| standard_req_op, | |||
| nonstandard_req_op, | |||
| state_loop, | |||
| dma_rx_isr, | |||
| dma_tx_isr | |||
| ) | sunxi_usb_setup_req_t setup_req_##name = {state_init, state_exit, state_reset, standard_req_op, nonstandard_req_op, state_loop, dma_rx_isr, dma_tx_isr}; |
| #define sunxi_usb_module_reg | ( | name | ) | sunxi_udev_active = &setup_req_##name |
| #define SUNXI_USB_REQ_DATA_HUNGRY (-4) |
| #define SUNXI_USB_REQ_DEVICE_NOT_SUPPORTED (-1) |
| #define SUNXI_USB_REQ_OP_ERR (-5) |
| #define SUNXI_USB_REQ_SUCCESSED (0) |
| #define SUNXI_USB_REQ_UNKNOWN_COMMAND (-2) |
| #define SUNXI_USB_REQ_UNMATCHED_COMMAND (-3) |
| #define USB_DT_CONFIG 0x02 |
| #define USB_DT_CONFIG_SIZE 9 |
| #define USB_DT_DEVICE 0x01 |
| #define USB_DT_DEVICE_QUALIFIER 0x06 |
| #define USB_DT_DEVICE_SIZE 18 |
| #define USB_DT_ENDPOINT 0x05 |
| #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ |
| #define USB_DT_ENDPOINT_SIZE 7 |
| #define USB_DT_HID (USB_TYPE_CLASS | 0x01) |
| #define USB_DT_HID_SIZE 9 |
| #define USB_DT_HUB (USB_TYPE_CLASS | 0x09) |
| #define USB_DT_HUB_NONVAR_SIZE 7 |
| #define USB_DT_INTERFACE 0x04 |
| #define USB_DT_INTERFACE_SIZE 9 |
| #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03) |
| #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02) |
| #define USB_DT_STRING 0x03 |
| #define usb_get_bit16 | ( | bp, | |
| reg | |||
| ) | (read16(reg) & (1 << (bp))) |
| #define usb_get_bit32 | ( | bp, | |
| reg | |||
| ) | (read32(reg) & (1 << (bp))) |
| #define usb_get_bit8 | ( | bp, | |
| reg | |||
| ) | (read8(reg) & (1 << (bp))) |
| typedef struct sunxi_ubuf sunxi_ubuf_t |
| typedef struct sunxi_udc sunxi_udc_t |
| typedef struct sunxi_usb_setup_req_s sunxi_usb_setup_req_t |
| enum usb_device_speed |
| struct umass_bbb_csw_t __attribute__ | ( | (packed) | ) |
| void sunxi_usb_attach | ( | ) |
Attach the USB device to the USB controller.
This function attaches the USB device to the USB controller and enters a loop to handle USB events. It continuously checks for pending USB interrupts, handles the USB interrupt by calling sunxi_usb_irq(), and then processes the USB device state by calling sunxi_udev_active->state_loop(&sunxi_ubuf) multiple times.
| none |
| void sunxi_usb_attach_module | ( | uint32_t | device_type | ) |
Attach a module to the USB controller.
This function attaches a module to the USB controller. It registers the specified USB module and switches to the specified device type. Currently, two types of devices are supported: USB device detect and USB mass storage. If an unknown device type is specified, an error message is printed.
| device_type | The type of the device to attach
|
| void sunxi_usb_bulk_ep_reset | ( | ) |
Reset the bulk endpoints of the USB controller.
This function resets the bulk endpoints of the Allwinner A64 USB controller. It configures the bulk-in and bulk-out endpoints for data transfer. The steps involved are as follows:
| none |
Dump the USB controller registers for a specific endpoint.
This function dumps the USB controller registers for a specific endpoint of the Allwinner A64 USB controller.
| usbc_base | The base address of the USB controller |
| ep_index | The index of the endpoint to dump registers for |
| void sunxi_usb_ep_reset | ( | ) |
Reset all endpoints of the USB controller.
This function resets all endpoints of the Allwinner A64 USB controller by calling the sunxi_usb_bulk_ep_reset() function to reset the bulk endpoints.
| none |
| int sunxi_usb_extern_loop | ( | ) |
Run the USB device state machine loop once.
This function runs the USB device state machine loop once by calling sunxi_udev_active->state_loop(&sunxi_ubuf) and returning the result.
| none |
| int sunxi_usb_get_ep_in_type | ( | void | ) |
Get the IN endpoint type.
This function returns the type of the IN endpoint.
| int sunxi_usb_get_ep_max | ( | void | ) |
Get the maximum number of endpoints.
This function returns the maximum number of endpoints supported by the USB controller.
| int sunxi_usb_get_ep_out_type | ( | void | ) |
Get the OUT endpoint type.
This function returns the type of the OUT endpoint.
| int sunxi_usb_init | ( | ) |
Initialize the USB controller.
This function initializes the USB controller. It first checks if it can successfully initialize the USB device, then initializes the UDC controller source and requests DMA channels for data sending and receiving. Next, it configures the USB device by setting the transfer mode and speed, configuring DMA, etc. Finally, it enables interrupts and opens the USB device.
| none |
| void sunxi_usb_irq | ( | ) |
Handle the USB interrupt.
This function is responsible for handling various USB interrupts, including RESET, RESUME, SUSPEND, DISCONNECT, SOF, endpoint 0 (EP0), and data transfers for both transmit (TX) and receive (RX) endpoints. It also handles DMA interrupts for both TX and RX endpoints.
| None |
| sunxi_usb_module_ext | ( | SUNXI_USB_DEVICE_DETECT | ) |
| sunxi_usb_module_ext | ( | SUNXI_USB_DEVICE_MASS | ) |
| int sunxi_usb_send_data | ( | void * | buffer, |
| uint32_t | buffer_size | ||
| ) |
Send data over USB.
This function sends data over USB. It sets the rx_ready_for_data flag to 0 in the sunxi_ubuf structure and calls sunxi_usb_write_fifo() to write the data to the USB FIFO.
| buffer | The buffer containing the data to send |
| buffer_size | The size of the data buffer |
| void sunxi_usb_send_setup | ( | uint32_t | length, |
| void * | buffer | ||
| ) |
Send a setup packet.
This function sends a setup packet over USB. If the length is zero, it sends a zero-length packet. Otherwise, it selects the appropriate FIFO, writes the packet to the FIFO, and calls sunxi_usb_write_complete() to handle the completion of the write operation.
| length | The length of the setup packet |
| buffer | The buffer containing the setup packet |
| int sunxi_usb_set_address | ( | uint32_t | address | ) |
Set USB device address.
This function sets the USB device address to the specified address. It updates the address value in the sunxi_udc_source structure and calls usb_device_read_data_status() to handle the status phase of the control transfer.
| address | The USB device address to set |
| int sunxi_usb_start_recv_by_dma | ( | void * | mem_base, |
| uint32_t | length | ||
| ) |
Start receiving data by DMA.
This function starts receiving data by DMA. It configures the USB controller to use DMA for receiving, flushes the cache, enables DMA transfer, and restores the active endpoint after the transfer is started.
| mem_base | The base address of the memory buffer |
| length | The length of the data to be received |
| uint8_t bAlternateSetting |
| uint16_t bcdDevice |
| uint16_t bcdUSB |
| uint8_t bConfigurationValue |
| uint8_t bDescriptorSubtype |
| uint8_t bDescriptorType |
| uint8_t bDeviceClass |
| uint8_t bDeviceProtocol |
| uint8_t bDeviceSubClass |
| uint8_t bEndpointAddress |
| uint8_t bInterfaceClass |
| uint8_t bInterfaceNumber |
| uint8_t bInterfaceProtocol |
| uint8_t bInterfaceSubClass |
| uint8_t bInterval |
| uint8_t bLength |
| uint8_t bmAttributes |
| uint8_t bMaxPacketSize0 |
| uint8_t bMaxPower |
| uint8_t bNumConfigurations |
| uint8_t bNumEndpoints |
| uint8_t bNumInterfaces |
| uint8_t breserved |
| uint8_t iConfiguration |
| uint16_t idProduct |
| uint16_t idVendor |
| uint8_t iInterface |
| uint8_t iManufacturer |
| uint16_t index |
| uint8_t iProduct |
| uint8_t iSerialNumber |
| uint16_t length |
| uint8_t request |
| uint8_t request_type |
| uint16_t value |
| uint16_t wData[0] |
| uint16_t wMaxPacketSize |
| uint16_t wTotalLength |