1 /******************************************************************************
2 * Filename: aon_event.c
3 * Revised: 2020-02-14 11:30:20 +0100 (Fri, 14 Feb 2020)
4 * Revision: 56760
5 *
6 * Description: Driver for the AON Event fabric.
7 *
8 * Copyright (c) 2015 - 2020, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38
39 #include "aon_event.h"
40
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #if !defined(DOXYGEN)
48 #undef AONEventMcuWakeUpSet
49 #define AONEventMcuWakeUpSet NOROM_AONEventMcuWakeUpSet
50 #undef AONEventMcuWakeUpGet
51 #define AONEventMcuWakeUpGet NOROM_AONEventMcuWakeUpGet
52 #undef AONEventMcuSet
53 #define AONEventMcuSet NOROM_AONEventMcuSet
54 #undef AONEventMcuGet
55 #define AONEventMcuGet NOROM_AONEventMcuGet
56 #endif
57
58 //*****************************************************************************
59 //
60 // Select event source for the specified MCU wakeup programmable event
61 //
62 //*****************************************************************************
63 void
AONEventMcuWakeUpSet(uint32_t ui32MCUWUEvent,uint32_t ui32EventSrc)64 AONEventMcuWakeUpSet(uint32_t ui32MCUWUEvent, uint32_t ui32EventSrc)
65 {
66 uint32_t ui32Shift ;
67 uint32_t ui32Mask ;
68 uint32_t ui32RegAdr ;
69
70 // Check the arguments.
71 ASSERT(( ui32MCUWUEvent >= AON_EVENT_MCU_WU0 ) && ( ui32MCUWUEvent <= AON_EVENT_MCU_WU7 ))
72 ASSERT( ui32EventSrc <= AON_EVENT_NONE );
73
74 ui32Shift = (( ui32MCUWUEvent & 3 ) << 3 );
75 ui32Mask = ( 0x3F << ui32Shift );
76 ui32RegAdr = ( AON_EVENT_BASE + AON_EVENT_O_MCUWUSEL );
77 if ( ui32MCUWUEvent > 3 ) {
78 ui32RegAdr += 4;
79 }
80 HWREG( ui32RegAdr ) = ( HWREG( ui32RegAdr ) & ( ~ui32Mask )) | ( ui32EventSrc << ui32Shift );
81 }
82
83 //*****************************************************************************
84 //
85 // Get event source for the specified MCU wakeup programmable event
86 //
87 //*****************************************************************************
88 uint32_t
AONEventMcuWakeUpGet(uint32_t ui32MCUWUEvent)89 AONEventMcuWakeUpGet(uint32_t ui32MCUWUEvent)
90 {
91 uint32_t ui32Shift ;
92 uint32_t ui32RegAdr ;
93
94 // Check the arguments.
95 ASSERT(( ui32MCUWUEvent >= AON_EVENT_MCU_WU0 ) && ( ui32MCUWUEvent <= AON_EVENT_MCU_WU7 ))
96
97 ui32Shift = (( ui32MCUWUEvent & 3 ) << 3 );
98 ui32RegAdr = ( AON_EVENT_BASE + AON_EVENT_O_MCUWUSEL );
99 if ( ui32MCUWUEvent > 3 ) {
100 ui32RegAdr += 4;
101 }
102 return (( HWREG( ui32RegAdr ) >> ui32Shift ) & 0x3F );
103 }
104
105 //*****************************************************************************
106 //
107 // Select event source for the specified programmable event forwarded to the
108 // MCU event fabric
109 //
110 //*****************************************************************************
111 void
AONEventMcuSet(uint32_t ui32MCUEvent,uint32_t ui32EventSrc)112 AONEventMcuSet(uint32_t ui32MCUEvent, uint32_t ui32EventSrc)
113 {
114 uint32_t ui32Ctrl;
115
116 // Check the arguments.
117 ASSERT((ui32MCUEvent == AON_EVENT_MCU_EVENT0) ||
118 (ui32MCUEvent == AON_EVENT_MCU_EVENT1) ||
119 (ui32MCUEvent == AON_EVENT_MCU_EVENT2));
120 ASSERT(ui32EventSrc <= AON_EVENT_NONE);
121
122 ui32Ctrl = HWREG(AON_EVENT_BASE + AON_EVENT_O_EVTOMCUSEL);
123
124 if(ui32MCUEvent == AON_EVENT_MCU_EVENT0)
125 {
126 ui32Ctrl &= ~(AON_EVENT_EVTOMCUSEL_AON_PROG0_EV_M);
127 ui32Ctrl |= (ui32EventSrc & 0x3f) << AON_EVENT_EVTOMCUSEL_AON_PROG0_EV_S;
128 }
129 else if(ui32MCUEvent == AON_EVENT_MCU_EVENT1)
130 {
131 ui32Ctrl &= ~(AON_EVENT_EVTOMCUSEL_AON_PROG1_EV_M);
132 ui32Ctrl |= (ui32EventSrc & 0x3f) << AON_EVENT_EVTOMCUSEL_AON_PROG1_EV_S;
133 }
134 else if(ui32MCUEvent == AON_EVENT_MCU_EVENT2)
135 {
136 ui32Ctrl &= ~(AON_EVENT_EVTOMCUSEL_AON_PROG2_EV_M);
137 ui32Ctrl |= (ui32EventSrc & 0x3f) << AON_EVENT_EVTOMCUSEL_AON_PROG2_EV_S;
138 }
139
140 HWREG(AON_EVENT_BASE + AON_EVENT_O_EVTOMCUSEL) = ui32Ctrl;
141 }
142
143 //*****************************************************************************
144 //
145 // Get source for the specified programmable event forwarded to the MCU event
146 // fabric.
147 //
148 //*****************************************************************************
149 uint32_t
AONEventMcuGet(uint32_t ui32MCUEvent)150 AONEventMcuGet(uint32_t ui32MCUEvent)
151 {
152 uint32_t ui32EventSrc;
153
154 // Check the arguments.
155 ASSERT((ui32MCUEvent == AON_EVENT_MCU_EVENT0) ||
156 (ui32MCUEvent == AON_EVENT_MCU_EVENT1) ||
157 (ui32MCUEvent == AON_EVENT_MCU_EVENT2));
158
159 ui32EventSrc = HWREG(AON_EVENT_BASE + AON_EVENT_O_EVTOMCUSEL);
160
161 if(ui32MCUEvent == AON_EVENT_MCU_EVENT0)
162 {
163 return((ui32EventSrc & AON_EVENT_EVTOMCUSEL_AON_PROG0_EV_M) >>
164 AON_EVENT_EVTOMCUSEL_AON_PROG0_EV_S);
165 }
166 else if(ui32MCUEvent == AON_EVENT_MCU_EVENT1)
167 {
168 return((ui32EventSrc & AON_EVENT_EVTOMCUSEL_AON_PROG1_EV_M) >>
169 AON_EVENT_EVTOMCUSEL_AON_PROG1_EV_S);
170 }
171 else if(ui32MCUEvent == AON_EVENT_MCU_EVENT2)
172 {
173 return((ui32EventSrc & AON_EVENT_EVTOMCUSEL_AON_PROG2_EV_M) >>
174 AON_EVENT_EVTOMCUSEL_AON_PROG2_EV_S);
175 }
176
177 // Should never get to this statement, but suppress warning.
178 ASSERT(0);
179 return(0);
180 }
181