erm_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2018 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  */
37 #include <stddef.h>
38 #include "erm_hw_access.h"
39 
40 /*******************************************************************************
41  * Variables
42  ******************************************************************************/
43 /* Table of base addresses for ERM instances */
44 static ERM_Type * const s_ermBase[] = ERM_BASE_PTRS;
45 
46 /*******************************************************************************
47  * Code
48  ******************************************************************************/
49 /*FUNCTION**********************************************************************
50  *
51  * Function Name : ERM_DRV_Init
52  * Description : This function initializes ERM driver based on user configuration input,
53  * channelCnt takes values between 1 and the maximum channel count supported by the hardware.
54  *
55  * Implements : ERM_DRV_Init_Activity
56  *END**************************************************************************/
57 void ERM_DRV_Init(uint32_t instance,
58  uint8_t channelCnt,
59  const erm_user_config_t * userConfigArr)
60 {
61  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
62  DEV_ASSERT(userConfigArr != NULL);
63  DEV_ASSERT(channelCnt > 0U);
64  DEV_ASSERT(channelCnt <= ERM_EARn_COUNT);
65  ERM_Type * base = s_ermBase[instance];
66  uint8_t i;
67 
68  /* Initializes the module */
69  ERM_Init(base);
70 
71  /* Sets interrupt notification from user configuration input */
72  for (i = 0U; i < channelCnt; i++)
73  {
74  ERM_DRV_SetInterruptConfig(instance, userConfigArr[i].channel, *userConfigArr[i].interruptCfg);
75  }
76 }
77 
78 /*FUNCTION**********************************************************************
79  *
80  * Function Name : ERM_DRV_Deinit
81  * Description : This function sets the default configuration.
82  *
83  * Implements : ERM_DRV_Deinit_Activity
84  *END**************************************************************************/
85 void ERM_DRV_Deinit(uint32_t instance)
86 {
87  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
88  ERM_Type * base = s_ermBase[instance];
89 
90  /* Set the default configuration */
91  ERM_Init(base);
92 }
93 
94 /*FUNCTION**********************************************************************
95  *
96  * Function Name : ERM_DRV_SetInterruptConfig
97  * Description : This function sets interrupt notification based on interrupt
98  * notification configuration input.
99  *
100  * Implements : ERM_DRV_SetInterruptConfig_Activity
101  *END**************************************************************************/
102 void ERM_DRV_SetInterruptConfig(uint32_t instance,
103  uint8_t channel,
104  erm_interrupt_config_t interruptCfg)
105 {
106  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
107  DEV_ASSERT(channel < ERM_EARn_COUNT);
108  ERM_Type * base = s_ermBase[instance];
109 
110  /* Set interrupt notification base on interrupt notification configuration input */
111  ERM_EnableEventInterrupt(base, channel, ERM_EVENT_SINGLE_BIT, interruptCfg.enableSingleCorrection);
112  ERM_EnableEventInterrupt(base, channel, ERM_EVENT_NON_CORRECTABLE, interruptCfg.enableNonCorrectable);
113 }
114 
115 /*FUNCTION**********************************************************************
116  *
117  * Function Name : ERM_DRV_GetInterruptConfig
118  * Description : This function gets the current interrupt configuration of the available events
119  * (which interrupts are enabled/disabled).
120  *
121  * Implements : ERM_DRV_GetInterruptConfig_Activity
122  *END**************************************************************************/
123 void ERM_DRV_GetInterruptConfig(uint32_t instance,
124  uint8_t channel,
125  erm_interrupt_config_t * const interruptPtr)
126 {
127  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
128  DEV_ASSERT(channel < ERM_EARn_COUNT);
129  DEV_ASSERT(interruptPtr != NULL);
130  const ERM_Type * base = s_ermBase[instance];
131 
132  /* Get interrupt notification into interrupt notification configuration input */
133  interruptPtr->enableSingleCorrection = ERM_IsEventInterruptEnabled(base, channel, ERM_EVENT_SINGLE_BIT);
134  interruptPtr->enableNonCorrectable = ERM_IsEventInterruptEnabled(base, channel, ERM_EVENT_NON_CORRECTABLE);
135 }
136 
137 /*FUNCTION**********************************************************************
138  *
139  * Function Name : ERM_DRV_ClearEvent
140  * Description : This function clears the record of an event. If the corresponding interrupt is enabled,
141  * the interrupt notification will be cleared.
142  *
143  * Implements : ERM_DRV_ClearEvent_Activity
144  *END**************************************************************************/
145 void ERM_DRV_ClearEvent(uint32_t instance,
146  uint8_t channel,
147  erm_ecc_event_t eccEvent)
148 {
149  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
150  DEV_ASSERT(channel < ERM_EARn_COUNT);
151  ERM_Type * base = s_ermBase[instance];
152 
153  /* Single-bit correction */
154  if (eccEvent == ERM_EVENT_SINGLE_BIT)
155  {
156  ERM_ClearEventSingle(base, channel);
157  }
158  /* Non-correctable */
159  else if (eccEvent == ERM_EVENT_NON_CORRECTABLE)
160  {
161  ERM_ClearEventDouble(base, channel);
162  }
163  else
164  {
165  /* Do nothing */
166  }
167 }
168 
169 /*FUNCTION**********************************************************************
170  *
171  * Function Name : ERM_DRV_GetErrorDetail
172  * Description : This function gets the address of the last ECC event in Memory n
173  * and the types of the event.
174  *
175  * Implements : ERM_DRV_GetErrorDetail_Activity
176  *END**************************************************************************/
178  uint8_t channel,
179  uint32_t * addressPtr)
180 {
181  DEV_ASSERT(instance < ERM_INSTANCE_COUNT);
182  DEV_ASSERT(channel < ERM_EARn_COUNT);
183  DEV_ASSERT(addressPtr != NULL);
184  const ERM_Type * base = s_ermBase[instance];
185  erm_ecc_event_t eccEvent;
186 
187  /* Single-bit correction ECC events */
188  if (ERM_IsEventDetected(base, channel, ERM_EVENT_SINGLE_BIT) != false)
189  {
190  eccEvent = ERM_EVENT_SINGLE_BIT;
191  }
192  /* Non-correctable ECC events */
193  else if (ERM_IsEventDetected(base, channel, ERM_EVENT_NON_CORRECTABLE) != false)
194  {
195  eccEvent = ERM_EVENT_NON_CORRECTABLE;
196  }
197  /* None ECC events */
198  else
199  {
200  eccEvent = ERM_EVENT_NONE;
201  }
202 
203  /* Gets address */
204  *addressPtr = ERM_GetLastErrorAddress(base, channel);
205 
206  return eccEvent;
207 }
208 
209 /*******************************************************************************
210  * EOF
211  ******************************************************************************/
erm_ecc_event_t ERM_DRV_GetErrorDetail(uint32_t instance, uint8_t channel, uint32_t *addressPtr)
Gets the address of the last ECC event in Memory n and ECC event.
Definition: erm_driver.c:177
ERM interrupt notification configuration structure Implements : erm_interrupt_config_t_Class.
Definition: erm_driver.h:56
void ERM_DRV_GetInterruptConfig(uint32_t instance, uint8_t channel, erm_interrupt_config_t *const interruptPtr)
Gets interrupt notification.
Definition: erm_driver.c:123
ERM user configuration structure Implements : erm_user_config_t_Class.
Definition: erm_driver.h:66
#define ERM_EARn_COUNT
Definition: S32K118.h:3216
#define DEV_ASSERT(x)
Definition: devassert.h:77
#define ERM_BASE_PTRS
Definition: S32K118.h:3239
static ERM_Type *const s_ermBase[]
Definition: erm_driver.c:44
#define ERM_INSTANCE_COUNT
Definition: S32K118.h:3228
void ERM_DRV_ClearEvent(uint32_t instance, uint8_t channel, erm_ecc_event_t eccEvent)
Clears error event and the corresponding interrupt notification.
Definition: erm_driver.c:145
void ERM_DRV_Init(uint32_t instance, uint8_t channelCnt, const erm_user_config_t *userConfigArr)
Initializes the ERM module.
Definition: erm_driver.c:57
void ERM_DRV_SetInterruptConfig(uint32_t instance, uint8_t channel, erm_interrupt_config_t interruptCfg)
Sets interrupt notification.
Definition: erm_driver.c:102
void ERM_DRV_Deinit(uint32_t instance)
Sets the default configuration.
Definition: erm_driver.c:85
erm_ecc_event_t
ERM types of ECC events Implements : erm_ecc_event_t_Class.
Definition: erm_driver.h:45