Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed serial and usb chat, bdm, and avrprog code to use pad

Instead of each defining its own buffer and so on. The only place that used
b>  and  b<  was bdm-usb-host, so I moved that code there.

Also, I defined little- and big-endian versions of w@ and w! (lew@ lew! bew@
bew!) so they exist no matter what kind of target is loaded. Using these and
pad was enough to do chat and avrprog pretty cleanly.
  • Loading branch information...
commit 9f8dd395147e7bd055f7927564fd323e282946c1 1 parent adec4d5
@nimblemachines authored
View
17 target/HC08/avrprog-serial-host.mu4
@@ -10,20 +10,11 @@ loading AVR SPI-over-serial programmer (host)
hex
-4 buffer avrbuf ( for returned values)
-variable avrptr ( pointer into avrbuf)
-
-: !avrbuf avrbuf avrptr ! ;
-: +avrptr 1 avrptr +! ;
-
-: b> ( byte) avrptr @ c! +avrptr ;
--- : b< ( - byte) avrptr @ c@ +avrptr ;
+: !chat <# ; ( init hld)
( Commands)
: avr.Execute ( b3 b2 b1 b0)
- !avrbuf
- 21 send
- 4 for send recv b> next ;
+ !chat 21 send 4 for send recv hold next ;
: avr.Bye ( End session, return to chat command loop) 00 send ;
: avr.ResetLow 22 send ;
@@ -36,10 +27,10 @@ variable avrptr ( pointer into avrbuf)
: avr ( b0 b1 b2 b3) swap 2swap swap ( b3 b2 b1 b0) avr.Execute ;
: avr2 ( b0 b1 b2 b3 - r2) ( do command; return second-to-last byte of response)
- avr avrbuf 2 + c@ ;
+ avr hld @ 1+ c@ ;
: avr3 ( b0 b1 b2 b3 - r3) ( do command; return last byte of response)
- avr avrbuf 3 + c@ ;
+ avr hld @ c@ ;
: prog ( enable programming)
.ifdef in-ram
View
8 target/HC08/avrprog-usb-host.mu4
@@ -20,10 +20,10 @@ hex
lohi> push lohi> pop ;
( Commands)
-: avr.Result 0c0 20 0 0 4 ubuf usb ;
+: avr.Result 0c0 20 0 0 4 pad usb ;
: avr.Execute ( b0 b1 b2 b3) >setup 2push
- 40 21 2pop 4 ubuf usb ;
+ 40 21 2pop 4 pad usb ;
: control-write
create , ( bRequest)
@@ -38,10 +38,10 @@ hex
: avr ( b0 b1 b2 b3) avr.Execute avr.Result ;
: avr2 ( b0 b1 b2 b3 - r2) ( do command; return second-to-last byte of response)
- avr ubuf 2 + c@ ;
+ avr pad 2 + c@ ;
: avr3 ( b0 b1 b2 b3 - r3) ( do command; return last byte of response)
- avr ubuf 3 + c@ ;
+ avr pad 3 + c@ ;
: prog ( enable programming)
.ifdef in-ram
View
20 target/HC08/bdm-usb-host.mu4
@@ -18,10 +18,10 @@ hex
( Commands)
: u.Result ( #expect) push ( fetch BDM result, or Sync pulse length)
- 0c0 20 0 0 pop ubuf usb ;
+ 0c0 20 0 0 pop pad usb ;
: u.Execute ( #write #expect) 2push ( execute BDM request)
- 40 21 0 pop pop ubuf usb ;
+ 40 21 0 pop pop pad usb ;
: control-write
create , ( bRequest)
@@ -44,16 +44,26 @@ hex
-- : b.Idle ;
+( A simple buffer for chatty communication protocols. Words for putting
+ values into a buffer -- at pad -- and taking them out again.)
+
+: !chat <# ;
+: #chat hld @ pad - ;
+: +hld 1 hld +! ;
+
+: b> ( byte) hld @ c! +hld ;
+: b< ( - byte) hld @ c@ +hld ;
+
( For S08 targets, we send up to four bytes, and expect up to two.)
-: Send1 !ubuf b> ;
+: Send1 !chat b> ;
: Send2 Send1 b> ;
: Send3 Send2 b> ;
: Send4 Send3 b> ;
-: expect ( #expect) #ubuf over u.Execute u.Result !ubuf ;
+: expect ( #expect) #chat over u.Execute u.Result !chat ;
: Expect0 0 expect ;
: Expect1 1 expect b< ;
: Expect2 2 expect b< b< ;
-: b.Sync u.Sync 2 u.Result !ubuf w< ;
+: b.Sync u.Sync 2 u.Result pad bew@ ;
View
24 target/HC08/chat-usb-host.mu4
@@ -51,23 +51,11 @@ hex
0c0 03 0 0 2 pop usb ;
variable uaddr ( current memory access address)
-10 buffer ubuf ( for short reads and writes)
-variable uptr ( pointer into ubuf)
-: !ubuf ubuf uptr ! ;
-: +uptr 1 uptr +! ;
-: #ubuf uptr @ ubuf - ;
+: usb-c@ ( addr - byte) 1 pad u.Read pad c@ ;
+: usb-c! ( byte addr) swap pad c! 1 pad u.Write ;
-: b> ( byte) uptr @ c! +uptr ;
-: b< ( - byte) uptr @ c@ +uptr ;
-
-: w> ( word) >lohi b> b> ; ( Big endian!)
-: w< ( - word) b< b< hilo> ; ( ditto!)
-
-: usb-c@ ( addr - byte) 1 ubuf u.Read ubuf c@ ;
-: usb-c! ( byte addr) swap ubuf c! 1 ubuf u.Write ;
-
-: usb-sp ( - sp) ubuf u.ReadSp !ubuf w< ;
+: usb-sp ( - sp) pad u.ReadSp pad bew@ ;
: u.SetAddr uaddr ! ;
: u.GetAddr uaddr @ ;
@@ -78,13 +66,13 @@ variable uptr ( pointer into ubuf)
usb-sp dup push 6 rot u.Read pop ;
: u.SetRegs ( buf)
- usb-sp 6 rot u.Write ;
+ usb-sp 6 rot u.Write ;
( Order of regs in memory: H CC A X PC)
( XXX this is a huge kludge)
: u.SetPC ( pc)
- usb-sp 4 + swap !ubuf w>
- 2 ubuf u.Write ;
+ usb-sp 4 + swap pad bew!
+ 2 pad u.Write ;
.ifdef t.Id ( if we've loaded interact support)
View
12 target/HC08/memory.mu4
@@ -32,22 +32,24 @@ loading HC08 memory image
: .debug-comma ;
.then
-( DEBUG: Define show-c! to show writes to image.)
-.ifdef show-c!
+( DEBUG: Define show-! to show writes to image.)
+.ifdef show-!
: .debug-c! cr ( byte addr) 2dup .hcell_ .h8 ;
+: .debug-w! cr ( word addr) 2dup .hcell_ .hcell ;
.else
: .debug-c! ;
+: .debug-w! ;
.then
: image-c@ image+ c@ ;
: image-c! .debug-c! image+ c! ;
( HC08s are big-endian, like all Motorola/Freescale processors!)
-: image-! ( w a) push >lohi r@ ( hi) image-c! pop 1+ ( lo) image-c! ;
-: image-@ ( a - w) dup image-c@ ( hi) swap 1+ image-c@ ( lo) hilo> ;
+: image-@ ( a - w) image+ bew@ ;
+: image-! ( w a) .debug-w! image+ bew! ;
-: image-p! image+ p! ;
: image-p@ p@ image- ;
+: image-p! image+ p! ;
: target-* ( - cell) c* c* hilo> ; ( big-endian 16-bit word)
View
15 target/common/16bit.mu4
@@ -6,17 +6,20 @@
loading Support for handling 16-bit words
( I'm not sure where to put this. It's not specific to a particular target,
- so having it here in target/common/ makes sense.
-
- These also aren't exactly particular to a certain target endianness,
- either, though they are useful when serialisng data into a buffer that
- gets sent to a target, or unserialising from a buffer received from a
- target.)
+ so having it here in target/common/ makes sense.)
( Generally helpful for little-endian targets.)
: >hilo ( w - hi lo) dup 8 u>> swap "0ff and ;
: lohi> ( lo hi - w) 8 << or ;
+( Little-endian word fetch and store.)
+: lew@ ( a - w) dup c@ ( lo) swap 1+ c@ ( hi) lohi> ;
+: lew! ( w a) push >hilo r@ c! ( lo) pop 1+ c! ( hi) ;
+
( Generally helpful for big-endian targets.)
: >lohi ( w - lo hi) dup "0ff and swap 8 u>> ;
: hilo> ( hi lo - w) swap 8 << or ;
+
+( Big-endian word fetch and store.)
+: bew@ ( a - w) dup c@ ( hi) swap 1+ c@ ( lo) hilo> ;
+: bew! ( w a) push >lohi r@ c! ( hi) pop 1+ c! ( lo) ;
Please sign in to comment.
Something went wrong with that request. Please try again.