libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
rtc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
26
27#ifndef LIBWS_CART_RTC_H_
28#define LIBWS_CART_RTC_H_
29
30#include "../ports.h"
31
36
37#define WS_CART_RTC_MONTH_AMPM 0x80
38#define WS_CART_RTC_MONTH_AM 0x00
39#define WS_CART_RTC_MONTH_PM 0x80
40
41#define WS_CART_RTC_STATUS_POWER_LOST 0x80
42#define WS_CART_RTC_STATUS_12_HOUR 0x00
43#define WS_CART_RTC_STATUS_24_HOUR 0x40
44#define WS_CART_RTC_STATUS_INTAE 0x20
45#define WS_CART_RTC_STATUS_INTME 0x08
46#define WS_CART_RTC_STATUS_INTFE 0x02
47#define WS_CART_RTC_STATUS_INT_OFF 0
48#define WS_CART_RTC_STATUS_INT_FREQ_STEADY (WS_CART_RTC_STATUS_INTFE)
49#define WS_CART_RTC_STATUS_INT_MINUTE_EDGE (WS_CART_RTC_STATUS_INTME)
50#define WS_CART_RTC_STATUS_INT_MINUTE_STEADY (WS_CART_RTC_STATUS_INTME | WS_CART_RTC_STATUS_INTFE)
51#define WS_CART_RTC_STATUS_INT_ALARM (WS_CART_RTC_STATUS_INTAE)
52
53#ifndef __ASSEMBLER__
54
55#include <stdbool.h>
56#include <stdint.h>
57#include <wonderful.h>
58
62typedef struct __attribute__((packed)) {
63 uint8_t year;
64 uint8_t month;
65 uint8_t date;
66 uint8_t day;
68
72typedef struct __attribute__((packed)) {
73 uint8_t hour;
74 uint8_t minute;
75 uint8_t second;
77
78typedef struct __attribute__((packed)) {
82
87
98uint16_t ws_cart_rtc_read(uint8_t command, void __wf_cram* buffer, uint16_t length);
99
110uint16_t ws_cart_rtc_write(uint8_t command, const void __wf_cram* buffer, uint16_t length);
111
112static inline bool ws_cart_rtc_reset(void) {
113 if (!ws_cart_rtc_wait_ready()) return false;
115}
116
117static inline bool ws_cart_rtc_read_status(uint8_t __wf_cram* result) {
119}
120
121static inline bool ws_cart_rtc_write_status(uint8_t result) {
123}
124
128
132
133static inline bool ws_cart_rtc_read_time(ws_cart_rtc_time_t __wf_cram* result) {
135}
136
137static inline bool ws_cart_rtc_write_time(ws_cart_rtc_time_t __wf_cram* result) {
139}
140
141static inline bool ws_cart_rtc_write_alarm(uint16_t alarm) {
142 alarm = __builtin_bswap16(alarm);
144}
145
147
148#endif /* __ASSEMBLER__ */
149
150#endif /* LIBWS_CART_RTC_H_ */
static bool ws_cart_rtc_read_time(ws_cart_rtc_time_t __wf_cram *result)
Definition rtc.h:133
static bool ws_cart_rtc_write_time(ws_cart_rtc_time_t __wf_cram *result)
Definition rtc.h:137
uint16_t ws_cart_rtc_write(uint8_t command, const void __wf_cram *buffer, uint16_t length)
Send command and write to RTC.
static bool ws_cart_rtc_read_status(uint8_t __wf_cram *result)
Definition rtc.h:117
static bool ws_cart_rtc_read_datetime(ws_cart_rtc_datetime_t __wf_cram *result)
Definition rtc.h:125
static bool ws_cart_rtc_write_status(uint8_t result)
Definition rtc.h:121
static bool ws_cart_rtc_write_datetime(ws_cart_rtc_datetime_t __wf_cram *result)
Definition rtc.h:129
static bool ws_cart_rtc_write_alarm(uint16_t alarm)
Definition rtc.h:141
static bool ws_cart_rtc_reset(void)
Definition rtc.h:112
bool ws_cart_rtc_wait_ready(void)
Wait until the RTC is ready.
uint16_t ws_cart_rtc_read(uint8_t command, void __wf_cram *buffer, uint16_t length)
Send command and read from RTC.
#define WS_CART_RTC_CTRL_CMD_READ_DATETIME
Definition ports.h:143
#define WS_CART_RTC_CTRL_CMD_WRITE_STATUS
Definition ports.h:140
#define WS_CART_RTC_CTRL_PORT
Definition ports.h:135
#define WS_CART_RTC_CTRL_CMD_WRITE_DATETIME
Definition ports.h:142
#define WS_CART_RTC_CTRL_CMD_WRITE_TIME
Definition ports.h:144
#define WS_CART_RTC_CTRL_CMD_READ_STATUS
Definition ports.h:141
#define WS_CART_RTC_CTRL_ACTIVE
Definition ports.h:138
#define WS_CART_RTC_CTRL_CMD_READ_TIME
Definition ports.h:145
#define WS_CART_RTC_CTRL_CMD_WRITE_ALARM
Definition ports.h:146
#define WS_CART_RTC_CTRL_CMD_RESET
Definition ports.h:139
Structure containing the date read from the RTC, BCD-encoded.
Definition rtc.h:62
uint8_t date
Definition rtc.h:65
uint8_t month
Definition rtc.h:64
uint8_t day
Definition rtc.h:66
uint8_t year
Definition rtc.h:63
ws_cart_rtc_time_t time
Definition rtc.h:80
ws_cart_rtc_date_t date
Definition rtc.h:79
Structure containing the time read from the RTC, BCD-encoded.
Definition rtc.h:72
uint8_t second
Definition rtc.h:75
uint8_t minute
Definition rtc.h:74
uint8_t hour
Definition rtc.h:73