type.h 3.0 KB
Newer Older
W
wangyq2018 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/**
  *********************************************************************************
  *
  * @file    type.h
  * @brief   define type
  *
  * @version V1.0
  * @date    17 Apr 2017
  * @author  AE Team
  * @note
  *
  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  *
  *********************************************************************************
  */

#ifndef __TYPE_H__
#define __TYPE_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>


#if defined (__CC_ARM)
#define __INLINE__		__inline
#define __STATIC_INLINE__	static __inline
#else
#define __INLINE__		inline
#define __STATIC_INLINE__	static inline
#endif

#define __isr__

W
wangyq2018 已提交
37 38 39 40
typedef enum
{
    RESET = 0x0,
    SET   = 0x1,
W
wangyq2018 已提交
41 42
} flag_status_t, it_status_t;

W
wangyq2018 已提交
43 44 45 46
typedef enum
{
    BIT_RESET = 0x0,
    BIT_SET   = 0x1,
W
wangyq2018 已提交
47 48
} bit_status_t;

W
wangyq2018 已提交
49 50 51 52
typedef enum
{
    DISABLE = 0x0,
    ENABLE  = 0x1,
W
wangyq2018 已提交
53 54 55
} type_func_t;
#define IS_FUNC_STATE(x)	(((x) == DISABLE) || ((x) == ENABLE))

W
wangyq2018 已提交
56 57 58 59
typedef enum
{
    FALSE = 0x0,
    TRUE  = 0x1,
W
wangyq2018 已提交
60 61
} type_bool_t;

W
wangyq2018 已提交
62 63 64 65
typedef enum
{
    UNLOCK = 0x0,
    LOCK   = 0x1,
W
wangyq2018 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79
} lock_state_t;
#define IS_LOCK_STATE(x)	(((x) == UNLOCK) || ((x) == LOCK))


#define BIT(x)			((1U << (x)))
#define BITS(s, e)		((0xffffffff << (s)) & (0xffffffff >> (31 - (e))))
#define SET_BIT(reg, bit)	((reg) |= (bit))
#define CLEAR_BIT(reg, bit)	((reg) &= ~(bit))
#define READ_BIT(reg, bit)	((reg) & (bit))
#define READ_BITS(reg, msk, s)	(((reg) & (msk)) >> (s))
#define CLEAR_REG(reg)		((reg) = (0x0))
#define WRITE_REG(reg, val)	((reg) = (val))
#define READ_REG(reg)		((reg))
#define MODIFY_REG(reg, clearmask, setmask)	\
W
wangyq2018 已提交
80
    WRITE_REG((reg), (((READ_REG(reg)) & (~(clearmask))) | (setmask)))
W
wangyq2018 已提交
81 82 83 84
#define UNUSED(x)	((void)(x))

#ifdef USE_ASSERT
#define assert_param(x)			\
W
wangyq2018 已提交
85 86 87 88 89 90 91
    do {					\
        if (!(x)) {			\
            __disable_irq();	\
            while (1)		\
                ;		\
        }				\
    } while (0)
W
wangyq2018 已提交
92 93 94 95 96 97 98 99 100 101 102 103
#else
#define assert_param(x)
#endif


#define PER_MEM_BASE         ((uint32_t) 0x40000000UL)	/* PER base address  */
#define RAM_MEM_BASE         ((uint32_t) 0x20000000UL)	/* RAM base address  */
#define BITBAND_PER_BASE     ((uint32_t) 0x42000000UL)	/* Peripheral Address Space bit-band area */
#define BITBAND_RAM_BASE     ((uint32_t) 0x22000000UL)	/* SRAM Address Space bit-band area */

__STATIC_INLINE__ void BITBAND_PER(volatile uint32_t *addr, uint32_t bit, uint32_t val)
{
W
wangyq2018 已提交
104 105
    uint32_t tmp = BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) << 5) + (bit << 2);
    *((volatile uint32_t *)tmp) = (uint32_t)val;
W
wangyq2018 已提交
106 107 108 109
}

__STATIC_INLINE__ void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
{
W
wangyq2018 已提交
110 111
    uint32_t tmp = BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) << 5) + (bit << 2);
    *((volatile uint32_t *)tmp) = (uint32_t)val;
W
wangyq2018 已提交
112 113 114
}

#if defined ( __GNUC__ )
W
wangyq2018 已提交
115 116 117 118 119 120
#ifndef __weak
#define __weak   __attribute__((weak))
#endif	/* __weak */
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif	/* __packed */
W
wangyq2018 已提交
121 122 123 124 125 126 127
#endif /* __GNUC__ */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __TYPE_H__ */