Shameful commit. Fixed HackRF mode not working...

Sync'd with Sharebrained's repo, no more SIMD warnings
This commit is contained in:
furrtek 2017-04-07 02:00:05 +01:00
commit 1e79be5555
11 changed files with 232 additions and 63 deletions

View File

@ -25,7 +25,7 @@ set(COMMON ${PROJECT_SOURCE_DIR}/common)
set(CHIBIOS ${PROJECT_SOURCE_DIR}/chibios)
set(CHIBIOS_PORTAPACK ${PROJECT_SOURCE_DIR}/chibios-portapack)
set(HACKRF_FIRMWARE_FILENAME hackrf_one_usb_ram.dfu)
set(HACKRF_FIRMWARE_FILENAME hackrf_one_usb.dfu)
set(HACKRF_FIRMWARE_IMAGE ${PROJECT_SOURCE_DIR}/${HACKRF_FIRMWARE_FILENAME})
set(HACKRF_CPLD_SVF_FILENAME hackrf_cpld_default.svf)

View File

@ -42,18 +42,40 @@ BHTView::~BHTView() {
}
void BHTView::generate_message() {
uint8_t ccir_message[20];
uint32_t c;
if (!_mode) {
if (tx_mode == SINGLE) {
text_message.set(
gen_message_xy(header_code_a.value(), header_code_b.value(), city_code_xy.value(), family_code_xy.value(),
checkbox_wcsubfamily.value(), subfamily_code.value(), checkbox_wcid.value(), receiver_code.value(),
relay_states[0].selected_index(), relay_states[1].selected_index(),
relay_states[2].selected_index(), relay_states[3].selected_index())
);
}/* else if (tx_mode == SEQUENCE) {
// sequence_lille_matin
for (c = 0; c < 20; c++) {
if (sequence_lille_matin[seq_index].code[c] <= 9)
ccir_message[c] = sequence_lille_matin[seq_index].code[c] - '0';
else
ccir_message[c] = sequence_lille_matin[seq_index].code[c] - 'A' + 10;
}
// Copy for baseband
memcpy(shared_memory.bb_data.tones_data.message, ccir_message, 20);
text_message.set(sequence_lille_matin[seq_index].code);
text_message.set_dirty();
}*/
} else {
/*else {
text_message.set(
gen_message_ep(city_code_ep.value(), family_code_ep.selected_index_value(),
relay_states[0].selected_index(), relay_states[1].selected_index())
);
);*/
}
}
@ -109,7 +131,15 @@ void BHTView::on_tx_progress(const int progress, const bool done) {
} else {
progressbar.set_value(progress);
}
}/* else if (tx_mode == SEQUENCE) {
if (done) {
transmitter_model.disable();
chThdSleepMilliseconds(sequence_lille_matin[seq_index].delay * 1000);
seq_index++;
generate_message();
start_tx();
}
}*/
}
BHTView::BHTView(NavigationView& nav) {
@ -135,6 +165,7 @@ BHTView::BHTView(NavigationView& nav) {
&text_message,
&checkbox_cligno,
&tempo_cligno,
&button_seq, // Sequence
&tx_view
});
@ -270,6 +301,15 @@ BHTView::BHTView(NavigationView& nav) {
};
};
button_seq.on_select = [this, &nav](Button&) {
if ((tx_mode == IDLE) && (!_mode)) {
seq_index = 0;
tx_mode = SEQUENCE;
tx_view.set_transmitting(true);
start_tx();
}
};
tx_view.on_start = [this]() {
if ((tx_mode == IDLE) && (!_mode)) {
if (speaker_enabled && _mode)

View File

@ -50,6 +50,45 @@ public:
std::string title() const override { return "BHT transmit"; };
private:
uint32_t seq_index { 0 };
struct sequence_t {
const std::string code;
const uint32_t delay;
};
/*
2017-03-03 07:11:04 0000189000B1002B0000 18:9:0:00 R1=OFF (1)
2017-03-03 07:11:23 0000189200B2110B0000 18:9:2:00 R1=ON (4)
2017-03-03 07:11:39 0000189200B1110B0000 18:9:2:00 R1=OFF (4)
2017-03-03 07:12:31 0001189200B2110B0000 18:9:2:00 R1=ON (4)
2017-03-03 07:12:48 0001189200B1110B0000 18:9:2:00 R1=OFF (4)
2017-03-03 07:13:04 0000189000B0012B0000 18:9:0:00 R3=OFF (2)
2017-03-03 07:13:26 0001189200B1120B0000 18:9:2:00 R3=ON (6)
2017-03-03 07:13:43 0001189200B1110B0000 18:9:2:00 R3=OFF (6)
2017-03-03 07:14:00 0001181AAAB1000B0000 18:1:A:AA R1=OFF (10)
2017-03-03 07:14:17 0001189400B1000B0000 18:9:4:00 R1=OFF (7)
2017-03-03 07:14:31 0001189200B1120B0000 18:9:2:00 R3=ON (6)
2017-03-03 07:14:48 0001189200B1110B0000 18:9:2:00 R3=OFF (6)
2017-03-03 07:15:05 0001181AAAB1000B0000 18:1:A:AA
2017-03-03 07:15:22 0001189400B0100B0000 18:9:4:00 R2=OFF (8)
*/
const sequence_t sequence_lille_matin[14] = {
{ "0000189000B1002B0000", 19 }, // 18:9:0:00 R1=OFF (1)
{ "0000189200B2110B0000", 16 }, // 18:9:2:00 R1=ON (4)
{ "0000189200B1110B0000", 52 }, // 18:9:2:00 R1=OFF (4)
{ "0000189200B2110B0000", 17 }, // 18:9:2:00 R1=ON (4)
{ "0000189200B1110B0000", 16 }, // 18:9:2:00 R1=OFF (4)
{ "0000189000B0012B0000", 22 }, // 18:9:0:00 R3=OFF (2)
{ "0000189200B1120B0000", 17 }, // 18:9:2:00 R3=ON (6)
{ "0000189200B1110B0000", 17 }, // 18:9:2:00 R3=OFF (6)
{ "0000181AAAB1000B0000", 17 }, // 18:1:A:AA R1=OFF (10)
{ "0000189400B1000B0000", 17 }, // 18:9:4:00 R1=OFF (7)
{ "0000189200B1120B0000", 14 }, // 18:9:2:00 R3=ON (6)
{ "0000189200B1110B0000", 17 }, // 18:9:2:00 R3=OFF (6)
{ "0000181AAAB1000B0000", 17 }, // 18:1:A:AA
{ "0000189400B0100B0000", 17 } // 18:9:4:00 R2=OFF (8)
};
enum tx_modes {
IDLE = 0,
SINGLE,
@ -215,6 +254,11 @@ private:
' '
};
Button button_seq {
{ 210, 210, 30, 30 },
"SQ"
};
TransmitterView tx_view {
16 * 16,
10000,

View File

@ -23,6 +23,7 @@
#define __CHANNEL_STATS_COLLECTOR_H__
#include "dsp_types.hpp"
#include "simd.hpp"
#include "message.hpp"
#include "utility.hpp"
@ -35,9 +36,10 @@ class ChannelStatsCollector {
public:
template<typename Callback>
void feed(const buffer_c16_t& src, Callback callback) {
auto src_p = src.p;
while(src_p < &src.p[src.count]) {
const uint32_t sample = *__SIMD32(src_p)++;
auto src_p = simd32_ptr(src.p);
const auto end_p = simd32_ptr(&src.p[src.count]);
while(src_p < end_p) {
const uint32_t sample = *(src_p++);
const uint32_t mag_sq = __SMUAD(sample, sample);
if( mag_sq > max_squared ) {
max_squared = mag_sq;

View File

@ -21,6 +21,8 @@
#include "dsp_decimate.hpp"
#include "simd.hpp"
#include <hal.h>
namespace dsp {
@ -566,39 +568,39 @@ buffer_c16_t DecimateBy2CIC3::execute(
uint32_t t1 = _iq0;
uint32_t t2 = _iq1;
const uint32_t taps = 0x00000003;
auto s = src.p;
auto d = dst.p;
const auto d_end = &dst.p[src.count / 2];
auto s = simd32_ptr(&src.p[0]);
auto d = simd32_ptr(&dst.p[0]);
const auto d_end = simd32_ptr(&dst.p[src.count / 2]);
while(d < d_end) {
uint32_t i = __SXTH(t1, 0); /* 1: I0 */
uint32_t q = __SXTH(t1, 16); /* 1: Q0 */
i = __SMLABB(t2, taps, i); /* 1: I1*3 + I0 */
q = __SMLATB(t2, taps, q); /* 1: Q1*3 + Q0 */
const uint32_t t3 = *__SIMD32(s)++; /* 3: Q2:I2 */
const uint32_t t4 = *__SIMD32(s)++; /* Q3:I3 */
const uint32_t t3 = *(s++); /* 3: Q2:I2 */
const uint32_t t4 = *(s++); /* Q3:I3 */
i = __SMLABB(t3, taps, i); /* 1: I2*3 + I1*3 + I0 */
q = __SMLATB(t3, taps, q); /* 1: Q2*3 + Q1*3 + Q0 */
int32_t si0 = __SXTAH(i, t4, 0); /* 1: I3 + Q2*3 + Q1*3 + Q0 */
int32_t sq0 = __SXTAH(q, t4, 16); /* 1: Q3 + Q2*3 + Q1*3 + Q0 */
i = __BFI(si0 / 8, sq0 / 8, 16, 16); /* 1: D2_Q0:D2_I0 */
*__SIMD32(d)++ = i; /* D2_Q0:D2_I0 */
*(d++) = i; /* D2_Q0:D2_I0 */
i = __SXTH(t3, 0); /* 1: I2 */
q = __SXTH(t3, 16); /* 1: Q2 */
i = __SMLABB(t4, taps, i); /* 1: I3*3 + I2 */
q = __SMLATB(t4, taps, q); /* 1: Q3*3 + Q2 */
t1 = *__SIMD32(s)++; /* 3: Q4:I4 */
t2 = *__SIMD32(s)++; /* Q5:I5 */
t1 = *(s++); /* 3: Q4:I4 */
t2 = *(s++); /* Q5:I5 */
i = __SMLABB(t1, taps, i); /* 1: I4*3 + I3*3 + I2 */
q = __SMLATB(t1, taps, q); /* 1: Q4*3 + Q3*3 + Q2 */
int32_t si1 = __SXTAH(i, t2, 0) ; /* 1: I5 + Q4*3 + Q3*3 + Q2 */
int32_t sq1 = __SXTAH(q, t2, 16); /* 1: Q5 + Q4*3 + Q3*3 + Q2 */
i = __BFI(si1 / 8, sq1 / 8, 16, 16); /* 1: D2_Q1:D2_I1 */
*__SIMD32(d)++ = i; /* D2_Q1:D2_I1 */
*(d++) = i; /* D2_Q1:D2_I1 */
}
_iq0 = t1;
_iq1 = t2;
@ -665,57 +667,57 @@ buffer_c16_t FIRAndDecimateComplex::execute(
const auto output_sampling_rate = src.sampling_rate / decimation_factor_;
const size_t output_samples = src.count / decimation_factor_;
sample_t* dst_p = dst.p;
auto dst_p = simd32_ptr(dst.p);
const buffer_c16_t result { dst.p, output_samples, output_sampling_rate };
const sample_t* src_p = src.p;
auto src_p = simd32_ptr(src.p);
size_t outer_count = output_samples;
while(outer_count > 0) {
/* Put new samples into delay buffer */
auto z_new_p = &samples_[taps_count_ - decimation_factor_];
auto z_new_p = simd32_ptr(&samples_[taps_count_ - decimation_factor_]);
for(size_t i=0; i<decimation_factor_; i++) {
*__SIMD32(z_new_p)++ = *__SIMD32(src_p)++;
*(z_new_p++) = *(src_p++);
}
size_t loop_count = taps_count_ / 8;
auto t_p = &taps_reversed_[0];
auto z_p = &samples_[0];
auto t_p = simd32_ptr(&taps_reversed_[0]);
auto z_p = simd32_ptr(&samples_[0]);
int64_t t_real = 0;
int64_t t_imag = 0;
while(loop_count > 0) {
const auto tap0 = *__SIMD32(t_p)++;
const auto sample0 = *__SIMD32(z_p)++;
const auto tap1 = *__SIMD32(t_p)++;
const auto sample1 = *__SIMD32(z_p)++;
const auto tap0 = *(t_p++);
const auto sample0 = *(z_p++);
const auto tap1 = *(t_p++);
const auto sample1 = *(z_p++);
t_real = __SMLSLD(sample0, tap0, t_real);
t_imag = __SMLALDX(sample0, tap0, t_imag);
t_real = __SMLSLD(sample1, tap1, t_real);
t_imag = __SMLALDX(sample1, tap1, t_imag);
const auto tap2 = *__SIMD32(t_p)++;
const auto sample2 = *__SIMD32(z_p)++;
const auto tap3 = *__SIMD32(t_p)++;
const auto sample3 = *__SIMD32(z_p)++;
const auto tap2 = *(t_p++);
const auto sample2 = *(z_p++);
const auto tap3 = *(t_p++);
const auto sample3 = *(z_p++);
t_real = __SMLSLD(sample2, tap2, t_real);
t_imag = __SMLALDX(sample2, tap2, t_imag);
t_real = __SMLSLD(sample3, tap3, t_real);
t_imag = __SMLALDX(sample3, tap3, t_imag);
const auto tap4 = *__SIMD32(t_p)++;
const auto sample4 = *__SIMD32(z_p)++;
const auto tap5 = *__SIMD32(t_p)++;
const auto sample5 = *__SIMD32(z_p)++;
const auto tap4 = *(t_p++);
const auto sample4 = *(z_p++);
const auto tap5 = *(t_p++);
const auto sample5 = *(z_p++);
t_real = __SMLSLD(sample4, tap4, t_real);
t_imag = __SMLALDX(sample4, tap4, t_imag);
t_real = __SMLSLD(sample5, tap5, t_real);
t_imag = __SMLALDX(sample5, tap5, t_imag);
const auto tap6 = *__SIMD32(t_p)++;
const auto sample6 = *__SIMD32(z_p)++;
const auto tap7 = *__SIMD32(t_p)++;
const auto sample7 = *__SIMD32(z_p)++;
const auto tap6 = *(t_p++);
const auto sample6 = *(z_p++);
const auto tap7 = *(t_p++);
const auto sample7 = *(z_p++);
t_real = __SMLSLD(sample6, tap6, t_real);
t_imag = __SMLALDX(sample6, tap6, t_imag);
t_real = __SMLSLD(sample7, tap7, t_real);
@ -731,7 +733,7 @@ buffer_c16_t FIRAndDecimateComplex::execute(
const int32_t i = t_imag >> 16;
const int32_t r_sat = __SSAT(r, 16);
const int32_t i_sat = __SSAT(i, 16);
*__SIMD32(dst_p)++ = __PKHBT(
*(dst_p++) = __PKHBT(
r_sat,
i_sat,
16
@ -741,14 +743,14 @@ buffer_c16_t FIRAndDecimateComplex::execute(
const size_t unroll_factor = 4;
size_t shift_count = (taps_count_ - decimation_factor_) / unroll_factor;
sample_t* t = &samples_[0];
const sample_t* s = &samples_[decimation_factor_];
auto t = simd32_ptr(&samples_[0]);
auto s = simd32_ptr(&samples_[decimation_factor_]);
while(shift_count > 0) {
*__SIMD32(t)++ = *__SIMD32(s)++;
*__SIMD32(t)++ = *__SIMD32(s)++;
*__SIMD32(t)++ = *__SIMD32(s)++;
*__SIMD32(t)++ = *__SIMD32(s)++;
*(t++) = *(s++);
*(t++) = *(s++);
*(t++) = *(s++);
*(t++) = *(s++);
shift_count--;
}

View File

@ -24,6 +24,7 @@
#include "complex.hpp"
#include "fxpt_atan2.hpp"
#include "utility_m4.hpp"
#include "simd.hpp"
#include <hal.h>
@ -34,12 +35,12 @@ buffer_f32_t AM::execute(
const buffer_c16_t& src,
const buffer_f32_t& dst
) {
const auto src_p = src.p;
const auto src_end = &src.p[src.count];
auto src_p = simd32_ptr(src.p);
auto src_end = simd32_ptr(&src.p[src.count]);
auto dst_p = dst.p;
while(src_p < src_end) {
const uint32_t sample0 = *__SIMD32(src_p)++;
const uint32_t sample1 = *__SIMD32(src_p)++;
const uint32_t sample0 = *(src_p++);
const uint32_t sample1 = *(src_p++);
const uint32_t mag_sq0 = __SMUAD(sample0, sample0);
const uint32_t mag_sq1 = __SMUAD(sample1, sample1);
*(dst_p++) = __builtin_sqrtf(mag_sq0) * k;
@ -90,12 +91,12 @@ buffer_f32_t FM::execute(
) {
auto z = z_;
const auto src_p = src.p;
const auto src_end = &src.p[src.count];
auto src_p = simd32_ptr(src.p);
auto src_end = simd32_ptr(&src.p[src.count]);
auto dst_p = dst.p;
while(src_p < src_end) {
const auto s0 = *__SIMD32(src_p)++;
const auto s1 = *__SIMD32(src_p)++;
const auto s0 = *(src_p++);
const auto s1 = *(src_p++);
const auto t0 = multiply_conjugate_s16_s32(s0, z);
const auto t1 = multiply_conjugate_s16_s32(s1, s0);
z = s1;
@ -113,12 +114,12 @@ buffer_s16_t FM::execute(
) {
auto z = z_;
const auto src_p = src.p;
const auto src_end = &src.p[src.count];
auto src_p = simd32_ptr(src.p);
auto src_end = simd32_ptr(&src.p[src.count]);
auto dst_p = dst.p;
while(src_p < src_end) {
const auto s0 = *__SIMD32(src_p)++;
const auto s1 = *__SIMD32(src_p)++;
const auto s0 = *(src_p++);
const auto s1 = *(src_p++);
const auto t0 = multiply_conjugate_s16_s32(s0, z);
const auto t1 = multiply_conjugate_s16_s32(s1, s0);
z = s1;
@ -126,7 +127,7 @@ buffer_s16_t FM::execute(
const int32_t theta0_sat = __SSAT(theta0_int, 16);
const int32_t theta1_int = angle_approx_0deg27(t1) * ks16;
const int32_t theta1_sat = __SSAT(theta1_int, 16);
*__SIMD32(dst_p)++ = __PKHBT(
*(dst_p++) = __PKHBT(
theta0_sat,
theta1_sat,
16

View File

@ -125,12 +125,6 @@ typedef enum IRQn {
#ifdef __cplusplus
/* NOTE: Override old, misbehaving SIMD #defines */
#define __SIMD32_TYPE int32_t
#define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr))
#define _SIMD32_OFFSET(addr) (*(__SIMD32_TYPE *) (addr))
/* Overload of __SXTB16() to add ROR argument, since using __ROR() as an
* argument to the existing __SXTB16() doesn't produce optimum/sane code.
*/

Binary file not shown.

Binary file not shown.

43
host/bin/switch_to_hackrf Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
printf "Hold down the HackRF's DFU button (the button closest to the antenna jack)\n"
printf "then plug the HackRF into a USB port on your computer.\n\n"
printf "After the HackRF is plugged in, you may release the DFU button.\n"
printf "Press any key to continue or ^c to abort\n"
read
for i in /usr/share/hackrf/hackrf_one_usb.dfu /usr/share/hackrf/hackrf_one_usb_ram.dfu hackrf_one_usb.dfu; do
if [ -r "${i}" ]; then
ram_firmware="${i}"
break
fi
done
if [ -n "${ram_firmware}" ]; then
printf "\nFound firmware: ${ram_firmware}\n"
printf "Flashing...\n"
else
printf "Unable to find firmware to flash, please have hackrf_one_usb.dfu\n"
printf "in current directory or /usr/share/hackrf/\n"
exit 1
fi
for i in /usr/share/hackrf/hackrf_one_usb.bin /usr/share/hackrf/hackrf_one_usb_rom_to_ram.bin hackrf_one_usb.bin; do
if [ -r "${i}" ]; then
rom_firmware="${i}"
break
fi
done
if [ -n "${rom_firmware}" ]; then
printf "\nFound firmware: ${rom_firmware}\n"
printf "Flashing...\n"
else
printf "Unable to find firmware to flash, please have hackrf_one_usb.bin\n"
printf "in current directory or /usr/share/hackrf/\n"
exit 1
fi
dfu-util --device 1fc9:000c --download "${ram_firmware}" --reset
sleep 2s
hackrf_spiflash -w "${rom_firmware}"

43
host/bin/switch_to_portapack Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
printf "Hold down the HackRF's DFU button (the button closest to the antenna jack)\n"
printf "then plug the HackRF into a USB port on your computer.\n\n"
printf "After the HackRF is plugged in, you may release the DFU button.\n"
printf "Press any key to continue or ^c to abort\n"
read
for i in /usr/share/hackrf/hackrf_one_usb.dfu /usr/share/hackrf/hackrf_one_usb_ram.dfu hackrf_one_usb.dfu; do
if [ -r "${i}" ]; then
ram_firmware="${i}"
break
fi
done
if [ -n "${ram_firmware}" ]; then
printf "\nFound firmware: ${ram_firmware}\n"
printf "Flashing...\n"
else
printf "Unable to find firmware to flash, please have hackrf_one_usb.dfu\n"
printf "in current directory or /usr/share/hackrf/\n"
exit 1
fi
for i in /usr/share/hackrf/portapack-h1-firmware.bin portapack-h1-firmware.bin; do
if [ -r "${i}" ]; then
rom_firmware="${i}"
break
fi
done
if [ -n "${rom_firmware}" ]; then
printf "\nFound firmware: ${rom_firmware}\n"
printf "Flashing...\n"
else
printf "Unable to find firmware to flash, please have portapack-h1-firmware.bin\n"
printf "in current directory or /usr/share/hackrf/\n"
exit 1
fi
dfu-util --device 1fc9:000c --download "${ram_firmware}" --reset
sleep 2s
hackrf_spiflash -w "${rom_firmware}"