mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
* massive name changes
This commit is contained in:
parent
e9da187fbc
commit
1206f6fd5e
@ -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)
|
||||
}
|
||||
|
@ -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 ;
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "tcb.h"
|
||||
#include "cpu.h"
|
||||
#include "flags.h"
|
||||
#include "scheduler.h"
|
||||
#include "sched.h"
|
||||
#include "cpu-conf.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_ */
|
||||
|
@ -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
|
@ -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 */
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
58
core/msg.c
58
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 */
|
||||
|
38
core/mutex.c
38
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 <debug.h>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#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; i<MAXTHREADS; i++) {
|
||||
fk_threads[i] = NULL;
|
||||
sched_threads[i] = NULL;
|
||||
#if SCHEDSTATISTICS
|
||||
pidlist[i].laststart = 0;
|
||||
pidlist[i].runtime = 0;
|
||||
@ -45,8 +45,8 @@ void scheduler_init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
fk_thread = NULL;
|
||||
fk_pid = -1;
|
||||
active_thread = NULL;
|
||||
thread_pid = -1;
|
||||
for (i = 0; i < SCHED_PRIO_LEVELS; i++) {
|
||||
runqueues[i] = NULL;
|
||||
}
|
||||
@ -54,19 +54,19 @@ void scheduler_init() {
|
||||
printf("[OK]\n");
|
||||
}
|
||||
|
||||
void fk_schedule() {
|
||||
fk_context_switch_request = 0;
|
||||
void sched_run() {
|
||||
sched_context_switch_request = 0;
|
||||
|
||||
tcb *my_fk_thread = (tcb*)fk_thread;
|
||||
tcb *my_active_thread = (tcb*)active_thread;
|
||||
|
||||
if (my_fk_thread) {
|
||||
if( my_fk_thread->status == 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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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
|
||||
|
@ -28,25 +28,25 @@ and the mailinglist (subscription via web site)
|
||||
#include <board.h>
|
||||
#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;
|
||||
|
@ -37,7 +37,7 @@ and the mailinglist (subscription via web site)
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <scheduler.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <cpu-conf.h>
|
||||
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ int main(void)
|
||||
if (i % 100 == 0) {
|
||||
printf("Waking up sleeper.\n");
|
||||
thread_wakeup(pid);
|
||||
fk_yield();
|
||||
thread_yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <hwtimer.h>
|
||||
#include <swtimer.h>
|
||||
#include <scheduler.h>
|
||||
#include <sched.h>
|
||||
|
||||
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");
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <thread.h>
|
||||
#include <hwtimer.h>
|
||||
#include <scheduler.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <thread.h>
|
||||
#include <hwtimer.h>
|
||||
#include <swtimer.h>
|
||||
#include <scheduler.h>
|
||||
#include <sched.h>
|
||||
#include <cpu.h>
|
||||
#include <irq.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user