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
  // ****************************************************************************
  // ****************************************************************************
  #pragma config TCM_CONFIGURATION = 0
  #pragma config SECURITY_BIT = CLEAR
  #pragma config BOOT_MODE = SET
  
  
  
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Driver Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  // <editor-fold defaultstate="collapsed" desc="DRV_SPI Instance 0 Initialization Data">
  
  /* SPI Client Objects Pool */
  static DRV_SPI_CLIENT_OBJ drvSPI0ClientObjPool[DRV_SPI_CLIENTS_NUMBER_IDX0];
  
  /* SPI Transfer Objects Pool */
  static DRV_SPI_TRANSFER_OBJ drvSPI0TransferObjPool[DRV_SPI_QUEUE_SIZE_IDX0];
  
  /* SPI PLIB Interface Initialization */
  const DRV_SPI_PLIB_INTERFACE drvSPI0PlibAPI = {
  
      /* SPI PLIB Setup */
      .setup = (DRV_SPI_PLIB_SETUP)SPI0_TransferSetup,
  
      /* SPI PLIB WriteRead function */
      .writeRead = (DRV_SPI_PLIB_WRITE_READ)SPI0_WriteRead,
  
      /* SPI PLIB Transfer Status function */
      .isBusy = (DRV_SPI_PLIB_IS_BUSY)SPI0_IsBusy,
  
      /* SPI PLIB Callback Register */
      .callbackRegister = (DRV_SPI_PLIB_CALLBACK_REGISTER)SPI0_CallbackRegister,
  };
  
  const uint32_t drvSPI0remapDataBits[]= { 0x0, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80 };
  const uint32_t drvSPI0remapClockPolarity[] = { 0x0, 0x1 };
  const uint32_t drvSPI0remapClockPhase[] = { 0x0, 0x2 };
  
  const DRV_SPI_INTERRUPT_SOURCES drvSPI0InterruptSources =
  {
      /* Peripheral has single interrupt vector */
      .isSingleIntSrc                        = true,
  
      /* Peripheral interrupt line */
      .intSources.spiInterrupt             = SPI0_IRQn,
      /* DMA interrupt line */
      .intSources.dmaInterrupt               = XDMAC_IRQn,
  };
  
  /* SPI Driver Initialization Data */
  const DRV_SPI_INIT drvSPI0InitData =
  {
      /* SPI PLIB API */
      .spiPlib = &drvSPI0PlibAPI,
  
      .remapDataBits = drvSPI0remapDataBits,
  
      .remapClockPolarity = drvSPI0remapClockPolarity,
  
      .remapClockPhase = drvSPI0remapClockPhase,
  
      /* SPI Number of clients */
      .numClients = DRV_SPI_CLIENTS_NUMBER_IDX0,
  
      /* SPI Client Objects Pool */
      .clientObjPool = (uintptr_t)&drvSPI0ClientObjPool[0],
  
      /* DMA Channel for Transmit */
      .dmaChannelTransmit = DRV_SPI_XMIT_DMA_CH_IDX0,
  
      /* DMA Channel for Receive */
      .dmaChannelReceive  = DRV_SPI_RCV_DMA_CH_IDX0,
  
      /* SPI Transmit Register */
      .spiTransmitAddress =  (void *)&(SPI0_REGS->SPI_TDR),
  
      /* SPI Receive Register */
      .spiReceiveAddress  = (void *)&(SPI0_REGS->SPI_RDR),
  
      /* SPI Queue Size */
      .transferObjPoolSize = DRV_SPI_QUEUE_SIZE_IDX0,
  
      /* SPI Transfer Objects Pool */
      .transferObjPool = (uintptr_t)&drvSPI0TransferObjPool[0],
  
      /* SPI interrupt sources (SPI peripheral and DMA) */
      .interruptSources = &drvSPI0InterruptSources,
  };
  
  // </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 )
  {
  
      EFC_Initialize();
    
      CLOCK_Initialize();
  	PIO_Initialize();
  
  
  
  	BSP_Initialize();
      XDMAC_Initialize();
  
  	RSWDT_REGS->RSWDT_MR = RSWDT_MR_WDDIS_Msk;	// Disable RSWDT 
  
  	WDT_REGS->WDT_MR = WDT_MR_WDDIS_Msk; 		// Disable WDT 
  
  	SPI0_Initialize();
  
  
      /* Initialize SPI0 Driver Instance */
      sysObj.drvSPI0 = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (SYS_MODULE_INIT *)&drvSPI0InitData);
  
  
  
      APP_EEPROM1_Initialize();
      APP_EEPROM2_Initialize();
      APP_MONITOR_Initialize();
  
  
      NVIC_Initialize();
  
  }
  
  
  /*******************************************************************************
   End of File
  */
  