-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.c
62 lines (48 loc) · 1.26 KB
/
timer.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
58
59
60
61
62
#include "types.h"
#include "defs.h"
#include "param.h"
#include "mmu.h"
#include "sh4.h"
#include "proc.h"
#include "spinlock.h"
#include "timer.h"
void timer_init(void)
{
/* stop count TCNTx (not change other TCNT)*/
TSTR = (TSTR & ((~TSTR_STR_BIT0) & (TSTR_STR_MASK)));
/* set timer constant. */
TCOR = TIMER_RATE;
TCNT = TIMER_RATE;
/* enable interrupts, counts Pck/3 clock */
TCR &= ~(TCR_UNF_BIT|TCR_UNIE_BIT|TCR_CKEG_MASK|TCR_TPSC_MASK);
/* clear under flowflag */
TCR |= (TCR_UNIE_BIT | TCR_TPSC_PCK4);
/* set interrupt level */
IPRA_TMU0(TINTLVL);
/* set interrupt mask */
//IMSKC = IMSK_TMU;
/*IMSK = (1UL << INTORG_TMUCH345_BIT);*/
//spm_intr_handler_register(tmu_interval, TMU_INTEVT, 0);
/* start timer */
TSTR = (TSTR & TSTR_STR_MASK) | TSTR_STR_BIT0;
}
void do_timer(void)
{
TCR &= ~TCR_UNF_BIT;
if(cpu->id == 0){
acquire(&tickslock);
ticks++;
wakeup(&ticks);
release(&tickslock);
}
if(proc && proc->killed)
exit();
// Force process to give up CPU on clock tick.
// If interrupts were on while locks held, would need to check nlock.
if(proc && proc->state == RUNNING)
yield();
// Check if the process has been killed since we yielded
if(proc && proc->killed)
exit();
return;
}