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.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: 22/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 /* End user code. Do not edit comment generated here */
\r
42 #include "r_cg_userdefine.h"
\r
44 /***********************************************************************************************************************
\r
45 Global variables and functions
\r
46 ***********************************************************************************************************************/
\r
47 const uint8_t * gp_scifa2_tx_address; /* SCIFA2 transmit buffer address */
\r
48 uint16_t g_scifa2_tx_count; /* SCIFA2 transmit data number */
\r
49 uint8_t * gp_scifa2_rx_address; /* SCIFA2 receive buffer address */
\r
50 uint16_t g_scifa2_rx_count; /* SCIFA2 receive data number */
\r
51 uint16_t g_scifa2_rx_length; /* SCIFA2 receive data length */
\r
52 /* Start user code for global. Do not edit comment generated here */
\r
53 /* End user code. Do not edit comment generated here */
\r
55 /***********************************************************************************************************************
\r
56 * Function Name: R_SCIFA2_Create
\r
57 * Description : This function initializes SCIFA2.
\r
59 * Return Value : None
\r
60 ***********************************************************************************************************************/
\r
61 void R_SCIFA2_Create(void)
\r
63 volatile uint16_t dummy;
\r
66 /* Cancel SCIFA2 module stop state */
\r
69 /* Disable TXIF2 interrupt */
\r
70 VIC.IEC3.LONG = 0x00008000UL;
\r
72 /* Disable RXIF2 interrupt */
\r
73 VIC.IEC3.LONG = 0x00004000UL;
\r
75 /* Disable BRIF2 interrupt */
\r
76 VIC.IEC3.LONG = 0x00002000UL;
\r
78 /* Disable DRIF2 interrupt */
\r
79 VIC.IEC3.LONG = 0x00010000UL;
\r
81 /* Clear transmit/receive enable bits */
\r
82 SCIFA2.SCR.BIT.TE = 0U;
\r
83 SCIFA2.SCR.BIT.RE = 0U;
\r
85 /* Reset transmit/receive FIFO data register operation */
\r
86 SCIFA2.FCR.BIT.TFRST = 1U;
\r
87 SCIFA2.FCR.BIT.RFRST = 1U;
\r
89 /* Read and clear status flags */
\r
90 dummy = SCIFA2.FSR.WORD;
\r
92 SCIFA2.FSR.WORD = 0x00U;
\r
93 dummy = (uint16_t) SCIFA2.LSR.BIT.ORER;
\r
95 SCIFA2.LSR.BIT.ORER = 0U;
\r
97 /* Set clock enable bits */
\r
98 SCIFA2.SCR.WORD = _SCIF_INTERNAL_SCK_UNUSED;
\r
100 /* Set transmission/reception format */
\r
101 SCIFA2.SMR.WORD = _SCIF_CLOCK_SERICLK_4 | _SCIF_STOP_1 | _SCIF_PARITY_DISABLE | _SCIF_DATA_LENGTH_8 |
\r
102 _SCIF_ASYNCHRONOUS_MODE;
\r
103 SCIFA2.SEMR.BYTE = _SCIF_16_BASE_CLOCK | _SCIF_NOISE_FILTER_ENABLE | _SCIF_DATA_TRANSFER_LSB_FIRST |
\r
104 _SCIF_BAUDRATE_SINGLE;
\r
106 /* Clear modulation duty register select */
\r
107 SCIFA2.SEMR.BIT.MDDRS = 0U;
\r
110 SCIFA2.BRR_MDDR.BRR = 0x3CU;
\r
112 /* Wait for at least 1-bit interval */
\r
113 for (w_count = 0U; w_count < _SCIF_1BIT_INTERVAL_2; w_count++)
\r
118 /* Set FIFO trigger conditions */
\r
119 SCIFA2.FTCR.WORD = _SCIF_TX_FIFO_TRIGGER_NUM_0 | _SCIF_TX_TRIGGER_TFTC_VALID | _SCIF_RX_FIFO_TRIGGER_NUM_1 |
\r
120 _SCIF_RX_TRIGGER_RFTC_VALID;
\r
121 SCIFA2.FCR.WORD = _SCIF_LOOPBACK_DISABLE | _SCIF_MODEM_CONTROL_DISABLE;
\r
123 /* Disable transmit/receive FIFO data register reset operation */
\r
124 SCIFA2.FCR.BIT.TFRST = 0U;
\r
125 SCIFA2.FCR.BIT.RFRST = 0U;
\r
127 /* Set TXIF2 interrupt priority */
\r
128 VIC.PRL111.LONG = _SCIF_PRIORITY_LEVEL2;
\r
130 /* Set TXIF2 interrupt address */
\r
131 VIC.VAD111.LONG = (uint32_t)r_scifa2_txif2_interrupt;
\r
133 /* Set RXIF2 interrupt priority */
\r
134 VIC.PRL110.LONG = _SCIF_PRIORITY_LEVEL3;
\r
136 /* Set RXIF2 interrupt address */
\r
137 VIC.VAD110.LONG = (uint32_t)r_scifa2_rxif2_interrupt;
\r
139 /* Set BRIF2 interrupt priority */
\r
140 VIC.PRL109.LONG = _SCIF_PRIORITY_LEVEL5;
\r
142 /* Set BRIF2 interrupt address */
\r
143 VIC.VAD109.LONG = (uint32_t)r_scifa2_brif2_interrupt;
\r
145 /* Set DRIF2 interrupt priority */
\r
146 VIC.PRL112.LONG = _SCIF_PRIORITY_LEVEL4;
\r
148 /* Set DRIF2 interrupt address */
\r
149 VIC.VAD112.LONG = (uint32_t)r_scifa2_drif2_interrupt;
\r
151 /***********************************************************************************************************************
\r
152 * Function Name: R_SCIFA2_Start
\r
153 * Description : This function starts SCIFA2.
\r
155 * Return Value : None
\r
156 ***********************************************************************************************************************/
\r
157 void R_SCIFA2_Start(void)
\r
159 /* Enable TXIF2 interrupt */
\r
160 VIC.IEN3.LONG |= 0x00008000UL;
\r
162 /* Enable RXIF2 interrupt */
\r
163 VIC.IEN3.LONG |= 0x00004000UL;
\r
165 /* Enable BRIF2 interrupt */
\r
166 VIC.IEN3.LONG |= 0x00002000UL;
\r
168 /* Enable DRIF2 interrupt */
\r
169 VIC.IEN3.LONG |= 0x00010000UL;
\r
171 /***********************************************************************************************************************
\r
172 * Function Name: R_SCIFA2_Stop
\r
173 * Description : This function stops SCIFA2.
\r
175 * Return Value : None
\r
176 ***********************************************************************************************************************/
\r
177 void R_SCIFA2_Stop(void)
\r
179 /* Disable serial transmit */
\r
180 SCIFA2.SCR.BIT.TE = 0U;
\r
182 /* Disable serial receive */
\r
183 SCIFA2.SCR.BIT.RE = 0U;
\r
185 /* Disable TXI interrupt */
\r
186 SCIFA2.SCR.BIT.TIE = 0U;
\r
188 /* Disable RXI and ERI interrupt */
\r
189 SCIFA2.SCR.BIT.RIE = 0U;
\r
191 /* Disable TXIF2 interrupt */
\r
192 VIC.IEC3.LONG = 0x00008000UL;
\r
194 /* Disable RXIF2 interrupt */
\r
195 VIC.IEC3.LONG = 0x00004000UL;
\r
197 /* Disable BRIF2 interrupt */
\r
198 VIC.IEC3.LONG = 0x00002000UL;
\r
200 /* Disable DRIF2 interrupt */
\r
201 VIC.IEC3.LONG = 0x00010000UL;
\r
203 /***********************************************************************************************************************
\r
204 * Function Name: R_SCIFA2_Serial_Receive
\r
205 * Description : This function receives SCIFA2 data.
\r
206 * Arguments : rx_buf -
\r
207 * receive buffer pointer (Not used when receive data handled by DMAC)
\r
209 * buffer size (Not used when receive data handled by DMAC)
\r
210 * Return Value : status -
\r
211 * MD_OK or MD_ARGERROR
\r
212 ***********************************************************************************************************************/
\r
213 MD_STATUS R_SCIFA2_Serial_Receive(uint8_t * rx_buf, uint16_t rx_num)
\r
215 MD_STATUS status = MD_OK;
\r
219 status = MD_ARGERROR;
\r
223 g_scifa2_rx_count = 0U;
\r
224 g_scifa2_rx_length = rx_num;
\r
225 gp_scifa2_rx_address = rx_buf;
\r
227 SCIFA2.FTCR.BIT.RFTC = _SCIF_RX_TRIG_NUM_2;
\r
229 SCIFA2.SCR.BIT.RE = 1U;
\r
230 SCIFA2.SCR.BIT.RIE = 1U;
\r
231 SCIFA2.SCR.BIT.REIE = 1U;
\r
236 /***********************************************************************************************************************
\r
237 * Function Name: R_SCIFA2_Serial_Send
\r
238 * Description : This function transmits SCIFA2 data.
\r
239 * Arguments : tx_buf -
\r
240 * transfer buffer pointer (Not used when transmit data handled by DMAC)
\r
242 * buffer size (Not used when transmit data handled by DMAC)
\r
243 * Return Value : status -
\r
244 * MD_OK or MD_ARGERROR
\r
245 ***********************************************************************************************************************/
\r
246 MD_STATUS R_SCIFA2_Serial_Send(const uint8_t * tx_buf, uint16_t tx_num)
\r
248 MD_STATUS status = MD_OK;
\r
252 status = MD_ARGERROR;
\r
256 gp_scifa2_tx_address = tx_buf;
\r
257 g_scifa2_tx_count = tx_num;
\r
258 SCIFA2.SCR.BIT.TE = 1U;
\r
259 SCIFA2.SCR.BIT.TIE = 1U;
\r
265 /* Start user code for adding. Do not edit comment generated here */
\r
266 /* End user code. Do not edit comment generated here */
\r