Ejemplo n.º 1
0
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    switch(state)
    {
        case SYSTEM_STATE_USB_START:
            //On the PIC18F46J50 Family of USB microcontrollers, the PLL will not power up and be enabled
            //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL).
            //This allows the device to power up at a lower initial operating frequency, which can be
            //advantageous when powered from a source which is not gauranteed to be adequate for 48MHz
            //operation.  On these devices, user firmware needs to manually set the OSCTUNE<PLLEN> bit to
            //power up the PLL.
            {
                unsigned int pll_startup_counter = 600;
                OSCTUNEbits.PLLEN = 1;  //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module
                while(pll_startup_counter--);
            }
            //Device switches over automatically to PLL output after PLL is locked and ready.

            
            BUTTON_Enable(BUTTON_USB_DEVICE_HID_CUSTOM);
			
            softStartStatus = SOFT_START_POWER_START;
            break;

        case SYSTEM_STATE_USB_SUSPEND: 
            //Configure device for low power consumption.  Turn off app power.
            AppPowerDisable();
            softStartStatus = SOFT_START_POWER_OFF;
            break;
            
        case SYSTEM_STATE_USB_RESUME:
            softStartStatus = SOFT_START_POWER_START;
            break;
    }
}
Ejemplo n.º 2
0
/******************************************************************************
 * Function:        void USBCBSuspend(void)
 *
 * Overview:        Call back that is invoked when a USB suspend is detected
 *****************************************************************************/
void USBCBSuspend(void)
{
	#if defined(SOFTSTART_ENABLED)
	//Turn off the App Vdd
	AppPowerDisable();
	#endif

	//Example power saving code.  Insert appropriate code here for the desired
	//application behavior.  If the microcontroller will be put to sleep, a
	//process similar to that shown below may be used:
	//ConfigureIOPinsForLowPower();
	//SaveStateOfAllInterruptEnableBits();
	//DisableAllInterruptEnableBits();
	//should enable at least USBActivityIF as a wake source:
	//EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMicro();	
	Sleep();
	//Preferrably, these should be done in the USBCBWakeFromSuspend() function:
	//RestoreStateOfAllPreviouslySavedInterruptEnableBits();	
	//RestoreIOPinsToNormal();									

	//IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here.   
	//This bit is cleared inside the usb_device.c file.  Clearing USBActivityIF 
	//here will cause things to not work as intended.	
}