[Haskell-cafe] ANN: Atom 1.0.7

Lee Pike leepike at gmail.com
Sun Sep 26 20:07:01 EDT 2010


Announcing Atom 1.0.7 http://hackage.haskell.org/package/atom/

Recent changes include:

atom 1.0.6: Support for math.h expressions (contributed by Sebastian Niller)
atom 1.0.7: Support for using a HW clock to control the duration of phases.

The patch to atom 1.0.7 adds the ability to use your HW to control precisely the duration of phases.  Previously, this would have to be done using "ad-hoc" C code.  For example, on an AVR microprocessor[1], I might call compile[2] with

compile name 
  defaults 
  { cCode = prePostCode
  , hardwareClock = Just defaultClock 
      { clockName = "millis"
      , clockType = Word32
      , delta     = 50
      , delay     = "delay"
      , err       = Just "error"
      }
  } 
  atomFn

to have phases of 50 milliseconds each, calling the user-defined error() C function if that bound  is violated.  See Code.hs[2] for documentation.  It'll generate code that looks something like the following:

void main_atom_loop() {
  __global_clock = millis();

 ... Scheduled Atom functions ...

  // In the following we sample the hardware clock, waiting for the next phase.

  uint32_t const __phase_len = 30;
  uint32_t const __max = 255;
  uint32_t __curr_time = millis();

  // An error check for when the phase has already expired.
  // The first disjunct is for when the current time has not overflowed,
  // and the second for when it has.
  if (   (   (__curr_time >= __global_clock) 
          && (__curr_time - __global_clock > __phase_len))
      || (   (__curr_time < __global_clock) 
          && ((__max - __global_clock) + __curr_time > __phase_len))) {
    error();
  }

  __curr_time = millis(); // Update the current time.
  // Wait until the phase has expired.  If the current time hasn't
  // overflowed, execute the first branch; otherwise, the second.
  if (__curr_time >= __global_clock) {
    delay(__phase_len - (__curr_time - __global_clock));
  }
  else {
    delay(__phase_len - (__curr_time + (__max - __global_clock)));
  }
}

Suggestions, bug reports, improvements welcomed.

Regards,
Lee

[1] http://www.nongnu.org/avr-libc/
[2] http://hackage.haskell.org/packages/archive/atom/1.0.7/doc/html/Language-Atom-Compile.html
[3] http://hackage.haskell.org/packages/archive/atom/1.0.7/doc/html/Language-Atom-Code.html

--  
<http://www.galois.com>
<http://www.cs.indiana.edu/~lepike/>
Phone: +1 503.808.7185
Fax: +1 503.350.0833



More information about the Haskell-Cafe mailing list