aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hc32f460/driver/inc/hc32f460_ots.h
blob: af1b3163dd70eada33ac05aa00a193539c780588 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
 *
 * This software component is licensed by HDSC under BSD 3-Clause license
 * (the "License"); You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                    opensource.org/licenses/BSD-3-Clause
 */
/******************************************************************************/
/** \file hc32f460_ots.h
 **
 ** A detailed description is available at
 ** @link OtsGroup Ots description @endlink
 **
 **   - 2018-10-26  CDT First version for Device Driver Library of Ots.
 **
 ******************************************************************************/
#ifndef __HC32F460_OTS_H__
#define __HC32F460_OTS_H__

/*******************************************************************************
 * Include files
 ******************************************************************************/
#include "hc32_common.h"

/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif

/**
 *******************************************************************************
 ** \defgroup OtsGroup On-chip Temperature Sensor(OTS)
 **
 ******************************************************************************/
//@{

/*******************************************************************************
 * Global type definitions ('typedef')
 ******************************************************************************/
/* Automatically turn off the analog temperature sensor after the temperature
   measurement is over. */
typedef enum en_ots_auto_off
{
    OtsAutoOff_Disable = 0x0,           ///< Disable automatically turn off OTS.
    OtsAutoOff_Enable  = 0x1,           ///< Enable automatically turn off OTS.
} en_ots_auto_off_t;

/* Temperature measurement end interrupt request. */
typedef enum en_ots_ie
{
    OtsInt_Disable = 0x0,               ///< Disable OTS interrupt.
    OtsInt_Enable  = 0x1,               ///< Enable OTS interrupt.
} en_ots_ie_t;

/* OTS clock selection. */
typedef enum en_ots_clk_sel
{
    OtsClkSel_Xtal = 0x0,               ///< Select XTAL as OTS clock.
    OtsClkSel_Hrc  = 0x1,               ///< Select HRC as OTS clock.
} en_ots_clk_sel_t;

/* OTS OTS initialization structure definition. */
typedef struct stc_ots_init
{
    en_ots_auto_off_t enAutoOff;        ///< @ref en_ots_auto_off_t.
    en_ots_clk_sel_t  enClkSel;         ///< @ref en_ots_clk_sel_t.
    float32_t f32SlopeK;                ///< K: Temperature slope (calculated by calibration experiment). */
    float32_t f32OffsetM;               ///< M: Temperature offset (calculated by calibration experiment). */
} stc_ots_init_t;

/* OTS common trigger source select */
typedef enum en_ots_com_trigger
{
    OtsComTrigger_1   = 0x1,            ///< Select common trigger 1.
    OtsComTrigger_2   = 0x2,            ///< Select common trigger 2.
    OtsComTrigger_1_2 = 0x3,            ///< Select common trigger 1 and 2.
} en_ots_com_trigger_t;

/*******************************************************************************
 * Global variable definitions ('extern')
 ******************************************************************************/

/*******************************************************************************
 * Global function prototypes (definition in C source)
 ******************************************************************************/

/**
 * @brief  Start OTS.
 * @param  None
 * @retval None
 */
__STATIC_INLINE void OTS_Start(void)
{
    bM4_OTS_CTL_OTSST = (uint32_t)1u;
}

/**
 * @brief  Stop OTS.
 * @param  None
 * @retval None
 */
__STATIC_INLINE void OTS_Stop(void)
{
    bM4_OTS_CTL_OTSST = (uint32_t)0u;
}

en_result_t OTS_Init(const stc_ots_init_t *pstcInit);
void OTS_DeInit(void);

en_result_t OTS_Polling(float32_t *pf32Temp, uint32_t u32Timeout);

void OTS_IntCmd(en_functional_state_t enNewState);
void OTS_SetTriggerSrc(en_event_src_t enEvent);
void OTS_ComTriggerCmd(en_ots_com_trigger_t enComTrigger, en_functional_state_t enState);

en_result_t OTS_ScalingExperiment(uint16_t *pu16Dr1, uint16_t *pu16Dr2, \
                                  uint16_t *pu16Ecr, float32_t *pf32A,  \
                                  uint32_t u32Timeout);

float OTS_CalculateTemp(void);

//@} // OtsGroup

#ifdef __cplusplus
}
#endif

#endif /* __HC32F460_OTS_H__ */

/*******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/