-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpitr_sem.cpp
55 lines (37 loc) · 936 Bytes
/
pitr_sem.cpp
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
#include "predef.h"
#include <ctype.h>
#include <basictypes.h>
#include <system.h>
#include <constants.h>
#include <ucos.h>
#include <ucosmcfc.h>
#include <sim.h>
#include <bsp.h>
#include <cfinter.h>
#include "pitr_sem.h"
// Instruct the C++ compiler not to mangle the function name
extern "C"
{
void SetIntc0( long func, int vector, int level, int prio );
}
volatile DWORD Pit_Count;
static WORD pit_pcsr_clr;
static OS_SEM * pSem;
INTERRUPT( my_pitr_func, 0x2600 )
{
sim.pit[1].pcsr = pit_pcsr_clr;
Pit_Count++;
if(pSem) OSSemPost(pSem);
}
extern DWORD CPU_CLOCK;
void PiterSem(OS_SEM *p_toSem, int pit_per_sec)
{
pSem=p_toSem;
DWORD div=2;
DWORD pcsr=0x00F;
while (((CPU_CLOCK/div)/pit_per_sec) > 65536) {div*=2; pcsr+=0x100;}
pit_pcsr_clr=pcsr;
sim.pit[1].pmr = ((CPU_CLOCK/div)/pit_per_sec); // Set the PIT modulus value
sim.pit[1].pcsr =pcsr;
SetIntc0( ( long ) &my_pitr_func, 56, 6, 3 );
}