]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RX700_RX71M_RSK_Renesas_e2studio/src/cg_src/r_cg_sci_user.c
Preparing for maintenance release -
[freertos] / FreeRTOS / Demo / RX700_RX71M_RSK_Renesas_e2studio / src / cg_src / r_cg_sci_user.c
index 6f4c8bca65f4a70ee31e84fc49e8456bddb077f2..e163cc5420821a99fd13ffeb44dfd6d770d36269 100644 (file)
 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
@@ -38,6 +48,11 @@ Includes
 #include "r_cg_macrodriver.h"\r
 #include "r_cg_sci.h"\r
 /* Start user code for include. Do not edit comment generated here */\r
+#include "rskrx71mdef.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
@@ -50,7 +65,6 @@ extern uint8_t * gp_sci7_rx_address;                /* SCI7 receive buffer addre
 extern uint16_t  g_sci7_rx_count;                   /* SCI7 receive data number */\r
 extern uint16_t  g_sci7_rx_length;                  /* SCI7 receive data length */\r
 /* Start user code for global. Do not edit comment generated here */\r
-/* Flag used locally to detect transmission complete */\r
 \r
 /* Global used to receive a character from the PC terminal */\r
 uint8_t g_rx_char;\r
@@ -58,8 +72,21 @@ uint8_t g_rx_char;
 /* 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
-static volatile uint8_t sci6_txdone;\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 sci7_txdone;\r
 \r
 /* End user code. Do not edit comment generated here */\r
@@ -98,7 +125,7 @@ static void r_sci7_transmit_interrupt(void)
 ***********************************************************************************************************************/\r
 void r_sci7_transmitend_interrupt(void)\r
 {\r
-    /* Set TXD7 pin */\r
+    MPC.P90PFS.BYTE = 0x00U;\r
     PORT9.PMR.BYTE &= 0xFEU;\r
     SCI7.SCR.BIT.TIE = 0U;\r
     SCI7.SCR.BIT.TE = 0U;\r
@@ -158,8 +185,20 @@ void r_sci7_receiveerror_interrupt(void)
 static void r_sci7_callback_transmitend(void)\r
 {\r
     /* Start user code. Do not edit comment generated here */\r
+    BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+    /* The sci7_txdone flag is used by the auto generated API only. */\r
     sci7_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
@@ -171,15 +210,30 @@ static void r_sci7_callback_transmitend(void)
 static void r_sci7_callback_receiveend(void)\r
 {\r
     /* Start user code. Do not edit comment generated here */\r
-    /* Check the contents of g_rx_char */\r
-    if (('c' == g_rx_char) || ('C' == g_rx_char))\r
+    BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+    configASSERT( xRxQueue );\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( sci7_txdone == TRUE )\r
     {\r
-//_RB_        g_adc_trigger = TRUE;\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 SCI7 receive buffer and callback function again */\r
+    /* Set up SCI7 receive buffer again */\r
     R_SCI7_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
@@ -228,5 +282,91 @@ MD_STATUS R_SCI7_AsyncTransmit (uint8_t * const tx_buf, const uint16_t tx_num)
 * End of function R_SCI7_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_SCI7_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(SCI7, RXI7) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
+    IPR(SCI7, TXI7) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
+    IPR(ICU,GROUPBL0) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
+\r
+    /* Enable SCI1 operations */\r
+    R_SCI7_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
+    sci7_txdone = FALSE;\r
+\r
+    /* Don't send the string unless the previous string has been sent. */\r
+    if( ( xSendingTask == NULL ) && ( usStringLength > 0 ) )\r
+    {\r
+        /* Ensure the calling task's notification state is not already\r
+        pending. */\r
+        vTaskNotifyStateClear( 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_SCI7_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