1 /******************************************************************************
2 *  Filename:       event.h
3 *
4 *  Description:    Defines and prototypes for the Event Handler.
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 //*****************************************************************************
38 //
39 //! \addtogroup peripheral_group
40 //! @{
41 //! \addtogroup event_api
42 //! @{
43 //
44 //*****************************************************************************
45 
46 #ifndef __EVENT_H__
47 #define __EVENT_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include "../inc/hw_types.h"
63 #include "../inc/hw_memmap.h"
64 #include "../inc/hw_event.h"
65 #include "debug.h"
66 
67 
68 //*****************************************************************************
69 //
70 // API Functions and prototypes
71 //
72 //*****************************************************************************
73 
74 //*****************************************************************************
75 //
76 //! \brief Connects an event to an event subscriber via Event Fabric.
77 //!
78 //! This function connects event sources to event subscribers.
79 //!
80 //! It is not possible to read event status in this module (except software events).
81 //! Event status must be read in the module that contains the event source. How a
82 //! specific event subscriber reacts to an event is configured and documented in
83 //! the respective modules.
84 //!
85 //! For a full list of configurable and constant mapped event sources to event
86 //! subscribers see the register descriptions for
87 //! <a href="../register_descriptions/CPU_MMAP/EVENT.html" target="_blank">Event Fabric</a>.
88 //!
89 //! Defines for event subscriber argument (\c ui32EventSubscriber) have the format:
90 //! - \ti_code{EVENT_O_[subscriber_name]}
91 //!
92 //! Defines for event source argument (\c ui32EventSource) must have the
93 //! following format where valid \c event_enum values are found in the
94 //! register description :
95 //! - \ti_code{EVENT_[subscriber_name]_EV_[event_enum]}
96 //!
97 //! Examples of valid defines for \c ui32EventSource:
98 //! - EVENT_CPUIRQSEL30_EV_AUX_TDC_DONE
99 //! - EVENT_RFCSEL9_EV_AUX_COMPA
100 //! - EVENT_GPT0ACAPTSEL_EV_AON_RTC_UPD
101 //!
102 //! \note Each event subscriber can only receive a sub-set of the event sources!
103 //!
104 //! \note Switching the event source is not glitch free, so it is imperative
105 //! that the subscriber is disabled for interrupts when switching the event
106 //! source. The behavior is undefined if not disabled.
107 //!
108 //! \param ui32EventSubscriber is the \b configurable event subscriber to receive the event.
109 //! Click the event subscriber to see the list of valid event sources in the
110 //! register description.
111 //! - EVENT_O_CPUIRQSEL30  : System CPU interrupt 30
112 //! - EVENT_O_RFCSEL9      : RF Core event 9
113 //! - EVENT_O_GPT0ACAPTSEL : GPT 0A capture event
114 //! - EVENT_O_GPT0BCAPTSEL : GPT 0B capture event
115 //! - EVENT_O_GPT1ACAPTSEL : GPT 1A capture event
116 //! - EVENT_O_GPT1BCAPTSEL : GPT 1B capture event
117 //! - EVENT_O_GPT2ACAPTSEL : GPT 2A capture event
118 //! - EVENT_O_GPT2BCAPTSEL : GPT 2B capture event
119 //! - EVENT_O_GPT3ACAPTSEL : GPT 3A capture event
120 //! - EVENT_O_GPT3BCAPTSEL : GPT 3B capture event
121 //! - EVENT_O_UDMACH9SSEL  : uDMA channel 9 single request
122 //! - EVENT_O_UDMACH9BSEL  : uDMA channel 9 burst request
123 //! - EVENT_O_UDMACH10SSEL : uDMA channel 10 single request
124 //! - EVENT_O_UDMACH10BSEL : uDMA channel 10 burst request
125 //! - EVENT_O_UDMACH11SSEL : uDMA channel 11 single request
126 //! - EVENT_O_UDMACH11BSEL : uDMA channel 11 burst request
127 //! - EVENT_O_UDMACH12SSEL : uDMA channel 12 single request
128 //! - EVENT_O_UDMACH12BSEL : uDMA channel 12 burst request
129 //! - EVENT_O_UDMACH14BSEL : uDMA channel 14 single request
130 //! - EVENT_O_AUXSEL0      : AUX
131 //! - EVENT_O_I2SSTMPSEL0  : I2S
132 //! - EVENT_O_FRZSEL0      : Freeze modules (some modules can freeze on CPU Halt)
133 //! \param ui32EventSource is the specific event that must be acted upon.
134 //! - Format: \ti_code{EVENT_[subscriber_name]_EV_[event_enum]} (see explanation above)
135 //!
136 //! \return None
137 //
138 //*****************************************************************************
139 __STATIC_INLINE void
EventRegister(uint32_t ui32EventSubscriber,uint32_t ui32EventSource)140 EventRegister(uint32_t ui32EventSubscriber, uint32_t ui32EventSource)
141 {
142     // Check the arguments.
143     ASSERT(( ui32EventSubscriber == EVENT_O_CPUIRQSEL30  ) ||
144            ( ui32EventSubscriber == EVENT_O_RFCSEL9      ) ||
145            ( ui32EventSubscriber == EVENT_O_GPT0ACAPTSEL ) ||
146            ( ui32EventSubscriber == EVENT_O_GPT0BCAPTSEL ) ||
147            ( ui32EventSubscriber == EVENT_O_GPT1ACAPTSEL ) ||
148            ( ui32EventSubscriber == EVENT_O_GPT1BCAPTSEL ) ||
149            ( ui32EventSubscriber == EVENT_O_GPT2ACAPTSEL ) ||
150            ( ui32EventSubscriber == EVENT_O_GPT2BCAPTSEL ) ||
151            ( ui32EventSubscriber == EVENT_O_GPT3ACAPTSEL ) ||
152            ( ui32EventSubscriber == EVENT_O_GPT3BCAPTSEL ) ||
153            ( ui32EventSubscriber == EVENT_O_UDMACH9SSEL  ) ||
154            ( ui32EventSubscriber == EVENT_O_UDMACH9BSEL  ) ||
155            ( ui32EventSubscriber == EVENT_O_UDMACH10SSEL ) ||
156            ( ui32EventSubscriber == EVENT_O_UDMACH10BSEL ) ||
157            ( ui32EventSubscriber == EVENT_O_UDMACH11SSEL ) ||
158            ( ui32EventSubscriber == EVENT_O_UDMACH11BSEL ) ||
159            ( ui32EventSubscriber == EVENT_O_UDMACH12SSEL ) ||
160            ( ui32EventSubscriber == EVENT_O_UDMACH12BSEL ) ||
161            ( ui32EventSubscriber == EVENT_O_UDMACH14BSEL ) ||
162            ( ui32EventSubscriber == EVENT_O_AUXSEL0      ) ||
163            ( ui32EventSubscriber == EVENT_O_I2SSTMPSEL0  ) ||
164            ( ui32EventSubscriber == EVENT_O_FRZSEL0      ) );
165 
166     // Map the event source to the event subscriber
167     HWREG(EVENT_BASE + ui32EventSubscriber) = ui32EventSource;
168 }
169 
170 //*****************************************************************************
171 //
172 //! \brief Sets software event.
173 //!
174 //! Setting a software event triggers the event if the value was 0 before.
175 //!
176 //! \note The software event must be cleared manually after the event has
177 //! triggered the event subscriber.
178 //!
179 //! \param ui32SwEvent is the software event number.
180 //! - 0 : SW Event 0
181 //! - 1 : SW Event 1
182 //! - 2 : SW Event 2
183 //! - 3 : SW Event 3
184 //!
185 //! \return None
186 //!
187 //! \sa \ref EventSwEventClear()
188 //
189 //*****************************************************************************
190 __STATIC_INLINE void
EventSwEventSet(uint32_t ui32SwEvent)191 EventSwEventSet(uint32_t ui32SwEvent)
192 {
193     // Check the arguments.
194     ASSERT( ui32SwEvent <= 3 );
195 
196     // Each software event is byte accessible
197     HWREGB(EVENT_BASE + EVENT_O_SWEV + ui32SwEvent) = 1;
198 }
199 
200 //*****************************************************************************
201 //
202 //! \brief Clears software event.
203 //!
204 //! \param ui32SwEvent is the software event number.
205 //! - 0 : SW Event 0
206 //! - 1 : SW Event 1
207 //! - 2 : SW Event 2
208 //! - 3 : SW Event 3
209 //!
210 //! \return None
211 //
212 //*****************************************************************************
213 __STATIC_INLINE void
EventSwEventClear(uint32_t ui32SwEvent)214 EventSwEventClear(uint32_t ui32SwEvent)
215 {
216     // Check the arguments.
217     ASSERT( ui32SwEvent <= 3 );
218 
219     // Each software event is byte accessible
220     HWREGB(EVENT_BASE + EVENT_O_SWEV + ui32SwEvent) = 0;
221 }
222 
223 //*****************************************************************************
224 //
225 //! \brief Gets software event status.
226 //!
227 //! \param ui32SwEvent is the software event number.
228 //! - 0 : SW Event 0
229 //! - 1 : SW Event 1
230 //! - 2 : SW Event 2
231 //! - 3 : SW Event 3
232 //!
233 //! \return Returns current value of requested software event.
234 //! - 0 : Software event is de-asserted.
235 //! - 1 : Software event is asserted.
236 //
237 //*****************************************************************************
238 __STATIC_INLINE uint32_t
EventSwEventGet(uint32_t ui32SwEvent)239 EventSwEventGet(uint32_t ui32SwEvent)
240 {
241     // Check the arguments.
242     ASSERT( ui32SwEvent <= 3 );
243 
244     // Each software event is byte accessible
245     return( HWREGB(EVENT_BASE + EVENT_O_SWEV + ui32SwEvent));
246 }
247 
248 //*****************************************************************************
249 //
250 // Mark the end of the C bindings section for C++ compilers.
251 //
252 //*****************************************************************************
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #endif // __EVENT_H__
258 
259 //*****************************************************************************
260 //
261 //! Close the Doxygen group.
262 //! @}
263 //! @}
264 //
265 //*****************************************************************************
266