]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR/src/cg_src/r_cg_sci_user_IAR.c
Demo tasks:
[freertos] / FreeRTOS / Demo / RX100_RX113-RSK_GCC_e2studio_IAR / src / cg_src / r_cg_sci_user_IAR.c
diff --git a/FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR/src/cg_src/r_cg_sci_user_IAR.c b/FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR/src/cg_src/r_cg_sci_user_IAR.c
new file mode 100644 (file)
index 0000000..ca57a95
--- /dev/null
@@ -0,0 +1,375 @@
+/***********************************************************************************************************************\r
+* DISCLAIMER\r
+* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.\r
+* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all\r
+* applicable laws, including copyright laws. \r
+* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED\r
+* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+* NON-INFRINGEMENT.  ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY\r
+* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,\r
+* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR\r
+* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\r
+* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability \r
+* of this software. By using this software, you agree to the additional terms and conditions found by accessing the \r
+* following link:\r
+* http://www.renesas.com/disclaimer\r
+*\r
+* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.\r
+***********************************************************************************************************************/\r
+\r
+/***********************************************************************************************************************\r
+* File Name    : r_cg_sci_user.c\r
+* Version      : Code Generator for RX113 V1.02.01.02 [28 May 2015]\r
+* Device(s)    : R5F51138AxFP\r
+* Tool-Chain   : CCRX\r
+* Description  : This file implements device driver for SCI module.\r
+* Creation Date: 21/09/2015\r
+***********************************************************************************************************************/\r
+\r
+/***********************************************************************************************************************\r
+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
+Includes\r
+***********************************************************************************************************************/\r
+#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 "rskrx113def.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
+/***********************************************************************************************************************\r
+Global variables and functions\r
+***********************************************************************************************************************/\r
+extern uint8_t * gp_sci1_tx_address;         /* SCI1 send buffer address */\r
+extern uint16_t  g_sci1_tx_count;            /* SCI1 send data number */\r
+extern uint8_t * gp_sci1_rx_address;         /* SCI1 receive buffer address */\r
+extern uint16_t  g_sci1_rx_count;            /* SCI1 receive data number */\r
+extern uint16_t  g_sci1_rx_length;           /* SCI1 receive data length */\r
+/* Start user code for global. Do not edit comment generated here */\r
+\r
+/* Global used to receive a character from the PC terminal */\r
+uint8_t g_rx_char;\r
+\r
+/* Flag used to control transmission to PC terminal */\r
+volatile uint8_t g_tx_flag = FALSE;\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 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
+/***********************************************************************************************************************\r
+* Function Name: r_sci1_transmit_interrupt\r
+* Description  : None\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+#pragma vector = VECT_SCI1_TXI1\r
+#if FAST_INTERRUPT_VECTOR == VECT_SCI1_TXI1\r
+__fast_interrupt static void r_sci1_transmit_interrupt(void)\r
+#else\r
+__interrupt static void r_sci1_transmit_interrupt(void)\r
+#endif\r
+{\r
+    if (g_sci1_tx_count > 0U)\r
+    {\r
+        SCI1.TDR = *gp_sci1_tx_address;\r
+        gp_sci1_tx_address++;\r
+        g_sci1_tx_count--;\r
+    }\r
+    else \r
+    {\r
+        SCI1.SCR.BIT.TIE = 0U;\r
+        SCI1.SCR.BIT.TEIE = 1U;\r
+    }\r
+}\r
+/***********************************************************************************************************************\r
+* Function Name: r_sci1_transmitend_interrupt\r
+* Description  : None\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+#pragma vector = VECT_SCI1_TEI1\r
+#if FAST_INTERRUPT_VECTOR == VECT_SCI1_TEI1\r
+__fast_interrupt static void r_sci1_transmitend_interrupt(void)\r
+#else\r
+__interrupt static void r_sci1_transmitend_interrupt(void)\r
+#endif\r
+{\r
+    /* Set TXD1 pin */\r
+    PORT1.PMR.BYTE &= 0xBFU;\r
+    SCI1.SCR.BIT.TIE = 0U;\r
+    SCI1.SCR.BIT.TE = 0U;\r
+    SCI1.SCR.BIT.TEIE = 0U;\r
+\r
+    r_sci1_callback_transmitend();\r
+}\r
+/***********************************************************************************************************************\r
+* Function Name: r_sci1_receive_interrupt\r
+* Description  : None\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+#pragma vector = VECT_SCI1_RXI1\r
+#if FAST_INTERRUPT_VECTOR == VECT_SCI1_RXI1\r
+__fast_interrupt static void r_sci1_receive_interrupt(void)\r
+#else\r
+__interrupt static void r_sci1_receive_interrupt(void)\r
+#endif\r
+{\r
+    if (g_sci1_rx_length > g_sci1_rx_count)\r
+    {\r
+        *gp_sci1_rx_address = SCI1.RDR;\r
+        gp_sci1_rx_address++;\r
+        g_sci1_rx_count++;\r
+\r
+        if (g_sci1_rx_length == g_sci1_rx_count)\r
+        {\r
+            r_sci1_callback_receiveend();\r
+        }\r
+    }\r
+}\r
+/***********************************************************************************************************************\r
+* Function Name: r_sci1_receiveerror_interrupt\r
+* Description  : None\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+#pragma vector = VECT_SCI1_ERI1\r
+#if FAST_INTERRUPT_VECTOR == VECT_SCI1_ERI1\r
+__fast_interrupt static void r_sci1_receiveerror_interrupt(void)\r
+#else\r
+__interrupt static void r_sci1_receiveerror_interrupt(void)\r
+#endif\r
+{\r
+    uint8_t err_type;\r
+\r
+    r_sci1_callback_receiveerror();\r
+\r
+    /* Clear overrun, framing and parity error flags */\r
+    err_type = SCI1.SSR.BYTE;\r
+    SCI1.SSR.BYTE = err_type & ( uint8_t ) 0xC7;\r
+}\r
+/***********************************************************************************************************************\r
+* Function Name: r_sci1_callback_transmitend\r
+* Description  : This function is a callback function when SCI1 finishes transmission.\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+void r_sci1_callback_transmitend(void)\r
+{\r
+    /* Start user code. Do not edit comment generated here */\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
+* Function Name: r_sci1_callback_receiveend\r
+* Description  : This function is a callback function when SCI1 finishes reception.\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\r
+void r_sci1_callback_receiveend(void)\r
+{\r
+    /* Start user code. Do not edit comment generated here */\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( 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
+* Function Name: r_sci1_callback_receiveerror\r
+* Description  : This function is a callback function when SCI1 reception encounters error.\r
+* Arguments    : None\r
+* Return Value : None\r
+***********************************************************************************************************************/\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
+}\r
+\r
+/* Start user code for adding. Do not edit comment generated here */\r
+/***********************************************************************************************************************\r
+ * Function Name: R_SCI1_AsyncTransmit\r
+ * Description  : This function sends SCI1 data and waits for the transmit end flag.\r
+ * Arguments    : tx_buf -\r
+ *                    transfer buffer pointer\r
+ *                tx_num -\r
+ *                    buffer size\r
+ * Return Value : status -\r
+ *                    MD_OK or MD_ARGERROR\r
+ ***********************************************************************************************************************/\r
+MD_STATUS R_SCI1_AsyncTransmit (uint8_t * const tx_buf, const uint16_t tx_num)\r
+{\r
+    MD_STATUS status = MD_OK;\r
+\r
+    /* clear the flag before initiating a new transmission */\r
+    sci1_txdone = FALSE;\r
+\r
+    /* Send the data using the API */\r
+    status = R_SCI1_Serial_Send(tx_buf, tx_num);\r
+\r
+    /* Wait for the transmit end flag */\r
+    while (FALSE == sci1_txdone)\r
+    {\r
+        /* Wait */\r
+    }\r
+    return (status);\r
+}\r
+/***********************************************************************************************************************\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