/* * Copyright 2013 Jared Boone * * This file is part of HackRF. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include void sgpio_dma_configure_lli( gpdma_lli_t* const lli, const size_t lli_count, const bool direction_transmit, void* const buffer, const size_t transfer_bytes ) { const size_t bytes_per_word = 4; const size_t transfer_words = (transfer_bytes + bytes_per_word - 1) / bytes_per_word; gpdma_lli_create_loop(lli, lli_count); for(size_t i=0; icsrcaddr; GPDMA_CDESTADDR(channel) = (uint32_t)lli->cdestaddr; GPDMA_CLLI(channel) = (uint32_t)lli->clli; GPDMA_CCONTROL(channel) = lli->ccontrol; /* 1: Memory -> Peripheral * 2: Peripheral -> Memory */ const uint_fast8_t flowcntrl = direction_transmit ? 1 : 2; GPDMA_CCONFIG(channel) = GPDMA_CCONFIG_E(0) | GPDMA_CCONFIG_SRCPERIPHERAL(0) | GPDMA_CCONFIG_DESTPERIPHERAL(0) | GPDMA_CCONFIG_FLOWCNTRL(flowcntrl) | GPDMA_CCONFIG_IE(1) | GPDMA_CCONFIG_ITC(1) | GPDMA_CCONFIG_L(0) | GPDMA_CCONFIG_H(0) ; gpdma_channel_enable(channel); } void sgpio_dma_init() { /* DMA peripheral/source 0, option 2 (SGPIO14) -- BREQ */ CREG_DMAMUX &= ~(CREG_DMAMUX_DMAMUXPER0_MASK); CREG_DMAMUX |= CREG_DMAMUX_DMAMUXPER0(0x2); // Disable sync, maybe it is causing max speed (10MT/sec) glitches? //GPDMA_DMACSYNC = (1 << 0); //GPDMA_SYNC = GPDMA_SYNC_DMACSYNC(0xFFFF); // TODO: Don't do this, I'm just going nuts here. gpdma_controller_enable(); } static const uint_fast8_t dma_channel_sgpio = 0; void sgpio_dma_rx_start(const gpdma_lli_t* const start_lli) { sgpio_dma_enable(dma_channel_sgpio, start_lli, false); } void sgpio_dma_tx_start(const gpdma_lli_t* const start_lli) { sgpio_dma_enable(dma_channel_sgpio, start_lli, true); } void sgpio_dma_irq_tc_acknowledge() { gpdma_channel_interrupt_tc_clear(dma_channel_sgpio); } void sgpio_dma_stop() { gpdma_channel_disable(dma_channel_sgpio); } size_t sgpio_dma_current_transfer_index( const gpdma_lli_t* const lli, const size_t lli_count ) { const uint32_t next_lli = GPDMA_CLLI(dma_channel_sgpio); for(size_t i=0; i