Pragma directive\r
***********************************************************************************************************************/\r
/* Start user code for pragma. Do not edit comment generated here */\r
+\r
+\r
+/*\r
+ * This file originated from an example project for the RSK - it has been\r
+ * adapted to allow it to be used in the FreeRTOS demo. Functions required by\r
+ * UARTCommandConsole.c have been added.\r
+ */\r
+\r
+\r
+\r
/* End user code. Do not edit comment generated here */\r
\r
/***********************************************************************************************************************\r
#include "r_cg_sci.h"\r
/* Start user code for include. Do not edit comment generated here */\r
#include "rskrx113def.h"\r
-//_RB_#include "r_cg_cmt.h"\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "serial.h"\r
/* End user code. Do not edit comment generated here */\r
#include "r_cg_userdefine.h"\r
\r
/* Flag used to control transmission to PC terminal */\r
volatile uint8_t g_tx_flag = FALSE;\r
\r
-/* Flag used locally to detect transmission complete */\r
+/* Characters received from the UART are stored in this queue, ready to be\r
+received by the application. ***NOTE*** Using a queue in this way is very\r
+convenient, but also very inefficient. It can be used here because characters\r
+will only arrive slowly. In a higher bandwidth system a circular RAM buffer or\r
+DMA should be used in place of this queue. */\r
+static QueueHandle_t xRxQueue = NULL;\r
+\r
+/* When a task calls vSerialPutString() its handle is stored in xSendingTask,\r
+before being placed into the Blocked state (so does not use any CPU time) to\r
+wait for the transmission to end. The task handle is then used from the UART\r
+transmit end interrupt to remove the task from the Blocked state. */\r
+static TaskHandle_t xSendingTask = NULL;\r
+\r
+/* Flag used locally to detect transmission complete. This is used by the\r
+auto generated API only. */\r
static volatile uint8_t sci1_txdone;\r
\r
/* End user code. Do not edit comment generated here */\r
\r
/* Clear overrun, framing and parity error flags */\r
err_type = SCI1.SSR.BYTE;\r
- SCI1.SSR.BYTE = err_type & 0xC7U;\r
+ SCI1.SSR.BYTE = err_type & ( uint8_t ) 0xC7;\r
}\r
/***********************************************************************************************************************\r
* Function Name: r_sci1_callback_transmitend\r
* Arguments : None\r
* Return Value : None\r
***********************************************************************************************************************/\r
-static void r_sci1_callback_transmitend(void)\r
+void r_sci1_callback_transmitend(void)\r
{\r
/* Start user code. Do not edit comment generated here */\r
- sci1_txdone = TRUE;\r
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ /* The sci1_txdone flag is used by the auto generated API only. */\r
+ sci1_txdone = TRUE;\r
\r
+ if( xSendingTask != NULL )\r
+ {\r
+ /* A task is waiting for the end of the Tx, unblock it now.\r
+ http://www.freertos.org/vTaskNotifyGiveFromISR.html */\r
+ vTaskNotifyGiveFromISR( xSendingTask, &xHigherPriorityTaskWoken );\r
+ xSendingTask = NULL;\r
+\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+ }\r
/* End user code. Do not edit comment generated here */\r
}\r
/***********************************************************************************************************************\r
* Arguments : None\r
* Return Value : None\r
***********************************************************************************************************************/\r
-static void r_sci1_callback_receiveend(void)\r
+void r_sci1_callback_receiveend(void)\r
{\r
/* Start user code. Do not edit comment generated here */\r
- /* Check the contents of g_rx_char */\r
- if ('z' == g_rx_char)\r
- {\r
- /* Stop the timer used to control transmission to PC terminal*/\r
-//_RB_ R_CMT0_Stop();\r
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
\r
- /* Turn off LED0 and turn on LED1 to indicate serial transmission\r
- inactive */\r
- LED0 = LED_OFF;\r
- LED1 = LED_ON;\r
- }\r
- else\r
- {\r
- /* Start the timer used to control transmission to PC terminal*/\r
-//_RB_ R_CMT0_Start();\r
+ configASSERT( xRxQueue );\r
\r
- /* Turn on LED0 and turn off LED1 to indicate serial transmission\r
- active */\r
- LED0 = LED_ON;\r
- LED1 = LED_OFF;\r
- }\r
+ /* Transmitting generates an interrupt for each character, which consumes\r
+ CPU time, and can cause standard demo RTOS tasks that monitor their own\r
+ performance to fail asserts - so don't receive new CLI commands if a\r
+ transmit is not already in progress. */\r
+ if( sci1_txdone == TRUE )\r
+ {\r
+ /* Characters received from the UART are stored in this queue, ready to be\r
+ received by the application. ***NOTE*** Using a queue in this way is very\r
+ convenient, but also very inefficient. It can be used here because\r
+ characters will only arrive slowly. In a higher bandwidth system a circular\r
+ RAM buffer or DMA should be used in place of this queue. */\r
+ xQueueSendFromISR( xRxQueue, &g_rx_char, &xHigherPriorityTaskWoken );\r
+ }\r
\r
/* Set up SCI1 receive buffer again */\r
R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);\r
\r
+ /* See http://www.freertos.org/xQueueOverwriteFromISR.html for information\r
+ on the semantics of this ISR. */\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
/* End user code. Do not edit comment generated here */\r
}\r
/***********************************************************************************************************************\r
* Arguments : None\r
* Return Value : None\r
***********************************************************************************************************************/\r
-static void r_sci1_callback_receiveerror(void)\r
+void r_sci1_callback_receiveerror(void)\r
{\r
/* Start user code. Do not edit comment generated here */\r
/* End user code. Do not edit comment generated here */\r
* End of function R_SCI1_AsyncTransmit\r
***********************************************************************************************************************/\r
\r
+/* Function required in order to link UARTCommandConsole.c - which is used by\r
+multiple different demo application. */\r
+xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
+{\r
+ ( void ) ulWantedBaud;\r
+ ( void ) uxQueueLength;\r
+\r
+ /* Characters received from the UART are stored in this queue, ready to be\r
+ received by the application. ***NOTE*** Using a queue in this way is very\r
+ convenient, but also very inefficient. It can be used here because\r
+ characters will only arrive slowly. In a higher bandwidth system a circular\r
+ RAM buffer or DMA should be used in place of this queue. */\r
+ xRxQueue = xQueueCreate( uxQueueLength, sizeof( char ) );\r
+ configASSERT( xRxQueue );\r
+\r
+ /* Set up SCI1 receive buffer */\r
+ R_SCI1_Serial_Receive((uint8_t *) &g_rx_char, 1);\r
+\r
+ /* Ensure the interrupt priority is at or below\r
+ configMAX_SYSCALL_INTERRUPT_PRIORITY. */\r
+ IPR( SCI1, ERI1 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
+\r
+ /* Enable SCI1 operations */\r
+ R_SCI1_Start();\r
+\r
+ /* Only one UART is supported, so it doesn't matter what is returned\r
+ here. */\r
+ return 0;\r
+}\r
+\r
+/* Function required in order to link UARTCommandConsole.c - which is used by\r
+multiple different demo application. */\r
+void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
+{\r
+const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 5000 );\r
+\r
+ /* Only one port is supported. */\r
+ ( void ) pxPort;\r
+\r
+ /* Clear the flag before initiating a new transmission */\r
+ sci1_txdone = FALSE;\r
+\r
+ /* Don't send the string unless the previous string has been sent. */\r
+ if( xSendingTask == NULL )\r
+ {\r
+ /* Ensure the calling task's notification state is not already\r
+ pending. */\r
+ vTaskNotifyClear( NULL );\r
+\r
+ /* Store the handle of the transmitting task. This is used to unblock\r
+ the task when the transmission has completed. */\r
+ xSendingTask = xTaskGetCurrentTaskHandle();\r
+\r
+ /* Send the string using the auto-generated API. */\r
+ R_SCI1_Serial_Send( ( uint8_t * ) pcString, usStringLength );\r
+\r
+ /* Wait in the Blocked state (so not using any CPU time) until the\r
+ transmission has completed. */\r
+ ulTaskNotifyTake( pdTRUE, xMaxBlockTime );\r
+ }\r
+}\r
+\r
+/* Function required in order to link UARTCommandConsole.c - which is used by\r
+multiple different demo application. */\r
+signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )\r
+{\r
+ /* Only one UART is supported. */\r
+ ( void ) pxPort;\r
+\r
+ /* Return a received character, if any are available. Otherwise block to\r
+ wait for a character. */\r
+ return xQueueReceive( xRxQueue, pcRxedChar, xBlockTime );\r
+}\r
+\r
+/* Function required in order to link UARTCommandConsole.c - which is used by\r
+multiple different demo application. */\r
+signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )\r
+{\r
+ /* Just mapped to vSerialPutString() so the block time is not used. */\r
+ ( void ) xBlockTime;\r
+\r
+ vSerialPutString( pxPort, &cOutChar, sizeof( cOutChar ) );\r
+ return pdPASS;\r
+}\r
+\r
/* End user code. Do not edit comment generated here */\r