1 /**
2  * @file    afe_timer.h
3  * @brief   Timer functions for AFE and HART UART interfacing.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_TIMER_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_TIMER_H_
29 
30 /* **** Includes **** */
31 #include "tmr_regs.h"
32 #include "tmr.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* **** Definitions **** */
39 // AFE timer will be lower 16 bits
40 #define AFE_SPI_TIMER (TMR_BIT_MODE_16A)
41 #define HART_TIMER (TMR_BIT_MODE_16B)
42 
43 /**
44  * @brief   The callback routine used by afe_timer_delay_async() when the delay is complete
45  *          or aborted early.
46  *
47  * @param   result      See \ref MXC_Error_Codes for the list of error codes.
48  */
49 typedef void (*afe_timeout_complete_t)(int result);
50 
51 /* **** Function Prototypes **** */
52 /**
53  * @brief      Configure AFE Timer
54  * @param      tmr   Pointer to selected timer registers
55  * @return     #E_NO_ERROR if everything is successful. See \ref MXC_Error_Codes for the list of error codes.
56  */
57 int afe_timer_config(mxc_tmr_regs_t *tmr);
58 
59 /**
60  * @brief      Starts a non-blocking delay for the specified number of
61  *             microseconds.
62  * @details    Uses the timer instance pass in /ref afe_timer_setup to time the
63  *              requested delay. Supports two 16 bit timers in one, so must also
64  *              specify which half to use.
65  * @param      timer_selection    Which 16bit timer half to use. /ref AFE_SPI_TIMER, /ref HART_TIMER
66  * @param      timeout_us    microseconds to delay
67  * @param      cb  Function pointer to function called upon delay completion. /ref afe_timeout_complete_t
68  * @return     #E_NO_ERROR if everything is successful. See \ref MXC_Error_Codes for the list of error codes.
69  */
70 int afe_timer_delay_async(mxc_tmr_bit_mode_t timer_selection, uint32_t timeout_us,
71                           afe_timeout_complete_t cb);
72 
73 /**
74  * @brief      Returns the status of a non-blocking delay request
75  * @pre        Start the asynchronous delay by calling /ref afe_timer_delay_async.
76  * @param      timer_selection    Which 16bit timer half to use. /ref AFE_SPI_TIMER, /ref HART_TIMER
77  * @return     #E_BUSY until the requested delay time has expired.
78  */
79 int afe_timer_delay_check(mxc_tmr_bit_mode_t timer_selection);
80 
81 /**
82  * @brief      Stops an asynchronous delay previously started. Calls CB if not NULL.
83  * @pre        Start the asynchronous delay by calling /ref afe_timer_delay_async.
84  * @param      timer_selection    Which 16bit timer half to use. /ref AFE_SPI_TIMER, /ref HART_TIMER
85  */
86 int afe_timer_delay_abort(mxc_tmr_bit_mode_t timer_selection);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_TIMER_H_
93