/**
  Generated main.c file from MPLAB Code Configurator

  @Company
    Microchip Technology Inc.

  @File Name
    main.c

  @Summary
    This is the generated main.c using PIC24 / dsPIC33 / PIC32MM MCUs.

  @Description
    This source file provides main entry point for system initialization and application code development.
    Generation Information :
        Product Revision  :  PIC24 / dsPIC33 / PIC32MM MCUs - 1.168.0
        Device            :  PIC24FJ1024GA606
    The generated drivers are tested against the following:
        Compiler          :  XC16 v1.50
        MPLAB 	          :  MPLAB X v5.40
*/

/*
    (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS.
*/

/**
  Section: Included Files
*/
#include "mcc_generated_files/system.h"
#include "mcc_generated_files/boot/boot_demo.h"
#include "mcc_generated_files/uart4.h"

#if __DEBUG
// max flash page erased
uint32_t maxEraseAddr=0;
// number calls to EraseFlash (typically 1)
uint32_t eraseCalls=0;
// last erase command dataLength member
uint32_t eraseCmdDataLen=0;
// last erase command start address
uint32_t eraseCmdAddr=0;
// nominal max flash page (EraseFlash loop page limit)
uint32_t eraseLimit=0;
// erase error flags (bit field)
// 0x1 page alignment error
// 0x2 illegal address (erase loop)
// 0x4 illegal address (post loop validate end address)
uint32_t eraseErrors=0;
// number of normal EraseFlash exits
uint32_t eraseOK=0;
// number calls to WriteFlash (typically many)
uint32_t writeCalls=0;
// max flash address written
uint32_t maxWriteAddr=0;
uint32_t writeCmdDataLen=0;
// write error flags (bit field)
// 0x1 command byte count error
// 0x2 write error BAD_ADDRESS-1
// 0x4 write error BAD_ADDRESS
uint32_t writeErrors=0;
uint32_t writeOK=0;
#endif
/*
                         Main application
 */
int main(void)
{
    // select primary interrupt vector table
    // (IVT, addr 0x02-0xFF)
    INTCON2bits.AIVTEN = 0;
    // initialize the device
     SYSTEM_Initialize();
     BOOT_DEMO_Initialize();
    // enable host, console transceiver enable bits
    PORTDbits.RD3=1;
    PORTEbits.RE6=1;
    // LED on to signal bootloader entry (2s)
    blink_led(2000,1);

    while (1)
    {
       // Add your application code
        BOOT_DEMO_Tasks();
    }

    return 1;
}
/**
 End of File
*/

