/**
 * \file    usbpd_timer_defs.h
 * \brief   DPM timer definitions
 *
 * \par     Copyright (c) 2018 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2018-03-12
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2018-03-12  Original Creation
 * 
 */
 
#ifndef __DPM_TIMER_H_
#define __DPM_TIMER_H_

#include "arch.h"

#pragma pack(1)

/**
 * DPM hardware timer interval definitions
 */

/** Below Timer working at 33.1776MHz sys_clk, which period is 30ns = 1/33.1776MHz per clock */
#define T_TRANSMIT_TIMER            6500UL      // 195us, maximum value is 195 us
#define T_RECEIVE_TIMER             36666UL     // 1.1 ms
#define T_HR_COMPLT_TIMER           166666UL    // maximum 5 ms

#if 0  /* modified by James Gan - 2019-04-16 */
/**
 * DPM software timer interval definitions
 *
 * Below timer interval define in microsecond for software timer
 */
#define T_RETRANSMIT_TIMER          1000UL     // 1 ms
#define T_SWAP_SRC_START            50000UL    // 50 ms, must >= 20ms
#define T_SENDER_RESPONSE           26000UL    // 26 ms, min 24ms, max 30ms
#define T_NO_RESPONSE               5000000UL  // 5s, min 4.5s, max 5.5s
#define T_SOURCE_CAPABILITY         120000UL   // 120 ms, > min 100 ms, < max 200 ms
#define T_PS_TRANSIT                500000UL   // 500 ms, 450 ms - 550 ms
#define T_SNK_REQUEST_DELAY         1000UL     // 1 ms
#define T_SNK_REQUEST               200000UL   // 200 ms, min 100ms
#define T_SRC_TRANSIT               26000UL    // 26 ms minimal tSrcTransition time, for turnoff source
#define T_SRC_TRANSITION            25000UL    // 25 ms maximal tSrcTransition time, for src transit supply
#define T_PS_SOURCE_ON              478000UL   // 478 ms, must < 480 ms
#define T_PS_SOURCE_OFF             918000UL   // 918 ms, must < 920 ms
#define T_VCON_SOURCE_ON            100000UL   // 100 ms
#define T_VDM_SENDER_RESPONSE       30000UL    // 30 ms
#define T_VDM_WAIT_MODE_ENTRY       50000UL    // 50 ms
#define T_VDM_WAIT_MODE_EXIT        50000UL    // 50 ms
#define T_HARD_RESET_COMPLETE       5000UL     // 5 ms
#define T_PS_HARD_RESET             30000UL    // 30 ms
#define T_BIST_CONT_MODE            50000UL    // 50ms, 30 - 60 ms
#define T_NEW_SRC                   60000UL    // 60 ms, must < 275 ms
#define T_DISCOVERY_IDENTITY        50000UL    // 50 ms
#define T_ERROR_RECOVERY            100000UL    // 100ms, min 25 ms
#define T_CC_DEBOUNCE               120000UL   // 120 ms, 100 - 200 ms
#define T_PD_DEBOUNCE               15000UL    // 15 ms, 10 - 20 ms
#define T_DRP_TIMER                 95000UL    // 95 ms, 50 - 100 ms, modified by James Gan - 2017-10-19, For matching IOP test
#define T_DRP_TRY                   100000UL   // 100 ms, 75 - 150 ms
#define T_DRP_TRY_WAIT              600000UL   // 600 ms
#define T_TRY_TIMEOUT               1050000UL  // 1050 ms, 550 ms - 1100 ms
#define T_FST_SRC_CAP               150000UL   // 150 ms
#define T_SNK_WAIT_CAP              550000UL   // 550 ms
#define T_SRC_READY                 100000UL   // 100 ms, must < 285 ms
#define T_SRC_SWP_STDBY             60000UL    // 60 ms must < 650ms
//#define T_SNK_WAIT_VSAFE0V          550000UL   // 550 ms
#define T_SNK_WAIT_VSAFE0V          645000UL   // 645ms, must < 650 ms
#define T_SNK_HARD_RESET_TIMER      2100000UL  // 2.1 s, must < 650(tSafe0V)+1000(tSrcRecover)+275(tSrcTurnOn)+620(tTypeCSinkWaitCap)
#define T_SRC_RECOVER               800000UL   // 800 ms
#define T_DELAY_5MS                 5000UL     // 5 ms
#define T_DELAY_10MS                10000UL    // 10 ms
#define T_DELAY_15MS                15000UL    // 15 ms
#define T_PR_SWP_REQUEST_TIMER      800000UL   // 800 ms
#define T_PPS_TIMER                 15999000UL // 14.8 s, 12 - 15s
#define T_SNK_PPS_REQ_TIMER_SHORT   150000UL   // 150 ms
#define T_SNK_PPS_REQ_TIMER         1000000UL  // 1 s, maximal 10s
#define T_PRS_IN_PROG_TIMER         3000000UL  // 3 s
#define T_PD_DEBOUNCE_2             15000UL    // 15 ms
#define T_CHUNKING_NOT_SUPPORTED    40000UL    // 40000 us, this unit is us, range: 40000 - 50000 us
#define T_DFP_UFP_DISCOVERY_IDENTITY    1500000UL    // 1500 ms
#define T_VDM_RESPONSE_DELAY        10000UL    // 10 ms
#else
/**
 * DPM software timer interval definitions
 *
 * Below timer interval define in millisecond for software timer
 */
#define T_RETRANSMIT_TIMER          1UL     // 1 ms
#define T_SWAP_SRC_START            50UL    // 50 ms, must >= 20ms
#define T_SENDER_RESPONSE           26UL    // 26 ms, min 24ms, max 30ms
#define T_NO_RESPONSE               5000UL  // 5s, min 4.5s, max 5.5s
#define T_SOURCE_CAPABILITY         120UL   // 120 ms, > min 100 ms, < max 200 ms
#define T_PS_TRANSIT                500UL   // 500 ms, 450 ms - 550 ms
#define T_SNK_REQUEST_DELAY         1UL     // 1 ms
#define T_SNK_REQUEST               200UL   // 200 ms, min 100ms
#define T_SRC_TRANSIT               26UL    // 26 ms, 25-35ms tSrcTransition time, for turnoff source
#define T_SRC_TRANSITION            25UL    // 26 ms, 25-35ms tSrcTransition time, for src transit supply
#define T_PS_SOURCE_ON              478UL   // 478 ms, 390 - 480 ms
#define T_PS_SOURCE_OFF             918UL   // 918 ms, 750 - 920 ms
#define T_VCON_SOURCE_ON            100UL   // 100 ms
#define T_VDM_SENDER_RESPONSE       30UL    // 30 ms
#define T_VDM_WAIT_MODE_ENTRY       50UL    // 50 ms
#define T_VDM_WAIT_MODE_EXIT        50UL    // 50 ms
#define T_HARD_RESET_COMPLETE       5UL     // 5 ms
#define T_PS_HARD_RESET             30UL    // 30 ms
#define T_BIST_CONT_MODE            50UL    // 50ms, 30 - 60 ms
#define T_NEW_SRC                   60UL    // 60 ms, must < 275 ms
#define T_DISCOVERY_IDENTITY        50UL    // 50 ms
#define T_ERROR_RECOVERY            100UL   // 100ms, min 25 ms
#define T_CC_DEBOUNCE               120UL   // 120 ms, 100 - 200 ms
#define T_PD_DEBOUNCE               15UL    // 15 ms, 10 - 20 ms
#define T_DRP_TIMER                 95UL    // 95 ms, 50 - 100 ms, modified by James Gan - 2017-10-19, For matching IOP test
#define T_DRP_TRY                   100UL   // 100 ms, 75 - 150 ms
#define T_DRP_TRY_WAIT              600UL   // 600 ms
#define T_TRY_TIMEOUT               1050UL  // 1050 ms, 550 ms - 1100 ms
#define T_FST_SRC_CAP               150UL   // 150 ms
#define T_SRC_CAP_AFTER_HRST        200UL   // 200 ms
#define T_SNK_WAIT_CAP              550UL   // 550 ms
//#define T_SRC_READY                 100UL   // 100 ms, must < 285 ms
#define T_SRC_SWP_STDBY             60UL    // 60 ms must < 650ms
//#define T_SRC_SWP_STDBY             500UL    // 500 ms must < 650ms
#define T_SNK_WAIT_VSAFE0V          400UL   // 400 ms, must < 650 ms
//#define T_SNK_WAIT_VSAFE0V          645UL   // 645ms, must < 650 ms
#define T_SNK_HARD_RESET_TIMER      2100UL  // 2.1 s, must < 650(tSafe0V)+1000(tSrcRecover)+275(tSrcTurnOn)+620(tTypeCSinkWaitCap)
#define T_SRC_RECOVER               800UL   // 800 ms
#define T_DELAY_5MS                 5UL     // 5 ms
#define T_DELAY_10MS                10UL    // 10 ms
#define T_DELAY_15MS                15UL    // 15 ms
#define T_PR_SWP_REQUEST_TIMER      800UL   // 800 ms
#define T_PPS_TIMER                 15999UL // 14.999 s, 12 - 15s
#define T_SNK_PPS_REQ_TIMER_SHORT   150UL   // 150 ms
#define T_SNK_PPS_REQ_TIMER         1000UL  // 1 s, maximal 10s
#define T_PRS_IN_PROG_TIMER         3000UL  // 3 s
#define T_PD_DEBOUNCE_2             15UL    // 15 ms
#define T_CHUNKING_NOT_SUPPORTED    40000UL // 40000 us, this unit is us, range: 40000 - 50000 us
#define T_DFP_UFP_DISCOVERY_IDENTITY    1500UL    // 1500 ms
#define T_VDM_RESPONSE_DELAY        10UL    // 10 ms
#define T_SNK_DISCONNECT            15UL   // 15 ms
#endif /* #if 0 */

#pragma pack()


#endif /* #ifndef __DPM_TIMER_H_ */

