kernel.h

Go to the documentation of this file.
00001 /**
00002  * @file   kernel.h
00003  *
00004  * @brief kernel data structures used in os.c.
00005  *
00006  * CSC 460/560 Real Time Operating Systems - Mantis Cheng
00007  *
00008  * @author Scott Craig
00009  * @author Justin Tanner
00010  */
00011 #ifndef __KERNEL_H__
00012 #define __KERNEL_H__
00013 
00014 #include <avr/io.h>
00015 #include "os.h"
00016 
00017 /** Disable default prescaler to make processor speed 8 MHz. */
00018 #define CLOCK8MHZ()    CLKPR = (1<<CLKPCE); CLKPR = 0x00;
00019 
00020 #define F_CPU 8000000UL
00021 
00022 #define Disable_Interrupt()     asm volatile ("cli"::)
00023 #define Enable_Interrupt()     asm volatile ("sei"::)
00024 
00025 /** The maximum number of names. Currently the same as the number of tasks. */
00026 #define     MAXNAME     MAXPROCESS
00027 
00028 /** The number of clock cycles in one "tick" or 5 ms */
00029 #define TICK_CYCLES     (F_CPU / 1000 * TICK)
00030 
00031 /** LEDs for OS_Abort() */
00032 #define LED_RED_MASK    (uint8_t)(_BV(4) | _BV(7))
00033 
00034 /** LEDs for OS_Abort() */
00035 #define LED_GREEN_MASK    (uint8_t)(_BV(5) | _BV(6))
00036 
00037 
00038 /* Typedefs and data structures. */
00039 
00040 typedef void (*voidfuncvoid_ptr) (void);      /* pointer to void f(void) */
00041 
00042 /**
00043  * @brief This is the set of states that a task can be in at any given time.
00044  */
00045 typedef enum
00046 {
00047     DEAD = 0,
00048     RUNNING,
00049     READY,
00050     WAITING
00051 }
00052 task_state_t;
00053 
00054 /**
00055  * @brief This is the set of kernel requests, i.e., a request code for each system call.
00056  */
00057 typedef enum
00058 {
00059     NONE = 0,
00060     TIMER_EXPIRED,
00061     TASK_CREATE,
00062     TASK_TERMINATE,
00063     TASK_NEXT,
00064     TASK_GET_ARG,
00065     EVENT_INIT,
00066     EVENT_WAIT,
00067     EVENT_SIGNAL,
00068     EVENT_BROADCAST,
00069     EVENT_SIGNAL_AND_NEXT,
00070     EVENT_BROADCAST_AND_NEXT
00071 }
00072 kernel_request_t;
00073 
00074 
00075 /**
00076  * @brief The arguments required to create a task.
00077  */
00078 typedef struct
00079 {
00080     /** The code the new task is to run.*/
00081     voidfuncvoid_ptr f;
00082     /** A new task may be created with an argument that it can retrieve later. */
00083     int arg;
00084     /** Priority of the new task: RR, PERIODIC, SYSTEM */
00085     uint8_t level;
00086     /** If the new task is PERIODIC, this is its name in the PPP array. */
00087     uint8_t name;
00088 }
00089 create_args_t;
00090 
00091 
00092 typedef struct td_struct task_descriptor_t;
00093 /**
00094  * @brief All the data needed to describe the task, including its context.
00095  */
00096 struct td_struct
00097 {
00098     /** The stack used by the task. SP points in here when task is RUNNING. */
00099     uint8_t                         stack[WORKSPACE];
00100     /** A variable to save the hardware SP into when the task is suspended. */
00101     uint8_t*               volatile sp;   /* stack pointer into the "workSpace" */
00102     /** PERIODIC tasks need a name in the PPP array. */
00103     uint8_t                         name;
00104     /** The state of the task in this descriptor. */
00105     task_state_t                    state;
00106     /** The argument passed to Task_Create for this task. */
00107     int                             arg;
00108     /** The priority (type) of this task. */
00109     uint8_t                         level;
00110     /** A link to the next task descriptor in the queue holding this task. */
00111     task_descriptor_t*              next;
00112 };
00113 
00114 
00115 /**
00116  * @brief Contains pointers to head and tail of a linked list.
00117  */
00118 typedef struct
00119 {
00120     /** The first item in the queue. NULL if the queue is empty. */
00121     task_descriptor_t*  head;
00122     /** The last item in the queue. Undefined if the queue is empty. */
00123     task_descriptor_t*  tail;
00124 }
00125 queue_t;
00126 
00127 
00128 #endif
00129 

Generated on Tue Oct 23 21:49:51 2007 for RTOS by  doxygen 1.5.1