KETCube
|
This file contains implementation of the ketCube RTC driver. More...
#include <math.h>
#include <time.h>
#include "hw.h"
#include "low_power.h"
#include "systime.h"
#include "ketCube_terminal.h"
#include "ketCube_mcu.h"
Macros | |
#define | MIN_ALARM_DELAY 3 /* in ticks */ |
#define | N_PREDIV_S 10 |
#define | PREDIV_S ((1<<N_PREDIV_S)-1) |
#define | PREDIV_A (1<<(15-N_PREDIV_S))-1 |
#define | RTC_ALARMSUBSECONDMASK (N_PREDIV_S<<RTC_ALRMASSR_MASKSS_Pos) |
#define | USEC_NUMBER 1000000 |
#define | MSEC_NUMBER (USEC_NUMBER/1000) |
#define | RTC_ALARM_TIME_BASE (USEC_NUMBER>>N_PREDIV_S) |
#define | COMMON_FACTOR 3 |
#define | CONV_NUMER (MSEC_NUMBER>>COMMON_FACTOR) |
#define | CONV_DENOM (1<<(N_PREDIV_S-COMMON_FACTOR)) |
#define | DAYS_IN_LEAP_YEAR ( ( uint32_t ) 366U ) |
#define | DAYS_IN_YEAR ( ( uint32_t ) 365U ) |
#define | SECONDS_IN_1DAY ( ( uint32_t )86400U ) |
#define | SECONDS_IN_1HOUR ( ( uint32_t ) 3600U ) |
#define | SECONDS_IN_1MINUTE ( ( uint32_t ) 60U ) |
#define | MINUTES_IN_1HOUR ( ( uint32_t ) 60U ) |
#define | HOURS_IN_1DAY ( ( uint32_t ) 24U ) |
#define | DAYS_IN_MONTH_CORRECTION_NORM ((uint32_t) 0x99AAA0 ) |
#define | DAYS_IN_MONTH_CORRECTION_LEAP ((uint32_t) 0x445550 ) |
#define | DIVC(X, N) ( ( (X) + (N) -1 ) / (N) ) |
Functions | |
uint32_t | ketCube_RTC_GetTimerElapsedTime (void) |
Get the RTC timer elapsed time since the last Alarm was set. More... | |
uint32_t | ketCube_RTC_SetTimerContext (void) |
set Time Reference set also the RTC_DateStruct and RTC_TimeStruct More... | |
static void | ketCube_RTC_SetConfig (void) |
Configures the RTC timer. More... | |
static void | ketCube_RTC_SetAlarmConfig (void) |
configure alarm at init More... | |
static void | ketCube_RTC_StartWakeUpAlarm (uint32_t timeoutValue) |
start wake up alarm More... | |
static uint64_t | ketCube_RTC_GetCalendarValue (RTC_DateTypeDef *RTC_DateStruct, RTC_TimeTypeDef *RTC_TimeStruct) |
get current time from calendar in ticks More... | |
ketCube_cfg_DrvError_t | ketCube_RTC_Init (void) |
Initializes the RTC timer. More... | |
void | ketCube_RTC_setMcuWakeUpTime (void) |
calculates the wake up time between wake up and mcu start More... | |
int16_t | ketCube_RTC_getMcuWakeUpTime (void) |
uint32_t | ketCube_RTC_GetMinimumTimeout (void) |
returns the wake up time in ticks More... | |
uint32_t | ketCube_RTC_ms2Tick (TimerTime_t timeMicroSec) |
converts time in ms to time in ticks More... | |
TimerTime_t | ketCube_RTC_Tick2ms (uint32_t tick) |
converts time in ticks to time in ms More... | |
void | ketCube_RTC_SetAlarm (uint32_t timeout) |
Set the alarm. More... | |
uint32_t | ketCube_RTC_GetTimerValue (void) |
Get the RTC timer value. More... | |
void | ketCube_RTC_StopAlarm (void) |
Stop the Alarm. More... | |
void | ketCube_RTC_IrqHandler (void) |
RTC IRQ Handler on the RTC Alarm. More... | |
void | ketCube_RTC_DelayMs (uint32_t delay) |
a delay of delay ms by polling RTC More... | |
uint32_t | HAL_GetTick (void) |
HAL_GetTick RTC-based replacement. More... | |
uint32_t | ketCube_RTC_GetTimerContext (void) |
Get the RTC timer Reference. More... | |
uint32_t | ketCube_RTC_GetCalendarTime (uint16_t *mSeconds) |
Get system time. More... | |
uint32_t | ketCube_RTC_GetSysTime (void) |
Get system time. More... | |
void | ketCube_RTC_BKUPWrite (uint32_t Data0, uint32_t Data1) |
void | ketCube_RTC_BKUPRead (uint32_t *Data0, uint32_t *Data1) |
TimerTime_t | RtcTempCompensation (TimerTime_t period, float temperature) |
void | HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef *hrtc) |
Alarm A callback. More... | |
void | ketCube_RTC_AlarmAEventExec (void) |
Alarm A callback. More... | |
void | HAL_RTC_MspInit (RTC_HandleTypeDef *hrtc) |
RTC MSP Initialization This function configures the hardware resources used in this example: More... | |
void | HAL_RTC_MspDeInit (RTC_HandleTypeDef *hrtc) |
RTC MSP De-Initialization This function freeze the hardware resources used in this example: More... | |
HAL_StatusTypeDef | HAL_InitTick (uint32_t TickPriority) |
This function configures the source of the time base. More... | |
void | HAL_Delay (__IO uint32_t delay) |
This function redefines systick-based HAL_Delay. More... | |
Variables | |
static volatile bool | initialized = FALSE |
static bool | McuWakeUpTimeInitialized = false |
compensates MCU wakeup time More... | |
static int16_t | McuWakeUpTimeCal = 0 |
compensates MCU wakeup time More... | |
static const uint8_t | DaysInMonth [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
static const uint8_t | DaysInMonthLeapYear [] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
static RTC_HandleTypeDef | RtcHandle ={0} |
static RTC_AlarmTypeDef | RTC_AlarmStructure |
static RtcTimerContext_t | RtcTimerContext |
static volatile bool | executeAlarmOutOfISR = FALSE |
This file contains implementation of the ketCube RTC driver.
This file contains definitions for the ketCube RTC driver.
Developed by: The SmartCampus Team Department of Technologies and Measurement www.smartcampus.cz | www.zcu.cz
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS 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 WITH THE SOFTWARE.
#define COMMON_FACTOR 3 |
#define CONV_DENOM (1<<(N_PREDIV_S-COMMON_FACTOR)) |
#define CONV_NUMER (MSEC_NUMBER>>COMMON_FACTOR) |
#define DAYS_IN_LEAP_YEAR ( ( uint32_t ) 366U ) |
#define DAYS_IN_MONTH_CORRECTION_LEAP ((uint32_t) 0x445550 ) |
#define DAYS_IN_MONTH_CORRECTION_NORM ((uint32_t) 0x99AAA0 ) |
#define DAYS_IN_YEAR ( ( uint32_t ) 365U ) |
#define DIVC | ( | X, | |
N | |||
) | ( ( (X) + (N) -1 ) / (N) ) |
#define HOURS_IN_1DAY ( ( uint32_t ) 24U ) |
#define MIN_ALARM_DELAY 3 /* in ticks */ |
#define MINUTES_IN_1HOUR ( ( uint32_t ) 60U ) |
#define MSEC_NUMBER (USEC_NUMBER/1000) |
#define N_PREDIV_S 10 |
#define PREDIV_A (1<<(15-N_PREDIV_S))-1 |
#define PREDIV_S ((1<<N_PREDIV_S)-1) |
#define RTC_ALARM_TIME_BASE (USEC_NUMBER>>N_PREDIV_S) |
#define RTC_ALARMSUBSECONDMASK (N_PREDIV_S<<RTC_ALRMASSR_MASKSS_Pos) |
#define SECONDS_IN_1DAY ( ( uint32_t )86400U ) |
#define SECONDS_IN_1HOUR ( ( uint32_t ) 3600U ) |
#define SECONDS_IN_1MINUTE ( ( uint32_t ) 60U ) |
#define USEC_NUMBER 1000000 |
void HAL_Delay | ( | __IO uint32_t | delay | ) |
This function redefines systick-based HAL_Delay.
This function provides delay in ms
Delay | specifies the delay time length, in milliseconds. |
None |
HAL_StatusTypeDef HAL_InitTick | ( | uint32_t | TickPriority | ) |
This function configures the source of the time base.
KETCube uses RTC, so sysTick is not enabled
TickPriority | Tick interrupt priority. |
HAL | status |
void HAL_RTC_AlarmAEventCallback | ( | RTC_HandleTypeDef * | hrtc | ) |
Alarm A callback.
hrtc | RTC handle |
None |
void HAL_RTC_MspDeInit | ( | RTC_HandleTypeDef * | hrtc | ) |
RTC MSP De-Initialization This function freeze the hardware resources used in this example:
hrtc | RTC handle pointer |
None |
void HAL_RTC_MspInit | ( | RTC_HandleTypeDef * | hrtc | ) |
RTC MSP Initialization This function configures the hardware resources used in this example:
hrtc | RTC handle pointer |
None |
|
static |
get current time from calendar in ticks
pointer | to RTC_DateStruct |
pointer | to RTC_TimeStruct |
time | in ticks |
|
static |
configure alarm at init
none |
none |
|
static |
Configures the RTC timer.
none |
none |
|
static |
start wake up alarm
timeoutValue | in ticks |
none |
TimerTime_t RtcTempCompensation | ( | TimerTime_t | period, |
float | temperature | ||
) |
|
static |
Number of days in each month on a normal year
|
static |
Number of days in each month on a leap year
|
static |
|
static |
|
static |
compensates MCU wakeup time
|
static |
compensates MCU wakeup time
|
static |
|
static |
|
static |
Keep the value of the RTC timer when the RTC alarm is set Set with the ketCube_RTC_SetTimerContext function Value is kept as a Reference to calculate alarm