void usb_on_isr(int vector, void* param) { int i; EXO* exo = param; unsigned int sta = OTG_FS_GENERAL->INTSTS; //first two most often called if ((OTG_FS_GENERAL->INTMSK & OTG_FS_GENERAL_INTMSK_RXFLVLM) && (sta & OTG_FS_GENERAL_INTSTS_RXFLVL)) { //mask interrupts, will be umasked by process after FIFO read OTG_FS_GENERAL->INTMSK &= ~OTG_FS_GENERAL_INTMSK_RXFLVLM; stm32_otg_on_isr_rx(exo); return; } for (i = 0; i < USB_EP_COUNT_MAX; ++i) if (exo->usb.in[i] != NULL && exo->usb.in[i]->io_active && (OTG_FS_DEVICE->INEP[i].INT & OTG_FS_DEVICE_ENDPOINT_INT_XFRC)) { OTG_FS_DEVICE->INEP[i].INT = OTG_FS_DEVICE_ENDPOINT_INT_XFRC; if (exo->usb.in[i]->size >= exo->usb.in[i]->io->data_size) { exo->usb.in[i]->io_active = false; iio_complete(exo->usb.device, HAL_IO_CMD(HAL_USB, IPC_WRITE), USB_EP_IN | i, exo->usb.in[i]->io); exo->usb.in[i]->io = NULL; } else stm32_otg_tx(exo, USB_EP_IN | i); return; } //rarely called if (sta & OTG_FS_GENERAL_INTSTS_ENUMDNE) { usb_enumdne(exo); OTG_FS_GENERAL->INTSTS |= OTG_FS_GENERAL_INTSTS_ENUMDNE; return; } if ((sta & OTG_FS_GENERAL_INTSTS_USBSUSP) && (OTG_FS_GENERAL->INTMSK & OTG_FS_GENERAL_INTMSK_USBSUSPM)) { usb_suspend(exo); OTG_FS_GENERAL->INTSTS |= OTG_FS_GENERAL_INTSTS_USBSUSP; return; } if (sta & OTG_FS_GENERAL_INTSTS_WKUPINT) { usb_wakeup(exo); OTG_FS_GENERAL->INTSTS |= OTG_FS_GENERAL_INTSTS_WKUPINT | OTG_FS_GENERAL_INTSTS_USBSUSP; } OTG_FS_GENERAL->OTGINT = 0xFFFFFF;// clear other request }
app_states_t app_susp_we(void) { // wdp_host_rx_setup(WDP_RX_SUSPEND); // Set up WDP low power receive mode usb_wakeup(); return APP_NORMAL; CE_LOW(); hal_nrf_set_power_mode(HAL_NRF_PWR_DOWN); // Power up radio RFCKEN = 0; // disable the radio clock // usb_wakeup(); // return APP_NORMAL; // Minimize the powerconsumption by powering down the MCU cklf_gpio_wakeup(0x0000, 0x0000); // GPIO wakeup off cklf_rtc_disable(); cklf_rtc_init(0x00, 0x1FFF); // Setup power down timeout to app. 1 s cpu_pwr_down(); // MCU goto sleep WUF = 0; // Clear WU flag return APP_SUSP_WE; }