sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
dmaCore.c
1// ____ ___ | / _____ _____
2// | __ | |___/ | |
3// |___| ___| | \ __|__ | gsKit Open Source Project.
4// ----------------------------------------------------------------------
5// Copyright 2004 - Chris "Neovanglist" Gilbert <Neovanglist@LainOS.org>
6// Licenced under Academic Free License version 2.0
7// Review gsKit README & LICENSE files for further details.
8//
9// dmaCore.c - Core DMA Routines.
10// Parts taken from emoon's BreakPoint Demo Library
11//
12
13#include "dmaKit.h"
14#include "dmaArrays.h"
15
16#include <stdio.h>
17#include <kernel.h>
18
19int dmaKit_wait(u16 channel, u32 timeout)
20{
21 #ifdef GSKIT_DEBUG
22 printf("Waiting for DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
23 #endif
24
25 while((*(volatile u32 *)DMA_CHCR[channel]) & 0x00000100)
26 {
27 if( timeout != 0)
28 {
29 if ( timeout == 1 )
30 {
31 printf("Timed out waiting for DMA Channel %i - %s to be clear.\n",channel, DMA_NAME[channel]);
32 return -1;
33 }
34 timeout--;
35 }
36 }
37
38 #ifdef GSKIT_DEBUG
39 printf("DMA Channel %i - %s is now clear.\n",channel, DMA_NAME[channel]);
40 #endif
41
42 return 0;
43}
44
46{
47 asm __volatile__("sync.l; sync.p;" \
48 "0:" \
49 "bc0t 0f; nop;" \
50 "bc0t 0f; nop;" \
51 "bc0t 0f; nop;" \
52 "bc0f 0b; nop;" \
53 "0:");
54}
55
56void dmaKit_send(u16 channel, void *data, u32 size)
57{
58 #ifdef GSKIT_DEBUG
59 printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
60 #endif
61
62 DMA_SET_CIS(1 << channel);
63
64 SyncDCache(data, (void *)(((u8 *)data)+size*16));
65
66 if(DMA_QWC[channel])
67 *(volatile u32 *)DMA_QWC[channel] = size;
68 *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data, 0);
69 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
70 0, // ChainMode
71 0, // Address Stack Pointer
72 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
73 0, // Enable Interrupts
74 1, // Start DMA
75 0 ); // Priority Control Enable??
76
77 #ifdef GSKIT_DEBUG
78 printf("Sent to DMA Channel\n");
79 #endif
80
81 return;
82}
83
84void dmaKit_send_ucab(u16 channel, void *data, u32 size)
85{
86 #ifdef GSKIT_DEBUG
87 printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
88 #endif
89
90 DMA_SET_CIS(1 << channel);
91
92 if(DMA_QWC[channel])
93 *(volatile u32 *)DMA_QWC[channel] = size;
94 *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data - 0x30000000, 0);
95 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
96 0, // ChainMode
97 0, // Address Stack Pointer
98 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
99 0, // Enable Interrupts
100 1, // Start DMA
101 0 ); // Priority Control Enable??
102
103 #ifdef GSKIT_DEBUG
104 printf("Sent to DMA Channel\n");
105 #endif
106
107 return;
108}
109
110void dmaKit_send_spr(u16 channel, void *data, u32 size)
111{
112 #ifdef GSKIT_DEBUG
113 printf("Sending to DMA Channel w/ SPR %i - %s\n",channel, DMA_NAME[channel]);
114 #endif
115
116 DMA_SET_CIS(1 << channel);
117
118 if(DMA_QWC[channel])
119 *(volatile u32 *)DMA_QWC[channel] = size;
120 *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data, 1);
121 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
122 0, // ChainMode
123 0, // Address Stack Pointer
124 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
125 0, // Enable Interrupts
126 1, // Start DMA
127 0 ); // Priority Control Enable??
128 #ifdef GSKIT_DEBUG
129 printf("Sent to DMA Channel w/ SPR\n");
130 #endif
131
132 return;
133}
134
135void dmaKit_send_chain(u16 channel, void *data, u32 size)
136{
137 #ifdef GSKIT_DEBUG
138 printf("Sending to DMA Channel in Chain Mode %i - %s\n",channel, DMA_NAME[channel]);
139 #endif
140
141 DMA_SET_CIS(1 << channel);
142
143 SyncDCache(data, data+size*16);
144
145 if(DMA_QWC[channel])
146 *(volatile u32 *)DMA_QWC[channel] = 0;
147
148 *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data, 0);
149 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
150 1, // ChainMode
151 0, // Address Stack Pointer
152 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
153 0, // Enable Interrupts
154 1, // Start DMA
155 0 ); // Priority Control Enable??
156
157 #ifdef GSKIT_DEBUG
158 printf("Sent to DMA Channel in Chain Mode\n");
159 #endif
160 return;
161}
162
163void dmaKit_send_chain_ucab(u16 channel, void *data)
164{
165 #ifdef GSKIT_DEBUG
166 printf("Sending to DMA Channel in Chain Mode from UCAB %i - %s\n",channel, DMA_NAME[channel]);
167 #endif
168
169 DMA_SET_CIS(1 << channel);
170
171 if(DMA_QWC[channel])
172 *(volatile u32 *)DMA_QWC[channel] = 0;
173
174 *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data - 0x30000000, 0);
175 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
176 1, // ChainMode
177 0, // Address Stack Pointer
178 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
179 0, // Enable Interrupts
180 1, // Start DMA
181 0 ); // Priority Control Enable??
182
183 #ifdef GSKIT_DEBUG
184 printf("Sent to DMA Channel in Chain Mode from UCAB\n");
185 #endif
186 return;
187}
188
189void dmaKit_send_chain_spr(u16 channel, void *data)
190{
191 #ifdef GSKIT_DEBUG
192 printf("Sending to DMA Channel in Chain Mode w/Scratchpad %i - %s\n",channel, DMA_NAME[channel]);
193 #endif
194
195 DMA_SET_CIS(1 << channel);
196
197 if(DMA_QWC[channel])
198 *(volatile u32 *)DMA_QWC[channel] = 0;
199 *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data, 1);
200 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
201 1, // ChainMode
202 0, // Address Stack Pointer
203 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
204 0, // Enable Interrupts
205 1, // Start DMA
206 0 ); // Priority Control Enable??
207
208 #ifdef GSKIT_DEBUG
209 printf("Sent to DMA Channel in Chain Mode w/Scratchpad\n");
210 #endif
211 return;
212}
213
214void dmaKit_get_spr(u16 channel, void *data, void *dest, u32 size)
215{
216 #ifdef GSKIT_DEBUG
217 printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
218 #endif
219
220 DMA_SET_CIS(1 << channel);
221
222 if(DMA_QWC[channel])
223 *(volatile u32 *)DMA_QWC[channel] = size;
224
225 *(volatile u32 *)DMA_SADR[channel] = DMA_SET_SADR((u32)data&0x3fff);
226 *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)dest&0x0fffffff, 0);
227 *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(0, // Direction
228 0, // ChainMode
229 0, // Address Stack Pointer
230 DMA_TAG_ENABLE[channel], // Transfer DMA Tag
231 0, // Enable Interrupts
232 1, // Start DMA
233 0 ); // Priority Control Enable??
234
235 #ifdef GSKIT_DEBUG
236 printf("Sent to DMA Channel\n");
237 #endif
238
239 return;
240}
241
void dmaKit_wait_fast(void)
Definition dmaCore.c:45
void dmaKit_send(u16 channel, void *data, u32 size)
Definition dmaCore.c:56
void dmaKit_get_spr(u16 channel, void *data, void *dest, u32 size)
Definition dmaCore.c:214
void dmaKit_send_ucab(u16 channel, void *data, u32 size)
Definition dmaCore.c:84
void dmaKit_send_chain_spr(u16 channel, void *data)
Definition dmaCore.c:189
void dmaKit_send_chain(u16 channel, void *data, u32 size)
Definition dmaCore.c:135
void dmaKit_send_spr(u16 channel, void *data, u32 size)
Definition dmaCore.c:110
int dmaKit_wait(u16 channel, u32 timeout)
Definition dmaCore.c:19
void dmaKit_send_chain_ucab(u16 channel, void *data)
Definition dmaCore.c:163