FreeNOS
lib
libarch
arm
broadcom
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
21
BroadcomMailbox::BroadcomMailbox
()
22
{
23
}
24
25
BroadcomMailbox::Result
BroadcomMailbox::initialize
()
26
{
27
// Map Mailbox registers
28
if
(
m_io
.
map
(IO_BASE +
Base
,
PAGESIZE
,
29
Memory::User
|
Memory::Readable
|
Memory::Writable
|
Memory::Device
) !=
IO::Success
)
30
return
IOError
;
31
32
// Initialize registers
33
m_io
.
write
(
Config
, 0);
34
return
Success
;
35
}
36
37
BroadcomMailbox::Result
BroadcomMailbox::read
(
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
54
BroadcomMailbox::Result
BroadcomMailbox::write
(
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
}
Channel
Unidirectional point-to-point messaging channel.
Definition:
Channel.h:34
BroadcomMailbox::IOError
@ IOError
Definition:
BroadcomMailbox.h:85
BroadcomMailbox::Empty
@ Empty
Definition:
BroadcomMailbox.h:74
BroadcomMailbox::Config
@ Config
Definition:
BroadcomMailbox.h:64
Memory::Writable
@ Writable
Definition:
Memory.h:42
BroadcomMailbox::Write
@ Write
Definition:
BroadcomMailbox.h:65
IO::map
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
Memory::User
@ User
Definition:
Memory.h:44
ARMIO::write
void write(u32 reg, u32 data)
write to memory mapped I/O register
Definition:
ARMIO.h:46
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition:
ARMConstant.h:97
Memory::Device
@ Device
Definition:
Memory.h:48
BroadcomMailbox::Success
@ Success
Definition:
BroadcomMailbox.h:84
Memory::Readable
@ Readable
Definition:
Memory.h:41
BroadcomMailbox::Full
@ Full
Definition:
BroadcomMailbox.h:73
BroadcomMailbox::BroadcomMailbox
BroadcomMailbox()
Constructor.
Definition:
BroadcomMailbox.cpp:21
BroadcomMailbox::Result
Result
Result codes.
Definition:
BroadcomMailbox.h:82
u32
unsigned int u32
Unsigned 32-bit number.
Definition:
Types.h:53
ARMIO::read
u32 read(u32 reg) const
read from memory mapped I/O register
Definition:
ARMIO.h:62
BroadcomMailbox.h
IO::Success
@ Success
Definition:
IO.h:44
BroadcomMailbox::read
Result read(Channel channel, u32 *message) const
Read 28-bit message.
Definition:
BroadcomMailbox.cpp:37
BroadcomMailbox::ChannelMask
static const uint ChannelMask
Channel Mask when reading or writing (lowest 4-bits).
Definition:
BroadcomMailbox.h:55
BroadcomMailbox::m_io
ARMIO m_io
I/O object.
Definition:
BroadcomMailbox.h:141
BroadcomMailbox::Status
@ Status
Definition:
BroadcomMailbox.h:63
BroadcomMailbox::write
Result write(Channel channel, u32 message)
Write 28-bit message.
Definition:
BroadcomMailbox.cpp:54
BroadcomMailbox::Base
static const Address Base
Register base offset for the Mailbox.
Definition:
BroadcomMailbox.h:52
BroadcomMailbox::Read
@ Read
Definition:
BroadcomMailbox.h:62
BroadcomMailbox::initialize
Result initialize()
Initialize the Mailbox.
Definition:
BroadcomMailbox.cpp:25
Generated by
1.8.17