-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPingInt
115 lines (91 loc) · 2.68 KB
/
PingInt
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
114
115
\ changed $HW to erase buffer with spaces so that the count and
\ retries saved into mybuff typed correctly at RX end
\res MCU: STM8S103
\res export BIT0 BIT1 BIT2 BIT3 BIT4 BIT5 BIT6 BIT7
\res export INT_EXTI2
\res MCU: nRF24L01
\res export R.SETUP_RETR R.STATUS R.DYNPD R.FEATURE
\ helper word: create BSET/BRES instructions
NVM
: $HW ( -- )
mybuff P0_width $20 FILL \ erase buffer
$" Hello World" COUNT ( --- a1 n1 )
mybuff SWAP CMOVE
;
: @retries ( --- n1 )
R.OBSERVE_TX nRF@1 \ get count of lost packets:retries
$0F AND \ mask off lost packets
;
: n>str ( n1 --- a1 n2 ) <# BL HOLD #S #> ;
: n>buff ( a1 n1 --- ) \ store n1 as a string at offset n1 in mybuff
n>str \ a1 a2 n2
ROT mybuff +
SWAP
CMOVE
;
VARIABLE STATUS \ nRF24 STATUS from IRQ
\ interrupt service routine
HERE ] \ headerless code (keep xt on stack)
SAVEC
\ R@STATUS ( s )
R.STATUS nRF@1 ( s )
DUP STATUS @ OR STATUS ! ( s )
DUP BIT4 AND IF
FlushTx \ FlushRx
THEN
\ DUP BIT5 AND IF
\ DEB.On \ Tx data sent
\ THEN
( s ) BIT6 AND IF
LED.On \ Rx data ready
\ RXBUFF 4 R_RX_PAYLOAD nrf>b DROP
RXBUFF 4 rx>b DROP
THEN
$70 R.STATUS nRF!1
IRET
[ OVERT ( xt ) INT_EXTI2 ! \ set Port C int vector
: PAYLOAD.TX ( -- ) \ send n bytes as set by P0_width
mybuff P0_WIDTH b>tx DROP
_CE.HD _CE.LOW \ 10us minimum, using 130uS
;
HERE $05A3 , $B4C5 , $D6E7 , ( myP0Addr )
: TxInit ( -- ) \ setup as primary transmitter
nRF24Init \ general setup
IrqInit \ enable nRF24 IRQ interrupt of PC.4
\ set pipe0 RX/TX to same address
( myP0Addr ) LITERAL COUNT b>p0addr
\ configure ACK payload mode
( DPL_P0 ) $01 R.DYNPD nRF!1
( EN_ACK_PAY ) $02 R.FEATURE nRF!1 \ see footnote ^d
4 SetPL_width \ make it work for SI24R1
\ set TX power to 0dBm output, modulation to 250kbps
[ $0 BIT5 >HIGH BIT2 >HIGH BIT1 >HIGH ] LITERAL RfSetup
\ ARD: retransmit delay, ARC: retries
[ ( ARD: 250us* ) $80 ( ARC: n* ) 0 + ] LITERAL R.SETUP_RETR nRF!1
$70 SetRF_CH
>Standby1
Set.TX \ enter TX mode
." Device reset" cr
;
: Ping1 ( -- )
TxInit
0 STATUS !
$HW 0 BEGIN
1+ 20 OVER n>buff
PAYLOAD.TX
@retries DUP 27 SWAP n>buff DROP
100 ms
STATUS @ 0 STATUS !
DUP BIT4 AND IF ." Max retries cleared" CR THEN
\ DUP BIT5 AND IF ." Tx data sent" CR THEN
DUP BIT6 AND IF ." Rx data ready" CR THEN
( s ) . SPACE RXBUFF 4 TYPE SPACE
LED.Off \ DEB.Off
900 ms
?RX \ input on serial line
IF 32 = ELSE 0 THEN \ only if it is a space char do we exit
UNTIL
DROP
;
' Ping1 'Boot !
RAM