RTC library for Max31341/2 devices

Fork of max3134x by Mahir Ozturk

Embed: (wiki syntax)

« Back to documentation index

RtcBase Class Reference

RTC base driver class for Maxim Max3134x RTC series. More...

#include <RtcBase.h>

Inherited by Max31341, and Max31342.

Public Types

enum  power_mgmt_mode_t { POW_MGMT_MODE_COMPARATOR, POW_MGMT_MODE_POWER_MANAGEMENT }
 

Mode of the comparator.

More...
enum  comp_thresh_t { COMP_THRESH_1V4, COMP_THRESH_1V6, COMP_THRESH_1V8, COMP_THRESH_2V0 }
 

Analog comparator threshold voltage.

More...
enum  power_mgmt_supply_t { POW_MGMT_SUPPLY_SEL_AUTO, POW_MGMT_SUPPLY_SEL_VCC, POW_MGMT_SUPPLY_SEL_AIN }
 

Supply voltage select.

More...
enum  trickle_charger_ohm_t { TRICKLE_CHARGER_3K5, TRICKLE_CHARGER_3K5_2, TRICKLE_CHARGER_7K, TRICKLE_CHARGER_13K }
 

Selection of charging path's resistor value.

More...
enum  timer_freq_t { TIMER_FREQ_1024HZ, TIMER_FREQ_256HZ, TIMER_FREQ_64HZ, TIMER_FREQ_16HZ }
 

Timer frequency selection.

More...
enum  clkin_freq_t { CLKIN_FREQ_1HZ, CLKIN_FREQ_50HZ, CLKIN_FREQ_60HZ, CLKIN_FREQ_32HZ768 }
 

CLKIN frequency selection.

More...
enum  square_wave_out_freq_t { SQUARE_WAVE_OUT_FREQ_1HZ, SQUARE_WAVE_OUT_FREQ_4096HZ, SQUARE_WAVE_OUT_FREQ_8192HZ, SQUARE_WAVE_OUT_FREQ_32768HZ }
 

Square wave output frequency selection on CLKOUT pin.

More...
enum  intr_id_t {
  INTR_ID_ALARM1, INTR_ID_ALARM2, INTR_ID_TIMER , INTR_ID_EXTERNAL,
  INTR_ID_ANALOG, INTR_ID_OSF, INTR_ID_LOS
}
 

Selection of interrupt ids.

More...
enum  alarm_no_t { ALARM1, ALARM2 }
 

Alarm number selection.

More...
enum  alarm_period_t {
  ALARM_PERIOD_EVERYSECOND, ALARM_PERIOD_EVERYMINUTE, ALARM_PERIOD_HOURLY, ALARM_PERIOD_DAILY,
  ALARM_PERIOD_WEEKLY, ALARM_PERIOD_MONTHLY, ALARM_PERIOD_YEARLY, ALARM_PERIOD_ONETIME
}
 

Alarm periodicity selection.

More...
enum  config_inta_clkin_pin_t { CONFIGURE_PIN_AS_INTA, CONFIGURE_PIN_AS_CLKIN }
 

Selection of INTA/CLKIN pin function.

More...
enum  config_intb_clkout_pin_t { CONFIGURE_PIN_AS_CLKOUT, CONFIGURE_PIN_AS_INTB }
 

Selection of INTB/CLKOUT pin function.

More...
enum  sync_delay_t { SYNC_DLY_LESS_THAN_1SEC = 0, SYNC_DLY_LESS_THAN_100MS, SYNC_DLY_LESS_THAN_20MS }
 

Selection of sync delay.

More...
typedef void(* interrupt_handler_function )(void *)
 Function pointer type to interrupt handler function.

Public Member Functions

int read_register (uint8_t reg, uint8_t *value, uint8_t len)
 Read from a register.
int write_register (uint8_t reg, const uint8_t *value, uint8_t len)
 Write to a register.
int get_time (struct tm *rtc_ctime)
 Read time info from RTC.
int set_time (const struct tm *rtc_ctime)
 Set time info to RTC.
int nvram_write (const uint8_t *buffer, int offset, int length)
 Non-volatile memory write.
int nvram_read (uint8_t *buffer, int offset, int length)
 Non-volatile memory read.
int nvram_size ()
 NVRAM size of the part.
int set_alarm (alarm_no_t alarm_no, const struct tm *alarm_time, alarm_period_t period)
 Set an alarm condition.
int get_alarm (alarm_no_t alarm_no, struct tm *alarm_time, alarm_period_t *period, bool *is_enabled)
 Get alarm data & time.
int set_power_mgmt_mode (power_mgmt_mode_t mode)
 Select power management mode of operation.
int comparator_threshold_level (comp_thresh_t th)
 Set comparator threshold.
int supply_select (power_mgmt_supply_t supply)
 Select device power source.
int trickle_charger_enable (trickle_charger_ohm_t res, bool diode)
 Configure trickle charger charging path, also enable it.
int trickle_charger_disable ()
 Disable trickle charger.
int set_output_square_wave_frequency (square_wave_out_freq_t freq)
 Select square wave output frequency selection.
int set_clkin_frequency (clkin_freq_t freq)
 Select external clock input frequency.
int configure_intb_clkout_pin (config_intb_clkout_pin_t sel)
 Select direction of INTB/CLKOUT pin.
int configure_inta_clkin_pin (config_inta_clkin_pin_t sel)
 Select direction of INTA/CLKIN pin.
int timer_init (uint8_t value, bool repeat, timer_freq_t freq)
 Initialize timer.
uint8_t timer_get ()
 Read timer value.
int timer_start ()
 Enable timer.
int timer_pause ()
 Pause timer, timer value is preserved.
int timer_continue ()
 Start timer from the paused value.
int timer_stop ()
 Disable timer.
int data_retention_mode_enter ()
 Put device into data retention mode.
int data_retention_mode_exit ()
 Remove device from data retention mode.
int i2c_timeout_enable ()
 Enable I2C bus timeout mechanism.
int i2c_timeout_disable ()
 Disable I2C bus timeout mechanism.
int irq_enable (intr_id_t id)
 Enable interrupt.
int irq_disable (intr_id_t id)
 Disable interrupt.
int irq_disable_all ()
 Disable all interrupts.
void set_intr_handler (intr_id_t id, interrupt_handler_function func, void *cb)
 Set interrupt handler for a specific interrupt id.
int sw_reset_assert ()
 Put device into reset state.
int sw_reset_release ()
 Release device from state state.
int rtc_start ()
 Enable the RTC oscillator.
int rtc_stop ()
 Disable the RTC oscillator.
 ~RtcBase ()
 Base class destructor.

Protected Member Functions

 RtcBase (const regmap_t *regmap, I2C *i2c, PinName inta_pin, PinName intb_pin)
 Base class constructor.

Detailed Description

RTC base driver class for Maxim Max3134x RTC series.

Definition at line 44 of file RtcBase.h.


Member Typedef Documentation

typedef void(* interrupt_handler_function)(void *)

Function pointer type to interrupt handler function.

Definition at line 190 of file RtcBase.h.


Member Enumeration Documentation

enum alarm_no_t

Alarm number selection.

Enumerator:
ALARM1 

Alarm number 1.

ALARM2 

Alarm number 2.

Definition at line 133 of file RtcBase.h.

Alarm periodicity selection.

Enumerator:
ALARM_PERIOD_EVERYSECOND 

Once per second.

ALARM_PERIOD_EVERYMINUTE 

Second match / Once per minute.

ALARM_PERIOD_HOURLY 

Second and Minute match.

ALARM_PERIOD_DAILY 

Hour, Minute and Second match.

ALARM_PERIOD_WEEKLY 

Day and Time match.

ALARM_PERIOD_MONTHLY 

Date and Time match.

ALARM_PERIOD_YEARLY 

Month, Date and Time match (Max31342 only)

ALARM_PERIOD_ONETIME 

Year, Month, Date and Time match (Max31342 only)

Definition at line 141 of file RtcBase.h.

CLKIN frequency selection.

Enumerator:
CLKIN_FREQ_1HZ 

1Hz

CLKIN_FREQ_50HZ 

50Hz

CLKIN_FREQ_60HZ 

60Hz

CLKIN_FREQ_32HZ768 

32.768Hz

Definition at line 97 of file RtcBase.h.

Analog comparator threshold voltage.

Enumerator:
COMP_THRESH_1V4 

1.4V

COMP_THRESH_1V6 

1.6V

COMP_THRESH_1V8 

1.8V

COMP_THRESH_2V0 

2.0V

Definition at line 58 of file RtcBase.h.

Selection of INTA/CLKIN pin function.

Enumerator:
CONFIGURE_PIN_AS_INTA 

Configure pin as interrupt out.

CONFIGURE_PIN_AS_CLKIN 

Configure pin as external clock in.

Definition at line 155 of file RtcBase.h.

Selection of INTB/CLKOUT pin function.

Enumerator:
CONFIGURE_PIN_AS_CLKOUT 

Output is square wave.

CONFIGURE_PIN_AS_INTB 

Output is interrupt.

Definition at line 163 of file RtcBase.h.

enum intr_id_t

Selection of interrupt ids.

Enumerator:
INTR_ID_ALARM1 

Alarm1 flag.

INTR_ID_ALARM2 

Alarm2 flag.

INTR_ID_TIMER 

Timer interrupt flag.

INTR_ID_EXTERNAL 

External interrupt flag for DIN1.

INTR_ID_ANALOG 

Analog Interrupt flag / Power fail flag.

INTR_ID_OSF 

Oscillator stop flag.

INTR_ID_LOS 

Loss of signal.

Definition at line 117 of file RtcBase.h.

Mode of the comparator.

Enumerator:
POW_MGMT_MODE_COMPARATOR 

Comparator.

POW_MGMT_MODE_POWER_MANAGEMENT 

Power Management / Trickle Charger Mode.

Definition at line 50 of file RtcBase.h.

Supply voltage select.

Enumerator:
POW_MGMT_SUPPLY_SEL_AUTO 

Circuit decides whether to use VCC or VBACKUP.

POW_MGMT_SUPPLY_SEL_VCC 

Use VCC as supply.

POW_MGMT_SUPPLY_SEL_AIN 

Use AIN as supply.

Definition at line 68 of file RtcBase.h.

Square wave output frequency selection on CLKOUT pin.

Enumerator:
SQUARE_WAVE_OUT_FREQ_1HZ 

1Hz

SQUARE_WAVE_OUT_FREQ_4096HZ 

4.098kHz

SQUARE_WAVE_OUT_FREQ_8192HZ 

8.192kHz

SQUARE_WAVE_OUT_FREQ_32768HZ 

32.768kHz

Definition at line 107 of file RtcBase.h.

Selection of sync delay.

Enumerator:
SYNC_DLY_LESS_THAN_1SEC 

Sync delay less than 1 second, recommended for external 1Hz clock.

SYNC_DLY_LESS_THAN_100MS 

Sync delay less than 100 msec, recommended for external 50Hz/60Hz/32KHz clock.

SYNC_DLY_LESS_THAN_20MS 

Sync delay less than 20 msec, recommended for internal clock.

Definition at line 171 of file RtcBase.h.

Timer frequency selection.

Enumerator:
TIMER_FREQ_1024HZ 

1024Hz

TIMER_FREQ_256HZ 

256Hz

TIMER_FREQ_64HZ 

64Hz

TIMER_FREQ_16HZ 

16Hz

Definition at line 87 of file RtcBase.h.

Selection of charging path's resistor value.

Enumerator:
TRICKLE_CHARGER_3K5 

3500 Ohm

TRICKLE_CHARGER_3K5_2 

3500 Ohm

TRICKLE_CHARGER_7K 

7000 Ohm

TRICKLE_CHARGER_13K 

13000 Ohm

Definition at line 77 of file RtcBase.h.


Constructor & Destructor Documentation

~RtcBase (  )

Base class destructor.

Definition at line 85 of file RtcBase.cpp.

RtcBase ( const regmap_t *  regmap,
I2C *  i2c,
PinName  inta_pin = NC,
PinName  intb_pin = NC 
) [protected]

Base class constructor.

Parameters:
[in]regmapPointer to device register mappings.
[in]i2cPointer to I2C bus object for this device.
[in]inta_pinMCU's pin number that device's INTA pin connected
[in]intb_pinMCU's pin number that device's INTB pin connected

Definition at line 44 of file RtcBase.cpp.


Member Function Documentation

int comparator_threshold_level ( comp_thresh_t  th )

Set comparator threshold.

Parameters:
[in]thSet Analog Comparator Threshold level, one of COMP_THRESH_*
Returns:
0 on success, error code on failure

Definition at line 572 of file RtcBase.cpp.

int configure_inta_clkin_pin ( config_inta_clkin_pin_t  sel )

Select direction of INTA/CLKIN pin.

Parameters:
[in]selPin function, one of CONFIGURE_PIN_B3_AS_INTA or CONFIGURE_PIN_B3_AS_CLKIN
Returns:
0 on success, error code on failure

Definition at line 771 of file RtcBase.cpp.

int configure_intb_clkout_pin ( config_intb_clkout_pin_t  sel )

Select direction of INTB/CLKOUT pin.

Parameters:
[in]selPin function, one of CONFIGURE_PIN_B3_AS_INTB or CONFIGURE_PIN_B3_AS_CLKOUT
Returns:
0 on success, error code on failure

Definition at line 751 of file RtcBase.cpp.

int data_retention_mode_enter (  )

Put device into data retention mode.

Returns:
0 on success, error code on failure

Definition at line 961 of file RtcBase.cpp.

int data_retention_mode_exit (  )

Remove device from data retention mode.

Returns:
0 on success, error code on failure

Definition at line 966 of file RtcBase.cpp.

int get_alarm ( alarm_no_t  alarm_no,
struct tm *  alarm_time,
alarm_period_t period,
bool *  is_enabled 
)

Get alarm data & time.

Parameters:
[in]alarm_noAlarm number, ALARM1 or ALARM2
[out]alarm_timePointer to alarm time to be filled in
[out]periodPointer to the period of alarm, one of ALARM_PERIOD_*
[out]is_enabledPointer to the state of alarm
Returns:
0 on success, error code on failure

Definition at line 506 of file RtcBase.cpp.

int get_time ( struct tm *  rtc_ctime )

Read time info from RTC.

Parameters:
[out]rtc_timeTime info from RTC.
Returns:
0 on success, negative error code on failure.

Definition at line 230 of file RtcBase.cpp.

int i2c_timeout_disable (  )

Disable I2C bus timeout mechanism.

Returns:
0 on success, error code on failure

Definition at line 996 of file RtcBase.cpp.

int i2c_timeout_enable (  )

Enable I2C bus timeout mechanism.

Returns:
0 on success, error code on failure

Definition at line 991 of file RtcBase.cpp.

int irq_disable ( intr_id_t  id )

Disable interrupt.

Parameters:
[in]idInterrupt id, one of INTR_ID_*
Returns:
0 on success, error code on failure

Definition at line 1021 of file RtcBase.cpp.

int irq_disable_all (  )

Disable all interrupts.

Returns:
0 on success, error code on failure

Definition at line 1041 of file RtcBase.cpp.

int irq_enable ( intr_id_t  id )

Enable interrupt.

Parameters:
[in]idInterrupt id, one of INTR_ID_*
Returns:
0 on success, error code on failure

Definition at line 1001 of file RtcBase.cpp.

int nvram_read ( uint8_t *  buffer,
int  offset,
int  length 
)

Non-volatile memory read.

Parameters:
[in]bufferBuffer to read in to
[in]offsetOffset of location in NVRAM
[in]lengthNumber of bytes to read
Returns:
0 on success, error code on failure

Definition at line 323 of file RtcBase.cpp.

int nvram_size (  )

NVRAM size of the part.

Returns:
0 if part does not have a NVRAM, otherwise returns size

Definition at line 349 of file RtcBase.cpp.

int nvram_write ( const uint8_t *  buffer,
int  offset,
int  length 
)

Non-volatile memory write.

Parameters:
[out]bufferPointer to the data to be written
[in]offsetOffset of location in NVRAM
[in]lengthNumber of bytes to write
Returns:
0 on success, error code on failure

Definition at line 297 of file RtcBase.cpp.

int read_register ( uint8_t  reg,
uint8_t *  value,
uint8_t  len 
)

Read from a register.

Parameters:
[in]regAddress of a register to be read.
[out]valuePointer to save result value.
[in]lenSize of result to be read.
Returns:
0 on success, negative error code on failure.

Definition at line 100 of file RtcBase.cpp.

int rtc_start (  )

Enable the RTC oscillator.

Returns:
0 on success, error code on failure

Definition at line 1139 of file RtcBase.cpp.

int rtc_stop (  )

Disable the RTC oscillator.

Returns:
0 on success, error code on failure

Definition at line 1161 of file RtcBase.cpp.

int set_alarm ( alarm_no_t  alarm_no,
const struct tm *  alarm_time,
alarm_period_t  period 
)

Set an alarm condition.

Parameters:
[in]alarm_noAlarm number, ALARM1 or ALARM2
[in]alarm_timePointer to alarm time to be set
[in]periodAlarm periodicity, one of ALARM_PERIOD_*
Returns:
0 on success, error code on failure

Definition at line 482 of file RtcBase.cpp.

int set_clkin_frequency ( clkin_freq_t  freq )

Select external clock input frequency.

Parameters:
[in]freqClock frequency, one of CLKIN_FREQ_*
Returns:
0 on success, error code on failure

Definition at line 725 of file RtcBase.cpp.

void set_intr_handler ( intr_id_t  id,
interrupt_handler_function  func,
void *  cb 
)

Set interrupt handler for a specific interrupt id.

Parameters:
[in]idInterrupt id, one of INTR_ID_*
[in]funcInterrupt handler function
[in]cbInterrupt handler data

Definition at line 1054 of file RtcBase.cpp.

int set_output_square_wave_frequency ( square_wave_out_freq_t  freq )

Select square wave output frequency selection.

Parameters:
[in]freqClock frequency, one of CLKOUT_FREQ_*
Returns:
0 on success, error code on failure

Definition at line 685 of file RtcBase.cpp.

int set_power_mgmt_mode ( power_mgmt_mode_t  mode )

Select power management mode of operation.

Parameters:
[in]modeMode selection, one of COMP_MODE_*
Returns:
0 on success, error code on failure

Definition at line 547 of file RtcBase.cpp.

int set_time ( const struct tm *  rtc_ctime )

Set time info to RTC.

Parameters:
[in]rtc_timeTime info to be written to RTC.
Returns:
0 on success, negative error code on failure.

Definition at line 277 of file RtcBase.cpp.

int supply_select ( power_mgmt_supply_t  supply )

Select device power source.

Parameters:
[in]supplySupply selection, one of POW_MGMT_SUPPLY_SEL_*
Returns:
0 on success, error code on failure

Definition at line 597 of file RtcBase.cpp.

int sw_reset_assert (  )

Put device into reset state.

Returns:
0 on success, error code on failure

Definition at line 1095 of file RtcBase.cpp.

int sw_reset_release (  )

Release device from state state.

Returns:
0 on success, error code on failure

Definition at line 1117 of file RtcBase.cpp.

int timer_continue (  )

Start timer from the paused value.

Returns:
0 on success, error code on failure

Definition at line 882 of file RtcBase.cpp.

uint8_t timer_get (  )

Read timer value.

Returns:
0 on success, error code on failure

Definition at line 827 of file RtcBase.cpp.

int timer_init ( uint8_t  value,
bool  repeat,
timer_freq_t  freq 
)

Initialize timer.

Parameters:
[in]valueTimer initial value
[in]repeatTimer repeat mode enable/disable
[in]freqTimer frequency, one of TIMER_FREQ_*
[in]modeTimer mode, 0 or 1
Returns:
0 on success, error code on failure
Note:
mode controls the countdown timer interrupt function along with repeat. Pulse interrupt when mode = 0, irrespective of repeat (true or false) Pulse interrupt when mode = 1 and repeat = true Level interrupt when mode = 1 and repeat = false

Definition at line 799 of file RtcBase.cpp.

int timer_pause (  )

Pause timer, timer value is preserved.

Returns:
0 on success, error code on failure

Definition at line 861 of file RtcBase.cpp.

int timer_start (  )

Enable timer.

Returns:
0 on success, error code on failure

Definition at line 840 of file RtcBase.cpp.

int timer_stop (  )

Disable timer.

Returns:
0 on success, error code on failure

Definition at line 903 of file RtcBase.cpp.

int trickle_charger_disable (  )

Disable trickle charger.

Returns:
0 on success, error code on failure

Definition at line 664 of file RtcBase.cpp.

int trickle_charger_enable ( trickle_charger_ohm_t  res,
bool  diode 
)

Configure trickle charger charging path, also enable it.

Parameters:
[in]resValue of resister
[in]diodeEnable diode
Returns:
0 on success, error code on failure

Definition at line 635 of file RtcBase.cpp.

int write_register ( uint8_t  reg,
const uint8_t *  value,
uint8_t  len 
)

Write to a register.

Parameters:
[in]regAddress of a register to be written.
[out]valuePointer of value to be written to register.
[in]lenSize of result to be written.
Returns:
0 on success, negative error code on failure.

Definition at line 124 of file RtcBase.cpp.