1 /***********************************************************************************************************************
\r
3 * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
\r
4 * No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
\r
5 * applicable laws, including copyright laws.
\r
6 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
\r
7 * OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
8 * NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
\r
9 * LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
\r
10 * INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
\r
11 * ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
12 * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
\r
13 * of this software. By using this software, you agree to the additional terms and conditions found by accessing the
\r
15 * http://www.renesas.com/disclaimer
\r
17 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
\r
18 ***********************************************************************************************************************/
\r
20 /***********************************************************************************************************************
\r
21 * File Name : r_cg_scifa_user.c
\r
22 * Version : Code Generator for RZ/T1 V1.00.00.09 [02 Mar 2015]
\r
23 * Device(s) : R7S910018CBG
\r
24 * Tool-Chain : GCCARM
\r
25 * Description : This file implements device driver for SCIF module.
\r
26 * Creation Date: 19/04/2015
\r
27 ***********************************************************************************************************************/
\r
29 /***********************************************************************************************************************
\r
31 ***********************************************************************************************************************/
\r
32 /* Start user code for pragma. Do not edit comment generated here */
\r
33 /* End user code. Do not edit comment generated here */
\r
35 /***********************************************************************************************************************
\r
37 ***********************************************************************************************************************/
\r
38 #include "r_cg_macrodriver.h"
\r
39 #include "r_cg_scifa.h"
\r
40 /* Start user code for include. Do not edit comment generated here */
\r
41 #include "r_typedefs.h"
\r
42 #include "FreeRTOS.h"
\r
46 /* End user code. Do not edit comment generated here */
\r
47 #include "r_cg_userdefine.h"
\r
49 /***********************************************************************************************************************
\r
50 Global variables and functions
\r
51 ***********************************************************************************************************************/
\r
52 extern const uint8_t * gp_scifa2_tx_address; /* SCIFA2 send buffer address */
\r
53 extern uint16_t g_scifa2_tx_count; /* SCIFA2 send data number */
\r
54 extern uint8_t * gp_scifa2_rx_address; /* SCIFA2 receive buffer address */
\r
55 extern uint16_t g_scifa2_rx_count; /* SCIFA2 receive data number */
\r
56 extern uint16_t g_scifa2_rx_length; /* SCIFA2 receive data length */
\r
58 /* Start user code for global. Do not edit comment generated here */
\r
60 /* Characters received from the UART are stored in this queue, ready to be
\r
61 received by the application. ***NOTE*** Using a queue in this way is very
\r
62 convenient, but also very inefficient. It can be used here because characters
\r
63 will only arrive slowly. In a higher bandwidth system a circular RAM buffer or
\r
64 DMA should be used in place of this queue. */
\r
65 static QueueHandle_t xRxQueue = NULL;
\r
67 /* When a task calls vSerialPutString() its handle is stored in xSendingTask,
\r
68 before being placed into the Blocked state (so does not use any CPU time) to
\r
69 wait for the transmission to end. The task handle is then used from the UART
\r
70 transmit end interrupt to remove the task from the Blocked state. */
\r
71 static TaskHandle_t xSendingTask = NULL;
\r
74 * Entry point for the handlers. These set the pxISRFunction variable to point
\r
75 * to the C handler for each timer, then branch to the FreeRTOS IRQ handler.
\r
78 void r_scifa2_txif2_interrupt_entry( void ) __attribute__((naked));
\r
79 void r_scifa2_rxif2_interrupt_entry( void ) __attribute__((naked));
\r
80 void r_scifa2_drif2_interrupt_entry( void ) __attribute__((naked));
\r
81 void r_scifa2_brif2_interrupt_entry( void ) __attribute__((naked));
\r
82 #endif /* __GNUC__ */
\r
85 /* IAR requires the entry point to be in an assembly file. The functions
\r
86 are implemented in $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm. */
\r
87 extern void r_scifa2_txif2_interrupt_entry( void );
\r
88 extern void r_scifa2_rxif2_interrupt_entry( void );
\r
89 extern void r_scifa2_drif2_interrupt_entry( void );
\r
90 extern void r_scifa2_brif2_interrupt_entry( void );
\r
91 #endif /* __ICCARM__ */
\r
94 /* End user code. Do not edit comment generated here */
\r
96 /***********************************************************************************************************************
\r
97 * Function Name: r_scifa2_txif2_interrupt
\r
98 * Description : This function is TXIF2 interrupt service routine.
\r
100 * Return Value : None
\r
101 ***********************************************************************************************************************/
\r
102 void r_scifa2_txif2_interrupt(void)
\r
104 uint16_t count = 0;
\r
106 /* Get the amount of untransmitted data stored in the FRDR register */
\r
107 uint16_t dummy_fdr = SCIFA2.FDR.BIT.T;
\r
109 /* Write data to the transmit FIFO data register */
\r
110 while ((g_scifa2_tx_count > 0U) && (count < _SCIF_FIFO_MAX_SIZE - dummy_fdr))
\r
112 SCIFA2.FTDR = *gp_scifa2_tx_address;
\r
113 gp_scifa2_tx_address++;
\r
114 g_scifa2_tx_count--;
\r
118 if (SCIFA2.FSR.BIT.TDFE == 1U)
\r
120 SCIFA2.FSR.BIT.TDFE = 0U;
\r
123 if (g_scifa2_tx_count <= 0U)
\r
125 SCIFA2.SCR.BIT.TIE = 0U;
\r
126 SCIFA2.SCR.BIT.TEIE = 1U;
\r
129 /* Wait the interrupt signal is disabled */
\r
130 while (0U != (VIC.IRQS3.LONG & 0x00008000UL))
\r
132 VIC.IEC3.LONG = 0x00008000UL;
\r
135 VIC.IEN3.LONG |= 0x00008000UL;
\r
138 VIC.HVA0.LONG = 0x00000000UL;
\r
140 /***********************************************************************************************************************
\r
141 * Function Name: r_scifa2_rxif2_interrupt
\r
142 * Description : This function is RXIF2 interrupt service routine.
\r
144 * Return Value : None
\r
145 ***********************************************************************************************************************/
\r
146 void r_scifa2_rxif2_interrupt(void)
\r
148 uint16_t count = 0;
\r
150 /* Get the amount of receive data stored in FRDR register */
\r
151 uint16_t dummy_fdr = SCIFA2.FDR.BIT.R;
\r
153 /* Read data from the receive FIFO data register */
\r
154 while ((g_scifa2_rx_length > g_scifa2_rx_count) && (count < dummy_fdr))
\r
156 *gp_scifa2_rx_address = SCIFA2.FRDR;
\r
157 gp_scifa2_rx_address++;
\r
158 g_scifa2_rx_count++;
\r
162 /* If remaining data is less than the receive trigger number, receive interrupt will not occur.
\r
163 In this case, set trigger number to 1 to force receive interrupt for each one byte of data in FRDR */
\r
164 if ((g_scifa2_rx_length - g_scifa2_rx_count < _SCIF_RX_TRIG_NUM_2) && (SCIFA2.FTCR.BIT.RFTC != 1U))
\r
166 SCIFA2.FTCR.BIT.RFTC = 1U;
\r
169 /* Clear receive FIFO data full flag */
\r
170 if (SCIFA2.FSR.BIT.RDF == 1U)
\r
172 SCIFA2.FSR.BIT.RDF = 0U;
\r
175 if (g_scifa2_rx_length <= g_scifa2_rx_count)
\r
177 /* All data received */
\r
178 SCIFA2.SCR.BIT.RE = 0U;
\r
179 r_scifa2_callback_receiveend();
\r
182 /* Wait the interrupt signal is disabled */
\r
183 while (0U != (VIC.IRQS3.LONG & 0x00004000UL))
\r
185 VIC.IEC3.LONG = 0x00004000UL;
\r
188 VIC.IEN3.LONG |= 0x00004000UL;
\r
191 VIC.HVA0.LONG = 0x00000000UL;
\r
193 /***********************************************************************************************************************
\r
194 * Function Name: r_scifa2_drif2_interrupt
\r
195 * Description : This function is TEIF 2 or DRIF2 interrupt service routine.
\r
197 * Return Value : None
\r
198 ***********************************************************************************************************************/
\r
199 void r_scifa2_drif2_interrupt(void)
\r
201 if (1U == SCIFA2.FSR.BIT.TEND)
\r
203 SCIFA2.SPTR.BIT.SPB2DT = 0U;
\r
204 SCIFA2.SPTR.BIT.SPB2IO = 1U;
\r
205 SCIFA2.SCR.BIT.TE = 0U;
\r
206 SCIFA2.SCR.BIT.TEIE = 0U;
\r
208 r_scifa2_callback_transmitend();
\r
210 /* Clear data ready detect flag */
\r
211 if (1U == SCIFA2.FSR.BIT.DR)
\r
213 /* Start user code. Do not edit comment generated here */
\r
214 /* End user code. Do not edit comment generated here */
\r
215 SCIFA2.FSR.BIT.DR = 0U;
\r
218 /* Wait the interrupt signal is disabled */
\r
219 while (0U != (VIC.IRQS3.LONG & 0x00010000UL))
\r
221 VIC.IEC3.LONG = 0x00010000UL;
\r
224 VIC.IEN3.LONG |= 0x00010000UL;
\r
227 VIC.HVA0.LONG = 0x00000000UL;
\r
229 /***********************************************************************************************************************
\r
230 * Function Name: r_scifa2_brif2_interrupt
\r
231 * Description : This function is BRIF2 or ERIF2 interrupt service routine.
\r
233 * Return Value : None
\r
234 ***********************************************************************************************************************/
\r
235 void r_scifa2_brif2_interrupt(void)
\r
237 if (1U == SCIFA2.FSR.BIT.BRK)
\r
239 r_scifa2_callback_error(BREAK_DETECT);
\r
240 /* Clear break detect flag */
\r
241 SCIFA2.FSR.BIT.BRK = 0U;
\r
244 if (1U == SCIFA2.FSR.BIT.ER)
\r
246 r_scifa2_callback_error(RECEIVE_ERROR);
\r
247 /* Clear receive error flag */
\r
248 SCIFA2.FSR.BIT.ER = 0U;
\r
251 if (1U == SCIFA2.LSR.BIT.ORER)
\r
253 r_scifa2_callback_error(OVERRUN_ERROR);
\r
254 /* Clear overrun error flag */
\r
255 SCIFA2.LSR.BIT.ORER = 0U;
\r
258 /* Wait the interrupt signal is disabled */
\r
259 while (0U != (VIC.IRQS3.LONG & 0x00002000UL))
\r
261 VIC.IEC3.LONG = 0x00002000UL;
\r
264 VIC.IEN3.LONG |= 0x00002000UL;
\r
267 VIC.HVA0.LONG = 0x00000000UL;
\r
269 /***********************************************************************************************************************
\r
270 * Function Name: r_scifa2_callback_transmitend
\r
271 * Description : This function is a callback function when SCIFA2 finishes transmission.
\r
273 * Return Value : None
\r
274 ***********************************************************************************************************************/
\r
275 void r_scifa2_callback_transmitend(void)
\r
277 /* Start user code. Do not edit comment generated here */
\r
278 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
280 if( xSendingTask != NULL )
\r
282 /* A task is waiting for the end of the Tx, unblock it now.
\r
283 http://www.freertos.org/vTaskNotifyGiveFromISR.html */
\r
284 vTaskNotifyGiveFromISR( xSendingTask, &xHigherPriorityTaskWoken );
\r
285 xSendingTask = NULL;
\r
287 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
290 /* End user code. Do not edit comment generated here */
\r
292 /***********************************************************************************************************************
\r
293 * Function Name: r_scifa2_callback_receiveend
\r
294 * Description : This function is a callback function when SCIFA2 finishes reception.
\r
296 * Return Value : None
\r
297 ***********************************************************************************************************************/
\r
298 void r_scifa2_callback_receiveend(void)
\r
300 /* Start user code. Do not edit comment generated here */
\r
301 uint8_t ucRxedChar = 0;
\r
302 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
304 /* Read the received data */
\r
305 ucRxedChar = SCIFA2.FRDR;
\r
307 /* Characters received from the UART are stored in this queue, ready to be
\r
308 received by the application. ***NOTE*** Using a queue in this way is very
\r
309 convenient, but also very inefficient. It can be used here because
\r
310 characters will only arrive slowly. In a higher bandwidth system a circular
\r
311 RAM buffer or DMA should be used in place of this queue. */
\r
312 xQueueSendFromISR( xRxQueue, ( void * ) &ucRxedChar, &xHigherPriorityTaskWoken );
\r
314 /* Re-enable receptions */
\r
315 SCIFA2.SCR.BIT.RE = 1U;
\r
317 /* End user code. Do not edit comment generated here */
\r
319 /***********************************************************************************************************************
\r
320 * Function Name: r_scifa2_callback_error
\r
321 * Description : This function is a callback function when SCIFA2 reception encounters error.
\r
322 * Arguments : error_type -
\r
323 * reception error type
\r
324 * Return Value : None
\r
325 ***********************************************************************************************************************/
\r
326 void r_scifa2_callback_error(scif_error_type_t error_type)
\r
328 /* Start user code. Do not edit comment generated here */
\r
330 /* Used to suppress the warning message generated for unused variables */
\r
331 UNUSED_PARAM(error_type);
\r
333 /* End user code. Do not edit comment generated here */
\r
336 /* Start user code for adding. Do not edit comment generated here */
\r
338 /* Function required in order to link UARTCommandConsole.c - which is used by
\r
339 multiple different demo application. */
\r
340 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
342 ( void ) ulWantedBaud;
\r
343 ( void ) uxQueueLength;
\r
345 /* Characters received from the UART are stored in this queue, ready to be
\r
346 received by the application. ***NOTE*** Using a queue in this way is very
\r
347 convenient, but also very inefficient. It can be used here because
\r
348 characters will only arrive slowly. In a higher bandwidth system a circular
\r
349 RAM buffer or DMA should be used in place of this queue. */
\r
350 xRxQueue = xQueueCreate( uxQueueLength, sizeof( char ) );
\r
351 configASSERT( xRxQueue );
\r
353 /* Enable the receive. */
\r
354 SCIFA2.FTCR.BIT.RFTC = _SCIF_RX_TRIG_NUM_2;
\r
356 SCIFA2.SCR.BIT.RE = 1U;
\r
357 SCIFA2.SCR.BIT.RIE = 1U;
\r
358 SCIFA2.SCR.BIT.REIE = 1U;
\r
360 /* Enable SCI1 operations */
\r
363 /* Only one UART is supported, so it doesn't matter what is returned
\r
368 /* Function required in order to link UARTCommandConsole.c - which is used by
\r
369 multiple different demo application. */
\r
370 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
372 const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 5000 );
\r
374 /* Only one port is supported. */
\r
377 /* Don't send the string unless the previous string has been sent. */
\r
378 if( xSendingTask == NULL )
\r
380 /* Ensure the calling task's notification state is not already
\r
382 vTaskNotifyStateClear( NULL );
\r
384 /* Store the handle of the transmitting task. This is used to unblock
\r
385 the task when the transmission has completed. */
\r
386 xSendingTask = xTaskGetCurrentTaskHandle();
\r
388 /* Send the string using the auto-generated API. */
\r
389 R_SCIFA2_Serial_Send( ( uint8_t * ) pcString, usStringLength );
\r
391 /* Wait in the Blocked state (so not using any CPU time) until the
\r
392 transmission has completed. */
\r
393 ulTaskNotifyTake( pdTRUE, xMaxBlockTime );
\r
397 /* Function required in order to link UARTCommandConsole.c - which is used by
\r
398 multiple different demo application. */
\r
399 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
401 /* Only one UART is supported. */
\r
404 /* Return a received character, if any are available. Otherwise block to
\r
405 wait for a character. */
\r
406 return xQueueReceive( xRxQueue, pcRxedChar, xBlockTime );
\r
409 /* Function required in order to link UARTCommandConsole.c - which is used by
\r
410 multiple different demo application. */
\r
411 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
413 /* Just mapped to vSerialPutString() so the block time is not used. */
\r
414 ( void ) xBlockTime;
\r
416 vSerialPutString( pxPort, &cOutChar, sizeof( cOutChar ) );
\r
419 /* End user code. Do not edit comment generated here */
\r
422 * The RZ/T vectors directly to a peripheral specific interrupt handler, rather
\r
423 * than using the Cortex-R IRQ vector. Therefore each interrupt handler
\r
424 * installed by the application must follow the examples below, which save a
\r
425 * pointer to a standard C function in the pxISRFunction variable, before
\r
426 * branching to the FreeRTOS IRQ handler. The FreeRTOS IRQ handler then manages
\r
427 * interrupt entry (including interrupt nesting), before calling the C function
\r
428 * saved in the pxISRFunction variable. NOTE: The entry points are naked
\r
429 * functions - do not add C code to these functions.
\r
432 /* The IAR equivalent is implemented in
\r
433 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
434 void r_scifa2_txif2_interrupt_entry( void )
\r
437 "PUSH {r0-r1} \t\n" \
\r
438 "LDR r0, =pxISRFunction \t\n" \
\r
439 "LDR r1, =r_scifa2_txif2_interrupt \t\n" \
\r
440 "STR r1, [r0] \t\n" \
\r
441 "POP {r0-r1} \t\n" \
\r
442 "B FreeRTOS_IRQ_Handler "
\r
445 #endif /* __GNUC__ */
\r
446 /*-----------------------------------------------------------*/
\r
449 /* The IAR equivalent is implemented in
\r
450 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
451 void r_scifa2_rxif2_interrupt_entry( void )
\r
454 "PUSH {r0-r1} \t\n" \
\r
455 "LDR r0, =pxISRFunction \t\n" \
\r
456 "LDR r1, =r_scifa2_rxif2_interrupt \t\n" \
\r
457 "STR r1, [r0] \t\n" \
\r
458 "POP {r0-r1} \t\n" \
\r
459 "B FreeRTOS_IRQ_Handler "
\r
462 #endif /* __GNUC__ */
\r
463 /*-----------------------------------------------------------*/
\r
466 /* The IAR equivalent is implemented in
\r
467 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
468 void r_scifa2_drif2_interrupt_entry( void )
\r
471 "PUSH {r0-r1} \t\n" \
\r
472 "LDR r0, =pxISRFunction \t\n" \
\r
473 "LDR r1, =r_scifa2_drif2_interrupt \t\n" \
\r
474 "STR r1, [r0] \t\n" \
\r
475 "POP {r0-r1} \t\n" \
\r
476 "B FreeRTOS_IRQ_Handler "
\r
479 #endif /* __GNUC__ */
\r
480 /*-----------------------------------------------------------*/
\r
483 /* The IAR equivalent is implemented in
\r
484 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
485 void r_scifa2_brif2_interrupt_entry( void )
\r
488 "PUSH {r0-r1} \t\n" \
\r
489 "LDR r0, =pxISRFunction \t\n" \
\r
490 "LDR r1, =r_scifa2_brif2_interrupt \t\n" \
\r
491 "STR r1, [r0] \t\n" \
\r
492 "POP {r0-r1} \t\n" \
\r
493 "B FreeRTOS_IRQ_Handler "
\r
496 #endif /* __GNUC__ */
\r
497 /*-----------------------------------------------------------*/
\r