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 ClockPrescaler

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

public class ClockPrescaler
extends Clock

The `ClockPrescaler` class represents a clock that is another clock scaled appropriately; e.g. 8x slower.

Field Summary
`protected long` | `base` The `base` field stores the cycle count of the underlying clock at the last time that this clock was reset.
`protected int` | `divider` The `divider` stores the number of cycles of the underlying clock are equivalent to one cycle of this clock.
`protected Clock` | `driveClock` The `driveClock` field stores a reference to the clock that the prescaler is derived from.
`protected long` | `ticksBeforeBase` The `ticksBeforeBase` field stores the number of ticks that were recorded before the prescaler was reset.

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

Constructor Summary
`ClockPrescaler(java.lang.String n, Clock drive, int divider)` The constructor of the `ClockPrescaler` creates a new clock that is an integer multiple slower than the clock that it is derived from.

Method Summary
`long` | `getCount()` The `getCount()` method returns the number of clock cycles (ticks) that have elapsed for this clock.
`long` | `getTotalCount()` The `getTotalCount()` method returns the total number of clock cycles (ticks) that have elapsed 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.
`void` | `reset()` The `reset()` method resets the internal clock prescaler to zero.

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 the prescaler is derived from.

### divider

    protected final int divider

  The `divider` stores the number of cycles of the underlying clock are equivalent to one cycle of this clock. For example, with a divider or 8, the underlying clock ticks 8 times for each tick of this clock.

### base

    protected long base

  The `base` field stores the cycle count of the underlying clock at the last time that this clock was reset.

### ticksBeforeBase

    protected long ticksBeforeBase

  The `ticksBeforeBase` field stores the number of ticks that were recorded before the prescaler was reset. This is used in the calculation of the total number of ticks that have elapsed.

Constructor Detail

### ClockPrescaler

    public ClockPrescaler(java.lang.String n,
                          Clock drive,
                          int divider)

  The constructor of the `ClockPrescaler` creates a new clock that is an integer multiple slower than the clock that it is derived from. Additionally, the phase at which this clock fires can be adjusted by resetting.

Parameters:
  `n` - the name of the new clock
  `drive` - the clock that drives this derived clock
  `divider` - the muliple by which the derived clock is slower than the source

Method Detail

### getCount

    public long getCount()

  The `getCount()` method returns the number of clock cycles (ticks) that have elapsed for this clock. In the implementation of the `ClockPrescaler`, this method calculates the number of scaled cycles since the last reset.

  Specified by:
    `getCount` in class `Clock`
  Returns:
    the number of elapsed time ticks in clock cycles

### getTotalCount

    public long getTotalCount()

  The `getTotalCount()` method returns the total number of clock cycles (ticks) that have elapsed for this clock. In the implementation of the `ClockPrescaler`, this method calculates the number of scaled cycles since the last reset, plus the number of ticks elapsed before the reset.

  Returns:
    the number of elapsed time ticks in clock cycles

### 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. In the implementation of `ClockPrescaler`, the event will be scheduled in the underlying clock, with the delay calculated correctly from the last time that the prescaler was reset.

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

### 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

### reset

    public void reset()

  The `reset()` method resets the internal clock prescaler to zero. Thus, the prescaler's previous phase is broken, and the clock signal continues with the same frequency, only that the first tick will happen `divider` cycles from now.

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