Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
bitstream
V5BitstreamDeviceDetector.cpp
Go to the documentation of this file.
1
6
#include <
bitstream/Bitstream.hpp
>
7
#include <
bitstream/V5BitstreamDeviceDetector.hpp
>
8
#include <
packetprocessor/V5RegisterAddress.hpp
>
9
#include <
exception/Exception.hpp
>
10
11
using namespace
bil;
12
13
14
V5BitstreamDeviceDetector::V5BitstreamDeviceDetector
()
15
{
16
reset
();
17
}
18
19
20
DeviceID::ID_t
V5BitstreamDeviceDetector::deviceID
()
const
21
{
22
return
m_id;
23
}
24
25
26
void
V5BitstreamDeviceDetector::reset
()
27
{
28
V5BitstreamSyntaxChecker::reset
();
29
m_id = 0;
30
}
31
32
33
void
V5BitstreamDeviceDetector::visit
(
const
Type1Packet
& type1Packet)
34
{
35
V5BitstreamSyntaxChecker::visit
(type1Packet);
36
checkDeviceID
(type1Packet);
37
}
38
39
40
void
V5BitstreamDeviceDetector::visit
(
const
Type2Packet
& type2Packet)
41
{
42
V5BitstreamSyntaxChecker::visit
(type2Packet);
43
checkDeviceID
(type2Packet);
44
}
45
46
47
void
V5BitstreamDeviceDetector::checkDeviceID
(
const
Type2Packet
& type2Packet)
48
{
49
// only writes to IDCODE register contain the device ID
50
if
(
PacketOpcode::REGISTER_WRITE
!= type2Packet.
opcode
())
return
;
51
if
(
V5RegisterAddress::IDCODE
!=
lastType1Address
())
return
;
52
if
(1 != type2Packet.
wordCount
())
return
;
53
54
// device ID found
55
const
DeviceID::ID_t
id
= *(type2Packet.
dataWords
());
56
// check for multiple contradicting device IDs
57
if
((0 != m_id) && (
id
!= m_id))
throw
Exception
();
58
// store device ID
59
m_id = id;
60
}
61
62
63
DeviceID::ID_t
bil::detectV5DeviceType
(
Bitstream
& bitstream)
64
{
65
V5BitstreamDeviceDetector
deviceDetector;
66
bitstream.
runVisitor
(deviceDetector);
67
return
deviceDetector.
deviceID
();
68
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1