]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2106_GCC/serial/serialISR.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / ARM7_LPC2106_GCC / serial / serialISR.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 \r
50 /* \r
51         BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0. \r
52 \r
53         This file contains all the serial port components that must be compiled\r
54         to ARM mode.  The components that can be compiled to either ARM or THUMB\r
55         mode are contained in serial.c.\r
56 \r
57 */\r
58 \r
59 /* Standard includes. */\r
60 #include <stdlib.h>\r
61 \r
62 /* Scheduler includes. */\r
63 #include "FreeRTOS.h"\r
64 #include "queue.h"\r
65 #include "task.h"\r
66 \r
67 /* Demo application includes. */\r
68 #include "serial.h"\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 /* Constant to access the VIC. */\r
73 #define serCLEAR_VIC_INTERRUPT                  ( ( unsigned long ) 0 )\r
74 \r
75 /* Constants to determine the ISR source. */\r
76 #define serSOURCE_THRE                                  ( ( unsigned char ) 0x02 )\r
77 #define serSOURCE_RX_TIMEOUT                    ( ( unsigned char ) 0x0c )\r
78 #define serSOURCE_ERROR                                 ( ( unsigned char ) 0x06 )\r
79 #define serSOURCE_RX                                    ( ( unsigned char ) 0x04 )\r
80 #define serINTERRUPT_SOURCE_MASK                ( ( unsigned char ) 0x0f )\r
81 \r
82 /* Queues used to hold received characters, and characters waiting to be\r
83 transmitted. */\r
84 static xQueueHandle xRxedChars; \r
85 static xQueueHandle xCharsForTx; \r
86 static volatile long lTHREEmpty;\r
87 \r
88 /*-----------------------------------------------------------*/\r
89 \r
90 /* \r
91  * The queues are created in serialISR.c as they are used from the ISR.\r
92  * Obtain references to the queues and THRE Empty flag. \r
93  */\r
94 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRxedChars, xQueueHandle *pxCharsForTx, long volatile **pplTHREEmptyFlag );\r
95 \r
96 /* UART0 interrupt service routine entry point. */\r
97 void vUART_ISR_Wrapper( void ) __attribute__ ((naked));\r
98 \r
99 /* UART0 interrupt service routine handler. */\r
100 void vUART_ISR_Handler( void ) __attribute__ ((noinline));\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 void vSerialISRCreateQueues(    unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRxedChars, \r
104                                                                 xQueueHandle *pxCharsForTx, long volatile **pplTHREEmptyFlag )\r
105 {\r
106         /* Create the queues used to hold Rx and Tx characters. */\r
107         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
108         xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
109 \r
110         /* Pass back a reference to the queues so the serial API file can \r
111         post/receive characters. */\r
112         *pxRxedChars = xRxedChars;\r
113         *pxCharsForTx = xCharsForTx;\r
114 \r
115         /* Initialise the THRE empty flag - and pass back a reference. */\r
116         lTHREEmpty = ( long ) pdTRUE;\r
117         *pplTHREEmptyFlag = &lTHREEmpty;\r
118 }\r
119 /*-----------------------------------------------------------*/\r
120 \r
121 void vUART_ISR_Wrapper( void )\r
122 {\r
123         /* Save the context of the interrupted task. */\r
124         portSAVE_CONTEXT();\r
125 \r
126         /* Call the handler.  This must be a separate function from the wrapper\r
127         to ensure the correct stack frame is set up. */\r
128         __asm volatile ("bl vUART_ISR_Handler");\r
129 \r
130         /* Restore the context of whichever task is going to run next. */\r
131         portRESTORE_CONTEXT();\r
132 }\r
133 /*-----------------------------------------------------------*/\r
134 \r
135 void vUART_ISR_Handler( void )\r
136 {\r
137 signed char cChar;\r
138 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
139 \r
140         /* What caused the interrupt? */\r
141         switch( UART0_IIR & serINTERRUPT_SOURCE_MASK )\r
142         {\r
143                 case serSOURCE_ERROR :  /* Not handling this, but clear the interrupt. */\r
144                                                                 cChar = UART0_LSR;\r
145                                                                 break;\r
146 \r
147                 case serSOURCE_THRE     :       /* The THRE is empty.  If there is another\r
148                                                                 character in the Tx queue, send it now. */\r
149                                                                 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
150                                                                 {\r
151                                                                         UART0_THR = cChar;\r
152                                                                 }\r
153                                                                 else\r
154                                                                 {\r
155                                                                         /* There are no further characters \r
156                                                                         queued to send so we can indicate \r
157                                                                         that the THRE is available. */\r
158                                                                         lTHREEmpty = pdTRUE;\r
159                                                                 }\r
160                                                                 break;\r
161 \r
162                 case serSOURCE_RX_TIMEOUT :\r
163                 case serSOURCE_RX       :       /* A character was received.  Place it in \r
164                                                                 the queue of received characters. */\r
165                                                                 cChar = UART0_RBR;\r
166                                                                 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );\r
167                                                                 break;\r
168 \r
169                 default                         :       /* There is nothing to do, leave the ISR. */\r
170                                                                 break;\r
171         }\r
172 \r
173         if( xHigherPriorityTaskWoken )\r
174         {\r
175                 portYIELD_FROM_ISR();\r
176         }\r
177 \r
178         /* Clear the ISR in the VIC. */\r
179         VICVectAddr = serCLEAR_VIC_INTERRUPT;\r
180 }\r
181 \r
182 \r
183 \r
184 \r
185 \r
186 \r
187         \r