/***************  COPYRIGHT (c) 2002-2007 FICOSA INTERNATIONAL   **************
| Language:       |  MISRA C
| Controller:     |  Generic
| Spec. Document: |  ISO15765-2-E.pdf
|-----------------|------------------------------------------------------------
| Project:        |  ISO15765-2
| Reference:      |  
|------------------------------------------------------------------------------
|    Date  - Cod. - Rev. - App. -             Description
| 12/09/02   AM                 Implementation of the kwp2000 for PSA.
| 19/08/04   DT                 Split ISO15765_2 protocol from the KWP2000
|                               because they are different modules.
| 24/04/09   DC                 Modification to guarantee the requirements SR1431, 
|                               SR1438, SR1681.
| 15/07/09   AC                 Corrected bug in ReadCF because it didn't count
|                               correctly the blocks
| 15/12/10   AC                 Converted ISO15765_2 protocol to multi-instance.
| 13/11/11   AC                 Converted ISO15765_2 to full-duplex
| 09/01/11   AC                 Changed file, routines and variable naming to 
|                               make it a standard component and to have a
|                               similar naming style with MPDT.
| 07/05/15   FPR                Removed TIMER_MS_TO_TICKS_R_UP macro. Now new macro
|								TIMER_MS_TO_TIME_RESTRICTIVE is used instead.
|								New macro implemented in HAL DSPIC (Timer.h). 
|------------------------------------------------------------------------------
| DESCRIPTION:
|   User interface for the transport protocol ISO15765_2 on CAN.
|   ISO15765_2 protocol is a transport protocol that permits the sending and
|   reception of frames until 4096 bytes on a network protocol with frames of
|   lower size. The original frame is segemented and sent with flow control
|   data that allows to the reception node to mount again the original frame.
| GENERAL CONSIDERATIONS
|   - This implementation allows full duplex communications.
|   - This implementation allows for each instance a communication channel
|     with physical address in which both transmission and receptions could
|     be done and a funcional address for only receptions.
|   - The functional address channel only supports frames with less than
|     8 bytes of data.
|   - This header must only be included in the ISO15765_2 transport protocol
|     source files but is forbidden to be included by the application as it
|     contains the private data of the ISO15765_2 module.
******************************************************************************/
#ifndef _TP_FUNCTIONS_H
#define _TP_FUNCTIONS_H

/*----------------------------- INCLUDES ---------------------------------*/
#include "Std_Types.h"
#include "DiagnosticL/Comp_HAL_Autosar_Wrappers/Timer.h"
#include "TP.h"

/*----------------------------- MACROS ---------------------------------*/

/*----------------------------- DEFINES ----------------------------------*/

/* Maximum data bytes that a CAN frame can allocate */
#define NP_SF_MAX_SIZE ((UI_8)7)

/* Maximum useful data size that a Single Frame can allocate in bytes */
#define CAN_FRM_MAX_SIZE ((UI_8)8)

/* Maximum useful data size that a Consecutive Frame can allocate in bytes */
#define CF_DATA_LEN      ((UI_8)7)

/*-------------------------- DATA TYEPS ----------------------------------*/

/* Interface between FICOSEKCOM and TP for physical frames */
typedef struct {
    t_can_handler can_handler;              //ACF must be called OsekCom_Handler
    t_symbolic_name sig_np_rx;              /* OSEKCOM signal to receive the physical frame */
    t_symbolic_name sig_np_tx;              /* OSEKCOM signal to request the sending of the phisical frame */
} t_tp_can_phy_interface;

/* Interface between FICOSEKCOM and TP for functional frames */
typedef struct {
    t_symbolic_name sig_np_rx;              /* OSEKCOM signal to receive the functional frame */
} t_tp_can_fun_interface;

/* States of the TX PHYSICAL FRAME FSM */
typedef enum {
    ESTAT_TP_NETWORKLAYERLOWERINTERFACE_TX_WAITINGTXCONFIRMATION = 1, 
    ESTAT_TP_NETWORKLAYERLOWERINTERFACE_TX_READYTOSEND = 2, 
    ESTAT_0_TP_NETWORKLAYERLOWERINTERFACE_TX = 0
} t_estat_tp_networklayerlowerinterface_tx;

/* If the ISO15765_2 is defined in full mode, define all the structures */
/* that allow transport protocol communications with more than 7 data   */
/* bytes (one single frame) */
#ifdef TP_MODE_FULL

/* States of the RX FULL PHYSICAL FSM */
typedef enum {
    ESTAT_TP_RX_FULL_INICIO = 1, 
    ESTAT_TP_RX_FULL_RXCF = 2, 
    ESTAT_TP_RX_FULL_CONFIRMAFC = 3, 
    ESTAT_0_TP_RX_FULL = 0
} t_estat_tp_rx_full;

/* States of the TX FULL PHYSICAL FSM */
typedef enum {
    ESTAT_TP_TX_FULL_INICI = 1, 
    ESTAT_TP_TX_FULL_ESPERAFC = 2, 
    ESTAT_TP_TX_FULL_CONFIRMATX = 3, 
    ESTAT_0_TP_TX_FULL = 0
} t_estat_tp_tx_full;

/* Configuration parameters of the TP FULL */
typedef struct {
    UI_16 np_max_frm_size;      /* Maximum size allowed for the diagnostics buffer. The protocol allows  */
                                /* frames until 4096 bytes. The buffer must be reserved having into      */
                                /* account the MACRO "SIZE_ALLOC_BUFFER" to avoid overflows.             */
    BOOL np_can_frm_size_fixed; /* Flag to configure fixed or variable length in the CAN frames          */
                                /* Allowed values:                                                       */
                                /*   TRUE -> Totes les trames Tx s'envien amb 8 bytes amb els bytes no   */
                                /*           utils a valor de padding configurat amb el parametre        */
                                /*           np_tx_padding_value. Les trames Rx de menys de 8 bytes son  */
                                /*           ignorades                                                   */
                                /*   FALSE -> Totes les trames s'envien i es reben amb la mida en funcio */
                                /*            dels bytes utils que contenen                              */ 
	BOOL np_rx_padding_sensitive;/* Flag to be taken into account if frm_size_fixed is defined as TRUE.  */
                                /* Allowed values:                                                       */
                                /*   TRUE -> RX TP frames with less than 8 bytes are ignored  			 */
                                /*   FALSE -> RX TP frames with less than 8 bytes are processed          */
								/*            correctly if the frame has a correct TP format             */
    UI_8 np_tx_padding_value;   /* Padding value for the non valid bytes in case that                    */
                                /* np_can_frm_size_fixed is configured to TRUE                           */
    UI_16 n_cr_max;             /* Maximum timeout measured in ms between Consecutive frames before      */
                                /* aborting the reception due to time out                                */
    UI_16 n_bs_max;             /* Time in ms between the first frame and the firs flow control or       */
                                /* between the last consecutive frame of a block and the flow control    */
                                /* before aborting the transmission due to timeout                       */
    UI_16 stmin;                /* Time in ms between consecutive frames of the transmitter to allow     */
                                /* ourself to process the received frames without losing anyone          */
                                /* If the block size if different from 1, this time must be minimum the  */
                                /* cycle frequency, otherwise if this is 1 the stmin could be 0          */
    UI_8 block_size;            /* Number of consecutive frames that the ECU will send without waiting   */
                                /* for a flow control before continuing. If the block size is set to 0   */
                                /* means that only one flow control is needed after receiving the first  */
                                /* frame                                                                 */
	UI_8 n_wftmax;				/* Maximum number of FC wait that TP can handle in a row 				 */
} t_tp_cfg_full;

/* Parameters to manage the Flow Controls in multiple frames */
typedef struct {
    t_tp_flow_sts flow_status;  /* Flow control type */
    UI_8 rx_bs;                 /* Block size received from the other part that we must guarantee in a TX */
    UI_8 stmin;                 /* Stmin received from the other part that we must garantee between CF */
    BOOL first_fc;              /* Flag that indicates if this is the first FC after a FF */
    BOOL fc_rx;                 /* Flag that notifies of the reception of a flow control  */
    UI_8 block_size_cnt;        /* Counter of the consecutive frames sent before waiting a FC */
	UI_8 num_fc_wait;			/* Counter of the FC wait received */
} t_tp_fc_data;

/* Parameters to manage the TP FULL reception */
typedef struct {
    UI_8 next_segm_num_rx;      /* Counter to manage the number of receive consecutive segments. */
    UI_16 byte_actual_rx;       /* Counter to manage the number of received bytes. */
    UI_16 num_frames_before_fc; /* Number of consecutive frames received since last FC sent, in order to be */
                                /* aware when another FC must be sent */
    t_tp_rx_frm frame_rx_type;  /* Type of the last received CAN frame */
    UI_8 frame_rx_data[8];      /* Last RX frame received */
    UI_8 frame_rx_len;          /* Last RX length */
    t_tp_fc_frm frame_fc_type;  /* Type of the last received FC frame */
    UI_8 frame_rx_fc_data[8];   /* Last FC frame received */
    UI_8 frame_rx_fc_len;       /* Last FC length */
} t_tp_rx_status_full;

/* Parameters to manage the TP FULL transmission */
typedef struct {
    BOOL ack_tx;                /* Flag that notifies if the CAN layer has notified the TX of the last frame */
    UI_8 next_segm_num_tx;      /* Counter to manage the number of sent consecutive segments. */
    UI_16 byte_actual_tx;       /* Counter to manage the number of transmitted bytes. */
    t_tp_tx_sts frame_tx_sts;   /* Flag that notifies the status of a TX data frame */
    UI_8 frame_tx_data[8];      /* TX frame data required */
    UI_8 frame_tx_len;          /* TX length required */
    t_tp_tx_sts frame_tx_fc_sts;/* Flag that notifies the status of a FC data frame */
    UI_8 frame_tx_fc_data[8];   /* FC frame data required */
    UI_8 frame_tx_fc_len;       /* FC length required */
} t_tp_tx_status_full;

/* Timers to control the TP FULL timeouts */
typedef struct {
    t_clock n_cr;               /* Timer variable that controls the TP CR timeout */
    t_clock n_ar;               /* Timer variable that controls the TP AR timeout */
    t_clock n_bs;               /* Timer variable that controls the TP BS timeout */
    t_clock n_cs;               /* Timer variable that controls the TP CS timeout */
    t_clock n_as;               /* Timer variable that controls the TP AS timeout */
} t_tp_timers_full;

/* Structure that contains all the data needed for an TP FULL instance */
typedef struct {
    t_estat_tp_tx_full state_tx;       /* State of the TP TX PHYSICAL FSM */
    t_estat_tp_rx_full state_rx;       /* State of the TP RX PHYSICAL FSM */
    t_estat_tp_networklayerlowerinterface_tx state_can_phy_tx; /* State of the TP Network layer lower inteface FSM */
    t_tp_can_phy_interface can_phy;    /* Interface with the network protocoal physical CAN structure */
    t_tp_can_fun_interface can_fun;    /* Interface with the network protocoal functional CAN structure */
    t_tp_cfg_full cfg;                 /* Configuration of the TP */
    t_tp_fc_data fc_data;              /* Estructura de dades de gestio del control de fluxe */
    t_tp_rx_status_full rx_st;         /* Status of the TP transmission/reception */
    t_tp_tx_status_full tx_st;         /* Status of the TP transmission/reception */
    t_tp_timers_full timers;           /* Timers to control and assure the expected TP managment */
} t_tp_data;

/* If the ISO15765_2 is defined in lite mode, define all the structures */
/* simplified that allow transport protocol communications equal or     */
/* less than 7 data bytes (only single frames) */
#else

/* States of the TX LITE PHYSICAL FSM */
typedef enum {
    ESTAT_TP_TX_LITE_INIT = 1, 
    ESTAT_TP_TX_LITE_CONFIRMTX = 2, 
    ESTAT_0_TP_TX_LITE = 0
} t_estat_tp_tx_lite;

/* Configuration parameters of the TP LITE */
typedef struct {
    BOOL np_can_frm_size_fixed; /* Flag to configure fixed or variable length in the CAN frames          */
                                /* Allowed values:                                                       */
                                /*   TRUE -> Totes les trames Tx s'envien amb 8 bytes amb els bytes no   */
                                /*           utils a valor de padding configurat amb el parametre        */
                                /*           np_tx_padding_value. Les trames Rx de menys de 8 bytes son  */
                                /*           ignorades                                                   */
                                /*   FALSE -> Totes les trames s'envien i es reben amb la mida en funcio */
                                /*            dels bytes utils que contenen                              */ 
	BOOL np_rx_padding_sensitive;/* Flag to be taken into account if frm_size_fixed is defined as TRUE.  */
                                /* Allowed values:                                                       */
                                /*   TRUE -> RX TP frames with less than 8 bytes are ignored  			 */
                                /*   FALSE -> RX TP frames with less than 8 bytes are processed          */
								/*            correctly if the frame has a correct TP format             */
    UI_8 np_tx_padding_value;   /* Padding value for the non valid bytes in case that                    */
                                /* np_can_frm_size_fixed is configured to TRUE                           */
} t_tp_cfg_lite;

/* Parameters to manage the TP LITE reception */
typedef struct {
    t_tp_rx_frm frame_rx_type;  /* Type of the last received CAN frame */
    UI_8 frame_rx_data[8];      /* Last RX frame received */
    UI_8 frame_rx_len;          /* Last RX length */
} t_tp_rx_status_lite;

/* Parameters to manage the TP LITE transmission */
typedef struct {
    BOOL ack_tx;                /* Flag that notifies if the CAN layer has notified the TX of the last frame */
    t_tp_tx_sts frame_tx_sts;   /* Flag that notifies the status of a TX data frame */
    UI_8 frame_tx_data[8];      /* TX frame data required */
    UI_8 frame_tx_len;          /* TX length required */
} t_tp_tx_status_lite;

/* Timers to control the TP LITE timeouts */
typedef struct {
    t_clock n_as;               /* Timer variable that controls the TP AS timeout */
} t_tp_timers_lite;

/* Structure that contains all the data needed for an TP LITE instance */
typedef struct {
    t_estat_tp_tx_lite state_tx;			/* State of the TP TX PHYSICAL FSM */
    t_estat_tp_networklayerlowerinterface_tx state_can_phy_tx;
    t_tp_can_phy_interface can_phy;         /* Interface with the network protocoal physical CAN structure */
    t_tp_can_fun_interface can_fun;         /* Interface with the network protocoal functional CAN structure */
    t_tp_cfg_lite cfg;                 		/* Configuration of the TP */
    t_tp_rx_status_lite rx_st;   			/* Status of the TP reception */
    t_tp_tx_status_lite tx_st;   			/* Status of the TP transmission */
    t_tp_timers_lite timers;           		/* Timers to control and assure the expected TP managment */
} t_tp_data;

#endif

/*--------------------------- GLOBAL VARIABLES ---------------------------*/

/* Declaration of the tp_frm phisical and functional defined structures */
extern t_tp_data tp_data[TP_NUM_INSTANCES];

/*--------------------------- ROUTINE PROTOTYPES ------------------------*/

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to process the last received physical CAN frame. This routine
|  will get the data bytes, the length and the type of transport protocol
|  frame using the CAN interfaces.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPProcessRxCanPhyFrame(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine that checks if any of the possible pending transport protocol
|  transmission frames are pending to be transmitted.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     result: boolean that indicates if transmission is pending
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckTxCanFrame(UI_8 tp_hdl, t_tp_tx_type *tp_tx_type);

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine that triggers the sending of a transport protocol frame (SF, FF, CF
|  or flow control). The priority of the transmission frames will be given by 
|  the order of checking each of the flags in the IF condition.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPProcessTxCanFrame(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine that checks if Osekcom notified the transmission of the TX last
|  frame
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     result: TRUE if transmission has been confirmed, FALSE otherwise
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckCanFrameConfirmation(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine that checks if for a given transmission frame (which could be
|  a "Flow Control", a "First Frame, a "Consecutive Frame" or a "Single Frame")
|  his transmission has been confirmed.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     tx_sts: current transmission status of the requested frame
|     result: TRUE if transmission has been confirmed, FALSE otherwise
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckTxConfirmed(UI_8 tp_hdl, t_tp_tx_sts tx_sts);

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to notify a new transmission frame status for a transmission
|  which still has his status as ongoing
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     tx_sts: new status to be set instead of ongoing
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPNotifyCanFrmTx(UI_8 tp_hdl, t_tp_tx_sts tx_sts);

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine that checks if there are still more frames pending to be sent.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     result: TRUE if there are not more pending frames to be sent.
|             FALSE if there are still more pending frames to be sent
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPTestEndFrame(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to request the sending of a single frame. Remember that a SF is
|  used only to sent network frames with equal ore less than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPSendSF(UI_8 tp_hdl);

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to request the sending of a first frame. Remember that a first
|  frame is used to send the initial network frame with more than 8 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPSendFF(UI_8 tp_hdl);
#endif

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to request the sending of a consecutive frame. Remember that CF
|  are used after sending a FF when the network frame has more than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPSendCF(UI_8 tp_hdl);
#endif

/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a CAN frame of the type "Single Frame" with physical
|  address. Remember that a SF is a frame with equal or less than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPReadSF(UI_8 tp_hdl);

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a CAN frame of the type "First Frame" and request directly
|  the sending of a Flow Control as always after receiving a FF a FC must 
|  be sent by protocol. Remember that a FF is a frame with more than 7
|  bytes. Remember that a FC is used to control the flow of the reception
|  of a frame with more than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPReadFFSendFC(UI_8 tp_hdl);
#endif

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to request the sending of a flow control. Remember that a FC is 
|  used to control the flow of the reception of a frame with more than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     flow_control_type: type of the flow control that must be sent
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPSendFC(UI_8 tp_hdl, t_tp_flow_sts flow_control_type);
#endif

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a CAN frame of the type "Consecutive Frame". Remember
|  that consecutive frames are received after receiving the first frame
|  with network frames with more than 7 bytes. 
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPReadCF(UI_8 tp_hdl);
#endif

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a CAN frame of the type "Consecutive Frame". Remember
|  that consecutive frames are received after receiving the first frame
|  with network frames with more than 7 bytes. This routine in case that
|  the received frame is consistent and has the correct format will request
|  the sending of a flow control.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPReadCFSendFC(UI_8 tp_hdl);
#endif

#ifdef TP_MODE_FULL
/*****************************************************************************
| Portability:  Generic
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a CAN frame of the type "Flow Control" and request
|  the sending of a "Consecutive Frame". Remember that "Flow Control" frames
|  are used to control the flow of the transmission in case of network
|  frames with more than 7 bytes.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
/---------------------------------------------------------------------------*/
void TPReadFCSendCF(UI_8 tp_hdl);
#endif

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to read a functional CAN frame. Remember that in functional
|  channel any frame with a type different from SF will be ignored as the
|  maximum allowed size for this channel is 7.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
void TPReadFunFrm(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to check if the timeout of the transmission frame has been notfied.
|  Remember that this timeout must be configured in the OSEKCOM database with
|  the specified AX timeout defined.
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     return: TRUE if timeout has been confirmed, FALSE otherwise
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckAxTimeout(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to check that all the physical interface routines with OSEKCOM layer
|  are correctly initialized
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     return: TRUE if configuration is correct, FALSE otherwise
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckPhyCfgData(UI_8 tp_hdl);

/*****************************************************************************
| Portability:  Generica
|----------------------------------------------------------------------------
| Functionalities Contract Description:
|  Routine to check that all the functional interface routines with OSEKCOM layer
|  are correctly initialized
|---------------------------------------------------------------------------
| Parameters Explanation:
|     tp_hdl: ISO15765_2 handler to be used
|     return: TRUE if configuration is correct, FALSE otherwise
|---------------------------------------------------------------------------
| Timing:
| Tmax Int Dis:   ? CPU cycles | O(n): CTE 
| Tmax Int En :   ? CPU cycles | O(n): CTE 
| Tmax Total  :   ? CPU cycles | O(n): CTE 
/---------------------------------------------------------------------------*/
BOOL TPCheckFunCfgData(UI_8 tp_hdl);

#endif
