1 /*****************************************************************************
\r
2 * © 2015 Microchip Technology Inc. and its subsidiaries.
\r
3 * You may use this software and any derivatives exclusively with
\r
4 * Microchip products.
\r
5 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".
\r
6 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
\r
7 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
\r
8 * AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP
\r
9 * PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
\r
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
\r
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
\r
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
\r
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.
\r
14 * TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
\r
15 * CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF
\r
16 * FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
\r
17 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
\r
19 ******************************************************************************
\r
21 Version Control Information (Perforce)
\r
22 ******************************************************************************
\r
24 $DateTime: 2016/09/22 08:03:49 $
\r
26 Last Change: Initial Draft
\r
27 ******************************************************************************/
\r
28 /** @file interrupt_ecia_perphl.c
\r
29 * \brief Interrupt ECIA Peripheral Source File
\r
32 * This file implements the ECIA peripheral functions
\r
33 ******************************************************************************/
\r
35 /** @defgroup Interrupt
\r
39 #include "common_lib.h"
\r
40 #include "interrupt.h"
\r
42 #define ECIA ((INTS_Type *) INTS_BASE)
\r
43 #define ECS ((EC_REG_BANK_Type *) EC_REG_BANK_BASE)
\r
45 /* ------------------------------------------------------------------------------- */
\r
46 /* Operations on GIRQ Block Enable Set, Enable Clear and Status Register */
\r
47 /* ------------------------------------------------------------------------------- */
\r
49 /** Enable specified GIRQ in ECIA block
\r
50 * @param girq_id - enum MEC_GIRQ_IDS
\r
52 void p_interrupt_ecia_block_enable_set(uint8_t girq_id)
\r
54 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
55 ECIA->BLOCK_ENABLE_SET = (1ul << ((girq_id + 8) & 0x1Fu));
\r
59 /** Enable GIRQs in ECIA Block
\r
60 * @param girq_bitmask - Bitmask of GIRQs to be enabled in ECIA Block
\r
62 void p_interrupt_ecia_block_enable_bitmask_set(uint32_t girq_bitmask)
\r
64 ECIA->BLOCK_ENABLE_SET = girq_bitmask;
\r
67 /** Check if specified GIRQ block enabled or not
\r
68 * @param girq_id - enum MEC_GIRQ_IDS
\r
69 * @return retVal - 1 if the particular GIRQ block enabled, else 0
\r
71 uint8_t p_interrupt_ecia_block_enable_get(uint8_t girq_id)
\r
76 if ( girq_id < (MEC_GIRQ_ID_MAX) )
\r
78 if ((ECIA->BLOCK_ENABLE_SET) & (1ul << ((girq_id + 8) & 0x1Fu)))
\r
86 /** Set all GIRQ block enables */
\r
87 void p_interrupt_ecia_block_enable_all_set(void)
\r
89 ECIA->BLOCK_ENABLE_SET = 0xfffffffful;
\r
92 /** Clear specified GIRQ in ECIA Block
\r
93 * @param girq_id - enum MEC_GIRQ_IDS
\r
95 void p_interrupt_ecia_block_enable_clr(uint8_t girq_id)
\r
97 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
98 ECIA->BLOCK_ENABLE_CLEAR = (1ul << ((girq_id + 8) & 0x1Fu));
\r
102 /** Clear GIRQs in ECIA Block
\r
103 * @param girq_bitmask - Bitmask of GIRQs to be cleared in ECIA Block
\r
105 void p_interrupt_ecia_block_enable_bitmask_clr(uint32_t girq_bitmask)
\r
107 ECIA->BLOCK_ENABLE_CLEAR = girq_bitmask;
\r
110 /** p_interrupt_ecia_block_enable_all_clr - Clears all GIRQ block enables */
\r
111 void p_interrupt_ecia_block_enable_all_clr(void)
\r
113 ECIA->BLOCK_ENABLE_CLEAR = 0xfffffffful;
\r
116 /** Get status of GIRQ in ECIA Block
\r
117 * @param girq_id - enum MEC_GIRQ_IDS
\r
118 * @return 0 if status bit not set; else non-zero value
\r
120 uint32_t p_interrupt_ecia_block_irq_status_get(uint8_t girq_id)
\r
124 retVal = ECIA->BLOCK_IRQ_VECTOR & (1ul << ((girq_id + 8) & 0x1Fu));
\r
129 /** Reads the Block IRQ Vector Register
\r
130 * @return 32-bit value
\r
132 uint32_t p_interrupt_ecia_block_irq_all_status_get(void)
\r
136 retVal = ECIA->BLOCK_IRQ_VECTOR;
\r
142 /* ------------------------------------------------------------------------------- */
\r
143 /* Operations on GIRQx Source, Enable, Result and Enable Registers */
\r
144 /* ------------------------------------------------------------------------------- */
\r
146 /** Clear specified interrupt source bit in GIRQx
\r
147 * @param girq_id - enum MEC_GIRQ_IDS
\r
148 * @param bitnum -[0, 31]
\r
150 void p_interrupt_ecia_girq_source_clr(int16_t girq_id, uint8_t bitnum)
\r
152 __IO uint32_t *girq_source = (uint32_t*)ECIA;
\r
154 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
155 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
156 * please refer INTS_Type in MCHP_device_internal.h
\r
157 * Based on the girq id calculate the offset in the structure INTS_Type
\r
159 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
160 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
162 girq_source += (5 * girq_id);
\r
163 *girq_source |= (1ul << (bitnum & 0x1Fu));
\r
167 /** Read the specified interrupt source bit in GIRQx
\r
168 * @param girq_id - enum MEC_GIRQ_IDS
\r
169 * @param bitnum -[0, 31]
\r
170 * @return 0 if source bit not set; else non-zero value
\r
172 uint32_t p_interrupt_ecia_girq_source_get(int16_t girq_id, uint8_t bitnum)
\r
175 __IO uint32_t *girq_source = (uint32_t*)ECIA;
\r
178 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
179 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
180 * please refer INTS_Type in MCHP_device_internal.h
\r
181 * Based on the girq id calculate the offset in the structure INTS_Type
\r
183 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
184 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
186 girq_source += (5 * girq_id);
\r
187 retVal = (*girq_source & (1ul << (bitnum & 0x1Fu)));
\r
192 /** Enable the specified interrupt in GIRQx
\r
193 * girq_id - enum MEC_GIRQ_IDS
\r
196 void p_interrupt_ecia_girq_enable_set(uint16_t girq_id, uint8_t bitnum)
\r
198 __IO uint32_t *girq_enable_set = (uint32_t*)(&(ECIA->GIRQ08_EN_SET));
\r
200 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
201 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
202 * please refer INTS_Type in MCHP_device_internal.h
\r
203 * Based on the girq id calculate the offset in the structure INTS_Type
\r
205 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
206 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
208 girq_enable_set += (5 * girq_id);
\r
209 *girq_enable_set |= (1ul << (bitnum & 0x1Fu));
\r
213 /** Disable the specified interrupt in GIRQx
\r
214 * girq_id - enum MEC_GIRQ_IDS
\r
217 void p_interrupt_ecia_girq_enable_clr(uint16_t girq_id, uint8_t bitnum)
\r
219 __IO uint32_t *girq_enable_clr = (uint32_t*)(&(ECIA->GIRQ08_EN_CLR));
\r
221 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
222 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
223 * please refer INTS_Type in MCHP_device_internal.h
\r
224 * Based on the girq id calculate the offset in the structure INTS_Type
\r
226 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
227 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
229 girq_enable_clr += (5 * girq_id);
\r
230 *girq_enable_clr |= (1ul << (bitnum & 0x1Fu));
\r
234 /** Read the status of the specified interrupt in GIRQx
\r
235 * girq_id - enum MEC_GIRQ_IDS
\r
237 * @return 0 if enable bit not set; else non-zero value
\r
239 uint32_t p_interrupt_ecia_girq_enable_get(uint16_t girq_id, uint8_t bitnum)
\r
242 __IO uint32_t *girq_enable_set = (uint32_t*)(&(ECIA->GIRQ08_EN_SET));
\r
245 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
246 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
247 * please refer INTS_Type in MCHP_device_internal.h
\r
248 * Based on the girq id calculate the offset in the structure INTS_Type
\r
250 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
251 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
253 girq_enable_set += (5 * girq_id);
\r
254 retVal = (*girq_enable_set & (1ul << (bitnum & 0x1Fu)));
\r
259 /** Read the result bit of the interrupt in GIRQx
\r
260 * @param girq_id - enum MEC_GIRQ_IDS
\r
261 * @param bitnum -[0, 31]
\r
262 * @return 0 if enable bit not set; else non-zero value
\r
264 uint32_t p_interrupt_ecia_girq_result_get(int16_t girq_id, uint8_t bitnum)
\r
267 __IO uint32_t *girq_result = (uint32_t*)(&(ECIA->GIRQ08_RESULT));
\r
270 if ( girq_id < (MEC_GIRQ_ID_MAX) ) {
\r
271 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
272 * please refer INTS_Type in MCHP_device_internal.h
\r
273 * Based on the girq id calculate the offset in the structure INTS_Type
\r
275 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
276 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
278 girq_result += (5 * girq_id);
\r
279 retVal = (*girq_result & (1ul << (bitnum & 0x1Fu)));
\r
285 /* ------------------------------------------------------------------------------- */
\r
286 /* Operations on all GIRQs */
\r
287 /* ------------------------------------------------------------------------------- */
\r
289 /** Clear all aggregator GIRQn status registers */
\r
290 void p_interrupt_ecia_girqs_source_reset(void)
\r
293 __IO uint32_t *girq_source = (uint32_t*)ECIA;
\r
295 for ( i = 0u; i < (MEC_GIRQ_ID_MAX); i++ ) {
\r
296 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
297 * please refer INTS_Type in MCHP_device_internal.h
\r
298 * Based on the girq id calculate the offset in the structure INTS_Type
\r
300 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
301 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
304 *girq_source = 0xfffffffful;
\r
308 /** Clear all aggregator GIRQn enables */
\r
309 void p_interrupt_ecia_girqs_enable_reset(void)
\r
312 __IO uint32_t *girq_enable_clr = (uint32_t*)(&(ECIA->GIRQ08_EN_CLR));
\r
314 for ( i = 0u; i < (MEC_GIRQ_ID_MAX); i++ ) {
\r
315 /* Each GIRQ has 5 32bit fields: SRC, ENABLE_SET, ENABLE_CLR, RESULT & RESERVED
\r
316 * please refer INTS_Type in MCHP_device_internal.h
\r
317 * Based on the girq id calculate the offset in the structure INTS_Type
\r
319 * BASED ON THE STRUCTURE DEFINITION OF INTS_Type ALL FIELDS ARE ALIGNED ON
\r
320 * 32 BIT BOUNDARY, FOLLOWING WILL NOT WORK IF THIS SCHEME CHANGES
\r
322 girq_enable_clr += 5;
\r
323 *girq_enable_clr = 0xfffffffful;
\r
327 /* ------------------------------------------------------------------------------- */
\r
328 /* Function to set interrupt control */
\r
329 /* ------------------------------------------------------------------------------- */
\r
331 /** Set interrupt control
\r
332 * @param nvic_en_flag : 0 = Alternate NVIC disabled, 1 = Alternate NVIC enabled
\r
334 void p_interrupt_control_set(uint8_t nvic_en_flag)
\r
336 ECS->INTERRUPT_CONTROL = nvic_en_flag;
\r
339 /** Read interrupt control
\r
340 * @return uint8_t - 0 = Alternate NVIC disabled, 1 = Alternate NVIC enabled
\r
342 uint8_t p_interrupt_control_get(void)
\r
344 return (ECS->INTERRUPT_CONTROL & 0x1);
\r
347 /* end interrupt_ecia_perphl.c */
\r