/**********************************************************************
 *
 * USB Generic Device Demo Main Application File
 *
 **********************************************************************
 * Description:
 * This file contains the demo application for the Microchip Generic Devce Driver.
 * Refer to AN1166 - USB Generic Function on an Embedded device
 *
 **********************************************************************
 * Filename:     main.c
 * Dependancies: See "Includes" section, below.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the “Company”) for its PICmicro® Microcontroller is intended and
 * supplied to you, the Company’s customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 * 
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Copyright (c) 2008 Microchip Technology, Inc.
 *
 **********************************************************************
 * Change History:
 * ID			Date            Changes
 * BC			2006			Initial Creation
 * C11842		12/01/2008		Updated comments, 80MHz operation.
 ***********************************************************************/
 
/************
 * Includes *
 ************/
 
#include <string.h>
#include <GenericTypeDefs.h>
#include "USB\usb.h"
#include "HardwareProfile.h"
#include <plib.h>


/**********************
 * Configuration Bits *
 **********************/

#ifndef OVERRIDE_CONFIG_BITS
        
    #pragma config UPLLEN   = ON            // USB PLL Enabled
    #pragma config FPLLMUL  = MUL_20        // PLL Multiplier
    #pragma config UPLLIDIV = DIV_2         // USB PLL Input Divider
    #pragma config FPLLIDIV = DIV_2         // PLL Input Divider
    #pragma config FPLLODIV = DIV_1         // PLL Output Divider
    #pragma config FPBDIV   = DIV_1         // Peripheral Clock divisor
    #pragma config FWDTEN   = OFF           // Watchdog Timer 
    #pragma config WDTPS    = PS1           // Watchdog Timer Postscale
    #pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor
    #pragma config OSCIOFNC = OFF           // CLKO Enable
    #pragma config POSCMOD  = HS            // Primary Oscillator
    #pragma config IESO     = OFF           // Internal/External Switch-over
    #pragma config FSOSCEN  = OFF           // Secondary Oscillator Enable
    #pragma config FNOSC    = PRIPLL        // Oscillator Selection
    #pragma config CP       = OFF           // Code Protect
    #pragma config BWP      = OFF           // Boot Flash Write Protect
    #pragma config PWP      = OFF           // Program Flash Write Protect
    #pragma config ICESEL   = ICS_PGx2      // ICE/ICD Comm Channel Select
    #pragma config DEBUG    = OFF           // Debugger Disabled for Starter Kit
            
#endif // OVERRIDE_CONFIG_BITS


/***************************
 * Application Entry Point *
 ***************************/

/*************************************************************************
 * Function:        main
 *
 * Precondition:    System has been initialized sufficiently to execute
 *                  C language code.
 *
 * Input:           none
 *
 * Output:          none
 *
 * Returns:         none
 *
 * Side Effects:    Keeps system running.
 *
 * Overview:        This is the system's main C-language entry point.  It
 *                  initializes the application and contains the main
 *                  processing loop.
 *
 * Notes:           Never exits.
 *************************************************************************/
 
int main ( void )
{
    // Configure the device for maximum performance, but do not change the PBDIV clock divisor.
	// Given the options, this function will change the program Flash wait states,
	// RAM wait state and enable prefetch cache, but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above.
   	SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);	

    // Enable system interrupts
    INTEnableSystemMultiVectoredInt();
    
    /* 	Initialize the DB_UTILS IO channel for Starter Kit.
	Note: To see these messages in MPLAB PIC32 Starter Kit Window
	add "PIC32_STARTER_KIT" to macro definitions:
	Project > Build Options > Project > Compiler Tab 
    */
	mInitMessage();
	mSendMessage1();
	mSendMessage2();

    // Initialize the USB stack.
    USBInitialize(0);

    // Initialize the user application (see user.c & .h)
    UserInit();

    // Main Processing Loop
    while(1)
    {
        // Check USB for events and handle them appropriately.
        USBTasks();

        // Handle app-specific IO requests.
        ProcessIO();
    }

    return 0;

} // main


/*************************************************************************
 * EOF
 */

