-
Notifications
You must be signed in to change notification settings - Fork 0
/
dma.h
71 lines (55 loc) · 2.31 KB
/
dma.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
// dma.h
#include "mylib.h"
#define DMATRANSFER(_dst, _src, _count, _ch, _mode) \
do { \
dma_mem[_ch].cnt = 0; \
dma_mem[_ch].src = (const void*) (_src); \
dma_mem[_ch].dst = (void*) (_dst); \
dma_mem[_ch].cnt = (_count) | (_mode); \
} while(0)
#define REG_DMA0SAD *(unsigned int*)0x40000B0 // source address
#define REG_DMA0DAD *(unsigned int*)0x40000B4 // destination address
#define REG_DMA0CNT *(unsigned int*)0x40000B8 // control register
/* DMA channel 1 register definitions */
#define REG_DMA1SAD *(unsigned int*)0x40000BC // source address
#define REG_DMA1DAD *(unsigned int*)0x40000C0 // destination address
#define REG_DMA1CNT *(unsigned int*)0x40000C4 // control register
/* DMA channel 2 register definitions */
#define REG_DMA2SAD *(unsigned int*)0x40000C8 // source address
#define REG_DMA2DAD *(unsigned int*)0x40000CC // destination address
#define REG_DMA2CNT *(unsigned int*)0x40000D0 // control register
/* DMA channel 3 register definitions */
#define REG_DMA3SAD *(unsigned int*)0x40000D4 // source address
#define REG_DMA3DAD *(unsigned int*)0x40000D8 // destination address
#define REG_DMA3CNT *(unsigned int*)0x40000DC // control register
/* Defines */
#define DMA_CHANNEL_0 0
#define DMA_CHANNEL_1 1
#define DMA_CHANNEL_2 2
#define DMA_CHANNEL_3 3
// Note: The next 4 lines can tell you the default: DMA_DESTINATION_INCREMENT
// as well as which bits are used for this (i.e. 22 and 21)
#define DMA_DESTINATION_INCREMENT (0 << 21)
#define DMA_DESTINATION_DECREMENT (1 << 21)
#define DMA_DESTINATION_FIXED (2 << 21)
#define DMA_DESTINATION_RESET (3 << 21)
#define DMA_SOURCE_INCREMENT (0 << 23)
#define DMA_SOURCE_DECREMENT (1 << 23)
#define DMA_SOURCE_FIXED (2 << 23)
#define DMA_REPEAT (1 << 25) // Used for sound
#define DMA_16 (0 << 26) // Typically use this
#define DMA_32 (1 << 26)
#define DMA_NOW (0 << 28) // Typically use this
#define DMA_AT_VBLANK (1 << 28)
#define DMA_AT_HBLANK (2 << 28)
#define DMA_AT_REFRESH (3 << 28)
#define DMA_IRQ (1 << 30)
#define DMA_ON (1 << 31) // The on switch!!!!
#define dma_mem ((volatile DMAREC*) 0x040000B0)
typedef struct
{
const volatile void *src;
volatile void *dst;
volatile unsigned int cnt;
} DMAREC;
void dma_memcpy(void *dst, const void *src, u16 count);