-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelay.c
97 lines (86 loc) · 2.58 KB
/
delay.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* NetUSBee USB driver for TOS
*
* This code is taken from EmuTOS:
*
* delay.c - initialise values used to provide microsecond-order delays
*
* note that the timings are quite imprecise (but conservative) unless
* you are running on at least a 32MHz 68030 processor
*
* Copyright (C) 2013-2017 The EmuTOS development team
*
* Authors:
* RFB Roger Burrows
*
* This file is distributed under the GPL, version 2 or at your
* option any later version. See doc/license.txt for details.
*/
#include <osbind.h>
#include "delay.h"
/*
* initial 1 millisecond delay loop values
*/
#define LOOPS_68060 110000 /* 68060 timing assumes 110MHz for safety */
#define LOOPS_68030 3800 /* 68030 timing assumes 32MHz */
#define LOOPS_68000 760 /* 68000 timing assumes 16MHz */
#define CALIBRATION_TIME 100 /* target # millisecs to run calibration */
#define TIMERD_INTNUM 4 /* for jdisint() etc */
/*
* global variables
*/
ulong loopcount_1_msec;
/*
* function prototypes (functions in delayasm.S)
*/
ulong run_calibration(ulong loopcount);
void calibration_timer(void);
/*
* initialise delay values
*
* this is called to set a reasonable default value for the actual calibration loop
*/
void init_delay(int mcpu)
{
switch(mcpu) {
case 60:
loopcount_1_msec = LOOPS_68060;
break;
case 40:
case 30: /* assumes 68030 */
loopcount_1_msec = LOOPS_68030;
break;
default: /* assumes 68000 */
loopcount_1_msec = LOOPS_68000;
}
}
/*
* calibrate delay values
*
* because this calls run_calibration() which needs to be in supervisor
* state, we just Supexec the whole function
*
* NOTE: we use TimerD so we should restore the RS232 stuff
*/
void calibrate_delay(void)
{
ulong loopcount, intcount;
/* we should save the RS232 serial port status here */
/*
* disable interrupts then run the calibration
*/
Jdisint(TIMERD_INTNUM);
loopcount = CALIBRATION_TIME * loopcount_1_msec;
intcount = run_calibration(loopcount);
Jenabint(TIMERD_INTNUM);
/* we should restore the RS232 serial port stuff here */
/*
* intcount is the number of interrupts that occur during 'loopcount'
* loops. an interrupt occurs every 1/960 sec (see delayasm.S).
* so the number of loops per second = loopcount/(intcount/960).
* so, loops per millisecond = (loopcount*960)/(intcount*1000)
* = (loopcount*24)/(intcount*25).
*/
if (intcount) /* check for valid */
loopcount_1_msec = (loopcount * 24) / (intcount * 25);
}