Statistics
| Branch: | Tag: | Revision:

root / LUFA / Platform / UC3 / InterruptManagement.h @ 978b99e5

History | View | Annotate | Download (6.36 KB)

1
/*
2
             LUFA Library
3
     Copyright (C) Dean Camera, 2011.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
*/
8

    
9
/*
10
  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11

12
  Permission to use, copy, modify, distribute, and sell this
13
  software and its documentation for any purpose is hereby granted
14
  without fee, provided that the above copyright notice appear in
15
  all copies and that both that the copyright notice and this
16
  permission notice and warranty disclaimer appear in supporting
17
  documentation, and that the name of the author not be used in
18
  advertising or publicity pertaining to distribution of the
19
  software without specific, written prior permission.
20

21
  The author disclaim all warranties with regard to this
22
  software, including all implied warranties of merchantability
23
  and fitness.  In no event shall the author be liable for any
24
  special, indirect or consequential damages or any damages
25
  whatsoever resulting from loss of use, data or profits, whether
26
  in an action of contract, negligence or other tortious action,
27
  arising out of or in connection with the use or performance of
28
  this software.
29
*/
30

    
31
/** \file
32
 *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
33
 *
34
 *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
35
 *  handlers within the device.
36
 */
37

    
38
/** \ingroup Group_PlatformDrivers
39
 *  \defgroup Group_PlatformDrivers_UC3Interrupts UC3 Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h
40
 *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
41
 *
42
 *  \section Sec_Dependencies Module Source Dependencies
43
 *  The following files must be built with any user project that uses this module:
44
 *    - LUFA/Platform/UC3/InterruptManagement.c
45
 *    - LUFA/Platform/UC3/Exception.S
46
 *
47
 *  \section Sec_ModDescription Module Description
48
 *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
49
 *  handlers within the device.
50
 *
51
 *  Usage Example:
52
 *  \code
53
 *                #include <LUFA/Platform/UC3/InterruptManagement.h>
54
 *
55
 *                ISR(USB_Group_IRQ_Handler)
56
 *                {
57
 *                        // USB group handler code here
58
 *                }
59
 *
60
 *                void main(void)
61
 *                {
62
 *                        INTC_Init();
63
 *                        INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);
64
 *                }
65
 *  \endcode
66
 *
67
 *  @{
68
 */
69

    
70
#ifndef _UC3_INTERRUPT_MANAGEMENT_H_
71
#define _UC3_INTERRUPT_MANAGEMENT_H_
72

    
73
        /* Includes: */
74
                #include <LUFA/Common/Common.h>
75

    
76
        /* Enable C linkage for C++ Compilers: */
77
                #if defined(__cplusplus)
78
                        extern "C" {
79
                #endif
80

    
81
        /* Private Interface - For use in library only: */
82
        #if !defined(__DOXYGEN__)
83
                /* Type Defines: */
84
                        typedef void (*InterruptHandlerPtr_t)(void);
85

    
86
                /* External Variables: */
87
                        extern const void            EVBA_Table;
88
                        extern const uint32_t        Autovector_Table[];
89
                        extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
90
        #endif
91

    
92
        /* Public Interface - May be used in end-application: */
93
                /* Macros: */
94
                        /** Converts a given interrupt index into its assocated interrupt group.
95
                         *
96
                         *  \param[in] IRQIndex  Index of the interrupt request to convert.
97
                         *
98
                         *  \return Interrupt group number associated with the interrupt index.
99
                         */
100
                        #define INTC_IRQ_GROUP(IRQIndex)  (IRQIndex / 32)
101

    
102
                        /** Converts a given interrupt index into its assocated interrupt line.
103
                         *
104
                         *  \param[in] IRQIndex  Index of the interrupt request to convert.
105
                         *
106
                         *  \return Interrupt line number associated with the interrupt index.
107
                         */
108
                        #define INTC_IRQ_LINE(IRQIndex)   (IRQIndex % 32)
109

    
110
                /* Function Prototypes: */
111
                        /** Initializes the interrupt controller, nulling out all interrupt handlers ready for new registration. This
112
                         *  function should be called once on startup to ensure the interrupt controller is ready for use.
113
                         */
114
                        void INTC_Init(void);
115

    
116
                /* Inline Functions: */
117
                        /** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by
118
                         *  peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to
119
                         *  determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts().
120
                         *
121
                         *  If multiple interrupts with the same group are registered, the last registered handler will become the
122
                         *  handler called for interrupts raised within that group.
123
                         *
124
                         *  To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.
125
                         *
126
                         *  \param[in] GroupNumber       Group number of the interrupt group to register a handler for.
127
                         *  \param[in] InterruptLevel    Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask.
128
                         *  \param[in] Handler           Address of the ISR handler for the interrupt group.
129
                         */
130
                        static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
131
                                                                     const uint8_t InterruptLevel,
132
                                                                     const InterruptHandlerPtr_t Handler) ATTR_ALWAYS_INLINE;
133
                        static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,
134
                                                                     const uint8_t InterruptLevel,
135
                                                                     const InterruptHandlerPtr_t Handler)
136
                        {
137
                                InterruptHandlers[GroupNumber] = Handler;
138
                                AVR32_INTC.ipr[GroupNumber]    = Autovector_Table[InterruptLevel];
139
                        }
140
                        
141
                        /** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked
142
                         *  against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To
143
                         *  obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro.
144
                         *
145
                         *  \param[in] GroupNumber Group number of the interrupt group to check.
146
                         *
147
                         *  \return Mask of pending interrupt lines for the given interrupt group.
148
                         */
149
                        static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber) ATTR_ALWAYS_INLINE;
150
                        static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber)
151
                        {
152
                                return AVR32_INTC.irr[GroupNumber];
153
                        }
154
        
155
        /* Disable C linkage for C++ Compilers: */
156
                #if defined(__cplusplus)
157
                        }
158
                #endif
159

    
160
#endif
161

    
162
/** @} */