1 /**********************************************************************************
2  *
3  * @file    type.h
4  * @brief   define type
5  *
6  * @date    30 Jan. 2023
7  * @author  AE Team
8  * @note
9  *          Change Logs:
10  *          Date            Author          Notes
11  *          30 Jan. 2023    Lisq            the first version
12  *
13  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
14  *
15  * SPDX-License-Identifier: Apache-2.0
16  *
17  * Licensed under the Apache License, Version 2.0 (the License); you may
18  * not use this file except in compliance with the License.
19  * You may obtain a copy of the License at
20  *
21  * www.apache.org/licenses/LICENSE-2.0
22  *
23  * Unless required by applicable law or agreed to in writing, software
24  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
25  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  * See the License for the specific language governing permissions and
27  * limitations under the License.
28  *
29  **********************************************************************************
30  */
31 
32 #ifndef __TYPE_H__
33 #define __TYPE_H__
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 
39 /* Includes ------------------------------------------------------------------ */
40 #include <stdint.h>
41 
42 
43 #if defined (__CC_ARM)
44 #define __INLINE__      __inline
45 #define __STATIC_INLINE__   static __inline
46 #else
47 #define __INLINE__      inline
48 #define __STATIC_INLINE__   static inline
49 #endif
50 
51 #define __isr__
52 
53 typedef enum
54 {
55     RESET = 0x0U,
56     SET   = 0x1U,
57 } flag_status_t, it_status_t;
58 
59 typedef enum
60 {
61     BIT_RESET = 0x0U,
62     BIT_SET   = 0x1U,
63 } bit_status_t;
64 
65 typedef enum
66 {
67     DISABLE = 0x0U,
68     ENABLE  = 0x1U,
69 } type_func_t, TypeFunc;
70 #define IS_FUNC_STATE(x)    (((x) == DISABLE) || ((x) == ENABLE))
71 
72 typedef enum
73 {
74     FALSE = 0x0U,
75     TRUE  = 0x1U,
76 } type_bool_t;
77 
78 typedef enum
79 {
80     UNLOCK = 0x0U,
81     LOCK   = 0x1U,
82 } lock_state_t;
83 #define IS_LOCK_STATE(x)    (((x) == UNLOCK) || ((x) == LOCK))
84 
85 
86 #define BIT(x)          ((1U << (x)))
87 #define BITS(s, e)      ((0xffffffffU << (s)) & (0xffffffffU >> (31 - (e))))
88 #define SET_BIT(reg, bit)   ((reg) |= (bit))
89 #define CLEAR_BIT(reg, bit) ((reg) &= ~(bit))
90 #define READ_BIT(reg, bit)  ((reg) & (bit))
91 #define READ_BITS(reg, msk, s)  (((reg) & (msk)) >> (s))
92 #define CLEAR_REG(reg)      ((reg) = (0x0))
93 #define WRITE_REG(reg, val) ((reg) = (val))
94 #define READ_REG(reg)       ((reg))
95 #define MODIFY_REG(reg, clearmask, setmask) \
96     WRITE_REG((reg), (((READ_REG(reg)) & (~(clearmask))) | (setmask)))
97 #define UNUSED(x)   ((void)(x))
98 
99 #ifdef USE_ASSERT
100 #define assert_param(x)         \
101     do {                    \
102         if (!(x)) {         \
103             __disable_irq();    \
104             while (1)       \
105                 ;       \
106         }               \
107     } while (0)
108 #else
109 #define assert_param(x)
110 #endif
111 
112 
113 #define PER_MEM_BASE         ((uint32_t) 0x40000000UL)  /* PER base address  */
114 #define RAM_MEM_BASE         ((uint32_t) 0x20000000UL)  /* RAM base address  */
115 #define BITBAND_PER_BASE     ((uint32_t) 0x42000000UL)  /* Peripheral Address Space bit-band area */
116 #define BITBAND_RAM_BASE     ((uint32_t) 0x22000000UL)  /* SRAM Address Space bit-band area */
117 
BITBAND_PER(volatile uint32_t * addr,uint32_t bit,uint32_t val)118 __STATIC_INLINE__ void BITBAND_PER(volatile uint32_t *addr, uint32_t bit, uint32_t val)
119 {
120     uint32_t tmp = BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) << 5) + (bit << 2);
121     *((volatile uint32_t *)tmp) = (uint32_t)val;
122 }
123 
BITBAND_SRAM(uint32_t * addr,uint32_t bit,uint32_t val)124 __STATIC_INLINE__ void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
125 {
126     uint32_t tmp = BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) << 5) + (bit << 2);
127     *((volatile uint32_t *)tmp) = (uint32_t)val;
128 }
129 
130 #if defined ( __GNUC__ )
131 #ifndef __weak
132 #define __weak   __attribute__((weak))
133 #endif  /* __weak */
134 #ifndef __packed
135 #define __packed __attribute__((__packed__))
136 #endif  /* __packed */
137 #endif /* __GNUC__ */
138 
139 #ifdef __cplusplus
140 }
141 #endif /* __cplusplus */
142 
143 #endif /* __TYPE_H__ */
144 
145 /************* (C) COPYRIGHT Eastsoft Microelectronics *****END OF FILE****/
146