Skip to content

Commit 5246b17

Browse files
committed
Improve documentation for Timekeeping API with detailed API descriptions and examples
1 parent ba1da56 commit 5246b17

File tree

1 file changed

+71
-42
lines changed

1 file changed

+71
-42
lines changed

doc/contents/datetime.tex

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,83 @@
1-
\documentclass{article}
2-
\usepackage{listings}
3-
\usepackage{geometry}
4-
\geometry{margin=1in}
5-
\title{Timekeeping API}
6-
\date{}
7-
\begin{document}
8-
9-
\maketitle
10-
11-
\section*{Structure Descriptions}
12-
13-
\begin{lstlisting}[language=C]
14-
15-
typedef struct
16-
{
17-
uint32_t hrs;
18-
uint32_t mins;
19-
uint32_t secs;
20-
} timeval;
21-
22-
typedef struct
23-
{
24-
uint32_t day;
25-
uint32_t month;
26-
uint32_t year;
27-
28-
} dateval;
29-
1+
\newpage
2+
\section{Timekeeping API}
3+
Provide calendar dates and clock time based on the on-chip RTC.
4+
5+
\subsection*{Overview}
6+
\begin{itemize}
7+
\item Reads a 32-bit seconds-since-1970 counter (RTC register at `0x101e8000`).
8+
\item Exposes two APIs:
9+
\begin{itemize}
10+
\item \texttt{getdate(dateval *date)}: Fetches current date in days, months, and years.
11+
\item \texttt{gettime(timeval *time)}: Fetches current time in hours, minutes, and seconds.
12+
\end{itemize}
13+
\end{itemize}
14+
15+
\subsection*{Data Structure}
16+
17+
\begin{lstlisting}[language=C, caption={Structure definitions for time and date values.}, label={lst:datetime_structs}]
18+
typedef struct
19+
{
20+
uint32_t hrs;
21+
uint32_t mins;
22+
uint32_t secs;
23+
} timeval;
24+
25+
typedef struct
26+
{
27+
uint32_t day;
28+
uint32_t month;
29+
uint32_t year;
30+
} dateval;
3031
\end{lstlisting}
3132

32-
\section*{Implementation Note}
33+
\noindent
34+
The number of seconds since epoch is retrieved from 926EJ-S's Real Time Clock
35+
Data Register(\textbf{RTCDR}). This is a 32 bit register, and therefore
36+
\underline{subject to the Year 2038 Problem}.
37+
38+
\subsection{API: \texttt{uint32\_t getdate(dateval *date\_struct)}}
39+
Populate the provided \texttt{*date\_struct} with the current date in days, months, and years.
3340

34-
The number of seconds since epoch is retrieved from 926EJ-S's Real Time Clock Data Register(\textbf{RTCDR}). This is a 32 bit register, and therefore \underline{subject to the Year 2038 Problem}
41+
\subsubsection*{Parameters}
42+
\begin{itemize}
43+
\item \texttt{date\_struct} pointer to a \texttt{dateval} structure; if \texttt{NULL},
44+
only the raw \textbf{RTC} counter is returned.
45+
\end{itemize}
3546

36-
\section*{uint32_t getdate(dateval *date)}
47+
\subsubsection*{Return Value}
48+
\begin{itemize}
49+
\item Returns number of seconds since epoch (\texttt{RTCDR}) as read from the hardware register.
50+
\end{itemize}
3751

38-
Fetch current date in days, months and years into \texttt{date}. Returns number of seconds since epoch.
52+
\subsection{API: \texttt{uint32\_t gettime(timeval *time\_struct)}}
53+
Populate \texttt{*time\_struct} with the current click time in hours, minutes, and seconds.
3954

40-
\section*{uint32_t gettime(timeval *time)}
55+
\subsubsection*{Parameters}
56+
\begin{itemize}
57+
\item \texttt{time\_struct} pointer to a \texttt{timeval} structure; if \texttt{NULL},
58+
only the raw \textbf{RTC} counter is returned.
59+
\end{itemize}
4160

42-
Fetch current time in hours, minutes and seconds into \texttt{time}. Returns number of seconds since epoch.
61+
\subsubsection*{Return Value}
62+
\begin{itemize}
63+
\item Returns number of seconds since epoch (\texttt{RTCDR}) as read from the hardware register.
64+
\end{itemize}
4365

44-
\section*{Examples}
66+
\subsection*{Examples}
4567

46-
\begin{lstlisting}[language=C,showstringspaces=false]
47-
gettime(&time_struct);
48-
puts("Current time(GMT): %d:%d:%d\n", time_struct.hrs, time_struct.mins, time_struct.secs);
68+
\begin{lstlisting}[language=C, caption={Examples of getdate and gettime usage in AstraKernel.}, label={lst:datetime_examples}]
69+
gettime(&time_struct);
70+
printf("Current time(GMT): %d:%d:%d\n", time_struct.hrs, time_struct.mins, time_struct.secs);
4971

50-
getdate(&date_struct);
51-
puts("Current date(MM-DD-YYYY): %d-%d-%d\n", date_struct.month, date_struct.day, date_struct.year);
72+
getdate(&date_struct);
73+
printf("Current date(MM-DD-YYYY): %d-%d-%d\n", date_struct.month, date_struct.day, date_struct.year);
5274
\end{lstlisting}
5375

54-
\end{document}
76+
\subsection*{Notes}
77+
\begin{itemize}
78+
\item Assumes \texttt{uint32\_t} is 4-bytes (compile-time check via \texttt{\_Static\_assert}).
79+
\item The time and date values are based on the system's RTC, which should be set
80+
correctly at boot time.
81+
\item The API does not handle time zones or daylight saving time adjustments; it
82+
provides GMT time only.
83+
\end{itemize}

0 commit comments

Comments
 (0)