-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathnanoPAL_AsyncProcCalls_decl.h
142 lines (104 loc) · 2.68 KB
/
nanoPAL_AsyncProcCalls_decl.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#ifndef NANOPAL_ASYNCPROCCALLS_DECL_H
#define NANOPAL_ASYNCPROCCALLS_DECL_H
#include <nanoWeak.h>
//--//
typedef void (*HAL_CALLBACK_FPN)(void *arg);
struct HAL_CALLBACK
{
public:
HAL_CALLBACK_FPN EntryPoint;
void *Argument;
public:
void Initialize(HAL_CALLBACK_FPN entryPoint, void *arg)
{
this->EntryPoint = entryPoint;
this->Argument = arg;
}
void SetArgument(void *arg)
{
this->Argument = arg;
}
HAL_CALLBACK_FPN GetEntryPoint() const
{
return this->EntryPoint;
}
void *GetArgument() const
{
return this->Argument;
}
void Execute() const
{
HAL_CALLBACK_FPN entryPoint = this->EntryPoint;
void *arg = this->Argument;
if (entryPoint)
{
EntryPoint(arg);
}
}
};
struct HAL_CONTINUATION : public HAL_DblLinkedNode<HAL_CONTINUATION>
{
private:
HAL_CALLBACK Callback;
public:
void InitializeCallback(HAL_CALLBACK_FPN EntryPoint, void *Argument = NULL);
void SetArgument(void *Argument)
{
Callback.SetArgument(Argument);
}
HAL_CALLBACK_FPN GetEntryPoint() const
{
return Callback.GetEntryPoint();
}
void *GetArgument() const
{
return Callback.GetArgument();
}
void Execute() const
{
Callback.Execute();
}
bool IsLinked();
void Enqueue();
void Abort();
//--//
static void Uninitialize();
static void InitializeList();
static bool Dequeue_And_Execute();
};
//--//
struct HAL_COMPLETION : public HAL_CONTINUATION
{
uint64_t EventTimeTicks;
bool ExecuteInISR;
#if defined(_DEBUG)
uint64_t Start_RTC_Ticks;
#endif
void InitializeForISR(HAL_CALLBACK_FPN EntryPoint, void *Argument = NULL)
{
ExecuteInISR = true;
InitializeCallback(EntryPoint, Argument);
}
void InitializeForUserMode(HAL_CALLBACK_FPN EntryPoint, void *Argument = NULL)
{
ExecuteInISR = false;
InitializeCallback(EntryPoint, Argument);
}
void EnqueueTicks(uint64_t eventTimeTicks);
void EnqueueDelta64(uint64_t miliSecondsFromNow);
void EnqueueDelta(uint32_t miliSecondsFromNow);
void Abort();
void Execute();
//--//
static void Uninitialize();
static void InitializeList();
static void DequeueAndExec();
static void WaitForInterrupts(uint64_t expireTimeInSysTicks, uint32_t sleepLevel, uint64_t wakeEvents);
};
//--//
#endif // NANOPAL_ASYNCPROCCALLS_DECL_H