about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
0 files changed, 0 insertions, 0 deletions
55 -0700 5650 - support a second OS: soso' href='/akkartik/mu/commit/kernel.soso/timer.c?h=main&id=46bb1d3157f9ad575c83a4bfa1e32b0d21bc8546'>46bb1d31 ^
67de9b02 ^
46bb1d31 ^



67de9b02 ^
46bb1d31 ^


67de9b02 ^
46bb1d31 ^


67de9b02 ^
46bb1d31 ^


67de9b02 ^
46bb1d31 ^


67de9b02 ^
46bb1d31 ^


67de9b02 ^
46bb1d31 ^










67de9b02 ^
46bb1d31 ^

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












                               
                                                   

                       
                                                                      



                             
                             


                            
                           


                                         
                                


                            
                        


                             
                         


                              
                                         










                                             
                        

                          
#include "timer.h"
#include "isr.h"
#include "screen.h"
#include "process.h"
#include "common.h"

#define TIMER_FREQ 1000

uint32 gSystemTickCount = 0;

BOOL gSchedulerEnabled = FALSE;

//called from assembly
void handleTimerIRQ(TimerInt_Registers registers) {
    gSystemTickCount++;

    if (/*gSystemTickCount % 10 == 0 &&*/ gSchedulerEnabled == TRUE) {
        schedule(&registers);
    }
}

uint32 getSystemTickCount() {
    return gSystemTickCount;
}

uint32 getUptimeSeconds() {
    return gSystemTickCount / TIMER_FREQ;
}

uint32 getUptimeMilliseconds() {
    return gSystemTickCount;
}

void enableScheduler() {
    gSchedulerEnabled = TRUE;
}

void disableScheduler() {
    gSchedulerEnabled = FALSE;
}

static void initTimer(uint32 frequency) {
    uint32 divisor = 1193180 / frequency;

    outb(0x43, 0x36);

    uint8 l = (uint8)(divisor & 0xFF);
    uint8 h = (uint8)( (divisor>>8) & 0xFF );

    outb(0x40, l);
    outb(0x40, h);
}

void initializeTimer() {
    initTimer(TIMER_FREQ);
}