1 /**
2  * @file xmc_ebu.c
3  * @date 2017-06-24
4  *
5  * @cond
6  *********************************************************************************************************************
7  * XMClib v2.1.24 - XMC Peripheral Driver Library
8  *
9  * Copyright (c) 2015-2019, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  * Change History
37  * --------------
38  *
39  * 2015-02-20:
40  *     - Initial <br>
41  *
42  * 2015-06-20:
43  *     - Removed GetDriverVersion API
44  *
45  * 2017-06-24:
46  *     - Changed XMC_EBU_Init() adding checks for the clock acknoledgment.
47  *
48  * @endcond
49  *
50  */
51 
52 /*********************************************************************************************************************
53  * HEADER FILES
54  *********************************************************************************************************************/
55 
56 #include <xmc_ebu.h>
57 
58 #if defined(EBU)
59 
60 /*********************************************************************************************************************
61  * API IMPLEMENTATION
62  *********************************************************************************************************************/
63 
64 /*
65  * Initialize the EBU peripheral
66  */
XMC_EBU_Init(XMC_EBU_t * const ebu,const XMC_EBU_CONFIG_t * const config)67 XMC_EBU_STATUS_t XMC_EBU_Init(XMC_EBU_t *const ebu,const XMC_EBU_CONFIG_t *const config)
68 {
69   XMC_ASSERT("XMC_EBU_Init: Invalid module pointer", XMC_EBU_CHECK_MODULE_PTR(ebu));
70   XMC_ASSERT("XMC_EBU_Init:Null Pointer", (config != (XMC_EBU_CONFIG_t *)NULL));
71 
72   /* Enable EBU */
73   XMC_EBU_Enable(ebu);
74 
75   /* Clock configuration */
76   ebu->CLC  =  config->ebu_clk_config.raw0;
77   while (((ebu->CLC & (EBU_CLC_SYNCACK_Msk | EBU_CLC_DIV2ACK_Msk | EBU_CLC_EBUDIVACK_Msk)) >> 4) !=
78          (config->ebu_clk_config.raw0 & (EBU_CLC_SYNC_Msk | EBU_CLC_DIV2_Msk | EBU_CLC_EBUDIV_Msk)));
79 
80   /*EBU Mode Configuration */
81   ebu->MODCON = config->ebu_mode_config.raw0;
82 
83   /* Address Bits available for GPIO function */
84   ebu->USERCON = config->ebu_free_pins_to_gpio.raw0;
85 
86   return XMC_EBU_STATUS_OK;
87 }
88 
89 /*
90  * Configures the SDRAM with operating modes and refresh parameters
91  */
XMC_EBU_ConfigureSdram(XMC_EBU_t * const ebu,const XMC_EBU_SDRAM_CONFIG_t * const config)92 void XMC_EBU_ConfigureSdram(XMC_EBU_t *const ebu,const XMC_EBU_SDRAM_CONFIG_t *const config)
93 {
94   XMC_ASSERT("XMC_EBU_Init: Invalid module pointer", XMC_EBU_CHECK_MODULE_PTR(ebu));
95   XMC_ASSERT("XMC_EBU_Init:Null Pointer", (config != (XMC_EBU_SDRAM_CONFIG_t *)NULL));
96 
97   /* EBU SDRAM Refresh Configuration Parameters */
98   ebu->SDRMREF = config->raw2;
99   /* EBU SDRAM General Configuration Parameters */
100   ebu->SDRMCON = config->raw0;
101   /* EBU SDRAM Operation Mode Configuration Parameters */
102   ebu->SDRMOD = config->raw1;
103 }
104 
105 /*
106  * Configures the SDRAM region for read and write operation
107  */
XMC_EBU_ConfigureRegion(XMC_EBU_t * const ebu,const XMC_EBU_REGION_t * const region)108 void XMC_EBU_ConfigureRegion(XMC_EBU_t *const ebu,const XMC_EBU_REGION_t *const region)
109 {
110 
111   XMC_ASSERT("XMC_EBU_Init: Invalid module pointer", XMC_EBU_CHECK_MODULE_PTR(ebu));
112   XMC_ASSERT("XMC_EBU_Init:Null Pointer", (region != (XMC_EBU_REGION_t *)NULL));
113 
114   /* Read configuration of the region*/
115   ebu->BUS[region->read_config.ebu_region_no].RDCON = region->read_config.ebu_bus_read_config.raw0;
116 
117   /* Read parameters of the region*/
118   ebu->BUS[region->read_config.ebu_region_no].RDAPR = region->read_config.ebu_bus_read_config.raw1;
119 
120   /* Write configuration of the region*/
121   ebu->BUS[region->write_config.ebu_region_no].WRCON = region->write_config.ebu_bus_write_config.raw0;
122 
123   /* Write parameters of the region*/
124   ebu->BUS[region->write_config.ebu_region_no].WRAPR = region->write_config.ebu_bus_write_config.raw1;
125 }
126 
127 
128 #endif /* defined(EBU) */
129