Commit f528d354 authored by Delia Cellarier's avatar Delia Cellarier

New serial driver for STM32F4xx and improved native serial driver

In this commit the new framing code is introduced, via the addition
of a start byte and appropriate synchronization.
parent 847db020
......@@ -71,7 +71,7 @@ package body PolyORB_HI_Drivers_Native_UART is
To_GNAT_Bits : constant array (7 .. 8) of
GNAT.Serial_Communications.Data_Bits :=
(7 => GNAT.Serial_Communications.CS8,
(7 => GNAT.Serial_Communications.CS7,
8 => GNAT.Serial_Communications.CS8);
pragma Suppress (Elaboration_Check, PolyORB_HI_Generated.Transport);
......@@ -106,6 +106,9 @@ package body PolyORB_HI_Drivers_Native_UART is
function To_PO_HI_Full_Stream is new Ada.Unchecked_Conversion
(AS_Full_Stream, Full_Stream);
-- Start marker to synchronize
START_MARKER : Unsigned_8 := 16#A0#;
----------------
-- Initialize --
----------------
......@@ -157,7 +160,7 @@ package body PolyORB_HI_Drivers_Native_UART is
('B' & S (First .. Last));
exception
when others =>
Put_Line (Normal, "Wrong baud rate: " & S (First .. Last));
-- Put_Line (Normal, "Wrong baud rate: " & S (First .. Last));
raise;
end;
......@@ -221,7 +224,7 @@ package body PolyORB_HI_Drivers_Native_UART is
exception
when others =>
Put_Line (Normal, "Initialization of UART subsystem dead");
null; -- Put_Line (Normal, "Initialization of UART subsystem dead");
end;
else
-- We got an ASN.1 configuration variable, use it
......@@ -245,16 +248,16 @@ package body PolyORB_HI_Drivers_Native_UART is
Parity := GNAT.Serial_Communications.None;
end if;
Put_Line (Normal, " -> Using ASN.1: " & Use_ASN1'Img);
Put_Line (Normal, "Device: " & Nodes (My_Node).UART_Config.devname);
Put_Line (Normal, " * Use Parity bits: "
& Nodes (My_Node).UART_Config.use_paritybit'Img);
Put_Line (Normal, " * Rate: "
& To_GNAT_Baud_Rate (Nodes (My_Node).UART_Config.Speed)'Img);
Put_Line (Normal, " * Parity: " & Parity'Img);
Put_Line (Normal, " * Bits: "
& To_GNAT_Bits
(Integer (Nodes (My_Node).UART_Config.Bits))'Img);
-- Put_Line (Normal, " -> Using ASN.1: " & Use_ASN1'Img);
-- Put_Line (Normal, "Device: " & Nodes (My_Node).UART_Config.devname);
-- Put_Line (Normal, " * Use Parity bits: "
-- & Nodes (My_Node).UART_Config.use_paritybit'Img);
-- Put_Line (Normal, " * Rate: "
-- & To_GNAT_Baud_Rate (Nodes (My_Node).UART_Config.Speed)'Img);
-- Put_Line (Normal, " * Parity: " & Parity'Img);
-- Put_Line (Normal, " * Bits: "
-- & To_GNAT_Bits
-- (Integer (Nodes (My_Node).UART_Config.Bits))'Img);
GNAT.Serial_Communications.Set
(Port => Nodes (My_Node).UART_Port,
......@@ -263,7 +266,7 @@ package body PolyORB_HI_Drivers_Native_UART is
Bits => To_GNAT_Bits (Integer (Nodes (My_Node).UART_Config.Bits)),
Block => True);
Put_Line (Normal, "Initialization of Native_UART subsystem is complete");
-- Put_Line (Normal, "Initialization of Native_UART subsystem is complete");
end Initialize;
-------------
......@@ -281,10 +284,19 @@ package body PolyORB_HI_Drivers_Native_UART is
begin
Main_Loop : loop
Put_Line ("Using user-provided Native_UART stack to receive");
-- Put_Line ("Using user-provided Native_UART stack to receive");
-- UART is a character-oriented protocol
-- Framing
while Unsigned_8(SEL (1)) /= START_MARKER loop
GNAT.Serial_Communications.Read
(Nodes (My_Node).UART_Port,
SEL (1 .. 1),
SEO);
end loop;
-- 1/ Receive message length
GNAT.Serial_Communications.Read
......@@ -311,26 +323,26 @@ package body PolyORB_HI_Drivers_Native_UART is
-- 2/ Receive full message
if SEO /= SEA'First - 1 then
Put_Line
(Normal,
"UART received"
& Ada.Streams.Stream_Element_Offset'Image (SEO)
& " bytes");
-- Put_Line
-- (Normal,
-- "UART received"
-- & Ada.Streams.Stream_Element_Offset'Image (SEO)
-- & " bytes");
-- Deliver to the peer handler
begin
PolyORB_HI_Generated.Transport.Deliver
(Corresponding_Entity
(Unsigned_8 (SEA (Message_Length_Size + 1))),
To_PO_HI_Full_Stream (SEA)
(1 .. Stream_Element_Offset (SEO)));
(1 .. Stream_Element_Offset (SEO)));
exception
when E : others =>
Put_Line (Ada.Exceptions.Exception_Information (E));
null; -- Put_Line (Ada.Exceptions.Exception_Information (E));
end;
else
Put_Line ("Got error");
null; -- Put_Line ("Got error");
end if;
end loop Main_Loop;
end Receive;
......@@ -346,6 +358,7 @@ package body PolyORB_HI_Drivers_Native_UART is
return Error_Kind
is
pragma Unreferenced (Node);
use type Ada.Streams.Stream_Element_Offset;
-- We cannot cast both array types using
-- Ada.Unchecked_Conversion because they are unconstrained
......@@ -357,16 +370,22 @@ package body PolyORB_HI_Drivers_Native_UART is
(1 .. Ada.Streams.Stream_Element_Offset (Size));
pragma Import (Ada, Msg);
for Msg'Address use Message'Address;
Packet : Ada.Streams.Stream_Element_Array
(1 .. Ada.Streams.Stream_Element_Offset (Size + 1));
begin
Put_Line ("Using user-provided UART stack to send");
Put_Line ("Sending through UART "
& Nodes (My_Node).UART_Config.devname
& Size'Img & " bytes");
-- Put_Line ("Using user-provided UART stack to send");
-- Put_Line ("Sending through UART "
-- & Nodes (My_Node).UART_Config.devname
-- & Size'Img & " bytes");
-- Adding a Start byte at the beginning
Packet (1) := Ada.Streams.Stream_Element (START_MARKER);
Packet (2 .. Ada.Streams.Stream_Element_Offset (Size + 1)) := Msg;
GNAT.Serial_Communications.Write
(Port => Nodes (My_Node).UART_Port,
Buffer => Msg);
Buffer => Packet);
return Error_Kind'(Error_None);
-- Note: we have no way to know there was an error here
......
This diff is collapsed.
------------------------------------------------------------------------------
-- --
-- PolyORB HI COMPONENTS --
-- --
-- P O L Y O R B _ H I _ D R I V E R S _ S T M 3 2 _ U A R T --
-- --
-- S p e c --
-- --
-- Copyright (C) 2012-2015 ESA & ISAE. --
-- --
-- PolyORB-HI is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. PolyORB-HI is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- PolyORB-HI/Ada is maintained by the TASTE project --
-- (taste-users@lists.tuxfamily.org) --
-- --
------------------------------------------------------------------------------
with PolyORB_HI.Errors;
with PolyORB_HI_Generated.Deployment;
with PolyORB_HI.Streams;
with PolyORB_HI.Utils;
package PolyORB_HI_Drivers_STM32F4_UART is
use PolyORB_HI.Errors;
use PolyORB_HI_Generated.Deployment;
use PolyORB_HI.Streams;
procedure Initialize (Name_Table : PolyORB_HI.Utils.Naming_Table_Type);
procedure Receive;
function Send
(Node : Node_Type;
Message : Stream_Element_Array;
Size : Stream_Element_Offset)
return Error_Kind;
end PolyORB_HI_Drivers_STM32F4_UART;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment