/** * @file ltcusb.h * @brief Library for USB controller. * @note * * ------------------------------------------------------------------ Copyright (c) 2023 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE. IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ */ #ifndef INCLUDE_LTCUSB_H_ #define INCLUDE_LTCUSB_H_ #pragma pack(1) #include #include #include "ltcusb_raw_rw.h" #include "ltcusb_regs.h" #include "ltcusb_regs_offsets.h" #include "ltcusb_regs_ops.h" #include "ltcusb_data_types.h" #include "GenMac.h" #include "request_fifo.h" #include "event_fifo.h" #include /* RISC V Addresses */ #define EVENT_FIFO_ADDR_RV 0x00200000 #define TRB_FIFO_ADDR_RV 0x00300000 #define REQ_FIFO_ADDR_RV 0x00400000 #define DESC_FIFO_ADDR_RV 0x00500000 /* USB23 Addresses */ #define EVENT_FIFO_ADDR_USB23 0x00000010 #define TRB_FIFO_ADDR_USB23 0x00001000 #define REQ_FIFO_ADDR_USB23 0x0004ff00 #define DESC_FIFO_ADDR_USB23 0x00050000 #define BULK_ADDRESS_USB23 0x00060000 #define CONTROL_ADDRESS_USB23 0x00070000 #define INTERRUPT_ADDRESS_USB23 0x00080000 /* Size of Bulk and Interrupt TRBs */ #define INTERRUPT_IN_HS_DATA_SIZE 0x400 #define SS_DATA_SIZE 0x400 #define INTERRUPT_IN_FS_DATA_SIZE 0x40 #define INTERRUPT_OUT_HS_DATA_SIZE 0x400 #define INTERRUPT_OUT_FS_DATA_SIZE 0x40 #define BULK_IN_HS_DATA_SIZE 0x200 #define BULK_IN_FS_DATA_SIZE 0x40 #define BULK_OUT_HS_DATA_SIZE 0x200 #define BULK_OUT_FS_DATA_SIZE 0x40 #define EVENT_FIFO_SIZE 0x400 /** * @brief Flag to handle Interrupt */ extern uint32_t g_request_interrupt_flag; /** * @brief To handle Initialization of Remote WakeUp */ extern uint32_t g_initiate_remote_wakeup; /** * @brief To clear Remote WakeUp */ extern uint32_t g_clear_remote_wakeup; /** * @brief Flag to handle Event */ extern uint32_t g_event_interrupt_flag; /** * @brief bconfiguration value is the wValue field value in * Set Configuration Request. The lower byte of the wValue field * specifies the desired configuration. This configuration value * must be zero or match a configuration value from a configuration * descriptor. If the configuration value is zero, the device is * placed in its Address state. The upper byte of the wValue field * is reserved. */ extern uint32_t g_bconfiguration_value; /** * @brief Suspend Mode Enable (When set, and if Suspend conditions are valid, * the USB 3.0 PHY enters Suspend mode). */ extern uint32_t g_suspend_mode_enable; /** * @brief Simulation Enable (Simulation Speed Up Factor. Program this register * to override scale-down) */ extern uint32_t g_simulation_enable; /** * @brief USB External Clock is the clock provided by the user. */ extern uint32_t g_external_clock_enable; /** * @brief USB_SPEED (Indicates the speed at which the application requires the * controller to connect) */ extern uint32_t g_usb_speed; /** * @brief Connection Speed (Indicates the speed at which the DWC_usb3 * controller has come up after speed detection) */ extern uint32_t g_connect_speed; /** * @brief To Enabe or Disable UART (Enable this to display any messages) */ extern uint32_t g_uart_enable; /** * @brief Size of the addresses available on the USB controller. */ #define USB_ADDRESS_SIZE (20UL) /** * @brief Lowest Possible address on the USB Controller. */ #define USB_ADDRESS_MIN (0x00) /** * @brief Highest Possible address on the USB controller. */ #define USB_ADDRESS_MAX ((1UL << (USB_ADDRESS_SIZE + 1UL)) - 1UL) /** * @brief Offset of the memory mapped USB controller. */ #define USB_ADDRESS_OFFSET (1UL << 20UL) /** * @brief The maximum address allocated for the ltcusb. * @note This register holds the maximum allowed address. This depends on * build type. For RISC-V this number depends on ADDRESS SIZE and on * GNU build this is a UINT64_MAX value. */ extern const uint32_t ltcusb_addr_max; /** * @brief RISC-V core frequency in Mega-Hertz. */ #define RV_FREQ_MHZ 100UL /** * @brief The synopsys id to be checked with the GSNPSID register. * @todo Correct the value. */ #define SYNOPSYS_ID 0x11223344 /** * @brief Retry count before giving up from the hardware to get any * information. */ #define RETRY_COUNT 100 /** * @brief Error when execution of command. */ #define EXECUTE_CMD_ERR 200 /**@todo add description here.*/ extern int ltcusb_init(); #define set_vid_pid(vid,pid) do{device_descriptor_data.idVendor = (vid);\ device_descriptor_data.idProduct = (pid);\ }while(0); #endif /* INCLUDE_LTCUSB_H_ */