#include "task_function.h" /* Start user code for import. Do not edit comment generated here */ #include "freertos_start.h" #include "platform.h" #include "r_sci_rx_if.h" #include "r_sci_rx_config.h" #include "r_byteq_if.h" static uint16_t my_sci_rx_length = 0; static volatile uint16_t my_sci_rx_count = 0; static void my_sci_callback(void *pArgs); /* End user code. Do not edit comment generated here */ void task_CONIO(void * pvParameters) { /* Start user code for function. Do not edit comment generated here */ INTERNAL_NOT_USED( pvParameters ); sci_err_t my_sci_err; sci_hdl_t my_sci_handle; sci_cfg_t my_sci_config; uint8_t my_char[3]; my_sci_config.async.baud_rate = 115200; my_sci_config.async.clk_src = SCI_CLK_INT; my_sci_config.async.data_size = SCI_DATA_8BIT; my_sci_config.async.parity_en = SCI_PARITY_OFF; my_sci_config.async.parity_type = SCI_EVEN_PARITY; my_sci_config.async.stop_bits = SCI_STOPBITS_1; my_sci_config.async.int_priority = 3; // 1=lowest, 15=highest my_sci_err = R_SCI_Open(SCI_CH1, SCI_MODE_ASYNC, &my_sci_config, my_sci_callback, &my_sci_handle); if (SCI_SUCCESS != my_sci_err) { for(;;); /* TODO: Handle an error */ } for (;;) { taskENTER_CRITICAL(); // or taskDISABLE_INTERRUPTS() { // FIXME: This is a super ultra tentative code :( my_sci_rx_length = 3; my_sci_rx_count = 0; } taskEXIT_CRITICAL(); // or taskENABLE_INTERRUPTS() xSemaphoreTake( semaphore_handle_CON_RX_READY, portMAX_DELAY ); my_sci_err = R_SCI_Receive(my_sci_handle, my_char, my_sci_rx_length); if (SCI_SUCCESS != my_sci_err) { for(;;); /* TODO: Handle an error */ } my_sci_err = R_SCI_Send(my_sci_handle, my_char, my_sci_rx_length); if (SCI_SUCCESS != my_sci_err) { for(;;); /* TODO: Handle an error */ } } /* End user code. Do not edit comment generated here */ } /* Start user code for other. Do not edit comment generated here */ void my_sci_callback(void *pArgs) { sci_cb_args_t *args; args = (sci_cb_args_t *)pArgs; if (args->event == SCI_EVT_RX_CHAR) { /* From RXI interrupt; received character data is in args->byte */ my_sci_rx_count++; if (my_sci_rx_count == my_sci_rx_length) { BaseType_t sHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR( semaphore_handle_CON_RX_READY, &sHigherPriorityTaskWoken ); portYIELD_FROM_ISR( sHigherPriorityTaskWoken ); } else if (my_sci_rx_count > my_sci_rx_length) { /* Prevent from doing xSemaphoreGiveFromISR() more than once */ /* Nothing to do */ } } #if SCI_CFG_CH1_DATA_MATCH_INCLUDED else if (args->event == SCI_EVT_RX_CHAR_MATCH) { /* From RXI interrupt; received match character data is in args->byte */ nop(); } #endif #if SCI_CFG_TEI_INCLUDED else if (args->event == SCI_EVT_TEI) { /* From TEI interrupt; transmitter is idle Possibly disable external transceiver here */ nop(); } #endif else if (args->event == SCI_EVT_RXBUF_OVFL) { /* From RXI interrupt; rx queue is full; 'lost' data is in args->byte You will need to increase buffer size or reduce baud rate */ nop(); } else if (args->event == SCI_EVT_OVFL_ERR) { /* From receiver overflow error interrupt; error data is in args->byte Error condition is cleared in calling interrupt routine */ nop(); } else if (args->event == SCI_EVT_FRAMING_ERR) { /* From receiver framing error interrupt; error data is in args->byte Error condition is cleared in calling interrupt routine */ nop(); } else if (args->event == SCI_EVT_PARITY_ERR) { /* From receiver parity error interrupt; error data is in args->byte Error condition is cleared in calling interrupt routine */ nop(); } } /* End user code. Do not edit comment generated here */