--- /dev/null
+/*\r
+ FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
+ All rights reserved\r
+\r
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
+\r
+ ***************************************************************************\r
+ >>! NOTE: The modification to the GPL is included to allow you to !<<\r
+ >>! distribute a combined work that includes FreeRTOS without being !<<\r
+ >>! obliged to provide the source code for proprietary components !<<\r
+ >>! outside of the FreeRTOS kernel. !<<\r
+ ***************************************************************************\r
+\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ FOR A PARTICULAR PURPOSE. Full license text is available on the following\r
+ link: http://www.freertos.org/a00114.html\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS provides completely free yet professionally developed, *\r
+ * robust, strictly quality controlled, supported, and cross *\r
+ * platform software that is more than just the market leader, it *\r
+ * is the industry's de facto standard. *\r
+ * *\r
+ * Help yourself get started quickly while simultaneously helping *\r
+ * to support the FreeRTOS project by purchasing a FreeRTOS *\r
+ * tutorial book, reference manual, or both: *\r
+ * http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading\r
+ the FAQ page "My application does not run, what could be wrong?". Have you\r
+ defined configASSERT()?\r
+\r
+ http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+ embedded software for free we request you assist our global community by\r
+ participating in the support forum.\r
+\r
+ http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+ be as productive as possible as early as possible. Now you can receive\r
+ FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+ Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+ http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+ Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+ Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS\r
+ licenses offer ticketed support, indemnification and commercial middleware.\r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
+ mission critical applications that require provable dependability.\r
+\r
+ 1 tab == 4 spaces!\r
+*/\r
+\r
+\r
+/* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.\r
+ *\r
+ * This is not a proper UART driver. It only supports one port, and is not\r
+ * intended to show an efficient implementation as queues are used to pass\r
+ * individual characters one at a time! This is ok for a slow interface, such\r
+ * as a command line interface (which this driver is used for), but is too\r
+ * inefficient for higher bandwidth applications.\r
+ */\r
+\r
+/* Standard includes. */\r
+#include <stdlib.h>\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "queue.h"\r
+#include "task.h"\r
+\r
+/* Demo application includes. */\r
+#include "serial.h"\r
+\r
+/* TI includes. */\r
+#include "driverlib.h"\r
+\r
+/* Misc. constants. */\r
+#define serNO_BLOCK ( ( TickType_t ) 0 )\r
+\r
+/* The queue used to hold received characters. */\r
+static QueueHandle_t xRxedChars;\r
+\r
+/* The queue used to hold characters waiting transmission. */\r
+static QueueHandle_t xCharsForTx;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
+{\r
+unsigned long ulBaudRateCount;\r
+\r
+ /* Initialise the hardware. */\r
+\r
+ /* Generate the baud rate constants for the wanted baud rate. */\r
+ ulBaudRateCount = configCPU_CLOCK_HZ / ulWantedBaud;\r
+\r
+ portENTER_CRITICAL();\r
+ {\r
+ /* Create the queues used by the com test task. */\r
+ xRxedChars = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( signed char ) );\r
+ xCharsForTx = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( signed char ) );\r
+\r
+ /* Reset UART. */\r
+ UCA0CTL1 |= UCSWRST;\r
+\r
+ /* Use SMCLK. */\r
+ UCA0CTL1 = UCSSEL0 | UCSSEL1;\r
+\r
+ /* Setup baud rate low byte. */\r
+ UCA0BR0 = ( unsigned char ) ( ulBaudRateCount & ( unsigned long ) 0xff );\r
+\r
+ /* Setup baud rate high byte. */\r
+ ulBaudRateCount >>= 8UL;\r
+ UCA0BR1 = ( unsigned char ) ( ulBaudRateCount & ( unsigned long ) 0xff );\r
+\r
+ /* Enable interrupts. */\r
+ UCA0IE |= UCRXIE;\r
+\r
+ /* Take out of reset. */\r
+ UCA0CTL1 &= ~UCSWRST;\r
+ }\r
+ portEXIT_CRITICAL();\r
+\r
+ /* Note the comments at the top of this file about this not being a generic\r
+ UART driver. */\r
+ return NULL;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )\r
+{\r
+ /* Get the next character from the buffer. Return false if no characters\r
+ are available, or arrive before xBlockTime expires. */\r
+ if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
+ {\r
+ return pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ return pdFALSE;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )\r
+{\r
+BaseType_t xReturn;\r
+\r
+ /* Send the next character to the queue of characters waiting transmission,\r
+ then enable the UART Tx interrupt, just in case UART transmission has already\r
+ completed and switched itself off. */\r
+ xReturn = xQueueSend( xCharsForTx, &cOutChar, xBlockTime );\r
+ UCA0IE |= UCTXIE;\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
+{\r
+UBaseType_t uxChar;\r
+const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 100 );\r
+\r
+ /* The driver only supports one port so the pxPort parameter is not used. */\r
+ ( void ) pxPort;\r
+\r
+ for( uxChar = 0; uxChar < usStringLength; uxChar++ )\r
+ {\r
+ if( xQueueSend( xCharsForTx, &( pcString[ uxChar ] ), xMaxBlockTime ) == pdFALSE )\r
+ {\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ UCA0IE |= UCTXIE;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The implementation of this interrupt is provided to demonstrate the use\r
+of queues from inside an interrupt service routine. It is *not* intended to\r
+be an efficient interrupt implementation. A real application should make use\r
+of the DMA. Or, as a minimum, transmission and reception could use a simple\r
+RAM ring buffer, and synchronise with a task using a semaphore when a complete\r
+message has been received or transmitted. */\r
+#pragma vector=USCI_A0_VECTOR\r
+__interrupt void prvUSCI_A0_ISR( void )\r
+{\r
+signed char cChar;\r
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ while( ( UCA0IFG & UCRXIFG ) != 0 )\r
+ {\r
+ /* Get the character from the UART and post it on the queue of Rxed\r
+ characters. */\r
+ cChar = UCA0RXBUF;\r
+ xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );\r
+ }\r
+\r
+ /* If there is a Tx interrupt pending and the tx interrupts are enabled. */\r
+ if( ( UCA0IFG & UCTXIFG ) != 0 )\r
+ {\r
+ /* The previous character has been transmitted. See if there are any\r
+ further characters waiting transmission. */\r
+ if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
+ {\r
+ /* There was another character queued - transmit it now. */\r
+ UCA0TXBUF = cChar;\r
+ }\r
+ else\r
+ {\r
+ /* There were no other characters to transmit - disable the Tx\r
+ interrupt. */\r
+ UCA0IE &= ~UCTXIE;\r
+ }\r
+ }\r
+\r
+ __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );\r
+\r
+ /* If writing to a queue caused a task to unblock, and the unblocked task\r
+ has a priority equal to or above the task that this interrupt interrupted,\r
+ then lHigherPriorityTaskWoken will have been set to pdTRUE internally within\r
+ xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this\r
+ interrupt returns directly to the higher priority unblocked task.\r
+\r
+ THIS MUST BE THE LAST THING DONE IN THE ISR. */\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+}\r
+\r
+\r