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