please dont rip this site

PIC 18C Microcontoller Program Flow Method

The code on this page and on "Simple C18 Cooperative Multitasking" /techref/microchip/language/c/MultiTask.c.htm only works with the PIC18Cxx chips. For other chips, see

Preemptive real-time multitasking kernel

Bob Ammerman [rammerman at prodigy.net] of RAm Systems says

The PIC18Cxx2 chips contain quite a few nice new features. One of the neatest is programmable access to the stack. This feature allows many powerful tricks.

Notes:

  1. this code has _NOT_ been tested!
  2. all multi-byte values are little-endian
  3. I assume the code space never exceeds 16 bits worth (which it never will on the 242, 252, 442 or 452 chips).
Preemptive real-time multitasking kernel

(: you didn't really think you'd find a whole kernel here, did you? :)

Extending the idea in "F", it would be relatively simple to create a tiny
kernel that did preemptive multitasking.

You would do this by creating a "task control block" for each task which
would hold the STKPTR and critical register values for that task (at least
WREG and STATUS, maybe BSR, one or more FSR's, PCLATH, etc).

Task switching would involve saving the outgoing task's registers in its
"task control block" and then loading everything up from the incoming task's
"task control block".

; Assumption: FSR2 is reserved for use by the kernel (it should't be used by
tasks)

; On entry: FSR2 points to the task's TCB

SAVE_TASK MACRO
 movwf POSTINC2,A
 movff STATUS,POSTINC2
 movff BSR,POSTINC2
 movff STKPTR,POSTINC2
 ENDM

; On entry: FSR2 points to the task's TCB

RESTORE_TASK MACRO
 movf POSTINC2,W,A
 movff POSTINC2,STATUS
 movff POSTINC2,BSR
 movff POSTINC2,STKPTR
 ENDM

 CBLOCK
   curr_task  ; Pointer to current task's TCB (assumed in bank 5)
   new_task  ; Pointer to new task's TCB (assumed in bank 5)
 ENDC


; Assumption: FSR2H contains a 5 at all times (for accessing kernel data
structures)

; On entry:
; 'curr_task' is pointer to current task's TCB (assumed in bank 5)
; 'new_task' is pointer to new task's TCB (assumed in bank 5)

switch_task:
 movff curr_task,FSR2L
 SAVE_TASK

 movff new_task,FSR2L
 RESTORE_TASK

 movff new_task,curr_task
 return  ; will return to current location in new task

Questions:


file: /Techref/microchip/18c/multitask-rtk-ba.htm, 3KB, , updated: 2007/1/24 17:20, local time: 2024/11/26 05:10,
TOP NEW HELP FIND: 
18.188.132.71:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/Techref/microchip/18c/multitask-rtk-ba.htm"> PIC 18C Microcontoller Program Flow Method - Preemptive real-time multitasking kernel</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .