EE445M RTOS
Taken at the University of Texas Spring 2015
timekit.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  clocktime
 

Macros

#define TK_MAX_PRINTBUFFER_LEN   20
 
#define TK_PRINT_MODE_HOURS_MINUTES   0
 
#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS   1
 
#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS   2
 
#define TK_TIME_VALID   0
 
#define TK_TIME_INVALID_HOURS   1
 
#define TK_TIME_INVALID_MINUTES   2
 
#define TK_TIME_INVALID_SECONDS   3
 
#define TK_TIME_INVALID_MS   4
 
#define TK_NUM_HOURS   24
 
#define TK_NUM_MINUTES   60
 
#define TK_NUM_SECONDS   60
 
#define TK_NUM_MS   1000
 

Typedefs

typedef struct clocktime clocktime
 

Functions

clocktimeTKCreateTimeHandle (char mode)
 
clocktimeTKDuplicateTimeHandle (clocktime *th)
 
void TKDestroy (clocktime *tm)
 
char * TKToString (clocktime *tm)
 
void TKIncrementHours (clocktime *tm, short hours)
 
void TKIncrementMinutes (clocktime *tm, short minutes)
 
void TKIncrementSeconds (clocktime *tm, short seconds)
 
void TKIncrementMS (clocktime *tm, short ms)
 
short TKValidateTime (clocktime *tm)
 
void TKCleanupTime (clocktime *tm)
 

Macro Definition Documentation

#define TK_MAX_PRINTBUFFER_LEN   20

Definition at line 4 of file timekit.h.

#define TK_NUM_HOURS   24

Definition at line 16 of file timekit.h.

Referenced by TKIncrementHours(), and TKValidateTime().

#define TK_NUM_MINUTES   60

Definition at line 17 of file timekit.h.

Referenced by TKIncrementMinutes(), and TKValidateTime().

#define TK_NUM_MS   1000

Definition at line 19 of file timekit.h.

Referenced by TKIncrementMS(), and TKValidateTime().

#define TK_NUM_SECONDS   60

Definition at line 18 of file timekit.h.

Referenced by TKIncrementSeconds(), and TKValidateTime().

#define TK_PRINT_MODE_HOURS_MINUTES   0

Definition at line 6 of file timekit.h.

Referenced by TKToString().

#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS   1

Definition at line 7 of file timekit.h.

Referenced by TKToString().

#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS   2

Definition at line 8 of file timekit.h.

Referenced by demonstrateClock(), main(), and TKToString().

#define TK_TIME_INVALID_HOURS   1

Definition at line 11 of file timekit.h.

Referenced by TKCleanupTime(), and TKValidateTime().

#define TK_TIME_INVALID_MINUTES   2

Definition at line 12 of file timekit.h.

Referenced by TKCleanupTime(), and TKValidateTime().

#define TK_TIME_INVALID_MS   4

Definition at line 14 of file timekit.h.

Referenced by TKCleanupTime(), and TKValidateTime().

#define TK_TIME_INVALID_SECONDS   3

Definition at line 13 of file timekit.h.

Referenced by TKCleanupTime(), and TKValidateTime().

#define TK_TIME_VALID   0

Definition at line 10 of file timekit.h.

Referenced by main(), TKCleanupTime(), and TKValidateTime().

Typedef Documentation

typedef struct clocktime clocktime

Function Documentation

void TKCleanupTime ( clocktime tm)

Definition at line 147 of file timekit.c.

References clocktime::hours, clocktime::minutes, clocktime::ms, clocktime::seconds, TK_TIME_INVALID_HOURS, TK_TIME_INVALID_MINUTES, TK_TIME_INVALID_MS, TK_TIME_INVALID_SECONDS, TK_TIME_VALID, and TKValidateTime().

147  {
148  short error = TKValidateTime(tm);
149 
150  switch(error) {
151  case TK_TIME_VALID:
152  break;
154  tm->hours = 0;
155  break;
157  tm->minutes = 0;
158  break;
160  tm->seconds = 0;
161  break;
162  case TK_TIME_INVALID_MS:
163  tm->ms = 0;
164  break;
165  default:
166  break;
167  }
168 }
#define TK_TIME_VALID
Definition: timekit.h:10
#define TK_TIME_INVALID_HOURS
Definition: timekit.h:11
#define TK_TIME_INVALID_MINUTES
Definition: timekit.h:12
short seconds
Definition: timekit.h:24
#define TK_TIME_INVALID_MS
Definition: timekit.h:14
#define TK_TIME_INVALID_SECONDS
Definition: timekit.h:13
short minutes
Definition: timekit.h:23
short TKValidateTime(clocktime *tm)
Definition: timekit.c:131
short hours
Definition: timekit.h:22
short ms
Definition: timekit.h:25

Here is the call graph for this function:

clocktime* TKCreateTimeHandle ( char  mode)

Definition at line 14 of file timekit.c.

References clocktime::hours, clocktime::minutes, clocktime::mode, clocktime::ms, and clocktime::seconds.

Referenced by demonstrateClock().

14  {
15  clocktime* t = (clocktime*)malloc(sizeof(clocktime));
16  t->hours = 0;
17  t->minutes = 0;
18  t->seconds = 0;
19  t->ms = 0;
20  t->mode = mode;
21  return t;
22 }
char mode
Definition: timekit.h:26
short seconds
Definition: timekit.h:24
short minutes
Definition: timekit.h:23
short hours
Definition: timekit.h:22
short ms
Definition: timekit.h:25

Here is the caller graph for this function:

void TKDestroy ( clocktime tm)

Definition at line 24 of file timekit.c.

Referenced by demonstrateClock().

24  {
25  free(tm);
26 }

Here is the caller graph for this function:

clocktime* TKDuplicateTimeHandle ( clocktime th)

Definition at line 170 of file timekit.c.

References clocktime::hours, clocktime::minutes, clocktime::mode, clocktime::ms, and clocktime::seconds.

170  {
171 
172  clocktime* handle = (clocktime*)malloc(sizeof(clocktime));
173 
174  handle->hours = th->hours;
175  handle->minutes = th->minutes;
176  handle->seconds = th->seconds;
177  handle->ms = th->ms;
178  handle->mode = th->mode;
179 
180  /* Don't copy the printbuffer! */
181 
182  return handle;
183 }
char mode
Definition: timekit.h:26
short seconds
Definition: timekit.h:24
short minutes
Definition: timekit.h:23
short hours
Definition: timekit.h:22
short ms
Definition: timekit.h:25
void TKIncrementHours ( clocktime tm,
short  hours 
)

Definition at line 55 of file timekit.c.

References clocktime::hours, and TK_NUM_HOURS.

Referenced by demonstrateClock(), main(), and TKIncrementMinutes().

55  {
56 
57  short tmpHours = tm->hours + hours;
58 
59  while ((1U * tmpHours) >= TK_NUM_HOURS) {
60  tmpHours %= TK_NUM_HOURS;
61  }
62 
63  tm->hours = tmpHours;
64 }
#define TK_NUM_HOURS
Definition: timekit.h:16
short hours
Definition: timekit.h:22

Here is the caller graph for this function:

void TKIncrementMinutes ( clocktime tm,
short  minutes 
)

Definition at line 69 of file timekit.c.

References clocktime::minutes, TK_NUM_MINUTES, and TKIncrementHours().

Referenced by demonstrateClock(), main(), and TKIncrementSeconds().

69  {
70  short tmpMinutes = tm->minutes + minutes;
71 
72  if(minutes > 0) {
73  while (tmpMinutes >= TK_NUM_MINUTES) {
74  tmpMinutes -= TK_NUM_MINUTES;
75  TKIncrementHours(tm, 1);
76  }
77  } else {
78  while (tmpMinutes < 0) {
79  tmpMinutes += TK_NUM_MINUTES;
80  TKIncrementHours(tm, -1);
81  }
82  }
83  tm->minutes = tmpMinutes;
84 }
void TKIncrementHours(clocktime *tm, short hours)
Definition: timekit.c:55
#define TK_NUM_MINUTES
Definition: timekit.h:17
short minutes
Definition: timekit.h:23

Here is the call graph for this function:

Here is the caller graph for this function:

void TKIncrementMS ( clocktime tm,
short  ms 
)

Definition at line 109 of file timekit.c.

References clocktime::ms, TK_NUM_MS, and TKIncrementSeconds().

Referenced by main(), and pseudointerrupt().

109  {
110  short tmpMs = tm->ms + ms;
111 
112  if(ms > 0) {
113  while (tmpMs >= TK_NUM_MS) {
114  tmpMs -= TK_NUM_MS;
115  TKIncrementSeconds(tm, 1);
116  }
117  } else {
118  while (tmpMs < 0) {
119  tmpMs += TK_NUM_MS;
120  TKIncrementSeconds(tm, -1);
121  }
122  }
123 
124  tm->ms = tmpMs;
125 }
#define TK_NUM_MS
Definition: timekit.h:19
void TKIncrementSeconds(clocktime *tm, short seconds)
Definition: timekit.c:89
short ms
Definition: timekit.h:25

Here is the call graph for this function:

Here is the caller graph for this function:

void TKIncrementSeconds ( clocktime tm,
short  seconds 
)

Definition at line 89 of file timekit.c.

References clocktime::seconds, TK_NUM_SECONDS, and TKIncrementMinutes().

Referenced by main(), and TKIncrementMS().

89  {
90  short tmpSeconds = tm->seconds + seconds;
91 
92  if(seconds > 0) {
93  while (tmpSeconds >= TK_NUM_SECONDS) {
94  tmpSeconds -= TK_NUM_SECONDS;
95  TKIncrementMinutes(tm, 1);
96  }
97  } else {
98  while (tmpSeconds < 0) {
99  tmpSeconds += TK_NUM_SECONDS;
100  TKIncrementMinutes(tm, -1);
101  }
102 }
103  tm->seconds = tmpSeconds;
104 }
short seconds
Definition: timekit.h:24
#define TK_NUM_SECONDS
Definition: timekit.h:18
void TKIncrementMinutes(clocktime *tm, short minutes)
Definition: timekit.c:69

Here is the call graph for this function:

Here is the caller graph for this function:

char* TKToString ( clocktime tm)

Definition at line 31 of file timekit.c.

References clocktime::hours, clocktime::minutes, clocktime::mode, clocktime::ms, clocktime::printBuffer, clocktime::seconds, TK_PRINT_MODE_HOURS_MINUTES, TK_PRINT_MODE_HOURS_MINUTES_SECONDS, and TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS.

Referenced by main().

31  {
32 
33  switch(tm->mode) {
35  sprintf(tm->printBuffer, "%0.2d:%0.2d", tm->hours, tm->minutes);
36  break;
38  sprintf(tm->printBuffer, "%0.2d:%0.2d:%0.2d",
39  tm->hours, tm->minutes, tm->seconds);
40  break;
42  sprintf(tm->printBuffer, "%0.2d:%0.2d:%0.2d:%0.3d",
43  tm->hours, tm->minutes, tm->seconds, tm->ms);
44  break;
45  default:
46  printf("ERROR OCCURRED IN toString!!");
47  break;
48  }
49  return tm->printBuffer;
50 }
char mode
Definition: timekit.h:26
#define TK_PRINT_MODE_HOURS_MINUTES
Definition: timekit.h:6
short seconds
Definition: timekit.h:24
char printBuffer[20]
Definition: timekit.h:27
short minutes
Definition: timekit.h:23
short hours
Definition: timekit.h:22
#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS
Definition: timekit.h:8
#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS
Definition: timekit.h:7
short ms
Definition: timekit.h:25

Here is the caller graph for this function:

short TKValidateTime ( clocktime tm)

Definition at line 131 of file timekit.c.

References clocktime::hours, clocktime::minutes, clocktime::mode, clocktime::ms, clocktime::seconds, TK_NUM_HOURS, TK_NUM_MINUTES, TK_NUM_MS, TK_NUM_SECONDS, TK_TIME_INVALID_HOURS, TK_TIME_INVALID_MINUTES, TK_TIME_INVALID_MS, TK_TIME_INVALID_SECONDS, and TK_TIME_VALID.

Referenced by main(), and TKCleanupTime().

131  {
132  if(tm->hours > TK_NUM_HOURS) {
133  return TK_TIME_INVALID_HOURS;
134  } else if(tm->minutes > TK_NUM_MINUTES) {
136  } else if((tm->mode > 0) && (tm->seconds > TK_NUM_SECONDS)) {
138  } else if((tm->mode > 1) && (tm->ms > TK_NUM_MS)) {
139  return TK_TIME_INVALID_MS;
140  }
141  return TK_TIME_VALID;
142 }
#define TK_TIME_VALID
Definition: timekit.h:10
char mode
Definition: timekit.h:26
#define TK_TIME_INVALID_HOURS
Definition: timekit.h:11
#define TK_TIME_INVALID_MINUTES
Definition: timekit.h:12
short seconds
Definition: timekit.h:24
#define TK_NUM_HOURS
Definition: timekit.h:16
#define TK_TIME_INVALID_MS
Definition: timekit.h:14
#define TK_NUM_MS
Definition: timekit.h:19
#define TK_NUM_SECONDS
Definition: timekit.h:18
#define TK_TIME_INVALID_SECONDS
Definition: timekit.h:13
#define TK_NUM_MINUTES
Definition: timekit.h:17
short minutes
Definition: timekit.h:23
short hours
Definition: timekit.h:22
short ms
Definition: timekit.h:25

Here is the caller graph for this function: