mirror of
https://github.com/greatscottgadgets/hackrf.git
synced 2026-02-20 00:33:48 +01:00
Move delay functions out of hackrf_core.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "hackrf_core.h"
|
||||
#include "platform_detect.h"
|
||||
#include "delay.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
42
firmware/common/delay.c
Normal file
42
firmware/common/delay.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
|
||||
*
|
||||
* 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 "delay.h"
|
||||
|
||||
void delay(uint32_t duration)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < duration; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us_at_mhz(uint32_t us, uint32_t mhz)
|
||||
{
|
||||
// The loop below takes 3 cycles per iteration.
|
||||
uint32_t loop_iterations = (us * mhz) / 3;
|
||||
asm volatile("start%=:\n"
|
||||
" subs %[ITERATIONS], #1\n" // 1 cycle
|
||||
" bpl start%=\n" // 2 cycles
|
||||
:
|
||||
: [ITERATIONS] "r"(loop_iterations));
|
||||
}
|
||||
34
firmware/common/delay.h
Normal file
34
firmware/common/delay.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
|
||||
*
|
||||
* 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 __DELAY_H
|
||||
#define __DELAY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void delay(uint32_t duration);
|
||||
void delay_us_at_mhz(uint32_t us, uint32_t mhz);
|
||||
|
||||
#endif /* __DELAY_H */
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "streaming.h"
|
||||
#include "selftest.h"
|
||||
#include "fpga.h"
|
||||
#include "delay.h"
|
||||
|
||||
// USB buffer used during selftests.
|
||||
#define USB_BULK_BUFFER_SIZE 0x8000
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "hackrf_core.h"
|
||||
#include "hackrf_ui.h"
|
||||
#include "delay.h"
|
||||
#include "sgpio.h"
|
||||
#include "si5351c.h"
|
||||
#include "spi_ssp.h"
|
||||
@@ -441,26 +442,6 @@ jtag_t jtag_cpld = {
|
||||
.gpio = &jtag_gpio_cpld,
|
||||
};
|
||||
|
||||
void delay(uint32_t duration)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < duration; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us_at_mhz(uint32_t us, uint32_t mhz)
|
||||
{
|
||||
// The loop below takes 3 cycles per iteration.
|
||||
uint32_t loop_iterations = (us * mhz) / 3;
|
||||
asm volatile("start%=:\n"
|
||||
" subs %[ITERATIONS], #1\n" // 1 cycle
|
||||
" bpl start%=\n" // 2 cycles
|
||||
:
|
||||
: [ITERATIONS] "r"(loop_iterations));
|
||||
}
|
||||
|
||||
/* GCD algo from wikipedia */
|
||||
/* http://en.wikipedia.org/wiki/Greatest_common_divisor */
|
||||
static uint32_t gcd(uint32_t u, uint32_t v)
|
||||
|
||||
@@ -389,9 +389,6 @@ extern "C" {
|
||||
#define SCU_H1R9_NO_VAA_EN (P6_10) /* GPIO3[6] on P6_10 */
|
||||
#define SCU_H1R9_TRIGGER_EN (P2_5) /* GPIO5[5] on P2_5 */
|
||||
|
||||
void delay(uint32_t duration);
|
||||
void delay_us_at_mhz(uint32_t us, uint32_t mhz);
|
||||
|
||||
/* TODO: Hide these configurations */
|
||||
extern si5351c_driver_t clock_gen;
|
||||
extern const ssp_config_t ssp_config_w25q80bv;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
#include "hackrf_core.h"
|
||||
#include "delay.h"
|
||||
|
||||
void ice40_spi_target_init(ice40_spi_driver_t* const drv)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
#include <libopencm3/lpc43xx/gima.h>
|
||||
#include "sct.h"
|
||||
#include "delay.h"
|
||||
|
||||
#define U1CTRL_SET SCT_OUT14_SET
|
||||
#define U1CTRL_CLR SCT_OUT14_CLR
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "firmware_info.h"
|
||||
#include "gpio_lpc.h"
|
||||
#include "hackrf_core.h"
|
||||
#include "delay.h"
|
||||
#include "adc.h"
|
||||
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "hackrf_core.h"
|
||||
#include "gpio_lpc.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "gpio_lpc.h"
|
||||
#include "hackrf_core.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
#include <libopencm3/lpc43xx/ssp.h>
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <libopencm3/lpc43xx/scu.h>
|
||||
#include "hackrf_core.h"
|
||||
#include "delay.h"
|
||||
|
||||
/* Default register values from vendor documentation or software. */
|
||||
static const uint16_t rffc5071_regs_default[RFFC5071_NUM_REGS] = {
|
||||
|
||||
@@ -168,6 +168,7 @@ endmacro()
|
||||
macro(DeclareTargets)
|
||||
SET(SRC_M4
|
||||
${SRC_M4}
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/delay.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/hackrf_core.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/sgpio.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/rf_path.c
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "clkin.h"
|
||||
#include "fpga.h"
|
||||
#include "selftest.h"
|
||||
#include "delay.h"
|
||||
|
||||
extern uint32_t __m0_start__;
|
||||
extern uint32_t __m0_end__;
|
||||
|
||||
Reference in New Issue
Block a user