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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "dolphin/arq.h"
#include "dolphin/os.h"
const char* __ARQVersion = "<< Dolphin SDK - ARQ\trelease build: Sep 5 2002 05:34:29 (0x2301) >>";
static ARQRequest* __ARQRequestQueueHi;
static ARQRequest* __ARQRequestTailHi;
static ARQRequest* __ARQRequestQueueLo;
static ARQRequest* __ARQRequestTailLo;
static ARQRequest* __ARQRequestPendingHi;
static ARQRequest* __ARQRequestPendingLo;
static ARQCallback __ARQCallbackHi;
static ARQCallback __ARQCallbackLo;
static u32 __ARQChunkSize;
static volatile BOOL __ARQ_init_flag = FALSE;
void __ARQPopTaskQueueHi(void);
void __ARQServiceQueueLo(void);
void __ARQCallbackHack(void);
void __ARQInterruptServiceRoutine(void);
void __ARQInitTempQueue(void);
void __ARQPushTempQueue(ARQRequest* task);
void __ARQPopTaskQueueHi(void) {
if (__ARQRequestQueueHi) {
if (__ARQRequestQueueHi->type == ARQ_TYPE_MRAM_TO_ARAM) {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->source, __ARQRequestQueueHi->dest,
__ARQRequestQueueHi->length);
} else {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->dest, __ARQRequestQueueHi->source,
__ARQRequestQueueHi->length);
}
__ARQCallbackHi = __ARQRequestQueueHi->callback;
__ARQRequestPendingHi = __ARQRequestQueueHi;
__ARQRequestQueueHi = __ARQRequestQueueHi->next;
}
}
void __ARQServiceQueueLo(void) {
if ((__ARQRequestPendingLo == NULL) && (__ARQRequestQueueLo)) {
__ARQRequestPendingLo = __ARQRequestQueueLo;
__ARQRequestQueueLo = __ARQRequestQueueLo->next;
}
if (__ARQRequestPendingLo) {
if (__ARQRequestPendingLo->length <= __ARQChunkSize) {
if (__ARQRequestPendingLo->type == ARQ_TYPE_MRAM_TO_ARAM)
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->source,
__ARQRequestPendingLo->dest, __ARQRequestPendingLo->length);
else
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->dest,
__ARQRequestPendingLo->source, __ARQRequestPendingLo->length);
__ARQCallbackLo = __ARQRequestPendingLo->callback;
} else {
if (__ARQRequestPendingLo->type == ARQ_TYPE_MRAM_TO_ARAM)
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->source,
__ARQRequestPendingLo->dest, __ARQChunkSize);
else
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->dest,
__ARQRequestPendingLo->source, __ARQChunkSize);
}
__ARQRequestPendingLo->length -= __ARQChunkSize;
__ARQRequestPendingLo->source += __ARQChunkSize;
__ARQRequestPendingLo->dest += __ARQChunkSize;
}
}
void __ARQCallbackHack(void) { return; }
void __ARQInterruptServiceRoutine(void) {
if (__ARQCallbackHi) {
(*__ARQCallbackHi)((u32)__ARQRequestPendingHi);
__ARQRequestPendingHi = NULL;
__ARQCallbackHi = NULL;
}
else if (__ARQCallbackLo) {
(*__ARQCallbackLo)((u32)__ARQRequestPendingLo);
__ARQRequestPendingLo = NULL;
__ARQCallbackLo = NULL;
}
__ARQPopTaskQueueHi();
if (__ARQRequestPendingHi == NULL)
__ARQServiceQueueLo();
}
void ARQInit(void) {
if (TRUE == __ARQ_init_flag) {
return;
}
OSRegisterVersion(__ARQVersion);
__ARQRequestQueueHi = __ARQRequestQueueLo = NULL;
__ARQChunkSize = ARQ_CHUNK_SIZE_DEFAULT;
ARRegisterDMACallback(&__ARQInterruptServiceRoutine);
__ARQRequestPendingHi = NULL;
__ARQRequestPendingLo = NULL;
__ARQCallbackHi = NULL;
__ARQCallbackLo = NULL;
__ARQ_init_flag = TRUE;
}
void ARQPostRequest(ARQRequest* request, u32 owner, u32 type, u32 priority, u32 source, u32 dest,
u32 length, ARQCallback callback) {
BOOL enabled;
request->next = NULL;
request->owner = owner;
request->type = type;
request->source = source;
request->dest = dest;
request->length = length;
if (callback) {
request->callback = callback;
} else {
request->callback = (ARQCallback)&__ARQCallbackHack;
}
enabled = OSDisableInterrupts();
switch (priority) {
case ARQ_PRIORITY_LOW:
if (__ARQRequestQueueLo) {
__ARQRequestTailLo->next = request;
} else {
__ARQRequestQueueLo = request;
}
__ARQRequestTailLo = request;
break;
case ARQ_PRIORITY_HIGH:
if (__ARQRequestQueueHi) {
__ARQRequestTailHi->next = request;
} else {
__ARQRequestQueueHi = request;
}
__ARQRequestTailHi = request;
break;
}
if ((__ARQRequestPendingHi == NULL) && (__ARQRequestPendingLo == NULL)) {
__ARQPopTaskQueueHi();
if (__ARQRequestPendingHi == NULL) {
__ARQServiceQueueLo();
}
}
OSRestoreInterrupts(enabled);
}
u32 ARQGetChunkSize(void) { return __ARQChunkSize; }
|