]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MCF5235/portmacro.h
Kernel changes to improve power saving:
[freertos] / FreeRTOS / Source / portable / GCC / MCF5235 / portmacro.h
1 /*\r
2     FreeRTOS V4.1.1 - Copyright (C) 2003-2006 Richard Barry.\r
3     MCF5235 Port - Copyright (C) 2006 Christian Walter.\r
4 \r
5     This file is part of the FreeRTOS distribution.\r
6 \r
7     FreeRTOS is free software; you can redistribute it and/or modify\r
8     it under the terms of the GNU General Public License** as published by\r
9     the Free Software Foundation; either version 2 of the License, or\r
10     (at your option) any later version.\r
11 \r
12     FreeRTOS is distributed in the hope that it will be useful,\r
13     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15     GNU General Public License for more details.\r
16 \r
17     You should have received a copy of the GNU General Public License\r
18     along with FreeRTOS; if not, write to the Free Software\r
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
20 \r
21     A special exception to the GPL can be applied should you wish to distribute\r
22     a combined work that includes FreeRTOS, without being obliged to provide\r
23     the source code for any proprietary components.  See the licensing section\r
24     of http://www.FreeRTOS.org for full details of how and when the exception\r
25     can be applied.\r
26 \r
27     ***************************************************************************\r
28     ***************************************************************************\r
29     *                                                                         *\r
30     * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
31         *                                                                         *\r
32         * This is a concise, step by step, 'hands on' guide that describes both   *\r
33         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
34         * explains numerous examples that are written using the FreeRTOS API.     *\r
35         * Full source code for all the examples is provided in an accompanying    *\r
36         * .zip file.                                                              *\r
37     *                                                                         *\r
38     ***************************************************************************\r
39     ***************************************************************************\r
40 \r
41         Please ensure to read the configuration and relevant port sections of the\r
42         online documentation.\r
43 \r
44         http://www.FreeRTOS.org - Documentation, latest information, license and\r
45         contact details.\r
46 \r
47         http://www.SafeRTOS.com - A version that is certified for use in safety\r
48         critical systems.\r
49 \r
50         http://www.OpenRTOS.com - Commercial support, development, porting,\r
51         licensing and training services.\r
52 */\r
53 \r
54 #ifndef PORTMACRO_H\r
55 #define PORTMACRO_H\r
56 \r
57 #ifdef __cplusplus\r
58 extern "C" {\r
59 #endif\r
60 \r
61 /* ------------------------ Data types for Coldfire ----------------------- */\r
62 #define portCHAR        char\r
63 #define portFLOAT       float\r
64 #define portDOUBLE      double\r
65 #define portLONG        long\r
66 #define portSHORT       short\r
67 #define portSTACK_TYPE  unsigned int\r
68 #define portBASE_TYPE   int\r
69 \r
70 typedef portSTACK_TYPE StackType_t;\r
71 typedef long BaseType_t;\r
72 typedef unsigned long UBaseType_t;\r
73 \r
74 #if( configUSE_16_BIT_TICKS == 1 )\r
75     typedef uint16_t TickType_t;\r
76     #define portMAX_DELAY ( TickType_t ) 0xffff\r
77 #else\r
78     typedef uint32_t TickType_t;\r
79     #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
80 #endif\r
81 \r
82 /* ------------------------ Architecture specifics ------------------------ */\r
83 #define portSTACK_GROWTH                ( -1 )\r
84 #define portTICK_PERIOD_MS                ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
85 #define portBYTE_ALIGNMENT              4\r
86 \r
87 #define portTRAP_YIELD                  0   /* Trap 0 */\r
88 #define portIPL_MAX                     7   /* Only NMI interrupt 7 allowed. */\r
89 \r
90 /* ------------------------ FreeRTOS macros for port ---------------------- */\r
91 \r
92 /*\r
93  * This function must be called when the current state of the active task\r
94  * should be stored. It must be called immediately after exception\r
95  * processing from the CPU, i.e. there exists a Coldfire exception frame at\r
96  * the current position in the stack. The function reserves space on\r
97  * the stack for the CPU registers and other task dependent values (e.g\r
98  * ulCriticalNesting) and updates the top of the stack in the TCB.\r
99  */\r
100 #define portSAVE_CONTEXT()                                                   \\r
101     asm volatile ( /* reserve space for task state. */                       \\r
102                    "lea.l   (-64, %sp), %sp\n\t"                             \\r
103                    /* push data register %d0-%d7/%a0-%a6 on stack. */        \\r
104                    "movem.l %d0-%d7/%a0-%a6, (%sp)\n\t"                      \\r
105                    /* push ulCriticalNesting counter on stack. */            \\r
106                    "lea.l  (60, %sp), %a0\n\t"                               \\r
107                    "move.l  ulCriticalNesting, (%a0)\n\t"                    \\r
108                    /* set the new top of the stack in the TCB. */            \\r
109                    "move.l  pxCurrentTCB, %a0\n\t"                           \\r
110                    "move.l  %sp, (%a0)");\r
111 \r
112 /*.\r
113  * This function restores the current active and continues its execution.\r
114  * It loads the current TCB and restores the processor registers, the\r
115  * task dependent values (e.g ulCriticalNesting). Finally execution\r
116  * is continued by executing an rte instruction.\r
117  */\r
118 #define portRESTORE_CONTEXT()                                                \\r
119     asm volatile ( "move.l  pxCurrentTCB, %sp\n\t"                           \\r
120                    "move.l  (%sp), %sp\n\t"                                  \\r
121                    /* stack pointer now points to the saved registers. */    \\r
122                    "movem.l (%sp), %d0-%d7/%a0-%a6\n\t"                      \\r
123                    /* restore ulCriticalNesting counter from stack. */       \\r
124                    "lea.l   (%sp, 60), %sp\n\t"                              \\r
125                    "move.l  (%sp)+, ulCriticalNesting\n\t"                   \\r
126                    /* stack pointer now points to exception frame. */        \\r
127                    "rte\n\t" );\r
128 \r
129 #define portENTER_CRITICAL()                                                 \\r
130     vPortEnterCritical();\r
131 \r
132 #define portEXIT_CRITICAL()                                                  \\r
133     vPortExitCritical();\r
134 \r
135 #define portSET_IPL( xIPL )                                                  \\r
136     asm_set_ipl( xIPL )\r
137 \r
138 #define portDISABLE_INTERRUPTS() \\r
139     do { ( void )portSET_IPL( portIPL_MAX ); } while( 0 )\r
140 #define portENABLE_INTERRUPTS() \\r
141     do { ( void )portSET_IPL( 0 ); } while( 0 )\r
142 \r
143 #define portYIELD()                                                          \\r
144     asm volatile ( " trap   %0\n\t" : : "i"(portTRAP_YIELD) )\r
145 \r
146 #define portNOP()                                                            \\r
147     asm volatile ( "nop\n\t" )\r
148 \r
149 #define portENTER_SWITCHING_ISR()                                            \\r
150     asm volatile ( "move.w  #0x2700, %sr" );                                 \\r
151     /* Save the context of the interrupted task. */                          \\r
152     portSAVE_CONTEXT(  );                                                    \\r
153     {\r
154 \r
155 #define portEXIT_SWITCHING_ISR( SwitchRequired )                             \\r
156         /* If a switch is required we call vTaskSwitchContext(). */          \\r
157         if( SwitchRequired )                                                 \\r
158         {                                                                    \\r
159             vTaskSwitchContext(  );                                          \\r
160         }                                                                    \\r
161     }                                                                        \\r
162     portRESTORE_CONTEXT(  );\r
163 \r
164 /* ------------------------ Function prototypes --------------------------- */\r
165 void vPortEnterCritical( void );\r
166 void vPortExitCritical( void );\r
167 int asm_set_ipl( uint32_t int uiNewIPL );\r
168 \r
169 /* ------------------------ Compiler specifics ---------------------------- */\r
170 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters )                   \\r
171     void vFunction( void *pvParameters )\r
172 \r
173 #define portTASK_FUNCTION( vFunction, pvParameters )                         \\r
174     void vFunction( void *pvParameters )\r
175 \r
176 #ifdef __cplusplus\r
177 }\r
178 #endif\r
179 \r
180 \r
181 #endif /* PORTMACRO_H */\r
182 \r