-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCoolTest.java
More file actions
127 lines (90 loc) · 2.26 KB
/
CoolTest.java
File metadata and controls
127 lines (90 loc) · 2.26 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public class CoolTest implements Runnable{
private int del;
public CoolTest(int delaynum){
del = delaynum * 234; //approx in centiseconds
}
public void run(){
int v = del;
while(true){
UC.gpioSetHi(0, 7, !UC.gpioIsHi(0,7));
int x = UC.clkGet();
while(UC.clkGet() - x < v);
}
}
public static void printString(String s){
int i, L = s.Xlen_(); //we cheat by not claling string methods - they are slow
for(i = 0; i < L; i++) uj.lang.RT.consolePut((char)s.XbyteAt_(i));
}
public static String toString(int v){
int t = v;
int len = 0;
byte [] ret;
boolean neg = false;
if(v < 0){
neg = true;
len++;
v = -v;
}
do{
len++;
t /= 10;
}while(t != 0);
ret = new byte[len];
do{
ret[--len] = (byte)((v % 10) + (int)'0');
v /= 10;
}while(v != 0);
if(neg) ret[--len] = '-';
return new String(ret);
}
public static String toString(float f){
String ret;
int exp, man;
man = 0;
exp = 0;
if(f < 0){
f = -f;
ret = "-";
} else ret = "";
if(f < 0.001f || f >= 100000.f){
while(f >= 10.0f){
exp++;
f /= 10.0f;
}
while(f < 1.0f){
exp--;
f *= 10.0f;
}
}
ret = ret + toString((int)f) + ".";
while(ret.length() < 10){ //doubles are good to 16 digits or so
f -= (int)f;
f *= 10.0f;
ret = ret + (char)(((int)f) + (int)'0');
man++;
}
if(exp != 0) ret = ret + "*10^" + toString(exp);
return ret;
}
public static void main(){
int clk = UC.clkGet();
UC.gpioSetOutput(0, 7, true);
int i = 200, j;
int needThreads = 10;
Thread[] threads = new Thread[needThreads];
int haveThreads = 0;
while(haveThreads < needThreads){
for(j = 2; j < i; j++) if(i % j == 0) break;
if(i == j){
threads[haveThreads++] = new Thread(new CoolTest(i));
printString("Started thread " + toString(haveThreads) + " with period " + toString(i) + "\n");
}
i++;
}
clk = UC.clkGet() - clk;
int instrs = UC.instrsGet();
float c = ((float)clk)/23437.5f;
printString(toString(instrs) + " instrs in " + toString(clk) + " ticks (" + toString(c) + "s) -> " + toString((float)instrs / c) + " instrs/sec (" + toString((float)clk * 1024f / (float)instrs) + " instrs/instr).\n");
while(true);
}
}