Change IPC to exchange data, not pointers.

This commit is contained in:
Jared Boone 2015-08-20 13:13:12 -07:00
parent f99016d78f
commit 4126f1ab1f
7 changed files with 76 additions and 126 deletions

View file

@ -26,56 +26,26 @@
using namespace lpc43xx;
bool MessageQueue::push(Message* const message) {
/* Returns true if success:
* - Message not in use.
* - FIFO wasn't full.
*/
if( message->state == Message::State::Free ) {
message->state = Message::State::InUse;
if( enqueue(message) ) {
signal();
return true;
} else {
// Roll back message state.
message->state = Message::State::Free;
}
bool MessageQueue::push(const void* const buf, const size_t len) {
const auto result = fifo.in_r(buf, len);
const bool success = (result == len);
if( success ) {
signal();
}
return false;
return success;
}
Message* MessageQueue::pop() {
/* TODO: Because of architecture characteristics, the two LSBs of the
* message pointer will always be 0. Other (non-pointer) message types
* could be encoded by setting these two bits to non-zero values.
* One of the bits could also be used as an "ack" flag... In fact, a
* pointer message could be turned into an "ack" message, or something
* like that...
* Might be better though to use formal operating structures in the
* message to do synchronization between processors.
*/
Message* message { nullptr };
const auto success = fifo.out(&message, 1);
return success ? message : nullptr;
size_t MessageQueue::pop(void* const buf, const size_t len) {
return fifo.out_r(buf, len);
}
#if defined(LPC43XX_M0)
bool MessageQueue::enqueue(Message* const message) {
return fifo.in(&message, 1);
}
void MessageQueue::signal() {
creg::m0apptxevent::assert();
}
#endif
#if defined(LPC43XX_M4)
bool MessageQueue::enqueue(Message* const message) {
return fifo.in(&message, 1);
}
void MessageQueue::signal() {
creg::m4txevent::assert();
}