atom.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Kelvin Lawson. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. No personal names or organizations' names associated with the
00014  *    Atomthreads project may be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef __ATOM_H
00031 #define __ATOM_H
00032 
00033 #include "atomtimer.h"
00034 #include "atomport.h"
00035 
00036 /* Data types */
00037 
00038 /* Forward declaration */
00039 struct atom_tcb;
00040 
00041 typedef struct atom_tcb
00042 {
00043     /* Thread's current stack pointer. When a thread is scheduled
00044      * out the architecture port can save*/
00045     POINTER sp_save_ptr;
00046 
00047     /* Thread priority (0-255) */
00048     uint8_t priority;
00049 
00050     /* Thread entry point and parameter */
00051     void (*entry_point)(uint32_t);
00052     uint32_t entry_param;
00053 
00054     /* Queue pointers */
00055     struct atom_tcb *prev_tcb;    /* Previous TCB in doubly-linked TCB list */
00056     struct atom_tcb *next_tcb;    /* Next TCB in doubly-linked list */
00057 
00058     /* Suspension data */
00059     uint8_t suspended;            /* TRUE if task is currently suspended */
00060     uint8_t suspend_wake_status;  /* Status returned to woken suspend calls */
00061     ATOM_TIMER *suspend_timo_cb;  /* Callback registered for suspension timeouts */
00062 
00063     /* Details used if thread stack-checking is required */
00064 #ifdef ATOM_STACK_CHECKING
00065     POINTER stack_top;            /* Pointer to top of stack allocation */
00066     uint32_t stack_size;          /* Size of stack allocation in bytes */
00067 #endif
00068 
00069 } ATOM_TCB;
00070 
00071 
00072 /* Global data */
00073 extern ATOM_TCB *tcbReadyQ;
00074 extern uint8_t atomOSStarted;
00075 
00076 
00077 /* Constants */
00078 #define TRUE                    1
00079 #define FALSE                   0
00080 
00081 /* Error values */
00082 
00083 #define ATOM_OK                 0
00084 #define ATOM_ERROR              1
00085 #define ATOM_TIMEOUT            2
00086 #define ATOM_WOULDBLOCK         3
00087 #define ATOM_ERR_CONTEXT        200
00088 #define ATOM_ERR_PARAM          201
00089 #define ATOM_ERR_DELETED        202
00090 #define ATOM_ERR_OVF            203
00091 #define ATOM_ERR_QUEUE          204
00092 #define ATOM_ERR_TIMER          205
00093 #define ATOM_ERR_NOT_FOUND      206
00094 #define ATOM_ERR_OWNERSHIP      207
00095 
00096 /* Idle thread priority (lowest) */
00097 #define IDLE_THREAD_PRIORITY    255
00098 
00099 
00100 /* Function prototypes */
00101 extern uint8_t atomOSInit (void *idle_thread_stack_top, uint32_t stack_size);
00102 extern void atomOSStart (void);
00103 
00104 extern void atomSched (uint8_t timer_tick);
00105 
00106 extern void atomIntEnter (void);
00107 extern void atomIntExit (uint8_t timer_tick);
00108 
00109 extern uint8_t tcbEnqueuePriority (ATOM_TCB **tcb_queue_ptr, ATOM_TCB *tcb_ptr);
00110 extern ATOM_TCB *tcbDequeueHead (ATOM_TCB **tcb_queue_ptr);
00111 extern ATOM_TCB *tcbDequeueEntry (ATOM_TCB **tcb_queue_ptr, ATOM_TCB *tcb_ptr);
00112 extern ATOM_TCB *tcbDequeuePriority (ATOM_TCB **tcb_queue_ptr, uint8_t priority);
00113 
00114 extern ATOM_TCB *atomCurrentContext (void);
00115 
00116 extern uint8_t atomThreadCreate (ATOM_TCB *tcb_ptr, uint8_t priority, void (*entry_point)(uint32_t), uint32_t entry_param, void *stack_top, uint32_t stack_size);
00117 extern uint8_t atomThreadStackCheck (ATOM_TCB *tcb_ptr, uint32_t *used_bytes, uint32_t *free_bytes);
00118 
00119 extern void archContextSwitch (ATOM_TCB *old_tcb_ptr, ATOM_TCB *new_tcb_ptr);
00120 extern void archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_point)(uint32_t), uint32_t entry_param);
00121 extern void archFirstThreadRestore(ATOM_TCB *new_tcb_ptr);
00122 
00123 extern void atomTimerTick (void);
00124 
00125 
00126 #endif /* __ATOM_H */

Generated on Fri Jun 4 01:00:01 2010 for atomthreads by  doxygen 1.6.1