From 1206f6fd5e9575bcae1d82569db2901774273084 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 11:22:57 +0200 Subject: [PATCH] * massive name changes --- board/olimex_lpc2148/tick.c | 4 +- core/Jamfile | 2 +- core/include/kernel.h | 2 +- core/include/kernel_intern.h | 8 +-- core/include/{scheduler.h => sched.h} | 12 ++--- core/include/thread.h | 4 +- core/kernel_init.c | 16 +++--- core/msg.c | 58 ++++++++++----------- core/mutex.c | 38 +++++++------- core/{scheduler.c => sched.c} | 74 +++++++++++++-------------- core/thread.c | 34 ++++++------ cpu/arm_common/arm_cpu.c | 12 ++--- cpu/arm_common/atomic.s | 2 +- cpu/arm_common/common.s | 41 ++++++++------- cpu/arm_common/include/arm_cpu.h | 2 +- cpu/arm_common/syscalls.c | 2 +- cpu/lpc214x/startup.s | 2 +- cpu/lpc2387/startup.s | 2 +- cpu/msp430/cpu.c | 22 ++++---- cpu/msp430/include/cpu.h | 10 ++-- drivers/cc110x/cc1100_phy.c | 4 +- projects/test_sleep/main.c | 2 +- projects/test_swtimer_remove/main.c | 12 ++--- sys/shell/ps.c | 6 +-- sys/swtimer.c | 2 +- 25 files changed, 186 insertions(+), 187 deletions(-) rename core/include/{scheduler.h => sched.h} (80%) rename core/{scheduler.c => sched.c} (60%) diff --git a/board/olimex_lpc2148/tick.c b/board/olimex_lpc2148/tick.c index 08b3dcb0bb..4b8912607b 100644 --- a/board/olimex_lpc2148/tick.c +++ b/board/olimex_lpc2148/tick.c @@ -51,12 +51,12 @@ int counter = 0; void Timer0_IRQHandler (void) { - extern unsigned int fk_context_switch_request; + extern unsigned int sched_context_switch_request; counter++; T0IR |= 0xff; // reset timer1 interrupt flag sl_printf("#"); - fk_context_switch_request = 1; + sched_context_switch_request = 1; VICVectAddr = 0; // acknowledge interrupt (if using VIC IRQ) } diff --git a/core/Jamfile b/core/Jamfile index 64862e7ed7..2787dcbc76 100644 --- a/core/Jamfile +++ b/core/Jamfile @@ -27,7 +27,7 @@ SubDir TOP core ; -Module core : kernel_init.c scheduler.c mutex.c msg.c queue.c +Module core : kernel_init.c sched.c mutex.c msg.c queue.c clist.c thread.c bitarithm.c ; Module hwtimer : hwtimer.c : hwtimer_cpu ; diff --git a/core/include/kernel.h b/core/include/kernel.h index 69e12e6dd8..97313916e9 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -25,7 +25,7 @@ #include "tcb.h" #include "cpu.h" #include "flags.h" -#include "scheduler.h" +#include "sched.h" #include "cpu-conf.h" /* ------------------------------------------------------------------------- */ diff --git a/core/include/kernel_intern.h b/core/include/kernel_intern.h index a58205319e..7b5bd12c17 100644 --- a/core/include/kernel_intern.h +++ b/core/include/kernel_intern.h @@ -18,10 +18,10 @@ void kernel_init(void); void board_init_drivers(); -char *fk_stack_init(void *task_func, void *stack_start); -void fk_task_exit(void); -void fk_print_stack (); -int fk_measure_stack_free(char* stack); +char *thread_stack_init(void *task_func, void *stack_start); +void sched_task_exit(void); +void thread_print_stack (); +int thread_measure_stack_usage(char* stack); /** @} */ #endif /* KERNEL_INTERN_H_ */ diff --git a/core/include/scheduler.h b/core/include/sched.h similarity index 80% rename from core/include/scheduler.h rename to core/include/sched.h index afff055c97..ca5f74ddb1 100644 --- a/core/include/scheduler.h +++ b/core/include/sched.h @@ -21,18 +21,18 @@ #define SCHED_PRIO_LEVELS 16 #endif -void scheduler_init(); -void fk_schedule(); +void sched_init(); +void sched_run(); void sched_set_status(tcb *process, unsigned int status); -volatile unsigned int fk_context_switch_request; +volatile unsigned int sched_context_switch_request; -volatile tcb *fk_threads[MAXTHREADS]; -volatile tcb *fk_thread; +volatile tcb *sched_threads[MAXTHREADS]; +volatile tcb *active_thread; extern volatile int num_tasks; -volatile int fk_pid; +volatile int thread_pid; //#define SCHEDSTATISTICS #if SCHEDSTATISTICS diff --git a/core/include/thread.h b/core/include/thread.h index 9f75470acb..b81e07dcd1 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -63,9 +63,9 @@ int thread_getpid(); * @brief Measures the stack usage of a stack. * Only works if the thread was created with the flag CREATE_STACKTEST. * - * @param stack The stack you want to measure. try fk_thread->stack_start. + * @param stack The stack you want to measure. try active_thread->stack_start. */ -int fk_measure_stack_free(char* stack); +int thread_measure_stack_usage(char* stack); /* @} */ #endif /* __THREAD_H */ diff --git a/core/kernel_init.c b/core/kernel_init.c index 8c3f0a2eab..e511c13067 100644 --- a/core/kernel_init.c +++ b/core/kernel_init.c @@ -20,7 +20,7 @@ #include "tcb.h" #include "kernel.h" #include "kernel_intern.h" -#include "scheduler.h" +#include "sched.h" #include "flags.h" #include "cpu.h" #include "lpm.h" @@ -34,14 +34,14 @@ #define ENABLE_DEBUG #include "debug.h" -volatile tcb *fk_threads[MAXTHREADS]; -volatile tcb *fk_thread; +volatile tcb *sched_threads[MAXTHREADS]; +volatile tcb *active_thread; volatile int lpm_prevent_sleep = 0; extern void main(void); -extern void fk_switch_context_exit(void); +extern void cpu_switch_context_exit(void); -void fk_idle(void) { +static void idle_thread(void) { while(1) { if (lpm_prevent_sleep) { lpm_set(LPM_IDLE); @@ -68,9 +68,9 @@ void kernel_init(void) dINT(); printf("kernel_init(): This is µkleos!\n"); - scheduler_init(); + sched_init(); - if (thread_create(KERNEL_CONF_STACKSIZE_IDLE, PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, fk_idle, idle_name) < 0) { + if (thread_create(KERNEL_CONF_STACKSIZE_IDLE, PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) { printf("kernel_init(): error creating idle task.\n"); } @@ -80,6 +80,6 @@ void kernel_init(void) printf("kernel_init(): jumping into first task...\n"); - fk_switch_context_exit(); + cpu_switch_context_exit(); } diff --git a/core/msg.c b/core/msg.c index 707f2effd2..32eda613fc 100644 --- a/core/msg.c +++ b/core/msg.c @@ -14,7 +14,7 @@ */ #include "kernel.h" -#include "scheduler.h" +#include "sched.h" #include "msg.h" #include "queue.h" #include "tcb.h" @@ -33,9 +33,9 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { int result = 1; - tcb *target = (tcb*)fk_threads[target_pid]; + tcb *target = (tcb*)sched_threads[target_pid]; - m->sender_pid = fk_pid; + m->sender_pid = thread_pid; if (m->sender_pid == target_pid) return -1; dINT(); @@ -47,33 +47,33 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { if (target->status != STATUS_RECEIVE_BLOCKED) { if (! block ) { - DEBUG("%s: receiver not waiting. block=%u\n", fk_thread->name, block); + DEBUG("%s: receiver not waiting. block=%u\n", active_thread->name, block); eINT(); return 0; } - DEBUG("%s: send_blocked.\n", fk_thread->name); + DEBUG("%s: send_blocked.\n", active_thread->name); queue_node_t n; - n.priority = fk_thread->priority; - n.data = (unsigned int) fk_thread; - DEBUG("%s: Adding node to msg_queue:\n", fk_thread->name); + n.priority = active_thread->priority; + n.data = (unsigned int) active_thread; + DEBUG("%s: Adding node to msg_queue:\n", active_thread->name); queue_priority_add(&(target->msg_queue), &n); - fk_thread->wait_data = (void*) m; + active_thread->wait_data = (void*) m; int newstatus; - if (fk_thread->status == STATUS_REPLY_BLOCKED) { + if (active_thread->status == STATUS_REPLY_BLOCKED) { newstatus = STATUS_REPLY_BLOCKED; } else { newstatus = STATUS_SEND_BLOCKED; } - sched_set_status((tcb*)fk_thread, newstatus); + sched_set_status((tcb*)active_thread, newstatus); - DEBUG("%s: back from send block.\n", fk_thread->name); + DEBUG("%s: back from send block.\n", active_thread->name); } else { - DEBUG("%s: direct msg copy.\n", fk_thread->name); + DEBUG("%s: direct msg copy.\n", active_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; *target_message = *m; @@ -81,13 +81,13 @@ int msg_send(msg* m, unsigned int target_pid, bool block) { } eINT(); - fk_yield(); + thread_yield(); return result; } int msg_send_int(msg* m, unsigned int target_pid) { - tcb *target = (tcb*)fk_threads[target_pid]; + tcb *target = (tcb*)sched_threads[target_pid]; if (target->status == STATUS_RECEIVE_BLOCKED) { DEBUG("msg_send_int: direct msg copy.\n"); @@ -99,7 +99,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { *target_message = *m; sched_set_status(target, STATUS_PENDING); - fk_context_switch_request = 1; + sched_context_switch_request = 1; return 1; } else { DEBUG("msg_send_int: receiver not waiting.\n"); @@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) { int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { dINT(); - tcb *me = (tcb*) fk_threads[fk_pid]; + tcb *me = (tcb*) sched_threads[thread_pid]; sched_set_status(me, STATUS_REPLY_BLOCKED); me->wait_data = (void*) reply; msg_send(m, target_pid, true); @@ -123,59 +123,59 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) { int msg_reply(msg *m, msg *reply) { int state = disableIRQ(); - tcb *target = (tcb*)fk_threads[m->sender_pid]; + tcb *target = (tcb*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { - DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", fk_thread->name, target->name); + DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name); restoreIRQ(state); return -1; } - DEBUG("%s: msg_reply(): direct msg copy.\n", fk_thread->name); + DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name); /* copy msg to target */ msg* target_message = (msg*)target->wait_data; *target_message = *reply; sched_set_status(target, STATUS_PENDING); restoreIRQ(state); - fk_yield(); + thread_yield(); return 1; } int msg_reply_int(msg *m, msg *reply) { - tcb *target = (tcb*)fk_threads[m->sender_pid]; + tcb *target = (tcb*)sched_threads[m->sender_pid]; if (target->status != STATUS_REPLY_BLOCKED) { - DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", fk_thread->name, target->name); + DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name); return -1; } msg* target_message = (msg*)target->wait_data; *target_message = *m; sched_set_status(target, STATUS_PENDING); - fk_context_switch_request = 1; + sched_context_switch_request = 1; return 1; } int msg_receive(msg* m) { dINT(); - DEBUG("%s: msg_receive.\n", fk_thread->name); + DEBUG("%s: msg_receive.\n", active_thread->name); - tcb *me = (tcb*) fk_threads[fk_pid]; + tcb *me = (tcb*) sched_threads[thread_pid]; me->wait_data = (void*) m; queue_node_t *n = queue_remove_head(&(me->msg_queue)); if (n == NULL) { - DEBUG("%s: msg_receive blocked\n", fk_thread->name); + DEBUG("%s: msg_receive blocked\n", active_thread->name); sched_set_status(me, STATUS_RECEIVE_BLOCKED); eINT(); - fk_yield(); + thread_yield(); /* sender copied message */ return 1; } else { - DEBUG("%s: msg_receive direct copy.\n", fk_thread->name); + DEBUG("%s: msg_receive direct copy.\n", active_thread->name); tcb *sender = (tcb*)n->data; /* copy msg */ diff --git a/core/mutex.c b/core/mutex.c index a9d4722ea3..be33fba931 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -19,7 +19,7 @@ #include "queue.h" #include "tcb.h" #include "kernel.h" -#include "scheduler.h" +#include "sched.h" //#define ENABLE_DEBUG #include @@ -35,17 +35,17 @@ int mutex_init(struct mutex_t* mutex) { } int mutex_trylock(struct mutex_t* mutex) { - return (atomic_set_return(&mutex->val, fk_pid ) == 0); + return (atomic_set_return(&mutex->val, thread_pid ) == 0); } int prio() { - return fk_thread->priority; + return active_thread->priority; } int mutex_lock(struct mutex_t* mutex) { - DEBUG("%s: trying to get mutex. val: %u\n", fk_thread->name, mutex->val); + DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val); - if (atomic_set_return(&mutex->val,fk_pid) != 0) { + if (atomic_set_return(&mutex->val,thread_pid) != 0) { // mutex was locked. mutex_wait(mutex); } @@ -53,14 +53,14 @@ int mutex_lock(struct mutex_t* mutex) { } void mutex_unlock(struct mutex_t* mutex, int yield) { - DEBUG("%s: unlocking mutex. val: %u pid: %u\n", fk_thread->name, mutex->val, fk_pid); + DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid); int me_value; if (inISR()) { me_value = 0; yield = MUTEX_INISR; } else { - me_value = fk_pid; + me_value = thread_pid; } if (atomic_set_return(&mutex->val,0) != me_value ) { @@ -71,36 +71,36 @@ void mutex_unlock(struct mutex_t* mutex, int yield) { void mutex_wait(struct mutex_t *mutex) { dINT(); - DEBUG("%s: Mutex in use. %u\n", fk_thread->name, mutex->val); + DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val); if (mutex->val == 0) { // somebody released the mutex. return. - mutex->val = fk_pid; - DEBUG("%s: mutex_wait early out. %u\n", fk_thread->name, mutex->val); + mutex->val = thread_pid; + DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val); eINT(); return; } - sched_set_status((tcb*)fk_thread, STATUS_MUTEX_BLOCKED); + sched_set_status((tcb*)active_thread, STATUS_MUTEX_BLOCKED); queue_node_t n; - n.priority = (unsigned int) fk_thread->priority; - n.data = (unsigned int) fk_thread; + n.priority = (unsigned int) active_thread->priority; + n.data = (unsigned int) active_thread; n.next = NULL; - DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", fk_thread->name, n.priority, n.data); + DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", active_thread->name, n.priority, n.data); queue_priority_add(&(mutex->queue), &n); eINT(); - fk_yield(); + thread_yield(); /* we were woken up by scheduler. waker removed us from queue. we have the mutex now. */ } void mutex_wake_waiters(struct mutex_t *mutex, int flags) { if ( ! (flags & MUTEX_INISR)) dINT(); - DEBUG("%s: waking up waiters.\n", fk_thread->name); + DEBUG("%s: waking up waiters.\n", active_thread->name); queue_node_t *next = queue_remove_head(&(mutex->queue)); tcb* process = (tcb*)next->data; @@ -113,14 +113,14 @@ void mutex_wake_waiters(struct mutex_t *mutex, int flags) { mutex->val = process->pid; } - DEBUG("%s: waiters woken up.\n", fk_thread->name); + DEBUG("%s: waiters woken up.\n", active_thread->name); /* If called from process, reenable interrupts, yield if requested */ if (! (flags & MUTEX_INISR)) { eINT(); - if (flags & MUTEX_YIELD) fk_yield(); + if (flags & MUTEX_YIELD) thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } } diff --git a/core/scheduler.c b/core/sched.c similarity index 60% rename from core/scheduler.c rename to core/sched.c index 279bb456a2..7cd222a3b8 100644 --- a/core/scheduler.c +++ b/core/sched.c @@ -15,7 +15,7 @@ #include #include -#include "scheduler.h" +#include "sched.h" #include "kernel.h" #include "kernel_intern.h" #include "clist.h" @@ -33,11 +33,11 @@ static uint32_t runqueue_bitcache = 0; schedstat pidlist[MAXTHREADS]; #endif -void scheduler_init() { +void sched_init() { printf("Scheduler..."); int i; for (i=0; istatus == STATUS_RUNNING) { - my_fk_thread->status = STATUS_PENDING; + if (my_active_thread) { + if( my_active_thread->status == STATUS_RUNNING) { + my_active_thread->status = STATUS_PENDING; } #ifdef SCHED_TEST_STACK - if (*((unsigned int*)my_fk_thread->stack_start) != (unsigned int) my_fk_thread->stack_start) { - printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_fk_thread->name, my_fk_thread->pid); + if (*((unsigned int*)my_active_thread->stack_start) != (unsigned int) my_active_thread->stack_start) { + printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_active_thread->name, my_active_thread->pid); } #endif @@ -75,12 +75,12 @@ void fk_schedule() { #if SCHEDSTATISTICS extern unsigned long hwtimer_now(void); unsigned int time = hwtimer_now(); - if (my_fk_thread && (pidlist[my_fk_thread->pid].laststart)) { - pidlist[my_fk_thread->pid].runtime += time - pidlist[my_fk_thread->pid].laststart; + if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) { + pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart; } #endif - DEBUG("\nscheduler: previous task: %s\n", ( my_fk_thread == NULL) ? "none" : my_fk_thread->name ); + DEBUG("\nscheduler: previous task: %s\n", ( my_active_thread == NULL) ? "none" : my_active_thread->name ); if (num_tasks == 0) { DEBUG("scheduler: no tasks left.\n"); @@ -88,8 +88,8 @@ void fk_schedule() { DEBUG("scheduler: new task created.\n"); } - my_fk_thread = NULL; - while(! my_fk_thread) { + my_active_thread = NULL; + while(! my_active_thread) { // for (int i = 0; i < SCHED_PRIO_LEVELS; i++) { /* TODO: introduce bitfield cache */ // if (runqueues[i]) { @@ -97,29 +97,29 @@ void fk_schedule() { clist_node_t next = *(runqueues[nextrq]); DEBUG("scheduler: first in queue: %s\n", ((tcb*)next.data)->name); clist_advance(&(runqueues[nextrq])); - my_fk_thread = (tcb*)next.data; - fk_pid = (volatile int) my_fk_thread->pid; + my_active_thread = (tcb*)next.data; + thread_pid = (volatile int) my_active_thread->pid; #if SCHEDSTATISTICS - pidlist[my_fk_thread->pid].laststart = time; - pidlist[my_fk_thread->pid].schedules ++; + pidlist[my_active_thread->pid].laststart = time; + pidlist[my_active_thread->pid].schedules ++; #endif // break; // } // } } - DEBUG("scheduler: next task: %s\n", my_fk_thread->name); + DEBUG("scheduler: next task: %s\n", my_active_thread->name); - if (my_fk_thread != fk_thread) { - if (fk_thread != NULL) { //TODO: necessary? - if (fk_thread->status == STATUS_RUNNING) { - fk_thread->status = STATUS_PENDING ; + if (my_active_thread != active_thread) { + if (active_thread != NULL) { //TODO: necessary? + if (active_thread->status == STATUS_RUNNING) { + active_thread->status = STATUS_PENDING ; } } - sched_set_status((tcb*)my_fk_thread, STATUS_RUNNING); + sched_set_status((tcb*)my_active_thread, STATUS_RUNNING); } - fk_thread = (volatile tcb*) my_fk_thread; + active_thread = (volatile tcb*) my_active_thread; DEBUG("scheduler: done.\n"); } @@ -144,18 +144,18 @@ void sched_set_status(tcb *process, unsigned int status) { process->status = status; } -extern void fk_switch_context_exit(void); +extern void cpu_switch_context_exit(void); -void fk_task_exit(void) { - DEBUG("fk_task_exit(): ending task %s...\n", fk_thread->name); +void sched_task_exit(void) { + DEBUG("sched_task_exit(): ending task %s...\n", active_thread->name); dINT(); - fk_threads[fk_thread->pid] = NULL; + sched_threads[active_thread->pid] = NULL; num_tasks--; - sched_set_status((tcb*)fk_thread, STATUS_STOPPED); + sched_set_status((tcb*)active_thread, STATUS_STOPPED); - free(((tcb*)fk_thread)->stack_start); - fk_thread = NULL; - fk_switch_context_exit(); + free(((tcb*)active_thread)->stack_start); + active_thread = NULL; + cpu_switch_context_exit(); } diff --git a/core/thread.c b/core/thread.c index a9f4663267..33adb3e31c 100644 --- a/core/thread.c +++ b/core/thread.c @@ -25,37 +25,37 @@ #include "kernel_intern.h" #include "bitarithm.h" #include "hwtimer.h" -#include "scheduler.h" +#include "sched.h" inline int thread_getpid() { - return fk_thread->pid; + return active_thread->pid; } unsigned int thread_getstatus(int pid) { - if (fk_threads[pid]==NULL) + if (sched_threads[pid]==NULL) return STATUS_NOT_FOUND; - return fk_threads[pid]->status; + return sched_threads[pid]->status; } void thread_sleep() { if ( inISR()) return; dINT(); - sched_set_status((tcb*)fk_thread, STATUS_SLEEPING); - fk_yield(); + sched_set_status((tcb*)active_thread, STATUS_SLEEPING); + thread_yield(); } int thread_wakeup(int pid) { int isr = inISR(); if (! isr) dINT(); - int result = fk_threads[pid]->status; + int result = sched_threads[pid]->status; if (result == STATUS_SLEEPING) { - sched_set_status((tcb*)fk_threads[pid], STATUS_RUNNING); + sched_set_status((tcb*)sched_threads[pid], STATUS_RUNNING); if (!isr) { eINT(); - fk_yield(); + thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } return 0; } else { @@ -64,7 +64,7 @@ int thread_wakeup(int pid) { } } -int fk_measure_stack_free(char* stack) { +int thread_measure_stack_usage(char* stack) { unsigned int* stackp = (unsigned int*)stack; /* assumption that the comparison fails before or after end of stack */ while( *stackp == (unsigned int)stackp ) @@ -119,8 +119,8 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi int pid = 0; while (pid < MAXTHREADS) { - if (fk_threads[pid] == NULL) { - fk_threads[pid] = pd; + if (sched_threads[pid] == NULL) { + sched_threads[pid] = pd; pd->pid = pid; break; } @@ -139,7 +139,7 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi return -EOVERFLOW; } - pd->sp = fk_stack_init(function,stack+stacksize); + pd->sp = thread_stack_init(function,stack+stacksize); pd->stack_start = stack; pd->stack_size = stacksize; @@ -169,14 +169,14 @@ int thread_create(int stacksize, char priority, int flags, void (*function) (voi if (!(flags & CREATE_WOUT_YIELD)) { if (! inISR()) { eINT(); - fk_yield(); + thread_yield(); } else { - fk_context_switch_request = 1; + sched_context_switch_request = 1; } } } - if (!inISR() && fk_thread!=NULL) { + if (!inISR() && active_thread!=NULL) { eINT(); } diff --git a/cpu/arm_common/arm_cpu.c b/cpu/arm_common/arm_cpu.c index 35a20a47de..a5ffb50f45 100644 --- a/cpu/arm_common/arm_cpu.c +++ b/cpu/arm_common/arm_cpu.c @@ -22,10 +22,10 @@ #include #include "arm_cpu.h" -#include "scheduler.h" +#include "sched.h" #include "kernel_intern.h" -void fk_yield() { +void thread_yield() { asm("svc 0\n"); } @@ -33,7 +33,7 @@ void fk_yield() { // Processor specific routine - here for ARM7 // sizeof(void*) = sizeof(int) //---------------------------------------------------------------------------- -char * fk_stack_init(void * task_func, void * stack_start) +char * thread_stack_init(void * task_func, void * stack_start) { unsigned int * stk; stk = (unsigned int *) stack_start; @@ -42,7 +42,7 @@ char * fk_stack_init(void * task_func, void * stack_start) *stk = 0x77777777; stk--; - *stk = (unsigned int)fk_task_exit; // LR + *stk = (unsigned int)sched_task_exit; // LR stk--; *stk = (unsigned int) stack_start - 4; // SP @@ -60,12 +60,12 @@ char * fk_stack_init(void * task_func, void * stack_start) return (char*)stk; } -void fk_print_stack () { +void thread_print_stack () { register void * stack = 0; asm( "mov %0, sp" : "=r" (stack)); register unsigned int * s = (unsigned int*) stack; - printf("task: %X SP: %X\n", (unsigned int)fk_thread, (unsigned int)stack); + printf("task: %X SP: %X\n", (unsigned int)active_thread, (unsigned int)stack); register int i = 0; s += 5; while (*s != 0x77777777) { diff --git a/cpu/arm_common/atomic.s b/cpu/arm_common/atomic.s index 3bdeb94dba..eb2612f0f6 100644 --- a/cpu/arm_common/atomic.s +++ b/cpu/arm_common/atomic.s @@ -4,7 +4,7 @@ .code 32 .align 4 /* 0 */ -/* .extern fk_schedule*/ +/* .extern sched_run*/ /* Public functions declared in this file */ .global atomic_set_return diff --git a/cpu/arm_common/common.s b/cpu/arm_common/common.s index cd6290530a..f296f51dd1 100644 --- a/cpu/arm_common/common.s +++ b/cpu/arm_common/common.s @@ -22,15 +22,14 @@ /* External references */ - .extern fk_thread - .extern fk_context_switch_request - .extern fk_schedule + .extern active_thread + .extern sched_context_switch_request + .extern sched_run .extern DEBUG_Routine /* Public functions declared in this file */ - .global fk_cpu_irq_isr - .global fk_switch_context_exit - .global fk_switch_context + .global arm_irq_handler + .global cpu_switch_context_exit .global task_return .global ctx_switch .global dINT @@ -80,32 +79,32 @@ ctx_switch2: /* store return address and spsr on user mode stack */ stmfd lr!, {r0, r1} - /* save user mode stack pointer in *fk_thread */ - ldr r1, =fk_thread /* r1 = &fk_thread */ - ldr r1, [r1] /* r1 = *r1 = fk_thread */ + /* save user mode stack pointer in *active_thread */ + ldr r1, =active_thread /* r1 = &active_thread */ + ldr r1, [r1] /* r1 = *r1 = active_thread */ str lr, [r1] /* store stack pointer in tasks tcb*/ /* now the calling task has all its registers saved on its stack and it's SP is saved in its tcb */ - /* call scheduler so fk_thread points to the next task */ - bl fk_schedule - b fk_task_return + /* call scheduler so active_thread points to the next task */ + bl sched_run + b task_return /* never coming back */ -fk_switch_context_exit: +cpu_switch_context_exit: mov r0, #NOINT|SVCMODE msr cpsr, r0 - /* call scheduler so fk_thread points to the next task */ - bl fk_schedule + /* call scheduler so active_thread points to the next task */ + bl sched_run - /* continue in fk_task_return: */ + /* continue in task_return: */ -fk_task_return: +task_return: /* load tcb->stackpointer in r0 */ - ldr r0, =fk_thread /* r0 = &fk_thread */ - ldr r0, [r0] /* r0 = *r0 = fk_thread */ + ldr r0, =active_thread /* r0 = &active_thread */ + ldr r0, [r0] /* r0 = *r0 = active_thread */ ldr r0, [r0] /* restore saved spsr and return address from tasks stack */ @@ -121,7 +120,7 @@ fk_task_return: /*---------------------------------------------------------------------------- * *----------------------------------------------------------------------------*/ -fk_cpu_irq_isr: +arm_irq_handler: sub lr, lr, #4 /* save interrupted tasks PC onto stack */ @@ -153,7 +152,7 @@ fk_cpu_irq_isr: MSR SPSR, R0 /* check if context switch was requested by irq */ - ldr r0, =fk_context_switch_request + ldr r0, =sched_context_switch_request ldr r0, [r0] cmp r0, #0x00 diff --git a/cpu/arm_common/include/arm_cpu.h b/cpu/arm_common/include/arm_cpu.h index 3159c005e7..6272119a64 100644 --- a/cpu/arm_common/include/arm_cpu.h +++ b/cpu/arm_common/include/arm_cpu.h @@ -11,7 +11,7 @@ extern void dINT(); extern void eINT(); -void fk_yield(); +void thread_yield(); uint32_t get_system_speed(void); void cpu_clock_scale(uint32_t source, uint32_t target, uint32_t* prescale); diff --git a/cpu/arm_common/syscalls.c b/cpu/arm_common/syscalls.c index a1e583f4a1..27dd5a957a 100644 --- a/cpu/arm_common/syscalls.c +++ b/cpu/arm_common/syscalls.c @@ -228,7 +228,7 @@ void _exit(int n) /*---------------------------------------------------------------------------*/ int _getpid(void) { - return fk_thread->pid; + return active_thread->pid; } /*---------------------------------------------------------------------------*/ int _kill_r(struct _reent *r, int pid, int sig) diff --git a/cpu/lpc214x/startup.s b/cpu/lpc214x/startup.s index f9b1f6900a..8a0c95b883 100644 --- a/cpu/lpc214x/startup.s +++ b/cpu/lpc214x/startup.s @@ -55,7 +55,7 @@ Undef_Addr: .word UNDEF_Routine /* defined in main.c */ SWI_Addr: .word ctx_switch /* defined in main.c */ PAbt_Addr: .word UNDEF_Routine /* defined in main.c */ DAbt_Addr: .word UNDEF_Routine /* defined in main.c */ -IRQ_Addr: .word fk_cpu_irq_isr /* defined in main.c */ +IRQ_Addr: .word arm_irq_handler /* defined in main.c */ FIQ_Addr: .word FIQ_Routine /* defined in main.c */ .word 0 /* rounds the vectors and ISR addresses to 64 bytes total */ diff --git a/cpu/lpc2387/startup.s b/cpu/lpc2387/startup.s index f9ef062b4b..057270f591 100644 --- a/cpu/lpc2387/startup.s +++ b/cpu/lpc2387/startup.s @@ -57,7 +57,7 @@ Undef_Addr: .word UNDEF_Routine /* defined in main.c */ SWI_Addr: .word ctx_switch /* defined in main.c */ PAbt_Addr: .word PABT_Routine /* defined in main.c */ DAbt_Addr: .word DABT_Routine /* defined in main.c */ -IRQ_Addr: .word fk_cpu_irq_isr /* defined in main.c */ +IRQ_Addr: .word arm_irq_handler /* defined in main.c */ /* Begin of boot code */ .text diff --git a/cpu/msp430/cpu.c b/cpu/msp430/cpu.c index 1ea79aa337..1ffd72b78a 100644 --- a/cpu/msp430/cpu.c +++ b/cpu/msp430/cpu.c @@ -28,25 +28,25 @@ and the mailinglist (subscription via web site) #include #include "kernel.h" #include "kernel_intern.h" -#include "scheduler.h" +#include "sched.h" volatile int __inISR = 0; char __isr_stack[MSP430_ISR_STACK_SIZE]; -void fk_yield() { +void thread_yield() { __save_context(); dINT(); - /* have fk_thread point to the next thread */ - fk_schedule(); + /* have active_thread point to the next thread */ + sched_run(); eINT(); __restore_context(); } // static void __resume_context () { -// __asm__("mov.w %0,r1" : : "m" (fk_thread->sp)); +// __asm__("mov.w %0,r1" : : "m" (active_thread->sp)); // // __asm__("pop r15"); // __asm__("pop r14"); @@ -81,15 +81,15 @@ void fk_yield() { // __asm__("push r14"); // __asm__("push r15"); // -// __asm__("mov.w r1,%0" : "=r" (fk_thread->sp)); +// __asm__("mov.w r1,%0" : "=r" (active_thread->sp)); // } // // // __return_from_isr -void fk_switch_context_exit(){ - fk_thread = fk_threads[0]; - fk_schedule(); +void cpu_switch_context_exit(){ + active_thread = sched_threads[0]; + sched_run(); __restore_context(); } @@ -97,12 +97,12 @@ void fk_switch_context_exit(){ //---------------------------------------------------------------------------- // Processor specific routine - here for MSP //---------------------------------------------------------------------------- -char *fk_stack_init(void *task_func, void *stack_start) +char *thread_stack_init(void *task_func, void *stack_start) { unsigned short * stk; stk = (unsigned short *) stack_start; - *stk = (unsigned short) fk_task_exit; + *stk = (unsigned short) sched_task_exit; --stk; *stk = (unsigned short) task_func; diff --git a/cpu/msp430/include/cpu.h b/cpu/msp430/include/cpu.h index 7a920aa053..830e5c9e7f 100644 --- a/cpu/msp430/include/cpu.h +++ b/cpu/msp430/include/cpu.h @@ -37,7 +37,7 @@ and the mailinglist (subscription via web site) * @{ */ -#include +#include #include #include #include @@ -66,11 +66,11 @@ inline void __save_context_isr() { __asm__("push r5"); __asm__("push r4"); - __asm__("mov.w r1,%0" : "=r" (fk_thread->sp)); + __asm__("mov.w r1,%0" : "=r" (active_thread->sp)); } inline void __restore_context_isr() { - __asm__("mov.w %0,r1" : : "m" (fk_thread->sp)); + __asm__("mov.w %0,r1" : : "m" (active_thread->sp)); __asm__("pop r4"); __asm__("pop r5"); @@ -94,7 +94,7 @@ inline void __enter_isr() { inline void __exit_isr() { __inISR = 0; - if (fk_context_switch_request) fk_schedule(); + if (sched_context_switch_request) sched_run(); __restore_context_isr(); __asm__("reti"); } @@ -121,7 +121,7 @@ inline void dINT() { #define lpm_set(...) -void fk_yield(); +void thread_yield(); int inISR(); diff --git a/drivers/cc110x/cc1100_phy.c b/drivers/cc110x/cc1100_phy.c index 036792ee2e..90cc800ac8 100644 --- a/drivers/cc110x/cc1100_phy.c +++ b/drivers/cc110x/cc1100_phy.c @@ -206,9 +206,9 @@ void cc1100_phy_init() void cc1100_phy_mutex_lock(void) { - if (fk_thread->pid != cc1100_mutex_pid) { + if (active_thread->pid != cc1100_mutex_pid) { mutex_lock(&cc1100_mutex); - cc1100_mutex_pid = fk_thread->pid; + cc1100_mutex_pid = active_thread->pid; } } diff --git a/projects/test_sleep/main.c b/projects/test_sleep/main.c index 32e05f90b7..b352b2f68d 100644 --- a/projects/test_sleep/main.c +++ b/projects/test_sleep/main.c @@ -38,7 +38,7 @@ int main(void) if (i % 100 == 0) { printf("Waking up sleeper.\n"); thread_wakeup(pid); - fk_yield(); + thread_yield(); } } } diff --git a/projects/test_swtimer_remove/main.c b/projects/test_swtimer_remove/main.c index 773265c758..414e57d61d 100644 --- a/projects/test_swtimer_remove/main.c +++ b/projects/test_swtimer_remove/main.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include int main(void) { @@ -13,7 +13,7 @@ int main(void) swtimer_t t; puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer...\n"); @@ -22,9 +22,9 @@ int main(void) swtimer_t t2; puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Setting timer 2...\n"); - swtimer_set_wakeup(&t2, 50000000L, fk_thread->pid); + swtimer_set_wakeup(&t2, 50000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer 1...\n"); @@ -34,9 +34,9 @@ int main(void) puts("Done.\n"); puts("Setting timer...\n"); - swtimer_set_wakeup(&t, 10000000L, fk_thread->pid); + swtimer_set_wakeup(&t, 10000000L, active_thread->pid); puts("Setting timer 2...\n"); - swtimer_set_wakeup(&t2, 50000000L, fk_thread->pid); + swtimer_set_wakeup(&t2, 50000000L, active_thread->pid); puts("Small delay...\n"); hwtimer_wait(200000); puts("Removing timer 2...\n"); diff --git a/sys/shell/ps.c b/sys/shell/ps.c index a54c8bc35b..0848bd5090 100644 --- a/sys/shell/ps.c +++ b/sys/shell/ps.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include /* list of states copied from tcb.h */ @@ -27,7 +27,7 @@ void thread_print_all(void) printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state"); for( i = 0; i < MAXTHREADS; i++ ) { - tcb* p = (tcb*)fk_threads[i]; + tcb* p = (tcb*)sched_threads[i]; if( p != NULL ) { int state = p->status; // copy state @@ -42,7 +42,7 @@ void thread_print_all(void) switches = pidlist[i].schedules; #endif overall_stacksz += stacksz; - stacksz -= fk_measure_stack_free(p->stack_start); + stacksz -= thread_measure_stack_usage(p->stack_start); printf("\t%3u | %-21s| %-8s %.1s | %3i | %5i (%5i) %p | %6.3f%% | %8i\n", p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start, runtime, switches); } diff --git a/sys/swtimer.c b/sys/swtimer.c index 0d87b97581..0b998de8b7 100644 --- a/sys/swtimer.c +++ b/sys/swtimer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include