use of joprt.RtThread in project jop by jop-devel.
the class PeriodicStack method main.
public static void main(String[] args) {
RtThread rt = new RtThread(10, 100000) {
public void run() {
waitForNextPeriod();
int ts_old = Native.rd(Const.IO_US_CNT);
for (; ; ) {
waitForNextPeriod();
int ts = Native.rd(Const.IO_US_CNT);
Result.printPeriod(ts_old, ts);
ts_old = ts;
}
}
};
//
// do busy work
//
RtThread rts = new RtThread(9, 1000000) {
public void run() {
f1();
}
void f1() {
f2();
}
void f2() {
f3();
}
void f3() {
f4();
}
void f4() {
f5();
}
void f5() {
f6();
}
void f6() {
f7();
}
void f7() {
f8();
}
void f8() {
f9();
}
void f9() {
f10();
}
void f10() {
loop();
}
void loop() {
for (; ; ) {
System.out.print('*');
waitForNextPeriod();
int ts = Native.rd(Const.IO_US_CNT) + 990000;
while (ts - Native.rd(Const.IO_US_CNT) > 0) ;
}
}
};
RtThread.startMission();
// sleep
for (; ; ) {
Timer.wd();
try {
RtThread.sleepMs(1200);
} catch (Exception e) {
}
}
}
use of joprt.RtThread in project jop by jop-devel.
the class PeriodicStack2 method main.
public static void main(String[] args) {
// use serial line for debug output
Dbg.initSer();
RtThread rt = new RtThread(10, 100000) {
public void run() {
// f1(); does NOT work!!!
f4();
}
void f1() {
f2();
}
void f2() {
f3();
}
void f3() {
f4();
}
void f4() {
f5();
}
void f5() {
f6();
}
void f6() {
f7();
}
void f7() {
f8();
}
void f8() {
f9();
}
void f9() {
f10();
}
void f10() {
loop();
}
void loop() {
waitForNextPeriod();
int ts_old = Native.rd(Const.IO_US_CNT);
for (; ; ) {
waitForNextPeriod();
int ts = Native.rd(Const.IO_US_CNT);
Result.printPeriod(ts_old, ts);
ts_old = ts;
}
}
};
//
// do busy work
//
RtThread rts = new RtThread(9, 1000000) {
public void run() {
f1();
}
void f1() {
f2();
}
void f2() {
f3();
}
void f3() {
f4();
}
void f4() {
f5();
}
void f5() {
f6();
}
void f6() {
f7();
}
void f7() {
f8();
}
void f8() {
f9();
}
void f9() {
f10();
}
void f10() {
loop();
}
void loop() {
for (; ; ) {
Dbg.wr('*');
waitForNextPeriod();
int ts = Native.rd(Const.IO_US_CNT) + 990000;
while (ts - Native.rd(Const.IO_US_CNT) > 0) ;
}
}
};
RtThread.startMission();
// sleep
for (; ; ) {
Timer.wd();
try {
RtThread.sleepMs(1200);
} catch (Exception e) {
}
}
}
use of joprt.RtThread in project jop by jop-devel.
the class Utilization method main.
public static void main(String[] args) {
RtThread rt = new RtThread(10, PERIOD) {
public void run() {
int busy = PERIOD * 9 / 10;
for (; ; ) {
int t = Native.rd(Const.IO_US_CNT) + busy;
while (t - Native.rd(Const.IO_US_CNT) > 0) {
;
}
waitForNextPeriod();
}
}
};
RtThread.startMission();
int t1, t2, t3;
int idle, timeout;
idle = 0;
t1 = Native.rd(Const.IO_US_CNT);
timeout = t1;
for (; ; ) {
t2 = Native.rd(Const.IO_US_CNT);
t3 = t2 - t1;
t1 = t2;
if (t3 < MIN_US) {
idle += t3;
}
if (t2 - timeout > 1000000) {
Timer.wd();
t2 -= timeout;
System.out.print(t2);
System.out.print(" ");
System.out.print(idle);
System.out.print(" ");
idle *= 100;
idle /= t2;
idle = 100 - idle;
System.out.print("CPU utilization [%]: ");
System.out.print(idle);
System.out.println();
idle = 0;
t1 = Native.rd(Const.IO_US_CNT);
timeout = t1;
}
}
}
use of joprt.RtThread in project jop by jop-devel.
the class ContextSwitch method main.
public static void main(String[] args) {
// use serial line for debug output
Dbg.initSerWait();
result = new int[CNT];
// low priority thread
RtThread lprt = new RtThread(5, 100000) {
public void run() {
for (; ; ) {
ts = Native.rd(Const.IO_CNT);
}
}
};
RtThread rt = new RtThread(10, 5000) {
public void run() {
int i;
// give lprt a chance to start
waitForNextPeriod();
for (i = 0; i < CNT; ++i) {
waitForNextPeriod();
result[i] = Native.rd(Const.IO_CNT) - ts;
}
result();
}
void result() {
int max = 0;
int min = 999999999;
int i;
for (i = 0; i < CNT; ++i) {
int val = result[i] - t_diff;
if (val < min)
min = val;
if (val > max)
max = val;
Dbg.intVal(val);
Dbg.wr('\n');
}
Dbg.intVal(min);
Dbg.intVal(max);
Dbg.wr('\n');
for (; ; ) waitForNextPeriod();
}
};
// measure time for measurement
ts = Native.rd(Const.IO_CNT);
ts = Native.rd(Const.IO_CNT) - ts;
t_diff = ts;
RtThread.startMission();
for (; ; ) {
// busy do nothing
;
}
}
use of joprt.RtThread in project jop by jop-devel.
the class LegoBoardTest method main.
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Initializing.");
/* Motor.setMotor(0, Motor.STATE_FORWARD, true, Motor.MAX_DUTYCYCLE);
Motor.setMotor(1, Motor.STATE_FORWARD, true, Motor.MAX_DUTYCYCLE);
Motor.setMotor(2, Motor.STATE_FORWARD, true, Motor.MAX_DUTYCYCLE);
//Native.wr(-1 << 1, Motor.IO_OUTPUT_MOTOR[1]);
*/
if (KNIGHT_RIDER_DEMO) {
val = LED0;
up = true;
new RtThread(10, 100 * 1000) {
public void run() {
for (; ; ) {
knightRiderLoop();
waitForNextPeriod();
}
}
};
}
if (SPEAKER_DEMO) {
up = true;
flag = false;
value = 10;
new RtThread(10, 1 * 1000) {
public void run() {
for (; ; ) {
speakerLoop();
waitForNextPeriod();
}
}
};
}
new RtThread(10, 1000 * 1000) {
public void run() {
do {
System.out.println("New measurement...");
System.out.println();
if (FREEMEMORY) {
System.out.print("Free memory: ");
System.out.println(GC.freeMemory());
}
if (BUTTONS) {
for (int i = 0; i < 4; i++) {
// uncomment this to have fun with javac
//System.out.println("Button " + i + ": " + Buttons.getButton(i));
// uncomment this to have fun with JOP
//System.out.println("Button " + i + ": " + new Boolean(Buttons.getButton(i)));
System.out.print("Button ");
System.out.print(i);
System.out.print(": ");
System.out.println(Buttons.getButton(i) ? "Down" : "Up");
}
}
if (DIGITALINPUTS) {
for (int i = 0; i < 3; i++) {
System.out.print("Digital input ");
System.out.print(i);
System.out.print(": ");
System.out.println(DigitalInputs.getDigitalInput(i) ? "1" : "0");
}
//output.append("Digital input ").append(i).append(": ").append(DigitalInputs.getDigitalInput(i) ? "1" : "0").append("\n");
}
if (FUTUREUSE) {
System.out.print("Unknown input: 0x");
System.out.println(Integer.toHexString((FutureUse.readPins())));
}
if (LEDS) {
Leds.setLeds(-1);
}
if (MICROPHONE) {
System.out.print("Microphone: ");
System.out.println(Microphone.readMicrophone());
}
if (MOTORS) {
Motor.synchronizedReadBackEMF();
for (int i = 0; i < 2; i++) {
// MS: two times new to read the back EMF!!!
int[] backEMF = new Motor(i).getSynchronizedBackEMF();
System.out.print("Motor ");
System.out.print(i);
System.out.print(" back-emf measurement: ");
System.out.print(backEMF[0] - 0x100);
System.out.print(", ");
System.out.println(backEMF[1] - 0x100);
}
}
if (SENSORS) {
Sensors.synchronizedReadSensors();
for (int i = 0; i < 3; i++) {
System.out.print("Analog sensor ");
System.out.print(i);
System.out.print(" : ");
System.out.print(Sensors.getBufferedSensor(i));
System.out.print(" (");
System.out.print(Sensors.readSensorValueAsPercentage(i));
System.out.println("%)");
}
}
if (PLD_RAW_INPUT) {
System.out.print("PLD raw input: ");
System.out.println(Native.rd(Const.IO_LEGO + 7));
}
System.out.println();
System.out.println("Measurement finished.");
if (!REPEAT)
break;
waitForNextPeriod();
} while (true);
}
};
RtThread.startMission();
System.out.println("Started.");
}
Aggregations