]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF5282_Eclipse/RTOSDemo/serial/serial.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / ColdFire_MCF5282_Eclipse / RTOSDemo / serial / serial.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 \r
67 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.\r
68 \r
69 NOTE:  This driver is primarily to test the scheduler functionality.  It does\r
70 not effectively use the buffers or DMA and is therefore not intended to be\r
71 an example of an efficient driver. */\r
72 \r
73 /* Standard include file. */\r
74 #include <stdlib.h>\r
75 \r
76 /* Scheduler include files. */\r
77 #include "FreeRTOS.h"\r
78 #include "queue.h"\r
79 #include "task.h"\r
80 \r
81 /* Demo app include files. */\r
82 #include "serial.h"\r
83 \r
84 /* Hardware definitions. */\r
85 #define serNO_PARITY            ( ( unsigned char ) 0x02 << 3 )\r
86 #define ser8DATA_BITS           ( ( unsigned char ) 0x03 )\r
87 #define ser1STOP_BIT            ( ( unsigned char ) 0x07 )\r
88 #define serSYSTEM_CLOCK         ( ( unsigned char ) 0xdd )\r
89 #define serTX_OUTPUT            ( ( unsigned char ) 0x04 )\r
90 #define serRX_INPUT                     ( ( unsigned char ) 0x08 )\r
91 #define serTX_ENABLE            ( ( unsigned char ) 0x04 )\r
92 #define serRX_ENABLE            ( ( unsigned char ) 0x01 )\r
93 #define serTX_INT                       ( ( unsigned char ) 0x01 )\r
94 #define serRX_INT                       ( ( unsigned char ) 0x02 )\r
95 \r
96 \r
97 /* The queues used to communicate between tasks and ISR's. */\r
98 static QueueHandle_t xRxedChars;\r
99 static QueueHandle_t xCharsForTx;\r
100 \r
101 /* Flag used to indicate the tx status. */\r
102 static portBASE_TYPE xTxHasEnded = pdTRUE;\r
103 \r
104 /*-----------------------------------------------------------*/\r
105 \r
106 /* The UART interrupt handler. */\r
107 void __attribute__( ( interrupt ) ) __cs3_isr_interrupt_78( void );\r
108 \r
109 /*-----------------------------------------------------------*/\r
110 \r
111 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
112 {\r
113 const unsigned long ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32UL * ulWantedBaud ) );\r
114 \r
115         /* Create the queues used by the com test task. */\r
116         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
117         xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
118 \r
119         xTxHasEnded = pdTRUE;\r
120 \r
121         /* Set the pins to UART mode. */\r
122         MCF_PAD_PUAPAR |= ( serTX_OUTPUT | serRX_INPUT );\r
123 \r
124         /* Reset the peripheral. */\r
125         MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;\r
126         MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;\r
127         MCF_UART1_UCR = MCF_UART_UCR_RESET_ERROR;\r
128         MCF_UART1_UCR = MCF_UART_UCR_RESET_BKCHGINT;\r
129         MCF_UART1_UCR = MCF_UART_UCR_RESET_MR | MCF_UART_UCR_RX_DISABLED | MCF_UART_UCR_TX_DISABLED;\r
130 \r
131         /* Configure the UART. */\r
132         MCF_UART1_UMR1 = serNO_PARITY | ser8DATA_BITS;\r
133         MCF_UART1_UMR2 = ser1STOP_BIT;\r
134         MCF_UART1_UCSR = serSYSTEM_CLOCK;\r
135 \r
136         MCF_UART1_UBG1 = ( unsigned char ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );\r
137         MCF_UART1_UBG2 = ( unsigned char ) ( ulBaudRateDivisor & 0xffUL );\r
138 \r
139         /* Turn it on. */\r
140         MCF_UART1_UCR = serTX_ENABLE | serRX_ENABLE;\r
141 \r
142         /* Configure the interrupt controller.  Run the UARTs above the kernel\r
143         interrupt priority for demo purposes. */\r
144     MCF_INTC0_ICR14 = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 2  ) << 3 );\r
145     MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK14 | 0x01 );\r
146 \r
147         /* The Tx interrupt is not enabled until there is data to send. */\r
148         MCF_UART1_UIMR = serRX_INT;\r
149 \r
150         /* Only a single port is implemented so we don't need to return anything. */\r
151         return NULL;\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )\r
156 {\r
157         /* Only one port is supported. */\r
158         ( void ) pxPort;\r
159 \r
160         /* Get the next character from the buffer.  Return false if no characters\r
161         are available or arrive before xBlockTime expires. */\r
162         if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
163         {\r
164                 return pdTRUE;\r
165         }\r
166         else\r
167         {\r
168                 return pdFALSE;\r
169         }\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )\r
174 {\r
175         /* Only one port is supported. */\r
176         ( void ) pxPort;\r
177 \r
178         /* Return false if after the block time there is no room on the Tx queue. */\r
179         if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )\r
180         {\r
181                 return pdFAIL;\r
182         }\r
183 \r
184         /* A critical section should not be required as xTxHasEnded will not be\r
185         written to by the ISR if it is already 0 (is this correct?). */\r
186         if( xTxHasEnded != pdFALSE )\r
187         {\r
188                 xTxHasEnded = pdFALSE;\r
189                 MCF_UART1_UIMR = serRX_INT | serTX_INT;\r
190         }\r
191 \r
192         return pdPASS;\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 void vSerialClose( xComPortHandle xPort )\r
197 {\r
198         ( void ) xPort;\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 void __cs3_isr_interrupt_78( void )\r
203 {\r
204 unsigned char ucChar;\r
205 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xDoneSomething = pdTRUE;\r
206 \r
207         while( xDoneSomething != pdFALSE )\r
208         {\r
209                 xDoneSomething = pdFALSE;\r
210 \r
211                 /* Does the tx buffer contain space? */\r
212                 if( ( MCF_UART1_USR & MCF_UART_USR_TXRDY ) != 0x00 )\r
213                 {\r
214                         /* Are there any characters queued to be sent? */\r
215                         if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
216                         {\r
217                                 /* Send the next char. */\r
218                                 MCF_UART1_UTB = ucChar;\r
219                                 xDoneSomething = pdTRUE;\r
220                         }\r
221                         else\r
222                         {\r
223                                 /* Turn off the Tx interrupt until such time as another character\r
224                                 is being transmitted. */\r
225                                 MCF_UART1_UIMR = serRX_INT;\r
226                                 xTxHasEnded = pdTRUE;\r
227                         }\r
228                 }\r
229 \r
230                 if( MCF_UART1_USR & MCF_UART_USR_RXRDY )\r
231                 {\r
232                         ucChar = MCF_UART1_URB;\r
233                         xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );\r
234                         xDoneSomething = pdTRUE;\r
235                 }\r
236         }\r
237 \r
238     portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
239 }\r
240 \r
241 \r
242 \r
243 \r
244 \r
245 \r
246 \r