remove unused ASF code

This commit is contained in:
Joey Castillo 2021-09-27 17:51:52 -04:00
parent a65dcf1ec8
commit b353e47506
8 changed files with 0 additions and 1570 deletions

View file

@ -31,8 +31,6 @@ LDFLAGS += -mcpu=cortex-m0plus -mthumb
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--script=$(TOP)//watch-library/linker/saml22j18.ld
# If you add any additional directories with headers, add them to this list, e.g.
# ../drivers/
INCLUDES += \
-I$(TOP)/tinyusb/src \
-I$(TOP)/boards/$(BOARD) \
@ -54,7 +52,6 @@ INCLUDES += \
-I$(TOP)/watch-library/hpl/oscctrl/ \
-I$(TOP)/watch-library/hpl/pm/ \
-I$(TOP)/watch-library/hpl/port/ \
-I$(TOP)/watch-library/hpl/rtc/ \
-I$(TOP)/watch-library/hpl/sercom/ \
-I$(TOP)/watch-library/hpl/slcd/ \
-I$(TOP)/watch-library/hpl/systick/ \
@ -64,8 +61,6 @@ INCLUDES += \
-I$(TOP)/watch-library/watch/ \
-I$(TOP)/watch-library
# If you add any additional C files to your project, add them each to this list, e.g.
# ../drivers/st25dv.c
SRCS += \
$(TOP)/tinyusb/src/tusb.c \
$(TOP)/tinyusb/src/common/tusb_fifo.c \
@ -78,7 +73,6 @@ SRCS += \
$(TOP)/watch-library/hw/driver_init.c \
$(TOP)/watch-library/watch/watch.c \
$(TOP)/watch-library/hal/src/hal_atomic.c \
$(TOP)/watch-library/hal/src/hal_calendar.c \
$(TOP)/watch-library/hal/src/hal_delay.c \
$(TOP)/watch-library/hal/src/hal_ext_irq.c \
$(TOP)/watch-library/hal/src/hal_gpio.c \
@ -100,7 +94,6 @@ SRCS += \
$(TOP)/watch-library/hpl/osc32kctrl/hpl_osc32kctrl.c \
$(TOP)/watch-library/hpl/oscctrl/hpl_oscctrl.c \
$(TOP)/watch-library/hpl/pm/hpl_pm.c \
$(TOP)/watch-library/hpl/rtc/hpl_rtc.c \
$(TOP)/watch-library/hpl/sercom/hpl_sercom.c \
$(TOP)/watch-library/hpl/slcd/hpl_slcd.c \
$(TOP)/watch-library/hpl/systick/hpl_systick.c \

View file

@ -1,72 +0,0 @@
===============================
The Calendar driver (bare-bone)
===============================
The Calendar driver provides means to set and get current date and time.
After enabling, an instance of the driver starts counting time from the base date with
the resolution of one second. The default base date is 00:00:00 1st of January 1970.
Only the base year of the base date can be changed via the driver API.
The current date and time is kept internally in a relative form as the difference between
current date and time and the base date and time. This means that changing the base year changes
current date.
The base date and time defines time "zero" or the earliest possible point in time that the calender driver can describe,
this means that current time and alarms can not be set to anything earlier than this time.
The Calendar driver provides alarm functionality.
An alarm is a software trigger which fires on particular date and time with particular periodicity.
Upon firing the given callback function is called.
An alarm can be in single-shot mode, firing only once at matching time; or in repeating mode, meaning that it will
reschedule a new alarm automatically based on repeating mode configuration.
In single-shot mode an alarm is removed from the alarm queue before its callback is called. It allows an application to
reuse the memory of expired alarm in the callback.
An alarm can be triggered on the following events: match on second, minute, hour, day, month or year.
Matching on second means that the alarm is triggered when the value of seconds of the current time is equal to
the alarm's value of seconds. This means repeating alarm with match on seconds is triggered with the period of a minute.
Matching on minute means that the calendars minute and seconds values has to match the alarms, the rest of the date-time
value is ignored. In repeating mode this means a new alarm every hour.
The same logic is applied to match on hour, day, month and year.
Each instance of the Calendar driver supports infinite amount of software alarms, only limited by the amount of RAM available.
Features
--------
* Initialization and de-initialization
* Enabling and disabling
* Date and time operations
* Software alarms
Applications
------------
* A source of current date and time for an embedded system.
* Periodical functionality in low-power applications since the driver is designed to use 1Hz clock.
* Periodical function calls in case if it is more convenient to operate with absolute time.
Dependencies
------------
* This driver expects a counter to be increased by one every second to count date and time correctly.
* Each instance of the driver requires separate hardware timer.
Concurrency
-----------
The Calendar driver is an interrupt driven driver.This means that the interrupt that triggers an alarm may occur during
the process of adding or removing an alarm via the driver's API. In such case the interrupt processing is postponed
until the alarm adding or removing is complete.
The alarm queue is not protected from the access by interrupts not used by the driver. Due to this
it is not recommended to add or remove an alarm from such interrupts: in case if a higher priority interrupt supersedes
the driver's interrupt, adding or removing an alarm may cause unpredictable behavior of the driver.
Limitations
-----------
* Only years divisible by 4 are deemed a leap year, this gives a correct result between the years 1901 to 2099.
* The driver is designed to work outside of an operating system environment, the software alarm queue is therefore processed in interrupt context which may delay execution of other interrupts.
* If there are a lot of frequently called interrupts with the priority higher than the driver's one, it may cause delay in alarm's triggering.
* Changing the base year or setting current date or time does not shift alarms' date and time accordingly or expires alarms.
Knows issues and workarounds
----------------------------
Not applicable

View file

@ -1,159 +0,0 @@
/**
* \file
*
* \brief Generic CALENDAR functionality declaration.
*
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#ifndef _HAL_CALENDER_H_INCLUDED
#define _HAL_CALENDER_H_INCLUDED
#include "hpl_calendar.h"
#include <utils_list.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \addtogroup doc_driver_hal_calendar_async
*
*@{
*/
/** \brief Prototype of callback on alarm match
* \param calendar Pointer to the HAL Calendar instance.
*/
typedef void (*calendar_cb_alarm_t)(struct calendar_descriptor *const calendar);
/** \brief Struct for alarm time
*/
struct calendar_alarm {
struct list_element elem;
struct _calendar_alarm cal_alarm;
calendar_cb_alarm_t callback;
};
/** \brief Initialize the Calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \param hw Pointer to the hardware instance.
* \return Operation status of init
* \retval 0 Completed successfully.
*/
int32_t calendar_init(struct calendar_descriptor *const calendar, const void *hw);
/** \brief Reset the Calendar HAL instance and hardware
*
* Reset Calendar instance to hardware defaults.
*
* \param calendar Pointer to the HAL Calendar instance.
* \return Operation status of reset.
* \retval 0 Completed successfully.
*/
int32_t calendar_deinit(struct calendar_descriptor *const calendar);
/** \brief Enable the Calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \return Operation status of init
* \retval 0 Completed successfully.
*/
int32_t calendar_enable(struct calendar_descriptor *const calendar);
/** \brief Disable the Calendar HAL instance and hardware
*
* Disable Calendar instance to hardware defaults.
*
* \param calendar Pointer to the HAL Calendar instance.
* \return Operation status of reset.
* \retval 0 Completed successfully.
*/
int32_t calendar_disable(struct calendar_descriptor *const calendar);
/** \brief Configure the base year for calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \param p_base_year The desired base year.
* \retval 0 Completed successfully.
*/
int32_t calendar_set_baseyear(struct calendar_descriptor *const calendar, const uint32_t p_base_year);
/** \brief Configure the time for calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \param p_calendar_time Pointer to the time configuration.
* \retval 0 Completed successfully.
*/
int32_t calendar_set_time(struct calendar_descriptor *const calendar, struct calendar_time *const p_calendar_time);
/** \brief Configure the date for calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \param p_calendar_date Pointer to the date configuration.
* \return Operation status of time set.
* \retval 0 Completed successfully.
*/
int32_t calendar_set_date(struct calendar_descriptor *const calendar, struct calendar_date *const p_calendar_date);
/** \brief Get the time for calendar HAL instance and hardware
*
* \param calendar Pointer to the HAL Calendar instance.
* \param date_time Pointer to the value that will be filled with the current time.
* \return Operation status of time retrieve.
* \retval 0 Completed successfully.
*/
int32_t calendar_get_date_time(struct calendar_descriptor *const calendar, struct calendar_date_time *const date_time);
/** \brief Config the alarm time for calendar HAL instance and hardware
*
* Set the alarm time to calendar instance. If the callback is NULL, remove
* the alarm if the alarm is already added, otherwise, ignore the alarm.
*
* \param calendar Pointer to the HAL Calendar instance.
* \param alarm Pointer to the configuration.
* \param callback Pointer to the callback function.
* \return Operation status of alarm time set.
* \retval 0 Completed successfully.
*/
int32_t calendar_set_alarm(struct calendar_descriptor *const calendar, struct calendar_alarm *const alarm,
calendar_cb_alarm_t callback);
/** \brief Retrieve the current driver version
* \return Current driver version.
*/
uint32_t calendar_get_version(void);
/**@}*/
#ifdef __cplusplus
}
#endif
#endif /* _HAL_CALENDER_H_INCLUDED */

View file

@ -33,68 +33,10 @@
#ifndef _HPL_CALENDER_H_INCLUDED
#define _HPL_CALENDER_H_INCLUDED
#include <compiler.h>
#include <utils_list.h>
#include "hpl_irq.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Calendar structure
*
* The Calendar structure forward declaration.
*/
struct calendar_dev;
/**
* \brief Available mask options for alarms.
*
* Available mask options for alarms.
*/
enum calendar_alarm_option {
/** Alarm disabled. */
CALENDAR_ALARM_MATCH_DISABLED = 0,
/** Alarm match on second. */
CALENDAR_ALARM_MATCH_SEC,
/** Alarm match on second and minute. */
CALENDAR_ALARM_MATCH_MIN,
/** Alarm match on second, minute, and hour. */
CALENDAR_ALARM_MATCH_HOUR,
/** Alarm match on second, minute, hour, and day. */
CALENDAR_ALARM_MATCH_DAY,
/** Alarm match on second, minute, hour, day, and month. */
CALENDAR_ALARM_MATCH_MONTH,
/** Alarm match on second, minute, hour, day, month and year. */
CALENDAR_ALARM_MATCH_YEAR
};
/**
* \brief Available mode for alarms.
*/
enum calendar_alarm_mode { ONESHOT = 1, REPEAT };
/**
* \brief Prototype of callback on alarm match
*/
typedef void (*calendar_drv_cb_t)();
typedef void (*calendar_drv_extwake_cb_t)(uint8_t reason);
/**
* \brief Structure of Calendar instance
*/
struct calendar_dev {
/** Pointer to the hardware base */
void *hw;
/** Alarm match callback */
calendar_drv_cb_t callback_alarm;
/** Tamper callback */
calendar_drv_extwake_cb_t callback_tamper;
/** Tick callback */
calendar_drv_cb_t callback_tick;
/** IRQ struct */
struct _irq_descriptor irq;
};
/**
* \brief Time struct for calendar
*/
@ -119,17 +61,6 @@ struct calendar_date {
uint16_t year;
};
/** \brief Calendar driver struct
*
*/
struct calendar_descriptor {
struct calendar_dev device;
struct list_descriptor alarms;
/*base date/time = base_year/1/1/0/0/0(year/month/day/hour/min/sec)*/
uint32_t base_year;
uint8_t flags;
};
/** \brief Date&Time struct for calendar
*/
struct calendar_date_time {
@ -137,188 +68,6 @@ struct calendar_date_time {
struct calendar_date date;
};
/** \brief struct for alarm time
*/
struct _calendar_alarm {
struct calendar_date_time datetime;
uint32_t timestamp;
enum calendar_alarm_option option;
enum calendar_alarm_mode mode;
};
/** \enum for tamper detection mode
*/
enum tamper_detection_mode { TAMPER_MODE_OFF = 0U, TAMPER_MODE_WAKE, TAMPER_MODE_CAPTURE, TAMPER_MODE_ACTL };
/** \enum for tamper detection mode
*/
enum tamper_id { TAMPID0 = 0U, TAMPID1, TAMPID2, TAMPID3, TAMPID4 };
/**
* \brief Initialize Calendar instance
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_init(struct calendar_dev *const dev);
/**
* \brief Deinitialize Calendar instance
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_deinit(struct calendar_dev *const dev);
/**
* \brief Enable Calendar instance
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_enable(struct calendar_dev *const dev);
/**
* \brief Disable Calendar instance
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_disable(struct calendar_dev *const dev);
/**
* \brief Set counter for calendar
*
* \param[in] dev The pointer to calendar device struct
* \param[in] counter The counter for set
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_set_counter(struct calendar_dev *const dev, const uint32_t counter);
/**
* \brief Get counter for calendar
*
* \param[in] dev The pointer to calendar device struct
*
* \return return current counter value
*/
uint32_t _calendar_get_counter(struct calendar_dev *const dev);
/**
* \brief Set compare value for calendar
*
* \param[in] dev The pointer to calendar device struct
* \param[in] comp The compare value for set
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_set_comp(struct calendar_dev *const dev, const uint32_t comp);
/**
* \brief Get compare value for calendar
*
* \param[in] dev The pointer to calendar device struct
*
* \return return current compare value
*/
uint32_t _calendar_get_comp(struct calendar_dev *const dev);
/**
* \brief Register callback for calendar alarm
*
* \param[in] dev The pointer to calendar device struct
* \param[in] callback The pointer to callback function
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _calendar_register_callback(struct calendar_dev *const dev, calendar_drv_cb_t callback);
/**
* \brief Set calendar IRQ
*
* \param[in] dev The pointer to calendar device struct
*/
void _calendar_set_irq(struct calendar_dev *const dev);
/**
* \brief Register callback for 1Hz tick from prescaler
*
* \param[in] dev The pointer to calendar device struct
* \param[in] callback The pointer to callback function
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _prescaler_register_callback(struct calendar_dev *const dev, calendar_drv_cb_t callback);
/**
* \brief Register callback for tamper detection
*
* \param[in] dev The pointer to calendar device struct
* \param[in] callback The pointer to callback function
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _extwake_register_callback(struct calendar_dev *const dev, calendar_drv_extwake_cb_t callback);
/**
* \brief Find tamper is detected on specified pin
*
* \param[in] dev The pointer to calendar device struct
* \param[in] enum Tamper ID number
*
* \return true on detection success and false on failure.
*/
bool _is_tamper_detected(struct calendar_dev *const dev, enum tamper_id tamper_id_pin);
/**
* \brief brief Clear the Tamper ID flag
*
* \param[in] dev The pointer to calendar device struct
* \param[in] enum Tamper ID number
*
* \return ERR_NONE
*/
int32_t _tamper_clear_tampid_flag(struct calendar_dev *const dev, enum tamper_id tamper_id_pin);
/**
* \brief Enable Debounce Asynchronous Feature
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _tamper_enable_debounce_asynchronous(struct calendar_dev *const dev);
/**
* \brief Disable Tamper Debounce Asynchronous Feature
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _tamper_disable_debounce_asynchronous(struct calendar_dev *const dev);
/**
* \brief Enable Tamper Debounce Majority Feature
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _tamper_enable_debounce_majority(struct calendar_dev *const dev);
/**
* \brief Enable Tamper Debounce Majority Feature
*
* \param[in] dev The pointer to calendar device struct
*
* \return ERR_NONE on success, or an error code on failure.
*/
int32_t _tamper_disable_debounce_majority(struct calendar_dev *const dev);
#ifdef __cplusplus
}
#endif

View file

@ -1,645 +0,0 @@
/**
* \file
*
* \brief Generic CALENDAR functionality implementation.
*
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#include "hal_calendar.h"
#include <utils.h>
#include <utils_assert.h>
#include <hal_atomic.h>
#define CALENDAR_VERSION 0x00000001u
#define SECS_IN_LEAP_YEAR 31622400
#define SECS_IN_NON_LEAP_YEAR 31536000
#define SECS_IN_31DAYS 2678400
#define SECS_IN_30DAYS 2592000
#define SECS_IN_29DAYS 2505600
#define SECS_IN_28DAYS 2419200
#define SECS_IN_DAY 86400
#define SECS_IN_HOUR 3600
#define SECS_IN_MINUTE 60
#define DEFAULT_BASE_YEAR 1970
#define SET_ALARM_BUSY 1
#define PROCESS_ALARM_BUSY 2
/** \brief leap year check
* \retval false not leap year.
* \retval true leap year.
*/
static bool leap_year(uint16_t year)
{
if (year & 3) {
return false;
} else {
return true;
}
}
/** \brief calculate the seconds in specified year/month
* \retval 0 month error.
*/
static uint32_t get_secs_in_month(uint32_t year, uint8_t month)
{
uint32_t sec_in_month = 0;
if (leap_year(year)) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sec_in_month = SECS_IN_31DAYS;
break;
case 2:
sec_in_month = SECS_IN_29DAYS;
break;
case 4:
case 6:
case 9:
case 11:
sec_in_month = SECS_IN_30DAYS;
break;
default:
break;
}
} else {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sec_in_month = SECS_IN_31DAYS;
break;
case 2:
sec_in_month = SECS_IN_28DAYS;
break;
case 4:
case 6:
case 9:
case 11:
sec_in_month = SECS_IN_30DAYS;
break;
default:
break;
}
}
return sec_in_month;
}
/** \brief convert timestamp to date/time
*/
static int32_t convert_timestamp_to_datetime(struct calendar_descriptor *const calendar, uint32_t ts,
struct calendar_date_time *dt)
{
uint32_t tmp, sec_in_year, sec_in_month;
uint32_t tmp_year = calendar->base_year;
uint8_t tmp_month = 1;
uint8_t tmp_day = 1;
uint8_t tmp_hour = 0;
uint8_t tmp_minutes = 0;
tmp = ts;
/* Find year */
while (true) {
sec_in_year = leap_year(tmp_year) ? SECS_IN_LEAP_YEAR : SECS_IN_NON_LEAP_YEAR;
if (tmp >= sec_in_year) {
tmp -= sec_in_year;
tmp_year++;
} else {
break;
}
}
/* Find month of year */
while (true) {
sec_in_month = get_secs_in_month(tmp_year, tmp_month);
if (tmp >= sec_in_month) {
tmp -= sec_in_month;
tmp_month++;
} else {
break;
}
}
/* Find day of month */
while (true) {
if (tmp >= SECS_IN_DAY) {
tmp -= SECS_IN_DAY;
tmp_day++;
} else {
break;
}
}
/* Find hour of day */
while (true) {
if (tmp >= SECS_IN_HOUR) {
tmp -= SECS_IN_HOUR;
tmp_hour++;
} else {
break;
}
}
/* Find minute in hour */
while (true) {
if (tmp >= SECS_IN_MINUTE) {
tmp -= SECS_IN_MINUTE;
tmp_minutes++;
} else {
break;
}
}
dt->date.year = tmp_year;
dt->date.month = tmp_month;
dt->date.day = tmp_day;
dt->time.hour = tmp_hour;
dt->time.min = tmp_minutes;
dt->time.sec = tmp;
return ERR_NONE;
}
/** \brief convert date/time to timestamp
* \return timestamp
*/
static uint32_t convert_datetime_to_timestamp(struct calendar_descriptor *const calendar, struct calendar_date_time *dt)
{
uint32_t tmp = 0;
uint32_t i = 0;
uint8_t year, month, day, hour, minutes, seconds;
year = dt->date.year - calendar->base_year;
month = dt->date.month;
day = dt->date.day;
hour = dt->time.hour;
minutes = dt->time.min;
seconds = dt->time.sec;
/* tot up year field */
for (i = 0; i < year; ++i) {
if (leap_year(calendar->base_year + i)) {
tmp += SECS_IN_LEAP_YEAR;
} else {
tmp += SECS_IN_NON_LEAP_YEAR;
}
}
/* tot up month field */
for (i = 1; i < month; ++i) {
tmp += get_secs_in_month(dt->date.year, i);
}
/* tot up day/hour/minute/second fields */
tmp += (day - 1) * SECS_IN_DAY;
tmp += hour * SECS_IN_HOUR;
tmp += minutes * SECS_IN_MINUTE;
tmp += seconds;
return tmp;
}
/** \brief calibrate timestamp to make desired timestamp ahead of current timestamp
*/
static void calibrate_timestamp(struct calendar_descriptor *const calendar, struct calendar_alarm *alarm,
struct calendar_alarm *current_dt)
{
uint32_t alarm_ts;
uint32_t current_ts = current_dt->cal_alarm.timestamp;
(void)calendar;
alarm_ts = alarm->cal_alarm.timestamp;
/* calibrate timestamp */
switch (alarm->cal_alarm.option) {
case CALENDAR_ALARM_MATCH_SEC:
if (alarm_ts <= current_ts) {
alarm_ts += SECS_IN_MINUTE;
}
break;
case CALENDAR_ALARM_MATCH_MIN:
if (alarm_ts <= current_ts) {
alarm_ts += SECS_IN_HOUR;
}
break;
case CALENDAR_ALARM_MATCH_HOUR:
if (alarm_ts <= current_ts) {
alarm_ts += SECS_IN_DAY;
}
break;
case CALENDAR_ALARM_MATCH_DAY:
if (alarm_ts <= current_ts) {
alarm_ts += get_secs_in_month(current_dt->cal_alarm.datetime.date.year,
current_dt->cal_alarm.datetime.date.month);
}
break;
case CALENDAR_ALARM_MATCH_MONTH:
if (alarm_ts <= current_ts) {
if (leap_year(current_dt->cal_alarm.datetime.date.year)) {
alarm_ts += SECS_IN_LEAP_YEAR;
} else {
alarm_ts += SECS_IN_NON_LEAP_YEAR;
}
}
break;
/* do nothing for year match */
case CALENDAR_ALARM_MATCH_YEAR:
default:
break;
}
/* desired timestamp after calibration */
alarm->cal_alarm.timestamp = alarm_ts;
}
/** \brief complete alarm to absolute date/time, then fill up the timestamp
*/
static void fill_alarm(struct calendar_descriptor *const calendar, struct calendar_alarm *alarm)
{
struct calendar_alarm current_dt;
uint32_t tmp, current_ts;
/* get current date/time */
current_ts = _calendar_get_counter(&calendar->device);
convert_timestamp_to_datetime(calendar, current_ts, &current_dt.cal_alarm.datetime);
current_dt.cal_alarm.timestamp = current_ts;
/* complete alarm */
switch (alarm->cal_alarm.option) {
case CALENDAR_ALARM_MATCH_SEC:
alarm->cal_alarm.datetime.date.year = current_dt.cal_alarm.datetime.date.year;
alarm->cal_alarm.datetime.date.month = current_dt.cal_alarm.datetime.date.month;
alarm->cal_alarm.datetime.date.day = current_dt.cal_alarm.datetime.date.day;
alarm->cal_alarm.datetime.time.hour = current_dt.cal_alarm.datetime.time.hour;
alarm->cal_alarm.datetime.time.min = current_dt.cal_alarm.datetime.time.min;
break;
case CALENDAR_ALARM_MATCH_MIN:
alarm->cal_alarm.datetime.date.year = current_dt.cal_alarm.datetime.date.year;
alarm->cal_alarm.datetime.date.month = current_dt.cal_alarm.datetime.date.month;
alarm->cal_alarm.datetime.date.day = current_dt.cal_alarm.datetime.date.day;
alarm->cal_alarm.datetime.time.hour = current_dt.cal_alarm.datetime.time.hour;
break;
case CALENDAR_ALARM_MATCH_HOUR:
alarm->cal_alarm.datetime.date.year = current_dt.cal_alarm.datetime.date.year;
alarm->cal_alarm.datetime.date.month = current_dt.cal_alarm.datetime.date.month;
alarm->cal_alarm.datetime.date.day = current_dt.cal_alarm.datetime.date.day;
break;
case CALENDAR_ALARM_MATCH_DAY:
alarm->cal_alarm.datetime.date.year = current_dt.cal_alarm.datetime.date.year;
alarm->cal_alarm.datetime.date.month = current_dt.cal_alarm.datetime.date.month;
break;
case CALENDAR_ALARM_MATCH_MONTH:
alarm->cal_alarm.datetime.date.year = current_dt.cal_alarm.datetime.date.year;
break;
case CALENDAR_ALARM_MATCH_YEAR:
break;
default:
break;
}
/* fill up the timestamp */
tmp = convert_datetime_to_timestamp(calendar, &alarm->cal_alarm.datetime);
alarm->cal_alarm.timestamp = tmp;
/* calibrate the timestamp */
calibrate_timestamp(calendar, alarm, &current_dt);
convert_timestamp_to_datetime(calendar, alarm->cal_alarm.timestamp, &alarm->cal_alarm.datetime);
}
/** \brief add new alarm into the list in ascending order
*/
static int32_t calendar_add_new_alarm(struct list_descriptor *list, struct calendar_alarm *alarm)
{
struct calendar_descriptor *calendar = CONTAINER_OF(list, struct calendar_descriptor, alarms);
struct calendar_alarm * head, *it, *prev = NULL;
/*get the head of alarms list*/
head = (struct calendar_alarm *)list_get_head(list);
/*if head is null, insert new alarm as head*/
if (!head) {
list_insert_as_head(list, alarm);
_calendar_set_comp(&calendar->device, alarm->cal_alarm.timestamp);
return ERR_NONE;
}
/*insert the new alarm in accending order, the head will be invoked firstly */
for (it = head; it; it = (struct calendar_alarm *)list_get_next_element(it)) {
if (alarm->cal_alarm.timestamp <= it->cal_alarm.timestamp) {
break;
}
prev = it;
}
/*insert new alarm into the list */
if (it == head) {
list_insert_as_head(list, alarm);
/*get the head and set it into register*/
_calendar_set_comp(&calendar->device, alarm->cal_alarm.timestamp);
} else {
list_insert_after(prev, alarm);
}
return ERR_NONE;
}
/** \brief callback for alarm
*/
static void calendar_alarm(struct calendar_dev *const dev)
{
struct calendar_descriptor *calendar = CONTAINER_OF(dev, struct calendar_descriptor, device);
struct calendar_alarm *head, *it, current_dt;
if ((calendar->flags & SET_ALARM_BUSY) || (calendar->flags & PROCESS_ALARM_BUSY)) {
calendar->flags |= PROCESS_ALARM_BUSY;
return;
}
/* get current timestamp */
current_dt.cal_alarm.timestamp = _calendar_get_counter(dev);
/* get the head */
head = (struct calendar_alarm *)list_get_head(&calendar->alarms);
ASSERT(head);
/* remove all alarms and invoke them*/
for (it = head; it; it = (struct calendar_alarm *)list_get_head(&calendar->alarms)) {
/* check the timestamp with current timestamp*/
if (it->cal_alarm.timestamp <= current_dt.cal_alarm.timestamp) {
list_remove_head(&calendar->alarms);
it->callback(calendar);
if (it->cal_alarm.mode == REPEAT) {
calibrate_timestamp(calendar, it, &current_dt);
convert_timestamp_to_datetime(calendar, it->cal_alarm.timestamp, &it->cal_alarm.datetime);
calendar_add_new_alarm(&calendar->alarms, it);
}
} else {
break;
}
}
/*if no alarm in the list, register null */
if (!it) {
_calendar_register_callback(&calendar->device, NULL);
return;
}
/*put the new head into register */
_calendar_set_comp(&calendar->device, it->cal_alarm.timestamp);
}
/** \brief Initialize Calendar
*/
int32_t calendar_init(struct calendar_descriptor *const calendar, const void *hw)
{
int32_t ret = 0;
/* Sanity check arguments */
ASSERT(calendar);
if (calendar->device.hw == hw) {
/* Already initialized with current configuration */
return ERR_NONE;
} else if (calendar->device.hw != NULL) {
/* Initialized with another configuration */
return ERR_ALREADY_INITIALIZED;
}
calendar->device.hw = (void *)hw;
ret = _calendar_init(&calendar->device);
calendar->base_year = DEFAULT_BASE_YEAR;
return ret;
}
/** \brief Reset the Calendar
*/
int32_t calendar_deinit(struct calendar_descriptor *const calendar)
{
/* Sanity check arguments */
ASSERT(calendar);
if (calendar->device.hw == NULL) {
return ERR_NOT_INITIALIZED;
}
_calendar_deinit(&calendar->device);
calendar->device.hw = NULL;
return ERR_NONE;
}
/** \brief Enable the Calendar
*/
int32_t calendar_enable(struct calendar_descriptor *const calendar)
{
/* Sanity check arguments */
ASSERT(calendar);
_calendar_enable(&calendar->device);
return ERR_NONE;
}
/** \brief Disable the Calendar
*/
int32_t calendar_disable(struct calendar_descriptor *const calendar)
{
/* Sanity check arguments */
ASSERT(calendar);
_calendar_disable(&calendar->device);
return ERR_NONE;
}
/** \brief Set base year for calendar
*/
int32_t calendar_set_baseyear(struct calendar_descriptor *const calendar, const uint32_t p_base_year)
{
/* Sanity check arguments */
ASSERT(calendar);
calendar->base_year = p_base_year;
return ERR_NONE;
}
/** \brief Set time for calendar
*/
int32_t calendar_set_time(struct calendar_descriptor *const calendar, struct calendar_time *const p_calendar_time)
{
struct calendar_date_time dt;
uint32_t current_ts, new_ts;
/* Sanity check arguments */
ASSERT(calendar);
/* convert time to timestamp */
current_ts = _calendar_get_counter(&calendar->device);
convert_timestamp_to_datetime(calendar, current_ts, &dt);
dt.time.sec = p_calendar_time->sec;
dt.time.min = p_calendar_time->min;
dt.time.hour = p_calendar_time->hour;
new_ts = convert_datetime_to_timestamp(calendar, &dt);
_calendar_set_counter(&calendar->device, new_ts);
return ERR_NONE;
}
/** \brief Set date for calendar
*/
int32_t calendar_set_date(struct calendar_descriptor *const calendar, struct calendar_date *const p_calendar_date)
{
struct calendar_date_time dt;
uint32_t current_ts, new_ts;
/* Sanity check arguments */
ASSERT(calendar);
/* convert date to timestamp */
current_ts = _calendar_get_counter(&calendar->device);
convert_timestamp_to_datetime(calendar, current_ts, &dt);
dt.date.day = p_calendar_date->day;
dt.date.month = p_calendar_date->month;
dt.date.year = p_calendar_date->year;
new_ts = convert_datetime_to_timestamp(calendar, &dt);
_calendar_set_counter(&calendar->device, new_ts);
return ERR_NONE;
}
/** \brief Get date/time for calendar
*/
int32_t calendar_get_date_time(struct calendar_descriptor *const calendar, struct calendar_date_time *const date_time)
{
uint32_t current_ts;
/* Sanity check arguments */
ASSERT(calendar);
/* convert current timestamp to date/time */
current_ts = _calendar_get_counter(&calendar->device);
convert_timestamp_to_datetime(calendar, current_ts, date_time);
return ERR_NONE;
}
/** \brief Set alarm for calendar
*/
int32_t calendar_set_alarm(struct calendar_descriptor *const calendar, struct calendar_alarm *const alarm,
calendar_cb_alarm_t callback)
{
struct calendar_alarm *head;
/* Sanity check arguments */
ASSERT(calendar);
ASSERT(alarm);
alarm->callback = callback;
fill_alarm(calendar, alarm);
calendar->flags |= SET_ALARM_BUSY;
head = (struct calendar_alarm *)list_get_head(&calendar->alarms);
if (head != NULL) {
/* already added */
if (is_list_element(&calendar->alarms, alarm)) {
if (callback == NULL) {
/* remove alarm */
list_delete_element(&calendar->alarms, alarm);
if (!list_get_head(&calendar->alarms)) {
_calendar_register_callback(&calendar->device, NULL);
}
} else {
/* re-add */
list_delete_element(&calendar->alarms, alarm);
calendar_add_new_alarm(&calendar->alarms, alarm);
}
} else if (callback != NULL) {
calendar_add_new_alarm(&calendar->alarms, alarm);
}
calendar->flags &= ~SET_ALARM_BUSY;
if (calendar->flags & PROCESS_ALARM_BUSY) {
CRITICAL_SECTION_ENTER()
calendar->flags &= ~PROCESS_ALARM_BUSY;
_calendar_set_irq(&calendar->device);
CRITICAL_SECTION_LEAVE()
}
} else if (callback != NULL) {
/* if head is NULL, Register callback*/
_calendar_register_callback(&calendar->device, calendar_alarm);
calendar_add_new_alarm(&calendar->alarms, alarm);
}
calendar->flags &= ~SET_ALARM_BUSY;
return ERR_NONE;
}
/** \brief Retrieve driver version
* \return Current driver version
*/
uint32_t calendar_get_version(void)
{
return CALENDAR_VERSION;
}

View file

@ -1,383 +0,0 @@
/**
* \file
*
* \brief RTC Driver
*
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#include <hpl_calendar.h>
#include <utils_assert.h>
#include <hpl_rtc_config.h>
/*!< Pointer to hpl device */
static struct calendar_dev *_rtc_dev = NULL;
/**
* \brief Initializes the RTC module with given configurations.
*/
int32_t _calendar_init(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
_rtc_dev = dev;
if (hri_rtcmode0_get_CTRLA_ENABLE_bit(dev->hw)) {
#if !CONF_RTC_INIT_RESET
return ERR_DENIED;
#else
hri_rtcmode0_clear_CTRLA_ENABLE_bit(dev->hw);
hri_rtcmode0_wait_for_sync(dev->hw, RTC_MODE0_SYNCBUSY_ENABLE);
#endif
}
hri_rtcmode0_set_CTRLA_SWRST_bit(dev->hw);
hri_rtcmode0_wait_for_sync(dev->hw, RTC_MODE0_SYNCBUSY_SWRST);
#if CONF_RTC_EVENT_CONTROL_ENABLE == 1
hri_rtcmode0_write_EVCTRL_reg(
dev->hw,
(CONF_RTC_PEREO0 << RTC_MODE0_EVCTRL_PEREO0_Pos) | (CONF_RTC_PEREO1 << RTC_MODE0_EVCTRL_PEREO1_Pos)
| (CONF_RTC_PEREO2 << RTC_MODE0_EVCTRL_PEREO2_Pos) | (CONF_RTC_PEREO3 << RTC_MODE0_EVCTRL_PEREO3_Pos)
| (CONF_RTC_PEREO4 << RTC_MODE0_EVCTRL_PEREO4_Pos) | (CONF_RTC_PEREO5 << RTC_MODE0_EVCTRL_PEREO5_Pos)
| (CONF_RTC_PEREO6 << RTC_MODE0_EVCTRL_PEREO6_Pos) | (CONF_RTC_PEREO7 << RTC_MODE0_EVCTRL_PEREO7_Pos)
| (CONF_RTC_COMPE0 << RTC_MODE0_EVCTRL_CMPEO_Pos) | (CONF_RTC_OVFEO << RTC_MODE0_EVCTRL_OVFEO_Pos));
#endif
hri_rtcmode0_write_CTRLA_reg(dev->hw, RTC_MODE0_CTRLA_PRESCALER(CONF_RTC_PRESCALER) | RTC_MODE0_CTRLA_COUNTSYNC);
hri_rtc_write_TAMPCTRL_reg(
dev->hw,
(CONF_RTC_TAMPER_INACT_0 << RTC_TAMPCTRL_IN0ACT_Pos) | (CONF_RTC_TAMPER_INACT_1 << RTC_TAMPCTRL_IN1ACT_Pos)
| (CONF_RTC_TAMPER_INACT_2 << RTC_TAMPCTRL_IN2ACT_Pos)
| (CONF_RTC_TAMPER_INACT_3 << RTC_TAMPCTRL_IN3ACT_Pos)
| (CONF_RTC_TAMPER_INACT_4 << RTC_TAMPCTRL_IN4ACT_Pos) | (CONF_RTC_TAMP_LVL_0 << RTC_TAMPCTRL_TAMLVL0_Pos)
| (CONF_RTC_TAMP_LVL_1 << RTC_TAMPCTRL_TAMLVL1_Pos) | (CONF_RTC_TAMP_LVL_2 << RTC_TAMPCTRL_TAMLVL2_Pos)
| (CONF_RTC_TAMP_LVL_3 << RTC_TAMPCTRL_TAMLVL3_Pos) | (CONF_RTC_TAMP_LVL_4 << RTC_TAMPCTRL_TAMLVL4_Pos)
| (CONF_RTC_TAMP_DEBNC_0 << RTC_TAMPCTRL_DEBNC0_Pos) | (CONF_RTC_TAMP_DEBNC_1 << RTC_TAMPCTRL_DEBNC1_Pos)
| (CONF_RTC_TAMP_DEBNC_2 << RTC_TAMPCTRL_DEBNC2_Pos) | (CONF_RTC_TAMP_DEBNC_3 << RTC_TAMPCTRL_DEBNC3_Pos)
| (CONF_RTC_TAMP_DEBNC_4 << RTC_TAMPCTRL_DEBNC4_Pos));
if ((CONF_RTC_TAMPER_INACT_0 == TAMPER_MODE_ACTL) | (CONF_RTC_TAMPER_INACT_1 == TAMPER_MODE_ACTL)
| (CONF_RTC_TAMPER_INACT_2 == TAMPER_MODE_ACTL) | (CONF_RTC_TAMPER_INACT_3 == TAMPER_MODE_ACTL)
| (CONF_RTC_TAMPER_INACT_4 == TAMPER_MODE_ACTL)) {
hri_rtcmode0_set_CTRLB_RTCOUT_bit(dev->hw);
}
return ERR_NONE;
}
/**
* \brief Deinit the RTC module
*/
int32_t _calendar_deinit(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
NVIC_DisableIRQ(RTC_IRQn);
dev->callback_alarm = NULL;
dev->callback_tick = NULL;
dev->callback_tamper = NULL;
hri_rtcmode0_clear_CTRLA_ENABLE_bit(dev->hw);
hri_rtcmode0_set_CTRLA_SWRST_bit(dev->hw);
return ERR_NONE;
}
/**
* \brief Enable the RTC module
*/
int32_t _calendar_enable(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
hri_rtcmode0_set_CTRLA_ENABLE_bit(dev->hw);
return ERR_NONE;
}
/**
* \brief Disable the RTC module
*/
int32_t _calendar_disable(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
hri_rtcmode0_clear_CTRLA_ENABLE_bit(dev->hw);
return ERR_NONE;
}
/**
* \brief Set the current calendar time to desired time.
*/
int32_t _calendar_set_counter(struct calendar_dev *const dev, const uint32_t counter)
{
ASSERT(dev && dev->hw);
hri_rtcmode0_write_COUNT_reg(dev->hw, counter);
return ERR_NONE;
}
/**
* \brief Get current counter
*/
uint32_t _calendar_get_counter(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
return hri_rtcmode0_read_COUNT_reg(dev->hw);
}
/**
* \brief Set the compare for the specified value.
*/
int32_t _calendar_set_comp(struct calendar_dev *const dev, const uint32_t comp)
{
ASSERT(dev && dev->hw);
hri_rtcmode0_write_COMP_reg(dev->hw, 0, comp);
return ERR_NONE;
}
/**
* \brief Get the compare value
*/
uint32_t _calendar_get_comp(struct calendar_dev *const dev)
{
ASSERT(dev && dev->hw);
return hri_rtcmode0_read_COMP_reg(dev->hw, 0);
}
/**
* \brief Find tamper is detected on specified pin
*/
bool _is_tamper_detected(struct calendar_dev *const dev, enum tamper_id tamper_id_pin)
{
bool value;
ASSERT(dev && dev->hw);
value = ((hri_rtc_read_TAMPID_reg(dev->hw) >> tamper_id_pin) & 0x01);
return value;
}
/**
* \brief Clear the Tamper ID flag
*/
int32_t _tamper_clear_tampid_flag(struct calendar_dev *const dev, enum tamper_id tamper_id_pin)
{
ASSERT(dev && dev->hw);
hri_rtc_write_TAMPID_reg(dev->hw, (true << tamper_id_pin));
return ERR_NONE;
}
/**
* \brief Enable Tamper Debounce Asynchronous Feature
*/
int32_t _tamper_enable_debounce_asynchronous(struct calendar_dev *const dev)
{
int32_t return_value;
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, false);
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
if (hri_rtcmode0_read_CTRLA_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
return_value = ERR_FAILURE;
} else {
hri_rtcmode0_write_CTRLB_DEBASYNC_bit(dev->hw, true);
return_value = ERR_NONE;
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, true);
}
return return_value;
}
/**
* \brief Disable Tamper Debounce Asynchronous Feature
*/
int32_t _tamper_disable_debounce_asynchronous(struct calendar_dev *const dev)
{
int32_t return_value;
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, false);
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
if (hri_rtcmode0_read_CTRLA_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
return_value = ERR_FAILURE;
} else {
hri_rtcmode0_write_CTRLB_DEBASYNC_bit(dev->hw, false);
return_value = ERR_NONE;
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, true);
}
return return_value;
}
/**
* \brief Enable Tamper Debounce Majority Feature
*/
int32_t _tamper_enable_debounce_majority(struct calendar_dev *const dev)
{
int32_t return_value;
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, false);
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
if (hri_rtcmode0_read_CTRLA_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
return_value = ERR_FAILURE;
} else {
hri_rtcmode0_write_CTRLB_DEBMAJ_bit(dev->hw, true);
return_value = ERR_NONE;
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, true);
}
return return_value;
}
/**
* \brief Disable Tamper Debounce Majority Feature
*/
int32_t _tamper_disable_debounce_majority(struct calendar_dev *const dev)
{
int32_t return_value;
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, false);
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
if (hri_rtcmode0_read_CTRLA_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
return_value = ERR_FAILURE;
} else {
hri_rtcmode0_write_CTRLB_DEBMAJ_bit(dev->hw, false);
return_value = ERR_NONE;
while (hri_rtcmode0_read_SYNCBUSY_reg(dev->hw) & RTC_MODE2_CTRLA_ENABLE) {
}
hri_rtcmode0_write_CTRLA_ENABLE_bit(dev->hw, true);
}
return return_value;
}
int32_t _prescaler_register_callback(struct calendar_dev *const dev, calendar_drv_cb_t callback)
{
ASSERT(dev && dev->hw);
/* Check callback */
if (callback != NULL) {
/* register the callback */
dev->callback_tick = callback;
/* enable RTC_IRQn */
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
/* enable periodic interrupt */
hri_rtcmode0_set_INTEN_PER7_bit(dev->hw);
} else {
/* disable periodic interrupt */
hri_rtcmode0_clear_INTEN_PER7_bit(dev->hw);
}
return ERR_NONE;
}
int32_t _extwake_register_callback(struct calendar_dev *const dev, calendar_drv_extwake_cb_t callback)
{
ASSERT(dev && dev->hw);
/* Check callback */
if (callback != NULL) {
/* register the callback */
dev->callback_tamper = callback;
/* enable RTC_IRQn */
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
hri_rtcmode0_clear_interrupt_TAMPER_bit(dev->hw);
/* enable tamper interrupt */
hri_rtcmode0_set_INTEN_TAMPER_bit(dev->hw);
} else {
/* disable tamper interrupt */
hri_rtcmode0_clear_INTEN_TAMPER_bit(dev->hw);
}
return ERR_NONE;
}
/**
* \brief Registers callback for the specified callback type
*/
int32_t _calendar_register_callback(struct calendar_dev *const dev, calendar_drv_cb_t callback)
{
ASSERT(dev && dev->hw);
/* Check callback */
if (callback != NULL) {
/* register the callback */
dev->callback_alarm = callback;
/* enable RTC_IRQn */
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
/* enable cmp */
hri_rtcmode0_set_INTEN_CMP0_bit(dev->hw);
} else {
/* disable cmp */
hri_rtcmode0_clear_INTEN_CMP0_bit(dev->hw);
}
return ERR_NONE;
}
void _calendar_set_irq(struct calendar_dev *const dev)
{
(void)dev;
NVIC_SetPendingIRQ(RTC_IRQn);
}

View file

@ -1,52 +0,0 @@
/**
* \file
*
* \brief RTC
*
* Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*/
#ifndef _HPL_RTC2_V200_H_INCLUDED
#define _HPL_RTC2_V200_H_INCLUDED
#include <hpl_timer.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Retrieve timer helper functions
*
* \return A pointer to set of timer helper functions
*/
struct _timer_hpl_interface *_rtc_get_timer(void);
#ifdef __cplusplus
}
#endif
#endif /* _HPL_RTC2_V200_H_INCLUDED */

View file

@ -31,7 +31,6 @@ extern "C" {
#include <hal_io.h>
#include <hal_sleep.h>
#include <hal_ext_irq.h>
#include <hal_calendar.h>
#include <hal_i2c_m_sync.h>
#include <hal_delay.h>
#include <hal_slcd_sync.h>