/**
  *****************************************************************************
  * @file    hal_def.h
  * @author  Product application department
  * @version V1.0
  * @date    2020.02.25
  * @brief   Header file of HAL DEF.
  *
  ******************************************************************************
  */


/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef HAL_DEF_H_
#define HAL_DEF_H_


#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "type.h"

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

/** @defgroup HAL_HAL_DEF HAL_DEF
  *
  *@{
  */

/*** 宏定义 *******************************************************************/
/** @defgroup HAL_DEF_Exported_Macros Exported Macros
  *
  * @{
  */ 
  #define HAL_MAX_DELAY      0xFFFFFFFF

  #if (USE_RTOS == 1)
    #error " USE_RTOS should be 0 in the current HAL release "
  #else
    #define __HAL_LOCK(__HANDLE__)                                           \
                                  do{                                        \
                                      if((__HANDLE__)->lock == HAL_LOCKED)  \
                                      {                                      \
                                        return HAL_BUSY;                    \
                                      }                                      \
                                      else                                   \
                                      {                                      \
                                        (__HANDLE__)->lock = HAL_LOCKED;    \
                                      }                                      \
                                    }while (0)

    #define __HAL_UNLOCK(__HANDLE__)                                          \
                                    do{                                       \
                                        (__HANDLE__)->lock = HAL_UNLOCKED;   \
                                      }while (0)
  #endif /* USE_RTOS */

  #ifndef __GNUC__
  #define __GNUC__
  #endif

  #if  defined ( __GNUC__ )
    #ifndef __weak
      #define __weak   __attribute__((weak))
    #endif /* __weak */

    #ifndef WEAK
      #define WEAK    __attribute__((weak))  /**< Defines 'WEAK' permissions */
    #endif /* WEAK */

    #ifndef __packed
      #define __packed __attribute__((__packed__))
    #endif /* __packed */

  #endif /* __GNUC__ */

/**
  * @}
  */

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

  /**
    * @brief  HAL Status structures definition
    */
  typedef enum
  {
      HAL_OK       = 0x00,
      HAL_ERROR    = 0x01,
      HAL_BUSY     = 0x02,
      HAL_TIMEOUT  = 0x03,


    /*CPM error code*/
    HAL_CPM_ERROR_SYSCLKDIV_OUTRANGE   = 0x100,  /**< 系统时钟分频 error */

    /*DMA error code*/
    HAL_DMA_ERROR_TE                   = 0x110,  /**< Transfer error    */  
    HAL_DMA_ERROR_CHANNEL_OUTRANG      = 0x111,  /**< DMA通道超过最大允许范围r    */  
  } HAL_StatusTypeDef;


  /** 
    * @brief  HAL Lock structures definition  
    */
  typedef enum 
  {
    HAL_UNLOCKED = 0x00,
    HAL_LOCKED   = 0x01  
  } HAL_LockTypeDef;


 /**
  * @}
  */

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

extern __IO uint32_t g_sys_clk;
extern __IO uint32_t g_ips_clk;
extern __IO uint32_t g_efm_clk;

/**
  * @}
  */


/*** 函数声明 ******************************************************************/
/** @defgroup HAL_DEF_Exported_Functions Exported Functions
  * @{
  */


/**
  * @}
  */

/**
  *@}
  */

/**
  *@}
  */

#ifdef __cplusplus
}
#endif

#endif /* HAL_DEF_H_ */

