00001 /* 00002 ********************************************************************************************************* 00003 * uC/OS-II 00004 * The Real-Time Kernel 00005 * 00006 * AVR Specific code 00007 * 00008 * File : OS_CPU.H 00009 * By : Ole Saether 00010 * Port Version : V1.01 00011 * 00012 * AVR-GCC port version : 1.0 2001-04-02 modified/ported to avr-gcc by Jesper Hansen (jesperh@telia.com) 00013 * 00014 * 00015 ********************************************************************************************************* 00016 */ 00017 00018 /* Definition moved here so it can be used in the assembler file OS_CPU_A.ASM */ 00019 /* See below for the meaning of this define */ 00020 00021 #define OS_CRITICAL_METHOD 1 00022 00023 00024 #ifndef OS_CPU_A /* skip the rest if we're including from the assembler file */ 00025 00026 #ifdef OS_CPU_GLOBALS 00027 #define OS_CPU_EXT 00028 #else 00029 #define OS_CPU_EXT extern 00030 #endif 00031 00032 /* 00033 ********************************************************************************************************** 00034 * DATA TYPES 00035 * (Compiler Specific) 00036 ********************************************************************************************************** 00037 */ 00038 00039 typedef unsigned char BOOLEAN; 00040 typedef unsigned char INT8U; /* Unsigned 8 bit quantity */ 00041 typedef signed char INT8S; /* Signed 8 bit quantity */ 00042 typedef unsigned int INT16U; /* Unsigned 16 bit quantity */ 00043 typedef signed int INT16S; /* Signed 16 bit quantity */ 00044 typedef unsigned long INT32U; /* Unsigned 32 bit quantity */ 00045 typedef signed long INT32S; /* Signed 32 bit quantity */ 00046 typedef float FP32; /* Single precision floating point */ 00047 00048 typedef unsigned char OS_STK; /* Each stack entry is 8-bit wide */ 00049 00050 /* 00051 ********************************************************************************************************** 00052 * Atmel AVR 00053 * 00054 * 00055 * Method #1: Disable/Enable interrupts using simple instructions. After critical section, interrupts 00056 * will be enabled even if they were disabled before entering the critical section. 00057 * 00058 * Method #2: Disable/Enable interrupts by preserving the state of interrupts. In other words, if 00059 * interrupts were disabled before entering the critical section, they will be disabled when 00060 * leaving the critical section. Here's what happens in the macro below : 00061 * 00062 * OS_ENTER_CRITICAL: 00063 * 00064 * input SREG to a free register, Rn 00065 * push Rn 00066 * 00067 * OS_EXIT_CRITICAL: 00068 * 00069 * pop to a free register, Rn 00070 * output Rn to SREG 00071 * 00072 * 00073 ********************************************************************************************************** 00074 */ 00075 00076 #if OS_CRITICAL_METHOD == 1 00077 #define OS_ENTER_CRITICAL() asm volatile ("cli") /* Disable interrupts */ 00078 #define OS_EXIT_CRITICAL() asm volatile ("sei") /* Enable interrupts */ 00079 #endif 00080 00081 #if OS_CRITICAL_METHOD == 2 00082 #define OS_ENTER_CRITICAL() { asm volatile ( \ 00083 "in %0,63" "\n\t" \ 00084 "cli" "\n\t" \ 00085 "push %0" "\n\t" \ 00086 : /*no outputs*/ \ 00087 : "r" (0) ); \ 00088 } 00089 00090 #define OS_EXIT_CRITICAL() { asm volatile ( \ 00091 "pop %0" "\n\t" \ 00092 "out 63,%0" "\n\t" \ 00093 : /*no outputs*/ \ 00094 : "r" (0) ); \ 00095 } 00096 #endif 00097 00098 /* 00099 ********************************************************************************************************** 00100 * AVR Miscellaneous 00101 ********************************************************************************************************** 00102 */ 00103 00104 #define OS_STK_GROWTH 1 /* Stack grows from HIGH to LOW memory on AVR */ 00105 00106 #define OS_TASK_SW() OSCtxSw() 00107 00108 /* 00109 ********************************************************************************************************** 00110 * GLOBAL VARIABLES 00111 ********************************************************************************************************** 00112 */ 00113 00114 OS_CPU_EXT INT16U OSTaskStkSize; 00115 OS_CPU_EXT INT16U OSTaskStkSizeHard; 00116 00117 00118 // Added by Leo Steinfeld 1/06/2009 00119 00120 void OSStartHighRdy (void); 00121 void OSIntCtxSw (void); 00122 void OSCtxSw (void); 00123 00124 00125 00126 #endif //OS_CPU_A