diff --git a/firmware/hackrf_usb/Makefile b/firmware/hackrf_usb/Makefile index 38dcc67e..e429af21 100644 --- a/firmware/hackrf_usb/Makefile +++ b/firmware/hackrf_usb/Makefile @@ -25,6 +25,8 @@ BINARY = hackrf_usb SRC = $(BINARY).c \ rf_path.c \ tuning.c \ + sgpio_isr.c \ + usb_bulk_buffer.c \ usb.c \ usb_request.c \ usb_standard_request.c \ diff --git a/firmware/hackrf_usb/Makefile_rom_to_ram b/firmware/hackrf_usb/Makefile_rom_to_ram index 0b38b0c1..a574692b 100644 --- a/firmware/hackrf_usb/Makefile_rom_to_ram +++ b/firmware/hackrf_usb/Makefile_rom_to_ram @@ -25,6 +25,8 @@ BINARY = hackrf_usb_rom_to_ram SRC = hackrf_usb.c \ rf_path.c \ tuning.c \ + sgpio_isr.c \ + usb_bulk_buffer.c \ usb.c \ usb_request.c \ usb_standard_request.c \ diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index a4d43862..e211d7d6 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -47,16 +47,11 @@ #include "rf_path.h" #include "tuning.h" +#include "sgpio_isr.h" +#include "usb_bulk_buffer.h" static volatile transceiver_mode_t transceiver_mode = TRANSCEIVER_MODE_OFF; -void sgpio_isr_rx(); -void sgpio_isr_tx(); - -uint8_t* const usb_bulk_buffer = (uint8_t*)0x20004000; -static volatile uint32_t usb_bulk_buffer_offset = 0; -static const uint32_t usb_bulk_buffer_mask = 32768 - 1; - usb_transfer_descriptor_t usb_td_bulk[2] ATTR_ALIGNED(64); const uint_fast8_t usb_td_bulk_count = sizeof(usb_td_bulk) / sizeof(usb_td_bulk[0]); @@ -808,72 +803,6 @@ void usb_configuration_changed( } } -void sgpio_isr_rx() { - SGPIO_CLR_STATUS_1 = (1 << SGPIO_SLICE_A); - - uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset]; - __asm__( - "ldr r0, [%[SGPIO_REG_SS], #44]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #0]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #20]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #4]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #40]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #8]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #8]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #12]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #36]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #16]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #16]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #20]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #32]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #24]\n\t" - "ldr r0, [%[SGPIO_REG_SS], #0]\n\t" - "rev16 r0, r0\n\t" /* Swap QI -> IQ */ - "str r0, [%[p], #28]\n\t" - : - : [SGPIO_REG_SS] "l" (SGPIO_PORT_BASE + 0x100), - [p] "l" (p) - : "r0" - ); - usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask; -} - -void sgpio_isr_tx() { - SGPIO_CLR_STATUS_1 = (1 << SGPIO_SLICE_A); - - uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset]; - __asm__( - "ldr r0, [%[p], #0]\n\t" - "str r0, [%[SGPIO_REG_SS], #44]\n\t" - "ldr r0, [%[p], #4]\n\t" - "str r0, [%[SGPIO_REG_SS], #20]\n\t" - "ldr r0, [%[p], #8]\n\t" - "str r0, [%[SGPIO_REG_SS], #40]\n\t" - "ldr r0, [%[p], #12]\n\t" - "str r0, [%[SGPIO_REG_SS], #8]\n\t" - "ldr r0, [%[p], #16]\n\t" - "str r0, [%[SGPIO_REG_SS], #36]\n\t" - "ldr r0, [%[p], #20]\n\t" - "str r0, [%[SGPIO_REG_SS], #16]\n\t" - "ldr r0, [%[p], #24]\n\t" - "str r0, [%[SGPIO_REG_SS], #32]\n\t" - "ldr r0, [%[p], #28]\n\t" - "str r0, [%[SGPIO_REG_SS], #0]\n\t" - : - : [SGPIO_REG_SS] "l" (SGPIO_PORT_BASE + 0x100), - [p] "l" (p) - : "r0" - ); - usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask; -} - int main(void) { const uint32_t ifreq = 2600000000U; diff --git a/firmware/hackrf_usb/sgpio_isr.c b/firmware/hackrf_usb/sgpio_isr.c new file mode 100644 index 00000000..76eebf0f --- /dev/null +++ b/firmware/hackrf_usb/sgpio_isr.c @@ -0,0 +1,93 @@ +/* + * Copyright 2012 Jared Boone + * Copyright 2013 Benjamin Vernoux + * + * 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 "sgpio_isr.h" + +#include + +#include "usb_bulk_buffer.h" + +void sgpio_isr_rx() { + SGPIO_CLR_STATUS_1 = (1 << SGPIO_SLICE_A); + + uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset]; + __asm__( + "ldr r0, [%[SGPIO_REG_SS], #44]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #0]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #20]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #4]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #40]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #8]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #8]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #12]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #36]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #16]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #16]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #20]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #32]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #24]\n\t" + "ldr r0, [%[SGPIO_REG_SS], #0]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ + "str r0, [%[p], #28]\n\t" + : + : [SGPIO_REG_SS] "l" (SGPIO_PORT_BASE + 0x100), + [p] "l" (p) + : "r0" + ); + usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask; +} + +void sgpio_isr_tx() { + SGPIO_CLR_STATUS_1 = (1 << SGPIO_SLICE_A); + + uint32_t* const p = (uint32_t*)&usb_bulk_buffer[usb_bulk_buffer_offset]; + __asm__( + "ldr r0, [%[p], #0]\n\t" + "str r0, [%[SGPIO_REG_SS], #44]\n\t" + "ldr r0, [%[p], #4]\n\t" + "str r0, [%[SGPIO_REG_SS], #20]\n\t" + "ldr r0, [%[p], #8]\n\t" + "str r0, [%[SGPIO_REG_SS], #40]\n\t" + "ldr r0, [%[p], #12]\n\t" + "str r0, [%[SGPIO_REG_SS], #8]\n\t" + "ldr r0, [%[p], #16]\n\t" + "str r0, [%[SGPIO_REG_SS], #36]\n\t" + "ldr r0, [%[p], #20]\n\t" + "str r0, [%[SGPIO_REG_SS], #16]\n\t" + "ldr r0, [%[p], #24]\n\t" + "str r0, [%[SGPIO_REG_SS], #32]\n\t" + "ldr r0, [%[p], #28]\n\t" + "str r0, [%[SGPIO_REG_SS], #0]\n\t" + : + : [SGPIO_REG_SS] "l" (SGPIO_PORT_BASE + 0x100), + [p] "l" (p) + : "r0" + ); + usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask; +} diff --git a/firmware/hackrf_usb/sgpio_isr.h b/firmware/hackrf_usb/sgpio_isr.h new file mode 100644 index 00000000..31162440 --- /dev/null +++ b/firmware/hackrf_usb/sgpio_isr.h @@ -0,0 +1,29 @@ +/* + * Copyright 2012 Jared Boone + * Copyright 2013 Benjamin Vernoux + * + * 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_ISR_H__ +#define __SGPIO_ISR_H__ + +void sgpio_isr_rx(); +void sgpio_isr_tx(); + +#endif/*__SGPIO_ISR_H__*/ diff --git a/firmware/hackrf_usb/usb_bulk_buffer.c b/firmware/hackrf_usb/usb_bulk_buffer.c new file mode 100644 index 00000000..3e6d0320 --- /dev/null +++ b/firmware/hackrf_usb/usb_bulk_buffer.c @@ -0,0 +1,27 @@ +/* + * Copyright 2012 Jared Boone + * Copyright 2013 Benjamin Vernoux + * + * 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 "usb_bulk_buffer.h" + +uint8_t* const usb_bulk_buffer = (uint8_t*)0x20004000; +const uint32_t usb_bulk_buffer_mask = 32768 - 1; +volatile uint32_t usb_bulk_buffer_offset = 0; diff --git a/firmware/hackrf_usb/usb_bulk_buffer.h b/firmware/hackrf_usb/usb_bulk_buffer.h new file mode 100644 index 00000000..fe298e69 --- /dev/null +++ b/firmware/hackrf_usb/usb_bulk_buffer.h @@ -0,0 +1,33 @@ +/* + * Copyright 2012 Jared Boone + * Copyright 2013 Benjamin Vernoux + * + * 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 __USB_BULK_BUFFER_H__ +#define __USB_BULK_BUFFER_H__ + +#include + +extern uint8_t* const usb_bulk_buffer; +extern const uint32_t usb_bulk_buffer_mask; + +extern volatile uint32_t usb_bulk_buffer_offset; + +#endif/*__USB_BULK_BUFFER_H__*/ diff --git a/firmware/hackrf_usb_rom_to_ram/Makefile b/firmware/hackrf_usb_rom_to_ram/Makefile index 2effde20..f09b0511 100644 --- a/firmware/hackrf_usb_rom_to_ram/Makefile +++ b/firmware/hackrf_usb_rom_to_ram/Makefile @@ -27,6 +27,8 @@ SRC_DIR = hackrf_usb SRC = hackrf_usb.c \ rf_path.c \ tuning.c \ + sgpio_isr.c \ + usb_bulk_buffer.c \ usb.c \ usb_request.c \ usb_standard_request.c \