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
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:
- this code has _NOT_ been tested!
- all multi-byte values are little-endian
- 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/12/26 04:10,
3.129.42.59: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? <A HREF="http://massmind.org/Techref/microchip/18c/multitask-rtk-ba.htm"> PIC 18C Microcontoller Program Flow Method - Preemptive real-time multitasking kernel</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to massmind.org! |
.