OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [OpenRISC_SIM_GCC/] [drivers/] [dma.c] - Blame information for rev 800

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 800 filepang
#include "board.h"
2
#include "dma.h"
3
#include "support.h"
4
 
5
static void dma_clear(void);
6
static volatile struct dma_t *_dma;
7
 
8
void dma_init(void *dma_base)
9
{
10
        _dma = (struct dma_t *)dma_base;
11
        dma_clear();
12
}
13
 
14
unsigned int dma_irq_src_a(void)
15
{
16
   return _dma->int_src_a;
17
}
18
 
19
unsigned int dma_irq_src_b(void)
20
{
21
   return _dma->int_src_b;
22
}
23
 
24
unsigned int dma_irq_msk_a(void)
25
{
26
   return _dma->int_msk_a;
27
}
28
 
29
unsigned int dma_irq_msk_b(void)
30
{
31
   return _dma->int_msk_b;
32
}
33
 
34
// enable DMA
35
// mask all interrupt
36
// disable all DMA channels
37
static void dma_clear(void)
38
{
39
        int i;
40
 
41
        _dma->control = DMA_CSR_GO;             // enable DMA
42
 
43
        _dma->int_msk_a = 0x00000000;   // mask interrupt for interface A
44
        _dma->int_msk_b = 0x00000000;   // mask interrupt for interface B
45
 
46
        // diable all DMA channles
47
        for(i = 0; i < DMA_CHAN_NUMBER; i++) {
48
                _dma->channels[i].control = 0x0;
49
                _dma->channels[i].tranfer_size = 0x0;
50
                _dma->channels[i].src_addr = 0x0;
51
                // _dma->channels[i].src_mask = 0xFFFFFFFC;   
52
                _dma->channels[i].dst_addr = 0x0;
53
                // _dma->channels[i].dat_mask = 0xFFFFFFFC;   
54
                _dma->channels[i].list_desc = 0x0;
55
                _dma->channels[i].sw_ptr = 0x0;
56
        }
57
}
58
 
59
// FIXME comments
60
int dma_channel_set(int channel,
61
                                        unsigned int src_interface, unsigned int src_addr, unsigned int src_addr_incr,
62
                                        unsigned int dst_interface, unsigned int dst_addr, unsigned int dst_addr_incr,
63
                                        unsigned int chunk_word, unsigned int transfer_word,
64
                                        int handshake_mode, int int_enable)
65
{
66
        unsigned int channel_control = 0x0;
67
        unsigned int channel_transfer_size = 0x0;
68
 
69
        if(channel < 0 || channel > 31)
70
                return 1;
71
 
72
        if(chunk_word > 0x100)          // 256 words max
73
                return 1;
74
 
75
        if(transfer_word > 0x1000)      // 4096 words max
76
                return 1;
77
 
78
        // wait until channel is free
79
        do { } while((_dma->channels[channel].control & DMA_CHAN_BUSY_MSK));
80
 
81
        channel_control = (0x1 << DMA_CHAN_ENABLE_SHT) |
82
                                          (src_interface  << DMA_CHAN_SRC_SEL_SHT ) & DMA_CHAN_SRC_SEL_MSK |
83
                                          (dst_interface  << DMA_CHAN_DST_SEL_SHT ) & DMA_CHAN_SRC_SEL_MSK |
84
                                          (src_addr_incr  << DMA_CHAN_INC_SRC_SHT ) & DMA_CHAN_INC_SRC_MSK |
85
                                          (dst_addr_incr  << DMA_CHAN_INC_DST_SHT ) & DMA_CHAN_INC_DST_MSK |
86
                                          (handshake_mode << DMA_CHAN_MODE_SHT    ) & DMA_CHAN_MODE_MSK    |
87
                                          (int_enable     << DMA_CHAN_INE_ERR_SHT ) & DMA_CHAN_INE_ERR_MSK |
88
                                          (int_enable     << DMA_CHAN_INE_DONE_SHT) & DMA_CHAN_INE_DONE_MSK;
89
 
90
        channel_transfer_size = (transfer_word << DMA_CHAN_TOT_SZ_SHT) & DMA_CHAN_TOT_SZ_MSK |
91
                                                        (chunk_word    << DMA_CHAN_CHK_SZ_SHT) & DMA_CHAN_CHK_SZ_MSK ;
92
 
93
        // set channel go
94
        _dma->channels[channel].src_addr = src_addr;
95
        _dma->channels[channel].dst_addr = dst_addr;
96
        _dma->channels[channel].tranfer_size = channel_transfer_size;
97
        _dma->channels[channel].control = channel_control;
98
 
99
        // uart_print_str("setting \n\r");
100
        // uart_print_int(_dma->channels[channel].src_addr); uart_print_str("\n\r");
101
        // uart_print_int(_dma->channels[channel].dst_addr); uart_print_str("\n\r");
102
        // uart_print_int(_dma->channels[channel].tranfer_size); uart_print_str("\n\r");
103
        // uart_print_int(_dma->channels[channel].control); uart_print_str("\n\r");
104
        // uart_print_str("gg \n\r");
105
 
106
        if(int_enable)
107
                return 0;
108
 
109
        // wait until dma is done if interrupt is not used
110
        do { } while(!(_dma->channels[channel].control & (DMA_CHAN_DONE_MSK | DMA_CHAN_ERR_MSK)));
111
 
112
        channel_control = _dma->channels[channel].control;
113
 
114
        if(channel_control & DMA_CHAN_DONE_MSK)
115
                return 0;
116
 
117
        if(channel_control & DMA_CHAN_ERR_MSK)
118
                return 2;
119
}
120
 
121
 
122
// FIXME comments
123
int dma_block_transfer(int channel,
124
                                           unsigned int src_interface, unsigned int src_addr,
125
                                           unsigned int dst_interface, unsigned int dst_addr,
126
                                           unsigned int chunk_word, unsigned int transfer_word,
127
                                           int int_enable)
128
{
129
        return dma_channel_set(channel,
130
                                                   src_interface, src_addr, 1,
131
                                                   dst_interface, dst_addr, 1,
132
                                                   chunk_word, transfer_word,
133
                                                   0, int_enable);
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.