Instrumenting Simulations with EventsAvrora's simulator maintains a cycle-accurate notion of time. The simulator allows the user to add instrumentation not only at particular points in the program, but also at particular points in time. The simulator allows the user to add an event to the simulation that will fire at a specific time. The simulator will advance time by executing instructions and simulating devices until it reaches the point in time when the event should fire. For example, suppose our application receives bytes from a serial port, and we would like to instrument the simulation to check whether the bytes are processed within a certain number of milliseconds. We can add an event to the simulation when the byte is received over the serial port that will fire at some time in the future and check that the program has processed the byte correctly.
Event Example: Sleep StatisticsThe simulator also provides a mechanism for time-triggered instrumentation through events. Unlike probes and watches which are triggered by your program executing a particular instruction or accessing a particular memory location, events are triggered by the passage of time, measured in clock cycles. Events are used internally to implement the behavior of devices such as timers, UART, and others, but they can also be used by you to instrument your programs. Like probes and watches, events implement an interface contained in the Simulator class.
Suppose now that we want to measure some time-dependent behavior of the program such as how much time it spends with the microcontroller in a sleep mode. This could be done using probes that run before and after every instruction and keep track of the number of cycles executed for each instruction--but in a sleep mode, no instructions are executed! Clearly another mechanism is needed. The solution is to use an event that is triggered by the passage of time (measured in clock cycles) within the simulation.
We can make a simple event that fires once per clock cycle and queries whether the microcontroller is in a sleep mode or not, and then keeps a count of how long the program sleeps and how long the program is awake.
Like probes and watches, events can be as simple or as complex as you need. You can have events insert other events into the event queue to be fired in the future. Events can inserts probes or watches into the simulation; anything that you can dream up.