diff --git a/conts/baremetal/timer_service/main.c b/conts/baremetal/timer_service/main.c index d628159..3b6c74b 100644 --- a/conts/baremetal/timer_service/main.c +++ b/conts/baremetal/timer_service/main.c @@ -5,8 +5,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -15,6 +17,7 @@ #include "sp804_timer.h" #include #include +#include /* Frequency of timer in MHz */ #define TIMER_FREQUENCY 1 @@ -25,7 +28,6 @@ static struct capability caparray[32]; static int total_caps = 0; static struct timer timer[TIMERS_TOTAL]; -static int notify_slot = 0; int cap_read_all() { @@ -81,9 +83,11 @@ int timer_probe_devices(void) return 0; } -void timer_irq_handler(void *arg) +int timer_irq_handler(void *arg) { + int err; struct timer *timer = (struct timer *)arg; + const int slot = 0; /* Initialise timer */ sp804_init(timer->base, SP804_TIMER_RUNMODE_PERIODIC, @@ -91,8 +95,8 @@ void timer_irq_handler(void *arg) SP804_TIMER_WIDTH32BIT, SP804_TIMER_IRQENABLE); /* Register self for timer irq, using notify slot 0 */ - if ((err = l4_irq_control(IRQ_CONTROL_REGISTER, 0, - timer->cap.irqnum)) < 0) { + if ((err = l4_irq_control(IRQ_CONTROL_REGISTER, slot, + timer->cap.irq)) < 0) { printf("%s: FATAL: Timer irq could not be registered. " "err=%d\n", __FUNCTION__, err); BUG(); @@ -106,7 +110,7 @@ void timer_irq_handler(void *arg) int count; /* Block on irq */ - count = l4_irq_wait(timer->cap.irqnum); + count = l4_irq_wait(slot, timer->cap.irq); /* Update timer count */ timer->count += count; @@ -120,12 +124,13 @@ void timer_irq_handler(void *arg) int timer_setup_devices(void) { struct task_ids irq_tids; + int err; for (int i = 0; i < TIMERS_TOTAL; i++) { /* Get one page from address pool */ timer[i].base = (unsigned long)l4_new_virtual(1); timer[i].count = 0; - link_init(&timer[i].tasklist); + link_init(&timer[i].task_list); l4_mutex_init(&timer[i].lock); /* Map timer to a virtual address region */ @@ -136,7 +141,7 @@ int timer_setup_devices(void) printf("%s: FATAL: Failed to map TIMER device " "%d to a virtual address\n", __CONTAINER_NAME__, - cap_devnum(&timer_cap[i])); + cap_devnum(&timer[i].cap)); BUG(); } @@ -148,7 +153,7 @@ int timer_setup_devices(void) * wait on irqs. */ if ((err = thread_create(timer_irq_handler, &timer[i], - TC_SHARED_SPACE, + TC_SHARE_SPACE, &irq_tids)) < 0) { printf("FATAL: Creation of irq handler " "thread failed.\n"); diff --git a/conts/baremetal/timer_service/src/thread.c b/conts/baremetal/timer_service/src/thread.c index 126d61b..5a865d9 100644 --- a/conts/baremetal/timer_service/src/thread.c +++ b/conts/baremetal/timer_service/src/thread.c @@ -14,8 +14,8 @@ char *__utcb_ptr = &utcb[1][0]; extern void local_setup_new_thread(void); -l4id_t thread_create(int (*func)(void *), void *args, unsigned int flags, - struct task_ids *new_ids) +int thread_create(int (*func)(void *), void *args, unsigned int flags, + struct task_ids *new_ids) { struct task_ids ids; struct exregs_data exregs; @@ -44,10 +44,10 @@ l4id_t thread_create(int (*func)(void *), void *args, unsigned int flags, return -ENOMEM; /* First word of new stack is arg */ - *(((unsigned long *)__stack_ptr)[-1]) = (unsigned long)args; + ((unsigned long *)__stack_ptr)[-1] = (unsigned long)args; /* Second word of new stack is function address */ - *(((unsigned long *)__stack_ptr)[-2]) = (unsigned long)func; + ((unsigned long *)__stack_ptr)[-2] = (unsigned long)func; /* Setup new thread pc, sp, utcb */ memset(&exregs, 0, sizeof(exregs)); @@ -63,9 +63,8 @@ l4id_t thread_create(int (*func)(void *), void *args, unsigned int flags, __utcb_ptr += UTCB_SIZE; /* Start the new thread */ - if (flags & THREAD_RUN) - if ((err = l4_thread_control(THREAD_RUN, &ids)) < 0) - return err; + if ((err = l4_thread_control(THREAD_RUN, &ids)) < 0) + return err; memcpy(new_ids, &ids, sizeof(ids)); diff --git a/conts/libl4/include/l4lib/irq.h b/conts/libl4/include/l4lib/irq.h new file mode 100644 index 0000000..3876f2e --- /dev/null +++ b/conts/libl4/include/l4lib/irq.h @@ -0,0 +1,7 @@ +#ifndef __L4LIB_IRQ_H__ +#define __L4LIB_IRQ_H__ + + +int l4_irq_wait(int slot, int irqnum); + +#endif /* __L4LIB_IRQ_H__ */ diff --git a/conts/libl4/src/irq.c b/conts/libl4/src/irq.c index 3fad05c..6eed241 100644 --- a/conts/libl4/src/irq.c +++ b/conts/libl4/src/irq.c @@ -11,7 +11,7 @@ * Reads the irq notification slot. Destructive atomic read ensures that * an irq may write to the slot in sync. */ -int l4_irq_read_blocking(int slot, int irqnum) +int l4_irq_wait(int slot, int irqnum) { int irqval = l4_atomic_dest_readb(&l4_get_utcb()->notify[slot]);