forked from Neirth/FreeNOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented intercore message passing using MemoryChannel (libipc).
- Loading branch information
1 parent
01f25c9
commit d421cad
Showing
19 changed files
with
542 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Channel.h" | ||
|
||
Channel::Channel() | ||
{ | ||
m_mode = Consumer; | ||
m_messageSize = 0; | ||
m_maximumMessages = 0; | ||
} | ||
|
||
Size Channel::getMaximumMessages() | ||
{ | ||
return m_maximumMessages; | ||
} | ||
|
||
Channel::Result Channel::setMode(Channel::Mode mode) | ||
{ | ||
m_mode = mode; | ||
return Success; | ||
} | ||
|
||
Channel::Result Channel::setMessageSize(Size size) | ||
{ | ||
m_messageSize = size; | ||
return Success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <FreeNOS/System.h> | ||
#include "MemoryChannel.h" | ||
|
||
MemoryChannel::MemoryChannel() | ||
: Channel() | ||
{ | ||
MemoryBlock::set(&m_head, 0, sizeof(m_head)); | ||
} | ||
|
||
MemoryChannel::Result MemoryChannel::setData(Address addr) | ||
{ | ||
if (m_messageSize < sizeof(RingHead) || m_messageSize > (PAGESIZE / 2)) | ||
return InvalidArgument; | ||
|
||
if (m_data.map(addr, PAGESIZE) != IO::Success) | ||
return IOError; | ||
|
||
m_maximumMessages = (PAGESIZE / m_messageSize) - 1; | ||
|
||
if (m_mode == Producer) | ||
m_data.write(0, sizeof(m_head), &m_head); | ||
return Success; | ||
} | ||
|
||
MemoryChannel::Result MemoryChannel::setFeedback(Address addr) | ||
{ | ||
if (m_feedback.map(addr, PAGESIZE) != IO::Success) | ||
return IOError; | ||
|
||
if (m_mode == Consumer) | ||
m_feedback.write(0, sizeof(m_head), &m_head); | ||
return Success; | ||
} | ||
|
||
MemoryChannel::Result MemoryChannel::read(void *buffer) | ||
{ | ||
RingHead head; | ||
|
||
// busy wait until a message comes in | ||
while (true) | ||
{ | ||
m_data.read(0, sizeof(head), &head); | ||
|
||
if (head.index != m_head.index) | ||
break; | ||
} | ||
// Read one message | ||
m_data.read((m_head.index+1) * m_messageSize, m_messageSize, buffer); | ||
|
||
// Increment head index | ||
m_head.index = (m_head.index + 1) % m_maximumMessages; | ||
|
||
// Update read index | ||
m_feedback.write(0, sizeof(m_head), &m_head); | ||
return Success; | ||
} | ||
|
||
MemoryChannel::Result MemoryChannel::write(void *buffer) | ||
{ | ||
RingHead reader; | ||
|
||
// Check for buffer space | ||
m_feedback.read(0, sizeof(RingHead), &reader); | ||
|
||
if (((m_head.index + 1) % m_maximumMessages) == reader.index) | ||
return ChannelFull; | ||
|
||
// write the message | ||
m_data.write((m_head.index+1) * m_messageSize, m_messageSize, buffer); | ||
|
||
// Increment write index | ||
m_head.index = (m_head.index + 1) % m_maximumMessages; | ||
m_data.write(0, sizeof(m_head), &m_head); | ||
return Success; | ||
} |
Oops, something went wrong.