-
Notifications
You must be signed in to change notification settings - Fork 38
/
hal_ll_tim.h
217 lines (200 loc) · 6.1 KB
/
hal_ll_tim.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/****************************************************************************
**
** Copyright (C) ${COPYRIGHT_YEAR} MikroElektronika d.o.o.
** Contact: https://www.mikroe.com/contact
**
** This file is part of the mikroSDK package
**
** Commercial License Usage
**
** Licensees holding valid commercial NECTO compilers AI licenses may use this
** file in accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The MikroElektronika Company.
** For licensing terms and conditions see
** https://www.mikroe.com/legal/software-license-agreement.
** For further information use the contact form at
** https://www.mikroe.com/contact.
**
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used for
** non-commercial projects under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
/*!
* @file hal_ll_tim.h
* @brief Brief file description.
*/
#ifndef _HAL_LL_TIM_H_
#define _HAL_LL_TIM_H_
#ifdef __cplusplus
extern "C"{
#endif
#include "hal_ll_target.h"
typedef struct
{
handle_t *hal_ll_tim_handle;
handle_t *hal_drv_tim_handle;
bool init_ll_state;
} hal_ll_tim_handle_register_t;
/**
* TIM modules
*/
typedef enum
{
HAL_LL_CCP_MODULE_DEFAULT = 0xFF,
#if defined(CCP_MODULE_1)
HAL_LL_CCP_MODULE_1 = 1,
#endif
#if defined(CCP_MODULE_2)
HAL_LL_CCP_MODULE_2 = 2,
#endif
#if defined(CCP_MODULE_3)
HAL_LL_CCP_MODULE_3 = 3,
#endif
#if defined(CCP_MODULE_4)
HAL_LL_CCP_MODULE_4 = 4,
#endif
#if defined(CCP_MODULE_5)
HAL_LL_CCP_MODULE_5 = 5,
#endif
#if defined(CCP_MODULE_6)
HAL_LL_CCP_MODULE_6 = 6,
#endif
#if defined(CCP_MODULE_7)
HAL_LL_CCP_MODULE_7 = 7,
#endif
#if defined(CCP_MODULE_8)
HAL_LL_CCP_MODULE_8 = 8,
#endif
#if defined(CCP_MODULE_9)
HAL_LL_CCP_MODULE_9 = 9,
#endif
#if defined(CCP_MODULE_10)
HAL_LL_CCP_MODULE_10 = 10,
#endif
HAL_LL_CCP_MODULE_NONE
} hal_ll_ccp_module_number_t;
/**
* @brief Registers handler for future use.
*
* Registers low level and hal level handlers
* for use with appropriate functions.
*
* @param pin TIM pin.
* @param handle_map HAL layer local handle map.
* @param hal_module_id HAL layer module number.
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined error values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_tim_register_handle( hal_ll_pin_name_t pin, hal_ll_tim_handle_register_t *handle_map,
uint8_t *hal_module_id );
/**
* @brief Configures specified module.
*
* Performs module configuration on the hardware
* level. Enables module specific clock gate and
* sets adequate alternate function values.
*
* @param[in] *handle HAL context object handle.
*
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_module_configure_tim( handle_t *handle );
/**
* @brief Enables counter for TIM module.
*
* Initializes TIM module on hardware level, if not already initialized and
* starts TIM module.
*
* @param handle TIM handle.
*
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined error values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_tim_start( handle_t *handle );
/**
* @brief Stops counter for TIM module.
*
* The TIM Module needs to be initialized so that
* the stop can be done.
*
* @param handle TIM handle.
*
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined error values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_tim_stop( handle_t *handle );
/**
* @brief Set TIM frequency in Hertz.
*
* This function is used to set the TIM frequency, it
* stops TIM module and sets duty_cycle on 0.
* Take into consideration that the module
* will be re-initialized on the hardware level.
*
* @param handle TIM handle.
* @param freq_hz TIM frequency in hz.
*
* @return This function returns the frequency value in hz,
* to which the PWM module is set.
*
* @note If the frequency value is less than allowed,
* the frequency will be set to the lowest possible value for the specified TIM.
*/
uint32_t hal_ll_tim_set_freq( handle_t *handle, uint32_t freq_hz );
/**
* @brief Set TIM duty cycle in percentages.
*
* The user should enter the duty_ratio in percentages.
* The dut_ratio value should be between 0 and 1
* (where 0 represents 0% and 1 represents 100%).
*
* @param handle TIM handle.
* @param duty_ratio TIM duty ratio in percentages.
*
* @return hal_ll_err_t Module specific error.
*
* @note Returns one of pre-defined error values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_tim_set_duty( handle_t *handle, float duty_ratio );
/**
* @brief Closes TIM master HAL and HAL_LOW_LEVEL context object.
*
* De-allocates hardware resources for specific driver object and
* de-initializes the module on a hardware level.
*
* @param handle TIM handle.
*
* @return void None.
*/
void hal_ll_tim_close( handle_t *handle );
#ifdef __cplusplus
}
#endif
#endif // _HAL_LL_TIM_H_