Skip to content

Commit 5672be9

Browse files
committed
firmware: move clock-associated gpio functions to clkin.x and rename to clock_io.h|c
1 parent e274109 commit 5672be9

12 files changed

Lines changed: 76 additions & 84 deletions

File tree

firmware/common/clock_gen.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
#include "delay.h"
3434
#include "portapack.h"
3535
#endif
36-
#if defined(IS_PRALINE)
37-
#include "gpio.h"
38-
#include "platform_gpio.h"
39-
#endif
4036

4137
void clock_gen_init(void)
4238
{
@@ -426,27 +422,3 @@ fp_28_36_t sample_rate_set(const fp_28_36_t sample_rate, const bool program)
426422

427423
return resultant_rate;
428424
}
429-
430-
#ifdef IS_PRALINE
431-
void p1_ctrl_set(const p1_ctrl_signal_t signal)
432-
{
433-
const platform_gpio_t* gpio = platform_gpio();
434-
435-
gpio_write(gpio->p1_ctrl0, signal & 1);
436-
gpio_write(gpio->p1_ctrl1, (signal >> 1) & 1);
437-
gpio_write(gpio->p1_ctrl2, (signal >> 2) & 1);
438-
}
439-
440-
void p2_ctrl_set(const p2_ctrl_signal_t signal)
441-
{
442-
const platform_gpio_t* gpio = platform_gpio();
443-
444-
gpio_write(gpio->p2_ctrl0, signal & 1);
445-
gpio_write(gpio->p2_ctrl1, (signal >> 1) & 1);
446-
}
447-
448-
void pps_out_set(const uint8_t value)
449-
{
450-
gpio_write(platform_gpio()->pps_out, value & 1);
451-
}
452-
#endif

firmware/common/clock_gen.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ extern "C" {
2828
#include "platform_detect.h" // IWYU pragma: keep
2929

3030
#include <stdbool.h>
31-
#ifdef IS_PRALINE
32-
#include <stdint.h>
33-
#endif
3431

3532
#include "fixed_point.h"
3633

@@ -47,30 +44,6 @@ clock_source_t activate_best_clock_source(void);
4744

4845
fp_28_36_t sample_rate_set(const fp_28_36_t sample_rate, const bool program);
4946

50-
#ifdef IS_PRALINE
51-
typedef enum {
52-
P1_SIGNAL_TRIGGER_IN = 0,
53-
P1_SIGNAL_AUX_CLK1 = 1,
54-
P1_SIGNAL_CLKIN = 2,
55-
P1_SIGNAL_TRIGGER_OUT = 3,
56-
P1_SIGNAL_P22_CLKIN = 4,
57-
P1_SIGNAL_P2_5 = 5,
58-
P1_SIGNAL_NC = 6,
59-
P1_SIGNAL_AUX_CLK2 = 7,
60-
} p1_ctrl_signal_t;
61-
62-
typedef enum {
63-
P2_SIGNAL_CLK3 = 0,
64-
P2_SIGNAL_TRIGGER_IN = 2,
65-
P2_SIGNAL_TRIGGER_OUT = 3,
66-
} p2_ctrl_signal_t;
67-
68-
void p1_ctrl_set(const p1_ctrl_signal_t signal);
69-
void p2_ctrl_set(const p2_ctrl_signal_t signal);
70-
71-
void pps_out_set(const uint8_t value);
72-
#endif
73-
7447
#ifdef __cplusplus
7548
}
7649
#endif
Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Great Scott Gadgets
2+
* Copyright 2022-2026 Great Scott Gadgets
33
*
44
* This file is part of HackRF.
55
*
@@ -19,8 +19,9 @@
1919
* Boston, MA 02110-1301, USA.
2020
*/
2121

22-
#include "clkin.h"
22+
#include "clock_io.h"
2323

24+
#include <stdbool.h>
2425
#include <stdint.h>
2526

2627
#include <libopencm3/lpc43xx/timer.h>
@@ -30,8 +31,10 @@
3031
#include <libopencm3/lpc43xx/creg.h>
3132

3233
#include "gpdma.h"
34+
#include "gpio.h"
35+
#include "hackrf_core.h"
3336
#ifdef IS_PRALINE
34-
#include "gpio.h"
37+
#include "fpga.h"
3538
#include "platform_gpio.h"
3639
#endif
3740

@@ -120,9 +123,45 @@ uint32_t clkin_frequency(void)
120123
return TIMER2_CR3 * (1000 / MEASUREMENT_WINDOW_MS);
121124
}
122125

126+
void trigger_enable(const bool enable)
127+
{
128+
#ifdef IS_NOT_PRALINE
129+
if (IS_NOT_PRALINE) {
130+
gpio_write(sgpio_config.gpio_trigger_enable, enable);
131+
}
132+
#endif
133+
#ifdef IS_PRALINE
134+
if (IS_PRALINE) {
135+
fpga_set_trigger_enable(&fpga, enable);
136+
}
137+
#endif
138+
}
139+
123140
#ifdef IS_PRALINE
124141
void clkin_ctrl_set(const clkin_signal_t signal)
125142
{
126143
gpio_write(platform_gpio()->clkin_ctrl, signal & 1);
127144
}
145+
146+
void p1_ctrl_set(const p1_ctrl_signal_t signal)
147+
{
148+
const platform_gpio_t* gpio = platform_gpio();
149+
150+
gpio_write(gpio->p1_ctrl0, signal & 1);
151+
gpio_write(gpio->p1_ctrl1, (signal >> 1) & 1);
152+
gpio_write(gpio->p1_ctrl2, (signal >> 2) & 1);
153+
}
154+
155+
void p2_ctrl_set(const p2_ctrl_signal_t signal)
156+
{
157+
const platform_gpio_t* gpio = platform_gpio();
158+
159+
gpio_write(gpio->p2_ctrl0, signal & 1);
160+
gpio_write(gpio->p2_ctrl1, (signal >> 1) & 1);
161+
}
162+
163+
void pps_out_set(const uint8_t value)
164+
{
165+
gpio_write(platform_gpio()->pps_out, value & 1);
166+
}
128167
#endif
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Great Scott Gadgets
2+
* Copyright 2022-2026 Great Scott Gadgets
33
*
44
* This file is part of HackRF.
55
*
@@ -21,18 +21,42 @@
2121

2222
#pragma once
2323

24+
#include <stdbool.h>
2425
#include <stdint.h>
2526

2627
#include "platform_detect.h" // IWYU pragma: keep
2728

2829
void clkin_detect_init(void);
2930
uint32_t clkin_frequency(void);
3031

32+
void trigger_enable(const bool enable);
33+
3134
#ifdef IS_PRALINE
3235
typedef enum {
3336
CLKIN_SIGNAL_P1 = 0,
3437
CLKIN_SIGNAL_P22 = 1,
3538
} clkin_signal_t;
3639

40+
typedef enum {
41+
P1_SIGNAL_TRIGGER_IN = 0,
42+
P1_SIGNAL_AUX_CLK1 = 1,
43+
P1_SIGNAL_CLKIN = 2,
44+
P1_SIGNAL_TRIGGER_OUT = 3,
45+
P1_SIGNAL_P22_CLKIN = 4,
46+
P1_SIGNAL_P2_5 = 5,
47+
P1_SIGNAL_NC = 6,
48+
P1_SIGNAL_AUX_CLK2 = 7,
49+
} p1_ctrl_signal_t;
50+
51+
typedef enum {
52+
P2_SIGNAL_CLK3 = 0,
53+
P2_SIGNAL_TRIGGER_IN = 2,
54+
P2_SIGNAL_TRIGGER_OUT = 3,
55+
} p2_ctrl_signal_t;
56+
3757
void clkin_ctrl_set(const clkin_signal_t value);
58+
void p1_ctrl_set(const p1_ctrl_signal_t signal);
59+
void p2_ctrl_set(const p2_ctrl_signal_t signal);
60+
61+
void pps_out_set(const uint8_t value);
3862
#endif

firmware/common/hackrf_core.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* Boston, MA 02110-1301, USA.
2222
*/
2323

24+
#include <stdbool.h>
25+
2426
#include <libopencm3/lpc43xx/memorymap.h>
2527
#include <libopencm3/lpc43xx/scu.h>
2628
#include <libopencm3/lpc43xx/ssp.h>
@@ -40,7 +42,7 @@
4042
#include "spi_bus.h"
4143
#include "w25q80bv_target.h"
4244
#ifdef IS_PRALINE
43-
#include "clkin.h"
45+
#include "clock_io.h"
4446
#include "ice40_spi.h"
4547
#endif
4648

@@ -512,17 +514,3 @@ void pin_setup(void)
512514

513515
sgpio_configure_pin_functions(&sgpio_config);
514516
}
515-
516-
void trigger_enable(const bool enable)
517-
{
518-
#ifdef IS_NOT_PRALINE
519-
if (IS_NOT_PRALINE) {
520-
gpio_write(sgpio_config.gpio_trigger_enable, enable);
521-
}
522-
#endif
523-
#ifdef IS_PRALINE
524-
if (IS_PRALINE) {
525-
fpga_set_trigger_enable(&fpga, enable);
526-
}
527-
#endif
528-
}

firmware/common/hackrf_core.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
extern "C" {
2828
#endif
2929

30-
#include <stdbool.h>
31-
3230
#include "cpld_jtag.h"
3331
#include "i2c_bus.h"
3432
#include "i2c_lpc.h"
@@ -76,8 +74,6 @@ void ssp1_set_mode_ice40(void);
7674
void pin_shutdown(void);
7775
void pin_setup(void);
7876

79-
void trigger_enable(const bool enable);
80-
8177
#ifdef __cplusplus
8278
}
8379
#endif

firmware/common/radio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <libopencm3/cm3/nvic.h>
2727

28+
#include "clock_io.h"
2829
#include "fixed_point.h"
2930
#include "hackrf_core.h"
3031
#include "mixer.h"

firmware/common/sgpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "platform_scu.h"
3333
#include "sgpio.h"
3434
#ifdef IS_NOT_PRALINE
35-
#include "hackrf_core.h"
35+
#include "clock_io.h"
3636
#endif
3737

3838
static void update_q_invert(sgpio_config_t* const config);

firmware/common/si5351c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <stdbool.h>
2424
#include <stddef.h>
2525

26-
#include "clkin.h"
26+
#include "clock_io.h"
2727
#include "delay.h"
2828
#include "platform_detect.h"
2929
#include "selftest.h"

firmware/hackrf-common.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ macro(DeclareTargets)
192192
${PATH_HACKRF_FIRMWARE_COMMON}/platform_gpio.c
193193
${PATH_HACKRF_FIRMWARE_COMMON}/platform_scu.c
194194
${PATH_HACKRF_FIRMWARE_COMMON}/firmware_info.c
195-
${PATH_HACKRF_FIRMWARE_COMMON}/clkin.c
195+
${PATH_HACKRF_FIRMWARE_COMMON}/clock_io.c
196196
${PATH_HACKRF_FIRMWARE_COMMON}/gpdma.c
197197
${PATH_HACKRF_FIRMWARE_COMMON}/radio.c
198198
${PATH_HACKRF_FIRMWARE_COMMON}/selftest.c

0 commit comments

Comments
 (0)