]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
algorithm load fix
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 5 Oct 2021 17:58:27 +0000 (13:58 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 5 Oct 2021 17:58:27 +0000 (13:58 -0400)
source/communication.cpp
source/conversion.cpp
source/conversion.hpp
source/elfload.cpp
source/elfload.hpp
source/handlers.cpp

index 3a264fb90084f0e29865d58ff53078b6ef0fcfde..ec02a42be2e7e6eacecd5e96a690635b729342c3 100644 (file)
@@ -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<uint8_t *>(&conversion_time_measurement.last),
                      sizeof(rtcnt_t));
 }
index 95118f0b3b0164ce03aa804516798c93a0c186bf..c9dc0c950e40125defd8138fc05e4e9f9db3f7f3 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #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;
index 0a18f3b69d2d027ac9aea11572854533fb91bd6c..6af4972177bc82900fcc12830c7dbb8d90de01e4 100644 (file)
@@ -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
 
index 2d75cb0e7e0ed0350661c485360ffa4d2815f381..87461e4b917e44a465372fccb20deee5d6d84538 100644 (file)
@@ -43,14 +43,16 @@ constexpr static auto ptr_from_offset(void *base, uint32_t offset)
     return reinterpret_cast<T>(reinterpret_cast<uint8_t *>(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<Elf32_Ehdr *>(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<ELFManager::EntryFunc>(ehdr->e_entry) : nullptr;
+    if (loaded)
+        m_entry = reinterpret_cast<ELFManager::EntryFunc>(ehdr->e_entry);
+
+    return loaded;
 }
 
index 84d49d3e3c2ef194dc196ec6b79666ba3fce3ee1..10d95d7831cae397861d0ee42c7e8f433df7f8d7 100644 (file)
@@ -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();
index 4b0e3eb032a3ee39826ad762fa2504c112a428d1..07f6ed39c035632a4412986c4023233f8e99e8e8 100644 (file)
@@ -7,6 +7,8 @@
 
 extern "C" {
 
+time_measurement_t conversion_time_measurement;
+
 __attribute__((naked))
 void port_syscall(struct port_extctx *ctxp, uint32_t n)
 {