-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFirewirePort.h
154 lines (111 loc) · 5.17 KB
/
FirewirePort.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Zihan Chen, Peter Kazanzides
(C) Copyright 2011-2019 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
#ifndef __FirewirePort_H__
#define __FirewirePort_H__
#include <vector>
#include <ostream>
#include "BoardIO.h"
#include "BasePort.h"
// Forward declarations
struct raw1394_handle;
typedef struct raw1394_handle *raw1394handle_t;
typedef int (*bus_reset_handler_t)(raw1394handle_t, unsigned int generation);
// Maximum Firewire packet size in bytes (at 400 Mbits/sec)
const unsigned int FW_MAX_PACKET_SIZE = 2048;
// We subtract 24 bytes for the Block Write or Block Read Response header and CRC.
// The Firewire specification will actually allow the full 2048 bytes for the data,
// but this would require a firmware update.
const unsigned int FW_MAX_DATA_SIZE = FW_MAX_PACKET_SIZE-24;
class FirewirePort : public BasePort {
public:
protected:
raw1394handle_t handle; // normal read/write handle
nodeid_t baseNodeId;
// List of all ports instantiated (for use by reset_handler)
typedef std::vector<FirewirePort *> PortListType;
static PortListType PortList;
bus_reset_handler_t old_reset_handler;
// callback for 1394 bus reset event
static int reset_handler(raw1394handle_t hdl, unsigned int gen);
//! Read quadlet from node (internal method called by ReadQuadlet).
// Parameter "flags" is not used for Firewire.
bool ReadQuadletNode(nodeid_t node, nodeaddr_t addr, quadlet_t &data, unsigned char flags = 0);
//! Write quadlet to node (internal method called by WriteQuadlet)
// Parameter "flags" is not used for Firewire.
bool WriteQuadletNode(nodeid_t node, nodeaddr_t addr, quadlet_t data, unsigned char flags = 0);
// Method called by ReadAllBoards/ReadAllBoardsBroadcast if no data read
void OnNoneRead(void);
// Method called by WriteAllBoards/WriteAllBoardsBroadcast if no data written
void OnNoneWritten(void);
// Poll for IEEE 1394 events, such as bus reset.
void PollEvents(void);
// Initialize Firewire port
bool Init(void);
// Cleanup Firewire port
void Cleanup(void);
// Initialize nodes on the bus; called by ScanNodes
// \return Maximum number of nodes on bus (0 if error)
nodeid_t InitNodes(void);
// Write the broadcast packet containing the DAC values and power control
bool WriteBroadcastOutput(quadlet_t *buffer, unsigned int size);
// Write a block to the specified node. Internal method called by WriteBlock and
// WriteAllBoardsBroadcast.
// Parameter "flags" is not used for Firewire.
bool WriteBlockNode(nodeid_t node, nodeaddr_t addr, quadlet_t *wdata,
unsigned int nbytes, unsigned char flags = 0);
// Read a block from the specified node. Internal method called by ReadBlock.
// Parameter "flags" is not used for Firewire.
bool ReadBlockNode(nodeid_t node, nodeaddr_t addr, quadlet_t *rdata,
unsigned int nbytes, unsigned char flags = 0);
public:
// Initialize IEEE-1394 (Firewire) port.
FirewirePort(int portNum, std::ostream &debugStream = std::cerr);
~FirewirePort();
//****************** BasePort pure virtual methods ***********************
PortType GetPortType(void) const { return PORT_FIREWIRE; }
// Call lsof to count the number of users, assumes /dev/fw<port-number>
int NumberOfUsers(void);
bool IsOK(void) { return (handle != NULL); }
unsigned int GetBusGeneration(void) const;
void UpdateBusGeneration(unsigned int gen);
unsigned int GetPrefixOffset(MsgType) const { return 0; }
unsigned int GetWritePostfixSize(void) const { return 0; }
unsigned int GetReadPrefixSize(void) const { return 0; }
unsigned int GetReadPostfixSize(void) const { return 0; }
unsigned int GetWriteQuadAlign(void) const { return 0; }
unsigned int GetReadQuadAlign(void) const { return 0; }
// Get the maximum number of data bytes that can be read
// (via ReadBlock) or written (via WriteBlock).
unsigned int GetMaxReadDataSize(void) const { return FW_MAX_DATA_SIZE; }
unsigned int GetMaxWriteDataSize(void) const { return FW_MAX_DATA_SIZE; }
// Adds board(s)
bool AddBoard(BoardIO *board);
// Removes board
bool RemoveBoard(unsigned char boardId);
/*!
\brief Write the broadcast read request
*/
bool WriteBroadcastReadRequest(unsigned int seq);
/*!
\brief Wait for broadcast read data to be available
*/
void WaitBroadcastRead(void);
/*!
\brief Add delay (if needed) for PROM I/O operations
The delay is 0 for FireWire.
*/
void PromDelay(void) const {}
//****************** FireWire specific methods ***********************
// Stop Cycle Start Packets
void StopCycleStartPacket(void);
};
#endif // __FirewirePort_H__