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_sci.c
\r
22 * Version : Code Generator for RX113 V1.02.01.02 [28 May 2015]
\r
23 * Device(s) : R5F51138AxFP
\r
25 * Description : This file implements device driver for SCI module.
\r
26 * Creation Date: 21/09/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_sci.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 uint8_t * gp_sci1_tx_address; /* SCI1 transmit buffer address */
\r
48 uint16_t g_sci1_tx_count; /* SCI1 transmit data number */
\r
49 uint8_t * gp_sci1_rx_address; /* SCI1 receive buffer address */
\r
50 uint16_t g_sci1_rx_count; /* SCI1 receive data number */
\r
51 uint16_t g_sci1_rx_length; /* SCI1 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_SCI1_Create
\r
57 * Description : This function initializes the SCI1.
\r
59 * Return Value : None
\r
60 ***********************************************************************************************************************/
\r
61 void R_SCI1_Create(void)
\r
63 /* Cancel SCI1 module stop state */
\r
66 /* Set interrupt priority */
\r
67 IPR(SCI1, ERI1) = _0F_SCI_PRIORITY_LEVEL15;
\r
69 /* Clear the SCR.TIE, RIE, TE, RE and TEIE bits */
\r
70 SCI1.SCR.BIT.TIE = 0U;
\r
71 SCI1.SCR.BIT.RIE = 0U;
\r
72 SCI1.SCR.BIT.TE = 0U;
\r
73 SCI1.SCR.BIT.RE = 0U;
\r
74 SCI1.SCR.BIT.TEIE = 0U;
\r
77 MPC.P15PFS.BYTE = 0x0AU;
\r
78 PORT1.PMR.BYTE |= 0x20U;
\r
80 MPC.P16PFS.BYTE = 0x0AU;
\r
81 PORT1.PODR.BYTE |= 0x40U;
\r
82 PORT1.PDR.BYTE |= 0x40U;
\r
83 PORT1.PMR.BYTE |= 0x40U;
\r
85 /* Set clock enable */
\r
86 SCI1.SCR.BYTE = _00_SCI_INTERNAL_SCK_UNUSED;
\r
88 /* Clear the SIMR1.IICM, SPMR.CKPH, and CKPOL bit */
\r
89 SCI1.SIMR1.BIT.IICM = 0U;
\r
90 SCI1.SPMR.BYTE = _00_SCI_RTS | _00_SCI_CLOCK_NOT_INVERTED | _00_SCI_CLOCK_NOT_DELAYED;
\r
92 /* Set control registers */
\r
93 SCI1.SMR.BYTE = _01_SCI_CLOCK_PCLK_4 | _00_SCI_STOP_1 | _00_SCI_PARITY_EVEN | _00_SCI_PARITY_DISABLE |
\r
94 _00_SCI_DATA_LENGTH_8 | _00_SCI_MULTI_PROCESSOR_DISABLE | _00_SCI_ASYNCHRONOUS_MODE;
\r
95 SCI1.SCMR.BYTE = _00_SCI_SERIAL_MODE | _00_SCI_DATA_INVERT_NONE | _00_SCI_DATA_LSB_FIRST | _72_SCI_SCMR_DEFAULT;
\r
97 /* Set SEMR, SNFR */
\r
98 SCI1.SEMR.BYTE = _00_SCI_LOW_LEVEL_START_BIT | _00_SCI_NOISE_FILTER_DISABLE | _10_SCI_8_BASE_CLOCK;
\r
103 /***********************************************************************************************************************
\r
104 * Function Name: R_SCI1_Start
\r
105 * Description : This function starts the SCI1.
\r
107 * Return Value : None
\r
108 ***********************************************************************************************************************/
\r
109 void R_SCI1_Start(void)
\r
111 IR(SCI1,TXI1) = 0U;
\r
112 IR(SCI1,TEI1) = 0U;
\r
113 IR(SCI1,RXI1) = 0U;
\r
114 IR(SCI1,ERI1) = 0U;
\r
115 IEN(SCI1,TXI1) = 1U;
\r
116 IEN(SCI1,TEI1) = 1U;
\r
117 IEN(SCI1,RXI1) = 1U;
\r
118 IEN(SCI1,ERI1) = 1U;
\r
120 /***********************************************************************************************************************
\r
121 * Function Name: R_SCI1_Stop
\r
122 * Description : This function stops the SCI1.
\r
124 * Return Value : None
\r
125 ***********************************************************************************************************************/
\r
126 void R_SCI1_Stop(void)
\r
129 PORT1.PMR.BYTE &= 0xBFU;
\r
131 SCI1.SCR.BYTE &= 0xCF; /* Disable serial transmit and receive */
\r
132 SCI1.SCR.BIT.TIE = 0U; /* Disable TXI interrupt */
\r
133 SCI1.SCR.BIT.RIE = 0U; /* Disable RXI and ERI interrupt */
\r
134 IR(SCI1,TXI1) = 0U;
\r
135 IEN(SCI1,TXI1) = 0U;
\r
136 IR(SCI1,TEI1) = 0U;
\r
137 IEN(SCI1,TEI1) = 0U;
\r
138 IR(SCI1,RXI1) = 0U;
\r
139 IEN(SCI1,RXI1) = 0U;
\r
140 IR(SCI1,ERI1) = 0U;
\r
141 IEN(SCI1,ERI1) = 0U;
\r
143 /***********************************************************************************************************************
\r
144 * Function Name: R_SCI1_Serial_Receive
\r
145 * Description : This function receives SCI1 data.
\r
146 * Arguments : rx_buf -
\r
147 * receive buffer pointer (Not used when receive data handled by DTC)
\r
150 * Return Value : status -
\r
151 * MD_OK or MD_ARGERROR
\r
152 ***********************************************************************************************************************/
\r
153 MD_STATUS R_SCI1_Serial_Receive(uint8_t * const rx_buf, uint16_t rx_num)
\r
155 MD_STATUS status = MD_OK;
\r
159 status = MD_ARGERROR;
\r
163 g_sci1_rx_count = 0U;
\r
164 g_sci1_rx_length = rx_num;
\r
165 gp_sci1_rx_address = rx_buf;
\r
166 SCI1.SCR.BIT.RIE = 1U;
\r
167 SCI1.SCR.BIT.RE = 1U;
\r
172 /***********************************************************************************************************************
\r
173 * Function Name: R_SCI1_Serial_Send
\r
174 * Description : This function transmits SCI1 data.
\r
175 * Arguments : tx_buf -
\r
176 * transfer buffer pointer (Not used when transmit data handled by DTC)
\r
179 * Return Value : status -
\r
180 * MD_OK or MD_ARGERROR
\r
181 ***********************************************************************************************************************/
\r
182 MD_STATUS R_SCI1_Serial_Send(uint8_t * const tx_buf, uint16_t tx_num)
\r
184 MD_STATUS status = MD_OK;
\r
188 status = MD_ARGERROR;
\r
192 gp_sci1_tx_address = tx_buf;
\r
193 g_sci1_tx_count = tx_num;
\r
195 PORT1.PMR.BYTE |= 0x40U;
\r
196 SCI1.SCR.BIT.TIE = 1U;
\r
197 SCI1.SCR.BIT.TE = 1U;
\r
203 /* Start user code for adding. Do not edit comment generated here */
\r
204 /* End user code. Do not edit comment generated here */
\r