-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFakeMicroTime.c
57 lines (52 loc) · 2.17 KB
/
FakeMicroTime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/***
* Excerpted from "Test-Driven Development for Embedded C",
* published by The Pragmatic Bookshelf.
* Copyrights apply to this code. It may not be used to create training material,
* courses, books, articles, and the like. Contact us if you are in doubt.
* We make no guarantees that this code is fit for any purpose.
* Visit http://www.pragmaticprogrammer.com/titles/jgade for more book information.
***/
/*- ------------------------------------------------------------------ -*/
/*- Copyright (c) James W. Grenning -- All Rights Reserved -*/
/*- For use by owners of Test-Driven Development for Embedded C, -*/
/*- and attendees of Renaissance Software Consulting, Co. training -*/
/*- classes. -*/
/*- -*/
/*- Available at http://pragprog.com/titles/jgade/ -*/
/*- ISBN 1-934356-62-X, ISBN13 978-1-934356-62-3 -*/
/*- -*/
/*- Authorized users may use this source code in your own -*/
/*- projects, however the source code may not be used to -*/
/*- create training material, courses, books, articles, and -*/
/*- the like. We make no guarantees that this source code is -*/
/*- fit for any purpose. -*/
/*- -*/
/*- www.renaissancesoftware.net [email protected] -*/
/*- ------------------------------------------------------------------ -*/
#include "MicroTime.h"
#include <stdlib.h>
#include <memory.h>
static uint32_t time = 0;
static uint32_t increment = 1;
static uint32_t totalDelay = 0;
void FakeMicroTime_Init(uint32_t start, uint32_t incr)
{
time = start;
increment = incr;
totalDelay = 0;
}
uint32_t MicroTime_Get(void)
{
uint32_t t = time;
time += increment;
return t;
}
void MicroTime_Delay(uint32_t delay)
{
time += delay;
totalDelay += delay;
}
uint32_t FakeMicroTime_GetDelayDuration(void)
{
return totalDelay;
}