Skip to content

Commit b6479dd

Browse files
author
Adam C. Foltzer
committed
add external monitors test
1 parent 32289ad commit b6479dd

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ TAGS
66
*.aadl
77
*.swp
88
.stack-work
9+
/tower-aadl/test_external_codegen

tower-aadl/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ include ../stack.mk
33
test: default
44
stack exec -- test --src-dir=test_codegen
55

6+
test-external: default
7+
stack exec -- test-external --src-dir=test_external_codegen
8+
69
.PHONY: test-echronos
710
test-echronos: default
811
stack exec -- test-echronos --src-dir=test_echronos_codegen --lib-dir=""

tower-aadl/test/External.hs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE QuasiQuotes #-}
4+
{-# LANGUAGE RecordWildCards #-}
5+
{-# LANGUAGE QuasiQuotes #-}
6+
{-# LANGUAGE FlexibleInstances #-}
7+
{-# LANGUAGE OverloadedStrings #-}
8+
9+
{-# OPTIONS_GHC -fno-warn-orphans #-}
10+
11+
module Main where
12+
13+
import Ivory.Tower
14+
import Ivory.Language
15+
import Tower.AADL
16+
import Ivory.Tower.Config
17+
18+
simpleTower :: Tower e ()
19+
simpleTower = do
20+
towerModule towerDepModule
21+
towerDepends towerDepModule
22+
23+
(c1in, c1out) <- channel
24+
(chtx, chrx) <- channel
25+
per <- period (Microseconds 1000)
26+
27+
monitor "periodicM" $ do
28+
s <- state "local_st"
29+
handler per "send" $ do
30+
e <- emitter c1in 1
31+
callback $ \_ -> do
32+
emit e (constRef (s :: Ref 'Global ('Stored Uint8)))
33+
handler chrx "rcv" $ callback $ \msg -> do
34+
n' <- deref msg
35+
store s (n' + 1)
36+
call_ printf "received: %u\n" n'
37+
38+
{-
39+
monitor "withsharedM" $ do
40+
s <- state "last_m2_chan1_message"
41+
42+
handler c1out "fromActiveh" $ do
43+
e <- emitter chtx 1
44+
callback $ \m -> do
45+
refCopy s m
46+
emitV e true
47+
48+
handler chrx "readStateh" $ do
49+
callback $ \_m -> do
50+
s' <- deref s
51+
call_ printf "rsh: %u\n" s'
52+
-}
53+
54+
ext_chan1 <- channel
55+
ext_chan2 <- channel
56+
57+
externalMonitor "extMon" $ do
58+
59+
handler c1out "send_ext" $ do
60+
e <- emitter (fst ext_chan1) 1
61+
callback $ \msg -> emit e msg
62+
63+
handler (snd ext_chan2) "rcv_ext" $ do
64+
e <- emitter chtx 1
65+
callback $ \msg -> emit e msg
66+
67+
68+
69+
70+
main :: IO ()
71+
main = compileTowerAADL id p simpleTower
72+
where
73+
p topts = getConfig topts $ aadlConfigParser defaultAADLConfig
74+
75+
[ivory|
76+
import (stdio.h, printf) void printf(string x, uint8_t y)
77+
|]
78+
79+
towerDepModule :: Module
80+
towerDepModule = package "towerDeps" $ do
81+
incl printf

tower-aadl/tower-aadl.cabal

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,16 @@ executable test-echronos
6464
, tower-aadl
6565
default-language: Haskell2010
6666
ghc-options: -Wall
67+
68+
executable test-external
69+
hs-source-dirs: test
70+
main-is: External.hs
71+
build-depends: base >= 4.6
72+
, base-compat
73+
, ivory >= 0.1.0.1
74+
, tower
75+
, tower-config
76+
, tower-aadl
77+
default-language: Haskell2010
78+
ghc-options: -Wall
79+

0 commit comments

Comments
 (0)