FreeNOS
BroadcomMailbox.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/System.h>
19#include "BroadcomMailbox.h"
20
24
26{
27 // Map Mailbox registers
28 if (m_io.map(IO_BASE + Base, PAGESIZE,
30 return IOError;
31
32 // Initialize registers
33 m_io.write(Config, 0);
34 return Success;
35}
36
38 Channel channel,
39 u32 *message) const
40{
41 // Busy wait until mailbox has data
42 while (m_io.read(Status) & Empty);
43
44 // Read message
45 for (;;)
46 {
47 if (((*message = m_io.read(Read)) & ChannelMask) == channel)
48 break;
49 }
50 *message &= ~(ChannelMask);
51 return Success;
52}
53
55 Channel channel,
56 u32 message)
57{
58 // Busy wait until mailbox becomes free
59 while (m_io.read(Status) & Full);
60
61 // Write message
62 m_io.write(Write, (message << 4) | channel);
63 return Success;
64}
void write(u32 reg, u32 data)
write to memory mapped I/O register
Definition ARMIO.h:46
u32 read(u32 reg) const
read from memory mapped I/O register
Definition ARMIO.h:62
ARMIO m_io
I/O object.
BroadcomMailbox()
Constructor.
static const uint ChannelMask
Channel Mask when reading or writing (lowest 4-bits).
Result write(Channel channel, u32 message)
Write 28-bit message.
Result read(Channel channel, u32 *message) const
Read 28-bit message.
Result
Result codes.
Result initialize()
Initialize the Mailbox.
static const Address Base
Register base offset for the Mailbox.
Unidirectional point-to-point messaging channel.
Definition Channel.h:35
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition IO.cpp:38
@ Success
Definition IO.h:44
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Device
Definition Memory.h:48
@ Writable
Definition Memory.h:42