Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
rtc.c
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
15
16#include "rtc/rtc.h"
17
18/*----------------------------------------------------------------------------*/
19/* Function implementations */
20/*----------------------------------------------------------------------------*/
21
22
23const char* Day_ordinal [] = {
24 "st",
25 "nd",
26 "rd",
27 "th"
28};
29
30
31const char* const DayStrings[] = {
32 "Unknown",
33 "Sunday",
34 "Monday",
35 "Tuesday",
36 "Wednesday",
37 "Thursday",
38 "Friday",
39 "Saturday"
40};
41
42
43const char* const MonthStrings[] = {
44 "Unknown",
45 "January",
46 "February",
47 "March",
48 "April",
49 "May",
50 "June",
51 "July" ,
52 "August" ,
53 "September" ,
54 "October",
55 "November" ,
56 "December"
57};
58
59
60
61const char* const meridiem[] = {
62 "am",
63 "pm"
64};
65
66
67
68const char* get_ordinal(u8 day) {
69 if (day >= 11 && day <= 13) return "th"; // Special case for 11th, 12th, 13th
70
71 switch (day % 10) {
72 case 1: return "st";
73 case 2: return "nd";
74 case 3: return "rd";
75 default: return "th";
76 }
77}
78
79
80u8 convert_hour_register(u8 old_reg_val, u8 to_12h)
81{
82 u8 h, pm_flag;
83 u8 new_reg_val;
84
85 if (to_12h) {
86 // --- Convert 24h to 12h ---
87 // Input is raw BCD (00 to 23)
88 h = bcd2bin(old_reg_val & 0x3F); // Mask 0x3F removes unused bits
89
90 if (h >= 12) {
91 pm_flag = 1;
92 if (h > 12) h -= 12;
93 } else {
94 pm_flag = 0;
95 if (h == 0) h = 12; // 00:00 becomes 12:00 AM
96 }
97
98 // Re-encode: [Bit 5 = PM] [Bits 4-0 = Hour BCD]
99 new_reg_val = bin2bcd(h) | (pm_flag << 5);
100 }
101 else {
102 // --- Convert 12h to 24h ---
103 // Input is [Bit 5 = PM] [Bits 4-0 = Hour BCD]
104 pm_flag = (old_reg_val & 0x20) >> 5;
105 h = bcd2bin(old_reg_val & 0x1F); // Mask 0x1F gets the number
106
107 if (pm_flag) {
108 // PM Case: 12 PM -> 12, 1 PM -> 13
109 if (h < 12) h += 12;
110 } else {
111 // AM Case: 12 AM -> 00, 1 AM -> 1
112 if (h == 12) h = 0;
113 }
114
115 new_reg_val = bin2bcd(h);
116 }
117 return new_reg_val;
118}
119
const char *const DayStrings[]
Get string representations for Sunday,Monday ,etc..
Definition rtc.c:31
const char *const meridiem[]
Get string representations for meridiem (AM/PM).
Definition rtc.c:61
u8 convert_hour_register(u8 old_reg_val, u8 to_12h)
Convert hour register between 12-hour and 24-hour format.
Definition rtc.c:80
const char * get_ordinal(u8 day)
Get ordinal suffix for a given day.
Definition rtc.c:68
const char *const MonthStrings[]
Get string representations for months.
Definition rtc.c:43
const char * Day_ordinal[]
Get ordinal suffix for a given day.
Definition rtc.c:23
RTC driver API definitions.
uint8_t u8
Definition type.h:26