UMEHOSHI ITA TOP PAGE COMPUTER SHIEN LAB
/******************************************************************************* MPLAB Harmony Project Main Source File Company: Microchip Technology Inc. File Name: main.c Summary: This file contains the "main" function for an MPLAB Harmony project. Description: This file contains the "main" function for an MPLAB Harmony project. The "main" function calls the "SYS_Initialize" function to initialize the state machines of all MPLAB Harmony modules in the system and it calls the "SYS_Tasks" function from within a system-wide "super" loop to maintain their correct operation. These two functions are implemented in configuration-specific files (usually "system_init.c" and "system_tasks.c") in a configuration-specific folder under the "src/system_config" folder within this project's top-level folder. An MPLAB Harmony project may have more than one configuration, each contained within it's own folder under the "system_config" folder. *******************************************************************************/ // DOM-IGNORE-BEGIN /******************************************************************************* Copyright (c) 2013-2014 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 <stddef.h> // Defines NULL #include <stdbool.h> // Defines true #include <stdlib.h> // Defines EXIT_FAILURE #include "system/common/sys_module.h" // SYS function prototypes #include <stdio.h> #include "my_sys.h" // ***************************************************************************** // ***************************************************************************** // Section: Main Entry Point // ***************************************************************************** // ***************************************************************************** int main ( void ) { init_main();// my_sys.c // この内部で、init_handlers()呼び出しでハンドラテーブルと、ユーザRAMエリア初期 /* Initialize all MPLAB Harmony modules, including application(s). */ SYS_Initialize ( NULL ); init_interrupt();// my_sys.c (ユーザRAMエリアからの呼び出しも行う) while ( true ) { /* Maintain state machines of all polled MPLAB Harmony modules. */ SYS_Tasks ( ); } /* Execution should not come here during normal operation */ return ( EXIT_FAILURE ); } /******************************************************************************* End of File */
/******************************************************************************* MPLAB Harmony Application Header File Company: Microchip Technology Inc. File Name: app.h Summary: This header file provides prototypes and definitions for the application. Description: This header file provides function prototypes and data type definitions for the application. Some of these are required by the system (such as the "APP_Initialize" and "APP_Tasks" prototypes) and some of them are only used internally by the application (such as the "APP_STATES" definition). Both are defined here for convenience. *******************************************************************************/ //DOM-IGNORE-BEGIN /******************************************************************************* Copyright (c) 2013-2014 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 #ifndef _APP_H #define _APP_H // ***************************************************************************** // ***************************************************************************** // Section: Included Files // ***************************************************************************** // ***************************************************************************** #include <stdint.h> #include <stdbool.h> #include <stddef.h> #include <stdlib.h> #include "system_config.h" #include "system_definitions.h" // DOM-IGNORE-BEGIN #ifdef __cplusplus // Provide C++ Compatibility extern "C" { #endif // DOM-IGNORE-END // ***************************************************************************** // ***************************************************************************** // Section: Type Definitions // ***************************************************************************** // ***************************************************************************** // ***************************************************************************** /* Application states Summary: Application states enumeration Description: This enumeration defines the valid application states. These states determine the behavior of the application at various times. */ typedef enum { /* Application's state machine's initial state. */ APP_STATE_INIT=0, APP_STATE_SERVICE_TASKS, /* TODO: Define states used by the application state machine. */ //////////////////////////////////////////////////////////////////////////// /* Application waits for device configuration*/ APP_STATE_WAIT_FOR_CONFIGURATION, /* The application checks if a switch was pressed */ APP_STATE_CHECK_SWITCH_PRESSED, /* Wait for a character receive */ APP_STATE_SCHEDULE_READ, /* A character is received from host */ APP_STATE_WAIT_FOR_READ_COMPLETE, /* Wait for the TX to get completed */ APP_STATE_SCHEDULE_WRITE, /* Wait for the write to complete */ APP_STATE_WAIT_FOR_WRITE_COMPLETE, // 2020-0419 下記をコメント化 // APP_REQUEST_WRITE, //★2020-4-10 /* Application Error state*/ APP_STATE_ERROR //////////////////////////////////////////////////////////////////////////// } APP_STATES; // ***************************************************************************** /* Application Data Summary: Holds application data Description: This structure holds the application's data. Remarks: Application strings and buffers are be defined outside this structure. */ typedef struct { /* The application's current state */ APP_STATES state; /* TODO: Define any additional data used by the application. */ //////////////////////////////////////////////////////////////////////////// /* Device layer handle returned by device layer open function */ USB_DEVICE_HANDLE deviceHandle; /* Set Line Coding Data */ USB_CDC_LINE_CODING setLineCodingData; /* Device configured state */ bool isConfigured; /* Get Line Coding Data */ USB_CDC_LINE_CODING getLineCodingData;//USB CDC ? /* Control Line State */ USB_CDC_CONTROL_LINE_STATE controlLineStateData; /* Read transfer handle */ USB_DEVICE_CDC_TRANSFER_HANDLE readTransferHandle; /* Write transfer handle */ USB_DEVICE_CDC_TRANSFER_HANDLE writeTransferHandle; /* True if a character was read */ bool isReadComplete; /* True if a character was written*/ bool isWriteComplete; /* True is switch was pressed */ bool isSwitchPressed; /* True if the switch press needs to be ignored*/ bool ignoreSwitchPress; /* Flag determines SOF event occurrence */ bool sofEventHasOccurred; /* Break data */ uint16_t breakData; /* Switch debounce timer */ unsigned int switchDebounceTimer; unsigned int debounceCount; /* Application CDC read buffer */ uint8_t * readBuffer; /* Number of bytes read from Host */ uint32_t numBytesRead; //////////////////////////////////////////////////////////////////////////// } APP_DATA; // ***************************************************************************** // ***************************************************************************** // Section: Application Callback Routines // ***************************************************************************** // ***************************************************************************** /* These routines are called by drivers when certain events occur. */ // ***************************************************************************** // ***************************************************************************** // Section: Application Initialization and State Machine Functions // ***************************************************************************** // ***************************************************************************** /******************************************************************************* Function: void APP_Initialize ( void ) Summary: MPLAB Harmony application initialization routine. Description: This function initializes the Harmony application. It places the application in its initial state and prepares it to run so that its APP_Tasks function can be called. Precondition: All other system initialization routines should be called before calling this routine (in "SYS_Initialize"). Parameters: None. Returns: None. Example: <code> APP_Initialize(); </code> Remarks: This routine must be called from the SYS_Initialize function. */ void APP_Initialize ( void ); /******************************************************************************* Function: void APP_Tasks ( void ) Summary: MPLAB Harmony Demo application tasks function Description: This routine is the Harmony Demo application's tasks function. It defines the application's state machine and core logic. Precondition: The system and application initialization ("SYS_Initialize") should be called before calling this. Parameters: None. Returns: None. Example: <code> APP_Tasks(); </code> Remarks: This routine must be called from SYS_Tasks() routine. */ void APP_Tasks( void ); #endif /* _APP_H */ //DOM-IGNORE-BEGIN #ifdef __cplusplus } #endif //DOM-IGNORE-END /******************************************************************************* End of File */
/******************************************************************************* MPLAB Harmony Application Source File Company: Microchip Technology Inc. File Name: app.c Summary: This file contains the source code for the MPLAB Harmony application. Description: This file contains the source code for the MPLAB Harmony application. It implements the logic of the application's state machine and it may call API routines of other MPLAB Harmony modules in the system, such as drivers, system services, and middleware. However, it does not call any of the system interfaces (such as the "Initialize" and "Tasks" functions) of any of the modules in the system or make any assumptions about when those functions are called. That is the responsibility of the configuration-specific system files. *******************************************************************************/ // DOM-IGNORE-BEGIN /******************************************************************************* Copyright (c) 2013-2014 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 "app.h" //////////////////////////////////////////////////////////////////////////////// #include "my_app.h" #include "common.h" // ***************************************************************************** // ***************************************************************************** // Section: Global Data Definitions // ***************************************************************************** // ***************************************************************************** // ***************************************************************************** /* Application Data Summary: Holds application data Description: This structure holds the application's data. Remarks: This structure should be initialized by the APP_Initialize function. Application strings and buffers are be defined outside this structure. */ APP_DATA appData; // ***************************************************************************** // ***************************************************************************** // Section: Application Callback Functions // ***************************************************************************** // ***************************************************************************** /* TODO: Add any necessary callback functions. */ // ***************************************************************************** // ***************************************************************************** // Section: Application Local Functions // ***************************************************************************** // ***************************************************************************** /* TODO: Add any necessary local functions. */ // ***************************************************************************** // ***************************************************************************** // Section: Application Initialization and State Machine Functions // ***************************************************************************** // ***************************************************************************** /******************************************************************************* Function: void APP_Initialize ( void ) Remarks: See prototype in app.h. */ void APP_Initialize ( void ) { /* Place the App state machine in its initial state. */ appData.state = APP_STATE_INIT; /* TODO: Initialize your application's state machine and other * parameters. */ Init_Usb(); } /****************************************************************************** Function: void APP_Tasks ( void ) Remarks: See prototype in app.h. */ void APP_Tasks ( void ) { /* Check the application's current state. */ switch ( appData.state ) { /* Application's initial state. */ case APP_STATE_INIT: { bool appInitialized = true; if (appInitialized) { appData.state = APP_STATE_SERVICE_TASKS; } break; } case APP_STATE_SERVICE_TASKS: { //////////////////////////////////////////////////////////////////// appData.deviceHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE ); if(appData.deviceHandle != USB_DEVICE_HANDLE_INVALID) { /* Register a callback with device layer to get event notification (for end point 0) */ USB_DEVICE_EventHandlerSet(appData.deviceHandle, APP_USBDeviceEventHandler, 0); appData.state = APP_STATE_WAIT_FOR_CONFIGURATION; } //////////////////////////////////////////////////////////////////// break; } /* TODO: implement your application state machine.*/ /* The default state should never be executed. */ default: { /* TODO: Handle error in application's state machine. */ /////////////////////////////////////////////////////////////////// _my_app_tasks(); //My_APP_Tasks () または My_APP_Tasks_Through(); break; } } } /******************************************************************************* End of File */