From 34b01d89af4515e0bfbc54758c8a0190ef17473e Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 7 Dec 2013 15:29:14 -0800 Subject: [PATCH] Add SGPIO DMA configuration code. --- firmware/common/sgpio_dma.c | 142 ++++++++++++++++++++++++++++++++++++ firmware/common/sgpio_dma.h | 35 +++++++++ 2 files changed, 177 insertions(+) create mode 100644 firmware/common/sgpio_dma.c create mode 100644 firmware/common/sgpio_dma.h diff --git a/firmware/common/sgpio_dma.c b/firmware/common/sgpio_dma.c new file mode 100644 index 00000000..b0383250 --- /dev/null +++ b/firmware/common/sgpio_dma.c @@ -0,0 +1,142 @@ +/* + * 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 + +#define LLI_COUNT 4 + +static void configure_dma_lli(gpdma_lli_t* const lli, const bool direction_transmit, void* const buffer, const size_t byte_count) { + const size_t transfer_count = LLI_COUNT; + const size_t transfer_bytes = 4; + const size_t transfer_size = byte_count / transfer_count / transfer_bytes; + const size_t transfer_size_bytes = transfer_size * transfer_bytes; + + for(size_t i=0; i 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); +} + +static gpdma_lli_t lli_rx[LLI_COUNT]; +static gpdma_lli_t lli_tx[LLI_COUNT]; + +void sgpio_dma_init(void* const buffer, const size_t byte_count) { + configure_dma_lli(lli_rx, false, buffer, byte_count); + configure_dma_lli(lli_tx, true, buffer, byte_count); + + /* 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() { + sgpio_dma_enable(dma_channel_sgpio, lli_rx, false); +} + +void sgpio_dma_tx_start() { + sgpio_dma_enable(dma_channel_sgpio, lli_tx, 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 next_lli = (gpdma_lli_t*)GPDMA_CLLI(dma_channel_sgpio); + for(size_t i=0; i + * + * 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. + */ + +#ifndef __SGPIO_DMA_H__ +#define __SGPIO_DMA_H__ + +#include + +void sgpio_dma_init(void* const buffer, const size_t byte_count); +void sgpio_dma_rx_start(); +void sgpio_dma_tx_start(); +void sgpio_dma_irq_tc_acknowledge(); +void sgpio_dma_stop(); + +size_t sgpio_dma_current_transfer_index(); + +#endif/*__SGPIO_DMA_H__*/