text: /*******************************************************************************
    System Initialization File
  
    File Name:
      system_init.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, such as the
      sysObj structure that contains the object handles to all the MPLAB Harmony
      module objects in the system.
   *******************************************************************************/
  
  // DOM-IGNORE-BEGIN
  /*******************************************************************************
  Copyright 2017 Microchip Technology Incorporated and its subsidiaries.
  
  Permission is hereby granted, free of charge, to any person obtaining a copy of 
  this software and associated documentation files (the "Software"), to deal in 
  the Software without restriction, including without limitation the rights to 
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
  of the Software, and to permit persons to whom the Software is furnished to do 
  so, subject to the following conditions:
  The above copyright notice and this permission notice shall be included in all 
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE
   *******************************************************************************/
  // DOM-IGNORE-END
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Included Files
  // *****************************************************************************
  // *****************************************************************************
  
  #include "system_config.h"
  #include "system_definitions.h"
  
  
  // ****************************************************************************
  // ****************************************************************************
  // Section: Configuration Bits
  // ****************************************************************************
  // ****************************************************************************
  // <editor-fold defaultstate="collapsed" desc="Configuration Bits">
  
  /*** DEVCFG0 ***/
  
  #pragma config DEBUG =      OFF
  #pragma config JTAGEN =     OFF
  #pragma config ICESEL =     ICS_PGx2
  #pragma config TRCEN =      OFF
  #pragma config BOOTISA =    MIPS32
  #pragma config FECCCON =    OFF_UNLOCKED
  #pragma config FSLEEP =     OFF
  #pragma config DBGPER =     PG_ALL
  #pragma config SMCLR =      MCLR_NORM
  #pragma config SOSCGAIN =   GAIN_LEVEL_3
  #pragma config SOSCBOOST =  ON
  #pragma config POSCGAIN =   GAIN_LEVEL_3
  #pragma config POSCBOOST =  ON
  #pragma config EJTAGBEN =   NORMAL
  #pragma config CP =         OFF
  
  /*** DEVCFG1 ***/
  
  #pragma config FNOSC =      SPLL
  #pragma config DMTINTV =    WIN_127_128
  #pragma config FSOSCEN =    OFF
  #pragma config IESO =       OFF
  #pragma config POSCMOD =    EC
  #pragma config OSCIOFNC =   OFF
  #pragma config FCKSM =      CSECME
  #pragma config WDTPS =      PS65536
  #pragma config WDTSPGM =    STOP
  #pragma config FWDTEN =     OFF
  #pragma config WINDIS =     NORMAL
  #pragma config FWDTWINSZ =  WINSZ_25
  #pragma config DMTCNT =     DMT9
  #pragma config FDMTEN =     OFF
  /*** DEVCFG2 ***/
  
  #pragma config FPLLIDIV =   DIV_1
  #pragma config FPLLRNG =    RANGE_8_16_MHZ
  #pragma config FPLLICLK =   PLL_FRC
  #pragma config FPLLMULT =   MUL_50
  #pragma config FPLLODIV =   DIV_2
  #pragma config UPLLFSEL =   FREQ_24MHZ
  /*** DEVCFG3 ***/
  
  #pragma config USERID =     0xffff
  #pragma config FMIIEN =     OFF
  #pragma config FETHIO =     ON
  #pragma config PGL1WAY =    ON
  #pragma config PMDL1WAY =   ON
  #pragma config IOL1WAY =    ON
  #pragma config FUSBIDIO =   OFF
  
  /*** BF1SEQ0 ***/
  #pragma config TSEQ =       0xffff
  #pragma config CSEQ =       0x0000
  
  // </editor-fold>
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Driver Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  
  // <editor-fold defaultstate="collapsed" desc="DRV_SPI Initialization Data"> 
   /*** SPI Driver Initialization Data ***/
    /*** Index 0  ***/
   DRV_SPI_INIT drvSpi0InitData =
   {
      .spiId = DRV_SPI_SPI_ID_IDX0,
      .taskMode = DRV_SPI_TASK_MODE_IDX0,
      .spiMode = DRV_SPI_SPI_MODE_IDX0,
      .allowIdleRun = DRV_SPI_ALLOW_IDLE_RUN_IDX0,
      .spiProtocolType = DRV_SPI_SPI_PROTOCOL_TYPE_IDX0,
      .commWidth = DRV_SPI_COMM_WIDTH_IDX0,
      .baudClockSource = DRV_SPI_CLOCK_SOURCE_IDX0,
      .spiClk = DRV_SPI_SPI_CLOCK_IDX0,
      .baudRate = DRV_SPI_BAUD_RATE_IDX0,
      .bufferType = DRV_SPI_BUFFER_TYPE_IDX0,
      .clockMode = DRV_SPI_CLOCK_MODE_IDX0,
      .inputSamplePhase = DRV_SPI_INPUT_PHASE_IDX0,
      .txInterruptSource = DRV_SPI_TX_INT_SOURCE_IDX0,
      .rxInterruptSource = DRV_SPI_RX_INT_SOURCE_IDX0,
      .errInterruptSource = DRV_SPI_ERROR_INT_SOURCE_IDX0,
      .dummyByteValue = DRV_SPI_TRANSMIT_DUMMY_BYTE_VALUE_IDX0,
      .txDmaChannel =         DRV_SPI_TX_DMA_CHANNEL_IDX0,
      .txDmaThreshold =       DRV_SPI_TX_DMA_THRESHOLD_IDX0,
      .rxDmaChannel =         DRV_SPI_RX_DMA_CHANNEL_IDX0,
      .rxDmaThreshold =       DRV_SPI_RX_DMA_THRESHOLD_IDX0,
      .queueSize = DRV_SPI_QUEUE_SIZE_IDX0,
      .jobQueueReserveSize = DRV_SPI_RESERVED_JOB_IDX0,
   };
  
  /* MIIM Driver Configuration */
  const DRV_MIIM_INIT drvMiimInitData =
  {
      .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
      .ethphyId = DRV_MIIM_ETH_MODULE_ID,
  };
  
  // <editor-fold defaultstate="collapsed" desc="DRV_Timer Initialization Data">
  /*** TMR Driver Initialization Data ***/
  
  const DRV_TMR_INIT drvTmr0InitData =
  {
      .moduleInit.sys.powerState = DRV_TMR_POWER_STATE_IDX0,
      .tmrId = DRV_TMR_PERIPHERAL_ID_IDX0,
      .clockSource = DRV_TMR_CLOCK_SOURCE_IDX0,
      .prescale = DRV_TMR_PRESCALE_IDX0,
      .mode = DRV_TMR_OPERATION_MODE_IDX0,
      .interruptSource = DRV_TMR_INTERRUPT_SOURCE_IDX0,
      .asyncWriteEnable = false,
  };
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="DRV_USART Initialization Data">
  
  const DRV_USART_INIT drvUsart0InitData =
  {
      .moduleInit.value = DRV_USART_POWER_STATE_IDX0,
      .usartID = DRV_USART_PERIPHERAL_ID_IDX0, 
      .mode = DRV_USART_OPER_MODE_IDX0,
      .flags = DRV_USART_INIT_FLAGS_IDX0,
      .brgClock = DRV_USART_BRG_CLOCK_IDX0,
      .lineControl = DRV_USART_LINE_CNTRL_IDX0,
      .baud = DRV_USART_BAUD_RATE_IDX0,
      .handshake = DRV_USART_HANDSHAKE_MODE_IDX0,
      .interruptTransmit = DRV_USART_XMIT_INT_SRC_IDX0,
      .interruptReceive = DRV_USART_RCV_INT_SRC_IDX0,
      .interruptError = DRV_USART_ERR_INT_SRC_IDX0,
      .queueSizeTransmit = DRV_USART_XMIT_QUEUE_SIZE_IDX0,
      .queueSizeReceive = DRV_USART_RCV_QUEUE_SIZE_IDX0,
      .dmaChannelTransmit = DMA_CHANNEL_NONE,
      .dmaInterruptTransmit = DRV_USART_XMIT_INT_SRC_IDX0,    
      .dmaChannelReceive = DMA_CHANNEL_NONE,
      .dmaInterruptReceive = DRV_USART_RCV_INT_SRC_IDX0,    
  };
  // </editor-fold>
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: System Data
  // *****************************************************************************
  // *****************************************************************************
  
  /* Structure to hold the object handles for the modules in the system. */
  SYSTEM_OBJECTS sysObj;
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Module Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  // <editor-fold defaultstate="collapsed" desc="SYS_COMMAND Initialization Data">
  /*** System Command Initialization Data ***/
  
  SYS_CMD_INIT sysCmdInit =
  {
      .moduleInit = {0},
      .consoleCmdIOParam = SYS_CMD_SINGLE_CHARACTER_READ_CONSOLE_IO_PARAM,
  };
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="SYS_CONSOLE Initialization Data">
  /*** System Console Initialization Data ***/
  
  SYS_MODULE_OBJ sysConsoleObjects[] = { SYS_MODULE_OBJ_INVALID };
  
  /* Declared in console device implementation (sys_console_uart.c) */
  extern SYS_CONSOLE_DEV_DESC consUsartDevDesc;
  SYS_CONSOLE_INIT consUsartInit0 =
  {
      .moduleInit = {0},
      .consDevDesc = &consUsartDevDesc,
  };
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="SYS_DEBUG Initialization Data">
  /*** System Debug Initialization Data ***/
  
  SYS_DEBUG_INIT debugInit =
  {
      .moduleInit = {0},
      .errorLevel = SYS_ERROR_FATAL
  };
  
  //<editor-fold defaultstate="collapsed" desc="SYS_DMA Initialization Data">
  /*** System DMA Initialization Data ***/
  
  const SYS_DMA_INIT sysDmaInit =
  {
  	.sidl = SYS_DMA_SIDL_DISABLE,
  
  };
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="SYS_TMR Initialization Data">
  /*** TMR Service Initialization Data ***/
  const SYS_TMR_INIT sysTmrInitData =
  {
      .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
      .drvIndex = DRV_TMR_INDEX_0,
      .tmrFreq = 1000, 
  };
  // </editor-fold>
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Library/Stack Initialization Data
  // *****************************************************************************
  // *****************************************************************************
  // <editor-fold defaultstate="collapsed" desc="TCP/IP Stack Initialization Data">
  // *****************************************************************************
  // *****************************************************************************
  // Section: TCPIP Data
  // *****************************************************************************
  // *****************************************************************************
  
  #if 0
  
  /*** ARP Service Initialization Data ***/
  const TCPIP_ARP_MODULE_CONFIG tcpipARPInitData =
  { 
      .cacheEntries       = TCPIP_ARP_CACHE_ENTRIES,     
      .deleteOld          = TCPIP_ARP_CACHE_DELETE_OLD,    
      .entrySolvedTmo     = TCPIP_ARP_CACHE_SOLVED_ENTRY_TMO, 
      .entryPendingTmo    = TCPIP_ARP_CACHE_PENDING_ENTRY_TMO, 
      .entryRetryTmo      = TCPIP_ARP_CACHE_PENDING_RETRY_TMO, 
      .permQuota          = TCPIP_ARP_CACHE_PERMANENT_QUOTA, 
      .purgeThres         = TCPIP_ARP_CACHE_PURGE_THRESHOLD, 
      .purgeQuanta        = TCPIP_ARP_CACHE_PURGE_QUANTA, 
      .retries            = TCPIP_ARP_CACHE_ENTRY_RETRIES, 
      .gratProbeCount     = TCPIP_ARP_GRATUITOUS_PROBE_COUNT,
  };
  
  
  /*** Announce Discovery Initialization Data ***/
  const TCPIP_ANNOUNCE_MODULE_CONFIG tcpipAnnounceInitData =
  { 
  };
  
  /*** UDP Sockets Initialization Data ***/
  const TCPIP_UDP_MODULE_CONFIG tcpipUDPInitData =
  {
      .nSockets       = TCPIP_UDP_MAX_SOCKETS,
      .sktTxBuffSize  = TCPIP_UDP_SOCKET_DEFAULT_TX_SIZE, 
  };
  
  /*** TCP Sockets Initialization Data ***/
  const TCPIP_TCP_MODULE_CONFIG tcpipTCPInitData =
  {
      .nSockets       = TCPIP_TCP_MAX_SOCKETS,
      .sktTxBuffSize  = TCPIP_TCP_SOCKET_DEFAULT_TX_SIZE, 
      .sktRxBuffSize  = TCPIP_TCP_SOCKET_DEFAULT_RX_SIZE,
  };
  
  
  
  
  
  
  /*** DHCP client Initialization Data ***/
  const TCPIP_DHCP_MODULE_CONFIG tcpipDHCPInitData =
  {     
      .dhcpEnable     = TCPIP_DHCP_CLIENT_ENABLED,   
      .dhcpTmo        = TCPIP_DHCP_TIMEOUT,
      .dhcpCliPort    = TCPIP_DHCP_CLIENT_CONNECT_PORT,
      .dhcpSrvPort    = TCPIP_DHCP_SERVER_LISTEN_PORT,
  
  };
  
  
  /*** ICMP Server Initialization Data ***/
  const TCPIP_ICMP_MODULE_CONFIG tcpipICMPInitData = 
  {
  };
  
  /*** NBNS Server Initialization Data ***/
  const TCPIP_NBNS_MODULE_CONFIG tcpipNBNSInitData =
  { 
  };
  
  #endif
  
  /*** ETH PHY Initialization Data ***/
  
  
  
  const DRV_ETHPHY_INIT tcpipPhyInitData =
  {
      .moduleInit             = {SYS_MODULE_POWER_RUN_FULL},
      .ethphyId               = TCPIP_EMAC_MODULE_ID,
      .phyAddress             = TCPIP_EMAC_PHY_ADDRESS,
      .phyFlags               = TCPIP_EMAC_PHY_CONFIG_FLAGS,
      .pPhyObject             = &DRV_ETHPHY_OBJECT_SMSC_LAN8720,
      .resetFunction          = 0,
      .pMiimObject            = &DRV_MIIM_OBJECT_BASE_Default,
      .pMiimInit              = &drvMiimInitData,
      .miimIndex              = DRV_MIIM_DRIVER_INDEX,
  };
  
  /*** ETH MAC Initialization Data ***/
  const TCPIP_MODULE_MAC_PIC32INT_CONFIG tcpipMACPIC32INTInitData =
  { 
      .nTxDescriptors         = TCPIP_EMAC_TX_DESCRIPTORS,
      .rxBuffSize             = TCPIP_EMAC_RX_BUFF_SIZE,
      .nRxDescriptors         = TCPIP_EMAC_RX_DESCRIPTORS,
      .nRxDedicatedBuffers    = TCPIP_EMAC_RX_DEDICATED_BUFFERS,
      .nRxInitBuffers         = TCPIP_EMAC_RX_INIT_BUFFERS,
      .rxLowThreshold         = TCPIP_EMAC_RX_LOW_THRESHOLD,
      .rxLowFill              = TCPIP_EMAC_RX_LOW_FILL,
      .linkInitDelay          = TCPIP_EMAC_PHY_LINK_INIT_DELAY,
      .ethFlags               = TCPIP_EMAC_ETH_OPEN_FLAGS,
      .ethModuleId            = TCPIP_EMAC_MODULE_ID,
      .pPhyBase               = &DRV_ETHPHY_OBJECT_BASE_Default,
      .pPhyInit               = &tcpipPhyInitData,
  };
  
  /**** Network Configuration Fata ***/
  const TCPIP_NETWORK_CONFIG __attribute__((unused))  TCPIP_HOSTS_CONFIGURATION[] =
  {
  /*** Network Configuration Index 0 ***/
      {
          TCPIP_NETWORK_DEFAULT_INTERFACE_NAME,       // interface
          TCPIP_NETWORK_DEFAULT_HOST_NAME,            // hostName
          TCPIP_NETWORK_DEFAULT_MAC_ADDR,             // macAddr
          TCPIP_NETWORK_DEFAULT_IP_ADDRESS,           // ipAddr
          TCPIP_NETWORK_DEFAULT_IP_MASK,              // ipMask
          TCPIP_NETWORK_DEFAULT_GATEWAY,              // gateway
          TCPIP_NETWORK_DEFAULT_DNS,                  // priDNS
          TCPIP_NETWORK_DEFAULT_SECOND_DNS,           // secondDNS
          TCPIP_NETWORK_DEFAULT_POWER_MODE,           // powerMode
          TCPIP_NETWORK_DEFAULT_INTERFACE_FLAGS,      // startFlags
         &TCPIP_NETWORK_DEFAULT_MAC_DRIVER,           // pMacObject
      },
  };
  
  
  #if 0
  
  /*** Zeroconfig initialization data ***/
  const ZCLL_MODULE_CONFIG tcpipZCLLInitData =
  {
  };
  
  
  
  
  /*** DNS Client Initialization Data ***/
  const TCPIP_DNS_CLIENT_MODULE_CONFIG tcpipDNSClientInitData =
  {
      .deleteOldLease         = TCPIP_DNS_CLIENT_DELETE_OLD_ENTRIES,
      .cacheEntries           = TCPIP_DNS_CLIENT_CACHE_ENTRIES,
      .entrySolvedTmo         = TCPIP_DNS_CLIENT_CACHE_ENTRY_TMO,    
      .nIPv4Entries  = TCPIP_DNS_CLIENT_CACHE_PER_IPV4_ADDRESS,
      .ipAddressType       = TCPIP_DNS_CLIENT_ADDRESS_TYPE,
      .nIPv6Entries  = TCPIP_DNS_CLIENT_CACHE_PER_IPV6_ADDRESS,
  };
  
  
  
  
  TCPIP_STACK_HEAP_INTERNAL_CONFIG tcpipHeapConfig =
  {
      .heapType = TCPIP_STACK_HEAP_TYPE_INTERNAL_HEAP,
      .heapFlags = TCPIP_STACK_HEAP_USE_FLAGS,
      .heapUsage = TCPIP_STACK_HEAP_USAGE_CONFIG,
      .malloc_fnc = TCPIP_STACK_MALLOC_FUNC,
      .calloc_fnc = TCPIP_STACK_CALLOC_FUNC,
      .free_fnc = TCPIP_STACK_FREE_FUNC,
      .heapSize = TCPIP_STACK_DRAM_SIZE,
  };
   
  const TCPIP_STACK_MODULE_CONFIG TCPIP_STACK_MODULE_CONFIG_TBL [] =
  {
      {TCPIP_MODULE_IPV4,             0},
      {TCPIP_MODULE_ICMP,             0},                             // TCPIP_MODULE_ICMP
      {TCPIP_MODULE_ARP,              &tcpipARPInitData},             // TCPIP_MODULE_ARP
      {TCPIP_MODULE_UDP,              &tcpipUDPInitData},             // TCPIP_MODULE_UDP
      {TCPIP_MODULE_TCP,              &tcpipTCPInitData},             // TCPIP_MODULE_TCP
      {TCPIP_MODULE_DHCP_CLIENT,      &tcpipDHCPInitData},            // TCPIP_MODULE_DHCP_CLIENT
      {TCPIP_MODULE_ANNOUNCE,         &tcpipAnnounceInitData},        // TCPIP_MODULE_ANNOUNCE
      {TCPIP_MODULE_DNS_CLIENT,       &tcpipDNSClientInitData},       // TCPIP_MODULE_DNS_CLIENT
      {TCPIP_MODULE_NBNS,             &tcpipNBNSInitData},            // TCPIP_MODULE_NBNS
  
      {TCPIP_MODULE_ZCLL,             0},                             // TCPIP_MODULE_ZCLL,
      { TCPIP_MODULE_MANAGER,         &tcpipHeapConfig },             // TCPIP_MODULE_MANAGER
      // MAC modules
      {TCPIP_MODULE_MAC_PIC32INT,     &tcpipMACPIC32INTInitData},     // TCPIP_MODULE_MAC_PIC32INT
  
  };
  
  /*********************************************************************
   * Function:        SYS_MODULE_OBJ TCPIP_STACK_Init()
   *
   * PreCondition:    None
   *
   * Input:
   *
   * Output:          valid system module object if Stack and its componets are initialized
   *                  SYS_MODULE_OBJ_INVALID otherwise
   *
   * Overview:        The function starts the initialization of the stack.
   *                  If an error occurs, the SYS_ERROR() is called
   *                  and the function de-initialize itself and will return false.
   *
   * Side Effects:    None
   *
   * Note:            This function must be called before any of the
   *                  stack or its component routines are used.
   *
   ********************************************************************/
  
  SYS_MODULE_OBJ TCPIP_STACK_Init()
  {
      TCPIP_STACK_INIT    tcpipInit;
  
      tcpipInit.moduleInit.sys.powerState = SYS_MODULE_POWER_RUN_FULL;
      tcpipInit.pNetConf = TCPIP_HOSTS_CONFIGURATION;
      tcpipInit.nNets = sizeof (TCPIP_HOSTS_CONFIGURATION) / sizeof (*TCPIP_HOSTS_CONFIGURATION);
      tcpipInit.pModConfig = TCPIP_STACK_MODULE_CONFIG_TBL;
      tcpipInit.nModules = sizeof (TCPIP_STACK_MODULE_CONFIG_TBL) / sizeof (*TCPIP_STACK_MODULE_CONFIG_TBL);
  
      return TCPIP_STACK_Initialize(0, &tcpipInit.moduleInit);
  }
  #endif
  // </editor-fold>
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: System Initialization
  // *****************************************************************************
  // *****************************************************************************
  
  /*******************************************************************************
    Function:
      void SYS_Initialize ( void *data )
  
    Summary:
      Initializes the board, services, drivers, application and other modules.
  
    Remarks:
      See prototype in system/common/sys_module.h.
   */
  
  void SYS_Initialize ( void* data )
  {
      /* Core Processor Initialization */
      SYS_CLK_Initialize( NULL );
      SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)NULL);
      SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
      SYS_DEVCON_JTAGEnable();
      SYS_PORTS_Initialize();
  
      /* Board Support Package Initialization */
      BSP_Initialize();        
  
      /* Initialize Drivers */
  
      sysObj.sysDma = SYS_DMA_Initialize((SYS_MODULE_INIT *)&sysDmaInit);
      SYS_INT_VectorPrioritySet(INT_VECTOR_DMA0, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_DMA0, INT_SUBPRIORITY_LEVEL0);
      SYS_INT_VectorPrioritySet(INT_VECTOR_DMA1, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_DMA1, INT_SUBPRIORITY_LEVEL0);
  
      SYS_INT_SourceEnable(INT_SOURCE_DMA_0);
      SYS_INT_SourceEnable(INT_SOURCE_DMA_1);
  
  
  
      /*** SPI Driver Index 0 initialization***/
  
      SYS_INT_VectorPrioritySet(DRV_SPI_TX_INT_VECTOR_IDX0, DRV_SPI_TX_INT_PRIORITY_IDX0);
      SYS_INT_VectorSubprioritySet(DRV_SPI_TX_INT_VECTOR_IDX0, DRV_SPI_TX_INT_SUB_PRIORITY_IDX0);
      SYS_INT_VectorPrioritySet(DRV_SPI_RX_INT_VECTOR_IDX0, DRV_SPI_RX_INT_PRIORITY_IDX0);
      SYS_INT_VectorSubprioritySet(DRV_SPI_RX_INT_VECTOR_IDX0, DRV_SPI_RX_INT_SUB_PRIORITY_IDX0);
      SYS_INT_VectorPrioritySet(DRV_DRV_SPI_ERROR_INT_VECTOR_IDX0, DRV_SPI_ERROR_INT_PRIORITY_IDX0);
      SYS_INT_VectorSubprioritySet(DRV_DRV_SPI_ERROR_INT_VECTOR_IDX0, DRV_SPI_ERROR_INT_SUB_PRIORITY_IDX0);
      sysObj.spiObjectIdx0 = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (const SYS_MODULE_INIT  * const)&drvSpi0InitData);
  	
      /* Initialize the MIIM Driver */
      sysObj.drvMiim = DRV_MIIM_Initialize(DRV_MIIM_INDEX_0, (const SYS_MODULE_INIT  * const)&drvMiimInitData);
  
      sysObj.drvTmr0 = DRV_TMR_Initialize(DRV_TMR_INDEX_0, (SYS_MODULE_INIT *)&drvTmr0InitData);
  
      SYS_INT_VectorPrioritySet(INT_VECTOR_T2, INT_PRIORITY_LEVEL4);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_T2, INT_SUBPRIORITY_LEVEL0);
   
   
       sysObj.drvUsart0 = DRV_USART_Initialize(DRV_USART_INDEX_0, (SYS_MODULE_INIT *)&drvUsart0InitData);
      SYS_INT_VectorPrioritySet(INT_VECTOR_UART1_TX, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_UART1_TX, INT_SUBPRIORITY_LEVEL0);
      SYS_INT_VectorPrioritySet(INT_VECTOR_UART1_RX, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_UART1_RX, INT_SUBPRIORITY_LEVEL0);
      SYS_INT_VectorPrioritySet(INT_VECTOR_UART1_FAULT, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_UART1_FAULT, INT_SUBPRIORITY_LEVEL0);
  
      /* Initialize System Services */
  
      /*** Command Service Initialization Code ***/
      SYS_CMD_Initialize((SYS_MODULE_INIT*)&sysCmdInit);
      sysObj.sysConsole0 = SYS_CONSOLE_Initialize(SYS_CONSOLE_INDEX_0, (SYS_MODULE_INIT *)&consUsartInit0);
  
  
      /*** Debug Service Initialization Code ***/
      sysObj.sysDebug = SYS_DEBUG_Initialize(SYS_DEBUG_INDEX_0, (SYS_MODULE_INIT*)&debugInit);
  
      /*** Interrupt Service Initialization Code ***/
      SYS_INT_Initialize();
  
      /*** Random Service Initialization Code ***/
      SYS_RANDOM_Initialize(0, 0);
  
      /*** TMR Service Initialization Code ***/
      sysObj.sysTmr  = SYS_TMR_Initialize(SYS_TMR_INDEX_0, (const SYS_MODULE_INIT  * const)&sysTmrInitData);
  
      /* Initialize Middleware */
  
      /* set priority for ETHERNET interrupt source */
      SYS_INT_VectorPrioritySet(INT_VECTOR_ETH, INT_PRIORITY_LEVEL5);
  
      /* set sub-priority for ETHERNET interrupt source */
      SYS_INT_VectorSubprioritySet(INT_VECTOR_ETH, INT_SUBPRIORITY_LEVEL3);
      /* TCPIP Stack Initialization */
  #if 0
      sysObj.tcpip = TCPIP_STACK_Init();
      SYS_ASSERT(sysObj.tcpip != SYS_MODULE_OBJ_INVALID, "TCPIP_STACK_Init Failed" );
  
      /* Initialize the Application */
      APP_Initialize();
  #endif
  }
  
  
  /*******************************************************************************
   End of File
  */
  
  