??? 09/01/04 14:25 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#76757 - RE: Multitasking with no traps Responding to: ???'s previous message |
hi,
in my applications I do next way: - All tasks have own counter; - these counters are decreased down to zero with a timer; - if a counter comes to zero, task "pop ups" and does what it needs, then it reloads counter with the new value of "sleep" duration. Here is how it looks in ASM (virtually): ; allocation of tasks` wait counters TASK1_WAITER DATA 0x40 TASK2_WAITER DATA 0x41 TASK3_WAITER DATA 0x42 TASK4_WAITER DATA 0x43 TASK5_WAITER DATA 0x44 TASKS_NUM EQU (TASK5_WAITER-TASK0_WAITER+1) ; somewhere in a timer ISR ; ... MOV R0,#TASK1_WAITER INT_TASK_WAITER_C: CJNE @R0,#0,INT_TASK_WAITER_0 INT_TASK_WAITER_NEXT: INC R0 CJNE R0,#(TASK1_WAITER+TASKS_NUM),INT_TASK_WAITER_C JMP INT_TASK_WAITER_END INT_TASK_WAITER_0: DEC @R0 JMP INT_TASK_WAITER_NEXT INT_TASK_WAITER_END: ; ... ; MAIN LOOP RUN: SETB FLG_WATCHDOG ; ping watchdog MOV PCON,#00000001b ; idle mode (till interrupt event) NOP CALL TASK1 CALL TASK2 CALL TASK3 CALL TASK4 CALL TASK5 JMP RUN ; in all tasks: TASKx: MOV A,TASK1_WAITER JNZ TASKx_END ; task worktime ; ... MOV TASKx_WAITER,#xx TASKx_END: RET This way any task may set how often it will get MCU productivity. If task is big then, like Erik says, it is divided on some parts (for this purpose I have variables TASKx_STAGE defined). And the each part of a task sets WAITER counter to own appropriate value. Regards, Oleg |
Topic | Author | Date |
\ | 01/01/70 00:00 | |
"Multitasking" with no traps | 01/01/70 00:00 | |
Title | 01/01/70 00:00 | |
RE: Multitasking with no traps | 01/01/70 00:00 | |
RE: Multitasking with no traps | 01/01/70 00:00 | |
RE: Multitasking with no traps | 01/01/70 00:00 | |
RE: soft interrupts | 01/01/70 00:00 | |
RE: \ | 01/01/70 00:00 | |
RE:I would like to know | 01/01/70 00:00 | |
true, but there are times when | 01/01/70 00:00 | |
RE: true, but there are times when | 01/01/70 00:00 | |
No, I am using SDCC | 01/01/70 00:00 | |
Never seen such times. | 01/01/70 00:00 | |
RE: Never seen such times. | 01/01/70 00:00 | |
OS Advocate | 01/01/70 00:00 |