-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_can_adapter.py
108 lines (88 loc) · 3.66 KB
/
test_can_adapter.py
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
import unittest
from edg import *
from .test_high_switch import CalSolCanConnectorRa
class CanAdapter(BoardTop):
def contents(self) -> None:
super().contents()
# USB Domain
self.usb = self.Block(UsbCReceptacle())
self.vusb = self.connect(self.usb.pwr)
self.gnd = self.connect(self.usb.gnd)
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.usb_reg, ), _ = self.chain(
self.usb.pwr,
imp.Block(LinearRegulator(3.3*Volt(tol=0.05)))
)
self.v3v3 = self.connect(self.usb_reg.pwr_out)
with self.implicit_connect(
ImplicitConnect(self.v3v3, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
# this uses the legacy / simple (non-mixin) USB and CAN IO style
(self.usb_esd, ), _ = self.chain(self.usb.usb, imp.Block(UsbEsdDiode()), self.mcu.usb.request())
(self.xcvr, ), self.can_chain = self.chain(self.mcu.can.request('can'), imp.Block(Iso1050dub()))
(self.sw_usb, ), _ = self.chain(imp.Block(DigitalSwitch()), self.mcu.gpio.request('sw_usb'))
(self.sw_can, ), _ = self.chain(imp.Block(DigitalSwitch()), self.mcu.gpio.request('sw_can'))
self.lcd = imp.Block(Qt096t_if09())
self.rgb_usb = imp.Block(IndicatorSinkRgbLed())
self.rgb_can = imp.Block(IndicatorSinkRgbLed())
self.connect(self.mcu.gpio.request('lcd_led'), self.lcd.led)
self.connect(self.mcu.gpio.request('lcd_reset'), self.lcd.reset)
self.connect(self.mcu.gpio.request('lcd_rs'), self.lcd.rs)
self.connect(self.mcu.spi.request('lcd_spi'), self.lcd.spi) # MISO unused
self.connect(self.mcu.gpio.request('lcd_cs'), self.lcd.cs)
self.connect(self.mcu.gpio.request_vector('rgb_usb'), self.rgb_usb.signals)
self.connect(self.mcu.gpio.request_vector('rgb_can'), self.rgb_can.signals)
# Isolated CAN Domain
self.can = self.Block(CalSolCanConnectorRa())
self.can_vcan = self.connect(self.can.pwr)
self.can_gnd = self.connect(self.can.gnd)
with self.implicit_connect(
ImplicitConnect(self.can_gnd, [Common]),
) as imp:
(self.can_reg, self.led_can), _ = self.chain(self.can_vcan,
imp.Block(LinearRegulator(5.0*Volt(tol=0.05))),
imp.Block(VoltageIndicatorLed()))
(self.can_esd, ), _ = self.chain(self.xcvr.can, imp.Block(CanEsdDiode()), self.can.differential)
self.can_v5v = self.connect(self.can_reg.pwr_out, self.xcvr.can_pwr)
self.connect(self.can_gnd, self.xcvr.can_gnd)
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(['mcu'], Lpc1549_48),
(['mcu', 'swd'], SwdCortexTargetTc2050),
(['mcu', 'swd', 'conn'], TagConnectNonLegged),
(['sw_usb', 'package'], SmtSwitchRa),
(['sw_can', 'package'], SmtSwitchRa),
(['usb_reg'], Ap2204k),
(['can_reg'], Ap2204k),
],
instance_values=[
(['mcu', 'pin_assigns'], [
'can.txd=8',
'can.rxd=12',
'sw_usb=28',
'sw_can=48',
'lcd_led=23',
'lcd_reset=13',
'lcd_rs=15',
'lcd_spi.sck=21',
'lcd_spi.mosi=18',
'lcd_spi.miso=NC',
'lcd_cs=22',
'rgb_usb_red=2',
'rgb_usb_green=1',
'rgb_usb_blue=3',
'rgb_can_red=6',
'rgb_can_green=4',
'rgb_can_blue=7',
]),
(['mcu', 'swd_swo_pin'], 'PIO0_8'),
]
)
class CanAdapterTestCase(unittest.TestCase):
def test_design(self) -> None:
compile_board_inplace(CanAdapter)