Main Page   Class Hierarchy   Compound List   File List   Header Files   Compound Members   File Members  

legOS/kernel/tm.c File Reference

Task management. More...


Defines

#define fatal (a)

Functions

void tm_switcher (void)
the task switcher. More...

 __asm__ (" .text .align 1 .globl _tm_switcher _tm_switcher: ; r6 saved by ROM ; r0 saved by system timer handler mov.w r1,@-r7 ; save registers mov.w r2,@-r7 mov.w r3,@-r7 mov.w r4,@-r7 mov.w r5,@-r7 mov.w r7,r0 ; pass sp jsr _tm_scheduler ; call scheduler _tm_switcher_return: mov.w r0,r7 ; set new sp mov.w @r7+,r5 mov.w @r7+,r4 mov.w @r7+,r3 mov.w @r7+,r2 mov.w @r7+,r1 ; r0 will be restored by system timer handler ; r6 will be restored by ROM rts ; return to new task ")
size_ttm_scheduler (size_t *old_sp)
the process scheduler. More...

void yield (void)
yield the rest of the current timeslice. More...

 __asm__ (" .text .globl _yield .align 1 _yield: stc ccr,r0h ; to fake an IRQ, we have to push r0 ; store the registers orc #0x80,ccr ; disable interrupts push r6 ; store r6 mov.w #0x04d4,r0 ; store rom return addr push r0 push r0 ; store r0 (destroyed by call.) mov.w #_systime_tm_return,r0 ; store systime return addr push r0 jmp @_tm_switcher ; call task switcher ")
int tm_idle_task (int argc,char **argv) __attribute__ ((noreturn))
the idle task. More...

 __asm__ (" .text .align 1 _tm_idle_task: sleep bra _tm_idle_task ")
void tm_init (void)
init task management. More...

void tm_start (void)
start task management. More...

pid_t execi (int (*code_start)(int,char**),int argc, char **argv, priority_t priority,size_t stack_size)
execute a memory image. More...

void exit (int code)
exit task, returning code. More...

wakeup_t wait_event (wakeup_t (*wakeup)(wakeup_t),wakeup_t data)
suspend process until wakeup function is non-null. More...

wakeup_t tm_sleep_wakeup (wakeup_t data)
wakeup function for sleep. More...

unsigned int msleep (unsigned int msec)
delay execution allowing other tasks to run. More...

unsigned int sleep (unsigned int sec)
delay execution allowing other tasks to run. More...

void kill (pid_t pid)
kill a process. More...

void killall (priority_t prio)
kill all processes with priority lower or equal than p, excluding self.


Variables

pchain_tpriority_head
head of process priority chain.

pdata_t pd_single
single process process data.

pdata_tpd_idle
idle proces.

pdata_tcpid
ptr to current process data.

unsigned nb_tasks
number of tasks.

sem_t task_sem
task data structure protection.


Detailed Description

Task management.

Author(s):
Markus L. Noga <markus@noga.de>

Contains the multitasking switcher and scheduler as well as library functions relating to task management.

Define Documentation

#define fatal (a)


Function Documentation

void tm_switcher (void)

the task switcher.

saves active context and passes sp to scheduler then restores new context from returned sp

__asm__ (".text.align 1.globl _tm_switcher_tm_switcher:;r6 saved by ROM;r0 saved by system timer handler mov. w r1, @-r7;save registers mov. w r2, @-r7 mov. w r3, @-r7 mov. w r4, @-r7 mov. w r5, @-r7 mov. w r7, r0;pass sp jsr _tm_scheduler;call scheduler_tm_switcher_return:mov. w r0, r7;set new sp mov.w@r7+, r5 mov.w@r7+, r4 mov.w@r7+, r3 mov.w@r7+, r2 mov.w@r7+, r1;r0 will be restored by system timer handler;r6 will be restored by ROM rts;return to new task")

size_t * tm_scheduler (size_t * old_sp)

the process scheduler.

Parameters:
old_sp   current task's current stack pointer
Returns:
new task's current stack pointer

actual context switches performed by tm_switcher (assembler wrapper)

void yield (void)

yield the rest of the current timeslice.

doesn't speed up the system clock.

__asm__ (".text.globl _yield.align 1_yield:stc ccr, r0h; to fake an IRQ, we have to push r0;store the registers orc# 0x80, ccr;disable interrupts push r6;store r6 mov.w# 0x04d4, r0;store rom return addr push r0 push r0;store r0(destroyed by call.)mov.w# _systime_tm_return, r0;store systime return addr push r0 jmp@_tm_switcher;call task switcher")

int tm_idle_task (int argc, char ** argv)

the idle task.

infinite sleep instruction to conserve power.

__asm__ (".text.align 1_tm_idle_task:sleep bra _tm_idle_task")

void tm_init (void)

init task management.

called in single tasking mode before task setup.

void tm_start (void)

start task management.

called in single tasking mode after task setup

pid_t execi (int(* code_start)(int,char **), int argc, char ** argv, priority_t priority, size_t stack_size)

execute a memory image.

Parameters:
code_start   start address of code to execute
argc   first argument passed, normally number of strings in argv
argv   second argument passed, normally pointer to argument pointers.
priority   new task's priority
stack_size   stack size for new process
Returns:
-1: fail, else pid.

will return to caller in any case.

void exit (int code)

exit task, returning code.

Parameters:
code   The return code

FIXME: for now, scrap the code.

wakeup_t wait_event (wakeup_t(* wakeup)(wakeup_t), wakeup_t data)

suspend process until wakeup function is non-null.

Parameters:
wakeup   the wakeup function. called in task scheduler context.
data   argument passed to wakeup function by scheduler
Returns:
return value passed on from wakeup

wakeup_t tm_sleep_wakeup (wakeup_t data) [static]

wakeup function for sleep.

Parameters:
data   time to wakeup encoded as a wakeup_t

unsigned int msleep (unsigned int msec)

delay execution allowing other tasks to run.

Parameters:
msec   sleep duration in milliseconds
Returns:
number of milliseconds left if interrupted, else 0.
Bugs and limitations:
interruptions not implemented.

unsigned int sleep (unsigned int sec)

delay execution allowing other tasks to run.

Parameters:
sec   sleep duration in seconds
Returns:
number of seconds left if interrupted, else 0.
Bugs and limitations:
interruptions not implemented.

void kill (pid_t pid)

kill a process.

Parameters:
pid   must be valid process ID, or undefined behaviour will result!

void killall (priority_t p)

kill all processes with priority lower or equal than p, excluding self.


Variable Documentation

pchain_t* priority_head

head of process priority chain.

pdata_t pd_single

single process process data.

pdata_t* pd_idle

idle proces.

pdata_t* cpid

ptr to current process data.

unsigned nb_tasks

number of tasks.

sem_t task_sem

task data structure protection.

legOS-0.2.4 is released under the Mozilla Public License. Original code copyright 1998-1999 by the authors.