Merge pull request #1661 from yatch/pr-tsch-cooja-mote
TSCH on Cooja mote
This commit is contained in:
commit
ecd1d57eec
|
@ -46,10 +46,10 @@
|
||||||
#include "net/rime/rimestats.h"
|
#include "net/rime/rimestats.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if CONTIKI_TARGET_COOJA
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
#include "lib/simEnvChange.h"
|
#include "lib/simEnvChange.h"
|
||||||
#include "sys/cooja_mt.h"
|
#include "sys/cooja_mt.h"
|
||||||
#endif /* CONTIKI_TARGET_COOJA */
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -158,10 +158,10 @@ send_one_packet(mac_callback_t sent, void *ptr)
|
||||||
wt = RTIMER_NOW();
|
wt = RTIMER_NOW();
|
||||||
watchdog_periodic();
|
watchdog_periodic();
|
||||||
while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + ACK_WAIT_TIME)) {
|
while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + ACK_WAIT_TIME)) {
|
||||||
#if CONTIKI_TARGET_COOJA
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
simProcessRunValue = 1;
|
simProcessRunValue = 1;
|
||||||
cooja_mt_yield();
|
cooja_mt_yield();
|
||||||
#endif /* CONTIKI_TARGET_COOJA */
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MAC_TX_NOACK;
|
ret = MAC_TX_NOACK;
|
||||||
|
@ -176,10 +176,10 @@ send_one_packet(mac_callback_t sent, void *ptr)
|
||||||
watchdog_periodic();
|
watchdog_periodic();
|
||||||
while(RTIMER_CLOCK_LT(RTIMER_NOW(),
|
while(RTIMER_CLOCK_LT(RTIMER_NOW(),
|
||||||
wt + AFTER_ACK_DETECTED_WAIT_TIME)) {
|
wt + AFTER_ACK_DETECTED_WAIT_TIME)) {
|
||||||
#if CONTIKI_TARGET_COOJA
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
simProcessRunValue = 1;
|
simProcessRunValue = 1;
|
||||||
cooja_mt_yield();
|
cooja_mt_yield();
|
||||||
#endif /* CONTIKI_TARGET_COOJA */
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +195,8 @@ send_one_packet(mac_callback_t sent, void *ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PRINTF("nullrdc tx noack\n");
|
PRINTF("nullrdc tx noack\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RADIO_TX_COLLISION:
|
case RADIO_TX_COLLISION:
|
||||||
|
|
|
@ -48,6 +48,10 @@
|
||||||
#include "net/linkaddr.h"
|
#include "net/linkaddr.h"
|
||||||
#include "net/mac/tsch/tsch-asn.h"
|
#include "net/mac/tsch/tsch-asn.h"
|
||||||
#include "net/mac/tsch/tsch-conf.h"
|
#include "net/mac/tsch/tsch-conf.h"
|
||||||
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
|
#include "lib/simEnvChange.h"
|
||||||
|
#include "sys/cooja_mt.h"
|
||||||
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
|
|
||||||
/************ Types ***********/
|
/************ Types ***********/
|
||||||
|
|
||||||
|
@ -109,7 +113,14 @@ void tsch_disassociate(void);
|
||||||
#define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length)
|
#define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length)
|
||||||
|
|
||||||
/* Wait for a condition with timeout t0+offset. */
|
/* Wait for a condition with timeout t0+offset. */
|
||||||
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
|
#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \
|
||||||
|
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) { \
|
||||||
|
simProcessRunValue = 1; \
|
||||||
|
cooja_mt_yield(); \
|
||||||
|
};
|
||||||
|
#else
|
||||||
#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \
|
#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \
|
||||||
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ;
|
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ;
|
||||||
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
#endif /* __TSCH_PRIVATE_H__ */
|
#endif /* __TSCH_PRIVATE_H__ */
|
||||||
|
|
|
@ -54,6 +54,10 @@
|
||||||
#include "net/mac/tsch/tsch-packet.h"
|
#include "net/mac/tsch/tsch-packet.h"
|
||||||
#include "net/mac/tsch/tsch-security.h"
|
#include "net/mac/tsch/tsch-security.h"
|
||||||
#include "net/mac/tsch/tsch-adaptive-timesync.h"
|
#include "net/mac/tsch/tsch-adaptive-timesync.h"
|
||||||
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
|
#include "lib/simEnvChange.h"
|
||||||
|
#include "sys/cooja_mt.h"
|
||||||
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
|
|
||||||
#if TSCH_LOG_LEVEL >= 1
|
#if TSCH_LOG_LEVEL >= 1
|
||||||
#define DEBUG DEBUG_PRINT
|
#define DEBUG DEBUG_PRINT
|
||||||
|
@ -104,7 +108,10 @@
|
||||||
#if RTIMER_SECOND < (32 * 1024)
|
#if RTIMER_SECOND < (32 * 1024)
|
||||||
#error "TSCH: RTIMER_SECOND < (32 * 1024)"
|
#error "TSCH: RTIMER_SECOND < (32 * 1024)"
|
||||||
#endif
|
#endif
|
||||||
#if RTIMER_SECOND >= 200000
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
|
/* Use 0 usec guard time for Cooja Mote with a 1 MHz Rtimer*/
|
||||||
|
#define RTIMER_GUARD 0u
|
||||||
|
#elif RTIMER_SECOND >= 200000
|
||||||
#define RTIMER_GUARD (RTIMER_SECOND / 100000)
|
#define RTIMER_GUARD (RTIMER_SECOND / 100000)
|
||||||
#else
|
#else
|
||||||
#define RTIMER_GUARD 2u
|
#define RTIMER_GUARD 2u
|
||||||
|
@ -200,7 +207,12 @@ tsch_get_lock(void)
|
||||||
if(tsch_in_slot_operation) {
|
if(tsch_in_slot_operation) {
|
||||||
busy_wait = 1;
|
busy_wait = 1;
|
||||||
busy_wait_time = RTIMER_NOW();
|
busy_wait_time = RTIMER_NOW();
|
||||||
while(tsch_in_slot_operation);
|
while(tsch_in_slot_operation) {
|
||||||
|
#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64
|
||||||
|
simProcessRunValue = 1;
|
||||||
|
cooja_mt_yield();
|
||||||
|
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
|
||||||
|
}
|
||||||
busy_wait_time = RTIMER_NOW() - busy_wait_time;
|
busy_wait_time = RTIMER_NOW() - busy_wait_time;
|
||||||
}
|
}
|
||||||
if(!tsch_locked) {
|
if(!tsch_locked) {
|
||||||
|
|
|
@ -181,4 +181,8 @@
|
||||||
#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \
|
#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \
|
||||||
|| CONTIKI_TARGET_OPENMOTE_CC2538 */
|
|| CONTIKI_TARGET_OPENMOTE_CC2538 */
|
||||||
|
|
||||||
|
#if CONTIKI_TARGET_COOJA
|
||||||
|
#define COOJA_CONF_SIMULATE_TURNAROUND 0
|
||||||
|
#endif /* CONTIKI_TARGET_COOJA */
|
||||||
|
|
||||||
#endif /* __PROJECT_CONF_H__ */
|
#endif /* __PROJECT_CONF_H__ */
|
||||||
|
|
279
examples/ipv6/rpl-tsch/rpl-tsch-cooja.csc
Normal file
279
examples/ipv6/rpl-tsch/rpl-tsch-cooja.csc
Normal file
|
@ -0,0 +1,279 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<simconf>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/mrm</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/mspsim</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/avrora</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/serial_socket</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/collect-view</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/powertracker</project>
|
||||||
|
<project EXPORT="discard">[APPS_DIR]/radiologger-headless</project>
|
||||||
|
<simulation>
|
||||||
|
<title>RPL+TSCH</title>
|
||||||
|
<randomseed>123456</randomseed>
|
||||||
|
<motedelay_us>1000000</motedelay_us>
|
||||||
|
<radiomedium>
|
||||||
|
org.contikios.cooja.radiomediums.UDGM
|
||||||
|
<transmitting_range>50.0</transmitting_range>
|
||||||
|
<interference_range>100.0</interference_range>
|
||||||
|
<success_ratio_tx>1.0</success_ratio_tx>
|
||||||
|
<success_ratio_rx>1.0</success_ratio_rx>
|
||||||
|
</radiomedium>
|
||||||
|
<events>
|
||||||
|
<logoutput>40000</logoutput>
|
||||||
|
</events>
|
||||||
|
<motetype>
|
||||||
|
org.contikios.cooja.contikimote.ContikiMoteType
|
||||||
|
<identifier>mtype660</identifier>
|
||||||
|
<description>Cooja Mote Type #z11</description>
|
||||||
|
<source>[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
|
||||||
|
<commands>make TARGET=cooja clean
|
||||||
|
make TARGET=cooja node.cooja</commands>
|
||||||
|
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiIPAddress</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiButton</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiClock</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiLED</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||||
|
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||||
|
<symbols>false</symbols>
|
||||||
|
</motetype>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>-1.285769821276336</x>
|
||||||
|
<y>38.58045647334346</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>1</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>-19.324109516886306</x>
|
||||||
|
<y>76.23135780254927</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>2</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>5.815501305791592</x>
|
||||||
|
<y>76.77463755494317</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>3</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>31.920697784030082</x>
|
||||||
|
<y>50.5212265977149</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>4</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>47.21747673247198</x>
|
||||||
|
<y>30.217765340599726</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>5</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>10.622284947035123</x>
|
||||||
|
<y>109.81862399725188</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>6</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>52.41150716335335</x>
|
||||||
|
<y>109.93228340481916</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>7</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>70.18727461718498</x>
|
||||||
|
<y>70.06861701541145</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>8</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
<mote>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.interfaces.Position
|
||||||
|
<x>80.29870484201041</x>
|
||||||
|
<y>99.37351603835938</y>
|
||||||
|
<z>0.0</z>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
|
||||||
|
<id>9</id>
|
||||||
|
</interface_config>
|
||||||
|
<interface_config>
|
||||||
|
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||||
|
<bitrate>250.0</bitrate>
|
||||||
|
</interface_config>
|
||||||
|
<motetype_identifier>mtype660</motetype_identifier>
|
||||||
|
</mote>
|
||||||
|
</simulation>
|
||||||
|
<plugin>
|
||||||
|
org.contikios.cooja.plugins.SimControl
|
||||||
|
<width>242</width>
|
||||||
|
<z>4</z>
|
||||||
|
<height>160</height>
|
||||||
|
<location_x>11</location_x>
|
||||||
|
<location_y>241</location_y>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
org.contikios.cooja.plugins.Visualizer
|
||||||
|
<plugin_config>
|
||||||
|
<moterelations>true</moterelations>
|
||||||
|
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||||
|
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||||
|
<skin>org.contikios.cooja.plugins.skins.TrafficVisualizerSkin</skin>
|
||||||
|
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||||
|
<viewport>1.7405603810040515 0.0 0.0 1.7405603810040515 47.95980153208088 -42.576134155447555</viewport>
|
||||||
|
</plugin_config>
|
||||||
|
<width>236</width>
|
||||||
|
<z>3</z>
|
||||||
|
<height>230</height>
|
||||||
|
<location_x>1</location_x>
|
||||||
|
<location_y>1</location_y>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
org.contikios.cooja.plugins.LogListener
|
||||||
|
<plugin_config>
|
||||||
|
<filter />
|
||||||
|
<formatted_time />
|
||||||
|
<coloring />
|
||||||
|
</plugin_config>
|
||||||
|
<width>1031</width>
|
||||||
|
<z>0</z>
|
||||||
|
<height>394</height>
|
||||||
|
<location_x>273</location_x>
|
||||||
|
<location_y>6</location_y>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
org.contikios.cooja.plugins.TimeLine
|
||||||
|
<plugin_config>
|
||||||
|
<mote>0</mote>
|
||||||
|
<mote>1</mote>
|
||||||
|
<mote>2</mote>
|
||||||
|
<mote>3</mote>
|
||||||
|
<mote>4</mote>
|
||||||
|
<mote>5</mote>
|
||||||
|
<mote>6</mote>
|
||||||
|
<mote>7</mote>
|
||||||
|
<mote>8</mote>
|
||||||
|
<showRadioRXTX />
|
||||||
|
<showRadioHW />
|
||||||
|
<showLEDs />
|
||||||
|
<zoomfactor>16529.88882215865</zoomfactor>
|
||||||
|
</plugin_config>
|
||||||
|
<width>1304</width>
|
||||||
|
<z>2</z>
|
||||||
|
<height>311</height>
|
||||||
|
<location_x>0</location_x>
|
||||||
|
<location_y>412</location_y>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
org.contikios.cooja.plugins.RadioLogger
|
||||||
|
<plugin_config>
|
||||||
|
<split>150</split>
|
||||||
|
<formatted_time />
|
||||||
|
<showdups>false</showdups>
|
||||||
|
<hidenodests>false</hidenodests>
|
||||||
|
<analyzers name="6lowpan-pcap" />
|
||||||
|
</plugin_config>
|
||||||
|
<width>500</width>
|
||||||
|
<z>1</z>
|
||||||
|
<height>300</height>
|
||||||
|
<location_x>30</location_x>
|
||||||
|
<location_y>442</location_y>
|
||||||
|
</plugin>
|
||||||
|
</simconf>
|
||||||
|
|
|
@ -376,9 +376,6 @@ Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory(JNIEnv *env, jobject obj,
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
clock_time_t nextEtimer;
|
|
||||||
rtimer_clock_t nextRtimer;
|
|
||||||
|
|
||||||
simProcessRunValue = 0;
|
simProcessRunValue = 0;
|
||||||
|
|
||||||
/* Let all simulation interfaces act first */
|
/* Let all simulation interfaces act first */
|
||||||
|
@ -403,21 +400,11 @@ Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
||||||
doActionsAfterTick();
|
doActionsAfterTick();
|
||||||
|
|
||||||
/* Do we have any pending timers */
|
/* Do we have any pending timers */
|
||||||
simEtimerPending = etimer_pending() || rtimer_arch_pending();
|
simEtimerPending = etimer_pending();
|
||||||
if(!simEtimerPending) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save nearest expiration time */
|
/* Save nearest expiration time */
|
||||||
nextEtimer = etimer_next_expiration_time() - (clock_time_t) simCurrentTime;
|
simEtimerNextExpirationTime = etimer_next_expiration_time();
|
||||||
nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
|
|
||||||
if(etimer_pending() && rtimer_arch_pending()) {
|
|
||||||
simNextExpirationTime = MIN(nextEtimer, nextRtimer);
|
|
||||||
} else if(etimer_pending()) {
|
|
||||||
simNextExpirationTime = nextEtimer;
|
|
||||||
} else if(rtimer_arch_pending()) {
|
|
||||||
simNextExpirationTime = nextRtimer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -200,8 +200,12 @@ typedef unsigned short uip_stats_t;
|
||||||
|
|
||||||
#define CLOCK_CONF_SECOND 1000L
|
#define CLOCK_CONF_SECOND 1000L
|
||||||
typedef unsigned long clock_time_t;
|
typedef unsigned long clock_time_t;
|
||||||
typedef unsigned long rtimer_clock_t;
|
typedef uint64_t rtimer_clock_t;
|
||||||
#define RTIMER_CLOCK_DIFF(a,b) ((signed long)((a)-(b)))
|
#define RTIMER_CLOCK_DIFF(a,b) ((int64_t)((a)-(b)))
|
||||||
|
|
||||||
|
#define RADIO_DELAY_BEFORE_TX 0
|
||||||
|
#define RADIO_DELAY_BEFORE_RX 0
|
||||||
|
#define RADIO_DELAY_BEFORE_DETECT 0
|
||||||
|
|
||||||
#define AODV_COMPLIANCE
|
#define AODV_COMPLIANCE
|
||||||
#define AODV_NUM_RT_ENTRIES 32
|
#define AODV_NUM_RT_ENTRIES 32
|
||||||
|
|
|
@ -452,9 +452,6 @@ Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory(JNIEnv *env, jobject obj,
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
clock_time_t nextEtimer;
|
|
||||||
rtimer_clock_t nextRtimer;
|
|
||||||
|
|
||||||
simProcessRunValue = 0;
|
simProcessRunValue = 0;
|
||||||
|
|
||||||
/* Let all simulation interfaces act first */
|
/* Let all simulation interfaces act first */
|
||||||
|
@ -479,21 +476,11 @@ Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
|
||||||
doActionsAfterTick();
|
doActionsAfterTick();
|
||||||
|
|
||||||
/* Do we have any pending timers */
|
/* Do we have any pending timers */
|
||||||
simEtimerPending = etimer_pending() || rtimer_arch_pending();
|
simEtimerPending = etimer_pending();
|
||||||
if(!simEtimerPending) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save nearest expiration time */
|
/* Save nearest expiration time */
|
||||||
nextEtimer = etimer_next_expiration_time() - (clock_time_t) simCurrentTime;
|
simEtimerNextExpirationTime = etimer_next_expiration_time();
|
||||||
nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
|
|
||||||
if(etimer_pending() && rtimer_arch_pending()) {
|
|
||||||
simNextExpirationTime = MIN(nextEtimer, nextRtimer);
|
|
||||||
} else if(etimer_pending()) {
|
|
||||||
simNextExpirationTime = nextEtimer;
|
|
||||||
} else if(rtimer_arch_pending()) {
|
|
||||||
simNextExpirationTime = nextRtimer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,15 +46,13 @@
|
||||||
#define COOJA_RADIO_BUFSIZE PACKETBUF_SIZE
|
#define COOJA_RADIO_BUFSIZE PACKETBUF_SIZE
|
||||||
#define CCA_SS_THRESHOLD -95
|
#define CCA_SS_THRESHOLD -95
|
||||||
|
|
||||||
#define WITH_TURNAROUND 1
|
|
||||||
#define WITH_SEND_CCA 1
|
|
||||||
|
|
||||||
const struct simInterface radio_interface;
|
const struct simInterface radio_interface;
|
||||||
|
|
||||||
/* COOJA */
|
/* COOJA */
|
||||||
char simReceiving = 0;
|
char simReceiving = 0;
|
||||||
char simInDataBuffer[COOJA_RADIO_BUFSIZE];
|
char simInDataBuffer[COOJA_RADIO_BUFSIZE];
|
||||||
int simInSize = 0;
|
int simInSize = 0;
|
||||||
|
rtimer_clock_t simLastPacketTimestamp = 0;
|
||||||
char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
|
char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
|
||||||
int simOutSize = 0;
|
int simOutSize = 0;
|
||||||
char simRadioHWOn = 1;
|
char simRadioHWOn = 1;
|
||||||
|
@ -66,8 +64,37 @@ int simLQI = 105;
|
||||||
|
|
||||||
static const void *pending_data;
|
static const void *pending_data;
|
||||||
|
|
||||||
PROCESS(cooja_radio_process, "cooja radio process");
|
/* If we are in the polling mode, poll_mode is 1; otherwise 0 */
|
||||||
|
static int poll_mode = 0; /* default 0, disabled */
|
||||||
|
static int auto_ack = 0; /* AUTO_ACK is not supported; always 0 */
|
||||||
|
static int addr_filter = 0; /* ADDRESS_FILTER is not supported; always 0 */
|
||||||
|
static int send_on_cca = (COOJA_TRANSMIT_ON_CCA != 0);
|
||||||
|
|
||||||
|
PROCESS(cooja_radio_process, "cooja radio process");
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
set_send_on_cca(uint8_t enable)
|
||||||
|
{
|
||||||
|
send_on_cca = enable;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
set_frame_filtering(int enable)
|
||||||
|
{
|
||||||
|
addr_filter = enable;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
set_auto_ack(int enable)
|
||||||
|
{
|
||||||
|
auto_ack = enable;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
set_poll_mode(int enable)
|
||||||
|
{
|
||||||
|
poll_mode = enable;
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
radio_set_channel(int channel)
|
radio_set_channel(int channel)
|
||||||
|
@ -97,7 +124,7 @@ radio_signal_strength_current(void)
|
||||||
int
|
int
|
||||||
radio_LQI(void)
|
radio_LQI(void)
|
||||||
{
|
{
|
||||||
return simLQI;
|
return simLQI;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
|
@ -152,8 +179,10 @@ radio_read(void *buf, unsigned short bufsize)
|
||||||
|
|
||||||
memcpy(buf, simInDataBuffer, simInSize);
|
memcpy(buf, simInDataBuffer, simInSize);
|
||||||
simInSize = 0;
|
simInSize = 0;
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, simSignalStrength);
|
if(!poll_mode) {
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, simLQI);
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, simSignalStrength);
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, simLQI);
|
||||||
|
}
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -173,14 +202,14 @@ radio_send(const void *payload, unsigned short payload_len)
|
||||||
int radiostate = simRadioHWOn;
|
int radiostate = simRadioHWOn;
|
||||||
|
|
||||||
/* Simulate turnaround time of 2ms for packets, 1ms for acks*/
|
/* Simulate turnaround time of 2ms for packets, 1ms for acks*/
|
||||||
#if WITH_TURNAROUND
|
#if COOJA_SIMULATE_TURNAROUND
|
||||||
simProcessRunValue = 1;
|
simProcessRunValue = 1;
|
||||||
cooja_mt_yield();
|
cooja_mt_yield();
|
||||||
if(payload_len > 3) {
|
if(payload_len > 3) {
|
||||||
simProcessRunValue = 1;
|
simProcessRunValue = 1;
|
||||||
cooja_mt_yield();
|
cooja_mt_yield();
|
||||||
}
|
}
|
||||||
#endif /* WITH_TURNAROUND */
|
#endif /* COOJA_SIMULATE_TURNAROUND */
|
||||||
|
|
||||||
if(!simRadioHWOn) {
|
if(!simRadioHWOn) {
|
||||||
/* Turn on radio temporarily */
|
/* Turn on radio temporarily */
|
||||||
|
@ -197,11 +226,11 @@ radio_send(const void *payload, unsigned short payload_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transmit on CCA */
|
/* Transmit on CCA */
|
||||||
#if WITH_SEND_CCA
|
#if COOJA_TRANSMIT_ON_CCA
|
||||||
if(!channel_clear()) {
|
if(send_on_cca && !channel_clear()) {
|
||||||
return RADIO_TX_COLLISION;
|
return RADIO_TX_COLLISION;
|
||||||
}
|
}
|
||||||
#endif /* WITH_SEND_CCA */
|
#endif /* COOJA_TRANSMIT_ON_CCA */
|
||||||
|
|
||||||
/* Copy packet data to temporary storage */
|
/* Copy packet data to temporary storage */
|
||||||
memcpy(simOutDataBuffer, payload, payload_len);
|
memcpy(simOutDataBuffer, payload, payload_len);
|
||||||
|
@ -253,6 +282,9 @@ PROCESS_THREAD(cooja_radio_process, ev, data)
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||||
|
if(poll_mode) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
packetbuf_clear();
|
packetbuf_clear();
|
||||||
len = radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
len = radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
||||||
|
@ -275,18 +307,87 @@ init(void)
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
get_value(radio_param_t param, radio_value_t *value)
|
get_value(radio_param_t param, radio_value_t *value)
|
||||||
{
|
{
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
switch(param) {
|
||||||
|
case RADIO_PARAM_RX_MODE:
|
||||||
|
*value = 0;
|
||||||
|
if(addr_filter) {
|
||||||
|
*value |= RADIO_RX_MODE_ADDRESS_FILTER;
|
||||||
|
}
|
||||||
|
if(auto_ack) {
|
||||||
|
*value |= RADIO_RX_MODE_AUTOACK;
|
||||||
|
}
|
||||||
|
if(poll_mode) {
|
||||||
|
*value |= RADIO_RX_MODE_POLL_MODE;
|
||||||
|
}
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
case RADIO_PARAM_TX_MODE:
|
||||||
|
*value = 0;
|
||||||
|
if(send_on_cca) {
|
||||||
|
*value |= RADIO_TX_MODE_SEND_ON_CCA;
|
||||||
|
}
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
case RADIO_PARAM_LAST_RSSI:
|
||||||
|
*value = simSignalStrength;
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
case RADIO_PARAM_LAST_LINK_QUALITY:
|
||||||
|
*value = simLQI;
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
default:
|
||||||
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
set_value(radio_param_t param, radio_value_t value)
|
set_value(radio_param_t param, radio_value_t value)
|
||||||
{
|
{
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
switch(param) {
|
||||||
|
case RADIO_PARAM_RX_MODE:
|
||||||
|
if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
|
||||||
|
RADIO_RX_MODE_AUTOACK | RADIO_RX_MODE_POLL_MODE)) {
|
||||||
|
return RADIO_RESULT_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only disabling is acceptable for RADIO_RX_MODE_ADDRESS_FILTER */
|
||||||
|
if ((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0) {
|
||||||
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
|
||||||
|
|
||||||
|
/* Only disabling is acceptable for RADIO_RX_MODE_AUTOACK */
|
||||||
|
if ((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0) {
|
||||||
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
set_auto_ack((value & RADIO_RX_MODE_AUTOACK) != 0);
|
||||||
|
|
||||||
|
set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
case RADIO_PARAM_TX_MODE:
|
||||||
|
if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
|
||||||
|
return RADIO_RESULT_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
case RADIO_PARAM_CHANNEL:
|
||||||
|
if(value < 11 || value > 26) {
|
||||||
|
return RADIO_RESULT_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
radio_set_channel(value);
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
default:
|
||||||
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
get_object(radio_param_t param, void *dest, size_t size)
|
get_object(radio_param_t param, void *dest, size_t size)
|
||||||
{
|
{
|
||||||
|
if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) {
|
||||||
|
if(size != sizeof(rtimer_clock_t) || !dest) {
|
||||||
|
return RADIO_RESULT_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
*(rtimer_clock_t *)dest = (rtimer_clock_t)simLastPacketTimestamp;
|
||||||
|
return RADIO_RESULT_OK;
|
||||||
|
}
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -315,5 +416,5 @@ const struct radio_driver cooja_radio_driver =
|
||||||
};
|
};
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SIM_INTERFACE(radio_interface,
|
SIM_INTERFACE(radio_interface,
|
||||||
doInterfaceActionsBeforeTick,
|
doInterfaceActionsBeforeTick,
|
||||||
doInterfaceActionsAfterTick);
|
doInterfaceActionsAfterTick);
|
||||||
|
|
|
@ -36,6 +36,18 @@
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "dev/radio.h"
|
#include "dev/radio.h"
|
||||||
|
|
||||||
|
#ifdef COOJA_CONF_SIMULATE_TURNAROUND
|
||||||
|
#define COOJA_SIMULATE_TURNAROUND COOJA_CONF_SIMULATE_TURNAROUND
|
||||||
|
#else
|
||||||
|
#define COOJA_SIMULATE_TURNAROUND 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef COOJA_CONF_TRANSMIT_ON_CCA
|
||||||
|
#define COOJA_TRANSMIT_ON_CCA COOJA_CONF_TRANSMIT_ON_CCA
|
||||||
|
#else
|
||||||
|
#define COOJA_TRANSMIT_ON_CCA 1
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const struct radio_driver cooja_radio_driver;
|
extern const struct radio_driver cooja_radio_driver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ char simDontFallAsleep = 0;
|
||||||
|
|
||||||
int simProcessRunValue;
|
int simProcessRunValue;
|
||||||
int simEtimerPending;
|
int simEtimerPending;
|
||||||
clock_time_t simNextExpirationTime;
|
clock_time_t simEtimerNextExpirationTime;
|
||||||
|
|
||||||
void doActionsBeforeTick() {
|
void doActionsBeforeTick() {
|
||||||
// Poll all interfaces to do their thing before the tick
|
// Poll all interfaces to do their thing before the tick
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct simInterface {
|
||||||
// Variable for keeping the last process_run() return value
|
// Variable for keeping the last process_run() return value
|
||||||
extern int simProcessRunValue;
|
extern int simProcessRunValue;
|
||||||
extern int simEtimerPending;
|
extern int simEtimerPending;
|
||||||
extern clock_time_t simNextExpirationTime;
|
extern clock_time_t simEtimerNextExpirationTime;
|
||||||
extern clock_time_t simCurrentTime;
|
extern clock_time_t simCurrentTime;
|
||||||
|
|
||||||
// Variable that when set to != 0, stops the mote from falling asleep next tick
|
// Variable that when set to != 0, stops the mote from falling asleep next tick
|
||||||
|
|
|
@ -48,46 +48,44 @@
|
||||||
#define PRINTF(...)
|
#define PRINTF(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern clock_time_t simCurrentTime;
|
/* COOJA */
|
||||||
|
int simRtimerPending;
|
||||||
static int pending_rtimer = 0;
|
rtimer_clock_t simRtimerNextExpirationTime;
|
||||||
static rtimer_clock_t next_rtimer = 0;
|
rtimer_clock_t simRtimerCurrentTicks;
|
||||||
static clock_time_t last_rtimer_now = 0;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rtimer_arch_init(void)
|
rtimer_arch_init(void)
|
||||||
{
|
{
|
||||||
next_rtimer = 0;
|
simRtimerNextExpirationTime = 0;
|
||||||
last_rtimer_now = 0;
|
simRtimerPending = 0;
|
||||||
pending_rtimer = 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rtimer_arch_schedule(rtimer_clock_t t)
|
rtimer_arch_schedule(rtimer_clock_t t)
|
||||||
{
|
{
|
||||||
next_rtimer = t;
|
simRtimerNextExpirationTime = t;
|
||||||
pending_rtimer = 1;
|
simRtimerPending = 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
rtimer_clock_t
|
rtimer_clock_t
|
||||||
rtimer_arch_next(void)
|
rtimer_arch_next(void)
|
||||||
{
|
{
|
||||||
return next_rtimer;
|
return simRtimerNextExpirationTime;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
rtimer_arch_pending(void)
|
rtimer_arch_pending(void)
|
||||||
{
|
{
|
||||||
return pending_rtimer;
|
return simRtimerPending;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
rtimer_arch_check(void)
|
rtimer_arch_check(void)
|
||||||
{
|
{
|
||||||
if (simCurrentTime == next_rtimer) {
|
if (simRtimerCurrentTicks == simRtimerNextExpirationTime) {
|
||||||
/* Execute rtimer */
|
/* Execute rtimer */
|
||||||
pending_rtimer = 0;
|
simRtimerPending = 0;
|
||||||
rtimer_run_next();
|
rtimer_run_next();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -97,14 +95,7 @@ rtimer_arch_check(void)
|
||||||
rtimer_clock_t
|
rtimer_clock_t
|
||||||
rtimer_arch_now(void)
|
rtimer_arch_now(void)
|
||||||
{
|
{
|
||||||
if(last_rtimer_now == simCurrentTime) {
|
return simRtimerCurrentTicks;
|
||||||
/* Yield to COOJA, to allow time to change */
|
|
||||||
simProcessRunValue = 1;
|
|
||||||
simNextExpirationTime = simCurrentTime + 1;
|
|
||||||
cooja_mt_yield();
|
|
||||||
}
|
|
||||||
last_rtimer_now = simCurrentTime;
|
|
||||||
return simCurrentTime;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,10 @@
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
#include "sys/clock.h"
|
#include "sys/clock.h"
|
||||||
|
|
||||||
#define RTIMER_ARCH_SECOND CLOCK_CONF_SECOND
|
#define RTIMER_ARCH_SECOND UINT64_C(1000000)
|
||||||
|
|
||||||
|
#define US_TO_RTIMERTICKS(US) (US)
|
||||||
|
#define RTIMERTICKS_TO_US(T) (T)
|
||||||
|
|
||||||
rtimer_clock_t rtimer_arch_now(void);
|
rtimer_clock_t rtimer_arch_now(void);
|
||||||
int rtimer_arch_check(void);
|
int rtimer_arch_check(void);
|
||||||
|
|
|
@ -52,8 +52,11 @@ import org.contikios.cooja.mote.memory.VarMemory;
|
||||||
* Contiki variables:
|
* Contiki variables:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>clock_time_t simCurrentTime
|
* <li>clock_time_t simCurrentTime
|
||||||
* <li>clock_time_t simNextExpirationTime
|
* <li>rtimer_clock_t simRtimerCurrentTicks
|
||||||
* <li>int simProcessRunValue
|
* <li>clock_time_t simEtimerNextExpirationTime
|
||||||
|
* <li>rtimer_clock_t simEtimerNextExpirationTime
|
||||||
|
* <li>int simEtimerProcessRunValue
|
||||||
|
* <li>int simRtimerProcessRunValue
|
||||||
* <li>int simEtimerPending
|
* <li>int simEtimerPending
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
@ -125,16 +128,24 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
public void doActionsBeforeTick() {
|
||||||
/* Update time */
|
/* Update time */
|
||||||
setTime(mote.getSimulation().getSimulationTime() + timeDrift);
|
long currentSimulationTime = simulation.getSimulationTime();
|
||||||
|
setTime(currentSimulationTime + timeDrift);
|
||||||
|
moteMem.setInt64ValueOf("simRtimerCurrentTicks", currentSimulationTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
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 */
|
/* Request next tick for remaining events / timers */
|
||||||
int processRunValue = moteMem.getIntValueOf("simProcessRunValue");
|
int processRunValue = moteMem.getIntValueOf("simProcessRunValue");
|
||||||
if (processRunValue != 0) {
|
if (processRunValue != 0) {
|
||||||
/* Handle next Contiki event in one millisecond */
|
/* Handle next Contiki event in one millisecond */
|
||||||
mote.scheduleNextWakeup(simulation.getSimulationTime() + Simulation.MILLISECOND);
|
mote.scheduleNextWakeup(currentSimulationTime + Simulation.MILLISECOND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,15 +155,20 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request tick next wakeup time */
|
/* Request tick next wakeup time for Etimer */
|
||||||
int nextExpirationTime = moteMem.getIntValueOf("simNextExpirationTime");
|
long etimerNextExpirationTime = (long)moteMem.getInt32ValueOf("simEtimerNextExpirationTime") * Simulation.MILLISECOND;
|
||||||
if (nextExpirationTime <= 0) {
|
long etimerTimeToNextExpiration = etimerNextExpirationTime - moteTime;
|
||||||
/*logger.warn("Event timer already expired, but has been delayed: " + nextExpirationTime);*/
|
if (etimerTimeToNextExpiration <= 0) {
|
||||||
mote.scheduleNextWakeup(simulation.getSimulationTime() + Simulation.MILLISECOND);
|
/* logger.warn(mote.getID() + ": Event timer already expired, but has been delayed: " + etimerTimeToNextExpiration); */
|
||||||
return;
|
/* 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>
|
* <p>
|
||||||
* <li>int simInSize (size of received data packet)
|
* <li>int simInSize (size of received data packet)
|
||||||
* <li>byte[] simInDataBuffer (data of received data packet)
|
* <li>byte[] simInDataBuffer (data of received data packet)
|
||||||
|
* <li>int64_t simLastPacketTimestamp (timestamp of the last received data packet)
|
||||||
* <p>
|
* <p>
|
||||||
* <li>int simOutSize (size of transmitted data packet)
|
* <li>int simOutSize (size of transmitted data packet)
|
||||||
* <li>byte[] simOutDataBuffer (data 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();
|
lastEventTime = mote.getSimulation().getSimulationTime();
|
||||||
lastEvent = RadioEvent.RECEPTION_STARTED;
|
lastEvent = RadioEvent.RECEPTION_STARTED;
|
||||||
|
|
||||||
|
myMoteMemory.setInt64ValueOf("simLastPacketTimestamp", lastEventTime);
|
||||||
|
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class VarMemory extends Memory {
|
||||||
* @param varName Variable name
|
* @param varName Variable name
|
||||||
* @param value 16 bit integer value to write
|
* @param value 16 bit integer value to write
|
||||||
*/
|
*/
|
||||||
public void setInt16ValueOf(String varName, byte value)
|
public void setInt16ValueOf(String varName, short value)
|
||||||
throws UnknownVariableException {
|
throws UnknownVariableException {
|
||||||
setInt16ValueOf(getVariable(varName).addr, value);
|
setInt16ValueOf(getVariable(varName).addr, value);
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ public class VarMemory extends Memory {
|
||||||
* @param varName Variable name
|
* @param varName Variable name
|
||||||
* @param value 32 bit integer value to write
|
* @param value 32 bit integer value to write
|
||||||
*/
|
*/
|
||||||
public void setInt32ValueOf(String varName, byte value)
|
public void setInt32ValueOf(String varName, int value)
|
||||||
throws UnknownVariableException {
|
throws UnknownVariableException {
|
||||||
setInt32ValueOf(getVariable(varName).addr, value);
|
setInt32ValueOf(getVariable(varName).addr, value);
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ public class VarMemory extends Memory {
|
||||||
* @param varName Variable name
|
* @param varName Variable name
|
||||||
* @param value 64 bit integer value to write
|
* @param value 64 bit integer value to write
|
||||||
*/
|
*/
|
||||||
public void setInt64ValueOf(String varName, byte value)
|
public void setInt64ValueOf(String varName, long value)
|
||||||
throws UnknownVariableException {
|
throws UnknownVariableException {
|
||||||
setInt64ValueOf(getVariable(varName).addr, value);
|
setInt64ValueOf(getVariable(varName).addr, value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue