Skip to content

Commit 866f0ee

Browse files
committed
revert to 8 bit _rxraw code
1 parent 11e2156 commit 866f0ee

File tree

2 files changed

+742
-909
lines changed

2 files changed

+742
-909
lines changed

sys/p2_code.spin

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,10 @@ pri _cogchk(id = long) : r
137137
'' serial send/receive code
138138
'' this code uses smarpins, so doesn't require a COG. The down side is that
139139
'' the smartpin has only a single character buffer.
140-
'' Following a suggestion from forum user evanh, we improve this for receive
141-
'' by putting the smartpin into 28 bit mode rather than 8 bit, and then manually
142-
'' checking for start/stop bits in the bottom 20 bits. This effectively
143-
'' creates a 6 character buffer: 3 characters in the Z register, and 3 characters
144-
'' internally to the smartpin
145140
''
146141
dat
147142
orgh
148143
_bitcycles long 0
149-
_rx_temp long 0
150144

151145
con
152146
_rxpin = 63
@@ -171,7 +165,7 @@ pri _setbaud(baudrate) | bitperiod, bit_mode
171165
_wrpin(_txpin, _txmode)
172166
_wxpin(_txpin, bit_mode)
173167
_wrpin(_rxpin, _rxmode)
174-
_wxpin(_rxpin, bit_mode + 20) ' async using 28 bits instead of 8
168+
_wxpin(_rxpin, bit_mode)
175169
_dirh(_txpin)
176170
_dirh(_rxpin)
177171

@@ -191,60 +185,29 @@ pri _rxraw(timeout = 0) : rxbyte = long | z, endtime, temp2, rxpin
191185
if timeout
192186
endtime := _getcnt() + timeout * (__clkfreq_var >> 10)
193187
else
194-
endtime := 0 ' just gets rid of a compiler warning
188+
endtime := 0 ' just to make compiler happy
195189
rxbyte := -1
196190
rxpin := _rxpin
197191
z := 0
198-
temp2 := _rx_temp
199-
'' slightly tricky code for pulling out the bytes from the 28 bits
200-
'' of data presented by the smartpin
201-
'' Courtesy of evanh
202192
repeat
203-
asm
204-
testb temp2, #8 wc ' check framing of prior character for valid character
205-
testbn temp2, #9 andc ' more framing check (1 then 0)
206-
shr temp2, #10 ' shift down next character, if any
207-
if_c mov z, #1
208-
if_c jmp #.breakone
209-
testp rxpin wz
210-
if_z mov z, #1
211-
if_z rdpin temp2, rxpin
212-
if_z shr temp2, #32 - 28
213-
.breakone
214-
endasm
215-
until z or (timeout and (endtime - _getcnt() < 0))
216-
if z
217-
rxbyte := temp2 & $ff
218-
_rx_temp := temp2
219-
220-
' like _rxraw, but no timeout and returns -1 at once if no pending
221-
' character
222-
pri _rxpoll() : rxbyte = long | z, temp2, rxpin
193+
z := _pinr(rxpin)
194+
if z
195+
rxbyte := _rdpin(rxpin)>>24
196+
quit
197+
if timeout
198+
if endtime - _getcnt() < 0
199+
quit
200+
201+
' returns -1 immediately if no pending character
202+
pri _rxpoll() : rxbyte = long | z, rxpin
223203
if _bitcycles == 0
224204
_setbaud(__default_baud__)
225205
rxbyte := -1
226206
rxpin := _rxpin
227-
z := 0
228-
temp2 := _rx_temp
229-
'' slightly tricky code for pulling out the bytes from the 28 bits
230-
'' of data presented by the smartpin
231-
'' Courtesy of evanh
232-
asm
233-
testb temp2, #8 wc ' check framing of prior character for valid character
234-
testbn temp2, #9 andc ' more framing check (1 then 0)
235-
shr temp2, #10 ' shift down next character, if any
236-
if_c mov z, #1
237-
if_c jmp #.breakone
238-
testp rxpin wz
239-
if_z mov z, #1
240-
if_z rdpin temp2, rxpin
241-
if_z shr temp2, #32 - 28
242-
.breakone
243-
endasm
207+
z := _pinr(rxpin)
244208
if z
245-
rxbyte := temp2 & $ff
246-
_rx_temp := temp2
247-
209+
rxbyte := _rdpin(rxpin)>>24
210+
248211
pri _dirl(pin = long)
249212
asm
250213
dirl pin

0 commit comments

Comments
 (0)