Prerequisites
Virgil is a cross-platform, portable language, but this tutorial focuses on one particular microcontroller model and architecture. You will need the following prerequisites to try this tutorial:
- Download and Build the Virgil compiler.
- avr-gcc - a gcc cross-compiler that can compile C code to AVR machine code.
- Avrora - a hardware simulator for the several popular AVR microcontroller models and platforms.
Step 1 - Compile Blink
The next step is to compile an actual application using the VPC compiler. We will focus
on a simple application that runs on the Mica2 sensor node platform,
which uses an AVR microcontroller.
VPC generates C code and uses gcc to compile to machine code;
therefore to compile for AVR, you must have avr-gcc
already installed.
For this step, you simply need to go to the apps/Blink
directory and
run make
. The default makefile uses VPC to compile the program into
an ELF binary for the ATMega128.
% cd apps/Blink % make java vpc.Compiler -config=../config.avr Blink.v ../../lib/mica2/Mica2.v ../../lib/mica2/LED.v ../../lib/mica2/Terminal.v ../../lib/avr/Timer0.v ../../lib/avr/Port.v ../../lib/avr/ADC.v ../../lib/avr/SPI.v ../../lib/avr/USART.v ../../lib/avr/MCU.v ../../lib/util/Queue.v mv output.elf Blink.elf % _
Step 2 - Simulate
Now that we have successfully compiled the Blink
application to AVR
machine code, we can either load the binary onto an actual Mica2 hardware device,
or we can run the program on a hardware simulator such as Avrora.
For instructions on downloading and installing Avrora, see
this page.
% avrora -platform=mica2 -seconds=2 Blink.elf
Avrora [Beta 1.7.87] - (c) 2003-2007 UCLA Compilers Group
This simulator and analysis tool is provided with absolutely no warranty,
either expressed or implied. It is provided to you with the hope that it be
useful for evaluation of and experimentation with microcontroller and sensor
network programs. For more information about the license that this software is
provided to you under, specify the "license" option.
Loading Blink.elf...[OK: 0.319 seconds]
=={ Simulation events }=======================================================
Node Time Event
------------------------------------------------------------------------------
0 432 on off off
0 432 on on off
0 432 on on on
0 459 off on on
0 459 off off on
0 459 off off off
0 3917392 off off on
0 7834193 off off off
0 11750992 off off on
==============================================================================
Simulated time: 14745600 cycles
Time for simulation: 0.929 seconds
Total throughput: 15.872551 mhz
% _