amforth : multitasking Erich W alde Forth Gesellschaft e.V. 2012 - - PowerPoint PPT Presentation

amforth multitasking
SMART_READER_LITE
LIVE PREVIEW

amforth : multitasking Erich W alde Forth Gesellschaft e.V. 2012 - - PowerPoint PPT Presentation

amforth : multitasking Erich W alde Forth Gesellschaft e.V. 2012 Task Control Block state (sleep or awake) follower (tid of next task) rp0 base of return stack sp0 base of data stack sp top of data stack catch/throw


slide-1
SLIDE 1

amforth: multitasking

Erich W¨ alde Forth Gesellschaft e.V. 2012

slide-2
SLIDE 2

Task Control Block

  • state (sleep or awake)
  • follower (tid of next task)
  • rp0 base of return stack
  • sp0 base of data stack
  • sp top of data stack
  • catch/throw handler
  • base
  • deferred words: emit . . .
slide-3
SLIDE 3

Task Switch

  • store relevant info of current task into TCB
  • lookup next task
  • switch user area pointer to new TCB
  • restore relevant info of new task into stacks

and pointers

  • resume execution of new task

Collaborative multitasking: All tasks need to give up control regularly by calling pause

slide-4
SLIDE 4

Example

  • task 1:
  • command loop
  • task 2:
  • increment N
  • store N on Port B
  • wait 500 ms
slide-5
SLIDE 5

talk to Port B

$38 constant PORTB $37 constant DDRB variable N : init $ff PORTB c! \ portB: all pins high $ff DDRB c! \ all pins output 0 N ! ;

slide-6
SLIDE 6

load multitasker

include multitask.frt

slide-7
SLIDE 7

code of task 2

\ call pause on wait : ms ( n -- ) 0 ?do pause 1ms loop ; : run-demo \ --- task 2 --- begin N @ invert PORTB c! 1 N +! &500 ms again ;

slide-8
SLIDE 8

create task 2

\ d-stack-size \ r-stack-size \ additional-user-area-size \ -- $20 $20 $10 task: task_demo : start-demo task_demo tcb>tid activate \ remainder runs in new task run-demo ;

slide-9
SLIDE 9

setup and start

: starttasker task_demo task-init start-demo

  • nlytask

task_demo tcb>tid alsotask multi ;

slide-10
SLIDE 10

run the show

: run-turnkey applturnkey init starttasker ; ’ run-turnkey is turnkey

slide-11
SLIDE 11

live

> hex tasks 93 running 135 running Multitasker is running ok > N @ . 148B

  • k

> 0 N !

  • k

> N @ . 9

  • k

>

slide-12
SLIDE 12

Thank You!

slide set generated with L

A

T EX/Beamer(Manhattan.sty)