You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB
C++

/**
* @file conversion.hpp
* @brief Manages algorithm application (converts input samples to output).
*
* Copyright (C) 2021 Clyne Sullivan
*
* Distributed under the GNU GPL v3 or later. You should have received a copy of
* the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef STMDSP_CONVERSION_HPP
#define STMDSP_CONVERSION_HPP
#include "ch.h"
#include "hal.h"
#include <array>
constexpr unsigned int CONVERSION_THREAD_STACK_SIZE =
#if defined(TARGET_PLATFORM_H7)
62 * 1024;
#else
15 * 1024;
#endif
class ConversionManager
{
public:
static void begin();
// Begins sample conversion.
static void start();
// Begins conversion with execution time measured.
static void startMeasured();
// Stops conversion.
static void stop();
static thread_t *getMonitorHandle();
// Internal only: Aborts a running conversion.
static void abort();
private:
static void threadMonitor(void *);
static void threadRunnerEntry(void *stack);
static void threadRunner(void *);
static void adcReadHandler(adcsample_t *buffer, size_t);
static void adcReadHandlerMeasure(adcsample_t *buffer, size_t);
static thread_t *m_thread_monitor;
static thread_t *m_thread_runner;
static std::array<char, 1024> m_thread_monitor_stack;
static std::array<char, THD_WORKING_AREA_SIZE(128)> m_thread_runner_entry_stack;
static std::array<char, CONVERSION_THREAD_STACK_SIZE> m_thread_runner_stack;
static std::array<msg_t, 2> m_mailbox_buffer;
static mailbox_t m_mailbox;
};
// Stores the measured execution time.
extern time_measurement_t conversion_time_measurement;
#endif // STMDSP_CONVERSION_HPP