[jaluino] r434 committed - pseudo-var to send and received, dealing with multiple bytes length pa...

2 views
Skip to first unread message

jal...@googlecode.com

unread,
Jun 15, 2013, 1:02:30 PM6/15/13
to jal...@googlegroups.com
Revision: 434
Author: sebastienlelong
Date: Sat Jun 15 10:02:15 2013
Log: pseudo-var to send and received, dealing with multiple bytes
length payload, using send/receive buffers
http://code.google.com/p/jaluino/source/detail?r=434

Modified:
/trunk/lib/nrf24l01.jal
/trunk/samples/jaluino_bee_nrf24_receive.jal
/trunk/samples/jaluino_bee_nrf24_send.jal

=======================================
--- /trunk/lib/nrf24l01.jal Sat Jun 15 09:21:33 2013
+++ /trunk/lib/nrf24l01.jal Sat Jun 15 10:02:15 2013
@@ -17,7 +17,9 @@
-- Notes: jalv2 port of MiRF lib for arduino. Greatly inspired from MiRF
lib port for arduino, by
-- Aaron Shrimpton and Stefan Engelke
--
--- URL:
+-- TODO:
+-- * remove serial_hw2_* hard-coded references
+-- * remove delay between csn low/high ?
--

-- -----------------
@@ -157,7 +159,7 @@
procedure nrf24_transmit_sync(byte in len)
procedure nrf24_read_register(byte in reg, byte in len)
procedure nrf24_transfer_sync(byte in len)
-procedure nrf24_send(byte in value)
+procedure nrf24_send()
function nrf24_get_status() return byte
procedure nrf24_power_up_tx()
function nrf24_rx_fifo_empty() return bit
@@ -257,9 +259,9 @@
end loop
end procedure

--- Sends a data package to the default address. Be sure to send the correct
--- amount of bytes as configured as payload on the receiver.
-procedure nrf24_send(byte in value) is
+-- Sends a data package to the default address. Sending buffer should be
+-- previously filled. Well, you should use pseudo-var nrf24_data for ease
+procedure nrf24_send() is

var byte st = nrf24_get_status()
while nrf24_ptx == 1 loop
@@ -280,10 +282,8 @@
nrf24_csn_pin = low

spi_master_data = NRF24_W_TX_PAYLOAD
- -- Write payload
- nrf24_bufin[0] = value
- -- TODO: I could send multiple byte at a time
- nrf24_transmit_sync(1)
+ -- send as many bytes as declared in payload
+ nrf24_transmit_sync(NRF24_PAYLOAD_SIZE)

-- Pull up chip select
nrf24_csn_pin = high
@@ -380,6 +380,55 @@
nrf24_write_register(NRF24_TX_ADDR,NRF24_ADDR_LEN)
end procedure

+-- Payload can be more than 1 byte long, so we need to
+-- track, when reading values, if we're starting to read
+-- (ie. data is just received) or if we're continuing to read
+-- (ie. move forward withing buffer)
+var byte _nrf24_receive_next_buffer_index = 0
+
+-- pseudo-var to read a byte, blocking call
+function nrf24_data'get() return byte is
+ -- reached end of buffer ? reset next index
+ if _nrf24_receive_next_buffer_index == NRF24_PAYLOAD_SIZE then
+ _nrf24_receive_next_buffer_index = 0
+ end if
+
+ -- next index is 0 ? Means nothing in buffer, we need to receive data
+ if _nrf24_receive_next_buffer_index == 0 then
+ while nrf24_data_ready() == false loop
+ end loop
+ nrf24_get_data()
+ end if
+
+ var byte c
+ c = nrf24_bufout[_nrf24_receive_next_buffer_index]
+ _nrf24_receive_next_buffer_index = _nrf24_receive_next_buffer_index + 1
+ return c
+
+end function
+
+var byte _nrf24_send_next_buffer_index = 0
+-- pseudo-var to send a byte, blocking call
+-- (will block until sent)
+-- Call this procedure as many times as payload size. This will load
+-- sending buffer. Once buffer is full (payload size is reached) data
+-- is actually sent (and not before). When sent, call will block until
+-- data is actually sent.
+procedure nrf24_data'put(byte in data) is
+ -- buffer filled, now send
+ if _nrf24_send_next_buffer_index == NRF24_PAYLOAD_SIZE then
+ nrf24_send()
+ while nrf24_is_sending() == true loop
+ end loop
+ _nrf24_send_next_buffer_index = 0
+ end if
+
+ -- Write payload
+ nrf24_bufin[_nrf24_send_next_buffer_index] = data
+ _nrf24_send_next_buffer_index = _nrf24_send_next_buffer_index + 1
+
+end procedure
+
procedure nrf24_print_registers() is
nrf24_read_register(NRF24_CONFIG_REG,1)
var byte config = nrf24_bufout[0]
=======================================
--- /trunk/samples/jaluino_bee_nrf24_receive.jal Sat Jun 15 09:21:33 2013
+++ /trunk/samples/jaluino_bee_nrf24_receive.jal Sat Jun 15 10:02:15 2013
@@ -83,18 +83,10 @@

forever loop

- if nrf24_data_ready() == true then
- nrf24_get_data()
- var byte i = 0
- var byte c = 0
- for NRF24_PAYLOAD_SIZE loop
- c = nrf24_bufout[i]
- print_byte_dec(serial_hw_data,c)
- serial_hw_data = ","
- i = i + 1
- end loop
- print_crlf(serial_hw_data)
- end if
+ var byte c
+ c = nrf24_data
+ print_byte_dec(serial_hw_data,c)
+ serial_hw_data = ","

end loop

=======================================
--- /trunk/samples/jaluino_bee_nrf24_send.jal Sat Jun 15 09:21:33 2013
+++ /trunk/samples/jaluino_bee_nrf24_send.jal Sat Jun 15 10:02:15 2013
@@ -89,9 +89,6 @@
var byte taddr[] = {0x00,0x01,0x02,0x03,0x04} -- see receive sample addr
nrf24_set_taddr(taddr)

-print_byte_dec(serial_hw_data,nrf24_ptx)
-
-
forever loop

var byte i = 0
@@ -101,16 +98,12 @@
print_string(serial_hw_data,str2)
print_byte_dec(serial_hw_data,i)
print_crlf(serial_hw_data)
- print_byte_dec(serial_hw_data,nrf24_ptx)
- nrf24_send(i)
- print_byte_dec(serial_hw_data,nrf24_ptx)
- i = i + 1
onboard_led = high
- while nrf24_is_sending() == true loop
- end loop
+ nrf24_data = i
delay_1ms(10)
onboard_led = low
delay_1ms(10)
+ i = i + 1
end loop

end loop
Reply all
Reply to author
Forward
0 new messages