diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-04-30 08:41:56 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-04-30 08:42:45 -0400 |
commit | e164629b3839eee0fda0be0e0a9842e78cf02f2b (patch) | |
tree | b72b58665b85a104e5b953af45f00579341b2802 /source/conversion.hpp | |
parent | 162dd6de8a0d883962b0b1475f47cbb08e0958d4 (diff) | |
parent | 3dd57491b1e81a9d93054eff19ca0e6c65c85b9b (diff) |
merge in branch devel
Diffstat (limited to 'source/conversion.hpp')
-rw-r--r-- | source/conversion.hpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/source/conversion.hpp b/source/conversion.hpp new file mode 100644 index 0000000..a26dd19 --- /dev/null +++ b/source/conversion.hpp @@ -0,0 +1,64 @@ +/** + * @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(bool fpu_stacked = true); + +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; +}; + +#endif // STMDSP_CONVERSION_HPP + |