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);
}
}
}
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));
}
+/**
+ * @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"
#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;
static mailbox_t m_mailbox;
};
-// Stores the measured execution time.
-extern time_measurement_t conversion_time_measurement;
-
#endif // STMDSP_CONVERSION_HPP
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;
}
- return loaded ? reinterpret_cast<ELFManager::EntryFunc>(ehdr->e_entry) : nullptr;
+ if (loaded)
+ m_entry = reinterpret_cast<ELFManager::EntryFunc>(ehdr->e_entry);
+
+ return loaded;
}
public:
using EntryFunc = Sample *(*)(Sample *, size_t);
- static EntryFunc loadFromInternalBuffer();
+ static bool loadFromInternalBuffer();
static EntryFunc loadedElf();
static unsigned char *fileBuffer();
static void unload();
extern "C" {
+time_measurement_t conversion_time_measurement;
+
__attribute__((naked))
void port_syscall(struct port_extctx *ctxp, uint32_t n)
{