示例#1
0
int main(void)
#endif
{
    InitializeSystem();

#if defined(USB_INTERRUPT)
    USBDeviceAttach();
#endif

    while(1)
    {
#if defined(USB_POLLING)
        // Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        // this function periodically.  This function will take care
        // of processing and responding to SETUP transactions
        // (such as during the enumeration process when you first
        // plug in).  USB hosts require that USB devices should accept
        // and process SETUP packets in a timely fashion.  Therefore,
        // when using polling, this function should be called
        // frequently (such as once about every 100 microseconds) at any
        // time that a SETUP packet might reasonably be expected to
        // be sent by the host to your device.  In most cases, the
        // USBDeviceTasks() function does not take very long to
        // execute (~50 instruction cycles) before it returns.
#endif


        // Application-specific tasks.
        // Application related code may be added here, or in the ProcessIO() function.
        ProcessIO();
    }//end while
}//end main
示例#2
0
文件: main.c 项目: iruka-/ORANGEpico
/******************************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *****************************************************************************/
int main(void)
{   
    InitializeSystem();

    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif

    while(1)
    {
        #if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        				  // this function periodically.  This function will take care
        				  // of processing and responding to SETUP transactions 
        				  // (such as during the enumeration process when you first
        				  // plug in).  USB hosts require that USB devices should accept
        				  // and process SETUP packets in a timely fashion.  Therefore,
        				  // when using polling, this function should be called 
        				  // regularly (such as once every 1.8ms or faster** [see 
        				  // inline code comments in usb_device.c for explanation when
        				  // "or faster" applies])  In most cases, the USBDeviceTasks() 
        				  // function does not take very long to execute (ex: <100 
        				  // instruction cycles) before it returns.
        #endif
    				  

		// Application-specific tasks.
		// Application related code may be added here, or in the ProcessIO() function.
        ProcessIO();        
    }//end while
}//end main
示例#3
0
/********************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();
    setup();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        //Application specific tasks
        APP_DeviceCDCBasicDemoTasks();

    }//end while
}//end main
示例#4
0
文件: main.c 项目: dacan84/u-mote
void main(void) {
    InitializeSystem();

    while (1) {
        // Comprueba el terminal que indica la conexión USB al inicio o al reset
        if (PORTBbits.RB4 == 1) {
            // Si no se ha activado el USB, lo activa
            if ((USBGetDeviceState() == DETACHED_STATE)) {
                USBDeviceAttach();
            } else {
                // Si ya se ha activado, realiza las tareas USB
                // USB Tasks
                blinkUSBStatus();
                processUSBData();
            }
        } else {
            // Si no está conectado el terminal USB, entra en modo de bajo consumo
            USBDeviceDetach();
            LATCbits.LATC0 = 0;
            OSCCONbits.IDLEN = 0;
            Sleep();
            Nop();
        }
    }//end while
}//end main
示例#5
0
/*****************************************************************************
 * void BinaryMemoryUpload(void)
 *****************************************************************************/
void BinaryMemoryUpload(void)
{
    #ifdef USE_COMM_PKT_MEDIA_USB
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
    #endif

    COMM_PKT_Init();

    while(!BinaryHandlePacket())
    {
        COMM_PKT_Update(FLASH_PROGRAMMER_COMMUNICATION_MEDIUM);

        #ifdef USE_COMM_PKT_MEDIA_USB
        #if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        				  // this function periodically.  This function will take care
        				  // of processing and responding to SETUP transactions 
        				  // (such as during the enumeration process when you first
        				  // plug in).  USB hosts require that USB devices should accept
        				  // and process SETUP packets in a timely fashion.  Therefore,
        				  // when using polling, this function should be called 
        				  // regularly (such as once every 1.8ms or faster** [see 
        				  // inline code comments in usb_device.c for explanation when
        				  // "or faster" applies])  In most cases, the USBDeviceTasks() 
        				  // function does not take very long to execute (ex: <100 
        				  // instruction cycles) before it returns.
        #endif
        #endif
    }
}
void prepareUSB(void)
{
    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.

    USBDeviceAttach(); // Activate USB Interruptions
}
示例#7
0
文件: main.c 项目: PeterLaiCCIT/regis
int main(void) {
    InitializeSystem();
    initADCDMA();

    
    #if defined(USB_INTERRUPT)
        if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE))
        {
            USBDeviceAttach();
        }
    #endif

    #if defined(USB_POLLING)
            // Check bus status and service USB interrupts.
            USBDeviceTasks();
    #endif
    while(1)
    {
        if (!ADC_DATA_READY)
            continue;
                
        ADC_DATA_READY = 0;
        
        RunFFT();

        putrsUSBUSART((char*)&fftOut[0].real);
        
        ProcessIO();
    }
    return (EXIT_SUCCESS);
}
示例#8
0
// Main program entry point
void main(void)
{   
	// Initialise and configure the PIC ready to go
    initialisePic();



	// If we are running in interrupt mode attempt to attach the USB device
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
	

	// Main processing loop
    while(1)
    {
        #if defined(USB_POLLING)
			// If we are in polling mode the USB device tasks must be processed here
			// (otherwise the interrupt is performing this task)
	        USBDeviceTasks();
        #endif
    	
    	// Process USB Commands
        processUsbCommands();  
        
        // Note: Other application specific actions can be placed here      
    }
}
示例#9
0
文件: usb_tty.c 项目: acacio1986/V2
void usb_tty_task(void *pvParameters){
    unsigned long tempo = 0;

    stack_uso_usb = uxTaskGetStackHighWaterMark( NULL );

    sinal_inicializado++;

    while(1){

        if ((TickGet() - tempo) >= (TICK_SECOND / 64)) {
            tempo = TickGet();
            usb_tty_status();

        }

        #if defined(USB_INTERRUPT)
            if (USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)){
                USBDeviceAttach();
            }
        #endif

        usb_tty_loop();

        stack_uso_usb = uxTaskGetStackHighWaterMark( NULL );
    }
}
示例#10
0
文件: main.c 项目: AleSuky/SkP32v1.1
// *--------------------------------------------------------------------------------*
int main(){
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	AD1PCFG = 0xFFFF;
	LED1_OUTPUT();
	LED2_OUTPUT();
	SW1_INPUT();
	SW2_INPUT();
	
	buttonCount = 0;
    buttonPressed = FALSE;
    stringPrinted = TRUE;
	
	USBDeviceInit();	
	while(1){
		#if defined(USB_INTERRUPT)
		if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)){
			USBDeviceAttach();
		}
		#endif
		#if defined(USB_POLLING)
			// Check bus status and service USB interrupts.
			USBDeviceTasks();
		#endif
		ProcessIO();
	}
}
示例#11
0
文件: user.c 项目: nabillo/Chargeur
/* App initialisation
 * init ADC
 * init timer 1
 * init interrupts
 */
void InitApp(void)
{
    cur_State = LIPO_ALGO_STARTED;
    strncpy(battery.battery_type,"LIPO\0",5);
    battery.charge.restore_Lowest_Voltage = 5;
    battery.number_of_cells = 1;
    battery.charge.restore_Charge_Current = 0.5;
    seconds = 0;

    OpenADC( ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_6_TAD,
            ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS,
            ADC_1ANA );
    /* open timers */
    OpenTimer1( TIMER_INT_ON &
                T1_8BIT_RW &
                T1_SOURCE_EXT &
                T1_PS_1_1 &
                T1_OSC1EN_ON &
                T1_SYNC_EXT_OFF );

    //ei();

    USBDeviceInit();            //usb_device.c
    #if defined(USB_INTERRUPT)
      USBDeviceAttach();        //usb_device.c
    #endif

    /* TODO init PI structure */
    PI.Ki = 2;
    PI.Kp = 35;
    /* TODO init analog port */
}
示例#12
0
文件: main.c 项目: jrapp01/SrDesign
int main(void)
{
    InitializeSystem();
    USBDeviceAttach();
    while(1)
    {
    }
}
示例#13
0
int32_t main(void)
{
    DDPCONbits.JTAGEN = 0; // Disable the JTAG programming port

    /*
    SYS_CFG_WAIT_STATES (configures flash wait states from system clock)
    SYS_CFG_PB_BUS (configures the PB bus from the system clock)
    SYS_CFG_PCACHE (configures the pCache if used)
    SYS_CFG_ALL (configures the flash wait states, PB bus, and pCache)*/

    /* TODO Add user clock/system configuration code if appropriate.  */
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL); 
    
    
    /*Configure Multivector Interrupt Mode.  Using Single Vector Mode
    is expensive from a timing perspective, so most applications
    should probably not use a Single Vector Mode*/
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    /* TODO <INSERT USER APPLICATION CODE HERE> */

    
    

    

    // initialise the IO pins and PWM outputs
    TRISD = 0;
    pickerBusTRIS = 0x00;
    pickerBus = 0x00;

    OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // vibration motor
    OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // head led
    OpenOC3( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // base led
    OpenTimer2( T2_ON | T2_PS_1_4 | T2_SOURCE_INT, 1024);
    SetDCOC1PWM(0);
    SetDCOC2PWM(0);
    SetDCOC3PWM(0);

    setVac1off;
    setVac2off;
    

    USBOutHandle = 0;
    USBInHandle = 0;
    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware

    USBDeviceAttach();
    
    init_component_picker();

    /*while(1)
    {
        LATBbits.LATB0 = feederXHome;
        LATBbits.LATB1 = feederZHome;
        //ProcessIO();
    }*/
}
示例#14
0
void preflight(void)
{
	printf("Initialising USB\r\n");

	USBDeviceInit();    //usb_device.c.  Initializes USB module SFRs and firmware variables to known states.
#if defined(USB_INTERRUPT)
	USBDeviceAttach();
#endif
}
示例#15
0
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();

    IPR1 = 0;   //All others interrupt sources will be Low priority
    IPR2 = 32; //USB interrupt is High priority
    RCONbits.IPEN = 1;  //Enabling interrupt priority
    ADCON1bits.PCFG = 0x0F; //By default all I/O digital
    CMCONbits.CM = 7; //Comparators off by default

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        //Application specific tasks
        APP_DeviceCustomHIDTasks();

    }//end while
}//end main
示例#16
0
// Main program entry point
void main(void)
{   
	UINT16 i;

	// Initialise and configure the PIC ready to go
    initialisePic();

	// If we are running in interrupt mode attempt to attach the USB device
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
	
	// Initialise the debug log functions
    //debugInitialise();
    
    // Show that we are up and running
    //mStatusLED0_on();
	
/*	sprintf(debugString, "USB Generic HID Demonstration 3");
	debugOut(debugString);

	//sprintf(debugString, "(C)2011 Simon Inns - http://www.waitingforfriday.com");
	//debugOut(debugString);
	
	sprintf(debugString, "USB Device Initialised. ");
	debugOut(debugString);

	sprintf(debugString, "Initializing N64 Controller.");
	debugOut(debugString);

	InitController();
	sprintf(debugString, "N64 Controller Initialised.");
	debugOut(debugString);*/
	
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);

	// Main processing loop
    while(1)
    {
        #if defined(USB_POLLING)
			// If we are in polling mode the USB device tasks must be processed here
			// (otherwise the interrupt is performing this task)
	        USBDeviceTasks();
        #endif
    	
    	// Process USB Commands
        processUsbCommands();  
        
        // Note: Other application specific actions can be placed here      
    }
}
示例#17
0
/********************************************************************
 * Function:        void main(void)
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize();

    USBDeviceInit();
    USBDeviceAttach();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }
        // implement nMCLR button
        if ( BUTTON_IsPressed(BUTTON_S1)) {
            LUNSoftDetach(0);       // mark the media as temporarily unavailable 
            ICSP_nMCLR = SLAVE_RESET;
            LED_Off(GREEN_LED);     // turn off RED LED to indicate ready for download
            LED_On (RED_LED);
            DIRECT_Initialize();    // reset the programming state machine
        }
        else { // simply act as a slave reset 
            LUNSoftAttach(0);                       // mark the media as available
            if ( !DIRECT_ProgrammingInProgress()) {  // do not release during prog.!
                ICSP_nMCLR = SLAVE_RUN;
                LED_On(GREEN_LED);   // turn off RED LED to indicate ready for download
                LED_Off(RED_LED);
            }
        }

        //Application specific tasks
        APP_DeviceMSDTasks();
        APP_DeviceCDCEmulatorTasks();

    }//end while
}//end main
示例#18
0
文件: main.c 项目: 21rcc/ioio
int main() {
  log_init();

  // If bootloader mode not requested, go immediately to app.
  if (!ShouldEnterBootloader()) {
    OscCalibrateCached();
    log_printf("Running app...");
    __asm__("goto __APP_RESET");
  }

  // We need to enter bootloader mode, wait for the boot pin to be released.
  while (!led_read());

  // Now we can start!
  led_init();
#ifdef SIGNAL_AFTER_BAD_RESET
  if (RCON & 0b1100001001000000) {
    SignalRcon();
  }
#endif

  log_printf("Hello from Bootloader!!!");
  if (IsPin1Grounded()) {
    log_printf("Erasing config.");
    EraseConfig();
  }
  OscCalibrateCached();
  Blink(5);
  USBInitialize();

  while (1) {
    // Wait for connection
    while (!(USBGetDeviceState() == CONFIGURED_STATE
      && CDCIsDtePresent())) USBTasks();

    log_printf("Connected!");
    BootProtocolInit();

    while (USBGetDeviceState() == CONFIGURED_STATE && CDCIsDtePresent()) {
      static char in_buf[64];
      USBTasks();

      BYTE size = getsUSBUSART(in_buf, sizeof(in_buf));
      if (!BootProtocolProcess(in_buf, size)) {
        log_printf("Protocol error. Will detach / re-attach.");
        USBSoftDetach();
        __delay_ms(2000);
        USBDeviceAttach();
        break;
      }
      BootProtocolTasks();
    }
    log_printf("Disconnected!");
  }
  return 0;
}
示例#19
0
void CDC_init()
{
    USBDeviceInit();		// Initializes USB module SFRs and firmware
    #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
        // nothing to do
    #else
        USBDeviceAttach();
    #endif
    Delayms(1500);
}
示例#20
0
/***************************************************
 * Function:        void Init(void)
 *
 * OverView:		All calling related to Initialized functions.
 *
 * Note:			None
 ***************************************************/
void Init(void)
{
	InitializeSystem();		//	Initialize Related to connect usb port.
	InitializeUser();		//	Initialize for User Variables.
	InitializeDevice();		//	Initialize PICF4550 LED, PWM, ADC Ports
	USBDeviceInit();		//	Initialize USB Module.

	#if defined(USB_INTERRUPT)
		USBDeviceAttach();	//	Enable to find USB Device
	#endif
}
示例#21
0
int main(void)
{
    struct BadgeState *game_state;
    char sample_i = 0, sample_val = 0;

    InitializeSystem();

    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif

    #if defined(GAME_MODE)
        game_state = Init_Game();
    #endif
    while(1)
    {
        if((play_count & 0x0fff) && play_count & 0x8000)
        {
            //LATBbits.LATB2 = 1;
            //LATBbits.LATB3 = 1;

            getNextSample( &sample_i, &sample_val);
            LATAbits.LATA9 = sample_val;
            play_count++;
        }
        else
            play_count = play_count & 0x8000;

        #if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        				  // this function periodically.  This function will take care
        				  // of processing and responding to SETUP transactions 
        				  // (such as during the enumeration process when you first
        				  // plug in).  USB hosts require that USB devices should accept
        				  // and process SETUP packets in a timely fashion.  Therefore,
        				  // when using polling, this function should be called 
        				  // regularly (such as once every 1.8ms or faster** [see 
        				  // inline code comments in usb_device.c for explanation when
        				  // "or faster" applies])  In most cases, the USBDeviceTasks() 
        				  // function does not take very long to execute (ex: <100 
        				  // instruction cycles) before it returns.
        #endif
    				  

		// Application-specific tasks.
		// Application related code may be added here, or in the ProcessIO() function.
        ProcessIO();
    #if defined(GAME_MODE)
         Run_Game(&game_state);
        //welcome(game_state);
    #endif
    }//end while
}//end main
示例#22
0
文件: main.c 项目: todbot/cstbase
// ****************************************************************************
// main
//
int main(void)
{
    InitializeSystem();

    USBDeviceAttach();
    
    while (1) {
        updateState();
        handleKeys();
        CLRWDT();  // tickle watchdog
    }

} //end main
示例#23
0
文件: main.c 项目: niamster/uc-pic
static void usbInit(void)
{
    //	The USB specifications require that USB peripheral devices must never source
    //	current onto the Vbus pin.  Additionally, USB peripherals should not source
    //	current on D+ or D- when the host/hub is not actively powering the Vbus line.
    //	When designing a self powered (as opposed to bus powered) USB peripheral
    //	device, the firmware should make sure not to turn on the USB module and D+
    //	or D- pull up resistor unless Vbus is actively powered.  Therefore, the
    //	firmware needs some means to detect when Vbus is being powered by the host.
    //	A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and
    // 	can be used to detect when Vbus is high (host actively powering), or low
    //	(host is shut down or otherwise not supplying power).  The USB firmware
    // 	can then periodically poll this I/O pin to know when it is okay to turn on
    //	the USB module/D+/D- pull up resistor.  When designing a purely bus powered
    //	peripheral device, it is not possible to source current on D+ or D- when the
    //	host is not actively providing power on Vbus. Therefore, implementing this
    //	bus sense feature is optional.  This firmware can be made to use this bus
    //	sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the
    //	HardwareProfile.h file.
#if defined(USE_USB_BUS_SENSE_IO)
    tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
#endif

    //	If the host PC sends a GetStatus (device) request, the firmware must respond
    //	and let the host know if the USB peripheral device is currently bus powered
    //	or self powered.  See chapter 9 in the official USB specifications for details
    //	regarding this request.  If the peripheral device is capable of being both
    //	self and bus powered, it should not return a hard coded value for this request.
    //	Instead, firmware should check if it is currently self or bus powered, and
    //	respond accordingly.  If the hardware has been configured like demonstrated
    //	on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
    //	currently selected power source.  On the PICDEM FS USB Demo Board, "RA2" 
    //	is used for	this purpose.  If using this feature, make sure "USE_SELF_POWER_SENSE_IO"
    //	has been defined in HardwareProfile.h, and that an appropriate I/O pin has been mapped
    //	to it in HardwareProfile.h.
#if defined(USE_SELF_POWER_SENSE_IO)
    tris_self_power = INPUT_PIN;	// See HardwareProfile.h
#endif

	UsbOutCmdHandle = 0;
	UsbInCmdHandle = 0;
    UsbOutDataHandle = 0;
	UsbInDataHandle = 0;

    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.

#if defined(USB_INTERRUPT)
    USBDeviceAttach();
#endif
}
示例#24
0
void preflight(void)
{
	printf("Initialising USB\r\n");
	USBDeviceInit();        //usb_device.c.  Initializes USB module SFRs and firmware variables to known states.
	#if defined(USB_INTERRUPT)
		USBDeviceAttach();
	#endif
	delay_ms(100);

	printf("Preflight setup\r\n");
	while (U1OTGSTATbits.VBUSVD)
	{
		#if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
		USBDeviceTasks();   // Interrupt or polling method.  If using polling, must call
		                    // this function periodically.  This function will take care
		                    // of processing and responding to SETUP transactions 
		                    // (such as during the enumeration process when you first
		                    // plug in).  USB hosts require that USB devices should accept
		                    // and process SETUP packets in a timely fashion.  Therefore,
		                    // when using polling, this function should be called 
		                    // regularly (such as once every 1.8ms or faster** [see 
		                    // inline code comments in usb_device.c for explanation when
		                    // "or faster" applies])  In most cases, the USBDeviceTasks() 
		                    // function does not take very long to execute (ex: <100 
		                    // instruction cycles) before it returns.
		#endif

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) {
			// do nothing
		} else {
#if (USE_MSD == 1)
			MSDTasks();
#endif
#if (USE_CDC == 1)
			CDCTasks();
#endif
		}
#if (CONSOLE_UART != 0)
		console();
#endif
	}

	led_off(LED_RED);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_ORANGE);

	printf("Preflight complete\r\n");
}
示例#25
0
void ConsoleInit(void)
{
#if defined(ENABLE_CONSOLE)
		unsigned long i = 0;
		
		// Don't attempt anything if not connected
		if (!USB_BUS_SENSE) return;

		USBInitializeSystem();
		USBDeviceAttach();

		// This will only work in an interrupt driven USB system - exits on button press, only exits after enumeration is usb is detected
		while (USBDeviceState < CONFIGURED_STATE)
		{
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(1);
			
			// Timed-out starting connection (perhaps a charger or disconnected?)
			if (i++ >= 1000000ul) 
			{ 
				// The USB connection has failed -- if we're not using the PLL when the radio is on, turn it off now
				USBDeviceDetach();
				return;
			}
		}
		

 		// Gives host time to assign CDC port
 		i = 0;
		while (USBDeviceState >= CONFIGURED_STATE && i++ < 600000ul)
		{
			MRF_LED = 1;
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(10);
			if (usb_haschar())
			{
				break;
			}	
		}
		MRF_LED = 0;
#endif
	return;
}
示例#26
0
MAIN_RETURN main(void) {
    gpio_init();
    timer_init();
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);
    USBDeviceInit();
    USBDeviceAttach();
    while (1) {
        SYSTEM_Tasks();
#if defined(USB_POLLING)
        USBDeviceTasks();
#endif
        //APP_DeviceCDCBasicDemoTasks();
        serial_update();
    }
}
示例#27
0
void main(void)
{
	InitializeSystem();

	#if defined(USB_INTERRUPT)
		USBDeviceAttach();
	#endif

	while(1)
	{
		#if defined(USB_POLLING)
			USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
		#endif
		ProcessIO();
	}//end while
}//end main
示例#28
0
int main(void)
{   
    InitializeSystem();

    while(1)
    {
        #if defined(USB_INTERRUPT)
            //if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE))
            //{
                USBDeviceAttach();              
            //}
        #endif

        /*if(USBDeviceState < CONFIGURED_STATE) {
            if(!I2CState.Slave)
                InitI2CSlave();
            }
        else if(!I2CState.Master)
            InitI2CMaster();*/

        #if defined(USB_POLLING)
    // Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
                          // this function periodically.  This function will take care
                          // of processing and responding to SETUP transactions 
                          // (such as during the enumeration process when you first
                          // plug in).  USB hosts require that USB devices should accept
                          // and process SETUP packets in a timely fashion.  Therefore,
                          // when using polling, this function should be called 
                          // regularly (such as once every 1.8ms or faster** [see 
                          // inline code comments in usb_device.c for explanation when
                          // "or faster" applies])  In most cases, the USBDeviceTasks() 
                          // function does not take very long to execute (ex: <100 
                          // instruction cycles) before it returns.
        #endif
        
        if(TMR0IF)
            WorkTick();

        if(Status.State == 'P'){
            AsicPushWork();
        }
                      
        ProcessIO();  
              
    }//end while
}//end main
示例#29
0
文件: main.c 项目: Shmuma/radio
void main (void)
{
    int cnt = 0;

    InitDevice ();
    Delay10KTCYx (250);
    InitializeUSB ();
    InitLCD ();

    /* UCONbits.USBEN = 0; */
    /* UCFGbits.UTRDIS = 0; */
    /* UCFGbits.UPUEN = 1; */
    /* UCFGbits.FSEN = 1; */
    USBDeviceAttach ();

    while (1) {
        WriteLCDChar (UCONbits.USBEN ? '0' : '1');
        WriteLCDChar (UCFGbits.FSEN  ? '0' : '1');
        WriteLCDChar (UCFGbits.UTRDIS ? '0' : '1');
        WriteLCDChar (UCFGbits.UPUEN ? '0' : '1');
        WriteLCDChar ('0' + UCFGbits.PPB);
        WriteLCDChar ('-');
        WriteLCDChar ('0' + USTATbits.ENDP);
        WriteLCDChar ('0' + USTATbits.DIR);
        WriteLCDChar ('0' + USTATbits.PPBI);
        WriteLCDChar ('-');
        putNumber (USBDeviceState);
        WriteLCDChar ('-');
        putNumber (cnt++);
//        if (USBDeviceState == DETACHED_STATE)
//            USBDeviceAttach ();
        Delay10KTCYx (1000);
        LCDHome ();
        Delay10KTCYx (10);
    }
//        if (USBDeviceState < CONFIGURED_STATE)
//            continue;

//        bitset (PORTB, E_PORT);
//        Delay10TCYx (10);
//        ClearLCD ();
//        bitclr (PORTB, E_PORT);
//        Delay10TCYx (10);
//    }
}
示例#30
0
void main( void )
{
    InitializeSystem();

    #if defined( USB_INTERRUPT )
    USBDeviceAttach();
    #endif

    while ( 1 )
    {
        #if defined( USB_POLLING )
        // Check bus status and service USB interrupts.
        USBDeviceTasks(); // Call every 100us or so (takes ~50 instruction cycles before it returns).
        #endif

        ProcessIO();
    }
}