Skip to content

Commit ada20c9

Browse files
committed
initial
0 parents  commit ada20c9

15 files changed

+847
-0
lines changed

LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Author name here (c) 2016
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Author name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include ../stack.mk
2+
3+
TARGET ?= /dev/ttyACM0
4+
IVORYFLAGS ?= --const-fold --verbose
5+
TESTS := \
6+
cansendrecv-test \
7+
can2uart-test \
8+
led-test \
9+
blink-test
10+
11+
AADL_TESTS :=
12+
CLEANS := $(foreach test,$(TESTS),$(test)-clean) \
13+
$(foreach test,$(AADL_TESTS),$(test)_clean)
14+
GDB := arm-none-eabi-gdb \
15+
--ex 'target extended-remote $(TARGET)' \
16+
--ex 'monitor connect_srst disable' \
17+
--ex 'monitor swdp_scan' \
18+
--ex 'set mem inaccessible-by-default off' \
19+
--ex 'attach 1'
20+
21+
.PHONY: test clean $(TESTS) $(AADL_TESTS) $(CLEANS)
22+
test: $(TESTS) $(AADL_TESTS)
23+
clean: $(CLEANS)
24+
25+
# FIXME: ideally we would build only target executable
26+
# needs fixing in stack
27+
# https://github.com/commercialhaskell/stack/issues/1406
28+
29+
define MKTEST
30+
$(1):
31+
stack build . --exec '$(1)-gen --src-dir=build/$(1) $(IVORYFLAGS)'
32+
make -C build/$(1)
33+
$(1)-clean:
34+
rm -rf build/$(1)
35+
$(1)-gdb: $(1)
36+
$(GDB) build/$(1)/image
37+
$(1)-load: $(1)
38+
$(GDB) --ex 'load' build/$(1)/image
39+
$(1)-run: $(1)
40+
$(GDB) --ex 'load' --ex 'run' build/$(1)/image
41+
endef
42+
43+
define MK_AADL_TEST
44+
$(1):
45+
stack build . --exec '$(1)_gen --src-dir=build_aadl/$(1) $(IVORYFLAGS)'
46+
$(1)_clean:
47+
rm -rf build_aadl/$(1)
48+
endef
49+
50+
$(foreach test,$(TESTS),$(eval $(call MKTEST,$(test))))
51+
$(foreach test,$(AADL_TESTS),$(eval $(call MK_AADL_TEST,$(test))))

README.rst

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
helloworld firmware
2+
====================
3+
4+
Experimental version of Hello world firmware
5+
6+
Written in http://ivorylang.org/
7+
8+
Requires
9+
--------
10+
11+
- stack https://docs.haskellstack.org/en/stable/README/
12+
- arm-none-eabi-newlib
13+
- arm-none-eabi-gcc
14+
15+
Fedora::
16+
17+
dnf install arm-none-eabi-gcc-cs arm-none-eabi-newlib
18+
19+
Building
20+
--------
21+
22+
To build all images::
23+
24+
./standalone-setup.sh # required if you don't have checked out ivory tower and ivory-tower-stm32 repos in ..
25+
make
26+
27+
Tests
28+
-----
29+
30+
Blink
31+
Blinks external LEDs on GPIO1 and GPIO2
32+
CANSendRecv
33+
Test application sending packets from CAN1, blinks on received packets.
34+
CAN2UART
35+
Test application for receiving and sending
36+
CAN packets controlled by UART
37+
38+
39+
Run `make` to build all test applications.
40+
Specific application can be built with `make APP`
41+
loaded with `make APP-load` and `make APP-run`.
42+
43+
To load Blink test application run::
44+
45+
make blink-test-load
46+
47+
to also issue run and start application after loading use::
48+
49+
make blink-test-run
50+
51+
to just run gdb with new binary without loading::
52+
53+
make blink-test-gdb
54+
# issuing 'load' in gdb == pwm-load
55+
# running both 'load' and 'run' == pwm-run
56+
57+
58+
Flashing
59+
--------
60+
61+
With BlackMagic Probe::
62+
63+
arm-none-eabi-gdb --ex 'target extended-remote /dev/ttyACM0' --ex 'monitor swdp_scan' --ex 'attach 1' --ex 'load' build/can2uart-test/image

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

default.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[args]
2+
platform="hello4disco"
3+
#platform="hellof0"
4+
5+
#optional "user.conf"

ivory-tower-helloworld.cabal

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
name: ivory-tower-helloworld
3+
version: 0.1.0.0
4+
synopsis: helloworld application
5+
-- description:
6+
license: BSD3
7+
author: Your name here
8+
maintainer: [email protected]
9+
copyright: 2017 Your name here
10+
-- category:
11+
build-type: Simple
12+
cabal-version: >=1.10
13+
14+
library
15+
hs-source-dirs: src
16+
exposed-modules: Hello.Tests.Platforms
17+
Hello.Tests.LED
18+
Hello.Tests.Blink
19+
Hello.Tests.CANSendRecv
20+
Hello.Tests.CAN2UART
21+
--Hello.App
22+
--Hello.Platforms
23+
24+
build-depends: base >= 4.6,
25+
monadLib,
26+
ivory,
27+
ivory-stdlib,
28+
ivory-hw,
29+
tower >= 0.9,
30+
tower-config,
31+
tower-hal,
32+
tower-freertos-stm32 >= 0.9,
33+
ivory-bsp-stm32,
34+
ivory-bsp-tests
35+
36+
default-language: Haskell2010
37+
ghc-options: -Wall
38+
39+
executable blink-test-gen
40+
main-is: BlinkTest.hs
41+
hs-source-dirs: test
42+
build-depends: base >= 4.6,
43+
ivory,
44+
ivory-stdlib,
45+
ivory-backend-c,
46+
ivory-hw,
47+
tower >= 0.9,
48+
tower-config,
49+
tower-freertos-stm32,
50+
ivory-bsp-stm32,
51+
ivory-bsp-tests,
52+
ivory-tower-helloworld
53+
ghc-options: -Wall
54+
55+
executable cansendrecv-test-gen
56+
main-is: CANSendRecvTest.hs
57+
hs-source-dirs: test
58+
build-depends: base >= 4.6,
59+
ivory,
60+
ivory-stdlib,
61+
ivory-backend-c,
62+
ivory-hw,
63+
tower >= 0.9,
64+
tower-config,
65+
tower-freertos-stm32,
66+
ivory-bsp-stm32,
67+
ivory-bsp-tests,
68+
ivory-tower-helloworld
69+
ghc-options: -Wall
70+
71+
executable can2uart-test-gen
72+
main-is: CAN2UARTTest.hs
73+
hs-source-dirs: test
74+
build-depends: base >= 4.6,
75+
ivory,
76+
ivory-stdlib,
77+
ivory-backend-c,
78+
ivory-hw,
79+
tower >= 0.9,
80+
tower-config,
81+
tower-freertos-stm32,
82+
ivory-bsp-stm32,
83+
ivory-bsp-tests,
84+
ivory-tower-helloworld
85+
ghc-options: -Wall

src/Hello/Tests/Blink.hs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE MultiParamTypeClasses #-}
3+
{-# LANGUAGE FlexibleContexts #-}
4+
5+
module Hello.Tests.Blink where
6+
7+
import Ivory.Language
8+
import Ivory.Tower
9+
import Ivory.HW.Module
10+
11+
import Hello.Tests.LED
12+
import Hello.Tests.Platforms
13+
------------------------------
14+
15+
-- | LED Controller: Given a set of leds and a control channel of booleans,
16+
-- setup the pin hardware, and turn the leds on when the control channel is
17+
-- true.
18+
ledController :: [LED] -> ChanOutput ('Stored IBool) -> Monitor e ()
19+
ledController leds rxer = do
20+
-- Bookkeeping: this task uses Ivory.HW.Module.hw_moduledef
21+
monitorModuleDef $ hw_moduledef
22+
-- Setup hardware before running any event handlers
23+
handler systemInit "hardwareinit" $
24+
callback $ const $ mapM_ ledSetup leds
25+
-- Run a callback on each message posted to the channel
26+
handler rxer "newoutput" $ callback $ \outref -> do
27+
out <- deref outref
28+
-- Turn pins on or off according to event value
29+
ifte_ out
30+
(mapM_ ledOn leds)
31+
(mapM_ ledOff leds)
32+
33+
-- | Blink task: Given a period and a channel source, output an alternating
34+
-- stream of true / false on each period.
35+
blinker :: Time a => a -> Tower e (ChanOutput ('Stored IBool))
36+
blinker t = do
37+
p_chan <- period t
38+
(cin, cout) <- channel
39+
monitor "blinker" $ do
40+
lastled <- stateInit "lastled" (ival false)
41+
handler p_chan "per" $ do
42+
e <- emitter cin 1
43+
callback $ \timeref -> do
44+
time <- deref timeref
45+
-- Emit boolean value which will alternate each period.
46+
store lastled (time .% (2*p) <? p)
47+
emitV e (time .% (2*p) <? p)
48+
return cout
49+
where p = toITime t
50+
51+
blink :: Time a => a -> [LED] -> Tower p ()
52+
blink per pins = do
53+
onoff <- blinker per
54+
monitor "led" $ ledController pins onoff
55+
56+
app :: (e -> ColoredLEDs) -> Tower e ()
57+
app toleds = do
58+
leds <- fmap toleds getEnv
59+
blink (Milliseconds 1000) [redLED leds]
60+
--blink (Milliseconds 333) [blueLED leds]

0 commit comments

Comments
 (0)