/* * Initialization_on_Connect_Done.c * * Created on: 01-Jun-2023 * Author: vivek */ #include "Initialization_on_Connect_Done.h" uint32_t Connect_Speed; int Initialization_onConnect_Done(void) { DEPCFG_Par1 DEPCFG_Par1_EP0 = {0}; DEPCFG_Par1_EP0.event_enable_mask = 0x5; DEPCFG_Par0 DEPCFG_Par0_EP0 = {0}; DEPCFG_Par0_EP0.config_action = modify_endpoint_state_config_action; DEPCFG_Par0_EP0.maximum_packet_size = 0x40; if(DEPCFG_cmd(0x0, 0x00000000,&DEPCFG_Par1_EP0,&DEPCFG_Par0_EP0)!=0) { return -1; } DEPCFG_Par1 DEPCFG_Par1_EP1 ={0}; DEPCFG_Par1_EP1.USB_ep_dir = 0x1; 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; } /* * Simulation Speed Up Factor. Program this register (GCTL) to * override scaledown. */ GCTL_data *gctl = gctl_setup(); /* * Table 1-17, Link waits for 8us of LFPS before it detects a valid * U2 Exit. */ gctl->U2EXIT_LFPS = 0x1; /* * Table 1-17, * Port capability direction for device configuration. */ gctl->PRTCAPDIR = 0x2; /* * Table 1-17 * If this bit is set, then device attempts three more times to * connect at SS, even if it previously failed to operate in SS * mode. For each attempt, the device checks receiver * termination eight times. */ gctl->U2RSTECN = 0x1; /* * Table 1-17, * More info from PWERDNSCALE from the document. */ gctl->PWRDNSCALE = 0x0618; if(SIM_EN) { /* * Table 1-17, Enables scale-down of all timing values except * Device mode suspend and resume. These include Speed * enumeration, HNP/SRP, and Host mode suspend and * resume. */ gctl->SCALEDOWN = 0x01; } else { gctl->SCALEDOWN = 0x0; } if(gctl_write()!=0) { return -3; } /* * Device Status Register. This register indicates the status of the device * controller with respect to USB-related events. */ DSTS_data *dsts = dsts_setup(); if(dsts_read()!=0) { return -4; } /* * Indicates the speed at which the DWC_usb3 controller has * come up after speed detection through a chirp sequence. */ Connect_Speed = dsts->CONNECTSPD; Connect_Speed = (Connect_Speed & (0x7)); // if(UART_Enable) // { // if(Connect_Speed == 0) // { // printf("H"); // } // else if(Connect_Speed == 1) // { // printf("F"); // } // else // { // printf("Error"); // } // // } return 0; }