/
dummy-comm.4th
54 lines (39 loc) · 1015 Bytes
/
dummy-comm.4th
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
\ dummy-comm.4th
\
\ Module for dummy communication functions, to test a
\ generic terminal application that can use various
\ asynchronous communications interfaces.
\ This module does not have any dependencies on other modules.
Module: dummy-comm
begin-module
create dummy-msg 64 allot
s" Dummy Terminal" dummy-msg swap move
3000 constant START_DELAY \ delay from open to start of reception
10 constant RX_DELAY \ 1 character rec'd every 10 ms
variable start-time
variable last-time
: total-elapsed ( -- u ) ms@ start-time @ - ;
: rx-elapsed ( -- u ) ms@ last-time @ - ;
Public:
variable config
\ Dummy Open
: open ( aconfig -- )
drop ms@ dup start-time ! last-time !
;
\ Dummy Get
: get ( -- c ) [char] A ;
\ Dummy Put
: put ( c -- ) drop ;
\ Dummy Rx-len
: Rx-len ( -- u )
0
total-elapsed START_DELAY > IF
rx-elapsed RX_DELAY > if
drop 1 ms@ last-time !
then
then ;
\ Dummy Write
: write ( a u -- ) 2drop ;
\ Dummy Close
: close ( -- ) ;
end-module