LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_timer.c
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 
22 #include "lms2012.h"
23 #include "c_timer.h"
24 
25 #if (HARDWARE != SIMULATION)
26 
27 #include <time.h>
28 #include <sys/time.h>
29 
30 
31 #endif
32 
33 #if (HARDWARE != SIMULATION)
34 
35 
37 {
38  ULONG Result;
39  struct timeval tv;
40 
41  gettimeofday(&tv,NULL);
42  Result = (ULONG)tv.tv_sec * 1000;
43  Result += (ULONG)tv.tv_usec / 1000;
44 
45  return(Result);
46 }
47 
48 
50 {
51  struct timeval tv;
52 
53  gettimeofday(&tv,NULL);
54  VMInstance.TimeuS = (ULONG)tv.tv_sec * 1000000;
55  VMInstance.TimeuS += (ULONG)tv.tv_usec;
56 
57  return(VMInstance.TimeuS);
58 }
59 
60 #endif
61 
62 //******* BYTE CODE SNIPPETS **************************************************
63 
64 
65 
79 void cTimerWait(void)
80 {
81  ULONG Time;
82 
83  Time = *(ULONG*)PrimParPointer();
84 
85  *(ULONG*)PrimParPointer() = cTimerGetmS() + Time;
86 }
87 
88 
101 void cTimerReady(void)
102 {
103  IP TmpIp;
104  DSPSTAT DspStat = BUSYBREAK;
105 
106  TmpIp = GetObjectIp();
107 
108  if (*(ULONG*)PrimParPointer() <= cTimerGetmS())
109  {
110  DspStat = NOBREAK;
111  }
112  if (DspStat == BUSYBREAK)
113  { // Rewind IP
114 
115  SetObjectIp(TmpIp - 1);
116  }
117  SetDispatchStatus(DspStat);
118 
119 }
120 
121 
134 void cTimerRead(void)
135 {
137 }
138 
139 
152 void cTimerReaduS(void)
153 {
155 }
156 
157 
158 //*****************************************************************************
159 
160 
void SetDispatchStatus(DSPSTAT DspStat)
Set object (dispatch) status.
Definition: lms2012.c:256
ULONG cTimerGetuS(void)
Definition: c_timer.c:49
void cTimerReaduS(void)
opTIMER_READ_US byte code
Definition: c_timer.c:152
SLONG DATA32
VM Type for 4 byte signed value.
Definition: lmstypes.h:63
void SetObjectIp(IP Ip)
Set current instruction pointer.
Definition: lms2012.c:309
void * PrimParPointer(void)
Get next encoded parameter from byte code stream.
Definition: lms2012.c:694
IP GetObjectIp(void)
Get current instruction pointer.
Definition: lms2012.c:298
ULONG cTimerGetmS(void)
Definition: c_timer.c:36
IMGDATA * IP
Instruction pointer type.
Definition: lmstypes.h:74
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
Definition: lmstypes.h:31
void cTimerReady(void)
opTIMER_READY byte code
Definition: c_timer.c:101
void cTimerRead(void)
opTIMER_READ byte code
Definition: c_timer.c:134
ULONG StartTime
Program start time [mS].
Definition: lms2012.h:739
ULONG TimeuS
Definition: lms2012.h:1460
PRG Program[MAX_PROGRAMS]
Program[0] is the UI byte codes running.
Definition: lms2012.h:1431
PRGID CurrentProgramId(void)
Get current program id.
Definition: lms2012.c:207
void cTimerWait(void)
opTIMER_WAIT byte code
Definition: c_timer.c:79
DSPSTAT
Definition: lms2012.h:665
GLOBALS VMInstance
Definition: lms2012.c:131
Break because of waiting for completion.
Definition: lms2012.h:671
Dispatcher running (looping)
Definition: lms2012.h:667
#define NULL