-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathflash_stub.spin2
More file actions
97 lines (84 loc) · 3.21 KB
/
flash_stub.spin2
File metadata and controls
97 lines (84 loc) · 3.21 KB
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
' *** SPI FLASH BOOT LOADER
' based on Chip Gracey's original flash loader,
' but simplified and made more independent for
' loadp2 purposes
'
CON spi_cs = 61
spi_ck = 60
spi_di = 59
spi_do = 58
DAT
'************
'* Loader *
'************
'
' The ROM booter reads this code from the 8-pin SPI flash from $000000..$0003FF, into cog
' registers $000..$0FF. If the booter verifies the 'Prop' checksum, it does a 'JMP #0' to
' execute this loader code.
'
' The initial application data trailing this code in registers app_start..$0FF are moved to
' hub RAM, starting at $00000. Then, any additional application data are read from the flash
' and stored into the hub, continuing from where the initial application data left off.
'
' On entry, both spi_cs and spi_ck are low outputs and the flash is outputting bit 7 of the
' byte at address $400 on spi_do. By cycling spi_ck, any additional application data can be
' received from spi_do.
'
' Once all application data is in the hub, an application checksum is verified, after which
' cog 0 is restarted by a 'COGINIT #0,#$00000' to execute the application. If that checksum
' fails, due to some data corruption, the SPI pins will be floated and the clock stopped
' until the next reset. As well, a checksum is verified upon initial download of all data,
' before programming the flash. This all ensures that no errant application code will boot.
'
org
'
'
' First, move application data in cog app_start..$0FF into hub $00000+
'
loader
x jmp #real_start ' re-used as temporary variable
propchksum long 0 ' magic value to make first 1K add to "Prop" (filled by loadp2)
app_longs long 0 ' number of longs (filled by loadp2)
real_start
'
'
' Read in remaining application longs
'
wrpin #%01_00101_0,#spi_ck 'set spi_ck smart pin for transitions, drives low
fltl #spi_ck 'reset smart pin
wxpin #1,#spi_ck 'set transition timebase to clk/1
drvl #spi_ck 'enable smart pin
setxfrq clk2 'set streamer rate to clk/2
wrfast #0,#0 'ready to write to hub at application start
.block bmask x,#10 'try max streamer block size for longs ($7FF)
fle x,app_longs 'limit to number of longs left
sub app_longs,x 'update number of longs left
shl x,#5 'get number of bits
setword wmode,x,#0 'insert into streamer command
shl x,#1 'double for number of spi_ck transitions
wypin x,#spi_ck '2 start spi_ck transitions
waitx #3 '2+3 align spi_ck transitions with spi_do sampling
xinit wmode,#0 '2 start inputting spi_do bits to hub, bytes-msb-first
waitxfi '? wait for streamer to finish
tjnz app_longs,#.block 'if more longs left, read another block
' shut down smart pins to leave them
' in known state for app
fltl #spi_do addpins 3 'float all pins
wrpin #0,#spi_ck 'clear spi_ck smart pin mode
{ FIXME DEBUG
drvl #56
waitx ##40_000_000
drvl #57
waitx ##40_000_000
drvh #56
waitx ##40_000_000
}
waitx ##2_000_000 'pause a bit
coginit #0,#$00000 'run application
'
'
' Data
'
clk2 long $4000_0000 'clk/2 nco value for streamer
wmode long $C081_0000 + spi_do<<17 'streamer mode, 1-pin input, bytes-msb-first, bytes to hub
fit $100 ' must fit in 1K