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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc3/] [or1ksim/] [peripheral/] [dma.c] - Diff between revs 252 and 256

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 252 Rev 256
Line 29... Line 29...
#include "trace.h"
#include "trace.h"
#include "pic.h"
#include "pic.h"
#include "abstract.h"
#include "abstract.h"
#include "fields.h"
#include "fields.h"
 
 
 
#define dprintf(x) printf x
 
 
/* The representation of the DMA controllers */
/* The representation of the DMA controllers */
static struct dma_controller dmas[NR_DMAS];
static struct dma_controller dmas[NR_DMAS];
 
 
static unsigned long dma_read32( unsigned long addr );
static unsigned long dma_read32( unsigned long addr );
static void dma_write32( unsigned long addr, unsigned long value );
static void dma_write32( unsigned long addr, unsigned long value );
Line 315... Line 317...
                if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN ) )
                if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN ) )
                        continue;
                        continue;
 
 
                /* Do we need to abort? */
                /* Do we need to abort? */
                if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, STOP ) ) {
                if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, STOP ) ) {
                        fprintf( stderr, "DMA: STOP requested\n" );
                        dprintf(( "DMA: STOP requested\n" ));
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
                        SET_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
                        SET_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
 
 
                        if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INE_ERR ) &&
                        if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INE_ERR ) &&
Line 333... Line 335...
                }
                }
 
 
                /* In HW Handshake mode, only work when dma_req_i asserted */
                /* In HW Handshake mode, only work when dma_req_i asserted */
                if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, MODE ) &&
                if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, MODE ) &&
                                 !channel->dma_req_i ) {
                                 !channel->dma_req_i ) {
                        fprintf( stderr, "DMA: Waiting for HW handshake\n" );
 
                        continue;
                        continue;
                }
                }
 
 
                /* If this is the first cycle of the transfer, initialize our state */
                /* If this is the first cycle of the transfer, initialize our state */
                if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY ) ) {
                if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY ) ) {
 
                        dprintf(( "Starting new transfer\n" ));
 
 
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, DONE );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, DONE );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
                        CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
                        SET_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
                        SET_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
 
 
                        /* If using linked lists, copy the appropriate fields to our registers */
                        /* If using linked lists, copy the appropriate fields to our registers */
Line 354... Line 357...
                        /* Set our internal status */
                        /* Set our internal status */
                        dma_init_transfer( channel );
                        dma_init_transfer( channel );
 
 
                        /* Might need to skip descriptor */
                        /* Might need to skip descriptor */
                        if ( CHANNEL_ND_I( channel ) ) {
                        if ( CHANNEL_ND_I( channel ) ) {
                                fprintf( stderr, "DMA: dma_nd_i asserted before dma_req_i, skipping descriptor\n" );
                                dprintf(( "DMA: dma_nd_i asserted before dma_req_i, skipping descriptor\n" ));
                                dma_channel_terminate_transfer( channel, 0 );
                                dma_channel_terminate_transfer( channel, 0 );
                                continue;
                                continue;
                        }
                        }
                }
                }
 
 
Line 373... Line 376...
                /* Have we finished a whole chunk? */
                /* Have we finished a whole chunk? */
                channel->dma_ack_o = (channel->words_transferred % channel->chunk_size == 0);
                channel->dma_ack_o = (channel->words_transferred % channel->chunk_size == 0);
 
 
                /* When done with a chunk, check for dma_nd_i */
                /* When done with a chunk, check for dma_nd_i */
                if ( CHANNEL_ND_I( channel ) ) {
                if ( CHANNEL_ND_I( channel ) ) {
                        fprintf( stderr, "DMA: dma_nd_i asserted, \n" );
                        dprintf(( "DMA: dma_nd_i asserted\n" ));
                        dma_channel_terminate_transfer( channel, 0 );
                        dma_channel_terminate_transfer( channel, 0 );
                        continue;
                        continue;
                }
                }
 
 
                /* Are we done? */
                /* Are we done? */
Line 426... Line 429...
 
 
 
 
/* Take care of transfer termination */
/* Take care of transfer termination */
void dma_channel_terminate_transfer( struct dma_channel *channel, int generate_interrupt )
void dma_channel_terminate_transfer( struct dma_channel *channel, int generate_interrupt )
{
{
 
        dprintf(( "DMA: Terminating transfer\n" ));
 
 
        /* Might be working in a linked list */
        /* Might be working in a linked list */
        if ( channel->load_next_descriptor_when_done ) {
        if ( channel->load_next_descriptor_when_done ) {
                dma_load_descriptor( channel );
                dma_load_descriptor( channel );
                dma_init_transfer( channel );
                dma_init_transfer( channel );
                return;
                return;
Line 470... Line 475...
}
}
 
 
/* Utility function: Add 4 to a value with a mask */
/* Utility function: Add 4 to a value with a mask */
void masked_increase( unsigned long *value, unsigned long mask )
void masked_increase( unsigned long *value, unsigned long mask )
{
{
        *value = (*value & ~mask) | ((*value & mask) + 4);
        *value = (*value & ~mask) | ((*value + 4) & mask);
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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