Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
maxim_ds3231.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Peter Bigot Consulting, LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
32#ifndef ZEPHYR_INCLUDE_DRIVERS_RTC_DS3231_H_
33#define ZEPHYR_INCLUDE_DRIVERS_RTC_DS3231_H_
34
35#include <time.h>
36
38#include <zephyr/kernel.h>
39#include <zephyr/types.h>
40#include <zephyr/sys/notify.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
47#define MAXIM_DS3231_ALARM1 BIT(0)
48
50#define MAXIM_DS3231_ALARM2 BIT(1)
51
52/* Constants corresponding to bits in the DS3231 control register at
53 * 0x0E.
54 *
55 * See the datasheet for interpretation of these bits.
56 */
58#define MAXIM_DS3231_REG_CTRL_A1IE MAXIM_DS3231_ALARM1
59
61#define MAXIM_DS3231_REG_CTRL_A2IE MAXIM_DS3231_ALARM2
62
70#define MAXIM_DS3231_REG_CTRL_INTCN BIT(2)
71
76#define MAXIM_DS3231_REG_CTRL_RS_Pos 3
77
79#define MAXIM_DS3231_REG_CTRL_RS_Msk (0x03 << MAXIM_DS3231_REG_CTRL_RS_Pos)
80
82#define MAXIM_DS3231_REG_CTRL_RS_1Hz 0x00
83
85#define MAXIM_DS3231_REG_CTRL_RS_1KiHz 0x01
86
88#define MAXIM_DS3231_REG_CTRL_RS_4KiHz 0x02
89
91#define MAXIM_DS3231_REG_CTRL_RS_8KiHz 0x03
92
94#define MAXIM_DS3231_REG_CTRL_CONV BIT(5)
95
97#define MAXIM_DS3231_REG_CTRL_BBSQW BIT(6)
98
100#define MAXIM_DS3231_REG_CTRL_EOSCn BIT(7),
101
108#define MAXIM_DS3231_REG_STAT_A1F MAXIM_DS3231_ALARM1
109
116#define MAXIM_DS3231_REG_STAT_A2F MAXIM_DS3231_ALARM2
117
119#define MAXIM_DS3231_REG_STAT_BSY BIT(2)
120
126#define MAXIM_DS3231_REG_STAT_EN32kHz BIT(3)
127
129#define MAXIM_DS3231_REG_STAT_OSF BIT(7)
130
145#define MAXIM_DS3231_ALARM_FLAGS_IGNSE BIT(0)
146
159#define MAXIM_DS3231_ALARM_FLAGS_IGNMN BIT(1)
160
172#define MAXIM_DS3231_ALARM_FLAGS_IGNHR BIT(2)
173
186#define MAXIM_DS3231_ALARM_FLAGS_IGNDA BIT(3)
187
196#define MAXIM_DS3231_ALARM_FLAGS_DOW BIT(4)
197
207#define MAXIM_DS3231_ALARM_FLAGS_AUTODISABLE BIT(7)
208
230typedef void (*maxim_ds3231_alarm_callback_handler_t)(const struct device *dev,
231 uint8_t id,
232 uint32_t syncclock,
233 void *user_data);
234
247typedef void (*maxim_ds3231_notify_callback)(const struct device *dev,
248 struct sys_notify *notify,
249 int res);
250
313
336
360static inline uint32_t maxim_ds3231_read_syncclock(const struct device *dev)
361{
362 return k_uptime_get_32();
363}
364
373static inline uint32_t maxim_ds3231_syncclock_frequency(const struct device *dev)
374{
375 return 1000U;
376}
377
395int maxim_ds3231_ctrl_update(const struct device *dev,
396 uint8_t set_bits,
397 uint8_t clear_bits);
398
428int maxim_ds3231_stat_update(const struct device *dev,
429 uint8_t set_bits,
430 uint8_t clear_bits);
431
450int maxim_ds3231_get_alarm(const struct device *dev,
451 uint8_t id,
452 struct maxim_ds3231_alarm *cfg);
453
474int maxim_ds3231_set_alarm(const struct device *dev,
475 uint8_t id,
476 const struct maxim_ds3231_alarm *cfg);
477
504int maxim_ds3231_synchronize(const struct device *dev,
505 struct sys_notify *notify);
506
522__syscall int maxim_ds3231_req_syncpoint(const struct device *dev,
523 struct k_poll_signal *signal);
524
537__syscall int maxim_ds3231_get_syncpoint(const struct device *dev,
538 struct maxim_ds3231_syncpoint *syncpoint);
539
567int maxim_ds3231_set(const struct device *dev,
568 const struct maxim_ds3231_syncpoint *syncpoint,
569 struct sys_notify *notify);
570
588int maxim_ds3231_check_alarms(const struct device *dev);
589
594#ifdef __cplusplus
595}
596#endif
597
598/* @todo this should be syscalls/drivers/rtc/maxim_ds3231.h */
599#include <zephyr/syscalls/maxim_ds3231.h>
600
601#endif /* ZEPHYR_INCLUDE_DRIVERS_RTC_DS3231_H_ */
_TIME_T_ time_t
Definition _timespec.h:14
Public API for counter and timer drivers.
static uint32_t k_uptime_get_32(void)
Get system uptime (32-bit version).
Definition kernel.h:1852
int maxim_ds3231_stat_update(const struct device *dev, uint8_t set_bits, uint8_t clear_bits)
Read the ctrl_stat register then set and clear bits in it.
int maxim_ds3231_ctrl_update(const struct device *dev, uint8_t set_bits, uint8_t clear_bits)
Set and clear specific bits in the control register.
int maxim_ds3231_req_syncpoint(const struct device *dev, struct k_poll_signal *signal)
Request to update the synchronization point.
int maxim_ds3231_set(const struct device *dev, const struct maxim_ds3231_syncpoint *syncpoint, struct sys_notify *notify)
Set the RTC to a time consistent with the provided synchronization.
int maxim_ds3231_get_syncpoint(const struct device *dev, struct maxim_ds3231_syncpoint *syncpoint)
Retrieve the most recent synchronization point.
void(* maxim_ds3231_notify_callback)(const struct device *dev, struct sys_notify *notify, int res)
Signature used to notify a user of the DS3231 that an asynchronous operation has completed.
Definition maxim_ds3231.h:247
void(* maxim_ds3231_alarm_callback_handler_t)(const struct device *dev, uint8_t id, uint32_t syncclock, void *user_data)
Signature for DS3231 alarm callbacks.
Definition maxim_ds3231.h:230
static uint32_t maxim_ds3231_read_syncclock(const struct device *dev)
Read the local synchronization clock.
Definition maxim_ds3231.h:360
static uint32_t maxim_ds3231_syncclock_frequency(const struct device *dev)
Get the frequency of the synchronization clock.
Definition maxim_ds3231.h:373
int maxim_ds3231_set_alarm(const struct device *dev, uint8_t id, const struct maxim_ds3231_alarm *cfg)
Configure a DS3231 alarm.
int maxim_ds3231_check_alarms(const struct device *dev)
Check for and clear flags indicating that an alarm has fired.
int maxim_ds3231_get_alarm(const struct device *dev, uint8_t id, struct maxim_ds3231_alarm *cfg)
Read a DS3231 alarm configuration.
int maxim_ds3231_synchronize(const struct device *dev, struct sys_notify *notify)
Synchronize the RTC against the local clock.
sighandler_t signal(int signo, sighandler_t handler)
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
Definition kernel.h:5768
Information defining the alarm configuration.
Definition maxim_ds3231.h:262
void * user_data
User-provided pointer passed to alarm callback.
Definition maxim_ds3231.h:297
time_t time
Time specification for an RTC alarm.
Definition maxim_ds3231.h:275
maxim_ds3231_alarm_callback_handler_t handler
Handler to be invoked when alarms are signalled.
Definition maxim_ds3231.h:294
uint8_t flags
Flags controlling configuration of the alarm alarm.
Definition maxim_ds3231.h:311
Register the RTC clock against system clocks.
Definition maxim_ds3231.h:320
uint32_t syncclock
Value of a local clock at the same instant as rtc.
Definition maxim_ds3231.h:334
struct timespec rtc
Time from the DS3231.
Definition maxim_ds3231.h:326
State associated with notification for an asynchronous operation.
Definition notify.h:138
Definition _timespec.h:22