atom.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef __ATOM_H
00031 #define __ATOM_H
00032 
00033 #include "atomtimer.h"
00034 #include "atomport.h"
00035 
00036 
00037 
00038 
00039 struct atom_tcb;
00040 
00041 typedef struct atom_tcb
00042 {
00043     
00044 
00045     POINTER sp_save_ptr;
00046 
00047     
00048     uint8_t priority;
00049 
00050     
00051     void (*entry_point)(uint32_t);
00052     uint32_t entry_param;
00053 
00054     
00055     struct atom_tcb *prev_tcb;    
00056     struct atom_tcb *next_tcb;    
00057 
00058     
00059     uint8_t suspended;            
00060     uint8_t suspend_wake_status;  
00061     ATOM_TIMER *suspend_timo_cb;  
00062 
00063     
00064 #ifdef ATOM_STACK_CHECKING
00065     POINTER stack_top;            
00066     uint32_t stack_size;          
00067 #endif
00068 
00069 } ATOM_TCB;
00070 
00071 
00072 
00073 extern ATOM_TCB *tcbReadyQ;
00074 extern uint8_t atomOSStarted;
00075 
00076 
00077 
00078 #define TRUE                    1
00079 #define FALSE                   0
00080 
00081 
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 
00097 #define IDLE_THREAD_PRIORITY    255
00098 
00099 
00100 
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