Files
Last update 7 years 4 months
by
Mengjiao Hong
FilesHW20CarWheelCtrfirmwaresrcsystem_configdefault | |
---|---|
.. | |
framework | |
configuration.xml | |
default.mhc | |
system_config.h | |
system_definitions.h | |
system_exceptions.c | |
system_init.c | |
system_interrupt.c | |
system_tasks.c |
system_init.c/******************************************************************************* 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 PWP = OFF #pragma config BWP = OFF #pragma config CP = OFF /*** DEVCFG1 ***/ #pragma config FNOSC = PRIPLL #pragma config FSOSCEN = OFF #pragma config IESO = OFF #pragma config POSCMOD = HS #pragma config OSCIOFNC = OFF #pragma config FPBDIV = DIV_1 #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_2 #pragma config UPLLIDIV = DIV_2 #pragma config UPLLEN = ON /*** DEVCFG3 ***/ #pragma config USERID = 0xffff #pragma config PMDL1WAY = OFF #pragma config IOL1WAY = OFF #pragma config FUSBIDIO = ON #pragma config FVBUSONIO = ON // </editor-fold> // ***************************************************************************** // ***************************************************************************** // Section: Driver Initialization Data // ***************************************************************************** // ***************************************************************************** // <editor-fold defaultstate="collapsed" desc="DRV_USB Initialization Data"> /****************************************************** * USB Driver Initialization ******************************************************/ /**************************************************** * Endpoint Table needed by the Device Layer. ****************************************************/ uint8_t __attribute__((aligned(512))) endPointTable[DRV_USBFS_ENDPOINTS_NUMBER * 32]; const DRV_USBFS_INIT drvUSBInit = { /* Assign the endpoint table */ .endpointTable= endPointTable, /* Interrupt Source for USB module */ .interruptSource = INT_SOURCE_USB_1, /* System module initialization */ .moduleInit = {SYS_MODULE_POWER_RUN_FULL}, .operationMode = DRV_USBFS_OPMODE_DEVICE, .operationSpeed = USB_SPEED_FULL, /* Stop in idle */ .stopInIdle = false, /* Suspend in sleep */ .suspendInSleep = false, /* Identifies peripheral (PLIB-level) ID */ .usbID = USB_ID_1 }; // </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_DEVCON Initialization Data"> /******************************************************************************* Device Control System Service Initialization Data */ const SYS_DEVCON_INIT sysDevconInit = { .moduleInit = {0}, }; // </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_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 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*/ NULL, 0, NULL, 3, // Total number of string descriptors available. stringDescriptors, // Pointer to array of string descriptors. NULL, NULL }; /**************************************************** * 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_FULL, /* Index of the USB Driver to be used by this Device Layer Instance */ .driverIndex = DRV_USBFS_INDEX_0, /* Pointer to the USB Driver Functions. */ .usbDriverInterface = DRV_USBFS_DEVICE_INTERFACE, }; // </editor-fold> // ***************************************************************************** // ***************************************************************************** // Section: Static Initialization Functions // ***************************************************************************** // ***************************************************************************** // ***************************************************************************** // ***************************************************************************** // 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 ); sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit); SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet()); SYS_PORTS_Initialize(); /* Initialize Drivers */ /* Initialize USB Driver */ sysObj.drvUSBObject = DRV_USBFS_Initialize(DRV_USBFS_INDEX_0, (SYS_MODULE_INIT *) &drvUSBInit); /* Initialize System Services */ /*** Interrupt Service Initialization Code ***/ SYS_INT_Initialize(); /* Initialize Middleware */ /* 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); /* 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 */ APP_Initialize(); } /******************************************************************************* End of File */