@@ -137,16 +137,10 @@ pri _cogchk(id = long) : r
137
137
' ' serial send/receive code
138
138
' ' this code uses smarpins, so doesn't require a COG. The down side is that
139
139
' ' 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
145
140
' '
146
141
dat
147
142
orgh
148
143
_bitcycles long 0
149
- _rx_temp long 0
150
144
151
145
con
152
146
_rxpin = 63
@@ -171,7 +165,7 @@ pri _setbaud(baudrate) | bitperiod, bit_mode
171
165
_wrpin(_txpin, _txmode)
172
166
_wxpin(_txpin, bit_mode)
173
167
_wrpin(_rxpin, _rxmode)
174
- _wxpin(_rxpin, bit_mode + 20 ) ' async using 28 bits instead of 8
168
+ _wxpin(_rxpin, bit_mode)
175
169
_dirh(_txpin)
176
170
_dirh(_rxpin)
177
171
@@ -191,60 +185,29 @@ pri _rxraw(timeout = 0) : rxbyte = long | z, endtime, temp2, rxpin
191
185
if timeout
192
186
endtime := _getcnt() + timeout * (__clkfreq_var >> 10 )
193
187
else
194
- endtime := 0 ' just gets rid of a compiler warning
188
+ endtime := 0 ' just to make compiler happy
195
189
rxbyte := - 1
196
190
rxpin := _rxpin
197
191
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
202
192
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
223
203
if _bitcycles == 0
224
204
_setbaud(__default_baud__)
225
205
rxbyte := - 1
226
206
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)
244
208
if z
245
- rxbyte := temp2 & $ff
246
- _rx_temp := temp2
247
-
209
+ rxbyte := _rdpin(rxpin)>> 24
210
+
248
211
pri _dirl (pin = long )
249
212
asm
250
213
dirl pin
0 commit comments