-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsfr_test.py
executable file
·89 lines (76 loc) · 2.38 KB
/
lsfr_test.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
#!/usr/bin/python
# the instruction set
# TODO port to allocator IR
from re import I
from boneless.arch.opcode import Instr
from boneless.arch.opcode import *
# the firmare constructs
from spork.firmware.base import *
from spork.firmware.firmware import Firmware
# the library code
from spork.lib.uartIO import UART
from spork.logger import logger
log = logger(__name__)
class Small(Firmware):
def setup(self):
self.w.req(["temp", "counter", "address", "value", "other", "status"])
# Code objects need to return a list of ASM instructions to do stuff.
def instr(self):
w = self.w
reg = self.reg
ll = LocalLabels()
self.stringer.second = "free running"
uart = UART()
return [
MOVI(w.counter, 0),
MOVI(w.other, 1),
STXA(w.other, reg.lsfr.mode),
# MOVI(w.other, 0x81A5),
# STXA(w.other, reg.lsfr.taps),
MOVI(w.value, 0xDEAD),
STXA(w.value, reg.lsfr.value),
# LDXA(w.temp, reg.lsfr.value),
# LDXA(w.temp, reg.lsfr.value),
# uart.readWait(),
ll("again"),
# [uart.writeHex(w.value), uart.cr(), uart.cr()],
LDXA(w.temp, reg.lsfr.value),
# uart.writeBin(w.temp),
# uart.cr(),
# uart.writeHex(w.counter),
# uart.sp(),
uart.writeHex(w.temp),
uart.sp(),
# uart.writeBin(w.temp),
# uart.cr(),
ADDI(w.counter, w.counter, 1),
# J(ll.again),
CMPI(w.counter, 32),
# CMP(w.value,w.temp),
BNE(ll.again),
uart.cr(),
MOVI(w.temp, 0),
STXA(w.temp, reg.lsfr.mode),
MOVI(w.counter, 0),
self.stringer.second(w.other),
uart.writestring(w.other),
uart.cr(),
uart.readWait(),
ll("second"),
LDXA(w.temp, reg.lsfr.value),
uart.writeHex(w.temp),
uart.sp(),
ADDI(w.counter, w.counter, 1),
CMPI(w.counter, 32),
BNE(ll.second),
uart.cr(),
uart.readWait(),
]
" load this "
firmware = Small
if __name__ == "__main__":
from spork.upload import Uploader
import fwtest
spork = fwtest.build(firmware, detail=False)
up = Uploader()
up.upload(spork)