use of joprt.RtThread in project jop by jop-devel.
the class HelloSpm method main.
/**
* @param args
*/
public static void main(String[] args) {
int start = 0;
int stop = 0;
int time = 0;
System.out.println("SPM Hello World");
int nrCpu = Runtime.getRuntime().availableProcessors();
if (nrCpu < 3) {
throw new Error("Not enogh CPUs");
}
Runnable sender = new Runnable() {
public void run() {
PrivateScope scope = new PrivateScope(1000);
Runnable r = new Runnable() {
public void run() {
// do nothing at the moment
}
};
scope.enter(r);
}
};
Runnable receiver = new Runnable() {
public void run() {
PrivateScope scope = new PrivateScope(1000);
Runnable r = new Runnable() {
public void run() {
int[] buffer = new int[CNT];
for (int i = 0; i < CNT; ++i) {
buffer[i] = i;
}
finished = true;
}
};
scope.enter(r);
}
};
// ni must be translated from proc index to NoC address!
new RtThread(sender, 1, 1000).setProcessor(1);
new RtThread(receiver, 1, 1000).setProcessor(2);
// start the other CPUs
System.out.println("starting cpus.");
RtThread.startMission();
start = (int) System.currentTimeMillis();
while (!finished) {
;
}
// End of measurement
stop = (int) System.currentTimeMillis();
System.out.println("StartTime: " + start);
System.out.println("StopTime: " + stop);
time = stop - start;
System.out.println("TimeSpent: " + time);
}
use of joprt.RtThread in project jop by jop-devel.
the class BgInit method main.
/**
* Start network and enter forever loop.
*/
public static void main(String[] args) {
Dbg.initSerWait();
Ejip ejip = new Ejip();
//
// start TCP/IP
//
net = new Net(ejip);
net.getUdp().addHandler(Tftp.PORT, new Tftp(ejip));
//
// use second serial line for simulation
// with JopSim and on the project usbser
//
ser = new Serial(Const.IO_UART_BG_MODEM_BASE);
int ip = Ejip.makeIp(192, 168, 1, 2);
ipLink = new Slip(ejip, ser, ip);
//
// start device driver threads
//
new RtThread(5, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
net.run();
}
}
};
// Slip timeout (for windoz slip reply) depends on
// period (=100*period) !
new RtThread(9, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
ipLink.run();
}
}
};
new RtThread(10, 3000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
ser.loop();
}
}
};
new Display(1, 5000);
System.out.println("Bginit");
RtThread.startMission();
Display.write(0, "BG263 Init");
//
// WD thread has lowest priority to see if every timing will be met
//
forever();
}
use of joprt.RtThread in project jop by jop-devel.
the class Demo2 method main.
/**
* @param args
*/
public static void main(String[] args) {
new RtThread(10, 1 * 100) {
public void run() {
up = true;
flag = false;
value = 10;
speed = 0x400;
while (true) {
if (state == STATE_ALL) {
counter++;
if ((counter % value) == 0) {
if (flag) {
flag = false;
} else {
flag = true;
}
}
counter1++;
if ((counter1 % speed) == 0) {
if (speaker_up) {
value++;
if (value >= 50) {
speaker_up = false;
value--;
}
} else {
value--;
if (value <= 10) {
speaker_up = true;
value++;
}
}
}
} else {
flag = false;
}
if (flag) {
Speaker.write(true);
} else
Speaker.write(false);
waitForNextPeriod();
}
}
};
new RtThread(10, 100 * 1000) {
public void run() {
val = LED0;
up = true;
while (true) {
if (state == STATE_ALL) {
if (up) {
switch(val) {
case LED0:
val = LED1;
break;
case LED1:
val = LED2;
break;
case LED2:
val = LED3;
break;
case LED3:
{
up = false;
val = LED2;
break;
}
default:
val = LED0;
break;
}
} else {
switch(val) {
case LED0:
{
up = true;
val = LED1;
break;
}
case LED1:
val = LED0;
break;
case LED2:
val = LED1;
break;
default:
val = LED0;
break;
}
}
} else if (state != STATE_LINEFOLLOWER) {
val = 0;
}
FutureUse.writePins(val);
waitForNextPeriod();
}
}
};
new RtThread(10, 50 * 1000) {
public void run() {
int forwardCount = 0;
System.out.println("Main thread ready.");
MOTORS = new Motor[] { new Motor(0), new Motor(1) };
freeValue = 0;
stop = true;
while (true) {
for (int i = 0; i < 4; i++) if (Buttons.getButton(i)) {
state = i + 1;
//System.out.println(state);
Leds.setLed(1, (i & 1) != 0);
Leds.setLed(2, (i & 2) != 0);
break;
}
stop = !DigitalInputs.getDigitalInput(2);
if ((Buttons.getButtons() != 0) || stop)
freeValue = Sensors.readSensor(IR_SENSOR);
if (stop)
for (int i = 0; i < 2; i++) MOTORS[i].setState(Motor.STATE_OFF);
switch(state) {
case STATE_OFF:
{
for (int i = 0; i < 2; i++) MOTORS[i].setState(Motor.STATE_OFF);
break;
}
case STATE_LINEFOLLOWER:
{
if (!stop) {
int val = Sensors.readSensor(IR_SENSOR);
//System.out.println(val);
// XXX
boolean black = val > 285;
//boolean black = val > freeValue - 5;
MOTORS[MOTOR_LEFT].setDutyCyclePercentage(60);
MOTORS[MOTOR_RIGHT].setDutyCyclePercentage(60);
if (black) {
MOTORS[MOTOR_RIGHT].setState(Motor.STATE_FORWARD);
MOTORS[MOTOR_LEFT].setState(Motor.STATE_BRAKE);
FutureUse.writePins(LED0 | LED3);
} else {
MOTORS[MOTOR_LEFT].setState(Motor.STATE_FORWARD);
MOTORS[MOTOR_RIGHT].setState(Motor.STATE_BRAKE);
FutureUse.writePins(LED1 | LED2);
}
}
break;
}
case STATE_TOUCHSENSOR:
case STATE_IRSENSOR:
case STATE_ALL:
{
if (!stop) {
for (int i = 0; i < 2; i++) MOTORS[i].setMotorPercentage(Motor.STATE_FORWARD, true, 40);
int totalDifference = Sensors.readSensor(IR_SENSOR) - freeValue;
if (forwardCount >= 60) {
if (MOTORS[0].readNormalizedBackEMF()[1] <= 5) {
Leds.setLeds(0x9);
turnback(false);
}
}
if (((state == STATE_IRSENSOR) || (state == STATE_ALL)) && (Math.abs(totalDifference) >= IR_SENSOR_THRESHOLD)) {
turnback(true);
} else if ((state == STATE_TOUCHSENSOR || state == STATE_ALL) && (forwardCount >= 6) && (DigitalInputs.getDigitalInput(1))) {
turnback(false);
}
}
break;
}
}
{
boolean goingForward = false;
for (int i = 0; i < 2; i++) {
if (MOTORS[i].getState() == Motor.STATE_FORWARD) {
goingForward = true;
break;
}
}
forwardCount = goingForward ? forwardCount + 1 : 0;
}
waitForNextPeriod();
}
}
void turnback(boolean fast) {
int turnspeed, turnsleep;
boolean dirLeft = false;
if (fast) {
turnspeed = 80;
turnsleep = 300;
} else {
turnspeed = 70;
turnsleep = 400;
}
speed = !fast ? 0x400 : 0x50;
dirLeft = (Native.rd(Const.IO_US_CNT) & 1) != 0;
for (int i = 0; i < 2; i++) MOTORS[i].setMotorPercentage(Motor.STATE_BACKWARD, false, 100);
RtThread.sleepMs(100);
for (int i = 0; i < 2; i++) MOTORS[i].setMotorPercentage(Motor.STATE_BACKWARD, false, turnspeed);
RtThread.sleepMs(turnsleep - 100);
MOTORS[dirLeft ? MOTOR_LEFT : MOTOR_RIGHT].setMotorPercentage(Motor.STATE_BACKWARD, false, 70);
MOTORS[dirLeft ? MOTOR_RIGHT : MOTOR_LEFT].setState(Motor.STATE_OFF);
RtThread.sleepMs(600);
speed = 0x400;
Leds.setLed(0, false);
Leds.setLed(3, false);
}
};
RtThread.startMission();
}
use of joprt.RtThread in project jop by jop-devel.
the class Sms method main.
/**
* Test main.
*/
public static void main(String[] args) {
// that's the UDP version
Dbg.init();
init();
ser = new Serial(Const.IO_UART1_BASE);
new RtThread(1, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
ser.loop();
}
}
};
//
// start TCP/IP
//
Ejip ejip = new Ejip();
net = new Net(ejip);
// don't use CS8900 when simulating on PC or for BG263
int[] eth = { 0x00, 0xe0, 0x98, 0x33, 0xb0, 0xf8 };
int ip = Ejip.makeIp(192, 168, 0, 123);
ipLink = new CS8900(ejip, eth, ip);
//
// start device driver threads
//
new RtThread(5, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
net.run();
}
}
};
new RtThread(5, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
ipLink.run();
}
}
};
RtThread.startMission();
int i, j;
int[] text = { 'H', 'e', 'l', 'l', 'o', ' ', 'f', 'r', 'o', 'm', ' ', 'J', 'O', 'P', '!' };
int[] nr = { '4', '3', '6', '9', '9', '1', '9', '5', '2', '0', '2', '2', '0' };
int[] gotNr = new int[Sms.NR_MAX];
int gotNrType;
int timer = Timer.getTimeoutMs(1000);
int sec = 0;
boolean doit = true;
for (; ; ) {
loop();
if (Timer.timeout(timer)) {
timer = Timer.getTimeoutMs(1000);
++sec;
}
if (state == READY && doit) {
Dbg.wr("ready to send");
// 0x91 for intl. numbers (43...)
Sms.send(text, nr, 0x91);
doit = false;
}
if (gotSms) {
// tim();
Dbg.wr("got SMS:");
for (i = 0; i < rcvTxt.length; ++i) {
j = rcvTxt[i];
if (j == 0)
break;
Dbg.wr((char) j);
}
Dbg.lf();
Dbg.wr("from ");
for (i = 0; i < rcvNr.length; ++i) {
j = rcvNr[i];
if (j == 0)
break;
Dbg.wr((char) j);
}
Dbg.wr(" type: " + Sms.rcvNrType);
Dbg.lf();
Sms.strcpy(gotNr, Sms.rcvNr);
gotNrType = Sms.rcvNrType;
if (Sms.isFree()) {
Dbg.wr("send replay");
Dbg.lf();
Sms.send(text, gotNr, gotNrType);
} else {
Dbg.wr("send buffer full!");
Dbg.lf();
}
Sms.gotSms = false;
}
}
}
use of joprt.RtThread in project jop by jop-devel.
the class Lift method main.
/**
* Start all threads and enter forever loop.
*/
public static void main(String[] args) {
// we provide a null pointer in Startup.java for JOP
simpc = args != null;
evn = true;
run = true;
// will be UDP...
if (simpc) {
Dbg.initSer();
} else {
Dbg.init();
}
//
// start TCP/IP
//
Ejip ejip = new Ejip();
net = new Net(ejip);
int[] outReg = new int[1];
outReg[0] = 0;
HtmlBaseio http = new HtmlBaseio();
// register the simple HTTP server
net.getTcp().addHandler(80, http);
http.setOutValArray(outReg);
// don't use CS8900 when simulating on PC
if (!simpc) {
int[] eth = { 0x00, 0xe0, 0x98, 0x33, 0xb0, 0xf8 };
int ip = Ejip.makeIp(192, 168, 0, 123);
ipLink = new CS8900(ejip, eth, ip);
// use instead Slip for PC simulation
// LinkLayer ipLink = Slip.init(Const.IO_UART_BG_MODEM_BASE,
// (192<<24) + (168<<16) + (1<<8) + 2);
new RtThread(5, 10000) {
public void run() {
for (; ; ) {
waitForNextPeriod();
net.run();
ipLink.run();
}
}
};
}
/* there is some problem with the ACEX board and paramter in Flash ???
par = new Param();
fwp = new Fwp();
Serial ser;
if (simpc) {
ser = new Serial(Const.IO_UART_BG_MODEM_BASE, 10, 3000);
} else {
ser = new Serial(Const.IO_UART1_BASE, 10, 3000);
}
if (evn) {
modem = Modem.getInstance(5, 100000, ser);
} else {
new Modbus(5, 10000, ser, outReg);
}
loop = new Loop(7, 20000);
*/
ctrl = new LiftControl();
RtThread.startMission();
forever();
}
Aggregations