ESOS32
ESOSOn32-bitProcessors
esos_pc_tick.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
33 // Documentation for this file. If the \file tag isn't present,
34 // this file won't be documented.
43 /************************************************************************
44  * esos_pc_tick.c
45  ************************************************************************
46  * User provided (HW-specific) ES_OS routines for IRQs
47  */
48 
49 #ifdef _WIN32
50 #include <windows.h>
51 #else
52 #include <unistd.h>
53 #include <sys/time.h>
54 #endif
55 
56 #include "all_generic.h"
57 
58 // PROTOTYPE our private little helper functions
59 uint32_t clock_time(void);
60 
61 // create a variable to save the initial clock time in
62 static uint32_t initClockCount;
63 
64 /*
65  * User must provide the HW-specific routine to setup a system
66  * tick for ES_OS.
67  *
68 
69  */
70 void __esos_hw_InitSystemTick(void) {
71  /*
72  * save the time.h clock() count when the system inits
73  * so we can compute elapsed time when the user apps
74  * and the ES_OS request it later via esos_GetSystemTick()
75  */
76  initClockCount = clock_time();
77 
78 } // end _esos_hw_InitSystemTick()
79 
80 /*
81  * User must provide the HW-specific routine to return the 32 bit
82  * system tick to ES_OS and user tasks.
83  *
84  * get the current time and compute delta back to init time
85  */
86 uint32_t __esos_hw_GetSystemTickCount(void) {
87  return (clock_time()-initClockCount);
88 } // end _esos_hw_GetSystemTickCount()
89 
90 uint32_t clock_time(void) {
91  struct timeval tv;
92  struct timezone tz;
93 
94  // gettimeofday() returns time since the epoch.....
95  // in sec and usec members
96  gettimeofday(&tv, &tz);
97  // give the user time count in milliseconds
98  return ((tv.tv_sec * 1000) +(tv.tv_usec / 1000));
99 }
__esos_hw_InitSystemTick
void __esos_hw_InitSystemTick(void)
Definition: esos_hwxxx_tick.c:102
all_generic.h
Embedded Systems Operating System 32 bit (ESOS32) definitions to make ESOS32 code more generic and po...