algorithm load fix

master
Clyne 3 years ago
parent 555749ef5d
commit b430a38ce5

@ -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));
}

@ -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;

@ -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

@ -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;
}

@ -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();

@ -7,6 +7,8 @@
extern "C" {
time_measurement_t conversion_time_measurement;
__attribute__((naked))
void port_syscall(struct port_extctx *ctxp, uint32_t n)
{

Loading…
Cancel
Save