Adding New Devices

Microcontroller programs often interact with devices that are both present on the microcontroller itself, such as timers, as well as devices that are off-chip and connected to the microcontroller through a serial interface or the general purpose IO pins. Avrora has a flexible framework for device implementation that allows software models of hardware devices to be connected to the simulation through IO registers and through pins on the microcontroller.


Implementing Onchip Devices

Avrora supports most of the devices present on the ATMega128L chip, with the exception of the watchdog timer. In Avrora, the job of implementing a device is greatly simplified. The asynchronous programming model for time-triggered devices provides a convenient interface to the execution engine. The other part of interfacing with the execution engine are IO Registers, which represent memory-mapped control and data registers for onchip devices.

IO registers are used to configure devices like the timer, the direction of pins, and input and output from devices like SPI and the UART. In Avrora, these IO registers are modelled with an interface called State.IOReg. When the program reads from an IO register, the corresponding State.IOReg.read() method is called, and when the program writes to an IO register, the corresponding State.IOReg.write() method is called. With this interface, a device implementor can acquire control when the program accesses one of the IO registers involved with that device. The three mechanisms of the event queue, the IO registers, and posting interrupts to the simulator allow the device implementor build the device behavior without any knowledge of the internals of simulator.

For more information and an example of a device implementation, see the source code for the avrora.sim.mcu.ATMega128L class, which contains an implementation of the timer 0 device.


Implementing Offchip Devices

In addition to emulating the onchip devices provided by a particular microcontroller implementation, Avrora also offers an interface to implement devices that are wired to the microcontroller such as LEDs and sensors. Each Microcontroller exposes an interface that allows an instance of Platform to connect devices to the IO ports of the chip. This is done through a Microcontroller.Pin interface. For more information on how this is done. See the JavaDoc API and consult the source of avrora.sim.platform.Mica.