1 /* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
2 *
3 * Copyright (c) 2014-2015 Datalight, Inc.
4 * All Rights Reserved Worldwide.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; use version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /* Businesses and individuals that for commercial or other reasons cannot
21 * comply with the terms of the GPLv2 license may obtain a commercial license
22 * before incorporating Reliance Edge into proprietary software for
23 * distribution in any form. Visit http://www.datalight.com/reliance-edge for
24 * more information.
25 */
26
27 /** @file
28 * @brief Implements timestamp functions.
29 *
30 * The functionality implemented herein is not needed for the file system
31 * driver, only to provide accurate results with performance tests.
32 */
33 #include <FreeRTOS.h>
34 #include <task.h>
35
36 #include <redfs.h>
37
38
39 /* configTICK_RATE_HZ is almost always 100, 250, 500, or 1000. If
40 * 1000000U % configTICK_RATE_HZ != 0, then RedOsTimePassed() will be a
41 * little inaccurate.
42 */
43 #define MICROSECS_PER_TICK ( 1000000U / configTICK_RATE_HZ )
44
45
46 /** @brief Initialize the timestamp service.
47 *
48 * The behavior of invoking this function when timestamps are already
49 * initialized is undefined.
50 *
51 * @return A negated ::REDSTATUS code indicating the operation result.
52 *
53 * @retval 0 Operation was successful.
54 * @retval -RED_ENOSYS The timestamp service has not been implemented.
55 */
RedOsTimestampInit(void)56 REDSTATUS RedOsTimestampInit( void )
57 {
58 return 0;
59 }
60
61
62 /** @brief Uninitialize the timestamp service.
63 *
64 * The behavior of invoking this function when timestamps are not initialized
65 * is undefined.
66 *
67 * @return A negated ::REDSTATUS code indicating the operation result.
68 *
69 * @retval 0 Operation was successful.
70 */
RedOsTimestampUninit(void)71 REDSTATUS RedOsTimestampUninit( void )
72 {
73 return 0;
74 }
75
76
77 /** @brief Retrieve a timestamp.
78 *
79 * The behavior of invoking this function when timestamps are not initialized
80 * is undefined
81 *
82 * @return A timestamp which can later be passed to RedOsTimePassed() to
83 * determine the amount of time which passed between the two calls.
84 */
RedOsTimestamp(void)85 REDTIMESTAMP RedOsTimestamp( void )
86 {
87 return xTaskGetTickCount();
88 }
89
90
91 /** @brief Determine how much time has passed since a timestamp was retrieved.
92 *
93 * The behavior of invoking this function when timestamps are not initialized
94 * is undefined.
95 *
96 * @param tsSince A timestamp acquired earlier via RedOsTimestamp().
97 *
98 * @return The number of microseconds which have passed since @p tsSince.
99 */
RedOsTimePassed(REDTIMESTAMP tsSince)100 uint64_t RedOsTimePassed( REDTIMESTAMP tsSince )
101 {
102 /* This works even if the tick count has wrapped around, provided it has
103 * only wrapped around once.
104 */
105 uint32_t ulTicksPassed = ( uint32_t ) xTaskGetTickCount() - tsSince;
106 uint64_t ullMicrosecs = ( uint64_t ) ulTicksPassed * MICROSECS_PER_TICK;
107
108 return ullMicrosecs;
109 }
110