4ms / metamodule

MetaModule virtual patch module firmware
Other
8 stars 0 forks source link

Redesign communication between components on different cores #177

Open LnnrtS opened 9 months ago

danngreen commented 3 months ago

Something like:

////////////
// A7 client:
// make request:
if (auto msg_id = proxy.request_read_file(buffer, offset, length)) {
    // request went through
} else {
    // communication bus is busy, try again later
}
...
// check for response, using our msg id:
if (auto msg = proxy.get_message(msg_id.value())) {
    if (msg.type == Proxy::Response::OK) 
        //OK, file was read into buffer
    else 
        //handle request failure (file not found, etc..)
}

////////////
// A7 proxy:
std::optional<uint32_t> Proxy::request_read_file(...){
    uint32_t uid = create_unique_id();

    if (comm.send_message({.uid = uid, .type = ReadFile, .buffer = buffer, ...}))
        return uid;
    else
        return std::nullopt;
}

std::optional<InterCoreMessage> Proxy::get_message(uint32_t uid) {
    if (auto msg = comm.get_message()) {
        if (msg.uid == uid) {
           // client request and response match
           return msg;
        } else {
            // message is a response to a different client request, store it for later
            rx_message_queue.push_back(msg);
        }
    }
    if (auto msg = rx_message_queue.find(uid)) {
       rx_message_queue.remove(uid);
       return msg;
    } else {
      // no matching response found yet
        return std::nullopt;
    }
}

////////////
// M4 handler:
if (message.type == ReadFile) {
    if (read_file(message.filename, message.buffer, message.offset))
        return Message{.uid = message.uid, .type = Response::OK, .bytes_read = ...};
    else 
        return Message{.uid = message.uid, .type = Response::Fail};
}
LnnrtS commented 3 months ago

Sounds good. I think the UID can just be a incremental - no need for anything fancy.

When reading the message I would first look in rx_message_queue.

danngreen commented 2 months ago

One thing of interest is that the IPCC hardware peripheral used for the inter-core communication, actually has 6 channels. We were just using 1 channel for all communication. I took advantage of this with the File System access implementation in the STS-coreproc-chanmap branch, and am using a new IPCC channel just for that (also using a std::variant).