Metasepi team meeting #7: Snatch application on tiny OS

37
Metasepi team meeting #7: Snatch application on tiny OS Metasepi team meeting #7: Snatch application on tiny OS Metasepi team meeting #7: Snatch application on tiny OS Metasepi team meeting #7: Snatch application on tiny OS Metasepi team meeting #7: Snatch application on tiny OS Kiwamu Okabe Kiwamu Okabe Kiwamu Okabe Kiwamu Okabe Kiwamu Okabe

description

Metasepi team meeting #7: Snatch application on tiny OS

Transcript of Metasepi team meeting #7: Snatch application on tiny OS

Page 1: Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7:Snatch application on tiny OS

Kiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu Okabe

Page 2: Metasepi team meeting #7: Snatch application on tiny OS

Who am I?Who am I?Who am I?Who am I?Who am I?

☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/☆ http://www.masterq.net/

☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q

☆ Organizer of Metasepi project☆ Organizer of Metasepi project☆ Organizer of Metasepi project☆ Organizer of Metasepi project☆ Organizer of Metasepi project

☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler

☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer

☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.☆ 10 years' experience in developing OS using NetBSD.

Page 3: Metasepi team meeting #7: Snatch application on tiny OS

AgendaAgendaAgendaAgendaAgenda

☆ [1] Demo☆ [1] Demo☆ [1] Demo☆ [1] Demo☆ [1] Demo

☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?☆ [2] What is Ajhc?

☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?☆ [3] What is Metasepi?

☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS☆ [4] What is compiler to build OS

☆ [5] How to use Ajhc☆ [5] How to use Ajhc☆ [5] How to use Ajhc☆ [5] How to use Ajhc☆ [5] How to use Ajhc

☆ [6] Snatch application on tiny OS☆ [6] Snatch application on tiny OS☆ [6] Snatch application on tiny OS☆ [6] Snatch application on tiny OS☆ [6] Snatch application on tiny OS

☆ [7] Let's Snatch it!☆ [7] Let's Snatch it!☆ [7] Let's Snatch it!☆ [7] Let's Snatch it!☆ [7] Let's Snatch it!

Page 4: Metasepi team meeting #7: Snatch application on tiny OS

[1] Demo[1] Demo[1] Demo[1] Demo[1] Demo

☆ RSS reader running on mbed (ARM).☆ RSS reader running on mbed (ARM).☆ RSS reader running on mbed (ARM).☆ RSS reader running on mbed (ARM).☆ RSS reader running on mbed (ARM).

☆ Show reddit articles on LCD display.☆ Show reddit articles on LCD display.☆ Show reddit articles on LCD display.☆ Show reddit articles on LCD display.☆ Show reddit articles on LCD display.

☆ You can watch the movie following.☆ You can watch the movie following.☆ You can watch the movie following.☆ You can watch the movie following.☆ You can watch the movie following.

http://bit.ly/mbedmovhttp://bit.ly/mbedmovhttp://bit.ly/mbedmovhttp://bit.ly/mbedmovhttp://bit.ly/mbedmov

Page 5: Metasepi team meeting #7: Snatch application on tiny OS

Demo hardwareDemo hardwareDemo hardwareDemo hardwareDemo hardware

Architecture: ARM Cortex-M3Architecture: ARM Cortex-M3Architecture: ARM Cortex-M3Architecture: ARM Cortex-M3Architecture: ARM Cortex-M3

RAM size: 64kBRAM size: 64kBRAM size: 64kBRAM size: 64kBRAM size: 64kB

IO: Ethernet, LED, LCD, SD Card, USB host/device, SerialIO: Ethernet, LED, LCD, SD Card, USB host/device, SerialIO: Ethernet, LED, LCD, SD Card, USB host/device, SerialIO: Ethernet, LED, LCD, SD Card, USB host/device, SerialIO: Ethernet, LED, LCD, SD Card, USB host/device, Serial

Page 6: Metasepi team meeting #7: Snatch application on tiny OS

Demo softwareDemo softwareDemo softwareDemo softwareDemo software

github.com/ajhc/demo-cortex-m3github.com/ajhc/demo-cortex-m3github.com/ajhc/demo-cortex-m3github.com/ajhc/demo-cortex-m3github.com/ajhc/demo-cortex-m3

Page 7: Metasepi team meeting #7: Snatch application on tiny OS

[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?[2] What is Ajhc?

http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/http://ajhc.metasepi.org/

☆ Ajhc := A fork of jhc☆ Ajhc := A fork of jhc☆ Ajhc := A fork of jhc☆ Ajhc := A fork of jhc☆ Ajhc := A fork of jhc

☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler☆ jhc := John's Haskell Compiler

☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/☆ http://repetae.net/computer/jhc/

☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.☆ Jhc outputs binary that has low-memory-footprint and runs fast.

☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.☆ Good for embedded software.

Page 8: Metasepi team meeting #7: Snatch application on tiny OS

Why need Ajhc?Why need Ajhc?Why need Ajhc?Why need Ajhc?Why need Ajhc?

☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.☆ GHC is de facto standard on Haskell.

☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler☆ GHC := Glasgow Haskell Compiler

☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/☆ http://www.haskell.org/ghc/

☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?☆ Why need another Haskell compiler?

☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".☆ To develop kernel named "Metasepi".

Page 9: Metasepi team meeting #7: Snatch application on tiny OS

[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?[3] What is Metasepi?

http://metasepi.org/http://metasepi.org/http://metasepi.org/http://metasepi.org/http://metasepi.org/

☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.☆ Unix-like OS designed by strong type.

☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.☆ Using ML or more strong type lang.

Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/Haskell http://www.haskell.org/

OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/OCaml http://caml.inria.fr/

MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/MLton http://mlton.org/

. . . and suchlike.. . . and suchlike.. . . and suchlike.. . . and suchlike.. . . and suchlike.

Page 10: Metasepi team meeting #7: Snatch application on tiny OS

Why need Metasepi?Why need Metasepi?Why need Metasepi?Why need Metasepi?Why need Metasepi?

☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.☆ We have already Linux or Windows.

☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.☆ But the developers are suffering.

☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,☆ If use the kernel changed by you,

☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.☆ you will get many runtime error.

☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.☆ Difficult even to reproduce it.

Page 11: Metasepi team meeting #7: Snatch application on tiny OS

Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?Doesn't OSS have good quality?

☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"☆ "The Cathedral and the Bazaar"

☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."☆ "Given enough eyeballs, all bugs are shallow."http://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.htmlhttp://cruel.org/freeware/cathedral.html

☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...☆ But if you develop your own product reusing OSS...

Page 12: Metasepi team meeting #7: Snatch application on tiny OS

Low quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrellaLow quality out of OSS umbrella

Page 13: Metasepi team meeting #7: Snatch application on tiny OS

Type safetyType safetyType safetyType safetyType safety

☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.☆ Less runtime errors.

☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"☆ "数理科学的バグ撲滅方法論のすすめ"http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/

Page 14: Metasepi team meeting #7: Snatch application on tiny OS

Kernel desperately wants typeKernel desperately wants typeKernel desperately wants typeKernel desperately wants typeKernel desperately wants type

☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.☆ Kernels are developed with C lang.

☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV☆ Error on user space => SEGV

☆ Error on kernel space => halt!☆ Error on kernel space => halt!☆ Error on kernel space => halt!☆ Error on kernel space => halt!☆ Error on kernel space => halt!

☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.☆ Should design kernel with the greatest care.

☆ C language is safe?☆ C language is safe?☆ C language is safe?☆ C language is safe?☆ C language is safe?

Page 15: Metasepi team meeting #7: Snatch application on tiny OS

[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS[4] What is compiler to build OS

☆ Need strong type.☆ Need strong type.☆ Need strong type.☆ Need strong type.☆ Need strong type.

☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.☆ Need flexibility such as C language.

☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!☆ Create it if there are not!

☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...☆ From scratch? No thank you...

☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.☆ Look for our compiler base.

Page 16: Metasepi team meeting #7: Snatch application on tiny OS

Want POSIX free compilerWant POSIX free compilerWant POSIX free compilerWant POSIX free compilerWant POSIX free compiler

Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.Programs to print "hoge" on terminal.

The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.The lesser depends on POSIX, the smaller values.

Page 17: Metasepi team meeting #7: Snatch application on tiny OS

Jhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undefJhc output has only 20 undef$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

$ nm hs.out | grep "U " U _IO_putc@@GLIBC_2.2.5 U __libc_start_main@@GLIBC_2.2.5 U _setjmp@@GLIBC_2.2.5 U abort@@GLIBC_2.2.5 U ctime@@GLIBC_2.2.5 U exit@@GLIBC_2.2.5 U fflush@@GLIBC_2.2.5 U fprintf@@GLIBC_2.2.5 U fputc@@GLIBC_2.2.5 U fputs@@GLIBC_2.2.5 U free@@GLIBC_2.2.5 U fwrite@@GLIBC_2.2.5 U getenv@@GLIBC_2.2.5 U malloc@@GLIBC_2.2.5 U memset@@GLIBC_2.2.5 U posix_memalign@@GLIBC_2.2.5 U realloc@@GLIBC_2.2.5 U setlocale@@GLIBC_2.2.5 U sysconf@@GLIBC_2.2.5 U times@@GLIBC_2.2.5

Page 18: Metasepi team meeting #7: Snatch application on tiny OS

Jhc is translator to C languageJhc is translator to C languageJhc is translator to C languageJhc is translator to C languageJhc is translator to C language

Page 19: Metasepi team meeting #7: Snatch application on tiny OS

Easy to cross buildEasy to cross buildEasy to cross buildEasy to cross buildEasy to cross build

Page 20: Metasepi team meeting #7: Snatch application on tiny OS

Survive burning outSurvive burning outSurvive burning outSurvive burning outSurvive burning out

Let's develop in dogfooding style. (The method is called "Snatch".)Let's develop in dogfooding style. (The method is called "Snatch".)Let's develop in dogfooding style. (The method is called "Snatch".)Let's develop in dogfooding style. (The method is called "Snatch".)Let's develop in dogfooding style. (The method is called "Snatch".)

Page 21: Metasepi team meeting #7: Snatch application on tiny OS

[5] How to use Ajhc[5] How to use Ajhc[5] How to use Ajhc[5] How to use Ajhc[5] How to use Ajhc

Case of Ubuntu 12.04 amd64.Case of Ubuntu 12.04 amd64.Case of Ubuntu 12.04 amd64.Case of Ubuntu 12.04 amd64.Case of Ubuntu 12.04 amd64.$ sudo apt-get install haskell-platform libncurses5-dev gcc m4$ cabal update$ export PATH=$HOME/.cabal/bin/:$PATH$ cabal install ajhc$ which ajhc/home/USER/.cabal/bin/ajhc$ echo 'main = print "hoge"' > Hoge.hs$ ajhc Hoge.hs$ ./hs.out"hoge"

$ sudo apt-get install haskell-platform libncurses5-dev gcc m4$ cabal update$ export PATH=$HOME/.cabal/bin/:$PATH$ cabal install ajhc$ which ajhc/home/USER/.cabal/bin/ajhc$ echo 'main = print "hoge"' > Hoge.hs$ ajhc Hoge.hs$ ./hs.out"hoge"

$ sudo apt-get install haskell-platform libncurses5-dev gcc m4$ cabal update$ export PATH=$HOME/.cabal/bin/:$PATH$ cabal install ajhc$ which ajhc/home/USER/.cabal/bin/ajhc$ echo 'main = print "hoge"' > Hoge.hs$ ajhc Hoge.hs$ ./hs.out"hoge"

$ sudo apt-get install haskell-platform libncurses5-dev gcc m4$ cabal update$ export PATH=$HOME/.cabal/bin/:$PATH$ cabal install ajhc$ which ajhc/home/USER/.cabal/bin/ajhc$ echo 'main = print "hoge"' > Hoge.hs$ ajhc Hoge.hs$ ./hs.out"hoge"

$ sudo apt-get install haskell-platform libncurses5-dev gcc m4$ cabal update$ export PATH=$HOME/.cabal/bin/:$PATH$ cabal install ajhc$ which ajhc/home/USER/.cabal/bin/ajhc$ echo 'main = print "hoge"' > Hoge.hs$ ajhc Hoge.hs$ ./hs.out"hoge"

You can use on Windows or Mac OS X.You can use on Windows or Mac OS X.You can use on Windows or Mac OS X.You can use on Windows or Mac OS X.You can use on Windows or Mac OS X.

Page 22: Metasepi team meeting #7: Snatch application on tiny OS

Detail of usageDetail of usageDetail of usageDetail of usageDetail of usage

Please read "Ajhc User's Manual".Please read "Ajhc User's Manual".Please read "Ajhc User's Manual".Please read "Ajhc User's Manual".Please read "Ajhc User's Manual".

☆ ajhc.metasepi.org/manual.html☆ ajhc.metasepi.org/manual.html☆ ajhc.metasepi.org/manual.html☆ ajhc.metasepi.org/manual.html☆ ajhc.metasepi.org/manual.html

Also you can read in Japanese.Also you can read in Japanese.Also you can read in Japanese.Also you can read in Japanese.Also you can read in Japanese.

☆ ajhc.metasepi.org/manual_ja.html☆ ajhc.metasepi.org/manual_ja.html☆ ajhc.metasepi.org/manual_ja.html☆ ajhc.metasepi.org/manual_ja.html☆ ajhc.metasepi.org/manual_ja.html

Page 23: Metasepi team meeting #7: Snatch application on tiny OS

[6] Snatch application on tiny OS[6] Snatch application on tiny OS[6] Snatch application on tiny OS[6] Snatch application on tiny OS[6] Snatch application on tiny OS

Snatch only the LED blinker thread.Snatch only the LED blinker thread.Snatch only the LED blinker thread.Snatch only the LED blinker thread.Snatch only the LED blinker thread.

☆ Board: STM32F4 Discovery☆ Board: STM32F4 Discovery☆ Board: STM32F4 Discovery☆ Board: STM32F4 Discovery☆ Board: STM32F4 Discovery

http://www.st.com/stm32f4-discoveryhttp://www.st.com/stm32f4-discoveryhttp://www.st.com/stm32f4-discoveryhttp://www.st.com/stm32f4-discoveryhttp://www.st.com/stm32f4-discovery

☆ OS: ChibiOS/RT☆ OS: ChibiOS/RT☆ OS: ChibiOS/RT☆ OS: ChibiOS/RT☆ OS: ChibiOS/RT

http://www.chibios.org/http://www.chibios.org/http://www.chibios.org/http://www.chibios.org/http://www.chibios.org/

Page 24: Metasepi team meeting #7: Snatch application on tiny OS

Application code before SnatchApplication code before SnatchApplication code before SnatchApplication code before SnatchApplication code before Snatch// File: main.c#include "ch.h"#include "hal.h"#include "test.h"static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];static const ADCConversionGroup adcgrpcfg = {// --snip--static PWMConfig pwmcfg = {// --snip--static const SPIConfig spi2cfg = {// --snip--static void pwmpcb(PWMDriver *pwmp) {// --snip--void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {// --snip--static void spicb(SPIDriver *spip) {// --snip--static WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) {// --snip--int main(void) {// --snip--

// File: main.c#include "ch.h"#include "hal.h"#include "test.h"static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];static const ADCConversionGroup adcgrpcfg = {// --snip--static PWMConfig pwmcfg = {// --snip--static const SPIConfig spi2cfg = {// --snip--static void pwmpcb(PWMDriver *pwmp) {// --snip--void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {// --snip--static void spicb(SPIDriver *spip) {// --snip--static WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) {// --snip--int main(void) {// --snip--

// File: main.c#include "ch.h"#include "hal.h"#include "test.h"static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];static const ADCConversionGroup adcgrpcfg = {// --snip--static PWMConfig pwmcfg = {// --snip--static const SPIConfig spi2cfg = {// --snip--static void pwmpcb(PWMDriver *pwmp) {// --snip--void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {// --snip--static void spicb(SPIDriver *spip) {// --snip--static WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) {// --snip--int main(void) {// --snip--

// File: main.c#include "ch.h"#include "hal.h"#include "test.h"static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];static const ADCConversionGroup adcgrpcfg = {// --snip--static PWMConfig pwmcfg = {// --snip--static const SPIConfig spi2cfg = {// --snip--static void pwmpcb(PWMDriver *pwmp) {// --snip--void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {// --snip--static void spicb(SPIDriver *spip) {// --snip--static WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) {// --snip--int main(void) {// --snip--

// File: main.c#include "ch.h"#include "hal.h"#include "test.h"static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];static const ADCConversionGroup adcgrpcfg = {// --snip--static PWMConfig pwmcfg = {// --snip--static const SPIConfig spi2cfg = {// --snip--static void pwmpcb(PWMDriver *pwmp) {// --snip--void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {// --snip--static void spicb(SPIDriver *spip) {// --snip--static WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) {// --snip--int main(void) {// --snip--

Page 25: Metasepi team meeting #7: Snatch application on tiny OS

LED blinker threadLED blinker threadLED blinker threadLED blinker threadLED blinker thread// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); }}

int main(void) {// --snip-- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); }}

int main(void) {// --snip-- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); }}

int main(void) {// --snip-- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); }}

int main(void) {// --snip-- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker");while (TRUE) {

palSetPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); /* Orange. */ chThdSleepMilliseconds(500); }}

int main(void) {// --snip-- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

>>>>>

Page 26: Metasepi team meeting #7: Snatch application on tiny OS

Application designApplication designApplication designApplication designApplication design

>>>>>

Page 27: Metasepi team meeting #7: Snatch application on tiny OS

[7] Let's Snatch it![7] Let's Snatch it![7] Let's Snatch it![7] Let's Snatch it![7] Let's Snatch it!

The source code at the following.The source code at the following.The source code at the following.The source code at the following.The source code at the following.

github.com/metasepi/chibios-arafuragithub.com/metasepi/chibios-arafuragithub.com/metasepi/chibios-arafuragithub.com/metasepi/chibios-arafuragithub.com/metasepi/chibios-arafura

>>>>>

Page 28: Metasepi team meeting #7: Snatch application on tiny OS

Run simple Haskell code #1Run simple Haskell code #1Run simple Haskell code #1Run simple Haskell code #1Run simple Haskell code #1-- File: hs_src/Main.hsmain :: IO ()main = return ()

-- File: hs_src/Main.hsmain :: IO ()main = return ()

-- File: hs_src/Main.hsmain :: IO ()main = return ()

-- File: hs_src/Main.hsmain :: IO ()main = return ()

-- File: hs_src/Main.hsmain :: IO ()main = return ()

// File: main.cstatic char malloc_heapstart[(2*1024)];static MemoryHeap heap_desc;void malloc_init(void) { chHeapInit(&heap_desc, (void *)malloc_heapstart, (2*1024));}int main(void) {// --snip-- { /* Init Ajhc RTS (Haskell) */ int hsargc = 1; char *hsargv = "q"; char **hsargvp = &hsargv; malloc_init(); hs_init(&hsargc, &hsargvp); _amain(); } chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic char malloc_heapstart[(2*1024)];static MemoryHeap heap_desc;void malloc_init(void) { chHeapInit(&heap_desc, (void *)malloc_heapstart, (2*1024));}int main(void) {// --snip-- { /* Init Ajhc RTS (Haskell) */ int hsargc = 1; char *hsargv = "q"; char **hsargvp = &hsargv; malloc_init(); hs_init(&hsargc, &hsargvp); _amain(); } chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic char malloc_heapstart[(2*1024)];static MemoryHeap heap_desc;void malloc_init(void) { chHeapInit(&heap_desc, (void *)malloc_heapstart, (2*1024));}int main(void) {// --snip-- { /* Init Ajhc RTS (Haskell) */ int hsargc = 1; char *hsargv = "q"; char **hsargvp = &hsargv; malloc_init(); hs_init(&hsargc, &hsargvp); _amain(); } chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic char malloc_heapstart[(2*1024)];static MemoryHeap heap_desc;void malloc_init(void) { chHeapInit(&heap_desc, (void *)malloc_heapstart, (2*1024));}int main(void) {// --snip-- { /* Init Ajhc RTS (Haskell) */ int hsargc = 1; char *hsargv = "q"; char **hsargvp = &hsargv; malloc_init(); hs_init(&hsargc, &hsargvp); _amain(); } chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

// File: main.cstatic char malloc_heapstart[(2*1024)];static MemoryHeap heap_desc;void malloc_init(void) { chHeapInit(&heap_desc, (void *)malloc_heapstart, (2*1024));}int main(void) {// --snip-- { /* Init Ajhc RTS (Haskell) */

int hsargc = 1;char *hsargv = "q";char **hsargvp = &hsargv;

malloc_init(); hs_init(&hsargc, &hsargvp); _amain(); } chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

>>>>>

Page 29: Metasepi team meeting #7: Snatch application on tiny OS

Run simple Haskell code #2Run simple Haskell code #2Run simple Haskell code #2Run simple Haskell code #2Run simple Haskell code #2

>>>>>

Page 30: Metasepi team meeting #7: Snatch application on tiny OS

Blink LED only once #1Blink LED only once #1Blink LED only once #1Blink LED only once #1Blink LED only once #1-- File: hs_src/Main.hsforeign export ccall "blinkOrange" blinkOrange :: IO ()blinkOrange :: IO ()blinkOrange = do c_palSetPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500 c_palClearPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500

-- File: hs_src/Main.hsforeign export ccall "blinkOrange" blinkOrange :: IO ()blinkOrange :: IO ()blinkOrange = do c_palSetPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500 c_palClearPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500

-- File: hs_src/Main.hsforeign export ccall "blinkOrange" blinkOrange :: IO ()blinkOrange :: IO ()blinkOrange = do c_palSetPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500 c_palClearPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500

-- File: hs_src/Main.hsforeign export ccall "blinkOrange" blinkOrange :: IO ()blinkOrange :: IO ()blinkOrange = do c_palSetPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500 c_palClearPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500

-- File: hs_src/Main.hsforeign export ccall "blinkOrange" blinkOrange :: IO ()blinkOrange :: IO ()blinkOrange = do c_palSetPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500 c_palClearPad c_GPIOD c_GPIOD_LED3 c_chThdSleepMilliseconds 500

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { blinkOrange(); // Haskell }}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { blinkOrange(); // Haskell }}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { blinkOrange(); // Haskell }}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { blinkOrange(); // Haskell }}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker");while (TRUE) {

blinkOrange(); // Haskell }}

>>>>>

Page 31: Metasepi team meeting #7: Snatch application on tiny OS

Blink LED only once #2Blink LED only once #2Blink LED only once #2Blink LED only once #2Blink LED only once #2

>>>>>

Page 32: Metasepi team meeting #7: Snatch application on tiny OS

Snatch blink thread code #1Snatch blink thread code #1Snatch blink thread code #1Snatch blink thread code #1Snatch blink thread code #1-- File: hs_src/Main.hsforeign export ccall "threadBlinkOrange" threadBlinkOrange :: IO ()threadBlinkOrange :: IO ()threadBlinkOrange = forever blinkOrange

-- File: hs_src/Main.hsforeign export ccall "threadBlinkOrange" threadBlinkOrange :: IO ()threadBlinkOrange :: IO ()threadBlinkOrange = forever blinkOrange

-- File: hs_src/Main.hsforeign export ccall "threadBlinkOrange" threadBlinkOrange :: IO ()threadBlinkOrange :: IO ()threadBlinkOrange = forever blinkOrange

-- File: hs_src/Main.hsforeign export ccall "threadBlinkOrange" threadBlinkOrange :: IO ()threadBlinkOrange :: IO ()threadBlinkOrange = forever blinkOrange

-- File: hs_src/Main.hsforeign export ccall "threadBlinkOrange" threadBlinkOrange :: IO ()threadBlinkOrange :: IO ()threadBlinkOrange = forever blinkOrange

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange();}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange();}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange();}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange();}

// File: main.cstatic WORKING_AREA(waThread1, 128);static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange();}

>>>>>

Page 33: Metasepi team meeting #7: Snatch application on tiny OS

Snatch blink thread code #2Snatch blink thread code #2Snatch blink thread code #2Snatch blink thread code #2Snatch blink thread code #2

>>>>>

Page 34: Metasepi team meeting #7: Snatch application on tiny OS

Use forkOS API #1Use forkOS API #1Use forkOS API #1Use forkOS API #1Use forkOS API #1-- File: hs_src/Main.hsmain :: IO ()main = void $ forkOS threadBlinkOrange

-- File: hs_src/Main.hsmain :: IO ()main = void $ forkOS threadBlinkOrange

-- File: hs_src/Main.hsmain :: IO ()main = void $ forkOS threadBlinkOrange

-- File: hs_src/Main.hsmain :: IO ()main = void $ forkOS threadBlinkOrange

-- File: hs_src/Main.hsmain :: IO ()main = void $ forkOS threadBlinkOrange

// File: conc_custom.cvoidforkOS_createThread_init(){ chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS);}jhc_threadid_tforkOS_createThread(void *(*wrapper) (void *),void *entry,int *err){ Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry); if (NULL == tid) { abort(); } return tid;}

// File: conc_custom.cvoidforkOS_createThread_init(){ chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS);}jhc_threadid_tforkOS_createThread(void *(*wrapper) (void *),void *entry,int *err){ Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry); if (NULL == tid) { abort(); } return tid;}

// File: conc_custom.cvoidforkOS_createThread_init(){ chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS);}jhc_threadid_tforkOS_createThread(void *(*wrapper) (void *),void *entry,int *err){ Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry); if (NULL == tid) { abort(); } return tid;}

// File: conc_custom.cvoidforkOS_createThread_init(){ chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS);}jhc_threadid_tforkOS_createThread(void *(*wrapper) (void *),void *entry,int *err){ Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry); if (NULL == tid) { abort(); } return tid;}

// File: conc_custom.cvoidforkOS_createThread_init(){ chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS);}jhc_threadid_tforkOS_createThread(void *(*wrapper) (void *),void *entry,int *err){ Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry);if (NULL == tid) { abort(); }return tid;

}

>>>>>

Page 35: Metasepi team meeting #7: Snatch application on tiny OS

Use forkOS API #2Use forkOS API #2Use forkOS API #2Use forkOS API #2Use forkOS API #2

>>>>>

Page 36: Metasepi team meeting #7: Snatch application on tiny OS

GOAL !GOAL !GOAL !GOAL !GOAL !

>>>>>

Page 37: Metasepi team meeting #7: Snatch application on tiny OS

PR: Call For ArticlesPR: Call For ArticlesPR: Call For ArticlesPR: Call For ArticlesPR: Call For Articles

☆ http://www.paraiso-lang.org/ikmsm/☆ http://www.paraiso-lang.org/ikmsm/☆ http://www.paraiso-lang.org/ikmsm/☆ http://www.paraiso-lang.org/ikmsm/☆ http://www.paraiso-lang.org/ikmsm/

☆ Fanzine of functional programming.☆ Fanzine of functional programming.☆ Fanzine of functional programming.☆ Fanzine of functional programming.☆ Fanzine of functional programming.

☆ About Haskell or OCaml or . . .☆ About Haskell or OCaml or . . .☆ About Haskell or OCaml or . . .☆ About Haskell or OCaml or . . .☆ About Haskell or OCaml or . . .

☆ Article about Ajhc in C84 book.☆ Article about Ajhc in C84 book.☆ Article about Ajhc in C84 book.☆ Article about Ajhc in C84 book.☆ Article about Ajhc in C84 book.

☆ Call me if you read it!☆ Call me if you read it!☆ Call me if you read it!☆ Call me if you read it!☆ Call me if you read it!http://www.paraiso-lang.org/ikmsm/books/c85.htmlhttp://www.paraiso-lang.org/ikmsm/books/c85.htmlhttp://www.paraiso-lang.org/ikmsm/books/c85.htmlhttp://www.paraiso-lang.org/ikmsm/books/c85.htmlhttp://www.paraiso-lang.org/ikmsm/books/c85.html

>>>>>