Merge pull request #1661 from yatch/pr-tsch-cooja-mote
TSCH on Cooja mote
This commit is contained in:
commit
ecd1d57eec
17 changed files with 514 additions and 104 deletions
|
@ -52,8 +52,11 @@ import org.contikios.cooja.mote.memory.VarMemory;
|
|||
* Contiki variables:
|
||||
* <ul>
|
||||
* <li>clock_time_t simCurrentTime
|
||||
* <li>clock_time_t simNextExpirationTime
|
||||
* <li>int simProcessRunValue
|
||||
* <li>rtimer_clock_t simRtimerCurrentTicks
|
||||
* <li>clock_time_t simEtimerNextExpirationTime
|
||||
* <li>rtimer_clock_t simEtimerNextExpirationTime
|
||||
* <li>int simEtimerProcessRunValue
|
||||
* <li>int simRtimerProcessRunValue
|
||||
* <li>int simEtimerPending
|
||||
* </ul>
|
||||
*
|
||||
|
@ -125,16 +128,24 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
|||
|
||||
public void doActionsBeforeTick() {
|
||||
/* Update time */
|
||||
setTime(mote.getSimulation().getSimulationTime() + timeDrift);
|
||||
long currentSimulationTime = simulation.getSimulationTime();
|
||||
setTime(currentSimulationTime + timeDrift);
|
||||
moteMem.setInt64ValueOf("simRtimerCurrentTicks", currentSimulationTime);
|
||||
}
|
||||
|
||||
public void doActionsAfterTick() {
|
||||
long currentSimulationTime = mote.getSimulation().getSimulationTime();
|
||||
|
||||
/* Always schedule for Rtimer if anything pending */
|
||||
if (moteMem.getIntValueOf("simRtimerPending") != 0) {
|
||||
mote.scheduleNextWakeup(moteMem.getInt64ValueOf("simRtimerNextExpirationTime"));
|
||||
}
|
||||
|
||||
/* Request next tick for remaining events / timers */
|
||||
int processRunValue = moteMem.getIntValueOf("simProcessRunValue");
|
||||
if (processRunValue != 0) {
|
||||
/* Handle next Contiki event in one millisecond */
|
||||
mote.scheduleNextWakeup(simulation.getSimulationTime() + Simulation.MILLISECOND);
|
||||
mote.scheduleNextWakeup(currentSimulationTime + Simulation.MILLISECOND);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -144,15 +155,20 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
|||
return;
|
||||
}
|
||||
|
||||
/* Request tick next wakeup time */
|
||||
int nextExpirationTime = moteMem.getIntValueOf("simNextExpirationTime");
|
||||
if (nextExpirationTime <= 0) {
|
||||
/*logger.warn("Event timer already expired, but has been delayed: " + nextExpirationTime);*/
|
||||
mote.scheduleNextWakeup(simulation.getSimulationTime() + Simulation.MILLISECOND);
|
||||
return;
|
||||
/* Request tick next wakeup time for Etimer */
|
||||
long etimerNextExpirationTime = (long)moteMem.getInt32ValueOf("simEtimerNextExpirationTime") * Simulation.MILLISECOND;
|
||||
long etimerTimeToNextExpiration = etimerNextExpirationTime - moteTime;
|
||||
if (etimerTimeToNextExpiration <= 0) {
|
||||
/* logger.warn(mote.getID() + ": Event timer already expired, but has been delayed: " + etimerTimeToNextExpiration); */
|
||||
/* Wake up in one millisecond to handle a missed Etimer task
|
||||
* which may be blocked by busy waiting such as one in
|
||||
* radio_send(). Scheduling it in a shorter time than one
|
||||
* millisecond, e.g., one microsecond, seems to be worthless and
|
||||
* it would cause unnecessary CPU usage. */
|
||||
mote.scheduleNextWakeup(currentSimulationTime + Simulation.MILLISECOND);
|
||||
} else {
|
||||
mote.scheduleNextWakeup(currentSimulationTime + etimerTimeToNextExpiration);
|
||||
}
|
||||
|
||||
mote.scheduleNextWakeup(simulation.getSimulationTime() + Simulation.MILLISECOND*nextExpirationTime);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.contikios.cooja.util.CCITT_CRC;
|
|||
* <p>
|
||||
* <li>int simInSize (size of received data packet)
|
||||
* <li>byte[] simInDataBuffer (data of received data packet)
|
||||
* <li>int64_t simLastPacketTimestamp (timestamp of the last received data packet)
|
||||
* <p>
|
||||
* <li>int simOutSize (size of transmitted data packet)
|
||||
* <li>byte[] simOutDataBuffer (data of transmitted data packet)
|
||||
|
@ -190,6 +191,8 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
|
|||
lastEventTime = mote.getSimulation().getSimulationTime();
|
||||
lastEvent = RadioEvent.RECEPTION_STARTED;
|
||||
|
||||
myMoteMemory.setInt64ValueOf("simLastPacketTimestamp", lastEventTime);
|
||||
|
||||
this.setChanged();
|
||||
this.notifyObservers();
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ public class VarMemory extends Memory {
|
|||
* @param varName Variable name
|
||||
* @param value 16 bit integer value to write
|
||||
*/
|
||||
public void setInt16ValueOf(String varName, byte value)
|
||||
public void setInt16ValueOf(String varName, short value)
|
||||
throws UnknownVariableException {
|
||||
setInt16ValueOf(getVariable(varName).addr, value);
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public class VarMemory extends Memory {
|
|||
* @param varName Variable name
|
||||
* @param value 32 bit integer value to write
|
||||
*/
|
||||
public void setInt32ValueOf(String varName, byte value)
|
||||
public void setInt32ValueOf(String varName, int value)
|
||||
throws UnknownVariableException {
|
||||
setInt32ValueOf(getVariable(varName).addr, value);
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ public class VarMemory extends Memory {
|
|||
* @param varName Variable name
|
||||
* @param value 64 bit integer value to write
|
||||
*/
|
||||
public void setInt64ValueOf(String varName, byte value)
|
||||
public void setInt64ValueOf(String varName, long value)
|
||||
throws UnknownVariableException {
|
||||
setInt64ValueOf(getVariable(varName).addr, value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue