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 (c) 2013-2015 released Microchip Technology Inc.  All rights reserved.
  
  Microchip licenses to you the right to use, modify, copy and distribute
  Software only when embedded on a Microchip microcontroller or digital signal
  controller that is integrated into your product or third party product
  (pursuant to the sublicense terms in the accompanying license agreement).
  
  You should refer to the license agreement accompanying this Software for
  additional information regarding your rights and obligations.
  
  SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
  IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
  CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
  OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
  CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
  SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
   *******************************************************************************/
  // 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_PGx1
  #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 =    HS
  #pragma config OSCIOFNC =   OFF
  #pragma config FCKSM =      CSECME
  #pragma config WDTPS =      PS1048576
  #pragma config WDTSPGM =    STOP
  #pragma config FWDTEN =     OFF
  #pragma config WINDIS =     NORMAL
  #pragma config FWDTWINSZ =  WINSZ_25
  #pragma config DMTCNT =     DMT31
  #pragma config FDMTEN =     OFF
  /*** DEVCFG2 ***/
  
  #pragma config FPLLIDIV =   DIV_1
  #pragma config FPLLRNG =    RANGE_5_10_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 =     ON
  #pragma config FETHIO =     ON
  #pragma config PGL1WAY =    ON
  #pragma config PMDL1WAY =   ON
  #pragma config IOL1WAY =    ON
  #pragma config FUSBIDIO =   ON
  
  /*** BF1SEQ0 ***/
  
  #pragma config TSEQ =       0x0000
  #pragma config CSEQ =       0xffff
  // </editor-fold>
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Driver 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_16_BIT,
      .interruptSource = DRV_TMR_INTERRUPT_SOURCE_IDX0,
      .asyncWriteEnable = false,
  };
  // <editor-fold defaultstate="collapsed" desc="DRV_USB Initialization Data">
  /******************************************************
   * USB Driver Initialization
   ******************************************************/
  const DRV_USBHS_INIT drvUSBHSInit =
  {
      /* Interrupt Source for USB module */
      .interruptSource = INT_SOURCE_USB_1,
      
      /* Interrupt Source for USB module */
      .interruptSourceUSBDma = INT_SOURCE_USB_1_DMA,
  
      /* System module initialization */
      .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
  
      /* Operation Mode */
      .operationMode = DRV_USBHS_OPMODE_DEVICE,
  
      /* Operation Speed */ 
      .operationSpeed = USB_SPEED_HIGH,
      
      /* Stop in idle */
      .stopInIdle = false,
  
      /* Suspend in sleep */
      .suspendInSleep = false,
  
      /* Identifies peripheral (PLIB-level) ID */
      .usbID = USBHS_ID_0,
      
  };
  // </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_CONSOLE Initialization Data">
  /*** System Console Initialization Data ***/
  
  SYS_MODULE_OBJ sysConsoleObjects[] = { SYS_MODULE_OBJ_INVALID };
  
  /* Declared in console device implementation (sys_console_usb_cdc.c) */
  extern SYS_CONSOLE_DEV_DESC consUsbCdcDevDesc;
  
  SYS_CONSOLE_INIT consUsbInit0 =
  {
      .moduleInit = {0},
      .consDevDesc = &consUsbCdcDevDesc,
  };
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="SYS_FS Initialization Data">
  /*** File System Initialization Data ***/
  
  const SYS_FS_MEDIA_MOUNT_DATA sysfsMountTable[SYS_FS_VOLUME_NUMBER] = 
  {
  	{NULL}
  };
  
  
  
  
  // </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="USB Stack Initialization Data">
  
  
  /**************************************************
   * USB Device Function Driver Init Data
   **************************************************/
      const USB_DEVICE_CDC_INIT cdcInit0 =
      {
          .queueSizeRead = 1,
          .queueSizeWrite = 1,
          .queueSizeSerialStateNotification = 1
      };
  /**************************************************
   * USB Device Layer Function Driver Registration 
   * Table
   **************************************************/
  const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
  {
      /* Function 1 */
      { 
          .configurationValue = 1,    /* Configuration value */ 
          .interfaceNumber = 0,       /* First interfaceNumber of this function */ 
          .speed = USB_SPEED_HIGH|USB_SPEED_FULL,    /* Function Speed */ 
          .numberOfInterfaces = 2,    /* Number of interfaces */
          .funcDriverIndex = 0,  /* Index of CDC Function Driver */
          .driver = (void*)USB_DEVICE_CDC_FUNCTION_DRIVER,    /* USB CDC function data exposed to device layer */
          .funcDriverInit = (void*)&cdcInit0    /* Function driver init data */
      },
  };
  
  /*******************************************
   * USB Device Layer Descriptors
   *******************************************/
  /*******************************************
   *  USB Device Descriptor 
   *******************************************/
  const USB_DEVICE_DESCRIPTOR deviceDescriptor =
  {
      0x12,                           // Size of this descriptor in bytes
      USB_DESCRIPTOR_DEVICE,          // DEVICE descriptor type
      0x0200,                         // USB Spec Release Number in BCD format
  	USB_CDC_CLASS_CODE,         // Class Code
      USB_CDC_SUBCLASS_CODE,      // Subclass code
      0x00,                       // Protocol code
      USB_DEVICE_EP0_BUFFER_SIZE,     // Max packet size for EP0, see system_config.h
      0x04D8,                         // Vendor ID
      0x000A,                         // Product ID
      0x0100,                         // Device release number in BCD format
      0x01,                           // Manufacturer string index
      0x02,                           // Product string index
      0x00,                           // Device serial number string index
      0x01                            // Number of possible configurations
  };
  
  /*******************************************
   *  USB Device Qualifier Descriptor for this
   *  demo.
   *******************************************/
  const USB_DEVICE_QUALIFIER deviceQualifierDescriptor1 =
  {
      0x0A,                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_DEVICE_QUALIFIER,    // Device Qualifier Type
      0x0200,                             // USB Specification Release number
  	USB_CDC_CLASS_CODE,         // Class Code
      USB_CDC_SUBCLASS_CODE,      // Subclass code
      0x00,                       // Protocol code
      USB_DEVICE_EP0_BUFFER_SIZE,         // Maximum packet size for endpoint 0
      0x01,                               // Number of possible configurations
      0x00                                // Reserved for future use.
  };
  
  /*******************************************
   *  USB High Speed Configuration Descriptor
   *******************************************/
   
  const uint8_t highSpeedConfigurationDescriptor[]=
  {
      /* Configuration Descriptor */
  
      0x09,                                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_CONFIGURATION,                       // Descriptor Type
      67,0,                //(67 Bytes)Size of the Config descriptor.e
      2,                                               // Number of interfaces in this cfg
      0x01,                                               // Index value of this configuration
      0x00,                                               // Configuration string index
      USB_ATTRIBUTE_DEFAULT | USB_ATTRIBUTE_SELF_POWERED, // Attributes
      50,                                                 // Max power consumption (2X mA)
      
      /* Descriptor for Function 1 - CDC     */ 
      
      /* Interface Descriptor */
  
      0x09,                                           // Size of this descriptor in bytes
      USB_DESCRIPTOR_INTERFACE,                       // Descriptor Type
      0,                                  // Interface Number
      0x00,                                           // Alternate Setting Number
      0x01,                                           // Number of endpoints in this interface
      USB_CDC_COMMUNICATIONS_INTERFACE_CLASS_CODE,    // Class code
      USB_CDC_SUBCLASS_ABSTRACT_CONTROL_MODEL,        // Subclass code
      USB_CDC_PROTOCOL_AT_V250,                       // Protocol code
      0x00,                                           // Interface string index
  
      /* CDC Class-Specific Descriptors */
  
      sizeof(USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR),               // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_HEADER,                                  // Type of functional descriptor
      0x20,0x01,                                                  // CDC spec version
  
      sizeof(USB_CDC_ACM_FUNCTIONAL_DESCRIPTOR),                  // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_ABSTRACT_CONTROL_MANAGEMENT,             // Type of functional descriptor
      USB_CDC_ACM_SUPPORT_LINE_CODING_LINE_STATE_AND_NOTIFICATION,// bmCapabilities of ACM
  
      sizeof(USB_CDC_UNION_FUNCTIONAL_DESCRIPTOR_HEADER) + 1,     // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_UNION,                                   // Type of functional descriptor
      0,                                                       // com interface number
      1,
  
      sizeof(USB_CDC_CALL_MANAGEMENT_DESCRIPTOR),                 // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_CALL_MANAGEMENT,                         // Type of functional descriptor
      0x00,                                                       // bmCapabilities of CallManagement
      1,                                                       // Data interface number
  
      /* Interrupt Endpoint (IN) Descriptor */
  
      0x07,                           // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
      1 | USB_EP_DIRECTION_IN,    // EndpointAddress ( EP1 IN INTERRUPT)
      USB_TRANSFER_TYPE_INTERRUPT,    // Attributes type of EP (INTERRUPT)
      0x10,0x00,                      // Max packet size of this EP
      0x02,                           // Interval (in ms)
  
      /* Interface Descriptor */
  
      0x09,                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_INTERFACE,           // INTERFACE descriptor type
      1,      // Interface Number
      0x00,                               // Alternate Setting Number
      0x02,                               // Number of endpoints in this interface
      USB_CDC_DATA_INTERFACE_CLASS_CODE,  // Class code
      0x00,                               // Subclass code
      USB_CDC_PROTOCOL_NO_CLASS_SPECIFIC, // Protocol code
      0x00,                               // Interface string index
  
      /* Bulk Endpoint (OUT) Descriptor */
  
      0x07,                       // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
      2 | USB_EP_DIRECTION_OUT,   // EndpointAddress ( EP2 OUT )
      USB_TRANSFER_TYPE_BULK,     // Attributes type of EP (BULK)
      0x00, 0x02,                 // Max packet size of this EP
      0x00,                       // Interval (in ms)
  
       /* Bulk Endpoint (IN)Descriptor */
  
      0x07,                       // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
      2 | USB_EP_DIRECTION_IN,    // EndpointAddress ( EP2 IN )
      0x02,                       // Attributes type of EP (BULK)
      0x00, 0x02,                 // Max packet size of this EP
      0x00,                       // Interval (in ms)
  
  };
  
  /*******************************************
   * Array of High speed config descriptors
   *******************************************/
  USB_DEVICE_CONFIGURATION_DESCRIPTORS_TABLE highSpeedConfigDescSet[1] =
  {
      highSpeedConfigurationDescriptor
  };
  
  /*******************************************
   *  USB Full Speed Configuration Descriptor
   *******************************************/
  const uint8_t fullSpeedConfigurationDescriptor[]=
  {
      /* Configuration Descriptor */
  
      0x09,                                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_CONFIGURATION,                       // Descriptor Type
      67,0,                //(67 Bytes)Size of the Config descriptor.e
      2,                                               // Number of interfaces in this cfg
      0x01,                                               // Index value of this configuration
      0x00,                                               // Configuration string index
      USB_ATTRIBUTE_DEFAULT | USB_ATTRIBUTE_SELF_POWERED, // Attributes
      50,                                                 // Max power consumption (2X mA)
      /* Descriptor for Function 1 - CDC     */ 
      
      /* Interface Descriptor */
  
      0x09,                                           // Size of this descriptor in bytes
      USB_DESCRIPTOR_INTERFACE,                       // Descriptor Type
      0,                                  // Interface Number
      0x00,                                           // Alternate Setting Number
      0x01,                                           // Number of endpoints in this interface
      USB_CDC_COMMUNICATIONS_INTERFACE_CLASS_CODE,    // Class code
      USB_CDC_SUBCLASS_ABSTRACT_CONTROL_MODEL,        // Subclass code
      USB_CDC_PROTOCOL_AT_V250,                       // Protocol code
      0x00,                                           // Interface string index
  
      /* CDC Class-Specific Descriptors */
  
      sizeof(USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR),               // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_HEADER,                                  // Type of functional descriptor
      0x20,0x01,                                                  // CDC spec version
  
      sizeof(USB_CDC_ACM_FUNCTIONAL_DESCRIPTOR),                  // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_ABSTRACT_CONTROL_MANAGEMENT,             // Type of functional descriptor
      USB_CDC_ACM_SUPPORT_LINE_CODING_LINE_STATE_AND_NOTIFICATION,// bmCapabilities of ACM
  
      sizeof(USB_CDC_UNION_FUNCTIONAL_DESCRIPTOR_HEADER) + 1,     // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_UNION,                                   // Type of functional descriptor
      0,                                                       // com interface number
      1,
  
      sizeof(USB_CDC_CALL_MANAGEMENT_DESCRIPTOR),                 // Size of the descriptor
      USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
      USB_CDC_FUNCTIONAL_CALL_MANAGEMENT,                         // Type of functional descriptor
      0x00,                                                       // bmCapabilities of CallManagement
      1,                                                       // Data interface number
  
      /* Interrupt Endpoint (IN) Descriptor */
  
      0x07,                           // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
      1 | USB_EP_DIRECTION_IN,    // EndpointAddress ( EP1 IN INTERRUPT)
      USB_TRANSFER_TYPE_INTERRUPT,    // Attributes type of EP (INTERRUPT)
      0x10,0x00,                      // Max packet size of this EP
      0x02,                           // Interval (in ms)
  
      /* Interface Descriptor */
  
      0x09,                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_INTERFACE,           // INTERFACE descriptor type
      1,      // Interface Number
      0x00,                               // Alternate Setting Number
      0x02,                               // Number of endpoints in this interface
      USB_CDC_DATA_INTERFACE_CLASS_CODE,  // Class code
      0x00,                               // Subclass code
      USB_CDC_PROTOCOL_NO_CLASS_SPECIFIC, // Protocol code
      0x00,                               // Interface string index
  
      /* Bulk Endpoint (OUT) Descriptor */
  
      0x07,                       // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
      2 | USB_EP_DIRECTION_OUT,   // EndpointAddress ( EP2 OUT )
      USB_TRANSFER_TYPE_BULK,     // Attributes type of EP (BULK)
      0x40,0x00,                  // Max packet size of this EP
      0x00,                       // Interval (in ms)
  
       /* Bulk Endpoint (IN)Descriptor */
  
      0x07,                       // Size of this descriptor
      USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
      2 | USB_EP_DIRECTION_IN,    // EndpointAddress ( EP2 IN )
      0x02,                       // Attributes type of EP (BULK)
      0x40,0x00,                  // Max packet size of this EP
      0x00,                       // Interval (in ms)
  
  
  };
  
  /*******************************************
   * Array of Full speed config descriptors
   *******************************************/
  USB_DEVICE_CONFIGURATION_DESCRIPTORS_TABLE fullSpeedConfigDescSet[1] =
  {
      fullSpeedConfigurationDescriptor
  };
  
  
  /**************************************
   *  String descriptors.
   *************************************/
  
   /*******************************************
   *  Language code string descriptor
   *******************************************/
      const struct
      {
          uint8_t bLength;
          uint8_t bDscType;
          uint16_t string[1];
      }
      sd000 =
      {
          sizeof(sd000),          // Size of this descriptor in bytes
          USB_DESCRIPTOR_STRING,  // STRING descriptor type
          {0x0409}                // Language ID
      };
  /*******************************************
   *  Manufacturer string descriptor
   *******************************************/
      const struct
      {
          uint8_t bLength;        // Size of this descriptor in bytes
          uint8_t bDscType;       // STRING descriptor type
          uint16_t string[25];    // String
      }
      sd001 =
      {
          sizeof(sd001),
          USB_DESCRIPTOR_STRING,
          {'M','i','c','r','o','c','h','i','p',' ','T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'}
  		
      };
  
  /*******************************************
   *  Product string descriptor
   *******************************************/
      const struct
      {
          uint8_t bLength;        // Size of this descriptor in bytes
          uint8_t bDscType;       // STRING descriptor type
          uint16_t string[22];    // String
      }
      sd002 =
      {
          sizeof(sd002),
          USB_DESCRIPTOR_STRING,
  		{'S','i','m','p','l','e',' ','C','D','C',' ','D','e','v','i','c','e',' ','D','e','m','o'}
      }; 
  
  /***************************************
   * Array of string descriptors
   ***************************************/
  USB_DEVICE_STRING_DESCRIPTORS_TABLE stringDescriptors[3]=
  {
      (const uint8_t *const)&sd000,
      (const uint8_t *const)&sd001,
      (const uint8_t *const)&sd002
  };
  
  /*******************************************
   * USB Device Layer Master Descriptor Table 
   *******************************************/
  const USB_DEVICE_MASTER_DESCRIPTOR usbMasterDescriptor =
  {
      &deviceDescriptor,          /* Full speed descriptor */
      1,                          /* Total number of full speed configurations available */
      fullSpeedConfigDescSet,     /* Pointer to array of full speed configurations descriptors*/
      &deviceDescriptor,          /* High speed device descriptor*/
      1,                          /* Total number of high speed configurations available */
      highSpeedConfigDescSet,     /* Pointer to array of high speed configurations descriptors. */
      3,                          // Total number of string descriptors available.
      stringDescriptors,          // Pointer to array of string descriptors.
      &deviceQualifierDescriptor1,// Pointer to full speed dev qualifier.
      &deviceQualifierDescriptor1 // Pointer to high speed dev qualifier.
  };
  
  
  /****************************************************
   * USB Device Layer Initialization Data
   ****************************************************/
  const USB_DEVICE_INIT usbDevInitData =
  {
      /* System module initialization */
      .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
      
      /* Number of function drivers registered to this instance of the
         USB device layer */
      .registeredFuncCount = 1,
      
      /* Function driver table registered to this instance of the USB device layer*/
      .registeredFunctions = (USB_DEVICE_FUNCTION_REGISTRATION_TABLE*)funcRegistrationTable,
  
      /* Pointer to USB Descriptor structure */
      .usbMasterDescriptor = (USB_DEVICE_MASTER_DESCRIPTOR*)&usbMasterDescriptor,
  
      /* USB Device Speed */
      .deviceSpeed = USB_SPEED_HIGH,
      
      /* Index of the USB Driver to be used by this Device Layer Instance */
      .driverIndex = DRV_USBHS_INDEX_0,
  
      /* Pointer to the USB Driver Functions. */
      .usbDriverInterface = DRV_USBHS_DEVICE_INTERFACE,
      
  };
  // </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());
  
      /* Initialize Drivers */
  
      sysObj.drvTmr0 = DRV_TMR_Initialize(DRV_TMR_INDEX_0, (SYS_MODULE_INIT *)&drvTmr0InitData);
  
  
      SYS_INT_VectorPrioritySet(INT_VECTOR_T1, INT_PRIORITY_LEVEL1);
      SYS_INT_VectorSubprioritySet(INT_VECTOR_T1, INT_SUBPRIORITY_LEVEL0);
   
   
       /* Initialize USB Driver */ 
      sysObj.drvUSBObject = DRV_USBHS_Initialize(DRV_USBHS_INDEX_0, (SYS_MODULE_INIT *) &drvUSBHSInit);
      
      /* Set priority of USB interrupt source */
      SYS_INT_VectorPrioritySet(INT_VECTOR_USB1, INT_PRIORITY_LEVEL4);
  
      /* Set Sub-priority of USB interrupt source */
      SYS_INT_VectorSubprioritySet(INT_VECTOR_USB1, INT_SUBPRIORITY_LEVEL0);
      
      /* Set the priority of the USB DMA Interrupt */
      SYS_INT_VectorPrioritySet(INT_VECTOR_USB1_DMA, INT_PRIORITY_LEVEL4);
  
      /* Set Sub-priority of the USB DMA Interrupt */
      SYS_INT_VectorSubprioritySet(INT_VECTOR_USB1_DMA, INT_SUBPRIORITY_LEVEL0);
      
  
      /* Initialize System Services */
      SYS_PORTS_Initialize();
      sysObj.sysConsole0 = SYS_CONSOLE_Initialize(SYS_CONSOLE_INDEX_0, (SYS_MODULE_INIT *)&consUsbInit0);
  
  
      /*** File System Service Initialization Code ***/
      SYS_FS_Initialize( (const void *) sysFSInit );
  
      /*** Interrupt Service Initialization Code ***/
      SYS_INT_Initialize();
  
      /*** TMR Service Initialization Code ***/
      sysObj.sysTmr  = SYS_TMR_Initialize(SYS_TMR_INDEX_0, (const SYS_MODULE_INIT  * const)&sysTmrInitData);
  
      /*** UnixFD Standard I/O Initialization Code ***/
      unixfd_init_usbcdc();
      unixfd_stdio_redirect(open(UNIXFD_STDIN_DEVICE, O_RDONLY), STDIN_FILENO);
      unixfd_stdio_redirect(open(UNIXFD_STDOUT_DEVICE, O_WRONLY), STDOUT_FILENO);
      unixfd_stdio_redirect(open(UNIXFD_STDERR_DEVICE, O_WRONLY), STDERR_FILENO);
  
      /* Initialize Middleware */
      /* Initialize the USB device layer */
      sysObj.usbDevObject0 = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 , ( SYS_MODULE_INIT* ) & usbDevInitData);
  
      /* Enable Global Interrupts */
      SYS_INT_Enable();
  
      /* Initialize the Application */
      RUN_MRB_Initialize();
  }
  
  
  /*******************************************************************************
   End of File
  */
  
  