1 /**
2   *********************************************************************************
3   *
4   * @file    ald_tsense.h
5   * @brief   Header file of TSENSE module driver.
6   *
7   * @version V1.0
8   * @date    15 Dec 2017
9   * @author  AE Team
10   * @note
11   *
12   * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
13   *
14   * SPDX-License-Identifier: Apache-2.0
15   *
16   * Licensed under the Apache License, Version 2.0 (the License); you may
17   * not use this file except in compliance with the License.
18   * You may obtain a copy of the License at
19   *
20   * www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   * See the License for the specific language governing permissions and
26   * limitations under the License.
27   *
28   ********************************************************************************
29   */
30 
31 #ifndef __ALD_TSENSE_H__
32 #define __ALD_TSENSE_H__
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include "utils.h"
39 
40 
41 /** @addtogroup ES32FXXX_ALD
42   * @{
43   */
44 
45 /** @addtogroup TSENSE
46   * @{
47   */
48 
49 /** @defgroup TSENSE_Public_Macros TSENSE Public Macros
50   * @{
51   */
52 #define TSENSE_LOCK()		(WRITE_REG(TSENSE->WPR, 0x0U))
53 #define TSENSE_UNLOCK()		(WRITE_REG(TSENSE->WPR, 0xA55A9669U))
54 #define TSENSE_ENABLE()					\
55 do {							\
56 	TSENSE_UNLOCK();				\
57 	SET_BIT(TSENSE->CR, TSENSE_CR_EN_MSK);		\
58 	TSENSE_LOCK();					\
59 } while (0)
60 #define TSENSE_DISABLE()				\
61 do {							\
62 	TSENSE_UNLOCK();				\
63 	CLEAR_BIT(TSENSE->CR, TSENSE_CR_EN_MSK);	\
64 	TSENSE_LOCK();					\
65 } while (0)
66 #define TSENSE_REQ_ENABLE()				\
67 do {							\
68 	TSENSE_UNLOCK();				\
69 	SET_BIT(TSENSE->CR, TSENSE_CR_REQEN_MSK);	\
70 	TSENSE_LOCK();					\
71 } while (0)
72 #define TSENSE_REQ_DISABLE()				\
73 do {							\
74 	TSENSE_UNLOCK();				\
75 	CLEAR_BIT(TSENSE->CR, TSENSE_CR_REQEN_MSK);	\
76 	TSENSE_LOCK();					\
77 } while (0)
78 #define TSENSE_CTN_ENABLE()				\
79 do {							\
80 	TSENSE_UNLOCK();				\
81 	SET_BIT(TSENSE->CR, TSENSE_CR_CTN_MSK);		\
82 	TSENSE_LOCK();					\
83 } while (0)
84 #define TSENSE_CTN_DISABLE()				\
85 do {							\
86 	TSENSE_UNLOCK();				\
87 	CLEAR_BIT(TSENSE->CR, TSENSE_CR_CTN_MSK);	\
88 	TSENSE_LOCK();					\
89 } while (0)
90 #define TSENSE_RESET()					\
91 do {							\
92 	TSENSE_UNLOCK();				\
93 	SET_BIT(TSENSE->CR, TSENSE_CR_RST_MSK);		\
94 	TSENSE_LOCK();					\
95 } while (0)
96 #define	TSENSE_LTGR_WR(data)				\
97 do {							\
98 	TSENSE_UNLOCK();				\
99 	WRITE_REG(TSENSE->LTGR, (data));		\
100 	TSENSE_LOCK();					\
101 } while (0)
102 #define	TSENSE_HTGR_WR(data)				\
103 do {							\
104 	TSENSE_UNLOCK();				\
105 	WRITE_REG(TSENSE->HTGR, (data));		\
106 	TSENSE_LOCK();					\
107 } while (0)
108 #define	TSENSE_TBDR_WR(data)				\
109 do {							\
110 	TSENSE_UNLOCK();				\
111 	WRITE_REG(TSENSE->TBDR, (data));		\
112 	TSENSE_LOCK();					\
113 } while (0)
114 #define	TSENSE_TCALBDR_WR(data)				\
115 do {							\
116 	TSENSE_UNLOCK();				\
117 	WRITE_REG(TSENSE->TCALBDR, (data));		\
118 	TSENSE_LOCK();					\
119 } while (0)
120 /**
121   * @}
122   */
123 
124 /** @defgroup TSENSE_Public_Types TSENSE Public Types
125   * @{
126   */
127 /**
128   * @brief Temperature update time
129   */
130 typedef enum {
131 	TSENSE_UPDATE_CYCLE_3 = 0x3U,	/**< 3 Cycles */
132 	TSENSE_UPDATE_CYCLE_4 = 0x4U,	/**< 4 Cycles */
133 	TSENSE_UPDATE_CYCLE_5 = 0x5U,	/**< 5 Cycles */
134 	TSENSE_UPDATE_CYCLE_6 = 0x6U,	/**< 6 Cycles */
135 	TSENSE_UPDATE_CYCLE_7 = 0x7U,	/**< 7 Cycles */
136 } tsense_update_cycle_t;
137 
138 /**
139   * @brief Temperature output mode
140   */
141 typedef enum {
142 	TSENSE_OUTPUT_MODE_200  = 0x0U,	/**< 200 cycles update one temperature */
143 	TSENSE_OUTPUT_MODE_400  = 0x1U,	/**< 400 cycles update one temperature */
144 	TSENSE_OUTPUT_MODE_800  = 0x2U,	/**< 800 cycles update one temperature */
145 	TSENSE_OUTPUT_MODE_1600 = 0x3U,	/**< 1600 cycles update one temperature */
146 	TSENSE_OUTPUT_MODE_3200 = 0x4U,	/**< 3200 cycles update one temperature */
147 } tsense_output_mode_t;
148 
149 /**
150   * @brief Source select
151   */
152 typedef enum {
153 	TSENSE_SOURCE_LOSC        = 0x0U,	/**< LOSC */
154 	TSENSE_SOURCE_LRC         = 0x1U,	/**< LRC */
155 } tsense_source_sel_t;
156 
157 
158 /**
159   * @brief Define callback function type
160   */
161 typedef void (*tsense_cbk)(uint16_t value, ald_status_t status);
162 /**
163   * @}
164   */
165 
166 /**
167   * @defgroup TSENSE_Private_Macros TSENSE Private Macros
168   * @{
169   */
170 #define IS_TSENSE_SOURCE_SEL(x)	(((x) == TSENSE_SOURCE_LOSC) || \
171                                  ((x) == TSENSE_SOURCE_LRC))
172 /**
173   * @}
174   */
175 
176 /** @addtogroup TSENSE_Public_Functions
177   * @{
178   */
179 /** @addtogroup TSENSE_Public_Functions_Group1
180   * @{
181   */
182 /* Initialization functions */
183 extern void ald_tsense_init(void);
184 extern void ald_tsense_source_select(tsense_source_sel_t sel);
185 /**
186   * @}
187   */
188 /** @addtogroup TSENSE_Public_Functions_Group2
189   * @{
190   */
191 /* Control functions */
192 extern ald_status_t ald_tsense_get_value(uint16_t *tsense);
193 extern void ald_tsense_get_value_by_it(tsense_cbk cbk);
194 extern void ald_tsense_irq_handler(void);
195 /**
196   * @}
197   */
198 /**
199   * @}
200   */
201 
202 /**
203   * @}
204   */
205 
206 /**
207   * @}
208   */
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif /* __ALD_TSENSE_H__ */
214