/*! \brief Main function. Execution starts here. * * \retval 42 Fatal error. */ int main(void) { #ifndef FREERTOS_USED Enable_global_exception(); INTC_init_interrupts(); #endif pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); init_dbg_rs232(FOSC0); pcl_configure_usb_clock(); usb_task_init(); #if USB_DEVICE_FEATURE == true device_template_task_init(); #endif #if USB_HOST_FEATURE == true host_template_task_init(); #endif #ifdef FREERTOS_USED vTaskStartScheduler(); portDBG_TRACE("FreeRTOS returned."); return 42; #else while (true) { usb_task(); #if USB_DEVICE_FEATURE == true device_template_task(); #endif #if USB_HOST_FEATURE == true host_template_task(); #endif } #endif // FREERTOS_USED }
/** * \brief UOTGHS Library Example Application entry point. * * \return 42 Fatal error. */ extern int main( void ) { /* Disable watchdog */ WDT_Disable( WDT ) ; /* UTMI parallel mode, High/Full/Low Speed */ /* UOTGCK not used in this configuration (High Speed) */ PMC->PMC_SCDR = PMC_SCDR_UOTGCK; /* USB clock register: USB Clock Input is UTMI PLL */ PMC->PMC_USB = PMC_USB_USBS; /* USBS: USB Input Clock Selection: USB Clock Input is PLLA */ /* Enable peripheral clock for UOTGHS */ PMC_EnablePeripheral(UOTGHS_IRQn); UOTGHS->UOTGHS_CTRL = 0x0; /* Enable PLL 480 MHz */ PMC->CKGR_UCKR = CKGR_UCKR_UPLLEN | CKGR_UCKR_UPLLCOUNT(0xF); /* Wait that PLL is considered locked by the PMC */ while( !(PMC->PMC_SR & PMC_SR_LOCKU) ); /* Enable peripheral clock for UOTGHS */ PMC_EnablePeripheral(UOTGHS_IRQn); /* Output example information */ printf( "-- UOTGHS Library Example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; /* UOTGHS pins */ PIO_PinConfigure( pUOTGHSPins, PIO_LISTSIZE( pUOTGHSPins ) ); if ( PIO_PinGet(&pUOTGHS_Fault) == 0 ) { TRACE_OTG("UOTGHS_Fault = 0 (active low ERROR FLAG !\r\n"); TRACE_OTG("Undervoltage, Soft Start, Overcurrent, or Overtemperature\r\n"); while(1); } /* Enable interrupt */ NVIC_EnableIRQ(UOTGHS_IRQn); /* Initialize USB task */ usb_task_init(); #if USB_DEVICE_FEATURE == ENABLED device_template_task_init(); #endif #if USB_HOST_FEATURE == ENABLED host_template_task_init(); #endif #ifdef FREERTOS_USED /* Start OS scheduler */ vTaskStartScheduler(); TRACE_OTG("FreeRTOS returned\n\r"); return 42; #else /* No OS here. Need to call each task in round-robin mode. */ while (TRUE) { usb_task(); #if USB_DEVICE_FEATURE == ENABLED device_template_task(); #endif #if USB_HOST_FEATURE == ENABLED host_template_task(); #endif } #endif /* FREERTOS_USED */ }