sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) { size_t wsz; void *wsp; syssts_t sts; thread_t *tp; (void)name; wsz = THD_WORKING_AREA_SIZE(stacksize); wsp = chCoreAlloc(wsz); if (wsp == NULL) return NULL; #if CH_DBG_FILL_THREADS == TRUE _thread_memfill((uint8_t *)wsp, (uint8_t *)wsp + sizeof(thread_t), CH_DBG_THREAD_FILL_VALUE); _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + wsz, CH_DBG_STACK_FILL_VALUE); #endif sts = chSysGetStatusAndLockX(); tp = chThdCreateI(wsp, wsz, prio, (tfunc_t)thread, arg); chRegSetThreadNameX(tp, name); chThdStartI(tp); chSysRestoreStatusX(sts); return (sys_thread_t)tp; }
/** * @brief Resumes a thread created with @p chThdCreateI(). * * @param[in] tp pointer to the thread * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * * @api */ thread_t *chThdStart(thread_t *tp) { chSysLock(); tp = chThdStartI(tp); chSysUnlock(); return tp; }
/** * @brief Configures and activates the USB peripheral. * @note Starting the OTG cell can be a slow operation carried out with * interrupts disabled, perform it before starting time-critical * operations. * * @param[in] usbp pointer to the @p USBDriver object * * @notapi */ void usb_lld_start(USBDriver *usbp) { stm32_otg_t *otgp = usbp->otg; if (usbp->state == USB_STOP) { /* Clock activation.*/ #if STM32_USB_USE_OTG1 if (&USBD1 == usbp) { /* OTG FS clock enable and reset.*/ rccEnableOTG_FS(FALSE); rccResetOTG_FS(); /* Enables IRQ vector.*/ nvicEnableVector(STM32_OTG1_NUMBER, STM32_USB_OTG1_IRQ_PRIORITY); } #endif #if STM32_USB_USE_OTG2 if (&USBD2 == usbp) { /* OTG HS clock enable and reset.*/ rccEnableOTG_HS(FALSE); rccResetOTG_HS(); /* Workaround for the problem described here: http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=1798 */ rccDisableOTG_HSULPI(TRUE); /* Enables IRQ vector.*/ nvicEnableVector(STM32_OTG2_NUMBER, STM32_USB_OTG2_IRQ_PRIORITY); } #endif usbp->txpending = 0; /* - Forced device mode. - USB turn-around time = TRDT_VALUE. - Full Speed 1.1 PHY.*/ otgp->GUSBCFG = GUSBCFG_FDMOD | GUSBCFG_TRDT(TRDT_VALUE) | GUSBCFG_PHYSEL; /* 48MHz 1.1 PHY.*/ otgp->DCFG = 0x02200000 | DCFG_DSPD_FS11; /* PHY enabled.*/ otgp->PCGCCTL = 0; /* Internal FS PHY activation.*/ #if defined(BOARD_OTG_NOVBUSSENS) otgp->GCCFG = GCCFG_NOVBUSSENS | GCCFG_VBUSASEN | GCCFG_VBUSBSEN | GCCFG_PWRDWN; #else otgp->GCCFG = GCCFG_VBUSASEN | GCCFG_VBUSBSEN | GCCFG_PWRDWN; #endif /* Soft core reset.*/ otg_core_reset(usbp); /* Interrupts on TXFIFOs half empty.*/ otgp->GAHBCFG = 0; /* Endpoints re-initialization.*/ otg_disable_ep(usbp); /* Clear all pending Device Interrupts, only the USB Reset interrupt is required initially.*/ otgp->DIEPMSK = 0; otgp->DOEPMSK = 0; otgp->DAINTMSK = 0; if (usbp->config->sof_cb == NULL) otgp->GINTMSK = GINTMSK_ENUMDNEM | GINTMSK_USBRSTM /*| GINTMSK_USBSUSPM | GINTMSK_ESUSPM |*/; else otgp->GINTMSK = GINTMSK_ENUMDNEM | GINTMSK_USBRSTM /*| GINTMSK_USBSUSPM | GINTMSK_ESUSPM */ | GINTMSK_SOFM; otgp->GINTSTS = 0xFFFFFFFF; /* Clears all pending IRQs, if any. */ #if defined(_CHIBIOS_RT_) /* Creates the data pump thread. Note, it is created only once.*/ if (usbp->tr == NULL) { usbp->tr = chThdCreateI(usbp->wa_pump, sizeof usbp->wa_pump, STM32_USB_OTG_THREAD_PRIO, usb_lld_pump, usbp); chThdStartI(usbp->tr); chSchRescheduleS(); } #endif /* Global interrupts enable.*/ otgp->GAHBCFG |= GAHBCFG_GINTMSK; } }