-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathnanoPAL_Events.h
92 lines (66 loc) · 2.78 KB
/
nanoPAL_Events.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
#ifndef NANOPAL_EVENTS_H
#define NANOPAL_EVENTS_H
#include <nanoHAL.h>
#include <nanoWeak.h>
typedef void (*set_Event_Callback)(void *);
#define EVENTS_TIMEOUT_INFINITE 0xFFFFFFFF
#ifdef __cplusplus
extern "C"
{
#endif
bool Events_Initialize();
bool Events_Uninitialize();
void Events_Set(uint32_t events);
// destructive read system event flags
uint32_t Events_Get(uint32_t eventsOfInterest);
// non-destructive read system event flags
uint32_t Events_MaskedRead(uint32_t eventsOfInterest);
// returns 0 for timeout, non-zero are events that have happened and were asked to be waiting on (non-destructive
// read) timeout limit is about 3034 milliseconds currently values greater than this are capped to this
// sleep relative time into the future, or until a SystemEvent occurs, which occurs first
// timeout is a non-negative number of 1mSec ticks, or -1 (any negative value) to sleep forever until a SystemEvent
// occurs
// Events_WaitForEvents(0, n), sleeps for n milliseconds independent of events
// Events_WaitForEvents(0, EVENTS_TIMEOUT_INFINITE) sleeps forever. Don't do that.
// Events_WaitForEvents(flags, EVENTS_TIMEOUT_INFINITE) waits forever for that event.
uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds);
void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow);
void Events_SetCallback(set_Event_Callback pfn, void *arg);
void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2);
void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2);
#ifdef __cplusplus
}
#endif
__inline uint32_t Events_WaitForEvents(uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds)
{
return Events_WaitForEvents(SLEEP_LEVEL__SLEEP, wakeupSystemEvents, timeoutMilliseconds);
}
//--//
typedef void (*PALEVENTLISTENER)(uint32_t e, uint32_t param);
struct PalEventListener : public HAL_DblLinkedNode<PalEventListener>
{
PALEVENTLISTENER m_palEventListener;
uint32_t m_eventMask;
};
HRESULT PalEvent_Initialize();
HRESULT PalEvent_Uninitialize();
HRESULT PalEvent_Post(uint32_t e, uint32_t param);
HRESULT PalEvent_Enlist(PalEventListener *listener);
//--//
struct PalEventDriver
{
public:
HAL_DblLinkedList<PalEventListener> listenerList;
static HRESULT Initialize();
static HRESULT Uninitialize();
static HRESULT PostEvent(uint32_t e, uint32_t param);
static HRESULT EnlistListener(PalEventListener *listener);
private:
static bool s_initialized;
};
extern PalEventDriver g_palEventDriver;
#endif // NANOPAL_EVENTS_H