/******************************************************************************

    USB Generic Device Demo Main Application File
    
This file contains the demo application for the Microchip Generic Devce Driver.

 * Filename:        main.c
 * Dependancies:    See "Includes" section, below.
 * Processor:       PIC32MX
 * Hardware:        Refer to AN1166 - USB Generic Function on an Embedded 
                    device
 * Assembler:       pic32-gcc
 * Linker:          pic32-ld
 * Company:         Microchip Technology, Inc.

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.
*******************************************************************************/
 

/************
 * Includes *
 ************/
 
#include <GenericTypeDefs.h>
#include "HardwareProfile.h"
#include <USB\usb.h>
#include <plib.h>
#include "ex16lcd.h"
#include "user.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    = ON            // Background Debugger Enable
            
#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 )
{
    /* 
    PIC32 Peripheral Library functions SYSTEMConfigPerformance() and SYSTEMConfig()
    configures system parameters, such as Flash wait states, RAM wait states, 
    enable cache and set Peripheral Bus Clock (PBCLK) frequency for optimal
    system performance based on the system clock frequency argument.
    
    SYSTEMConfigPerformance() ignores the PBCLK fuse selection FPBDIV and calculates
    the fastest possible PBCLK based on the system clock frequency parameter.
    Use this function if you want to set the fastest PBCLK frequency.
    Example: SYSTEMConfigPerformance(80000000);  //@80MHz PBCLK ratio = 1:1
    
    SYSTEMConfig() uses the PBCLK defined by configuration fuse selection FPBDIV 
    set in code or from the MPLAB IDE Configuration Bits menu.
    Use this function if you want to maintain the PBCLK frequency set by FPBDIV.
    Example: SYSTEMConfig(80000000, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    */
    SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Enable system interrupts
    INTEnableSystemMultiVectoredInt();
    
    // Initialize and display the user messages
    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
 */

