/***************************************************************************//**
* \file .h
* \version 3.20
*
* \brief
*  This file provides private function prototypes and constants for the 
*  USBFS component. It is not intended to be used in the user project.
*
********************************************************************************
* \copyright
* Copyright 2013-2016, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/

#if !defined(CY_USBFS_CDC_pvt_H)
#define CY_USBFS_CDC_pvt_H

#include "CDC.h"
   
#ifdef CDC_ENABLE_AUDIO_CLASS
    #include "CDC_audio.h"
#endif /* CDC_ENABLE_AUDIO_CLASS */

#ifdef CDC_ENABLE_CDC_CLASS
    #include "CDC_cdc.h"
#endif /* CDC_ENABLE_CDC_CLASS */

#if (CDC_ENABLE_MIDI_CLASS)
    #include "CDC_midi.h"
#endif /* (CDC_ENABLE_MIDI_CLASS) */

#if (CDC_ENABLE_MSC_CLASS)
    #include "CDC_msc.h"
#endif /* (CDC_ENABLE_MSC_CLASS) */

#if (CDC_EP_MANAGEMENT_DMA)
    #if (CY_PSOC4)
        #include <CyDMA.h>
    #else
        #include <CyDmac.h>
        #if ((CDC_EP_MANAGEMENT_DMA_AUTO) && (CDC_EP_DMA_AUTO_OPT == 0u))
            #include "CDC_EP_DMA_Done_isr.h"
            #include "CDC_EP8_DMA_Done_SR.h"
            #include "CDC_EP17_DMA_Done_SR.h"
        #endif /* ((CDC_EP_MANAGEMENT_DMA_AUTO) && (CDC_EP_DMA_AUTO_OPT == 0u)) */
    #endif /* (CY_PSOC4) */
#endif /* (CDC_EP_MANAGEMENT_DMA) */

#if (CDC_DMA1_ACTIVE)
    #include "CDC_ep1_dma.h"
    #define CDC_EP1_DMA_CH     (CDC_ep1_dma_CHANNEL)
#endif /* (CDC_DMA1_ACTIVE) */

#if (CDC_DMA2_ACTIVE)
    #include "CDC_ep2_dma.h"
    #define CDC_EP2_DMA_CH     (CDC_ep2_dma_CHANNEL)
#endif /* (CDC_DMA2_ACTIVE) */

#if (CDC_DMA3_ACTIVE)
    #include "CDC_ep3_dma.h"
    #define CDC_EP3_DMA_CH     (CDC_ep3_dma_CHANNEL)
#endif /* (CDC_DMA3_ACTIVE) */

#if (CDC_DMA4_ACTIVE)
    #include "CDC_ep4_dma.h"
    #define CDC_EP4_DMA_CH     (CDC_ep4_dma_CHANNEL)
#endif /* (CDC_DMA4_ACTIVE) */

#if (CDC_DMA5_ACTIVE)
    #include "CDC_ep5_dma.h"
    #define CDC_EP5_DMA_CH     (CDC_ep5_dma_CHANNEL)
#endif /* (CDC_DMA5_ACTIVE) */

#if (CDC_DMA6_ACTIVE)
    #include "CDC_ep6_dma.h"
    #define CDC_EP6_DMA_CH     (CDC_ep6_dma_CHANNEL)
#endif /* (CDC_DMA6_ACTIVE) */

#if (CDC_DMA7_ACTIVE)
    #include "CDC_ep7_dma.h"
    #define CDC_EP7_DMA_CH     (CDC_ep7_dma_CHANNEL)
#endif /* (CDC_DMA7_ACTIVE) */

#if (CDC_DMA8_ACTIVE)
    #include "CDC_ep8_dma.h"
    #define CDC_EP8_DMA_CH     (CDC_ep8_dma_CHANNEL)
#endif /* (CDC_DMA8_ACTIVE) */


/***************************************
*     Private Variables
***************************************/

/* Generated external references for descriptors. */
extern const uint8 CYCODE CDC_DEVICE0_DESCR[18u];
extern const uint8 CYCODE CDC_DEVICE0_CONFIGURATION0_DESCR[67u];
extern const T_CDC_EP_SETTINGS_BLOCK CYCODE CDC_DEVICE0_CONFIGURATION0_EP_SETTINGS_TABLE[3u];
extern const uint8 CYCODE CDC_DEVICE0_CONFIGURATION0_INTERFACE_CLASS[2u];
extern const T_CDC_LUT CYCODE CDC_DEVICE0_CONFIGURATION0_TABLE[5u];
extern const T_CDC_LUT CYCODE CDC_DEVICE0_TABLE[3u];
extern const T_CDC_LUT CYCODE CDC_TABLE[1u];
extern const uint8 CYCODE CDC_SN_STRING_DESCRIPTOR[2];
extern const uint8 CYCODE CDC_STRING_DESCRIPTORS[159u];


extern const uint8 CYCODE CDC_MSOS_DESCRIPTOR[CDC_MSOS_DESCRIPTOR_LENGTH];
extern const uint8 CYCODE CDC_MSOS_CONFIGURATION_DESCR[CDC_MSOS_CONF_DESCR_LENGTH];
#if defined(CDC_ENABLE_IDSN_STRING)
    extern uint8 CDC_idSerialNumberStringDescriptor[CDC_IDSN_DESCR_LENGTH];
#endif /* (CDC_ENABLE_IDSN_STRING) */

extern volatile uint8 CDC_interfaceNumber;
extern volatile uint8 CDC_interfaceSetting[CDC_MAX_INTERFACES_NUMBER];
extern volatile uint8 CDC_interfaceSettingLast[CDC_MAX_INTERFACES_NUMBER];
extern volatile uint8 CDC_deviceAddress;
extern volatile uint8 CDC_interfaceStatus[CDC_MAX_INTERFACES_NUMBER];
extern const uint8 CYCODE *CDC_interfaceClass;

extern volatile T_CDC_EP_CTL_BLOCK CDC_EP[CDC_MAX_EP];
extern volatile T_CDC_TD CDC_currentTD;

#if (CDC_EP_MANAGEMENT_DMA)
    #if (CY_PSOC4)
        extern const uint8 CDC_DmaChan[CDC_MAX_EP];
    #else
        extern uint8 CDC_DmaChan[CDC_MAX_EP];
        extern uint8 CDC_DmaTd  [CDC_MAX_EP];
    #endif /* (CY_PSOC4) */
#endif /* (CDC_EP_MANAGEMENT_DMA) */

#if (CDC_EP_MANAGEMENT_DMA_AUTO)
#if (CY_PSOC4)
    extern uint8  CDC_DmaEpBurstCnt   [CDC_MAX_EP];
    extern uint8  CDC_DmaEpLastBurstEl[CDC_MAX_EP];

    extern uint8  CDC_DmaEpBurstCntBackup  [CDC_MAX_EP];
    extern uint32 CDC_DmaEpBufferAddrBackup[CDC_MAX_EP];
    
    extern const uint8 CDC_DmaReqOut     [CDC_MAX_EP];    
    extern const uint8 CDC_DmaBurstEndOut[CDC_MAX_EP];
#else
    #if (CDC_EP_DMA_AUTO_OPT == 0u)
        extern uint8 CDC_DmaNextTd[CDC_MAX_EP];
        extern volatile uint16 CDC_inLength [CDC_MAX_EP];
        extern volatile uint8  CDC_inBufFull[CDC_MAX_EP];
        extern const uint8 CDC_epX_TD_TERMOUT_EN[CDC_MAX_EP];
        extern const uint8 *CDC_inDataPointer[CDC_MAX_EP];
    #endif /* (CDC_EP_DMA_AUTO_OPT == 0u) */
#endif /* CY_PSOC4 */
#endif /* (CDC_EP_MANAGEMENT_DMA_AUTO) */

extern volatile uint8 CDC_ep0Toggle;
extern volatile uint8 CDC_lastPacketSize;
extern volatile uint8 CDC_ep0Mode;
extern volatile uint8 CDC_ep0Count;
extern volatile uint16 CDC_transferByteCount;


/***************************************
*     Private Function Prototypes
***************************************/
void  CDC_ReInitComponent(void)            ;
void  CDC_HandleSetup(void)                ;
void  CDC_HandleIN(void)                   ;
void  CDC_HandleOUT(void)                  ;
void  CDC_LoadEP0(void)                    ;
uint8 CDC_InitControlRead(void)            ;
uint8 CDC_InitControlWrite(void)           ;
void  CDC_ControlReadDataStage(void)       ;
void  CDC_ControlReadStatusStage(void)     ;
void  CDC_ControlReadPrematureStatus(void) ;
uint8 CDC_InitControlWrite(void)           ;
uint8 CDC_InitZeroLengthControlTransfer(void) ;
void  CDC_ControlWriteDataStage(void)      ;
void  CDC_ControlWriteStatusStage(void)    ;
void  CDC_ControlWritePrematureStatus(void);
uint8 CDC_InitNoDataControlTransfer(void)  ;
void  CDC_NoDataControlStatusStage(void)   ;
void  CDC_InitializeStatusBlock(void)      ;
void  CDC_UpdateStatusBlock(uint8 completionCode) ;
uint8 CDC_DispatchClassRqst(void)          ;

void CDC_Config(uint8 clearAltSetting) ;
void CDC_ConfigAltChanged(void)        ;
void CDC_ConfigReg(void)               ;
void CDC_EpStateInit(void)             ;


const T_CDC_LUT CYCODE *CDC_GetConfigTablePtr(uint8 confIndex);
const T_CDC_LUT CYCODE *CDC_GetDeviceTablePtr(void)           ;
#if (CDC_BOS_ENABLE)
    const T_CDC_LUT CYCODE *CDC_GetBOSPtr(void)               ;
#endif /* (CDC_BOS_ENABLE) */
const uint8 CYCODE *CDC_GetInterfaceClassTablePtr(void)                    ;
uint8 CDC_ClearEndpointHalt(void)                                          ;
uint8 CDC_SetEndpointHalt(void)                                            ;
uint8 CDC_ValidateAlternateSetting(void)                                   ;

void CDC_SaveConfig(void)      ;
void CDC_RestoreConfig(void)   ;

#if (CY_PSOC3 || CY_PSOC5LP)
    #if (CDC_EP_MANAGEMENT_DMA_AUTO && (CDC_EP_DMA_AUTO_OPT == 0u))
        void CDC_LoadNextInEP(uint8 epNumber, uint8 mode)  ;
    #endif /* (CDC_EP_MANAGEMENT_DMA_AUTO && (CDC_EP_DMA_AUTO_OPT == 0u)) */
#endif /* (CY_PSOC3 || CY_PSOC5LP) */

#if defined(CDC_ENABLE_IDSN_STRING)
    void CDC_ReadDieID(uint8 descr[])  ;
#endif /* CDC_ENABLE_IDSN_STRING */

#if defined(CDC_ENABLE_HID_CLASS)
    uint8 CDC_DispatchHIDClassRqst(void) ;
#endif /* (CDC_ENABLE_HID_CLASS) */

#if defined(CDC_ENABLE_AUDIO_CLASS)
    uint8 CDC_DispatchAUDIOClassRqst(void) ;
#endif /* (CDC_ENABLE_AUDIO_CLASS) */

#if defined(CDC_ENABLE_CDC_CLASS)
    uint8 CDC_DispatchCDCClassRqst(void) ;
#endif /* (CDC_ENABLE_CDC_CLASS) */

#if (CDC_ENABLE_MSC_CLASS)
    #if (CDC_HANDLE_MSC_REQUESTS)
        uint8 CDC_DispatchMSCClassRqst(void) ;
    #endif /* (CDC_HANDLE_MSC_REQUESTS) */
#endif /* (CDC_ENABLE_MSC_CLASS */

CY_ISR_PROTO(CDC_EP_0_ISR);
CY_ISR_PROTO(CDC_BUS_RESET_ISR);

#if (CDC_SOF_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_SOF_ISR);
#endif /* (CDC_SOF_ISR_ACTIVE) */

#if (CDC_EP1_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_1_ISR);
#endif /* (CDC_EP1_ISR_ACTIVE) */

#if (CDC_EP2_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_2_ISR);
#endif /* (CDC_EP2_ISR_ACTIVE) */

#if (CDC_EP3_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_3_ISR);
#endif /* (CDC_EP3_ISR_ACTIVE) */

#if (CDC_EP4_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_4_ISR);
#endif /* (CDC_EP4_ISR_ACTIVE) */

#if (CDC_EP5_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_5_ISR);
#endif /* (CDC_EP5_ISR_ACTIVE) */

#if (CDC_EP6_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_6_ISR);
#endif /* (CDC_EP6_ISR_ACTIVE) */

#if (CDC_EP7_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_7_ISR);
#endif /* (CDC_EP7_ISR_ACTIVE) */

#if (CDC_EP8_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_EP_8_ISR);
#endif /* (CDC_EP8_ISR_ACTIVE) */

#if (CDC_EP_MANAGEMENT_DMA)
    CY_ISR_PROTO(CDC_ARB_ISR);
#endif /* (CDC_EP_MANAGEMENT_DMA) */

#if (CDC_DP_ISR_ACTIVE)
    CY_ISR_PROTO(CDC_DP_ISR);
#endif /* (CDC_DP_ISR_ACTIVE) */

#if (CY_PSOC4)
    CY_ISR_PROTO(CDC_INTR_HI_ISR);
    CY_ISR_PROTO(CDC_INTR_MED_ISR);
    CY_ISR_PROTO(CDC_INTR_LO_ISR);
    #if (CDC_LPM_ACTIVE)
        CY_ISR_PROTO(CDC_LPM_ISR);
    #endif /* (CDC_LPM_ACTIVE) */
#endif /* (CY_PSOC4) */

#if (CDC_EP_MANAGEMENT_DMA_AUTO)
#if (CY_PSOC4)
    #if (CDC_DMA1_ACTIVE)
        void CDC_EP1_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA1_ACTIVE) */

    #if (CDC_DMA2_ACTIVE)
        void CDC_EP2_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA2_ACTIVE) */

    #if (CDC_DMA3_ACTIVE)
        void CDC_EP3_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA3_ACTIVE) */

    #if (CDC_DMA4_ACTIVE)
        void CDC_EP4_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA4_ACTIVE) */

    #if (CDC_DMA5_ACTIVE)
        void CDC_EP5_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA5_ACTIVE) */

    #if (CDC_DMA6_ACTIVE)
        void CDC_EP6_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA6_ACTIVE) */

    #if (CDC_DMA7_ACTIVE)
        void CDC_EP7_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA7_ACTIVE) */

    #if (CDC_DMA8_ACTIVE)
        void CDC_EP8_DMA_DONE_ISR(void);
    #endif /* (CDC_DMA8_ACTIVE) */

#else
    #if (CDC_EP_DMA_AUTO_OPT == 0u)
        CY_ISR_PROTO(CDC_EP_DMA_DONE_ISR);
    #endif /* (CDC_EP_DMA_AUTO_OPT == 0u) */
#endif /* (CY_PSOC4) */
#endif /* (CDC_EP_MANAGEMENT_DMA_AUTO) */


/***************************************
*         Request Handlers
***************************************/

uint8 CDC_HandleStandardRqst(void) ;
uint8 CDC_DispatchClassRqst(void)  ;
uint8 CDC_HandleVendorRqst(void)   ;


/***************************************
*    HID Internal references
***************************************/

#if defined(CDC_ENABLE_HID_CLASS)
    void CDC_FindReport(void)            ;
    void CDC_FindReportDescriptor(void)  ;
    void CDC_FindHidClassDecriptor(void) ;
#endif /* CDC_ENABLE_HID_CLASS */


/***************************************
*    MIDI Internal references
***************************************/

#if defined(CDC_ENABLE_MIDI_STREAMING)
    void CDC_MIDI_IN_EP_Service(void)  ;
#endif /* (CDC_ENABLE_MIDI_STREAMING) */


/***************************************
*    CDC Internal references
***************************************/

#if defined(CDC_ENABLE_CDC_CLASS)

    typedef struct
    {
        uint8  bRequestType;
        uint8  bNotification;
        uint8  wValue;
        uint8  wValueMSB;
        uint8  wIndex;
        uint8  wIndexMSB;
        uint8  wLength;
        uint8  wLengthMSB;
        uint8  wSerialState;
        uint8  wSerialStateMSB;
    } t_CDC_cdc_notification;

    uint8 CDC_GetInterfaceComPort(uint8 interface) ;
    uint8 CDC_Cdc_EpInit( const T_CDC_EP_SETTINGS_BLOCK CYCODE *pEP, uint8 epNum, uint8 cdcComNums) ;

    extern volatile uint8  CDC_cdc_dataInEpList[CDC_MAX_MULTI_COM_NUM];
    extern volatile uint8  CDC_cdc_dataOutEpList[CDC_MAX_MULTI_COM_NUM];
    extern volatile uint8  CDC_cdc_commInEpList[CDC_MAX_MULTI_COM_NUM];
#endif /* (CDC_ENABLE_CDC_CLASS) */


#endif /* CY_USBFS_CDC_pvt_H */


/* [] END OF FILE */
