/* * initialization_on_setsonfiguration.c * * Created on: 27-Jul-2023 * Author: vivek */ #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; DEPCFG_Par0_EP1.maximum_packet_size = 0x40; if(DEPCFG_cmd(0x1, 0x00000000,&DEPCFG_Par1_EP1,&DEPCFG_Par0_EP1) != 0) { return -2; } if(DEPSTARTCFG_cmd(0x0) != 0) { return -3; } /* 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP2.maximum_packet_size = 0x200; } else { DEPCFG_Par0_EP2.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP3.maximum_packet_size = 0x200; } else { DEPCFG_Par0_EP3.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP4.maximum_packet_size = 0x200; } else { DEPCFG_Par0_EP4.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP5.maximum_packet_size = 0x200; } else { DEPCFG_Par0_EP5.maximum_packet_size = 0x040; } 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 = 0x040; 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 = 0x040; 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 = 0x040; 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 = 0x040; 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP10.maximum_packet_size = 0x400; } else { DEPCFG_Par0_EP10.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP11.maximum_packet_size = 0x400; } else { DEPCFG_Par0_EP11.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP12.maximum_packet_size = 0x400; } else { DEPCFG_Par0_EP12.maximum_packet_size = 0x040; } 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(Connect_Speed == high_speed_usb) { DEPCFG_Par0_EP13.maximum_packet_size = 0x400; } else { DEPCFG_Par0_EP13.maximum_packet_size = 0x040; } 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; }