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