diff options
author | Jakob Odersky <jodersky@gmail.com> | 2014-04-08 13:18:27 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2014-04-08 14:57:10 +0200 |
commit | 350437ef4b8ba0811d285f7454d2b54ffce6b029 (patch) | |
tree | 5084c73adbb4cc3aee9d000b3816d98a57203f36 /kernel | |
parent | c4ebb91caf33ecf5a47785584a4231eb1e4dfa2a (diff) | |
download | mux-350437ef4b8ba0811d285f7454d2b54ffce6b029.tar.gz mux-350437ef4b8ba0811d285f7454d2b54ffce6b029.tar.bz2 mux-350437ef4b8ba0811d285f7454d2b54ffce6b029.zip |
change build structure
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/bug/include/bug/debug.h | 6 | ||||
-rw-r--r-- | kernel/bug/include/bug/panic.h | 6 | ||||
-rw-r--r-- | kernel/include/init.h | 10 | ||||
-rw-r--r-- | kernel/include/mux/clock.h (renamed from kernel/time/include/time/clock.h) | 4 | ||||
-rw-r--r-- | kernel/include/mux/debug.h | 7 | ||||
-rw-r--r-- | kernel/include/mux/idle.h | 6 | ||||
-rw-r--r-- | kernel/include/mux/io.h (renamed from kernel/io/include/io/io.h) | 4 | ||||
-rw-r--r-- | kernel/include/mux/list.h (renamed from kernel/collection/include/collection/list.h) | 4 | ||||
-rw-r--r-- | kernel/include/mux/lock.h (renamed from kernel/task/include/task/lock.h) | 6 | ||||
-rw-r--r-- | kernel/include/mux/rbuffer.h (renamed from kernel/collection/include/collection/rbuffer.h) | 0 | ||||
-rw-r--r-- | kernel/include/mux/sched.h (renamed from kernel/task/include/task/sched.h) | 55 | ||||
-rw-r--r-- | kernel/init.c | 29 | ||||
-rw-r--r-- | kernel/io/io.c | 12 | ||||
-rw-r--r-- | kernel/mcu/atmega2560/clock.c (renamed from kernel/time/mcu/atmega2560/clock.c) | 6 | ||||
-rw-r--r-- | kernel/mcu/atmega2560/context.c (renamed from kernel/task/mcu/atmega2560/context.c) | 2 | ||||
-rw-r--r-- | kernel/mcu/atmega2560/include/mcu/context.h (renamed from kernel/task/mcu/atmega2560/include/mcu/task/context.h) | 6 | ||||
-rw-r--r-- | kernel/mcu/atmega2560/include/mcu/usart.h (renamed from kernel/io/mcu/atmega2560/include/mcu/io/usart.h) | 2 | ||||
-rw-r--r-- | kernel/mcu/atmega2560/usart.c (renamed from kernel/io/mcu/atmega2560/usart.c) | 12 | ||||
-rw-r--r-- | kernel/sched/idle.c (renamed from kernel/task/idle.c) | 4 | ||||
-rw-r--r-- | kernel/sched/sched.c (renamed from kernel/task/sched.c) | 18 | ||||
-rw-r--r-- | kernel/task/include/task/idle.h | 6 | ||||
-rw-r--r-- | kernel/task/include/task/task.h | 46 | ||||
-rw-r--r-- | kernel/task/mcu/atmega2560/include/mcu/task/task.h | 11 | ||||
-rw-r--r-- | kernel/tshield/include/tshield/tshield.h | 51 | ||||
-rw-r--r-- | kernel/tshield/mcu/atmega2560/tshield.c | 140 |
25 files changed, 145 insertions, 308 deletions
diff --git a/kernel/bug/include/bug/debug.h b/kernel/bug/include/bug/debug.h deleted file mode 100644 index 854f4c6..0000000 --- a/kernel/bug/include/bug/debug.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef DEBUG_H -#define DEBUG_H - -void debug_led(int led, int value); - -#endif
\ No newline at end of file diff --git a/kernel/bug/include/bug/panic.h b/kernel/bug/include/bug/panic.h deleted file mode 100644 index 2a39076..0000000 --- a/kernel/bug/include/bug/panic.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PANIC_H -#define PANIC_H - -void panic(); - -#endif
\ No newline at end of file diff --git a/kernel/include/init.h b/kernel/include/init.h new file mode 100644 index 0000000..8df22f5 --- /dev/null +++ b/kernel/include/init.h @@ -0,0 +1,10 @@ +#ifndef MUX_INIT_H +#define MUX_INIT_H + +#include <stddef.h> + +void setup(); +void task1(char args); +void task2(char args); + +#endif
\ No newline at end of file diff --git a/kernel/time/include/time/clock.h b/kernel/include/mux/clock.h index 0a247a8..429a00d 100644 --- a/kernel/time/include/time/clock.h +++ b/kernel/include/mux/clock.h @@ -1,5 +1,5 @@ -#ifndef CLOCK_H -#define CLOCK_H +#ifndef MUX_CLOCK_H +#define MUX_CLOCK_H /** * Initializes main system clock. diff --git a/kernel/include/mux/debug.h b/kernel/include/mux/debug.h new file mode 100644 index 0000000..7119c35 --- /dev/null +++ b/kernel/include/mux/debug.h @@ -0,0 +1,7 @@ +#ifndef MUX_DEBUG_H +#define MUX_DEBUG_H + +void panic(); +void debug_led(int led, int value); + +#endif
\ No newline at end of file diff --git a/kernel/include/mux/idle.h b/kernel/include/mux/idle.h new file mode 100644 index 0000000..0d94a9a --- /dev/null +++ b/kernel/include/mux/idle.h @@ -0,0 +1,6 @@ +#ifndef MUX_IDLE_H +#define MUX_IDLE_H + +void idle_entry(char args); + +#endif
\ No newline at end of file diff --git a/kernel/io/include/io/io.h b/kernel/include/mux/io.h index 3c83cdc..4ec45f5 100644 --- a/kernel/io/include/io/io.h +++ b/kernel/include/mux/io.h @@ -1,5 +1,5 @@ -#ifndef IO_H -#define IO_H +#ifndef MUX_IO_H +#define MUX_IO_H #include <stddef.h> diff --git a/kernel/collection/include/collection/list.h b/kernel/include/mux/list.h index 3a76885..98ea766 100644 --- a/kernel/collection/include/collection/list.h +++ b/kernel/include/mux/list.h @@ -1,5 +1,5 @@ -#ifndef __LIST_H -#define __LIST_H +#ifndef MUX_LIST_H +#define MUX_LIST_H /* This file is from Linux Kernel (include/linux/list.h) * and modified by simply removing hardware prefetching of list items. diff --git a/kernel/task/include/task/lock.h b/kernel/include/mux/lock.h index 47246b2..b5ac4d9 100644 --- a/kernel/task/include/task/lock.h +++ b/kernel/include/mux/lock.h @@ -1,7 +1,7 @@ -#ifndef LOCK_H -#define LOCK_H +#ifndef MUX_LOCK_H +#define MUX_LOCK_H -#include "task/sched.h" +#include "mux/sched.h" typedef volatile char spin_lock_t; diff --git a/kernel/collection/include/collection/rbuffer.h b/kernel/include/mux/rbuffer.h index dceaeb0..dceaeb0 100644 --- a/kernel/collection/include/collection/rbuffer.h +++ b/kernel/include/mux/rbuffer.h diff --git a/kernel/task/include/task/sched.h b/kernel/include/mux/sched.h index b8946db..de50f98 100644 --- a/kernel/task/include/task/sched.h +++ b/kernel/include/mux/sched.h @@ -1,9 +1,47 @@ -#ifndef SCHED_H -#define SCHED_H +#ifndef MUX_SCHED_H +#define MUX_SCHED_H + +#include "mux/list.h" + +/** + * Task control block, contains runtime + * information about tasks. + */ +struct tcb_t { + /** Stack pointer of this task. (must be first in structure) */ + char* volatile sp; + + /** Lowest address of this task's memory (inclusive). */ + char* mem_low; + + /** Highest address of this task's memory (inclusive). */ + char* mem_high; + + /** Entry function of this task. */ + void (*entry)(char); + + /** Current wait queue that this task is in.*/ + struct list_head queue; + + /** ID of task. */ + char id; + +}; + +/** + * Utility for declaring a task with statically allocated memory. + * Note: for a task to be scheduled, it must first be spawned (see spawn()). +*/ +#define DECLARE_TASK(name, stack_size, entry_function) \ + static char _declared_stack_##name[stack_size]; \ + static struct tcb_t name = { \ + .sp = 0, \ + .mem_low = _declared_stack_##name, \ + .mem_high = _declared_stack_##name + stack_size - 1, \ + .entry = entry_function, \ + .queue = {} \ + }; -#include "collection/list.h" -#include "task/task.h" -#include "mcu/task/task.h" /** * Points to currently executing task. If no scheduling has been enabled, @@ -36,7 +74,12 @@ static inline void wake_all_queue(struct list_head* queue) { /** * Initializes a given task and adds it to the ready queue. */ -void spawn(struct tcb_t* const tcb); +void spawn(struct tcb_t* const tcb, char id); + +/** + * Spawns the idle task + */ +void spawn_idle(struct tcb_t* const tcb, char id); /** * Voluntarily relinquishes control of the CPU from the current task to the scheduler. diff --git a/kernel/init.c b/kernel/init.c new file mode 100644 index 0000000..5a9a2e9 --- /dev/null +++ b/kernel/init.c @@ -0,0 +1,29 @@ +#include "init.h" +#include "mux/debug.h" +#include "mux/sched.h" +#include "mux/idle.h" +#include "mux/clock.h" +#include "mcu/context.h" + +#define HZ 100 + +DECLARE_TASK(task_idle, IDLE_STACK_SIZE, idle_entry); +DECLARE_TASK(tcb1, DEFAULT_STACK_SIZE, task1); +DECLARE_TASK(tcb2, DEFAULT_STACK_SIZE, task2); + +int main(int argc, char *argv[]) { + cli(); + + setup(); + + spawn_idle(&task_idle, 0); + spawn(&tcb1, 1); + spawn(&tcb2, 2); + + sei(); + clock_init(1000/HZ, schedule); + clock_start(); + sched_init(); + panic(); //should never reach here + while(1){} +}
\ No newline at end of file diff --git a/kernel/io/io.c b/kernel/io/io.c index f39168b..63e9669 100644 --- a/kernel/io/io.c +++ b/kernel/io/io.c @@ -1,25 +1,25 @@ -#include "io/io.h" +#include "mux/io.h" int open(struct file* file) { - file->fops->open(file); + return file->fops->open(file); } int ioctl(struct file* file, int cmd, long args) { - file->fops->ioctl(file, cmd, args); + return file->fops->ioctl(file, cmd, args); } ssize_t read(struct file* file, char* const buffer, size_t size) { struct file_operations* fops = file->fops; if (fops->read == NULL) return -1; - else fops->read(file, buffer, size); + else return fops->read(file, buffer, size); } ssize_t write(struct file* file, const char* const buffer, size_t size) { struct file_operations* fops = file->fops; if (fops->write == NULL) return -1; - else fops->write(file, buffer, size); + else return fops->write(file, buffer, size); } int close(struct file* file) { - file->fops->close(file); + return file->fops->close(file); }
\ No newline at end of file diff --git a/kernel/time/mcu/atmega2560/clock.c b/kernel/mcu/atmega2560/clock.c index 95622dc..4f53372 100644 --- a/kernel/time/mcu/atmega2560/clock.c +++ b/kernel/mcu/atmega2560/clock.c @@ -1,7 +1,7 @@ #include <avr/interrupt.h> -#include "time/clock.h" -#include "task/sched.h" -#include "mcu/task/context.h" +#include "mux/clock.h" +#include "mux/sched.h" +#include "mcu/context.h" static void (*on_tick)(); diff --git a/kernel/task/mcu/atmega2560/context.c b/kernel/mcu/atmega2560/context.c index 9bb7036..137a985 100644 --- a/kernel/task/mcu/atmega2560/context.c +++ b/kernel/mcu/atmega2560/context.c @@ -1,4 +1,4 @@ -#include "mcu/task/context.h" +#include "mcu/context.h" char* stack_init(const char* const mem_low, const char* const mem_high, void (*entry)(char), char args) { char* sp = (char*) mem_high; diff --git a/kernel/task/mcu/atmega2560/include/mcu/task/context.h b/kernel/mcu/atmega2560/include/mcu/context.h index 0de1fb4..5f6e947 100644 --- a/kernel/task/mcu/atmega2560/include/mcu/task/context.h +++ b/kernel/mcu/atmega2560/include/mcu/context.h @@ -4,6 +4,12 @@ #include <avr/interrupt.h> #define ret() asm volatile ( "ret" ) +/** Default stack size, you may use this definition for declaring tasks. */ +#define DEFAULT_STACK_SIZE 256 + +/** Stack size to be allocated for the idle task. */ +#define IDLE_STACK_SIZE 64 + /* * The macros save_context(), restore_context() as well as the code contained in * init_stack is adapted from the FreeRTOS kernel (http://www.freertos.org/). diff --git a/kernel/io/mcu/atmega2560/include/mcu/io/usart.h b/kernel/mcu/atmega2560/include/mcu/usart.h index 6b210fe..e06f0cf 100644 --- a/kernel/io/mcu/atmega2560/include/mcu/io/usart.h +++ b/kernel/mcu/atmega2560/include/mcu/usart.h @@ -1,7 +1,7 @@ #ifndef MCU_USART #define MCU_USART -#include "io/io.h" +#include "mux/io.h" #define USART_BUFFER_SIZE 64 #define IOCTL_SET_BAUD 0 diff --git a/kernel/io/mcu/atmega2560/usart.c b/kernel/mcu/atmega2560/usart.c index 6f59787..f07e137 100644 --- a/kernel/io/mcu/atmega2560/usart.c +++ b/kernel/mcu/atmega2560/usart.c @@ -1,9 +1,9 @@ -#include "io/io.h" -#include "collection/list.h" -#include "collection/rbuffer.h" -#include "task/sched.h" -#include "mcu/io/usart.h" -#include "mcu/task/context.h" +#include "mux/io.h" +#include "mux/list.h" +#include "mux/rbuffer.h" +#include "mux/sched.h" +#include "mcu/usart.h" +#include "mcu/context.h" #include <avr/interrupt.h> #include <avr/io.h> diff --git a/kernel/task/idle.c b/kernel/sched/idle.c index 7d6576d..aaf4337 100644 --- a/kernel/task/idle.c +++ b/kernel/sched/idle.c @@ -2,8 +2,8 @@ #include <avr/interrupt.h> #include <avr/sleep.h> #include <avr/power.h> -#include "task/idle.h" -#include "task/task.h" +#include "mux/idle.h" +#include "mux/sched.h" void idle_entry(char args) { diff --git a/kernel/task/sched.c b/kernel/sched/sched.c index 5989136..4b36f03 100644 --- a/kernel/task/sched.c +++ b/kernel/sched/sched.c @@ -1,7 +1,5 @@ -#include "bug/panic.h" -#include "task/task.h" -#include "task/sched.h" -#include "mcu/task/context.h" +#include "mux/sched.h" +#include "mcu/context.h" struct tcb_t* volatile current = 0; @@ -10,15 +8,19 @@ static struct tcb_t* volatile idle = 0; struct list_head ready = LIST_HEAD_INIT(ready); -void spawn(struct tcb_t* const tcb) { +static void _spawn(struct tcb_t* const tcb, char id) { + tcb->id = id; tcb->sp = stack_init(tcb->mem_low, tcb->mem_high, tcb->entry, tcb->id); INIT_LIST_HEAD(&tcb->queue); +} + +void spawn(struct tcb_t* const tcb, char id) { + _spawn(tcb, id); list_add_tail(&tcb->queue, &ready); } -void spawn_idle(struct tcb_t* const tcb) { - spawn(tcb); - list_del(&tcb->queue); +void spawn_idle(struct tcb_t* const tcb, char id) { + _spawn(tcb, id); idle = tcb; } diff --git a/kernel/task/include/task/idle.h b/kernel/task/include/task/idle.h deleted file mode 100644 index 3b6e40a..0000000 --- a/kernel/task/include/task/idle.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef IDLE_H -#define IDLE_H - -void idle_entry(char args); - -#endif
\ No newline at end of file diff --git a/kernel/task/include/task/task.h b/kernel/task/include/task/task.h deleted file mode 100644 index 120bda4..0000000 --- a/kernel/task/include/task/task.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include "collection/list.h" - -/** - * Task control block, contains runtime - * information about tasks. - */ -struct tcb_t { - /** Stack pointer of this task. (must be first in structure) */ - char* volatile sp; - - /** Lowest address of this task's memory (inclusive). */ - char* mem_low; - - /** Highest address of this task's memory (inclusive). */ - char* mem_high; - - /** Entry function of this task. */ - void (*entry)(char); - - /** Current wait queue that this task is in.*/ - struct list_head queue; - - /** ID of task. */ - char id; - -}; - -/** - * Utility for declaring a task with statically allocated memory. - * Note: for a task to be scheduled, it must first be spawned (see spawn()). -*/ -#define DECLARE_TASK(name, stack_size, entry_function, pid) \ - static char _declared_stack_##name[stack_size]; \ - static struct tcb_t name = { \ - .sp = 0, \ - .mem_low = _declared_stack_##name, \ - .mem_high = _declared_stack_##name + stack_size - 1, \ - .entry = entry_function, \ - .queue = {}, \ - .id = pid \ - }; - -#endif
\ No newline at end of file diff --git a/kernel/task/mcu/atmega2560/include/mcu/task/task.h b/kernel/task/mcu/atmega2560/include/mcu/task/task.h deleted file mode 100644 index d9823af..0000000 --- a/kernel/task/mcu/atmega2560/include/mcu/task/task.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef MCU_TASK_H -#define MACU_TASK_H - - -/** Default stack size, you may use this definition for declaring tasks. */ -#define DEFAULT_STACK_SIZE 256 - -/** Stack size to be allocated for the idle task. */ -#define IDLE_STACK_SIZE 64 - -#endif
\ No newline at end of file diff --git a/kernel/tshield/include/tshield/tshield.h b/kernel/tshield/include/tshield/tshield.h deleted file mode 100644 index b485ad2..0000000 --- a/kernel/tshield/include/tshield/tshield.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TSHIElD_H -#define TSHIELD_H - -/* - * Custom test shield - * Pin mappings - * - * Leds (from left to right) - * ===== - * Color | Arduino pin | atmega2560 - * ---------------------------------- - * Green D6 PH3 - * Yellow D7 PH4 - * Red D5 PE3 - * Red D4 PG5 - * - * - * Buttons (from left to right) - * ===== - * Number | Arduino pin | atmega2560 - * --------------------------------- - * 0 D2 PE4 (INT4) - * 1 D8 PH5 - * 2 D10 PB4 - * - * Outputs (from top to bottom) - * ===== - * Type | Arduino pin | atmega2560 - * ------------------------------------------------------ - * Servo 11, Vcc, GND PB5 - * Diode protected (max 200mA) 12 PB6 - * - */ - -#define DEBUG_LEDS 4 -#define DEBUG_LED_IDLE 0 - -void tshield_init(); - -void tshield_test(); - -unsigned char tshield_read(); - -void tshield_led(unsigned char led, unsigned char value); - -void tshield_pp(unsigned char value); - -void tshield_servo(unsigned char angle); - - -#endif diff --git a/kernel/tshield/mcu/atmega2560/tshield.c b/kernel/tshield/mcu/atmega2560/tshield.c deleted file mode 100644 index 7cc6e58..0000000 --- a/kernel/tshield/mcu/atmega2560/tshield.c +++ /dev/null @@ -1,140 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include "tshield/tshield.h" -#include "bug/panic.h" - -static void tshield_init_servo(); - -void tshield_init() { - - DDRH |= (1 << 3) | (1 << 4); //leds - PORTH &= ~( (1 << 3) | (1 << 4)); - DDRE |= (1 << 3); - PORTE &= ~(1 << 3); - DDRG |= (1 << 5); - PORTG &= ~(1 << 5); - - DDRE &= ~(1 << 4); // buttons - PORTE |= (1 << 4); - DDRH &= ~(1 << 5); - PORTH |= (1 << 5); - DDRB &= ~(1 << 4); - PORTB |= (1 << 4); - - DDRB |= (1 << 6); - PORTB &= ~(1 << 6); - - tshield_init_servo(); -} - -#define WAIT_VALUE 20000 -#define WAIT() \ - for (volatile long x = 0; x < WAIT_VALUE; ++x){} - -void tshield_test() { - while(1) { - PORTG |= (1 << 5); - WAIT(); - PORTG &= ~(1 << 5); - PORTE |= (1 << 3); - WAIT(); - PORTE &= ~(1 << 3); - PORTH |= (1 << 3); - WAIT(); - PORTH &= ~(1 << 3); - PORTH |= (1 << 4); - WAIT(); - PORTH &= ~(1 << 4); - } - -} - -unsigned char tshield_read() { - return ((PINE & (1 << 4) ? 0 : 1) << 2 ) | - ((PINH & (1 << 5) ? 0 : 1) << 1 ) | - (PINB & (1 << 4) ? 0 : 1); -} - -void tshield_led(unsigned char led, unsigned char value) { - volatile unsigned char* port; - unsigned char bit; - switch (led) { - case 0: - port = &PORTG; - bit = 5; - break; - case 1: - port = &PORTE; - bit = 3; - break; - case 2: - port = &PORTH; - bit = 3; - break; - case 3: - port = &PORTH; - bit = 4; - break; - default: - return; - } - - if (value) { - *port |= (1 << bit); - } else { - *port &= ~(1 << bit); - } - -} - -void tshield_pp(unsigned char value) { - if (value) { - PORTB |= (1 << 6); - } else { - PORTB &= ~(1 << 6); - } -} - -void tshield_init_servo() { - - TCCR1A |= (1<<COM1A1); // non inverted pwm on channel A - TCCR1B |= (1<<CS11) | (1<<CS10); // prescaler 64 - - //fast pwm - TCCR1A |= (1<<WGM11); - TCCR1B|=(1<<WGM13) | (1<<WGM12); - - ICR1=4999; //fPWM=50Hz (Period = 20ms Standard). - - DDRB |= (1<< 5); -} - -void tshield_servo(unsigned char angle) { - unsigned long k = (unsigned long) angle; - unsigned long counter = (450 * k) / 255 + 150; - OCR1A = (unsigned int) counter; -} - -void debug_led(int led, int value) { - tshield_led(led, value); -} - -static inline void _wait() { - for (volatile long i = 0; i < 20000; ++i) {}; -} - -void panic() { - cli(); - while(1) { - for(int i = 0; i < DEBUG_LEDS; ++i) { - debug_led((i - 1) % DEBUG_LEDS, 0); - debug_led(i, 1); - _wait(); - } - for(int i = DEBUG_LEDS - 1; i >= 0; --i) { - debug_led((i + 1) % DEBUG_LEDS, 0); - debug_led(i, 1); - _wait(); - } - } -}
\ No newline at end of file |