1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge branch 'master' of ssh://ukleos.des-mesh.net/home/git/ukleos

This commit is contained in:
Oliver Hahm 2010-11-18 17:34:13 +01:00
commit c1546b1631
7 changed files with 67 additions and 60 deletions

View File

@ -78,8 +78,6 @@ int main(int argc, char **argv)
char* port_name = argv[1];
char* file_name = argv[2];
sleep(1);
if (open_serial_port(port_name) < 0) {
return(1);
}

View File

@ -25,6 +25,7 @@ void sched_init();
void sched_run();
void sched_set_status(tcb *process, unsigned int status);
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr);
volatile unsigned int sched_context_switch_request;

View File

@ -20,6 +20,7 @@
#include "tcb.h"
#include "kernel.h"
#include "sched.h"
#include <irq.h>
//#define ENABLE_DEBUG
#include <debug.h>
@ -36,48 +37,27 @@ int mutex_init(struct mutex_t* mutex) {
int mutex_trylock(struct mutex_t* mutex) {
DEBUG("%s: trylocking to get mutex. val: %u\n", active_thread->name, mutex->val);
return (atomic_set_return(&mutex->val, thread_pid ) == 0);
}
int prio() {
return active_thread->priority;
return atomic_set_return(&mutex->val, 1 ) == 0;
}
int mutex_lock(struct mutex_t* mutex) {
DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val);
if (atomic_set_return(&mutex->val,thread_pid) != 0) {
if (atomic_set_return(&mutex->val,1) != 0) {
// mutex was locked.
mutex_wait(mutex);
}
return 1;
}
void mutex_unlock(struct mutex_t* mutex, int yield) {
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 = thread_pid;
}
if (atomic_set_return(&mutex->val,0) != me_value ) {
// there were waiters.
mutex_wake_waiters(mutex, yield);
}
}
void mutex_wait(struct mutex_t *mutex) {
dINT();
int irqstate = disableIRQ();
DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val);
if (mutex->val == 0) {
// somebody released the mutex. return.
mutex->val = thread_pid;
DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val);
eINT();
restoreIRQ(irqstate);
return;
}
@ -88,49 +68,34 @@ void mutex_wait(struct mutex_t *mutex) {
n.data = (unsigned int) active_thread;
n.next = NULL;
DEBUG("%s: Adding node to mutex queue: prio: %u data: %u\n", active_thread->name, n.priority, n.data);
DEBUG("%s: Adding node to mutex queue: prio: %u\n", active_thread->name, n.priority);
queue_priority_add(&(mutex->queue), &n);
eINT();
restoreIRQ(irqstate);
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", active_thread->name);
void mutex_unlock(struct mutex_t* mutex, int yield) {
DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid);
int irqstate = disableIRQ();
if (mutex->val != 0) {
if (mutex->queue.next) {
queue_node_t *next = queue_remove_head(&(mutex->queue));
tcb* process = (tcb*)next->data;
DEBUG("%s: waking up waiter %s.\n", process->name);
sched_set_status(process, STATUS_PENDING);
queue_node_t *next = queue_remove_head(&(mutex->queue));
/* queue is empty */
if (!next) {
DEBUG("%s: no waiters?\n", active_thread->name);
mutex->val = 0;
if ( ! (flags & MUTEX_INISR)) eINT();
return;
sched_switch(active_thread->priority, process->priority, inISR());
} else {
mutex->val = 0;
}
}
tcb* process = (tcb*)next->data;
sched_set_status(process, STATUS_PENDING);
if ( mutex->queue.next != NULL) {
mutex->val = -1;
} else {
mutex->val = process->pid;
}
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) thread_yield();
} else {
sched_context_switch_request = 1;
}
restoreIRQ(irqstate);
}

View File

@ -56,7 +56,7 @@ void queue_priority_add(queue_node_t* root, queue_node_t* new_obj) {
queue_node_t* node = root;
while (node->next != NULL) {
if (node->next->priority < new_obj->priority) {
if (node->next->priority > new_obj->priority) {
new_obj->next = node->next;
node->next = new_obj;
return;

View File

@ -143,6 +143,17 @@ void sched_set_status(tcb *process, unsigned int status) {
process->status = status;
}
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr) {
DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr);
if (current_prio <= other_prio) {
if (in_isr) {
sched_context_switch_request = 1;
} else {
thread_yield();
}
}
}
extern void cpu_switch_context_exit(void);
void sched_task_exit(void) {

5
projects/laser/Jamfile Normal file
View File

@ -0,0 +1,5 @@
SubDir TOP projects laser ;
Module laser : main.c : sht11 swtimer auto_init ;
UseModule laser ;

27
projects/laser/main.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <sht11.h>
#include <board.h>
#include <swtimer.h>
int main(void)
{
sht11_val_t sht11_val;
uint8_t success = 0;
puts("");
puts("LaSeR: Longterm Sensor Reader initialized.");
puts("Printing \"temperature in °C;relative humidity;temperature compensated relative humidity\".");
puts("");
while (1) {
success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE);
if (!success) {
printf("error;error;error\n");
}
else {
printf("%.2f;%.2f;%.2f\n", sht11_val.temperature, sht11_val.relhum, sht11_val.relhum_temp);
}
LED_RED_TOGGLE;
swtimer_usleep(1000 * 1000);
}
}