/* * ------------------------------------------------------------------ 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 "initialization_on_setconfiguration.h" int Initialization_on_SetConfiguration(void) { /* * Write DALEPENA.Enable physical endpoints 0 & 1 by writing 0x3 to * this register. */ DALEPENA_data *dalepena = dalepena_setup(); dalepena ->USBACTEP = 0x00000003; if(dalepena_write()!=0) { return -1; } DEPCFG_Par1 DEPCFG_Par1_EP1 = {0}; DEPCFG_Par1_EP1.USB_ep_dir = 0x1; DEPCFG_Par1_EP1.USB_ep_number = 0x0; DEPCFG_Par1_EP1.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP1 = {0}; DEPCFG_Par0_EP1.config_action = modify_endpoint_state_config_action; if(g_connect_speed == super_speed_usb) { DEPCFG_Par0_EP1.maximum_packet_size = 0x200; } else { DEPCFG_Par0_EP1.maximum_packet_size = 0x40; } if(DEPCFG_cmd(0x1, 0x00000000,&DEPCFG_Par1_EP1,&DEPCFG_Par0_EP1) != 0) { return -2; } uint32_t value = 0; Command_type cmdtyp = DEPSTARTCFG_cmdtyp; BITMASK_SET(value, (cmdtyp & DEPCMD_BIT_3_0_CMDTYPE_MASK)); BIT_SET(value, DEPCMD_BIT_10_CMDACT); BIT_SET(value, DEPCMD_BIT_31_16_COMMANDPARAM); uintptr_t addr = (DEPCMD_OFFSET) | USB_ADDRESS_OFFSET; ltcusb_mem_write(addr,value); ltcusb_mem_read(addr, &value); while((BIT_CHECK(value,DEPCMD_BIT_10_CMDACT)) != FALSE) { ltcusb_mem_read(addr, &value); } /* BULK */ DEPCFG_Par1 DEPCFG_Par1_EP2 = {0}; //OUT -- EndPoint Number 1 DEPCFG_Par1_EP2.USB_ep_dir = 0x0; DEPCFG_Par1_EP2.USB_ep_number = 0x1; DEPCFG_Par1_EP2.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP2 = {0}; DEPCFG_Par0_EP2.EPType = bulk_endpoint_type; if(g_connect_speed == high_speed_usb) { DEPCFG_Par0_EP2.maximum_packet_size = 0x200; } else if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP2.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP2.maximum_packet_size = 0x400; DEPCFG_Par0_EP2.BrstSiz = 0x3; } if(DEPCFG_cmd(0x2, 0x00000000,&DEPCFG_Par1_EP2,&DEPCFG_Par0_EP2) != 0) { return -4; } DEPCFG_Par1 DEPCFG_Par1_EP3 = {0}; //IN -- EndPoint Number 1 DEPCFG_Par1_EP3.USB_ep_dir = 0x1; DEPCFG_Par1_EP3.USB_ep_number = 0x1; DEPCFG_Par1_EP3.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP3 = {0}; DEPCFG_Par0_EP3.EPType = bulk_endpoint_type; if(g_connect_speed == high_speed_usb) { DEPCFG_Par0_EP3.maximum_packet_size = 0x200; } else if (g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP3.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP3.maximum_packet_size = 0x400; DEPCFG_Par0_EP3.BrstSiz = 0x3; } DEPCFG_Par0_EP3.FIFONum = 0x1; if(DEPCFG_cmd(0x3, 0x00000000,&DEPCFG_Par1_EP3,&DEPCFG_Par0_EP3) != 0) { return -5; } DEPCFG_Par1 DEPCFG_Par1_EP4 = {0}; //OUT -- EndPoint Number 2 DEPCFG_Par1_EP4.USB_ep_dir = 0x0; DEPCFG_Par1_EP4.USB_ep_number = 0x2; DEPCFG_Par1_EP4.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP4 = {0}; DEPCFG_Par0_EP4.EPType = bulk_endpoint_type; if(g_connect_speed == high_speed_usb) { DEPCFG_Par0_EP4.maximum_packet_size = 0x200; } else if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP4.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP4.maximum_packet_size = 0x400; } if(DEPCFG_cmd(0x4, 0x00000000,&DEPCFG_Par1_EP4,&DEPCFG_Par0_EP4) != 0) { return -6; } DEPCFG_Par1 DEPCFG_Par1_EP5 = {0}; //IN -- EndPoint Number 2 DEPCFG_Par1_EP5.USB_ep_dir = 0x1; DEPCFG_Par1_EP5.USB_ep_number = 0x2; DEPCFG_Par1_EP5.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP5 = {0}; DEPCFG_Par0_EP5.EPType = bulk_endpoint_type; if(g_connect_speed == high_speed_usb) { DEPCFG_Par0_EP5.maximum_packet_size = 0x200; } else if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP5.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP5.maximum_packet_size = 0x400; } DEPCFG_Par0_EP5.FIFONum = 0x2; if(DEPCFG_cmd(0x5, 0x00000000,&DEPCFG_Par1_EP5,&DEPCFG_Par0_EP5) != 0) { return -7; } /* Isochronous */ DEPCFG_Par1 DEPCFG_Par1_EP6 = {0}; //OUT -- EndPoint Number 3 DEPCFG_Par1_EP6.USB_ep_dir = 0x0; DEPCFG_Par1_EP6.USB_ep_number = 0x3; DEPCFG_Par1_EP6.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP6 = {0}; DEPCFG_Par0_EP6.EPType = isochronous_endpoint_type; DEPCFG_Par0_EP6.maximum_packet_size = 0x400; if(DEPCFG_cmd(0x6, 0x00000000,&DEPCFG_Par1_EP6,&DEPCFG_Par0_EP6) != 0) { return -8; } DEPCFG_Par1 DEPCFG_Par1_EP7 = {0}; //IN -- EndPoint Number 3 DEPCFG_Par1_EP7.USB_ep_dir = 0x1; DEPCFG_Par1_EP7.USB_ep_number = 0x3; DEPCFG_Par1_EP7.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP7 = {0}; DEPCFG_Par0_EP7.EPType = isochronous_endpoint_type; DEPCFG_Par0_EP7.maximum_packet_size = 0x400; DEPCFG_Par0_EP7.FIFONum = 0x3; if(DEPCFG_cmd(0x7, 0x00000000,&DEPCFG_Par1_EP7,&DEPCFG_Par0_EP7) != 0) { return -9; } DEPCFG_Par1 DEPCFG_Par1_EP8 = {0}; //OUT -- EndPoint Number 4 DEPCFG_Par1_EP8.USB_ep_dir = 0x0; DEPCFG_Par1_EP8.USB_ep_number = 0x4; DEPCFG_Par1_EP8.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP8 = {0}; DEPCFG_Par0_EP8.EPType = isochronous_endpoint_type; DEPCFG_Par0_EP8.maximum_packet_size = 0x400; if(DEPCFG_cmd(0x8, 0x00000000,&DEPCFG_Par1_EP8,&DEPCFG_Par0_EP8) != 0) { return -10; } DEPCFG_Par1 DEPCFG_Par1_EP9 = {0}; //IN -- EndPoint Number 4 DEPCFG_Par1_EP9.USB_ep_dir = 0x1; DEPCFG_Par1_EP9.USB_ep_number = 0x4; DEPCFG_Par1_EP9.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP9 = {0}; DEPCFG_Par0_EP9.EPType = isochronous_endpoint_type; DEPCFG_Par0_EP9.maximum_packet_size = 0x400; DEPCFG_Par0_EP9.FIFONum = 0x4; if(DEPCFG_cmd(0x9, 0x00000000,&DEPCFG_Par1_EP9,&DEPCFG_Par0_EP9) != 0) { return -11; } /* Interrupt */ DEPCFG_Par1 DEPCFG_Par1_EP10 = {0}; //OUT -- EndPoint Number 5 DEPCFG_Par1_EP10.USB_ep_dir = 0x0; DEPCFG_Par1_EP10.USB_ep_number = 0x5; DEPCFG_Par1_EP10.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP10 = {0}; DEPCFG_Par0_EP10.EPType = interrupt_endpoint_type; if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP10.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP10.maximum_packet_size = 0x400; } if(DEPCFG_cmd(0xa, 0x00000000,&DEPCFG_Par1_EP10,&DEPCFG_Par0_EP10) != 0) { return -12; } DEPCFG_Par1 DEPCFG_Par1_EP11 = {0}; //IN -- EndPoint Number 5 DEPCFG_Par1_EP11.USB_ep_dir = 0x1; DEPCFG_Par1_EP11.USB_ep_number = 0x5; DEPCFG_Par1_EP11.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP11 = {0}; DEPCFG_Par0_EP11.EPType = interrupt_endpoint_type; if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP11.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP11.maximum_packet_size = 0x400; } DEPCFG_Par0_EP11.FIFONum = 0x5; if(DEPCFG_cmd(0xb, 0x00000000,&DEPCFG_Par1_EP11,&DEPCFG_Par0_EP11) != 0) { return -13; } DEPCFG_Par1 DEPCFG_Par1_EP12 = {0}; //OUT -- EndPoint Number 6 DEPCFG_Par1_EP12.USB_ep_dir = 0x0; DEPCFG_Par1_EP12.USB_ep_number = 0x6; DEPCFG_Par1_EP12.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP12 = {0}; DEPCFG_Par0_EP12.EPType = interrupt_endpoint_type; if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP12.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP12.maximum_packet_size = 0x400; } if(DEPCFG_cmd(0xc, 0x00000000,&DEPCFG_Par1_EP12,&DEPCFG_Par0_EP12) != 0) { return -14; } DEPCFG_Par1 DEPCFG_Par1_EP13 = {0}; //IN -- EndPoint Number 6 DEPCFG_Par1_EP13.USB_ep_dir = 0x1; DEPCFG_Par1_EP13.USB_ep_number = 0x6; DEPCFG_Par1_EP13.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP13 = {0}; DEPCFG_Par0_EP13.EPType = interrupt_endpoint_type; if(g_connect_speed == full_speed_usb) { DEPCFG_Par0_EP13.maximum_packet_size = 0x040; } else { DEPCFG_Par0_EP13.maximum_packet_size = 0x400; } DEPCFG_Par0_EP13.FIFONum = 0x6; if(DEPCFG_cmd(0xd, 0x00000000,&DEPCFG_Par1_EP13,&DEPCFG_Par0_EP13) != 0) { return -15; } if(DEPXFERCFG_cmd(0x2) != 0) { return -16; } if(DEPXFERCFG_cmd(0x3) != 0) { return -17; } if(DEPXFERCFG_cmd(0x4) != 0) { return -18; } if(DEPXFERCFG_cmd(0x5) != 0) { return -19; } if(DEPXFERCFG_cmd(0x6) != 0) { return -20; } if(DEPXFERCFG_cmd(0x7) != 0) { return -21; } if(DEPXFERCFG_cmd(0x8) != 0) { return -22; } if(DEPXFERCFG_cmd(0x9) != 0) { return -23; } if(DEPXFERCFG_cmd(0xa) != 0) { return -24; } if(DEPXFERCFG_cmd(0xb) != 0) { return -25; } if(DEPXFERCFG_cmd(0xc) != 0) { return -26; } if(DEPXFERCFG_cmd(0xd) != 0) { return -27; } /* * Write DALEPENA.Enable physical endpoints 0 & 1 by writing 0x3 to * this register. */ DALEPENA_data *dalepena_data = dalepena_setup(); dalepena_data ->USBACTEP = 0x00003fff; if(dalepena_write()!=0) { return -28; } if(event_while(ep_event_XferNotReady,0,0x1)!=0) { return -30; } if(TRB_control_status2() != 0) { return -29; } return 0; }