Harald Welte | d1bd5c4 | 2019-05-17 16:38:30 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief Timer related functionality declaration. |
| 5 | * |
| 6 | * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries. |
| 7 | * |
| 8 | * \asf_license_start |
| 9 | * |
| 10 | * \page License |
| 11 | * |
| 12 | * Subject to your compliance with these terms, you may use Microchip |
| 13 | * software and any derivatives exclusively with Microchip products. |
| 14 | * It is your responsibility to comply with third party license terms applicable |
| 15 | * to your use of third party software (including open source software) that |
| 16 | * may accompany Microchip software. |
| 17 | * |
| 18 | * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, |
| 19 | * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, |
| 20 | * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, |
| 21 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE |
| 22 | * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL |
| 23 | * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE |
| 24 | * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE |
| 25 | * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT |
| 26 | * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY |
| 27 | * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, |
| 28 | * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. |
| 29 | * |
| 30 | * \asf_license_stop |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #ifndef _HPL_TIMER_H_INCLUDED |
| 35 | #define _HPL_TIMER_H_INCLUDED |
| 36 | |
| 37 | /** |
| 38 | * \addtogroup HPL Timer |
| 39 | * |
| 40 | * \section hpl_timer_rev Revision History |
| 41 | * - v1.0.0 Initial Release |
| 42 | * |
| 43 | *@{ |
| 44 | */ |
| 45 | |
| 46 | #include <compiler.h> |
| 47 | #include <hpl_irq.h> |
| 48 | |
| 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
| 53 | /** |
| 54 | * \brief Timer device structure |
| 55 | * |
| 56 | * The Timer device structure forward declaration. |
| 57 | */ |
| 58 | struct _timer_device; |
| 59 | |
| 60 | /** |
| 61 | * \brief Timer interrupt callbacks |
| 62 | */ |
| 63 | struct _timer_callbacks { |
| 64 | void (*period_expired)(struct _timer_device *device); |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * \brief Timer device structure |
| 69 | */ |
| 70 | struct _timer_device { |
| 71 | struct _timer_callbacks timer_cb; |
| 72 | struct _irq_descriptor irq; |
| 73 | void * hw; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * \brief Timer functions, pointers to low-level functions |
| 78 | */ |
| 79 | struct _timer_hpl_interface { |
| 80 | int32_t (*init)(struct _timer_device *const device, void *const hw); |
| 81 | void (*deinit)(struct _timer_device *const device); |
| 82 | void (*start_timer)(struct _timer_device *const device); |
| 83 | void (*stop_timer)(struct _timer_device *const device); |
| 84 | void (*set_timer_period)(struct _timer_device *const device, const uint32_t clock_cycles); |
| 85 | uint32_t (*get_period)(const struct _timer_device *const device); |
| 86 | bool (*is_timer_started)(const struct _timer_device *const device); |
| 87 | void (*set_timer_irq)(struct _timer_device *const device); |
| 88 | }; |
| 89 | /** |
| 90 | * \brief Initialize TCC |
| 91 | * |
| 92 | * This function does low level TCC configuration. |
| 93 | * |
| 94 | * \param[in] device The pointer to timer device instance |
| 95 | * \param[in] hw The pointer to hardware instance |
| 96 | * |
| 97 | * \return Initialization status. |
| 98 | */ |
| 99 | int32_t _timer_init(struct _timer_device *const device, void *const hw); |
| 100 | |
| 101 | /** |
| 102 | * \brief Deinitialize TCC |
| 103 | * |
| 104 | * \param[in] device The pointer to timer device instance |
| 105 | */ |
| 106 | void _timer_deinit(struct _timer_device *const device); |
| 107 | |
| 108 | /** |
| 109 | * \brief Start hardware timer |
| 110 | * |
| 111 | * \param[in] device The pointer to timer device instance |
| 112 | */ |
| 113 | void _timer_start(struct _timer_device *const device); |
| 114 | |
| 115 | /** |
| 116 | * \brief Stop hardware timer |
| 117 | * |
| 118 | * \param[in] device The pointer to timer device instance |
| 119 | */ |
| 120 | void _timer_stop(struct _timer_device *const device); |
| 121 | |
| 122 | /** |
| 123 | * \brief Set timer period |
| 124 | * |
| 125 | * \param[in] device The pointer to timer device instance |
| 126 | */ |
| 127 | void _timer_set_period(struct _timer_device *const device, const uint32_t clock_cycles); |
| 128 | |
| 129 | /** |
| 130 | * \brief Retrieve timer period |
| 131 | * |
| 132 | * \param[in] device The pointer to timer device instance |
| 133 | * |
| 134 | * \return Timer period |
| 135 | */ |
| 136 | uint32_t _timer_get_period(const struct _timer_device *const device); |
| 137 | |
| 138 | /** |
| 139 | * \brief Check if timer is running |
| 140 | * |
| 141 | * \param[in] device The pointer to timer device instance |
| 142 | * |
| 143 | * \return Check status. |
| 144 | * \retval true The given timer is running |
| 145 | * \retval false The given timer is not running |
| 146 | */ |
| 147 | bool _timer_is_started(const struct _timer_device *const device); |
| 148 | |
| 149 | /** |
| 150 | * \brief Set timer IRQ |
| 151 | * |
| 152 | * \param[in] device The pointer to timer device instance |
| 153 | */ |
| 154 | void _timer_set_irq(struct _timer_device *const device); |
| 155 | |
| 156 | #ifdef __cplusplus |
| 157 | } |
| 158 | #endif |
| 159 | /**@}*/ |
| 160 | #endif /* _HPL_TIMER_H_INCLUDED */ |