S32 SDK
eim_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
40 #include "eim_hw_access.h"
41 
42 /*******************************************************************************
43  * Variables
44  ******************************************************************************/
45 
47 static EIM_Type * const s_eimBase[] = EIM_BASE_PTRS;
48 
49 /*******************************************************************************
50  * Code
51  ******************************************************************************/
52 
53 /*FUNCTION**********************************************************************
54  *
55  * Function Name : EIM_DRV_Init
56  * Description : Initializes EIM module.
57  * This function configures for EIM channels.
58  * The EIM channel configuration structure array and number of configured channels
59  * shall be passed as arguments and enables module.
60  * This function should be called before calling any other EIM driver function
61  * and make sure that EIM channel has disabled before calling this function.
62  *
63  * Implements : EIM_DRV_Init_Activity
64  *END**************************************************************************/
65 void EIM_DRV_Init(uint32_t instance,
66  uint8_t channelCnt,
67  const eim_user_channel_config_t *channelConfigArr)
68 {
69  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
70  DEV_ASSERT(channelCnt > 0U);
71  DEV_ASSERT(channelCnt <= EIM_EICHDn_COUNT);
72  DEV_ASSERT(channelConfigArr != NULL);
73  EIM_Type * base = s_eimBase[instance];
74  uint8_t index;
75 
76  for (index = 0U; index < channelCnt; index++)
77  {
78  /* Configures for EIM module */
79  EIM_DRV_ConfigChannel(instance, &channelConfigArr[index]);
80  }
81 
82  /* Enables EIM module */
83  EIM_Enable(base);
84 }
85 
86 /*FUNCTION**********************************************************************
87  *
88  * Function Name : EIM_DRV_Deinit
89  * Description : De-initializes EIM module.
90  * This function sets all registers to reset value and disables EIM channel.
91  * In order to use the EIM channel again, EIM_DRV_Init must be called.
92  *
93  * Implements : EIM_DRV_Deinit_Activity
94  *END**************************************************************************/
95 void EIM_DRV_Deinit(uint32_t instance)
96 {
97  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
98  EIM_Type * base = s_eimBase[instance];
99 
100  /* Disables EIM module */
101  EIM_Disable(base);
102 
103  /* Resets EIM descriptors and disables EIM channels */
104  EIM_InitChannel(base);
105 }
106 
107 /*FUNCTION**********************************************************************
108  *
109  * Function Name : EIM_DRV_ConfigChannel
110  * Description : This function configures check bit mask, data mask and
111  * operation status(enable/disable) for EIM channel.
112  * The EIM channel configuration structure shall be
113  * passed as arguments.
114  * Make sure that EIM module has disabled before calling this function.
115  *
116  * Implements : EIM_DRV_ConfigChannel_Activity
117  *END**************************************************************************/
118 void EIM_DRV_ConfigChannel(uint32_t instance,
119  const eim_user_channel_config_t *userChannelConfig)
120 {
121  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
122  DEV_ASSERT(userChannelConfig != NULL);
123  DEV_ASSERT(userChannelConfig->channel < EIM_EICHDn_COUNT);
124  EIM_Type * base = s_eimBase[instance];
125 
126  /* Disables EIM channel to configure EIM channel */
127  EIM_EnableChannelCmd(base, userChannelConfig->channel, false);
128  /* Configures check-bit mask for EIM channel */
129  EIM_SetCheckBitMask(base, userChannelConfig->channel, userChannelConfig->checkBitMask);
130  /* Configures data mask for EIM channel */
131  EIM_SetDataMask(base, userChannelConfig->channel, userChannelConfig->dataMask);
132  /* Enables or disables EIM channel operation corresponding to channel configuration */
133  EIM_EnableChannelCmd(base, userChannelConfig->channel, userChannelConfig->enable);
134 }
135 
136 /*FUNCTION**********************************************************************
137  *
138  * Function Name : EIM_DRV_GetChannelConfig
139  * Description : This function gets check-bit mask, data mask and operation
140  * status of EIM channel.
141  *
142  * Implements : EIM_DRV_GetChannelConfig_Activity
143  *END**************************************************************************/
144 void EIM_DRV_GetChannelConfig(uint32_t instance,
145  uint8_t channel,
146  eim_user_channel_config_t *channelConfig)
147 {
148  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
149  DEV_ASSERT(channel < EIM_EICHDn_COUNT);
150  DEV_ASSERT(channelConfig != NULL);
151  const EIM_Type * base = s_eimBase[instance];
152 
153  /* Gets the channel number */
154  channelConfig->channel = channel;
155  /* Gets check-bit mask of EIM channel */
156  channelConfig->checkBitMask = EIM_GetCheckBitMask(base, channel);
157  /* Gets data mask of EIM channel */
158  channelConfig->dataMask = EIM_GetDataMask(base, channel);
159  /* Gets operation status */
160  channelConfig->enable = EIM_IsChannelEnabled(base, channel);
161 }
162 
163 /*FUNCTION**********************************************************************
164  *
165  * Function Name : EIM_DRV_GetDefaultConfig
166  * Description : This function gets check-bit mask, data mask and operation
167  * status default of EIM channel.
168  *
169  * Implements : EIM_DRV_GetDefaultConfig_Activity
170  *END**************************************************************************/
171 void EIM_DRV_GetDefaultConfig(uint8_t channel,
172  eim_user_channel_config_t *channelConfig)
173 {
174  DEV_ASSERT(channelConfig != NULL);
175  DEV_ASSERT(channel < EIM_EICHDn_COUNT);
176 
177  /* Gets the channel number */
178  channelConfig->channel = channel;
179  /* Gets check-bit mask default of EIM channel */
180  channelConfig->checkBitMask = EIM_CHECKBITMASK_DEFAULT;
181  /* Gets data mask default of EIM channel */
182  channelConfig->dataMask = EIM_DATAMASK_DEFAULT;
183  /* Enable EIM channel */
184  channelConfig->enable = true;
185 }
186 
187 /*******************************************************************************
188  * EOF
189  ******************************************************************************/
#define EIM_EICHDn_COUNT
Definition: S32K142.h:3086
#define EIM_DATAMASK_DEFAULT
The value default of EIM data mask.
Definition: eim_driver.h:50
#define DEV_ASSERT(x)
Definition: devassert.h:77
static EIM_Type *const s_eimBase[]
Table of base addresses for EIM instances.
Definition: eim_driver.c:47
void EIM_DRV_ConfigChannel(uint32_t instance, const eim_user_channel_config_t *userChannelConfig)
Configures the EIM channel.
Definition: eim_driver.c:118
#define EIM_CHECKBITMASK_DEFAULT
The value default of EIM check-bit mask.
Definition: eim_driver.h:48
void EIM_DRV_Deinit(uint32_t instance)
De-initializes the EIM module.
Definition: eim_driver.c:95
void EIM_DRV_Init(uint32_t instance, uint8_t channelCnt, const eim_user_channel_config_t *channelConfigArr)
Initializes the EIM module.
Definition: eim_driver.c:65
EIM channel configuration structure.
Definition: eim_driver.h:58
#define EIM_BASE_PTRS
Definition: S32K142.h:3112
void EIM_DRV_GetChannelConfig(uint32_t instance, uint8_t channel, eim_user_channel_config_t *channelConfig)
Gets the EIM channel configuration.
Definition: eim_driver.c:144
void EIM_DRV_GetDefaultConfig(uint8_t channel, eim_user_channel_config_t *channelConfig)
Gets the EIM channel configuration default.
Definition: eim_driver.c:171
#define EIM_INSTANCE_COUNT
Definition: S32K142.h:3101