RTEMS 6.1-rc6
Loading...
Searching...
No Matches
i2c-rtc.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2023-2024 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef LIBCHIP_I2C_RTC_H
37#define LIBCHIP_I2C_RTC_H
38
39#include <rtems.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
85#include <rtems.h>
86#include <rtems/thread.h>
87#include <libchip/rtc.h>
88#include <stdint.h>
89
90#ifdef __cplusplus
91extern "C" {
92#endif /* __cplusplus */
93
94extern const rtc_fns i2c_rtc_fns;
95bool i2c_rtc_probe(int minor);
96
100 rtems_mutex mutex;
101
103 const char *i2c_bus_path;
104
106 uint8_t i2c_addr;
107
110
116 int (*hw_init) (struct i2c_rtc_base *ctx);
117
120
122 struct {
123 size_t year;
124 size_t month;
125 size_t wkday;
126 size_t day;
127 size_t hour;
128 size_t min;
129 size_t sec;
131};
132
138int i2c_rtc_read(struct i2c_rtc_base *ctx, uint8_t addr, uint8_t *buf,
139 size_t len);
140
146int i2c_rtc_write(struct i2c_rtc_base *ctx, uint8_t addr, const uint8_t *buf,
147 size_t len);
148
149#define I2C_RTC_ORDER_sec_min_hour_wkday_day_month_year \
150 { .sec = 0, .min = 1, .hour = 2, .day = 4, .wkday = 3, .month = 5, .year = 6 }
151
152#define I2C_RTC_ORDER_sec_min_hour_day_wkday_month_year \
153 { .sec = 0, .min = 1, .hour = 2, .day = 3, .wkday = 4, .month = 5, .year = 6 }
154
155#define I2C_RTC_INITIALIZER(i2c_path, i2c_address, offset, reg_order, \
156 driver_name, hwinit)\
157 { \
158 .mutex = RTEMS_MUTEX_INITIALIZER(driver_name), \
159 .i2c_bus_path = i2c_path, \
160 .i2c_addr = i2c_address, \
161 .initialized = false, \
162 .hw_init = hwinit, \
163 .clock_offset = offset, \
164 .order = reg_order, \
165 }
166
167#define I2C_RTC_TBL_ENTRY(dev_name, i2c_rtc_ctx) \
168 { \
169 .sDeviceName = dev_name, \
170 .deviceType = RTC_CUSTOM, \
171 .pDeviceFns = &i2c_rtc_fns, \
172 .deviceProbe = i2c_rtc_probe, \
173 .pDeviceParams = (void *)i2c_rtc_ctx, \
174 .ulCtrlPort1 = 0, \
175 .ulDataPort = 0, \
176 .getRegister = NULL, \
177 .setRegister = NULL, \
178 }
179
182#ifdef __cplusplus
183}
184#endif /* __cplusplus */
185
186#endif /* LIBCHIP_I2C_RTC_H */
int i2c_rtc_read(struct i2c_rtc_base *ctx, uint8_t addr, uint8_t *buf, size_t len)
Definition: i2c-rtc.c:112
int i2c_rtc_write(struct i2c_rtc_base *ctx, uint8_t addr, const uint8_t *buf, size_t len)
Definition: i2c-rtc.c:149
This header file defines the RTEMS Classic API.
Definition: rtc.h:46
Definition: i2c-rtc.h:98
size_t clock_offset
Definition: i2c-rtc.h:119
int(* hw_init)(struct i2c_rtc_base *ctx)
Definition: i2c-rtc.h:116
struct i2c_rtc_base::@573 order
bool initialized
Definition: i2c-rtc.h:109
uint8_t i2c_addr
Definition: i2c-rtc.h:106
rtems_mutex mutex
Definition: i2c-rtc.h:100
const char * i2c_bus_path
Definition: i2c-rtc.h:103
This header file provides the API of Self-Contained Objects.