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