/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2023. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */
/******************************************************************************
 * @version: V1.0.0 demo
 ******************************************************************************/

/*!
* @file can.h
*
* @brief This file contains the user gpio function..
*
*/

#ifndef _CANBUSOFF_H
#define _CANBUSOFF_H


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* ===========================================  Includes  =========================================== */
#include "ac7803x.h"
#include "string.h"
#include "system_ac7803x.h"
/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */
typedef enum
{
    Busoff_check = 0,
    Fast_Recover = 1,
    Slow_Recover = 2,
    
}CAN_BusoffState_t;

typedef enum
{
    CAN_NORMAL = 0,
    CAN_BUSOFF = 1,
}CAN_State_t;

/* busoff struct */
typedef struct
{
    CAN_BusoffState_t busoffState;  /* Status of busoff processing */
    CAN_State_t canState;           /* CAN state */
    uint8_t canRecoverCnt;          /* Number of recoveries */
    uint32_t canRecoverTimerCnt;    /* Recovery Time Count */
    uint32_t canTimerOut;           /* Exit fast and slow recovery time */
}CAN_BusoffConfig_t;                

/* ==========================================  Variables  =========================================== */
extern CAN_BusoffConfig_t g_canBuoffCtrl;;
/* ====================================  Functions declaration  ===================================== */
/*!
* @brief   Busoff state switching processing
*
* @param[in] none
* @return  none
*/
extern void CAN_BusoffProcess(void);

/*!
* @brief   busoff init
*
* @param[in] none
* @return  none
*/
extern void CAN_BusoffInit(void);

/*!
* @brief   Get the can status of the current busoff processing logic
*
* @param[in] none
* @return  CAN_State_t
*/
extern CAN_State_t CAN_GetBusoffState(void);

/*!
* @brief   Set CAN to busoff state
*
* @param[in] none
* @return  none
*/
extern void CAN_SetBusoffState(void);

/*!
* @brief   Time processing of busoff
*          It is recommended to place a timing interrupt of 1ms
*
* @param[in] none
* @return  none
*/
extern void CAN_BusoffTimerCnt(void);

/* ======================================  Functions define  ======================================== */
#ifdef __cplusplus
}
#endif

#endif /* _CANBUSOFF_H */

/* =============================================  EOF  ============================================== */

