/**
  ******************************************************************************
             Copyright(c) 2021 China Core Co. Ltd.
                      All Rights Reserved
  ******************************************************************************
  * @file    can_hal.h
  * @author  Product application department
  * @version V1.0
  * @date    2021.06.07
  * @brief   Header file of UART HAL module..
  ******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CAN_HAL_H
#define __CAN_HAL_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "hal_def.h"
#include "can_drv.h"

/**@defgroup HAL HAL driver
  *
  *@{
  */

/** @defgroup HAL_CAN CAN
  *
  *@{
  */

/*** 宏定义 *******************************************************************/
/** @defgroup UART_Exported_Macros Exported Macros
  *
  * @{
  */

/**
  * @brief UART Error Codes
  *
  */
#define HAL_CAN_ERROR_NONE      ((uint32_t)0x00)    /*!< No error            */
#define HAL_CAN_ERROR_PE        ((uint32_t)0x01)    /*!< Parity error        */
#define HAL_CAN_ERROR_NE        ((uint32_t)0x02)    /*!< Noise error         */
#define HAL_CAN_ERROR_FE        ((uint32_t)0x04)    /*!< frame error         */
#define HAL_CAN_ERROR_ORE       ((uint32_t)0x08)    /*!< Overrun error       */

/**
  * @}
  */

/*** 结构体、枚举变量定义 *****************************************************/
/** @defgroup UART_Exported_Types Exported Types
  *
  * @{
  */

/**
  * @brief HAL UART State structures definition
  */
typedef enum
{
  HAL_CAN_STATE_RESET             = 0x00U,  /*!< CAN not yet initialized or disabled */
  HAL_CAN_STATE_READY             = 0x01U,  /*!< CAN initialized and ready for use   */
  HAL_CAN_STATE_BUSY              = 0x02U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_TX           = 0x12U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_RX           = 0x22U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_TX_RX        = 0x32U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_TIMEOUT           = 0x03U,  /*!< Timeout state                       */
  HAL_CAN_STATE_ERROR             = 0x04U   /*!< CAN error state                     */

}HAL_CAN_StateTypeDef;

typedef void (*HAL_CAN_CALLBACK)(void*);
/**
  *@brief CAN 句柄结构体定义
  */
typedef struct
{
    
    CAN_TypeDef                 *Instance;          /*!< Register base address          */
    CAN_InitTypeDef             Init;               /*!< CAN required parameters        */
    CanTxMsgTypeDef             *pTxMsg;            /*!< Pointer to transmit structure  */
    uint32_t                    TxSize;             /**< 待接收数据长度   */
    uint32_t                    TxCnt;              /**< 待接收数据计数   */
    CanRxMsgTypeDef             *pRxMsg;            /*!< Pointer to reception structure */
    uint32_t                    RxSize;             /**< 待发送数据长度  */
    uint32_t                    RxCnt;              /**< 待发送数据计数  */
    __IO HAL_CAN_StateTypeDef   State;              /*!< CAN communication state        */
    //  HAL_LockTypeDef             Lock;           /*!< CAN locking object             */
    __IO uint32_t               ErrorCode;          /*!< CAN Error code                 */
    HAL_CAN_CALLBACK            BOFFCallback;       /**< Bus Off回调函数 */
    HAL_CAN_CALLBACK            ErrCallback;        /**< 错误处理回调函数 */
    HAL_CAN_CALLBACK            RwrnCallback;       /**< RX Warning处理回调函数 */
    HAL_CAN_CALLBACK            TwrnCallback;       /**< TX Warning处理回调函数 */
	HAL_CAN_CALLBACK            MBIsrCallback;      /**< Message Buffer中断回调函数 */    
}CAN_HandleTypeDef,*pCAN_HandleTypeDef;


/**
  * @}
  */

/*** 全局变量声明 **************************************************************/
/** @defgroup UART_Exported_Variables Exported Variables
  *
  * @{
  */



/**
  * @}
  */

/*** 函数声明 ******************************************************************/
/** @defgroup CAN_Exported_Functions Exported Functions
  * @{
  */
extern void HAL_CAN_IRQHandler(uint8_t can_channel);
HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan);
HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout);
HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef *hcan, uint32_t Timeout);
HAL_StatusTypeDef HAL_CAN_TransmitIT(CAN_HandleTypeDef *hcan, uint32_t Timeout);
HAL_StatusTypeDef HAL_CAN_ReceiveIT(CAN_HandleTypeDef *hcan, uint32_t Timeout);

/**
  * @}
  */

/**
  *@}
  */

/**
  *@}
  */

#ifdef __cplusplus
}
#endif

#endif /* __CAN_HAL_H */
/************************ (C) COPYRIGHT C*Core *****END OF FILE****/
