-
Notifications
You must be signed in to change notification settings - Fork 11
AVR Motes in Cooja
Cooja uses the Avrora simulator for AVR motes. Platforms currently available are:
- MicaZ (ATmega128L + CC2420 radio)
- Raven (ATmega1284p + AT86RF230 radio, using the RF231 emulator)
- avr-atmega128rfa1 (the bare chip, in Cooja the platform is named RFA1)
Cooja currently simulates radio transmissions between motes of the same type as 802.15.4 byte streams (preamble, start of frame delimiter, data, and checksum), but complete packets are used when motes are of different type. However it is possible to have the avr platforms communicate among themselves at the stream level, and with sky radios as well. This requires changes in the AbstractRadioMedium, Radio802154, and CustomDataRadio java files which are included in the above repository.
For simplicity this example uses UDP-ipv6 server/client motes with no RPL or radio duty cycling. Prebuilt targets for all the platforms are available in the /tools/cooja/examples/uip_client_server_binaries folder.
See An Introduction to Cooja for general information about running Cooja.
cd /tools/cooja ant clean ant run
will compile all the sources and launch the simulation window. Choose File->New simulation and then Mote Types->Create mote type->Raven mote type. Browse to the udp-server.avr-raven file, open, create, create and add. The server must be node 1 as all the clients will use a fixed aaaa::212:7401:1:101 address for it.
Now add a client: Mote Types->Create mote type->Raven mote type and open udp-client.avr-raven. Two circles will have appeared in the Visualizer window at random locations. They may be too far apart for radio communication, so drag one close to the other!!!
Start the simulation and the boot messages will appear. The motes are given random startup times; in this case the client starts before the server. The output from UART0 is shown in the log window
244 ID:2 247 ID:2 Checking MCUSR... 251 ID:2 CLOCK_SECOND 128 255 ID:2 RTIMER_ARCH_SECOND 7812 258 ID:2 F_CPU 8000000 259 ID:2 269 ID:2 *******Booting Contiki-2.5-release-454-g88eafcf******* 275 ID:2 rng issues 171 278 ID:2 Initial node_id 2 284 ID:2 EUI-64 MAC: 0-12-74-2-0-2-2-2 297 ID:2 nullmac sicslowmac, channel 26 , check rate 128 Hz tx power 0 304 ID:2 UDP client process started 312 ID:2 Client IPv6 addresses: aaaa::212:7402:2:202 316 ID:2 fe80::212:7402:2:202 332 ID:2 Created a connection with the server aaaa::212:7401:1:101 local/remote port 3001/3000 333 ID:2 Online 390 ID:1 393 ID:1 Checking MCUSR... 397 ID:1 CLOCK_SECOND 128 401 ID:1 RTIMER_ARCH_SECOND 7812 404 ID:1 F_CPU 8000000 405 ID:1 415 ID:1 *******Booting Contiki-2.5-release-454-g88eafcf******* 421 ID:1 rng issues 171 424 ID:1 Initial node_id 1 430 ID:1 EUI-64 MAC: 0-12-74-1-0-1-1-1 442 ID:1 nullmac sicslowmac, channel 26 , check rate 128 Hz tx power 0 448 ID:1 UDP server started 457 ID:1 Server IPv6 addresses: aaaa::212:7401:1:101 460 ID:1 fe80::212:7401:1:101 462 ID:1 Online 2344 ID:2 Addresses [4 max] 2348 ID:2 aaaa::212:7402:2:202 2352 ID:2 fe80::212:7402:2:202 2353 ID:2 2356 ID:2 Neighbors [20 max] 2358 ID:2 <none> 2361 ID:2 Routes [20 max] 2363 ID:2 <none> 2365 ID:2 --------- 2490 ID:1 Addresses [4 max] 2494 ID:1 aaaa::212:7401:1:101 2498 ID:1 fe80::212:7401:1:101 2499 ID:1 2502 ID:1 Neighbors [20 max] 2504 ID:1 <none> 2507 ID:1 Routes [20 max] 2509 ID:1 <none> 2511 ID:1 --------- 3396 ID:2 Never-used stack > 4830 bytes 3542 ID:1 Never-used stack > 4840 bytes 16067 ID:2 Client sending to: aaaa::212:7401:1:101 (msg: Hello 1 from the client) 16096 ID:1 Server received: 'Hello 1 from the client' from aaaa::212:7402:2:202 16106 ID:1 Responding with message: Hello from the server! (1) 16122 ID:2 Response from the server: 'Hello from the server! (1)'
Pause the simulation and open the radio logger plugin, right-click on it, and enable 6LoWPAN analyzer. Start simulation and you can see the packets being exchanged:
files/udp-client-server.png
Check out the various interfaces shown when you right-click on a mote. Three LED's are enabled, connected to PORTD but that is easily changed in the /avrora/sim/platform/Raven.java file. As you can see, the hardware pins can be referenced either symbolically or by actual pin number:
ledGroup = new LED.LEDGroup(sim, new LED[] { yellow, green, red }); addDevice("leds", ledGroup); AtmelMicrocontroller amcu = (AtmelMicrocontroller)mcu; if (true) { mcu.getPin("PD5").connectOutput(yellow); mcu.getPin("PD6").connectOutput(green); mcu.getPin("PD7").connectOutput(red); } // install the new AT86RF230 radio. Actually an AT86RF231. AT86RF231Radio radio = new AT86RF231Radio(mcu, MAIN_HZ * 2); // mcu.getPin("PB7").connectOutput(radio.SCLK_pin); mcu.getPin(3).connectOutput(radio.SCLK_pin); //PB7 mcu.getPin(1).connectOutput(radio.MOSI_pin); //PB5 mcu.getPin(2).connectInput(radio.MISO_pin); //PB6 mcu.getPin(41).connectOutput(radio.RSTN_pin); //PB1 mcu.getPin(43).connectOutput(radio.SLPTR_pin);//PB3 mcu.getPin(44).connectOutput(radio.CS_pin); //PB4 SPI spi = (SPI)amcu.getDevice("spi"); spi.connect(radio.spiInterface); addDevice("radio", radio); radio.RF231_interrupt = mcu.getProperties().getInterrupt("TIMER1 CAPT"); } }
Add sky, micaz, and rfa1 clients and they should all get responses from the server.
Build RPL and radio cycling firmware for even more fun. The RFA1 emulates the hardware csma and random backoff; as yet the Ravens do not so there will be a lot of collisions in contikimac.
The AVR Debugger visualizer has a "Source" button that will spawn an avr-objdump -S on the firmware file and read the stdout into assembly and c source panels. If avr-objdump can't find the original c source files the c panel will be empty; similarly avr-objdump won't know if the source files have been changed. Use a rebuilt .elf as necessary, i.e. in cooja select udp-client.c and compile rather than a direct selection of the udp-client.avr-raven file.
Step over, step into, and breakpoints are implemented from either c or assembly source. Registers contents are shown when stepping through assembly. Currently RAM variables can only be examined using the separate Mote Plugin -> Variable Watch panel. Enabling the live update gives a good feel for the contiki program flow.
files/cooja-avrora-stepping2.png