Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## avrora.sim.clock
Class DerivedClock

    java.lang.Object
      avrora.sim.clock.Clock
          avrora.sim.clock.DerivedClock

public class DerivedClock
extends Clock

The `DerivedClock` class represents a clock that is derived from another clock; i.e. the derived clock runs slower but is synchronized with the clock that it is derived from. An example is the 32khz real time clock on the Mica2--it runs independently of the main clock, but in the simulation, it uses the main clock signal to synchronize its execution to the execution of the program.

Field Summary
`protected double` | `divider` The `divider` stores a the ration between the clockspeed of the drive clock and the clockspeed of this clock.
`protected Clock` | `driveClock` The `driveClock` field stores a reference to the clock that is underlying this derived clock.

Fields inherited from class avrora.sim.clock.Clock
`hz, name`

Constructor Summary
`DerivedClock(java.lang.String n, Clock driver, long hz)` The constructor of the `DerivedClock` creates a new clock with the specified name, driven by the specified clock, with the specified clockrate.

Method Summary
`long` | `getCount()` The `getCount()` method returns the total count of clock ticks that have happened for this clock.
`void` | `insertEvent(Simulator.Event e, long delta)` The `insertEvent()` method inserts an event into the event queue of the clock with the specified delay in clock cycles.
`void` | `removeEvent(Simulator.Event e)` The `removeEvent()` method removes an event from the event queue of the clock.

Methods inherited from class avrora.sim.clock.Clock
`getHZ, getName`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### driveClock

    protected final Clock driveClock

  The `driveClock` field stores a reference to the clock that is underlying this derived clock.

### divider

    protected final double divider

  The `divider` stores a the ration between the clockspeed of the drive clock and the clockspeed of this clock.

Constructor Detail

### DerivedClock

    public DerivedClock(java.lang.String n,
                        Clock driver,
                        long hz)

  The constructor of the `DerivedClock` creates a new clock with the specified name, driven by the specified clock, with the specified clockrate. The derived clock can have any speed that is slower than the clock that it is derived from. Roundoff errors will happen when the rates are not an integer multiple of each other, but are guaranteed never to exceed 1 cycle of the underlying clock.

Parameters:
  `n` - the name of the clock
  `driver` - the clock source from which this clock is derived
  `hz` - the number of cycles per second of this clock

Method Detail

### getCount

    public long getCount()

  The `getCount()` method returns the total count of clock ticks that have happened for this clock. Since this clock is a derived clock, it computes the number of clock cycles that have happened based on the number of clock cycles that have happened for the underlying clock from which it is derived.

  Specified by:
    `getCount` in class `Clock`
  Returns:
    the count in cycles of this clock

### insertEvent

    public void insertEvent(Simulator.Event e,
                            long delta)

  The `insertEvent()` method inserts an event into the event queue of the clock with the specified delay in clock cycles. The event will then be executed at the future time specified.

  Specified by:
    `insertEvent` in class `Clock`
  Parameters:
    `e` - the event to be inserted
    `delta` - the number of cycles in the future at which to event

### removeEvent

    public void removeEvent(Simulator.Event e)

  The `removeEvent()` method removes an event from the event queue of the clock. The comparison used is reference equality, not `.equals()`.

  Specified by:
    `removeEvent` in class `Clock`
  Parameters:
    `e` - the event to remove

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD