]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX113-RSK_GCC_e2studio_IAR/src/cg_src/r_cg_sci.c
761f53ca5a2bcfcfef572bf756af05e96c590490
[freertos] / FreeRTOS / Demo / RX113-RSK_GCC_e2studio_IAR / src / cg_src / r_cg_sci.c
1 /***********************************************************************************************************************\r
2 * DISCLAIMER\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
14 * following link:\r
15 * http://www.renesas.com/disclaimer\r
16 *\r
17 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.\r
18 ***********************************************************************************************************************/\r
19 \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
24 * Tool-Chain   : CCRX\r
25 * Description  : This file implements device driver for SCI module.\r
26 * Creation Date: 21/09/2015\r
27 ***********************************************************************************************************************/\r
28 \r
29 /***********************************************************************************************************************\r
30 Pragma directive\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
34 \r
35 /***********************************************************************************************************************\r
36 Includes\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
43 \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
54 \r
55 /***********************************************************************************************************************\r
56 * Function Name: R_SCI1_Create\r
57 * Description  : This function initializes the SCI1.\r
58 * Arguments    : None\r
59 * Return Value : None\r
60 ***********************************************************************************************************************/\r
61 void R_SCI1_Create(void)\r
62 {\r
63     /* Cancel SCI1 module stop state */\r
64     MSTP(SCI1) = 0U;\r
65 \r
66     /* Set interrupt priority */\r
67     IPR(SCI1, ERI1) = _0F_SCI_PRIORITY_LEVEL15;\r
68 \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
75 \r
76     /* Set RXD1 pin */\r
77     MPC.P15PFS.BYTE = 0x0AU;\r
78     PORT1.PMR.BYTE |= 0x20U;\r
79     /* Set TXD1 pin */\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
84 \r
85     /* Set clock enable */\r
86     SCI1.SCR.BYTE = _00_SCI_INTERNAL_SCK_UNUSED;\r
87 \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
91 \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
96 \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
99 \r
100     /* Set bitrate */\r
101     SCI1.BRR = 0x19U;\r
102 }\r
103 /***********************************************************************************************************************\r
104 * Function Name: R_SCI1_Start\r
105 * Description  : This function starts the SCI1.\r
106 * Arguments    : None\r
107 * Return Value : None\r
108 ***********************************************************************************************************************/\r
109 void R_SCI1_Start(void)\r
110 {\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
119 }\r
120 /***********************************************************************************************************************\r
121 * Function Name: R_SCI1_Stop\r
122 * Description  : This function stops the SCI1.\r
123 * Arguments    : None\r
124 * Return Value : None\r
125 ***********************************************************************************************************************/\r
126 void R_SCI1_Stop(void)\r
127 {\r
128     /* Set TXD1 pin */\r
129     PORT1.PMR.BYTE &= 0xBFU;\r
130 \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
142 }\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
148 *                rx_num -\r
149 *                    buffer size\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
154 {\r
155     MD_STATUS status = MD_OK;\r
156 \r
157     if (rx_num < 1U)\r
158     {\r
159         status = MD_ARGERROR;\r
160     }\r
161     else\r
162     {\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
168     }\r
169 \r
170     return (status);\r
171 }\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
177 *                tx_num -\r
178 *                    buffer size\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
183 {\r
184     MD_STATUS status = MD_OK;\r
185 \r
186     if (tx_num < 1U)\r
187     {\r
188         status = MD_ARGERROR;\r
189     }\r
190     else\r
191     {\r
192         gp_sci1_tx_address = tx_buf;\r
193         g_sci1_tx_count = tx_num;\r
194         /* Set TXD1 pin */\r
195         PORT1.PMR.BYTE |= 0x40U;\r
196         SCI1.SCR.BIT.TIE = 1U;\r
197         SCI1.SCR.BIT.TE = 1U;\r
198     }\r
199 \r
200     return (status);\r
201 }\r
202 \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