blob: 75d644e9cb1247a2ac45c5d103c0dc3b4ee1f845 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/**
* @file conversion.hpp
* @brief Manages algorithm application (converts input samples to output).
*
* Copyright (C) 2023 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:
/**
* Starts two threads: the privileged monitor thread and the unprivileged
* algorithm execution thread.
*/
static void begin();
// Begins sample conversion.
static void start();
// Prepare to measure execution time of next conversion.
static void startMeasurement();
// 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
|