Metasepi team meeting #7: Snatch application on tiny OS
Upcoming SlideShare
Loading in...5
×
 

Metasepi team meeting #7: Snatch application on tiny OS

on

  • 10,768 views

Metasepi team meeting #7: Snatch application on tiny OS

Metasepi team meeting #7: Snatch application on tiny OS

Statistics

Views

Total Views
10,768
Views on SlideShare
10,066
Embed Views
702

Actions

Likes
2
Downloads
7
Comments
0

7 Embeds 702

https://k-of.jp 513
http://metasepi.org 110
http://www.redditmedia.com 66
http://0.0.0.0 7
http://kof.dev.an-nai.jp 4
https://twitter.com 1
http://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • Metasepi team meeting #7:  #7: Snatch application on tiny OS Kiwamu Okabe
  • 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.
  • 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!
  • [1] Demo ☆ RSS reader running on mbed (ARM). ☆ Show reddit articles on LCD display. ☆ You can watch the movie following. http://bit.ly/mbedmov
  • Demo hardware Architecture: ARM Cortex-M3 RAM size: 64kB IO: Ethernet, LED, LCD, SD Card, USB host/device, Serial
  • Demo software github.com/ajhc/demo-cortex-m3
  • [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.
  • 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".
  • [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.
  • 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.
  • 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...
  • Low quality out of OSS umbrella
  • Type safety ☆ Less runtime errors. ☆ "数理科学的バグ撲滅方法論のすすめ" http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/
  • 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?
  • [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.
  • Want POSIX free compiler Programs to print "hoge" on terminal. The lesser depends on POSIX, the smaller values.
  • 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
  • Jhc is translator to C language
  • Easy to cross build
  • Survive burning out Let's develop in dogfooding style. (The method is called "Snatch".)
  • [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.
  • 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
  • [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/
  • 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) {
  • 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);
  • Application design
  • [7] Let's Snatch it! The source code at the following. github.com/metasepi/chibios-arafura
  • 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);
  • Run simple Haskell code #2
  • 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 } }
  • Blink LED only once #2
  • 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(); }
  • Snatch blink thread code #2
  • 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; }
  • Use forkOS API #2
  • GOAL !
  • 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