RTEMS 6.1-rc2
Loading...
Searching...
No Matches
mcp7940m-rtc.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2023 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef LIBCHIP_MCP7940M_RTC_H
29#define LIBCHIP_MCP7940M_RTC_H
30
31#include <rtems.h>
32#include <rtems/thread.h>
33#include <libchip/rtc.h>
34#include <stdint.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40extern const rtc_fns rtc_mcp7940m_fns;
41bool rtc_mcp7940m_probe(int minor);
42
43/*
44 * It is expected, that the RTC can be accessed as a raw file. A pointer to a
45 * constant string with the name of that device has to be passed to the table
46 * initializer.
47 *
48 * The MCP7940M uses an EEPROM-like interface. So you could for example use the
49 * following initialization:
50 *
51 * Define a context for the RTC somewhere:
52 *
53 * static struct mcp7940m_rtc rtc_ctx =
54 * MCP7940M_RTC_INITIALIZER("/dev/i2c-1", 0x6F, true);
55 *
56 * Then you can use the following for the RTC_Table:
57 *
58 * MCP7940M_RTC_TBL_ENTRY("/dev/rtc", &rtc_ctx)
59 */
60
63 rtems_mutex mutex;
64
66 const char *i2c_bus_path;
67
69 uint8_t i2c_addr;
70
72 bool crystal;
73
76};
77
78#define MCP7940M_RTC_INITIALIZER(i2c_path, i2c_address, has_crystal) { \
79 .mutex = RTEMS_MUTEX_INITIALIZER("mcp7940m"), \
80 .i2c_bus_path = i2c_path, \
81 .i2c_addr = i2c_address, \
82 .crystal = has_crystal, \
83 .initialized = false, \
84 }
85
86#define MCP7940M_RTC_TBL_ENTRY(dev_name, mcp7940m_rtc_ctx) \
87 { \
88 .sDeviceName = dev_name, \
89 .deviceType = RTC_CUSTOM, \
90 .pDeviceFns = &rtc_mcp7940m_fns, \
91 .deviceProbe = rtc_mcp7940m_probe, \
92 .pDeviceParams = (void *)mcp7940m_rtc_ctx, \
93 .ulCtrlPort1 = 0, \
94 .ulDataPort = 0, \
95 .getRegister = NULL, \
96 .setRegister = NULL, \
97 }
98
99#ifdef __cplusplus
100}
101#endif /* __cplusplus */
102
103#endif /* LIBCHIP_MCP7940M_RTC_H */
This header file defines the RTEMS Classic API.
Definition: rtc.h:46
Definition: mcp7940m-rtc.h:61
bool initialized
Definition: mcp7940m-rtc.h:75
const char * i2c_bus_path
Definition: mcp7940m-rtc.h:66
uint8_t i2c_addr
Definition: mcp7940m-rtc.h:69
bool crystal
Definition: mcp7940m-rtc.h:72
rtems_mutex mutex
Definition: mcp7940m-rtc.h:63
This header file provides the API of Self-Contained Objects.