Your SlideShare is downloading. ×
  • Like
Metasepi team meeting #7: Snatch application on tiny OS
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Metasepi team meeting #7: Snatch application on tiny OS

  • 11,850 views
Published

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
11,850
On SlideShare
0
From Embeds
0
Number of Embeds
10

Actions

Shares
Downloads
8
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Metasepi team meeting #7:  #7: Snatch application on tiny OS Kiwamu Okabe
  • 2. Who am I? ☆ http://www.masterq.net/ ☆ Twitter: @master_q ☆ Organizer of Metasepi project ☆ A developer of Ajhc Haskell compiler ☆ A Debian Maintainer ☆ 10 years' experience in developing OS using NetBSD.
  • 3. Agenda ☆ [1] Demo ☆ [2] What is Ajhc? ☆ [3] What is Metasepi? ☆ [4] What is compiler to build OS ☆ [5] How to use Ajhc ☆ [6] Snatch application on tiny OS ☆ [7] Let's Snatch it!
  • 4. [1] Demo ☆ RSS reader running on mbed (ARM). ☆ Show reddit articles on LCD display. ☆ You can watch the movie following. http://bit.ly/mbedmov
  • 5. Demo hardware Architecture: ARM Cortex-M3 RAM size: 64kB IO: Ethernet, LED, LCD, SD Card, USB host/device, Serial
  • 6. Demo software github.com/ajhc/demo-cortex-m3
  • 7. [2] What is Ajhc? http://ajhc.metasepi.org/ ☆ Ajhc := A fork of jhc ☆ jhc := John's Haskell Compiler ☆ http://repetae.net/computer/jhc/ ☆ Jhc outputs binary that has lowmemory-footprint and runs fast. ☆ Good for embedded software.
  • 8. Why need Ajhc? ☆ GHC is de facto standard on Haskell. ☆ GHC := Glasgow Haskell Compiler ☆ http://www.haskell.org/ghc/ ☆ Why need another Haskell compiler? ☆ To develop kernel named "Metasepi".
  • 9. [3] What is Metasepi? http://metasepi.org/ ☆ Unix-like OS designed by strong type. ☆ Using ML or more strong type lang. Haskell http://www.haskell.org/ OCaml http://caml.inria.fr/ MLton http://mlton.org/ . . . and suchlike.
  • 10. Why need Metasepi? ☆ We have already Linux or Windows. ☆ But the developers are suffering. ☆ If use the kernel changed by you, ☆ you will get many runtime error. ☆ Difficult even to reproduce it.
  • 11. Doesn't OSS have good quality? ☆ "The Cathedral and the Bazaar" ☆ "Given enough eyeballs, all bugs are shallow." http://cruel.org/freeware/cathedral.html ☆ But if you develop your own product reusing OSS...
  • 12. Low quality out of OSS umbrella
  • 13. Type safety ☆ Less runtime errors. ☆ "数理科学的バグ撲滅方法論のすすめ" http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/
  • 14. Kernel desperately wants type ☆ Kernels are developed with C lang. ☆ Error on user space => SEGV ☆ Error on kernel space => halt! ☆ Should design kernel with the greatest care. ☆ C language is safe?
  • 15. [4] What is compiler to build OS ☆ Need strong type. ☆ Need flexibility such as C language. ☆ Create it if there are not! ☆ From scratch? No thank you... ☆ Look for our compiler base.
  • 16. Want POSIX free compiler Programs to print "hoge" on terminal. The lesser depends on POSIX, the smaller values.
  • 17. Jhc output has only 20 undef $ nm hs.out | grep U U U U U U U U U U U U U U U U U U U U "U " _IO_putc@@GLIBC_2.2.5 __libc_start_main@@GLIBC_2.2.5 _setjmp@@GLIBC_2.2.5 abort@@GLIBC_2.2.5 ctime@@GLIBC_2.2.5 exit@@GLIBC_2.2.5 fflush@@GLIBC_2.2.5 fprintf@@GLIBC_2.2.5 fputc@@GLIBC_2.2.5 fputs@@GLIBC_2.2.5 free@@GLIBC_2.2.5 fwrite@@GLIBC_2.2.5 getenv@@GLIBC_2.2.5 malloc@@GLIBC_2.2.5 memset@@GLIBC_2.2.5 posix_memalign@@GLIBC_2.2.5 realloc@@GLIBC_2.2.5 setlocale@@GLIBC_2.2.5 sysconf@@GLIBC_2.2.5 times@@GLIBC_2.2.5
  • 18. Jhc is translator to C language
  • 19. Easy to cross build
  • 20. Survive burning out Let's develop in dogfooding style. (The method is called "Snatch".)
  • 21. [5] How to use Ajhc 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" You can use on Windows or Mac OS X.
  • 22. Detail of usage Please read "Ajhc User's Manual". ☆ ajhc.metasepi.org/manual.html Also you can read in Japanese. ☆ ajhc.metasepi.org/manual_ja.html
  • 23. [6] Snatch application on tiny OS Snatch only the LED blinker thread. ☆ Board: STM32F4 Discovery http://www.st.com/stm32f4-discovery ☆ OS: ChibiOS/RT http://www.chibios.org/
  • 24. Application 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, // --snip-static void spicb(SPIDriver *spip) { // --snip-static WORKING_AREA(waThread1, 128); static msg_t Thread1(void *arg) { // --snip-int main(void) { // --snip-- * size_t n) {
  • 25. LED blinker thread // File: main.c static WORKING_AREA(waThread1, 128); static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { palSetPad(GPIOD, GPIOD_LED3); chThdSleepMilliseconds(500); palClearPad(GPIOD, GPIOD_LED3); chThdSleepMilliseconds(500); } } /* Orange. */ /* Orange. */ int main(void) { // --snip-chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  • 26. Application design
  • 27. [7] Let's Snatch it! The source code at the following. github.com/metasepi/chibios-arafura
  • 28. Run simple Haskell code #1 -- File: hs_src/Main.hs main :: IO () main = return () // File: main.c static 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);
  • 29. Run simple Haskell code #2
  • 30. Blink LED only once #1 -- File: hs_src/Main.hs foreign 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.c static WORKING_AREA(waThread1, 128); static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { blinkOrange(); // Haskell } }
  • 31. Blink LED only once #2
  • 32. Snatch blink thread code #1 -- File: hs_src/Main.hs foreign export ccall "threadBlinkOrange" threadBlinkOrange :: IO () threadBlinkOrange :: IO () threadBlinkOrange = forever blinkOrange // File: main.c static WORKING_AREA(waThread1, 128); static msg_t Thread1(void *arg) { (void)arg; threadBlinkOrange(); }
  • 33. Snatch blink thread code #2
  • 34. Use forkOS API #1 -- File: hs_src/Main.hs main :: IO () main = void $ forkOS threadBlinkOrange // File: conc_custom.c void forkOS_createThread_init() { chPoolInit(&pooldesc, THD_WA_SIZE(STACKSIZE), NULL); chPoolLoadArray(&pooldesc, (void *) pool_buf, NTHREADS); } jhc_threadid_t forkOS_createThread(void *(*wrapper) (void *),void *entry,int *err) { Thread *tid; tid = chThdCreateFromMemoryPool(&pooldesc, NORMALPRIO, (tfunc_t) wrapper, entry); if (NULL == tid) { abort(); } return tid; }
  • 35. Use forkOS API #2
  • 36. GOAL !
  • 37. PR: Call For Articles ☆ http://www.paraiso-lang.org/ikmsm/ ☆ Fanzine of functional programming. ☆ About Haskell or OCaml or . . . ☆ Article about Ajhc in C84 book. ☆ Call me if you read it! http://www.paraiso-lang.org/ikmsm/books/c85.html