-
Notifications
You must be signed in to change notification settings - Fork 5
Transmitting
This page explains how to use the driver to transmit packets using the DW1000.
Sending a packet basically involves three steps:
- Load the packet into the DW1000.
- Tell the DW1000 to start sending the packet.
- Wait for the packet to finish sending (optional).
Here's a code example to send 100 bytes:
declare
Packet : constant DW1000.Types.Byte_Array (1 .. 100) := (others 16#AA#);
begin
-- Load the packet into the radio
DW1000.Driver.Set_Tx_Data
(Data => Packet,
Offset => 0);
DW1000.Driver.Set_Tx_Frame_Length
(Length => Packet'Length,
Offset => 0);
-- Tell the radio to start transmitting now.
-- (and don't enable the receiver after transmitting).
DecaDriver.Driver.Start_Tx_Immediate (Rx_After_Tx => False,
Auto_Append_FCS => False);
-- Delay until the radio has finished sending the packet
Ada.Synchronous_Task_Control.Suspend_Until_True(DecaDriver.Tx_Complete_Flag);
end;
The DW1000 has the capability to automatically enable the receiver after a packet has finished sending. For example, to listen for an acknowledgement packet. You can enable this by setting Rx_After_Tx
to True
when calling Start_Tx_Immediate
. Here's an example:
declare
Tx_Packet : constant DW1000.Types.Byte_Array (1 .. 100) := (others 16#AA#);
Rx_Packet : DW1000.Types.Byte_Array (1 .. 1024);
Rx_Packet_Length : DecaDriver.Frame_Length_Number;
Rx_Frame_Info : DecaDriver.Frame_Info_Type;
Rx_Status : DecaDriver.Rx_Status_Type;
Rx_Overrun : Boolean;
begin
-- Load the packet into the radio
DW1000.Driver.Set_Tx_Data
(Data => Packet,
Offset => 0);
DW1000.Driver.Set_Tx_Frame_Length
(Length => Packet'Length,
Offset => 0);
-- Tell the radio to start transmitting now.
DecaDriver.Driver.Start_Tx_Immediate (Rx_After_Tx => True,
Auto_Append_FCS => False);
-- Delay until the radio has finished sending the packet
Ada.Synchronous_Task_Control.Suspend_Until_True(DecaDriver.Tx_Complete_Flag);
-- Delay until the acknowledgement packet has been received
DecaDriver.Driver.Rx_Wait
(Frame => Rx_Packet,
Length => Rx_Packet_Length,
Frame_Info => Rx_Frame_Info,
Status => Rx_Status,
Overrun => Rx_Overrun);
-- Process the received packet.
if Rx_Status = DecaDriver.Success then
Process_Packet (Frame (1 .. Rx_Packet_Length));
end if;
end;
The Offset
parameter to the Set_Tx_Data
procedure allows you to write data to a different part of the DW1000's transmit buffer. This is useful for loading another packet into the radio's transmit buffer whilst the radio is still sending a previous packet that was written to another part of the buffer. Here is an example to demonstrate this:
declare
First_Packet : constant DW1000.Types.Byte_Array (1 .. 100) := (others 16#AA#);
Second_Packet : constant DW1000.Types.Byte_Array (1 .. 100) := (others 16#55#);
begin
-- Load the first packet into the radio
DW1000.Driver.Set_Tx_Data
(Data => First_Packet,
Offset => 0);
DW1000.Driver.Set_Tx_Frame_Length
(Length => First_Packet'Length,
Offset => 0);
-- Start sending the first packet
DecaDriver.Driver.Start_Tx_Immediate (Rx_After_Tx => False,
Auto_Append_FCS => False);
-- While the first packet is sending, load the second packet into
-- another part of the transmit buffer.
DW1000.Driver.Set_Tx_Data
(Data => Second_Packet,
Offset => 100);
-- Delay until the radio has finished sending the first packet
Ada.Synchronous_Task_Control.Suspend_Until_True(DecaDriver.Tx_Complete_Flag);
-- Start sending the second packet
DW1000.Driver.Set_Tx_Frame_Length
(Length => Second_Packet'Length,
Offset => 100);
DecaDriver.Driver.Start_Tx_Immediate (Rx_After_Tx => False,
Auto_Append_FCS => False);
end;