Zephyr Project API 4.2.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
231typedef void (*maxim_ds3231_alarm_callback_handler_t)(const struct device *dev,
232 uint8_t id,
233 uint32_t syncclock,
234 void *user_data);
235
248typedef void (*maxim_ds3231_notify_callback)(const struct device *dev,
249 struct sys_notify *notify,
250 int res);
251
314
337
361static inline uint32_t maxim_ds3231_read_syncclock(const struct device *dev)
362{
363 return k_uptime_get_32();
364}
365
374static inline uint32_t maxim_ds3231_syncclock_frequency(const struct device *dev)
375{
376 return 1000U;
377}
378
396int maxim_ds3231_ctrl_update(const struct device *dev,
397 uint8_t set_bits,
398 uint8_t clear_bits);
399
429int maxim_ds3231_stat_update(const struct device *dev,
430 uint8_t set_bits,
431 uint8_t clear_bits);
432
451int maxim_ds3231_get_alarm(const struct device *dev,
452 uint8_t id,
453 struct maxim_ds3231_alarm *cfg);
454
475int maxim_ds3231_set_alarm(const struct device *dev,
476 uint8_t id,
477 const struct maxim_ds3231_alarm *cfg);
478
505int maxim_ds3231_synchronize(const struct device *dev,
506 struct sys_notify *notify);
507
523__syscall int maxim_ds3231_req_syncpoint(const struct device *dev,
524 struct k_poll_signal *signal);
525
538__syscall int maxim_ds3231_get_syncpoint(const struct device *dev,
539 struct maxim_ds3231_syncpoint *syncpoint);
540
568int maxim_ds3231_set(const struct device *dev,
569 const struct maxim_ds3231_syncpoint *syncpoint,
570 struct sys_notify *notify);
571
589int maxim_ds3231_check_alarms(const struct device *dev);
590
595#ifdef __cplusplus
596}
597#endif
598
599/* @todo this should be syscalls/drivers/rtc/maxim_ds3231.h */
600#include <zephyr/syscalls/maxim_ds3231.h>
601
602#endif /* ZEPHYR_INCLUDE_DRIVERS_RTC_DS3231_H_ */
_TIME_T_ time_t
Definition _timespec.h:14
Main header file for counter driver API.
static uint32_t k_uptime_get_32(void)
Get system uptime (32-bit version).
Definition kernel.h:1950
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:248
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:231
static uint32_t maxim_ds3231_read_syncclock(const struct device *dev)
Read the local synchronization clock.
Definition maxim_ds3231.h:361
static uint32_t maxim_ds3231_syncclock_frequency(const struct device *dev)
Get the frequency of the synchronization clock.
Definition maxim_ds3231.h:374
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:510
Definition kernel.h:6127
Information defining the alarm configuration.
Definition maxim_ds3231.h:263
void * user_data
User-provided pointer passed to alarm callback.
Definition maxim_ds3231.h:298
time_t time
Time specification for an RTC alarm.
Definition maxim_ds3231.h:276
maxim_ds3231_alarm_callback_handler_t handler
Handler to be invoked when alarms are signalled.
Definition maxim_ds3231.h:295
uint8_t flags
Flags controlling configuration of the alarm alarm.
Definition maxim_ds3231.h:312
Register the RTC clock against system clocks.
Definition maxim_ds3231.h:321
uint32_t syncclock
Value of a local clock at the same instant as rtc.
Definition maxim_ds3231.h:335
struct timespec rtc
Time from the DS3231.
Definition maxim_ds3231.h:327
State associated with notification for an asynchronous operation.
Definition notify.h:138
Definition _timespec.h:22