Harald Welte | d1bd5c4 | 2019-05-17 16:38:30 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief Generic CALENDAR 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 | #ifndef _HPL_CALENDER_H_INCLUDED |
| 34 | #define _HPL_CALENDER_H_INCLUDED |
| 35 | |
| 36 | #include <compiler.h> |
| 37 | #include <utils_list.h> |
| 38 | #include "hpl_irq.h" |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | /** |
| 45 | * \brief Calendar structure |
| 46 | * |
| 47 | * The Calendar structure forward declaration. |
| 48 | */ |
| 49 | struct calendar_dev; |
| 50 | |
| 51 | /** |
| 52 | * \brief Available mask options for alarms. |
| 53 | * |
| 54 | * Available mask options for alarms. |
| 55 | */ |
| 56 | enum calendar_alarm_option { |
| 57 | /** Alarm disabled. */ |
| 58 | CALENDAR_ALARM_MATCH_DISABLED = 0, |
| 59 | /** Alarm match on second. */ |
| 60 | CALENDAR_ALARM_MATCH_SEC, |
| 61 | /** Alarm match on second and minute. */ |
| 62 | CALENDAR_ALARM_MATCH_MIN, |
| 63 | /** Alarm match on second, minute, and hour. */ |
| 64 | CALENDAR_ALARM_MATCH_HOUR, |
| 65 | /** Alarm match on second, minute, hour, and day. */ |
| 66 | CALENDAR_ALARM_MATCH_DAY, |
| 67 | /** Alarm match on second, minute, hour, day, and month. */ |
| 68 | CALENDAR_ALARM_MATCH_MONTH, |
| 69 | /** Alarm match on second, minute, hour, day, month and year. */ |
| 70 | CALENDAR_ALARM_MATCH_YEAR |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * \brief Available mode for alarms. |
| 75 | */ |
| 76 | enum calendar_alarm_mode { ONESHOT = 1, REPEAT }; |
| 77 | /** |
| 78 | * \brief Prototype of callback on alarm match |
| 79 | */ |
| 80 | typedef void (*calendar_drv_cb_alarm_t)(struct calendar_dev *const dev); |
| 81 | |
| 82 | /** |
| 83 | * \brief Prototype of callback on tamper detect |
| 84 | */ |
| 85 | typedef void (*tamper_drv_cb_t)(struct calendar_dev *const dev); |
| 86 | |
| 87 | /** |
| 88 | * \brief Structure of Calendar instance |
| 89 | */ |
| 90 | struct calendar_dev { |
| 91 | /** Pointer to the hardware base */ |
| 92 | void *hw; |
| 93 | /** Alarm match callback */ |
| 94 | calendar_drv_cb_alarm_t callback; |
| 95 | /** Tamper callback */ |
| 96 | tamper_drv_cb_t callback_tamper; |
| 97 | /** IRQ struct */ |
| 98 | struct _irq_descriptor irq; |
| 99 | }; |
| 100 | /** |
| 101 | * \brief Time struct for calendar |
| 102 | */ |
| 103 | struct calendar_time { |
| 104 | /*range from 0 to 59*/ |
| 105 | uint8_t sec; |
| 106 | /*range from 0 to 59*/ |
| 107 | uint8_t min; |
| 108 | /*range from 0 to 23*/ |
| 109 | uint8_t hour; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * \brief Time struct for calendar |
| 114 | */ |
| 115 | struct calendar_date { |
| 116 | /*range from 1 to 28/29/30/31*/ |
| 117 | uint8_t day; |
| 118 | /*range from 1 to 12*/ |
| 119 | uint8_t month; |
| 120 | /*absolute year>= 1970(such as 2000)*/ |
| 121 | uint16_t year; |
| 122 | }; |
| 123 | |
| 124 | /** \brief Calendar driver struct |
| 125 | * |
| 126 | */ |
| 127 | struct calendar_descriptor { |
| 128 | struct calendar_dev device; |
| 129 | struct list_descriptor alarms; |
| 130 | /*base date/time = base_year/1/1/0/0/0(year/month/day/hour/min/sec)*/ |
| 131 | uint32_t base_year; |
| 132 | uint8_t flags; |
| 133 | }; |
| 134 | |
| 135 | /** \brief Date&Time struct for calendar |
| 136 | */ |
| 137 | struct calendar_date_time { |
| 138 | struct calendar_time time; |
| 139 | struct calendar_date date; |
| 140 | }; |
| 141 | |
| 142 | /** \brief struct for alarm time |
| 143 | */ |
| 144 | struct _calendar_alarm { |
| 145 | struct calendar_date_time datetime; |
| 146 | uint32_t timestamp; |
| 147 | enum calendar_alarm_option option; |
| 148 | enum calendar_alarm_mode mode; |
| 149 | }; |
| 150 | |
| 151 | /** \enum for tamper detection mode |
| 152 | */ |
| 153 | enum tamper_detection_mode { TAMPER_MODE_OFF = 0U, TAMPER_MODE_WAKE, TAMPER_MODE_CAPTURE, TAMPER_MODE_ACTL }; |
| 154 | |
| 155 | /** \enum for tamper detection mode |
| 156 | */ |
| 157 | enum tamper_id { TAMPID0 = 0U, TAMPID1, TAMPID2, TAMPID3, TAMPID4 }; |
| 158 | /** |
| 159 | * \brief Initialize Calendar instance |
| 160 | * |
| 161 | * \param[in] dev The pointer to calendar device struct |
| 162 | * |
| 163 | * \return ERR_NONE on success, or an error code on failure. |
| 164 | */ |
| 165 | int32_t _calendar_init(struct calendar_dev *const dev); |
| 166 | |
| 167 | /** |
| 168 | * \brief Deinitialize Calendar instance |
| 169 | * |
| 170 | * \param[in] dev The pointer to calendar device struct |
| 171 | * |
| 172 | * \return ERR_NONE on success, or an error code on failure. |
| 173 | */ |
| 174 | int32_t _calendar_deinit(struct calendar_dev *const dev); |
| 175 | |
| 176 | /** |
| 177 | * \brief Enable Calendar instance |
| 178 | * |
| 179 | * \param[in] dev The pointer to calendar device struct |
| 180 | * |
| 181 | * \return ERR_NONE on success, or an error code on failure. |
| 182 | */ |
| 183 | int32_t _calendar_enable(struct calendar_dev *const dev); |
| 184 | |
| 185 | /** |
| 186 | * \brief Disable Calendar instance |
| 187 | * |
| 188 | * \param[in] dev The pointer to calendar device struct |
| 189 | * |
| 190 | * \return ERR_NONE on success, or an error code on failure. |
| 191 | */ |
| 192 | int32_t _calendar_disable(struct calendar_dev *const dev); |
| 193 | /** |
| 194 | * \brief Set counter for calendar |
| 195 | * |
| 196 | * \param[in] dev The pointer to calendar device struct |
| 197 | * \param[in] counter The counter for set |
| 198 | * |
| 199 | * \return ERR_NONE on success, or an error code on failure. |
| 200 | */ |
| 201 | int32_t _calendar_set_counter(struct calendar_dev *const dev, const uint32_t counter); |
| 202 | |
| 203 | /** |
| 204 | * \brief Get counter for calendar |
| 205 | * |
| 206 | * \param[in] dev The pointer to calendar device struct |
| 207 | * |
| 208 | * \return return current counter value |
| 209 | */ |
| 210 | uint32_t _calendar_get_counter(struct calendar_dev *const dev); |
| 211 | |
| 212 | /** |
| 213 | * \brief Set compare value for calendar |
| 214 | * |
| 215 | * \param[in] dev The pointer to calendar device struct |
| 216 | * \param[in] comp The compare value for set |
| 217 | * |
| 218 | * \return ERR_NONE on success, or an error code on failure. |
| 219 | */ |
| 220 | int32_t _calendar_set_comp(struct calendar_dev *const dev, const uint32_t comp); |
| 221 | |
| 222 | /** |
| 223 | * \brief Get compare value for calendar |
| 224 | * |
| 225 | * \param[in] dev The pointer to calendar device struct |
| 226 | * |
| 227 | * \return return current compare value |
| 228 | */ |
| 229 | uint32_t _calendar_get_comp(struct calendar_dev *const dev); |
| 230 | |
| 231 | /** |
| 232 | * \brief Register callback for calendar alarm |
| 233 | * |
| 234 | * \param[in] dev The pointer to calendar device struct |
| 235 | * \param[in] callback The pointer to callback function |
| 236 | * |
| 237 | * \return ERR_NONE on success, or an error code on failure. |
| 238 | */ |
| 239 | int32_t _calendar_register_callback(struct calendar_dev *const dev, calendar_drv_cb_alarm_t callback); |
| 240 | |
| 241 | /** |
| 242 | * \brief Set calendar IRQ |
| 243 | * |
| 244 | * \param[in] dev The pointer to calendar device struct |
| 245 | */ |
| 246 | void _calendar_set_irq(struct calendar_dev *const dev); |
| 247 | |
| 248 | /** |
| 249 | * \brief Register callback for tamper detection |
| 250 | * |
| 251 | * \param[in] dev The pointer to calendar device struct |
| 252 | * \param[in] callback The pointer to callback function |
| 253 | * |
| 254 | * \return ERR_NONE on success, or an error code on failure. |
| 255 | */ |
| 256 | int32_t _tamper_register_callback(struct calendar_dev *const dev, tamper_drv_cb_t callback_tamper); |
| 257 | |
| 258 | /** |
| 259 | * \brief Find tamper is detected on specified pin |
| 260 | * |
| 261 | * \param[in] dev The pointer to calendar device struct |
| 262 | * \param[in] enum Tamper ID number |
| 263 | * |
| 264 | * \return true on detection success and false on failure. |
| 265 | */ |
| 266 | bool _is_tamper_detected(struct calendar_dev *const dev, enum tamper_id tamper_id_pin); |
| 267 | |
| 268 | /** |
| 269 | * \brief brief Clear the Tamper ID flag |
| 270 | * |
| 271 | * \param[in] dev The pointer to calendar device struct |
| 272 | * \param[in] enum Tamper ID number |
| 273 | * |
| 274 | * \return ERR_NONE |
| 275 | */ |
| 276 | int32_t _tamper_clear_tampid_flag(struct calendar_dev *const dev, enum tamper_id tamper_id_pin); |
| 277 | |
| 278 | /** |
| 279 | * \brief Enable Debounce Asynchronous Feature |
| 280 | * |
| 281 | * \param[in] dev The pointer to calendar device struct |
| 282 | * |
| 283 | * \return ERR_NONE on success, or an error code on failure. |
| 284 | */ |
| 285 | int32_t _tamper_enable_debounce_asynchronous(struct calendar_dev *const dev); |
| 286 | |
| 287 | /** |
| 288 | * \brief Disable Tamper Debounce Asynchronous Feature |
| 289 | * |
| 290 | * \param[in] dev The pointer to calendar device struct |
| 291 | * |
| 292 | * \return ERR_NONE on success, or an error code on failure. |
| 293 | */ |
| 294 | int32_t _tamper_disable_debounce_asynchronous(struct calendar_dev *const dev); |
| 295 | |
| 296 | /** |
| 297 | * \brief Enable Tamper Debounce Majority Feature |
| 298 | * |
| 299 | * \param[in] dev The pointer to calendar device struct |
| 300 | * |
| 301 | * \return ERR_NONE on success, or an error code on failure. |
| 302 | */ |
| 303 | int32_t _tamper_enable_debounce_majority(struct calendar_dev *const dev); |
| 304 | |
| 305 | /** |
| 306 | * \brief Enable Tamper Debounce Majority Feature |
| 307 | * |
| 308 | * \param[in] dev The pointer to calendar device struct |
| 309 | * |
| 310 | * \return ERR_NONE on success, or an error code on failure. |
| 311 | */ |
| 312 | int32_t _tamper_disable_debounce_majority(struct calendar_dev *const dev); |
| 313 | |
| 314 | #ifdef __cplusplus |
| 315 | } |
| 316 | #endif |
| 317 | |
| 318 | #endif /* _HPL_RTC_H_INCLUDED */ |