int main() { // Make SSbar be an output so it does not interfere with SPI communication. set_digital_output(IO_B4, LOW); // Set the mode to SVP_MODE_ANALOG so we can get analog readings on line D/RX. svp_set_mode(SVP_MODE_ANALOG); while(1) { clear(); // Erase the LCD. if (usb_configured()) { // Connected to USB and the computer recognizes the device. print("USB"); } else if (usb_power_present()) { // Connected to USB. print("usb"); } if (usb_suspend()) { // Connected to USB, in the Suspend state. lcd_goto_xy(4,0); print("SUS"); } if (dtr_enabled()) { // The DTR virtual handshaking line is 1. // This often means that a terminal program is conencted to the // Pololu Orangutan SVP USB Communication Port. lcd_goto_xy(8,0); print("DTR"); } if (rts_enabled()) { // The RTS virtual handshaking line is 1. lcd_goto_xy(12,0); print("RTS"); } // Display an analog reading from channel D, in millivolts. lcd_goto_xy(0,1); print("Channel D: "); print_long(analog_read_millivolts(CHANNEL_D)); // Wait for 100 ms, otherwise the LCD would flicker. delay_ms(100); } }
void idle_mode(void) { u8 key; //deg_str("idle_mode \n"); //dac_out_select(DAC_MUSIC, 0); //clear_all_event(); dac_mute_control(1,1); #ifdef PLAY_STATUS_LED_FUNC set_play_status_led_spark(PLED_OFF); #endif KT_AMFMStandby(); usb_suspend(); flush_all_msg(); disp_port(MENU_POWER_OFF); input_number_en=0; vol_change_en=0; #ifdef DEFAULT_VOL sys_main_vol=DEFAULT_VOL; #endif delay_10ms(20); #ifdef SYS_SOFT_WARE_GOIN_STANDBY if(sys_pwr_flag==0){ put_msg_fifo(MSG_SYS_CORE_SLEEP); } #endif while (1) { key = app_get_msg(); switch (key) { #ifdef SYS_SOFT_WARE_GOIN_STANDBY case MSG_SYS_CORE_SLEEP: core_power_off(); break; #endif case MSG_CHANGE_WORK_MODE: clear_all_event(); flush_all_msg(); return; case MSG_MUSIC_NEW_DEVICE_IN: //有新设备接入 break; default: ap_handle_hotkey(key); break; } } }
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 }
/*----------------------------------------------------------------------------*/ void decode_play(void) { #ifdef MP3_UART_ENABLE sys_printf(" SYS GO IN DECODE MODE"); #endif Mute_Ext_PA(MUTE); disp_play_filenum_timer=10; folder_select=0; folder_mode_select=0; rtc_setting=0; disp_scenario = DISP_NORMAL; Disp_Con(DISP_SCAN_DISK); sysclock_div2(1); #ifndef NO_SD_DECODE_FUNC sd_speed_init(0, 50); #endif decodeclock_div2(DECODE_CLK_DIV2); //decoder分频,可以减少功耗 music_info_init(); dsp_hi_pro(); decodeint_hi_pro(); device_active = 0; put_msg_lifo(SEL_GIVEN_DEVICE_GIVEN_FILE); set_max_vol(MAX_ANALOG_VOL-DECODE_ANALOG_VOL_CUT, MAX_DIGITAL_VOL); //设置Music模式的音量上限 //suspend_sdmmc(); music_play(); Mute_Ext_PA(MUTE); #ifdef ADKEY_SELECT_MODE mode_switch_protect_bit=1; #endif disp_scenario = DISP_NORMAL; folder_select=0; folder_mode_select=0; stop_decode(); #ifdef USE_USB_PROG_PLAY_MODE usb_prog_mode_cls(); #endif #if(MEMORY_STYLE != USE_DEVICE) usb_suspend(); //Entered Suspend mode #endif write_playtime(&playpoint_time); //记录断点信息(EEPROM) main_vol_set(0, CHANGE_VOL_NO_MEM); }
void idle_mode(void) { u8 key; //deg_str("idle_mode \n"); //dac_out_select(DAC_MUSIC, 0); //clear_all_event(); KT_AMFMStandby(); usb_suspend(); flush_all_msg(); disp_port(MENU_POWER_OFF); input_number_en=0; vol_change_en=0; SYS_POWER_OFF(); LCD_BACKLIGHT_OFF(); //core_power_off(); while (1) { key = app_get_msg(); switch (key) { case MSG_POWER: work_mode = MUSIC_MODE; case MSG_CHANGE_WORK_MODE: clear_all_event(); flush_all_msg(); irkey_activated =0; sys_pwr_flag =1; return; case MSG_MUSIC_NEW_DEVICE_IN: //有新设备接入 //put_msg_lifo(MSG_CHANGE_WORK_MODE); break; default: //ap_handle_hotkey(key); break; } } }
/*----------------------------------------------------------------------------*/ void music_decode(void) { sys_printf(" ------------------------------------>music_decode "); #ifdef AC_SLAVE_ENABLE DSA_init(); #endif dev_remov_timer=0; play_mode = REPEAT_OFF; disk_toc_ok=0; dev_invalid=0; input_number_en = 1; //允许数字输入功能 vol_change_en=1; key_voice_en=1; main_menu = MENU_MUSIC_MAIN; dec_msg = get_dec_msg_ptr(); fat_ptr1.buf = win_buffer; SYSTEM_CLK_DIV1(); //sd_speed_init(0, 100); key_table_sel(0); flush_all_msg(); music_info_init(); set_max_vol(MAX_ANOLOG_VOL,MAX_DIGITAL_VOL);///设置最大音量 if(DSA_SEL_DEV==DEVICE_SDMMC0){ given_device = DEVICE_SDMMC0; } else if(DSA_SEL_DEV==DEVICE_UDISK){ given_device = DEVICE_UDISK; } //put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE); music_play(); //delay_10ms(3); stop_decode(); usb_suspend(); //Entered Suspend Mode key_voice_en=0; main_vol_set(0, CHANGE_VOL_NO_MEM); given_device = NO_DEVICE; }
void sys_sleep_mode() { #if 1 usb_suspend(); //Entered Suspend mode suspend_sdmmc(); dac_mute_control(1,1); #if 1 DACCON1 |= BIT(6); //DAC高阻 CLKGAT |= BIT(5); //SDCLK关闭 //CLKCON |= (BIT(3)); //CLKCON |= (BIT(6)); //Delay(600); #endif rc_pll_delay(); //Delay(200); sysclock_div2(1); #endif }
static int usb_dev_poweroff(struct device *dev) { return usb_suspend(dev, PMSG_HIBERNATE); }
static int usb_dev_freeze(struct device *dev) { return usb_suspend(dev, PMSG_FREEZE); }
static int usb_dev_suspend(struct device *dev) { return usb_suspend(dev, PMSG_SUSPEND); }
void platform_isr_usb (void) { /// Check if the setup interrupt is pending. We need to check it before other /// interrupts, to work around that the Setup Int has lower priority then Input /// Endpoint 0 //ot_u8 bWakeUp = FALSE; if (USBIFG & SETUPIFG) { //bWakeUp = usbisr_setuppkt(); usbisr_setuppkt(); USBIFG &= ~SETUPIFG; // clear the interrupt bit } switch (__even_in_range(USBVECINT, USBVECINT_OUTPUT_ENDPOINT7)) { case USBVECINT_NONE: break; case USBVECINT_PWR_DROP: //__no_operation(); break; case USBVECINT_PLL_LOCK: break; case USBVECINT_PLL_SIGNAL: break; # if (USBEVT_MASK & USBEVT_CLOCKFAULT) case USBVECINT_PLL_RANGE: usbevt_pllerror(); break; # endif case USBVECINT_PWR_VBUSOn: usbisr_vbuson(); # if (USBEVT_MASK & USBEVT_VBUSON) usbevt_vbuson(); # endif break; case USBVECINT_PWR_VBUSOff: usbisr_vbusoff(); # if (USBEVT_MASK & USBEVT_VBUSOFF) usbevt_vbusoff(); # endif break; case USBVECINT_USB_TIMESTAMP: break; case USBVECINT_INPUT_ENDPOINT0: usbisr_ep0in(); break; case USBVECINT_OUTPUT_ENDPOINT0: //bWakeUp = usbisr_ep0out(); usbisr_ep0out(); break; case USBVECINT_RSTR: usb_reset(); # if (USBEVT_MASK & USBEVT_RESET) usbevt_reset(); # endif break; case USBVECINT_SUSR: usb_suspend(); # if (USBEVT_MASK & USBEVT_SUSPEND) usbevt_suspend(); # endif break; case USBVECINT_RESR: usb_resume(); # if (USBEVT_MASK & USBEVT_RESUME) usbevt_resume(); # endif //bWakeUp = TRUE; //Always wake on resume break; case USBVECINT_SETUP_PACKET_RECEIVED: // NAK both IEP and OEP enpoints dblock_ep0.bIEPBCNT = EPBCNT_NAK; dblock_ep0.bOEPBCNT = EPBCNT_NAK; //bWakeUp = usbisr_setuppkt(); usbisr_setuppkt(); break; case USBVECINT_STPOW_PACKET_RECEIVED: break; case USBVECINT_INPUT_ENDPOINT1: break; case USBVECINT_INPUT_ENDPOINT2: //bWakeUp = CdcToHostFromBuffer(CDC0_INTFNUM); usbcdc_transfer_buf2host(CDC0_INTFNUM); break; case USBVECINT_INPUT_ENDPOINT3: break; case USBVECINT_INPUT_ENDPOINT4: break; case USBVECINT_INPUT_ENDPOINT5: break; case USBVECINT_INPUT_ENDPOINT6: break; case USBVECINT_INPUT_ENDPOINT7: break; case USBVECINT_OUTPUT_ENDPOINT1: break; case USBVECINT_OUTPUT_ENDPOINT2: //bWakeUp = CdcToBufferFromHost(CDC0_INTFNUM); usbcdc_transfer_host2buf(CDC0_INTFNUM); break; case USBVECINT_OUTPUT_ENDPOINT3: break; case USBVECINT_OUTPUT_ENDPOINT4: break; case USBVECINT_OUTPUT_ENDPOINT5: break; case USBVECINT_OUTPUT_ENDPOINT6: break; case USBVECINT_OUTPUT_ENDPOINT7: break; default: break; } //return bWakeUp; }
/* These routines rely on the bus (pci, platform, etc) * to handle powerdown and wakeup, and currently also on * transceivers that don't need any software attention to set up * the right sort of wakeup. * * They're also used for turning on/off the port when doing OTG. */ static int ehci_fsl_drv_suspend(struct platform_device *pdev, pm_message_t message) { struct usb_hcd *hcd = platform_get_drvdata(pdev); struct ehci_hcd *ehci = hcd_to_ehci(hcd); struct usb_device *roothub = hcd->self.root_hub; u32 port_status; struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; printk(KERN_DEBUG "USB Host suspend begins\n"); /* Only handles OTG mode switch event, system suspend event will be done in bus suspend */ if (pdata->pmflags == 0) { printk(KERN_DEBUG "%s, pm event \n", __func__); if (!host_can_wakeup_system(pdev)) { int mask; /* Need open clock for register access */ if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) fsl_usb_clk_gate(hcd->self.controller->platform_data, true); mask = ehci_readl(ehci, &ehci->regs->intr_enable); mask &= ~STS_PCD; ehci_writel(ehci, mask, &ehci->regs->intr_enable); usb_host_set_wakeup(hcd->self.controller, false); fsl_usb_clk_gate(hcd->self.controller->platform_data, false); } return 0; } /* only the otg host can go here */ /* wait for all usb device on the hcd dettached */ usb_lock_device(roothub); if (roothub->children[0] != NULL) { int old = hcd->self.is_b_host; printk(KERN_DEBUG "will resume roothub and its children\n"); hcd->self.is_b_host = 0; /* resume the roothub, so that it can test the children is disconnected */ if (roothub->state == USB_STATE_SUSPENDED) usb_resume(&roothub->dev, PMSG_USER_SUSPEND); /* we must do unlock here, the hubd thread will hold the same lock * here release the lock, so that the hubd thread can process the usb * disconnect event and set the children[0] be NULL, or there will be * a deadlock */ usb_unlock_device(roothub); while (roothub->children[0] != NULL) msleep(1); usb_lock_device(roothub); hcd->self.is_b_host = old; } usb_unlock_device(roothub); if (!(hcd->state & HC_STATE_SUSPENDED)) { printk(KERN_DEBUG "will suspend roothub and its children\n"); usb_lock_device(roothub); usb_suspend(&roothub->dev, PMSG_USER_SUSPEND); usb_unlock_device(roothub); } if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { fsl_usb_clk_gate(hcd->self.controller->platform_data, true); set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); } port_status = ehci_readl(ehci, &ehci->regs->port_status[0]); /* save EHCI registers */ pdata->pm_command = ehci_readl(ehci, &ehci->regs->command); pdata->pm_command &= ~CMD_RUN; pdata->pm_status = ehci_readl(ehci, &ehci->regs->status); pdata->pm_intr_enable = ehci_readl(ehci, &ehci->regs->intr_enable); pdata->pm_frame_index = ehci_readl(ehci, &ehci->regs->frame_index); pdata->pm_segment = ehci_readl(ehci, &ehci->regs->segment); pdata->pm_frame_list = ehci_readl(ehci, &ehci->regs->frame_list); pdata->pm_async_next = ehci_readl(ehci, &ehci->regs->async_next); pdata->pm_configured_flag = ehci_readl(ehci, &ehci->regs->configured_flag); pdata->pm_portsc = ehci_readl(ehci, &ehci->regs->port_status[0]); /* clear the W1C bits */ pdata->pm_portsc &= cpu_to_hc32(ehci, ~PORT_RWC_BITS); /* clear PHCD bit */ pdata->pm_portsc &= ~PORT_PTS_PHCD; usb_host_set_wakeup(hcd->self.controller, true); fsl_usb_lowpower_mode(pdata, true); if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); fsl_usb_clk_gate(hcd->self.controller->platform_data, false); } pdata->pmflags = 0; printk(KERN_DEBUG "host suspend ends\n"); return 0; }
void __irq_usb_lp_can_rx0(void) { if (CAN1->enabled) { can_rx_irq_handler(); return; } uint16 istr = USB_BASE->ISTR; /* Use USB_ISR_MSK to only include code for bits we care about. */ #if (USB_ISR_MSK & USB_ISTR_RESET) if (istr & USB_ISTR_RESET & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_RESET; pProperty->Reset(); } #endif #if (USB_ISR_MSK & USB_ISTR_PMAOVR) if (istr & ISTR_PMAOVR & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_PMAOVR; } #endif #if (USB_ISR_MSK & USB_ISTR_ERR) if (istr & USB_ISTR_ERR & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_ERR; } #endif #if (USB_ISR_MSK & USB_ISTR_WKUP) if (istr & USB_ISTR_WKUP & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_WKUP; usb_resume(RESUME_EXTERNAL); } #endif #if (USB_ISR_MSK & USB_ISTR_SUSP) if (istr & USB_ISTR_SUSP & USBLIB->irq_mask) { /* check if SUSPEND is possible */ if (SUSPEND_ENABLED) { usb_suspend(); } else { /* if not possible then resume after xx ms */ usb_resume(RESUME_LATER); } /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ USB_BASE->ISTR = ~USB_ISTR_SUSP; } #endif #if (USB_ISR_MSK & USB_ISTR_SOF) if (istr & USB_ISTR_SOF & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_SOF; } #endif #if (USB_ISR_MSK & USB_ISTR_ESOF) if (istr & USB_ISTR_ESOF & USBLIB->irq_mask) { USB_BASE->ISTR = ~USB_ISTR_ESOF; /* resume handling timing is made with ESOFs */ usb_resume(RESUME_ESOF); /* request without change of the machine state */ } #endif /* * Service the correct transfer interrupt. */ #if (USB_ISR_MSK & USB_ISTR_CTR) if (istr & USB_ISTR_CTR & USBLIB->irq_mask) { dispatch_ctr_lp(); } #endif }