From b430a38ce5674b319ef9bf1c6e773c9eb33f1542 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 5 Oct 2021 13:58:27 -0400 Subject: [PATCH] algorithm load fix --- source/communication.cpp | 6 ++++-- source/conversion.cpp | 13 +++++++++++-- source/conversion.hpp | 3 --- source/elfload.cpp | 11 ++++++++--- source/elfload.hpp | 2 +- source/handlers.cpp | 2 ++ 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/source/communication.cpp b/source/communication.cpp index 3a264fb..ec02a42 100644 --- a/source/communication.cpp +++ b/source/communication.cpp @@ -142,8 +142,8 @@ void loadAlgorithm(unsigned char *cmd) unsigned int size = cmd[1] | (cmd[2] << 8); if (EM.assert(size < MAX_ELF_FILE_SIZE, Error::BadUserCodeSize)) { USBSerial::read(ELFManager::fileBuffer(), size); - auto entry = ELFManager::loadFromInternalBuffer(); - EM.assert(entry != nullptr, Error::BadUserCodeLoad); + auto success = ELFManager::loadFromInternalBuffer(); + EM.assert(success, Error::BadUserCodeLoad); } } } @@ -214,6 +214,8 @@ void readIdentifier(unsigned char *) void readExecTime(unsigned char *) { + // Stores the measured execution time. + extern time_measurement_t conversion_time_measurement; USBSerial::write(reinterpret_cast(&conversion_time_measurement.last), sizeof(rtcnt_t)); } diff --git a/source/conversion.cpp b/source/conversion.cpp index 95118f0..c9dc0c9 100644 --- a/source/conversion.cpp +++ b/source/conversion.cpp @@ -1,3 +1,14 @@ +/** + * @file conversion.cpp + * @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 . + */ + #include "conversion.hpp" #include "periph/adc.hpp" @@ -18,8 +29,6 @@ #define MSG_FOR_FIRST(msg) (msg & 1) #define MSG_FOR_MEASURE(msg) (msg > 2) -time_measurement_t conversion_time_measurement; - __attribute__((section(".convdata"))) thread_t *ConversionManager::m_thread_monitor = nullptr; thread_t *ConversionManager::m_thread_runner = nullptr; diff --git a/source/conversion.hpp b/source/conversion.hpp index 0a18f3b..6af4972 100644 --- a/source/conversion.hpp +++ b/source/conversion.hpp @@ -60,8 +60,5 @@ private: static mailbox_t m_mailbox; }; -// Stores the measured execution time. -extern time_measurement_t conversion_time_measurement; - #endif // STMDSP_CONVERSION_HPP diff --git a/source/elfload.cpp b/source/elfload.cpp index 2d75cb0..87461e4 100644 --- a/source/elfload.cpp +++ b/source/elfload.cpp @@ -43,14 +43,16 @@ constexpr static auto ptr_from_offset(void *base, uint32_t offset) return reinterpret_cast(reinterpret_cast(base) + offset); } -ELFManager::EntryFunc ELFManager::loadFromInternalBuffer() +bool ELFManager::loadFromInternalBuffer() { + m_entry = nullptr; + auto elf_data = m_file_buffer.data(); // Check the ELF's header signature auto ehdr = reinterpret_cast(elf_data); if (!std::equal(ehdr->e_ident, ehdr->e_ident + 4, elf_header)) - return nullptr; + return false; // Iterate through program header LOAD sections bool loaded = false; @@ -74,6 +76,9 @@ ELFManager::EntryFunc ELFManager::loadFromInternalBuffer() } - return loaded ? reinterpret_cast(ehdr->e_entry) : nullptr; + if (loaded) + m_entry = reinterpret_cast(ehdr->e_entry); + + return loaded; } diff --git a/source/elfload.hpp b/source/elfload.hpp index 84d49d3..10d95d7 100644 --- a/source/elfload.hpp +++ b/source/elfload.hpp @@ -24,7 +24,7 @@ class ELFManager public: using EntryFunc = Sample *(*)(Sample *, size_t); - static EntryFunc loadFromInternalBuffer(); + static bool loadFromInternalBuffer(); static EntryFunc loadedElf(); static unsigned char *fileBuffer(); static void unload(); diff --git a/source/handlers.cpp b/source/handlers.cpp index 4b0e3eb..07f6ed3 100644 --- a/source/handlers.cpp +++ b/source/handlers.cpp @@ -7,6 +7,8 @@ extern "C" { +time_measurement_t conversion_time_measurement; + __attribute__((naked)) void port_syscall(struct port_extctx *ctxp, uint32_t n) {