]> git.sur5r.net Git - freertos/blob - Demo/PIC18_WizC/serial/isrSerialRx.c
001716f7684f11a989c528164ee53cd611a03c5a
[freertos] / Demo / PIC18_WizC / serial / isrSerialRx.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 Changes from V3.0.0\r
51         + ISRcode pulled inline to reduce stack-usage.\r
52 \r
53         + Added functionality to only call vTaskSwitchContext() once\r
54           when handling multiple interruptsources in a single interruptcall.\r
55 \r
56         + Filename changed to a .c extension to allow stepping through code\r
57           using F7.\r
58 \r
59 Changes from V3.0.1\r
60 */\r
61 \r
62 #ifndef _FREERTOS_SERIAL_ISRSERIALRX_C\r
63 #define _FREERTOS_SERIAL_ISRSERIALRX_C\r
64 \r
65 #define serCONTINUOUS_RX                ( 1 )\r
66 #define serCLEAR_OVERRUN                ( 0 )\r
67 \r
68 {\r
69         /*\r
70          * Was the interrupt a byte being received?\r
71          */\r
72         if( bRCIF && bRCIE)\r
73         {\r
74                 /*\r
75                  * Queue to interface between comms API and interrupt routine.\r
76                 */\r
77                 extern xQueueHandle xRxedChars;\r
78                 \r
79                 /*\r
80                  * Because we are not allowed to use local variables here,\r
81                  * PRODL is (ab)used as temporary storage.  This is allowed\r
82                  * because this SFR will be restored before exiting the ISR.\r
83                  */\r
84                 extern char                     cChar;\r
85                 extern portBASE_TYPE xHigherPriorityTaskWoken;\r
86                 #pragma locate cChar    &PRODL\r
87 \r
88                 /*\r
89                  * If there was a framing error, just get and ignore\r
90                  * the character\r
91                  */\r
92                 if( bFERR )\r
93                 {\r
94                         cChar = RCREG;\r
95                 }\r
96                 else\r
97                 {\r
98                         /*\r
99                          * Get the character and post it on the queue of Rxed\r
100                          * characters. If the post causes a task to wake ask\r
101                          * for a context switch as the woken task may have a\r
102                          * higher priority than the task we have interrupted.\r
103                          */\r
104                         cChar = RCREG;\r
105 \r
106                         /*\r
107                          * Clear any overrun errors.\r
108                          */\r
109                         if( bOERR )\r
110                         {\r
111                                 bCREN = serCLEAR_OVERRUN;\r
112                                 bCREN = serCONTINUOUS_RX;       \r
113                         }\r
114 \r
115                         xHigherPriorityTaskWoken = pdFALSE;\r
116                         xQueueSendFromISR( xRxedChars, ( const void * ) &cChar, &xHigherPriorityTaskWoken );\r
117 \r
118                         if( xHigherPriorityTaskWoken )\r
119                         {\r
120                                 uxSwitchRequested = pdTRUE;\r
121                         }\r
122                 }\r
123         }\r
124 }\r
125 \r
126 #endif  /* _FREERTOS_SERIAL_ISRSERIALRX_C */\r