]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RX100_RX113-RSK_Renesas_e2studio/src/cg_src/r_cg_sci_user.c
Demo tasks:
[freertos] / FreeRTOS / Demo / RX100_RX113-RSK_Renesas_e2studio / src / cg_src / r_cg_sci_user.c
index aec0de1017d723417a6219e6b72ec52fb812b580..08fa2ce1e30a9e04a3d407b51205c4559eb3201b 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
@@ -39,7 +49,10 @@ Includes
 #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
@@ -59,7 +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
+/* 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
@@ -154,7 +181,7 @@ static void r_sci1_receiveerror_interrupt(void)
 \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
@@ -162,11 +189,23 @@ static void r_sci1_receiveerror_interrupt(void)
 * 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
@@ -175,34 +214,33 @@ static void r_sci1_callback_transmitend(void)
 * 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
@@ -211,7 +249,7 @@ static void r_sci1_callback_receiveend(void)
 * 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
@@ -249,4 +287,89 @@ MD_STATUS R_SCI1_AsyncTransmit (uint8_t * const tx_buf, const uint16_t tx_num)
  * 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