-
Notifications
You must be signed in to change notification settings - Fork 0
/
TXTest.spin2
114 lines (88 loc) · 3.5 KB
/
TXTest.spin2
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
{
--------------------------------------------
Filename: TXTest.spin2
Author: Jesse Burt
Description: ZModem transmit from Propeller test
Send a file 'p2rom.bin' containing the
Propeller 2's ROM to the remote device
Copyright (c) 2022
Started Nov 28, 2021
Updated Nov 15, 2022
See end of file for terms of use.
--------------------------------------------
}
CON
_clkfreq = 180_000_000
_xtlfreq = 20_000_000
OBJ
com : "com.serial.terminal" ' remote device
ser : "com.serial.terminal.ansi" ' debug/terminal output
pub main | ptr_data, st_pos, frm_end, xfer, pos
ser.startrxtx(63, 62, 0, 2_000_000)
com.startrxtx(2, 4, 0, 115_200)
waitms(30)
ser.clear
_subpsz := 1024
bytemove(@_f_name, @"p2rom.bin", 9)
_f_sz := 16384
ptr_data := $FC000 ' P2 ROM start
st_pos := 0
ser.printf(@"Filename: %s\n\r", @_f_name)
ser.printf(@"Size : %u\n\r", _f_sz)
zmtx_hex_header(ZRQINIT, 0)
repeat until (zget_hdr() == ZRINIT)
ser.strln(@"got ZRINIT")
_txflags[ZF0] := 0
_txflags[ZF1] := 0
_txflags[ZF2] := 0
_txflags[ZF3] := 0
zmtx_bin_header(ZBIN32, ZFILE, @_txflags)
zmtx_file_info()
repeat until (zget_hdr() == ZRPOS)
ser.strln(@"got ZRPOS")
zmtx_bin_header(ZBIN32, ZDATA, @st_pos) ' start position
xfer := 0
repeat pos from st_pos to (_f_sz-1) step _subpsz
if (pos < (_f_sz-_subpsz)) ' before last subpacket?
frm_end := ZCRCQ ' Q: ACK, G: no ACK
else
frm_end := ZCRCE ' frame ends
xfer += zmtx_data_subpkt(ptr_data, pos, _subpsz, frm_end)
if (frm_end == ZCRCQ)
if (zget_hdr() <> ZACK)
ser.fgcolor(ser.red)
ser.strln(@"error from receiver - aborting")
ser.fgcolor(ser.white)
repeat
ser.pos_xy(0, 3)
ser.printf(@"transferred %d/%d bytes\n\r", xfer, _f_sz)
zmtx_bin_header(ZBIN32, ZEOF, @_f_sz)
repeat until (zget_hdr() == ZRINIT)
zmtx_hex_header(ZFIN, 0)
repeat until (zget_hdr() == ZFIN)
ser.strln(@"Transfer complete")
putchar("O") ' over and out
putchar("O")
repeat
PUB putchar(ch)
com.putchar(ch)
PUB getchar(): ch
return com.getchar()
#include "zmodem.common.spinh"
#include "protocol.file-xfer.zmodem.spin2h"
DAT
{
Copyright 2022 Jesse Burt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}