S32 SDK
eim_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 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 <stddef.h>
41 #include "eim_driver.h"
42 
43 /*******************************************************************************
44  * Variables
45  ******************************************************************************/
46 
49 
50 /*******************************************************************************
51  * Code
52  ******************************************************************************/
53 
54 /*FUNCTION**********************************************************************
55  *
56  * Function Name : EIM_DRV_Init
57  * Description : Initializes EIM module.
58  * This function configures for EIM channels.
59  * The EIM channel configuration structure array and number of configured channels
60  * shall be passed as arguments and enables module.
61  * This function should be called before calling any other EIM driver function
62  * and make sure that EIM module has disabled before calling this function.
63  *
64  * Implements : EIM_DRV_Init_Activity
65  *END**************************************************************************/
66 void EIM_DRV_Init(uint32_t instance,
67  uint8_t channelCnt,
68  const eim_user_channel_config_t *channelConfigArr)
69 {
70  EIM_Type * base;
71 
72  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
73 
74  base = g_eimBase[instance];
75  uint8_t index;
76 
77  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
78  DEV_ASSERT(channelCnt > 0U);
79  DEV_ASSERT(channelCnt <= EIM_EICHDn_COUNT);
80  DEV_ASSERT(channelConfigArr != NULL);
81 
82  for(index = 0U; index < channelCnt; index++)
83  {
84  /* Configures for EIM channel */
85  EIM_DRV_ConfigChannel(instance, &channelConfigArr[index]);
86  }
87 
88  /* Enables EIM module */
89  EIM_HAL_Enable(base);
90 }
91 
92 /*FUNCTION**********************************************************************
93  *
94  * Function Name : EIM_DRV_Deinit
95  * Description : De-initializes EIM module.
96  * This function sets all registers to reset value and disables EIM module.
97  * In order to use the EIM module again, EIM_DRV_Init must be called.
98  *
99  * Implements : EIM_DRV_Deinit_Activity
100  *END**************************************************************************/
101 void EIM_DRV_Deinit(uint32_t instance)
102 {
103  EIM_Type * base;
104 
105  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
106 
107  base = g_eimBase[instance];
108 
109  /* Disables EIM module */
110  EIM_HAL_Disable(base);
111  /* Resets EIM descriptors and disables EIM channels */
112  EIM_HAL_Init(base);
113 }
114 
115 /*FUNCTION**********************************************************************
116  *
117  * Function Name : EIM_DRV_ConfigChannel
118  * Description : This function configures check bit mask, data mask and
119  * operation status(enable/disable) for EIM channel.
120  * The EIM channel configuration structure shall be
121  * passed as arguments.
122  * Make sure that EIM module has disabled before calling this function.
123  *
124  * Implements : EIM_DRV_ConfigChannel_Activity
125  *END**************************************************************************/
126 void EIM_DRV_ConfigChannel(uint32_t instance,
127  const eim_user_channel_config_t *userChannelConfig)
128 {
129  EIM_Type * base;
130 
131  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
132  DEV_ASSERT(userChannelConfig != NULL);
133  DEV_ASSERT(userChannelConfig->channel < EIM_EICHDn_COUNT);
134 
135  base = g_eimBase[instance];
136 
137  /* Disables EIM channel to configure EIM channel */
138  EIM_HAL_EnableChannelCmd(base, userChannelConfig->channel, false);
139  /* Configures checkbit mask for EIM channel */
140  EIM_HAL_SetCheckBitMask(base, userChannelConfig->channel, userChannelConfig->checkBitMask);
141  /* Configures data mask for EIM channel */
142  EIM_HAL_SetDataMask(base, userChannelConfig->channel, userChannelConfig->dataMask);
143  /* Enables or disables EIM channel operation corresponding to channel configuration */
144  EIM_HAL_EnableChannelCmd(base, userChannelConfig->channel, userChannelConfig->enable);
145 }
146 
147 /*FUNCTION**********************************************************************
148  *
149  * Function Name : EIM_DRV_GetChannelConfig
150  * Description : This function gets checkbit mask, data mask and operation
151  * status of EIM channel.
152  *
153  * Implements : EIM_DRV_GetChannelConfig_Activity
154  *END**************************************************************************/
155 void EIM_DRV_GetChannelConfig(uint32_t instance,
156  uint8_t channel,
157  eim_user_channel_config_t *channelConfig)
158 {
159  const EIM_Type * base;
160 
161  DEV_ASSERT(instance < EIM_INSTANCE_COUNT);
162  DEV_ASSERT(channelConfig != NULL);
163  DEV_ASSERT(channel < EIM_EICHDn_COUNT);
164 
165  base = g_eimBase[instance];
166 
167  /* Gets the channel number */
168  channelConfig->channel = channel;
169  /* Gets checkbit mask of EIM channel */
170  channelConfig->checkBitMask = EIM_HAL_GetCheckBitMask(base, channel);
171  /* Gets data mask of EIM channel */
172  channelConfig->dataMask = EIM_HAL_GetDataMask(base, channel);
173  /* Gets operation status */
174  channelConfig->enable = EIM_HAL_IsChannelEnabled(base, channel);
175 }
176 
177 /*******************************************************************************
178  * EOF
179  ******************************************************************************/
#define EIM_EICHDn_COUNT
Definition: S32K144.h:3172
static uint32_t EIM_HAL_GetDataMask(const EIM_Type *const base, uint8_t channel)
Gets data mask of EIM channel.
Definition: eim_hal.h:208
static void EIM_HAL_Disable(EIM_Type *const base)
Disables the EIM module.
Definition: eim_hal.h:89
static void EIM_HAL_SetDataMask(EIM_Type *const base, uint8_t channel, uint32_t dataMask)
Sets data mask for EIM channel.
Definition: eim_hal.h:189
#define DEV_ASSERT(x)
Definition: devassert.h:78
void EIM_HAL_Init(EIM_Type *const base)
Resets for the registers of EIM descriptor.
Definition: eim_hal.c:43
static void EIM_HAL_Enable(EIM_Type *const base)
Enables EIM module.
Definition: eim_hal.h:76
void EIM_DRV_ConfigChannel(uint32_t instance, const eim_user_channel_config_t *userChannelConfig)
Initializes the EIM channel.
Definition: eim_driver.c:126
void EIM_DRV_Deinit(uint32_t instance)
De-initializes the EIM module.
Definition: eim_driver.c:101
static uint8_t EIM_HAL_GetCheckBitMask(const EIM_Type *const base, uint8_t channel)
Gets check bit mask of EIM channel.
Definition: eim_hal.h:170
static void EIM_HAL_EnableChannelCmd(EIM_Type *const base, uint8_t channel, bool enable)
Enables or disables EIM channel operation.
Definition: eim_hal.h:106
static bool EIM_HAL_IsChannelEnabled(const EIM_Type *const base, uint8_t channel)
Checks whether EIM channel is enabled.
Definition: eim_hal.h:132
EIM_Type *const g_eimBase[]
Table of base addresses for EIM instances.
Definition: eim_driver.c:48
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:66
EIM channel configuration structure.
Definition: eim_driver.h:55
#define EIM_BASE_PTRS
Definition: S32K144.h:3198
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:155
#define EIM_INSTANCE_COUNT
Definition: S32K144.h:3187
static void EIM_HAL_SetCheckBitMask(EIM_Type *const base, uint8_t channel, uint8_t checkBitMask)
Sets check bit mask for EIM channel.
Definition: eim_hal.h:150