// Flash Interface Descriptor {sizeof(USB_Interface_Descriptor), // Size of this descriptor in bytes INTERFACE_DESCRIPTOR, // Interface descriptor type 0, // Interface Number 0, // Alternate Setting Number 2, // Number of endpoints in this interface 0xff, // Class code 0xff, // Subclass code 0xff, // Protocol code 5}, // Interface string index // Flash Endpoint Descriptors {{sizeof(USB_Endpoint_Descriptor), ENDPOINT_DESCRIPTOR, EP(1) | OUT_EP, BULK, 64, // 68 bytes max 0}, // not used for full speed bulk EP {sizeof(USB_Endpoint_Descriptor), ENDPOINT_DESCRIPTOR, EP(2) | IN_EP, BULK, 64, // 68 bytes max 0}} // not used for full speed bulk EP }; const USB_Application_Composite_Descriptor application_cfg = { // Configuration Descriptor {sizeof(USB_Configuration_Descriptor), // Size of this descriptor in bytes
.flags = IORESOURCE_IRQ, }, }; #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \ [idx] = { \ .name = nam, \ .index = idx, \ .fifo_size = maxpkt, \ .nr_banks = maxbk, \ .can_dma = dma, \ .can_isoc = isoc, \ } static struct usba_ep_data usba_udc_ep[] __initdata = { EP("ep0", 0, 64, 1, 0, 0), EP("ep1", 1, 1024, 2, 1, 1), EP("ep2", 2, 1024, 2, 1, 1), EP("ep3", 3, 1024, 3, 1, 0), EP("ep4", 4, 1024, 3, 1, 0), EP("ep5", 5, 1024, 3, 1, 1), EP("ep6", 6, 1024, 3, 1, 1), }; #undef EP /* * pdata doesn't have room for any endpoints, so we need to * append room for the ones we need right after it. */ static struct {
void USBHAL::usbisr(void) { // Start of frame if (LPC_USB->INTSTAT & FRAME_INT) { // Clear SOF interrupt LPC_USB->INTSTAT = FRAME_INT; // SOF event, read frame number SOF(FRAME_NR(LPC_USB->INFO)); } // Device state if (LPC_USB->INTSTAT & DEV_INT) { LPC_USB->INTSTAT = DEV_INT; if (LPC_USB->DEVCMDSTAT & DSUS_C) { // Suspend status changed LPC_USB->DEVCMDSTAT = devCmdStat | DSUS_C; if((LPC_USB->DEVCMDSTAT & DSUS) != 0) { suspendStateChanged(1); } } if (LPC_USB->DEVCMDSTAT & DRES_C) { // Bus reset LPC_USB->DEVCMDSTAT = devCmdStat | DRES_C; suspendStateChanged(0); // Disable endpoints > 0 disableEndpoints(); // Bus reset event busReset(); } } // Endpoint 0 if (LPC_USB->INTSTAT & EP(EP0OUT)) { // Clear EP0OUT/SETUP interrupt LPC_USB->INTSTAT = EP(EP0OUT); // Check if SETUP if (LPC_USB->DEVCMDSTAT & SETUP) { // Clear Active and Stall bits for EP0 // Documentation does not make it clear if we must use the // EPSKIP register to achieve this, Fig. 16 and NXP reference // code suggests we can just clear the Active bits - check with // NXP to be sure. ep[0].in[0] = 0; ep[0].out[0] = 0; // Clear EP0IN interrupt LPC_USB->INTSTAT = EP(EP0IN); // Clear SETUP (and INTONNAK_CI/O) in device status register LPC_USB->DEVCMDSTAT = devCmdStat | SETUP; // EP0 SETUP event (SETUP data received) EP0setupCallback(); } else { // EP0OUT ACK event (OUT data received) EP0out(); } } if (LPC_USB->INTSTAT & EP(EP0IN)) { // Clear EP0IN interrupt LPC_USB->INTSTAT = EP(EP0IN); // EP0IN ACK event (IN data sent) EP0in(); } for (uint8_t num = 2; num < 5*2; num++) { if (LPC_USB->INTSTAT & EP(num)) { LPC_USB->INTSTAT = EP(num); epComplete |= EP(num); if ((instance->*(epCallback[num - 2]))()) { epComplete &= ~EP(num); } } } }
bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options) { uint32_t tmpEpRamPtr; if (endpoint > LAST_PHYSICAL_ENDPOINT) { return false; } // Not applicable to the control endpoints if ((endpoint==EP0IN) || (endpoint==EP0OUT)) { return false; } // Allocate buffers in USB RAM tmpEpRamPtr = epRamPtr; // Must be 64 byte aligned tmpEpRamPtr = ROUND_UP_TO_MULTIPLE(tmpEpRamPtr, 64); if ((tmpEpRamPtr + maxPacket) > (USB_RAM_START + USB_RAM_SIZE)) { // Out of memory return false; } // Allocate first buffer endpointState[endpoint].buffer[0] = tmpEpRamPtr; tmpEpRamPtr += maxPacket; if (!(options & SINGLE_BUFFERED)) { // Must be 64 byte aligned tmpEpRamPtr = ROUND_UP_TO_MULTIPLE(tmpEpRamPtr, 64); if ((tmpEpRamPtr + maxPacket) > (USB_RAM_START + USB_RAM_SIZE)) { // Out of memory return false; } // Allocate second buffer endpointState[endpoint].buffer[1] = tmpEpRamPtr; tmpEpRamPtr += maxPacket; } // Commit to this USB RAM allocation epRamPtr = tmpEpRamPtr; // Remaining endpoint state values endpointState[endpoint].maxPacket = maxPacket; endpointState[endpoint].options = options; // Enable double buffering if required if (options & SINGLE_BUFFERED) { LPC_USB->EPBUFCFG &= ~EP(endpoint); } else { // Double buffered LPC_USB->EPBUFCFG |= EP(endpoint); } // Enable interrupt LPC_USB->INTEN |= EP(endpoint); // Enable endpoint unstallEndpoint(endpoint); return true; }
EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) { uint32_t flags = 0; uint32_t bf; // Validate parameters if (data == NULL) { return EP_INVALID; } if (endpoint > LAST_PHYSICAL_ENDPOINT) { return EP_INVALID; } if ((endpoint==EP0IN) || (endpoint==EP0OUT)) { return EP_INVALID; } if (size > endpointState[endpoint].maxPacket) { return EP_INVALID; } if (LPC_USB->EPBUFCFG & EP(endpoint)) { // Double buffered if (LPC_USB->EPINUSE & EP(endpoint)) { bf = 1; } else { bf = 0; } } else { // Single buffered bf = 0; } // Check if already active if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_A) { return EP_INVALID; } // Check if stalled if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_S) { return EP_STALLED; } // Copy data to USB RAM USBMemCopy((uint8_t *)endpointState[endpoint].buffer[bf], data, size); // Add options if (endpointState[endpoint].options & RATE_FEEDBACK_MODE) { flags |= CMDSTS_RF; } if (endpointState[endpoint].options & ISOCHRONOUS) { flags |= CMDSTS_T; } // Add transfer ep[PHY_TO_LOG(endpoint)].in[bf] = CMDSTS_ADDRESS_OFFSET( \ endpointState[endpoint].buffer[bf]) \ | CMDSTS_NBYTES(size) | CMDSTS_A | flags; return EP_PENDING; }
USBHAL::USBHAL(void) { NVIC_DisableIRQ(USB_IRQ); // fill in callback array epCallback[0] = &USBHAL::EP1_OUT_callback; epCallback[1] = &USBHAL::EP1_IN_callback; epCallback[2] = &USBHAL::EP2_OUT_callback; epCallback[3] = &USBHAL::EP2_IN_callback; epCallback[4] = &USBHAL::EP3_OUT_callback; epCallback[5] = &USBHAL::EP3_IN_callback; epCallback[6] = &USBHAL::EP4_OUT_callback; epCallback[7] = &USBHAL::EP4_IN_callback; #if defined(TARGET_LPC1549) /* Set USB PLL input to system oscillator */ LPC_SYSCON->USBPLLCLKSEL = 0x01; /* Setup USB PLL (FCLKIN = 12MHz) * 4 = 48MHz MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2) FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */ LPC_SYSCON->USBPLLCTRL = (0x3 | (1UL << 6)); /* Powerup USB PLL */ LPC_SYSCON->PDRUNCFG &= ~(CLK_USB); /* Wait for PLL to lock */ while(!(LPC_SYSCON->USBPLLSTAT & 0x01)); /* enable USB main clock */ LPC_SYSCON->USBCLKSEL = 0x02; LPC_SYSCON->USBCLKDIV = 1; /* Enable AHB clock to the USB block. */ LPC_SYSCON->SYSAHBCLKCTRL1 |= CLK_USB; /* power UP USB Phy */ LPC_SYSCON->PDRUNCFG &= ~(1UL << 9); /* Reset USB block */ LPC_SYSCON->PRESETCTRL1 |= (CLK_USB); LPC_SYSCON->PRESETCTRL1 &= ~(CLK_USB); #else #if defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) // USB_VBUS input with pull-down LPC_IOCON->PIO0_3 = 0x00000009; #endif // nUSB_CONNECT output LPC_IOCON->PIO0_6 = 0x00000001; // Enable clocks (USB registers, USB RAM) LPC_SYSCON->SYSAHBCLKCTRL |= CLK_USB | CLK_USBRAM; // Ensure device disconnected (DCON not set) LPC_USB->DEVCMDSTAT = 0; #endif // to ensure that the USB host sees the device as // disconnected if the target CPU is reset. wait(0.3); // Reserve space in USB RAM for endpoint command/status list // Must be 256 byte aligned usbRamPtr = ROUND_UP_TO_MULTIPLE(usbRamPtr, 256); ep = (EP_COMMAND_STATUS *)usbRamPtr; usbRamPtr += (sizeof(EP_COMMAND_STATUS) * NUMBER_OF_LOGICAL_ENDPOINTS); LPC_USB->EPLISTSTART = (uint32_t)(ep) & 0xffffff00; // Reserve space in USB RAM for Endpoint 0 // Must be 64 byte aligned usbRamPtr = ROUND_UP_TO_MULTIPLE(usbRamPtr, 64); ct = (CONTROL_TRANSFER *)usbRamPtr; usbRamPtr += sizeof(CONTROL_TRANSFER); LPC_USB->DATABUFSTART =(uint32_t)(ct) & 0xffc00000; // Setup command/status list for EP0 ep[0].out[0] = 0; ep[0].in[0] = 0; ep[0].out[1] = CMDSTS_ADDRESS_OFFSET((uint32_t)ct->setup); // Route all interrupts to IRQ, some can be routed to // USB_FIQ if you wish. LPC_USB->INTROUTING = 0; // Set device address 0, enable USB device, no remote wakeup devCmdStat = DEV_ADDR(0) | DEV_EN | DSUS; LPC_USB->DEVCMDSTAT = devCmdStat; // Enable interrupts for device events and EP0 LPC_USB->INTEN = DEV_INT | EP(EP0IN) | EP(EP0OUT) | FRAME_INT; instance = this; //attach IRQ handler and enable interrupts NVIC_SetVector(USB_IRQ, (uint32_t)&_usbisr); }
void umat_plasticity_kin_iso_CCP(const vec &Etot, const vec &DEtot, vec &sigma, mat &Lt, mat &L, vec &sigma_in, const mat &DR, const int &nprops, const vec &props, const int &nstatev, vec &statev, const double &T, const double &DT, const double &Time, const double &DTime, double &Wm, double &Wm_r, double &Wm_ir, double &Wm_d, const int &ndi, const int &nshr, const bool &start, const int &solver_type, double &tnew_dt) { UNUSED(nprops); UNUSED(nstatev); UNUSED(Time); UNUSED(DTime); UNUSED(nshr); UNUSED(tnew_dt); //From the props to the material properties double E = props(0); double nu= props(1); double alpha_iso = props(2); double sigmaY = props(3); double k=props(4); double m=props(5); double kX = props(6); //definition of the CTE tensor vec alpha = alpha_iso*Ith(); ///@brief Temperature initialization double T_init = statev(0); //From the statev to the internal variables double p = statev(1); vec EP(6); EP(0) = statev(2); EP(1) = statev(3); EP(2) = statev(4); EP(3) = statev(5); EP(4) = statev(6); EP(5) = statev(7); ///@brief a is the internal variable associated with kinematical hardening vec a = zeros(6); a(0) = statev(8); a(1) = statev(9); a(2) = statev(10); a(3) = statev(11); a(4) = statev(12); a(5) = statev(13); //Rotation of internal variables (tensors) EP = rotate_strain(EP, DR); a = rotate_strain(a, DR); ///@brief Initialization if(start) { //Elstic stiffness tensor L = L_iso(E, nu, "Enu"); T_init = T; vec vide = zeros(6); sigma = vide; EP = vide; a = vide; p = 0.; Wm = 0.; Wm_r = 0.; Wm_ir = 0.; Wm_d = 0.; } //Additional parameters and variables vec X = kX*(a%Ir05()); double Hp=0.; double dHpdp=0.; if (p > iota) { dHpdp = m*k*pow(p, m-1); Hp = k*pow(p, m); } else { dHpdp = 0.; Hp = 0.; } //Variables values at the start of the increment vec sigma_start = sigma; vec EP_start = EP; vec a_start = a; vec X_start = X; double A_p_start = -Hp; vec A_a_start = -X_start; //Variables required for the loop vec s_j = zeros(1); s_j(0) = p; vec Ds_j = zeros(1); vec ds_j = zeros(1); ///Elastic prediction - Accounting for the thermal prediction vec Eel = Etot + DEtot - alpha*(T+DT-T_init) - EP; sigma = el_pred(L, Eel, ndi); //Define the plastic function and the stress vec Phi = zeros(1); mat B = zeros(1,1); vec Y_crit = zeros(1); double dPhidp=0.; vec dPhida = zeros(6); vec dPhidsigma = zeros(6); double dPhidtheta = 0.; //Compute the explicit flow direction vec Lambdap = eta_stress(sigma-X); vec Lambdaa = eta_stress(sigma-X); std::vector<vec> kappa_j(1); kappa_j[0] = L*Lambdap; mat K = zeros(1,1); //Loop parameters int compteur = 0; double error = 1.; //Loop for (compteur = 0; ((compteur < maxiter_umat) && (error > precision_umat)); compteur++) { p = s_j(0); if (p > iota) { dHpdp = m*k*pow(p, m-1); Hp = k*pow(p, m); } else { dHpdp = 0.; Hp = 0.; } dPhidsigma = eta_stress(sigma-X); dPhidp = -1.*dHpdp; dPhida = -1.*kX*(eta_stress(sigma - X)%Ir05()); //compute Phi and the derivatives Phi(0) = Mises_stress(sigma-X) - Hp - sigmaY; Lambdap = eta_stress(sigma-X); Lambdaa = eta_stress(sigma-X); kappa_j[0] = L*Lambdap; K(0,0) = dPhidp + sum(dPhida%Lambdaa); B(0, 0) = -1.*sum(dPhidsigma%kappa_j[0]) + K(0,0); Y_crit(0) = sigmaY; Fischer_Burmeister_m(Phi, Y_crit, B, Ds_j, ds_j, error); s_j(0) += ds_j(0); EP = EP + ds_j(0)*Lambdap; a = a + ds_j(0)*Lambdaa; X = kX*(a%Ir05()); //the stress is now computed using the relationship sigma = L(E-Ep) Eel = Etot + DEtot - alpha*(T + DT - T_init) - EP; sigma = el_pred(L, Eel, ndi); } //Computation of the increments of variables vec Dsigma = sigma - sigma_start; vec DEP = EP - EP_start; double Dp = Ds_j[0]; vec Da = a - a_start; if (solver_type == 0) { //Computation of the tangent modulus mat Bhat = zeros(1, 1); Bhat(0, 0) = sum(dPhidsigma%kappa_j[0]) - K(0,0); vec op = zeros(1); mat delta = eye(1,1); for (int i=0; i<1; i++) { if(Ds_j[i] > iota) op(i) = 1.; } mat Bbar = zeros(1,1); for (int i = 0; i < 1; i++) { for (int j = 0; j < 1; j++) { Bbar(i, j) = op(i)*op(j)*Bhat(i, j) + delta(i,j)*(1-op(i)*op(j)); } } mat invBbar = zeros(1, 1); mat invBhat = zeros(1, 1); invBbar = inv(Bbar); for (int i = 0; i < 1; i++) { for (int j = 0; j < 1; j++) { invBhat(i, j) = op(i)*op(j)*invBbar(i, j); } } std::vector<vec> P_epsilon(1); P_epsilon[0] = invBhat(0, 0)*(L*dPhidsigma); std::vector<double> P_theta(1); P_theta[0] = dPhidtheta - sum(dPhidsigma%(L*alpha)); Lt = L - (kappa_j[0]*P_epsilon[0].t()); } else if(solver_type == 1) { sigma_in = -L*EP; } double A_p = -Hp; vec A_a = -X; double Dgamma_loc = 0.5*sum((sigma_start+sigma)%DEP) + 0.5*(A_p_start + A_p)*Dp + 0.5*sum((A_a_start + A_a)%Da); //Computation of the mechanical and thermal work quantities Wm += 0.5*sum((sigma_start+sigma)%DEtot); Wm_r += 0.5*sum((sigma_start+sigma)%(DEtot-DEP)) - 0.5*sum((A_a_start + A_a)%Da); Wm_ir += -0.5*(A_p_start + A_p)*Dp; Wm_d += Dgamma_loc; ///@brief statev evolving variables //statev statev(0) = T_init; statev(1) = p; statev(2) = EP(0); statev(3) = EP(1); statev(4) = EP(2); statev(5) = EP(3); statev(6) = EP(4); statev(7) = EP(5); statev(8) = a(0); statev(9) = a(1); statev(10) = a(2); statev(11) = a(3); statev(12) = a(4); statev(13) = a(5); }