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