Skip to content

Commit

Permalink
protected Console object
Browse files Browse the repository at this point in the history
  • Loading branch information
masonticehurst committed Feb 14, 2024
1 parent 4ee4f5c commit 7c98a88
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 112 deletions.
9 changes: 5 additions & 4 deletions eRINA_STM32F7/src/net/receiver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package body Receiver is

Ready : Ada.Synchronous_Task_Control.Suspension_Object;
ONE_US : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Microseconds (1);

-- ------------------------------
-- Start the receiver loop.
-- ------------------------------
Expand All @@ -33,12 +34,13 @@ package body Receiver is
Total : Net.Uint64 := 0;
Count : Net.Uint64 := 0;
begin
Debug.Print (Debug.Info, "Initializing Ethernet Controller...");

Debug.Console.Print (Debug.Info, "Initializing Ethernet Controller...");

-- Wait until the Ethernet driver is ready.
Ada.Synchronous_Task_Control.Suspend_Until_True (Ready);

Debug.Print (Debug.Info, "Ethernet Controller Initialized!");
Debug.Console.Print (Debug.Info, "Ethernet Controller Initialized!");

-- Loop receiving packets and dispatching them.
Min_Receive_Time := Us_Time'Last;
Expand All @@ -58,8 +60,7 @@ package body Receiver is
if Ether.Ether_Type =
Net.Headers.To_Network (Net.Protos.ETHERTYPE_ARP)
then
ARP_Request_Count := ARP_Request_Count + 1;
Debug.Print (Debug.Info, "ARP Packet Received");
Debug.Console.Print (Debug.Info, "ARP Packet Received");
Net.Protos.Arp.Receive (Network.Ifnet, Packet);
elsif Ether.Ether_Type =
Net.Headers.To_Network (Net.Protos.ETHERTYPE_RINA)
Expand Down
2 changes: 0 additions & 2 deletions eRINA_STM32F7/src/net/receiver.ads
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ package Receiver is
Max_Receive_Time : Us_Time := 0 with
Atomic;

ARP_Request_Count : Natural := 0;

-- Start the receiver loop.
procedure Start;

Expand Down
2 changes: 1 addition & 1 deletion eRINA_STM32F7/src/rina/board.adb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package body Board is
procedure Pressed is
begin
STM32.Board.All_LEDs_On;
Debug.Print(Debug.Info, "Button pressed!");
Debug.Console.Print(Debug.Info, "Button pressed!");
end Pressed;
end Button_Handler;
end Board;
168 changes: 78 additions & 90 deletions eRINA_STM32F7/src/rina/debug.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,93 @@ with GUI;

package body Debug is

protected body Mutex is
entry Seize when not Owned is
protected body Console is
procedure Print (Debug_Level : in Debug; Msg : in String) is
currentLine : constant Natural :=
(CURRENT_CONSOLE_POSITION.Y - 100) / FONT_HEIGHT; -- zero indexed
Foreground : HAL.Bitmap.Bitmap_Color;
Background : HAL.Bitmap.Bitmap_Color;
begin
Owned := True;
end Seize;
procedure Release is
begin
Owned := False;
end Release;
end Mutex;

-- Probably a cleaner way to do this
procedure Print (Debug_Level : in Debug; Msg : in String) is
currentLine : constant Natural :=
(CURRENT_CONSOLE_POSITION.Y - 100) / FONT_HEIGHT; -- zero indexed
Foreground : HAL.Bitmap.Bitmap_Color;
Background : HAL.Bitmap.Bitmap_Color;
begin
Print_Mutex.Seize;

Foreground :=
(case Debug_Level is when Info | Error => HAL.Bitmap.White,
when Warning => HAL.Bitmap.Black);
Foreground :=
(case Debug_Level is when Info | Error => HAL.Bitmap.White,
when Warning => HAL.Bitmap.Black);

Background :=
(case Debug_Level is when Info => HAL.Bitmap.Blue,
when Warning => HAL.Bitmap.Yellow, when Error => HAL.Bitmap.Red);
Background :=
(case Debug_Level is when Info => HAL.Bitmap.Blue,
when Warning => HAL.Bitmap.Yellow, when Error => HAL.Bitmap.Red);

if currentLine > MAX_LINES then
-- Shift console lines up
for I in 1 .. MAX_LINES loop
CopyLine (I, I - 1, I = MAX_LINES);
end loop;
if currentLine > MAX_LINES then
-- Shift console lines up
for I in 1 .. MAX_LINES loop
CopyLine (I, I - 1, I = MAX_LINES);
end loop;

-- Adjust Y position to overwrite the last line
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y - FONT_HEIGHT - LINE_PADDING;
end if;
-- Adjust Y position to overwrite the last line
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y - FONT_HEIGHT - LINE_PADDING;
end if;

-- Draw debug prefix
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y)),
Msg => Debug_Level'Image, Font => BMP_Fonts.Font8x8,
Foreground => Foreground, Background => Background);
-- Draw debug prefix
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y)),
Msg => Debug_Level'Image, Font => BMP_Fonts.Font8x8,
Foreground => Foreground, Background => Background);

-- Draw actual message text
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X +
GUI.MeasureText (Debug_Level'Image, BMP_Fonts.Font8x8).Width +
LINE_PADDING * 2,
CURRENT_CONSOLE_POSITION.Y)),
Msg => Msg, Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
Background => HAL.Bitmap.Black);
-- Draw actual message text
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X +
GUI.MeasureText (Debug_Level'Image, BMP_Fonts.Font8x8).Width +
LINE_PADDING * 2,
CURRENT_CONSOLE_POSITION.Y)),
Msg => Msg, Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
Background => HAL.Bitmap.Black);

-- Move the Y position down for the next message
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT + LINE_PADDING;
-- Move the Y position down for the next message
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT + LINE_PADDING;

STM32.Board.Display.Update_Layer (1, True);
STM32.Board.Display.Update_Layer (1, True);
end Print;

Print_Mutex.Release;
end Print;
procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean)
is
-- TODO: Cleanup later...
srcToPoint : constant HAL.Bitmap.Point :=
(0,
Natural'Min
(CONSOLE_STARTING_POINT.Y +
(FONT_HEIGHT + LINE_PADDING) * SrcLineNumber,
GUI.Board_Resolution.Height - 2));
dstToPoint : constant HAL.Bitmap.Point :=
(0,
Natural'Min
(CONSOLE_STARTING_POINT.Y +
(FONT_HEIGHT + LINE_PADDING) * DstLineNumer,
GUI.Board_Resolution.Height - 2));
srcRect : constant HAL.Bitmap.Rect :=
(Position => srcToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT + LINE_PADDING);
begin
HAL.Bitmap.Copy_Rect
(Src_Buffer => GUI.Screen_Buffer.all, Src_Pt => srcToPoint,
Dst_Buffer => GUI.Screen_Buffer.all, Dst_Pt => dstToPoint,
Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT + LINE_PADDING, Synchronous => True);
if DeleteSrc then
HAL.Bitmap.Fill_Rect
(Buffer => GUI.Screen_Buffer.all, Area => srcRect);
end if;
STM32.Board.Display.Update_Layer (1, True);
end CopyLine;
end Console;

procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean)
is
-- TODO: Cleanup later...
srcToPoint : constant HAL.Bitmap.Point :=
(0,
Natural'Min
(CONSOLE_STARTING_POINT.Y +
(FONT_HEIGHT + LINE_PADDING) * SrcLineNumber,
GUI.Board_Resolution.Height - 2));
dstToPoint : constant HAL.Bitmap.Point :=
(0,
Natural'Min
(CONSOLE_STARTING_POINT.Y +
(FONT_HEIGHT + LINE_PADDING) * DstLineNumer,
GUI.Board_Resolution.Height - 2));
srcRect : constant HAL.Bitmap.Rect :=
(Position => srcToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT + LINE_PADDING);
begin
HAL.Bitmap.Copy_Rect
(Src_Buffer => GUI.Screen_Buffer.all, Src_Pt => srcToPoint,
Dst_Buffer => GUI.Screen_Buffer.all, Dst_Pt => dstToPoint,
Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT + LINE_PADDING, Synchronous => True);
if DeleteSrc then
HAL.Bitmap.Fill_Rect
(Buffer => GUI.Screen_Buffer.all, Area => srcRect);
end if;
STM32.Board.Display.Update_Layer (1, True);
end CopyLine;
end Debug;
20 changes: 8 additions & 12 deletions eRINA_STM32F7/src/rina/debug.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ with BMP_Fonts;
package Debug is
type Debug is (Error, Warning, Info);

CONSOLE_STARTING_POINT : HAL.Bitmap.Point := (0, 100);
CURRENT_CONSOLE_POSITION : HAL.Bitmap.Point := (0, 100);
FONT_HEIGHT : constant Natural :=
BMP_Fonts.Char_Height (Font => BMP_Fonts.Font8x8);
MAX_LINES : constant Natural := 20;
LINE_PADDING : constant Natural := 2;

protected type Mutex is
entry Seize;
procedure Release;
protected Console is
procedure Print (Debug_Level : in Debug; Msg : in String);
procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean);
private
Owned : Boolean := False;
end Mutex;
CONSOLE_STARTING_POINT : HAL.Bitmap.Point := (0, 100);
CURRENT_CONSOLE_POSITION : HAL.Bitmap.Point := (0, 100);
end Console;

Print_Mutex : Mutex;
procedure Print (Debug_Level : in Debug; Msg : in String);
procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean);
end Debug;
11 changes: 10 additions & 1 deletion eRINA_STM32F7/src/rina/demo.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ with Textures.PSU;
with Network;
with STM32;
with STM32.Board;
with Debug;

procedure Demo is
begin
Expand All @@ -23,6 +24,14 @@ begin
("Ignored Packets: " & Network.Ifnet.Rx_Stats.Ignored'Image,
(80, 30));

delay Duration(1 / GUI.Frame_Rate);
GUI.Print
("Status: ",
(80, 45));

GUI.Print
("Waiting for enrollment request",
(145, 45));

delay Duration(1.0 / GUI.Frame_Rate);
end loop;
end Demo;
4 changes: 2 additions & 2 deletions eRINA_STM32F7/src/rina/gui.ads
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ package GUI is
end record;

Board_Resolution : Size := (480, 272);
Frame_Rate : Natural := 60;
Frame_Rate : Natural := 30;

procedure Initialize;
procedure Update;
procedure Print (Msg : in String; Pos : in HAL.Bitmap.Point);
Expand Down

0 comments on commit 7c98a88

Please sign in to comment.