PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
mstimer.c
Go to the documentation of this file.
1 
13 #include "simpletools.h" // Include simpletools
14 #include "mstimer.h"
15 
16 static volatile int t, dt, cog; // Global var for cogs to share
17 static unsigned int stack[40 + 25]; // Stack vars for other cog
18 
19 void ms_timer(void *par);
20 
22 {
23  mstime_stop();
24  cog = 1 + cogstart(ms_timer, NULL, stack, sizeof(stack));
25 }
26 
28 {
29  if(cog)
30  {
31  cogstop(cog -1);
32  cog = 0;
33  }
34 }
35 
37 {
38  return t;
39 }
40 
42 {
43  t = 0;
44 }
45 
46 void mstime_set(int newTime)
47 {
48  t = newTime;
49 }
50 
51 // Function runs in another cog
52 void ms_timer(void *par)
53 {
54  dt = CLKFREQ/1000;
55  int ticks = CNT;
56  while(1)
57  {
58  waitcnt(ticks+=dt);
59  t++;
60  }
61 }
62 
mstimer.h
Tracks milliseconds elapsed in another cog. This is part of a tutorial on adding a Simple Library to ...
mstime_get
int mstime_get()
Get milliseconds since call to start.
Definition: mstimer.c:36
mstime_reset
void mstime_reset()
Reset the millisecond time elapsed to zero.
Definition: mstimer.c:41
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
mstime_start
int mstime_start()
Start the millisecond timer.
Definition: mstimer.c:21
mstime_stop
void mstime_stop()
Stop the millisecond timer and free up a cog.
Definition: mstimer.c:27
CLKFREQ
#define CLKFREQ
Returns the current clock frequency.
Definition: propeller.h:46
mstime_set
void mstime_set(int newTime)
Set the millisecond timer.
Definition: mstimer.c:46
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
cogstop
#define cogstop(a)
Stop a COG.
Definition: propeller.h:100
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
cogstart
int cogstart(void(*func)(void *), void *par, void *stack, size_t stacksize)
Start a new propeller LMM function/thread in another COG.