text: /*******************************************************************************
    System Initialization File
  
    File Name:
      initialization.c
  
    Summary:
      This file contains source code necessary to initialize the system.
  
    Description:
      This file contains source code necessary to initialize the system.  It
      implements the "SYS_Initialize" function, defines the configuration bits,
      and allocates any necessary global system resources,
   *******************************************************************************/
  
  // DOM-IGNORE-BEGIN
  /*******************************************************************************
  * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries.
  *
  * Subject to your compliance with these terms, you may use Microchip software
  * and any derivatives exclusively with Microchip products. It is your
  * responsibility to comply with third party license terms applicable to your
  * use of third party software (including open source software) that may
  * accompany Microchip software.
  *
  * 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.
  *
  * 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.
   *******************************************************************************/
  // DOM-IGNORE-END
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Included Files
  // *****************************************************************************
  // *****************************************************************************
  #include "configuration.h"
  #include "definitions.h"
  #include "device.h"
  
  
  
  // ****************************************************************************
  // ****************************************************************************
  // Section: Configuration Bits
  // ****************************************************************************
  // ****************************************************************************
  
  /*** DEVCFG0 ***/
  #pragma config DEBUG =      OFF
  #pragma config JTAGEN =     OFF
  #pragma config ICESEL =     ICS_PGx2
  #pragma config PWP =        OFF
  #pragma config BWP =        OFF
  #pragma config CP =         OFF
  
  
  /*** DEVCFG1 ***/
  #pragma config FNOSC =      FRCPLL
  #pragma config FPBDIV =     DIV_2
  #pragma config FSOSCEN =    OFF
  #pragma config IESO =       ON
  #pragma config POSCMOD =    OFF
  #pragma config OSCIOFNC =   OFF
  #pragma config FCKSM =      CSDCMD
  #pragma config WDTPS =      PS1048576
  #pragma config FWDTEN =     OFF
  #pragma config WINDIS =     OFF
  #pragma config FWDTWINSZ =  WINSZ_25
  
  
  /*** DEVCFG2 ***/
  #pragma config FPLLIDIV =   DIV_2
  #pragma config FPLLMUL =    MUL_24
  #pragma config FPLLODIV =   DIV_1
  #pragma config UPLLEN =     OFF
  #pragma config UPLLIDIV =   DIV_2
  
  /*** DEVCFG3 ***/
  #pragma config FSRSSEL =    PRIORITY_7
  #pragma config FVBUSONIO =  ON
  #pragma config USERID =     0xffff
  #pragma config PMDL1WAY =   ON
  #pragma config IOL1WAY =    ON
  #pragma config FUSBIDIO =   ON
  
  
  
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Driver Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  // <editor-fold defaultstate="collapsed" desc="DRV_USART Instance 0 Initialization Data">
  
  static DRV_USART_CLIENT_OBJ drvUSART0ClientObjPool[DRV_USART_CLIENTS_NUMBER_IDX0];
  
  
  const DRV_USART_PLIB_INTERFACE drvUsart0PlibAPI = {
      .readCallbackRegister = (DRV_USART_PLIB_READ_CALLBACK_REG)UART1_ReadCallbackRegister,
      .read = (DRV_USART_PLIB_READ)UART1_Read,
      .readIsBusy = (DRV_USART_PLIB_READ_IS_BUSY)UART1_ReadIsBusy,
      .readCountGet = (DRV_USART_PLIB_READ_COUNT_GET)UART1_ReadCountGet,
      .writeCallbackRegister = (DRV_USART_PLIB_WRITE_CALLBACK_REG)UART1_WriteCallbackRegister,
      .write = (DRV_USART_PLIB_WRITE)UART1_Write,
      .writeIsBusy = (DRV_USART_PLIB_WRITE_IS_BUSY)UART1_WriteIsBusy,
      .writeCountGet = (DRV_USART_PLIB_WRITE_COUNT_GET)UART1_WriteCountGet,
      .errorGet = (DRV_USART_PLIB_ERROR_GET)UART1_ErrorGet,
      .serialSetup = (DRV_USART_PLIB_SERIAL_SETUP)UART1_SerialSetup
  };
  
  const uint32_t drvUsart0remapDataWidth[] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x6 };
  const uint32_t drvUsart0remapParity[] = { 0x0, 0x2, 0x4, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  const uint32_t drvUsart0remapStopBits[] = { 0x0, 0xFFFFFFFF, 0x1 };
  const uint32_t drvUsart0remapError[] = { 0x2, 0x8, 0x4 };
  
  const DRV_USART_INIT drvUsart0InitData =
  {
      .usartPlib = &drvUsart0PlibAPI,
  
      /* USART Number of clients */
      .numClients = DRV_USART_CLIENTS_NUMBER_IDX0,
  
      /* USART Client Objects Pool */
      .clientObjPool = (uintptr_t)&drvUSART0ClientObjPool[0],
  
      .dmaChannelTransmit = DRV_USART_XMIT_DMA_CH_IDX0,
  
      .usartTransmitAddress = (void *)&(U1TXREG),
  
      .dmaChannelReceive = DRV_USART_RCV_DMA_CH_IDX0,
  
      .usartReceiveAddress = (void *)&(U1RXREG),
  
  
      .remapDataWidth = drvUsart0remapDataWidth,
  
      .remapParity = drvUsart0remapParity,
  
      .remapStopBits = drvUsart0remapStopBits,
  
      .remapError = drvUsart0remapError,
  };
  
  // </editor-fold>
  
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: System Data
  // *****************************************************************************
  // *****************************************************************************
  /* Structure to hold the object handles for the modules in the system. */
  SYSTEM_OBJECTS sysObj;
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Library/Stack Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: System Initialization
  // *****************************************************************************
  // *****************************************************************************
  
  
  
  /*******************************************************************************
    Function:
      void SYS_Initialize ( void *data )
  
    Summary:
      Initializes the board, services, drivers, application and other modules.
  
    Remarks:
   */
  
  void SYS_Initialize ( void* data )
  {
      /* Start out with interrupts disabled before configuring any modules */
      __builtin_disable_interrupts();
  
    
      CLK_Initialize();
  
      /* Configure KSEG0 as cacheable memory. This is needed for Prefetch Buffer */
      __builtin_mtc0(16, 0,(__builtin_mfc0(16, 0) | 0x3));
  
      /* Configure Flash Wait States and Prefetch */
      CHECONbits.PFMWS = 2;
      CHECONbits.PREFEN = 3;
  
      /* Set the SRAM wait states to zero */
      BMXCONbits.BMXWSDRM = 0;
  
  
  
  
  
  	GPIO_Initialize();
  
  	BSP_Initialize();
  	UART1_Initialize();
  
      DMAC_Initialize();
  
      sysObj.drvUsart0 = DRV_USART_Initialize(DRV_USART_INDEX_0, (SYS_MODULE_INIT *)&drvUsart0InitData);
  
  
  
  
      APP_USART_ECHO_Initialize();
  
  
      EVIC_Initialize();
  
  	/* Enable global interrupts */
      __builtin_enable_interrupts();
  
  
  }
  
  
  /*******************************************************************************
   End of File
  */
  