simpleTower :: Tower e ()
simpleTower = do
  towerModule  towerDepModule
  towerDepends towerDepModule

  (c1in, c1out) <- channel
  (chtx, chrx) <- channel
  per <- period (Microseconds 1000)

  monitor "periodicM" $ do
    s <- state "local_st"
    handler per "tickh" $ do
      e <- emitter c1in 1
      callback $ \_ -> do
        emit e (constRef (s :: Ref 'Global ('Stored Uint8)))

  monitor "withsharedM" $ do
    s <- state "last_m2_chan1_message"

    handler c1out "fromActiveh" $ do
      e <- emitter chtx 1
      callback $ \m -> do
        refCopy s m
        emitV e true

    handler chrx "readStateh" $ do
      callback $ \_m -> do
        s' <- deref s
        call_ debug_print "rsh: "
        call_ debug_printhex8 s'
        call_ debug_println ""

--------------------------------------------------------------------------------
simpleTower :: Tower e ()
simpleTower = do
  towerModule  towerDepModule
  towerDepends towerDepModule

  (c1in, c1out) <- channel
  (chtx, chrx) <- channel
  per <- period (Microseconds 1000)

  monitor "periodicM" $ do
    s <- state "local_st"
    handler per "tickh" $ do
      e <- emitter c1in 1
      callback $ \_ -> do
        emit e (constRef (s :: Ref 'Global ('Stored Uint8)))

  monitor "withsharedM" $ do
    s <- state "last_m2_chan1_message"

    handler c1out "fromActiveh" $ do
      e <- emitter chtx 1
      callback $ \m -> do
        refCopy s m
        emitV e true

    handler chrx "readStateh" $ do
      callback $ \_m -> do
        s' <- deref s
        call_ debug_print "rsh: "
        call_ debug_printhex8 s'
        call_ debug_println ""

--------------------------------------------------------------------------------
simpleTower = do
  towerModule  towerDepModule
  towerDepends towerDepModule

  (c1in, c1out) <- channel
  (chtx, chrx) <- channel
  per <- period (Microseconds 1000)

  monitor "periodicM" $ do
    s <- state "local_st"
    handler per "tickh" $ do
      e <- emitter c1in 1
      callback $ \_ -> do
        emit e (constRef (s :: Ref 'Global ('Stored Uint8)))

  monitor "withsharedM" $ do
    s <- state "last_m2_chan1_message"

    handler c1out "fromActiveh" $ do
      e <- emitter chtx 1
      callback $ \m -> do
        refCopy s m
        emitV e true

    handler chrx "readStateh" $ do
      callback $ \_m -> do
        s' <- deref s
        call_ debug_print "rsh: "
        call_ debug_printhex8 s'
        call_ debug_println ""

--------------------------------------------------------------------------------