Skip to content

Commit

Permalink
RP.PIO: allow non-blocking put/get on FIFOs
Browse files Browse the repository at this point in the history
Also add FIFO status functions.
  • Loading branch information
Fabien-Chouteau authored and JeremyGrosser committed Feb 29, 2024
1 parent 70984e0 commit 71f589d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/drivers/rp-pio.adb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ package body RP.PIO is
end loop;
end Put;

procedure Try_Put
(This : in out PIO_Device;
SM : PIO_SM;
Data : UInt32;
Success : out Boolean)
is
begin
Success := not This.TX_FIFO_Full (SM);
if Success then
This.Periph.TXF (SM) := Data;
end if;
end Try_Put;

procedure Get
(This : in out PIO_Device;
SM : PIO_SM;
Expand All @@ -433,6 +446,31 @@ package body RP.PIO is
end loop;
end Get;

procedure Try_Get
(This : in out PIO_Device;
SM : PIO_SM;
Data : out UInt32;
Success : out Boolean)
is
begin
Success := not This.RX_FIFO_Empty (SM);
if Success then
Data := This.Periph.RXF (SM);
end if;
end Try_Get;

function RX_FIFO_Full (This : PIO_Device; SM : PIO_SM) return Boolean
is (This.Periph.FSTAT.RXFULL (SM));

function RX_FIFO_Empty (This : PIO_Device; SM : PIO_SM) return Boolean
is (This.Periph.FSTAT.RXEMPTY (SM));

function TX_FIFO_Full (This : PIO_Device; SM : PIO_SM) return Boolean
is (This.Periph.FSTAT.TXFULL (SM));

function TX_FIFO_Empty (This : PIO_Device; SM : PIO_SM) return Boolean
is (This.Periph.FSTAT.TXEMPTY (SM));

function TX_FIFO_Address
(This : PIO_Device;
SM : PIO_SM)
Expand Down
30 changes: 30 additions & 0 deletions src/drivers/rp-pio.ads
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,51 @@ is
(This : in out PIO_Device;
SM : PIO_SM;
Data : UInt32);
-- Put one word in the TX FIFO of the given state machine. If the FIFO is
-- full, this call will run a buzy loop until there's room for the data.

procedure Put
(This : in out PIO_Device;
SM : PIO_SM;
Data : UInt32_Array);
-- Put data in the TX FIFO of the given state machine. If the FIFO is
-- full, this call will run a buzy loop until there's room for the data.

procedure Try_Put
(This : in out PIO_Device;
SM : PIO_SM;
Data : UInt32;
Success : out Boolean);
-- Try to put one word in the TX FIFO of the given state machine. If the
-- FIFO is full, Success is set to False and the data not transmitted.

procedure Get
(This : in out PIO_Device;
SM : PIO_SM;
Data : out UInt32);
-- Get one word from the RX FIFO of the given state machine. If the FIFO
-- is empty, this call will run a buzy loop until there's data available.

procedure Get
(This : in out PIO_Device;
SM : PIO_SM;
Data : out UInt32_Array);
-- Get data from the RX FIFO of the given state machine. If the FIFO is
-- empty, this call will run a buzy loop until there's data available.

procedure Try_Get
(This : in out PIO_Device;
SM : PIO_SM;
Data : out UInt32;
Success : out Boolean);
-- Try to get one word from the RX FIFO of the given state machine. If the
-- FIFO is empty, Success is set to False and Data is not set.

function RX_FIFO_Full (This : PIO_Device; SM : PIO_SM) return Boolean;
function RX_FIFO_Empty (This : PIO_Device; SM : PIO_SM) return Boolean;

function TX_FIFO_Full (This : PIO_Device; SM : PIO_SM) return Boolean;
function TX_FIFO_Empty (This : PIO_Device; SM : PIO_SM) return Boolean;

function TX_FIFO_Address
(This : PIO_Device;
Expand Down

0 comments on commit 71f589d

Please sign in to comment.