/* * ------------------------------------------------------------------ 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. ------------------------------------------------------------------ * */ #include #include "trb_fifo.h" static inline int is_even(uint32_t value) { return ((value & 0x1))?FALSE:TRUE; } int ltcusb_trb_write(LtcUSB_TRB* trb) { uint8_t* data = (uint8_t*)trb; uint32_t* data32 = (uint32_t*)data; for(int i=0;i<4;i++) { if(ltcusb_fifo_write(TRB_FIFO_ADDR_RV, data32[i]) != 0) { return -1; } } return 0; } int TRB_control_setup() { LtcUSB_TRB control_setup_trb = {0}; control_setup_trb.BPTRL = REQ_FIFO_ADDR_USB23; control_setup_trb.BUFSIZE = 0x8; control_setup_trb.HWO = 1; control_setup_trb.LST = 1; control_setup_trb.TRBCTL = control_setup_trbctl; control_setup_trb.IOC = 1; if(ltcusb_trb_write(&control_setup_trb) !=0 ) { return -1; } DEPSTRTXFER_Par1 Depstrtxfer_par1_data = {0}; Depstrtxfer_par1_data.TDAddr_Low = TRB_FIFO_ADDR_USB23; DEPSTRTXFER_Par0 Depstrtxfer_par0_data = {0}; Depstrtxfer_par0_data.TDAddr_High = 0; if(DEPSTRTXFER_cmd(0, &Depstrtxfer_par1_data, &Depstrtxfer_par0_data) != 0) { return -2; } return 0; } int TRB_control_data2(uint32_t size_descriptor, uint32_t size_data_buffer, uint32_t descriptor_data[]) { LtcUSB_TRB control_data_trb = {0}; control_data_trb.BPTRL = DESC_FIFO_ADDR_USB23; control_data_trb.BUFSIZE = (size_descriptor & 0xFFFFFF); control_data_trb.HWO = 1; control_data_trb.LST = 1; control_data_trb.TRBCTL = control_data_trbctl; control_data_trb.IOC = 1; uint32_t rem = size_data_buffer%4; if(rem != 0) { size_data_buffer += (4-rem); } uint32_t loops = size_data_buffer / 4; if(!is_even(loops)) { size_data_buffer += 4; } size_data_buffer >>= 2; if(ltcusb_trb_write(&control_data_trb) !=0 ) { return -1; } if(descriptor_fifo_write(size_data_buffer, descriptor_data) != 0) { return -2; } DEPSTRTXFER_Par1 Depstrtxfer_par1_data = {0}; Depstrtxfer_par1_data.TDAddr_Low = TRB_FIFO_ADDR_USB23; DEPSTRTXFER_Par0 Depstrtxfer_par0_data = {0}; Depstrtxfer_par0_data.TDAddr_High = 0; if(DEPSTRTXFER_cmd(0x1, &Depstrtxfer_par1_data, &Depstrtxfer_par0_data) != 0) { return -3; } return 0; } int TRB_control_status2() { LtcUSB_TRB control_status2_trb = {0}; control_status2_trb.BPTRL = TRB_FIFO_ADDR_USB23; control_status2_trb.BUFSIZE = 0; control_status2_trb.HWO = 1; control_status2_trb.LST = 1; control_status2_trb.TRBCTL = control_status_2_trbctl; control_status2_trb.IOC = 1; if(ltcusb_trb_write(&control_status2_trb) !=0 ) { return -1; } DEPSTRTXFER_Par1 Depstrtxfer_par1_data = {0}; Depstrtxfer_par1_data.TDAddr_Low = TRB_FIFO_ADDR_USB23; DEPSTRTXFER_Par0 Depstrtxfer_par0_data = {0}; Depstrtxfer_par0_data.TDAddr_High = 0; if(DEPSTRTXFER_cmd(0x1, &Depstrtxfer_par1_data, &Depstrtxfer_par0_data) != 0) { return -2; } return 0; } int TRB_control_status3(uint32_t direction) { if(direction != ep_in) { direction = ep_out; } LtcUSB_TRB control_status3_trb = {0}; control_status3_trb.BPTRL = TRB_FIFO_ADDR_USB23; control_status3_trb.BUFSIZE = 0; control_status3_trb.HWO = 1; control_status3_trb.LST = 1; control_status3_trb.TRBCTL = control_status_3_trbctl; control_status3_trb.IOC = 1; if(ltcusb_trb_write(&control_status3_trb) !=0 ) { return -1; } DEPSTRTXFER_Par1 Depstrtxfer_par1_data = {0}; Depstrtxfer_par1_data.TDAddr_Low = TRB_FIFO_ADDR_USB23; DEPSTRTXFER_Par0 Depstrtxfer_par0_data = {0}; Depstrtxfer_par0_data.TDAddr_High = 0; if(DEPSTRTXFER_cmd(direction, &Depstrtxfer_par1_data, &Depstrtxfer_par0_data) != 0) { return -2; } return 0; }