Fix baseband thread init order bug for all procs. (#1293)

This commit is contained in:
Kyle Reed 2023-07-22 23:54:17 -07:00 committed by GitHub
parent 828eb67a52
commit 7bd370b5bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 226 additions and 174 deletions

View file

@ -46,24 +46,34 @@ Thread* BasebandThread::thread = nullptr;
BasebandThread::BasebandThread(
uint32_t sampling_rate,
BasebandProcessor* const baseband_processor,
const tprio_t priority,
baseband::Direction direction)
: baseband_processor{baseband_processor},
_direction{direction},
sampling_rate{sampling_rate} {
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
priority, ThreadBase::fn,
this);
baseband::Direction direction,
bool auto_start,
tprio_t priority)
: baseband_processor_{baseband_processor},
direction_{direction},
sampling_rate_{sampling_rate},
priority_{priority} {
if (auto_start) start();
}
BasebandThread::~BasebandThread() {
chThdTerminate(thread);
chThdWait(thread);
thread = nullptr;
if (thread) {
chThdTerminate(thread);
chThdWait(thread);
thread = nullptr;
}
}
void BasebandThread::start() {
if (!thread) {
thread = chThdCreateStatic(
baseband_thread_wa, sizeof(baseband_thread_wa),
priority_, ThreadBase::fn, this);
}
}
void BasebandThread::set_sampling_rate(uint32_t new_sampling_rate) {
sampling_rate = new_sampling_rate;
sampling_rate_ = new_sampling_rate;
}
void BasebandThread::run() {
@ -71,9 +81,7 @@ void BasebandThread::run() {
baseband::dma::init();
const auto baseband_buffer = std::make_unique<std::array<baseband::sample_t, 8192>>();
baseband::dma::configure(
baseband_buffer->data(),
direction());
baseband::dma::configure(baseband_buffer->data(), direction());
// baseband::dma::allocate(4, 2048);
baseband_sgpio.configure(direction());
@ -85,10 +93,10 @@ void BasebandThread::run() {
const auto buffer_tmp = baseband::dma::wait_for_buffer();
if (buffer_tmp) {
buffer_c8_t buffer{
buffer_tmp.p, buffer_tmp.count, sampling_rate};
buffer_tmp.p, buffer_tmp.count, sampling_rate_};
if (baseband_processor) {
baseband_processor->execute(buffer);
if (baseband_processor_) {
baseband_processor_->execute(buffer);
}
}
}