forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SSwitch.h
59 lines (48 loc) · 1.69 KB
/
SSwitch.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
// Copyright (c) 2011, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#ifndef _SSwitch_h_
#define _SSwitch_h_
#include "Token.h"
#include "ChanEndpoint.h"
#include "SSwitchCtrlRegs.h"
class Node;
class SSwitch : public ChanEndpoint {
private:
struct Request {
bool write;
uint16_t returnNode;
uint8_t returnNum;
uint32_t regNum;
uint32_t data;
};
Node *parent;
SSwitchCtrlRegs regs;
/// Length of a write request (excluding CT_END).
static const unsigned writeRequestLength = 1 + 3 + 2 + 4;
/// Length of a read request (excluding CT_END).
static const unsigned readRequestLength = 1 + 3 + 2;
/// Number of tokens in the buffer.
unsigned recievedTokens;
Token buf[writeRequestLength];
bool junkIncomingTokens;
/// Are we in the middle of sending a response?
bool sendingResponse;
unsigned sentTokens;
/// Length of response (including CT_END).
unsigned responseLength;
bool parseRequest(ticks_t time, Request &request) const;
void handleRequest(ticks_t time, const Request &request);
public:
SSwitch(Node *parent);
void initRegisters() { regs.initRegisters(); }
virtual void notifyDestClaimed(ticks_t time);
virtual void notifyDestCanAcceptTokens(ticks_t time, unsigned tokens);
virtual bool canAcceptToken();
virtual bool canAcceptTokens(unsigned tokens);
virtual void receiveDataToken(ticks_t time, uint8_t value);
virtual void receiveDataTokens(ticks_t time, uint8_t *values, unsigned num);
virtual void receiveCtrlToken(ticks_t time, uint8_t value);
};
#endif //_SSwitch_h_