|
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; |
30 | 31 | \end{lstlisting} |
31 | 32 |
|
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. |
33 | 40 |
|
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} |
35 | 46 |
|
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} |
37 | 51 |
|
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. |
39 | 54 |
|
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} |
41 | 60 |
|
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} |
43 | 65 |
|
44 | | -\section*{Examples} |
| 66 | +\subsection*{Examples} |
45 | 67 |
|
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); |
49 | 71 |
|
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); |
52 | 74 | \end{lstlisting} |
53 | 75 |
|
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