foxBMS - Unit Tests  1.5.1
The foxBMS Unit Tests API Documentation
rtc.h File Reference

Header file of the RTC driver. More...

#include "fstd_types.h"
#include <stdint.h>
Include dependency graph for rtc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RTC_TIME_DATA_s
 

Macros

#define RTC_I2C_INTERFACE   (i2cREG1)
 
#define RTC_I2C_ADDRESS   (0x53u)
 
#define RTC_CTRL3_PWRMNG_DIRECTSWITCH_LOWDETECTIONENABLE_MODE   (0b011u)
 
#define RTC_OTPR_BIT_WAIT_TIMEOUT_ms   (150u)
 
#define RTC_SECONDS_OSF_BIT_MASK   (0x80u)
 
#define RTC_SECONDS_OSF_BIT_POSITION   (7u)
 
#define RTC_NUMBER_OF_TIMEDATA_BYTES   (8u)
 
#define RTC_START_YEAR   (2000)
 
#define RTC_MAX_DIFFERENCE_BETWEEN_TIMER_AND_IC_s   (1)
 
#define RTC_FACTOR_MIN_TO_MS   (60000u)
 
#define RTC_TIME_BETWEEN_RTC_TIMER_ADJUSTMENT_min   (60u)
 
#define RTC_TIME_BETWEEN_BLF_FLAG_CHECK_min   (10u)
 
#define RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES   (10u)
 
#define RTC_WRITE_REGISTER_I2C_TRANSACTION_SIZE_IN_BYTES   (2u)
 
#define RTC_REG_CONTROL_1_ADDR   (0x0u)
 
#define RTC_CTRL1_STOP_BIT_MASK   (0x20u)
 
#define RTC_CTRL1_12_24HOUR_MODE_BIT_MASK   (0x04u)
 
#define RTC_REG_CONTROL_3_ADDR   (0x02u)
 
#define RTC_CTRL3_BATTERY_PWRMNG_BITS_MASK   (0xE0u)
 
#define RTC_CTRL3_BATTERY_PWRMNG_BITS_POSITION   (5u)
 
#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_MASK   (0x04u)
 
#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_POSITION   (2u)
 
#define RTC_REG_CLKOUT_CTL_ADDR   (0x13u)
 
#define RTC_CLKOUT_CTL_OTPR_BIT_MASK   (0x20u)
 
#define RTC_CLKOUT_CTL_OTPR_BIT_POSITION   (5u)
 
#define RTC_REG_SOFTWARE_RESET_ADDR   (0x5u)
 
#define RTC_SWRESET_CLEARPRESCALER   (0xA4u)
 
#define RTC_REG_TIME_START_ADDR   (0x06u)
 
#define RTC_100TH_OF_SECONDS_OFFSET   (0x0u)
 
#define RTC_SECONDS_OFFSET   (0x1u)
 
#define RTC_MINUTES_OFFSET   (0x2u)
 
#define RTC_HOURS_OFFSET   (0x3u)
 
#define RTC_DAYS_OFFSET   (0x4u)
 
#define RTC_WEEKDAYS_OFFSET   (0x5u)
 
#define RTC_MONTHS_OFFSET   (0x6u)
 
#define RTC_YEARS_OFFSET   (0x7u)
 
#define RTC_TENS_PLACE_FACTOR   (10u)
 
#define RTC_TENS_PLACE_OFFSET   (4u)
 
#define RTC_HUNDREDTH_OF_SECONDS_TENS_PLACE_MASK   (0xF0u)
 
#define RTC_SECONDS_TENS_PLACE_MASK   (0x70u)
 
#define RTC_MINUTES_TENS_PLACE_MASK   (0x70u)
 
#define RTC_HOURS_TENS_PLACE_MASK   (0x30u)
 
#define RTC_DAYS_TENS_PLACE_MASK   (0x30u)
 
#define RTC_MONTHS_TENS_PLACE_MASK   (0x10u)
 
#define RTC_YEARS_TENS_PLACE_MASK   (0xF0u)
 
#define RTC_UNITS_PLACE_MASK   (0x0Fu)
 
#define RTC_WEEKDAYS_UNITS_PLACE_MASK   (0x07u)
 
#define RTC_CTIME_YEAR_START   (1900)
 
#define RTC_CTIME_MONTH_START   (1)
 

Enumerations

enum  RTC_INIT_STATES_e {
  RTC_SET_SYSTEM_TIMER , RTC_SET_BLF , RTC_CLEAR_OTPR , RTC_WAIT_CLEAR_OTPR ,
  RTC_OTPR_CLEARED , RTC_SET_OTPR , RTC_WAIT_SET_OTPR , RTC_INIT_SET_FINISHED
}
 

Functions

RTC_TIME_DATA_s RTC_GetSystemTimeRtcFormat (void)
 get the RTC system timer. More...
 
void RTC_IncrementSystemTime (void)
 increment the RTC system timer. More...
 
STD_RETURN_TYPE_e RTC_Initialize (void)
 initialization of the RTC IC. More...
 
void RTC_InitializeSystemTimeWithRtc (void)
 initialize system time with RTC time. More...
 
void RTC_SetSystemTimeRtcFormat (RTC_TIME_DATA_s timeRtcFormat)
 set the RTC system timer. More...
 
void RTC_Trigger (void)
 trigger function for the RTC driver. More...
 

Detailed Description

Header file of the RTC driver.

SPDX-License-Identifier: BSD-3-Clause

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2021-02-22 (date of creation)
Updated
2023-02-23 (date of last update)
Version
v1.5.1
Prefix
RTC

Uses the NXP PCF2131 RTC over I2C

Definition in file rtc.h.

Macro Definition Documentation

◆ RTC_100TH_OF_SECONDS_OFFSET

#define RTC_100TH_OF_SECONDS_OFFSET   (0x0u)

Definition at line 134 of file rtc.h.

◆ RTC_CLKOUT_CTL_OTPR_BIT_MASK

#define RTC_CLKOUT_CTL_OTPR_BIT_MASK   (0x20u)

Definition at line 113 of file rtc.h.

◆ RTC_CLKOUT_CTL_OTPR_BIT_POSITION

#define RTC_CLKOUT_CTL_OTPR_BIT_POSITION   (5u)

Definition at line 114 of file rtc.h.

◆ RTC_CTIME_MONTH_START

#define RTC_CTIME_MONTH_START   (1)

Definition at line 172 of file rtc.h.

◆ RTC_CTIME_YEAR_START

#define RTC_CTIME_YEAR_START   (1900)

Definition at line 171 of file rtc.h.

◆ RTC_CTRL1_12_24HOUR_MODE_BIT_MASK

#define RTC_CTRL1_12_24HOUR_MODE_BIT_MASK   (0x04u)

Definition at line 94 of file rtc.h.

◆ RTC_CTRL1_STOP_BIT_MASK

#define RTC_CTRL1_STOP_BIT_MASK   (0x20u)

Definition at line 93 of file rtc.h.

◆ RTC_CTRL3_BATTERY_LOW_FLAG_BIT_MASK

#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_MASK   (0x04u)

Definition at line 102 of file rtc.h.

◆ RTC_CTRL3_BATTERY_LOW_FLAG_BIT_POSITION

#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_POSITION   (2u)

Definition at line 103 of file rtc.h.

◆ RTC_CTRL3_BATTERY_PWRMNG_BITS_MASK

#define RTC_CTRL3_BATTERY_PWRMNG_BITS_MASK   (0xE0u)

Definition at line 100 of file rtc.h.

◆ RTC_CTRL3_BATTERY_PWRMNG_BITS_POSITION

#define RTC_CTRL3_BATTERY_PWRMNG_BITS_POSITION   (5u)

Definition at line 101 of file rtc.h.

◆ RTC_CTRL3_PWRMNG_DIRECTSWITCH_LOWDETECTIONENABLE_MODE

#define RTC_CTRL3_PWRMNG_DIRECTSWITCH_LOWDETECTIONENABLE_MODE   (0b011u)

Definition at line 108 of file rtc.h.

◆ RTC_DAYS_OFFSET

#define RTC_DAYS_OFFSET   (0x4u)

Definition at line 138 of file rtc.h.

◆ RTC_DAYS_TENS_PLACE_MASK

#define RTC_DAYS_TENS_PLACE_MASK   (0x30u)

Definition at line 155 of file rtc.h.

◆ RTC_FACTOR_MIN_TO_MS

#define RTC_FACTOR_MIN_TO_MS   (60000u)

Definition at line 178 of file rtc.h.

◆ RTC_HOURS_OFFSET

#define RTC_HOURS_OFFSET   (0x3u)

Definition at line 137 of file rtc.h.

◆ RTC_HOURS_TENS_PLACE_MASK

#define RTC_HOURS_TENS_PLACE_MASK   (0x30u)

Definition at line 154 of file rtc.h.

◆ RTC_HUNDREDTH_OF_SECONDS_TENS_PLACE_MASK

#define RTC_HUNDREDTH_OF_SECONDS_TENS_PLACE_MASK   (0xF0u)

Definition at line 151 of file rtc.h.

◆ RTC_I2C_ADDRESS

#define RTC_I2C_ADDRESS   (0x53u)

Definition at line 70 of file rtc.h.

◆ RTC_I2C_INTERFACE

#define RTC_I2C_INTERFACE   (i2cREG1)

RTC I2C interface

Definition at line 68 of file rtc.h.

◆ RTC_MAX_DIFFERENCE_BETWEEN_TIMER_AND_IC_s

#define RTC_MAX_DIFFERENCE_BETWEEN_TIMER_AND_IC_s   (1)

Definition at line 176 of file rtc.h.

◆ RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES

#define RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES   (10u)

Definition at line 86 of file rtc.h.

◆ RTC_MINUTES_OFFSET

#define RTC_MINUTES_OFFSET   (0x2u)

Definition at line 136 of file rtc.h.

◆ RTC_MINUTES_TENS_PLACE_MASK

#define RTC_MINUTES_TENS_PLACE_MASK   (0x70u)

Definition at line 153 of file rtc.h.

◆ RTC_MONTHS_OFFSET

#define RTC_MONTHS_OFFSET   (0x6u)

Definition at line 140 of file rtc.h.

◆ RTC_MONTHS_TENS_PLACE_MASK

#define RTC_MONTHS_TENS_PLACE_MASK   (0x10u)

Definition at line 156 of file rtc.h.

◆ RTC_NUMBER_OF_TIMEDATA_BYTES

#define RTC_NUMBER_OF_TIMEDATA_BYTES   (8u)

Definition at line 145 of file rtc.h.

◆ RTC_OTPR_BIT_WAIT_TIMEOUT_ms

#define RTC_OTPR_BIT_WAIT_TIMEOUT_ms   (150u)

Definition at line 118 of file rtc.h.

◆ RTC_REG_CLKOUT_CTL_ADDR

#define RTC_REG_CLKOUT_CTL_ADDR   (0x13u)

Definition at line 112 of file rtc.h.

◆ RTC_REG_CONTROL_1_ADDR

#define RTC_REG_CONTROL_1_ADDR   (0x0u)

Definition at line 92 of file rtc.h.

◆ RTC_REG_CONTROL_3_ADDR

#define RTC_REG_CONTROL_3_ADDR   (0x02u)

Definition at line 99 of file rtc.h.

◆ RTC_REG_SOFTWARE_RESET_ADDR

#define RTC_REG_SOFTWARE_RESET_ADDR   (0x5u)

Definition at line 127 of file rtc.h.

◆ RTC_REG_TIME_START_ADDR

#define RTC_REG_TIME_START_ADDR   (0x06u)

Definition at line 133 of file rtc.h.

◆ RTC_SECONDS_OFFSET

#define RTC_SECONDS_OFFSET   (0x1u)

Definition at line 135 of file rtc.h.

◆ RTC_SECONDS_OSF_BIT_MASK

#define RTC_SECONDS_OSF_BIT_MASK   (0x80u)

Definition at line 121 of file rtc.h.

◆ RTC_SECONDS_OSF_BIT_POSITION

#define RTC_SECONDS_OSF_BIT_POSITION   (7u)

Definition at line 123 of file rtc.h.

◆ RTC_SECONDS_TENS_PLACE_MASK

#define RTC_SECONDS_TENS_PLACE_MASK   (0x70u)

Definition at line 152 of file rtc.h.

◆ RTC_START_YEAR

#define RTC_START_YEAR   (2000)

Definition at line 167 of file rtc.h.

◆ RTC_SWRESET_CLEARPRESCALER

#define RTC_SWRESET_CLEARPRESCALER   (0xA4u)

Definition at line 128 of file rtc.h.

◆ RTC_TENS_PLACE_FACTOR

#define RTC_TENS_PLACE_FACTOR   (10u)

Definition at line 149 of file rtc.h.

◆ RTC_TENS_PLACE_OFFSET

#define RTC_TENS_PLACE_OFFSET   (4u)

Definition at line 150 of file rtc.h.

◆ RTC_TIME_BETWEEN_BLF_FLAG_CHECK_min

#define RTC_TIME_BETWEEN_BLF_FLAG_CHECK_min   (10u)

Definition at line 182 of file rtc.h.

◆ RTC_TIME_BETWEEN_RTC_TIMER_ADJUSTMENT_min

#define RTC_TIME_BETWEEN_RTC_TIMER_ADJUSTMENT_min   (60u)

Definition at line 180 of file rtc.h.

◆ RTC_UNITS_PLACE_MASK

#define RTC_UNITS_PLACE_MASK   (0x0Fu)

Definition at line 162 of file rtc.h.

◆ RTC_WEEKDAYS_OFFSET

#define RTC_WEEKDAYS_OFFSET   (0x5u)

Definition at line 139 of file rtc.h.

◆ RTC_WEEKDAYS_UNITS_PLACE_MASK

#define RTC_WEEKDAYS_UNITS_PLACE_MASK   (0x07u)

Definition at line 163 of file rtc.h.

◆ RTC_WRITE_REGISTER_I2C_TRANSACTION_SIZE_IN_BYTES

#define RTC_WRITE_REGISTER_I2C_TRANSACTION_SIZE_IN_BYTES   (2u)

Definition at line 87 of file rtc.h.

◆ RTC_YEARS_OFFSET

#define RTC_YEARS_OFFSET   (0x7u)

Definition at line 141 of file rtc.h.

◆ RTC_YEARS_TENS_PLACE_MASK

#define RTC_YEARS_TENS_PLACE_MASK   (0xF0u)

Definition at line 157 of file rtc.h.

Enumeration Type Documentation

◆ RTC_INIT_STATES_e

States for the OTPR procedure

Enumerator
RTC_SET_SYSTEM_TIMER 
RTC_SET_BLF 
RTC_CLEAR_OTPR 
RTC_WAIT_CLEAR_OTPR 
RTC_OTPR_CLEARED 
RTC_SET_OTPR 
RTC_WAIT_SET_OTPR 
RTC_INIT_SET_FINISHED 

Definition at line 185 of file rtc.h.

Function Documentation

◆ RTC_GetSystemTimeRtcFormat()

RTC_TIME_DATA_s RTC_GetSystemTimeRtcFormat ( void  )

get the RTC system timer.

This function is used to get the RTC system timer value.

Returns
value of the RTC system timer

Definition at line 607 of file rtc.c.

Here is the call graph for this function:

◆ RTC_IncrementSystemTime()

void RTC_IncrementSystemTime ( void  )

increment the RTC system timer.

This function must be called every millisecond and so must be called in the 1ms task.

Definition at line 586 of file rtc.c.

◆ RTC_Initialize()

STD_RETURN_TYPE_e RTC_Initialize ( void  )

initialization of the RTC IC.

Returns
STD_OK if initialization is finished, STD_NOT_OK otherwise

Definition at line 441 of file rtc.c.

Here is the call graph for this function:

◆ RTC_InitializeSystemTimeWithRtc()

void RTC_InitializeSystemTimeWithRtc ( void  )

initialize system time with RTC time.

This function is called once at the startup of the system. It reads the time from the RTC IC over I2C and sets the RTC system timer with this value. It must be called once the 1ms task is already running, otherwise the RTC system timer will not be incremented and there will be a discrepancy between the RTC IC time and the RTC system timer.

Definition at line 577 of file rtc.c.

Here is the call graph for this function:

◆ RTC_SetSystemTimeRtcFormat()

void RTC_SetSystemTimeRtcFormat ( RTC_TIME_DATA_s  timeRtcFormat)

set the RTC system timer.

This function is used to set the RTC system timer with RTC time data. It is called at startup by RTC_InitializeSystemTimeWithRtc().

Parameters
timeRtcFormattime data to set the RTC system timer

Definition at line 595 of file rtc.c.

Here is the call graph for this function:

◆ RTC_Trigger()

void RTC_Trigger ( void  )

trigger function for the RTC driver.

This function uses RTC_SetOverCanMessage() to check in the RTC queue for requests to set the RTC time. If a request was made, the time of the RTC IC is set over I2C and the RTC system timer is set.

Definition at line 414 of file rtc.c.

Here is the call graph for this function: