File : s-textio-leon3.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT RUN-TIME COMPONENTS                         --
   4 --                                                                          --
   5 --                       S Y S T E M . T E X T _ I O                        --
   6 --                                                                          --
   7 --                                 B o d y                                  --
   8 --                                                                          --
   9 --          Copyright (C) 1992-2016, Free Software Foundation, Inc.         --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 -- You should have received a copy of the GNU General Public License and    --
  23 -- a copy of the GCC Runtime Library Exception along with this program;     --
  24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  25 -- <http://www.gnu.org/licenses/>.                                          --
  26 --                                                                          --
  27 -- GNAT was originally developed  by the GNAT team at  New York University. --
  28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  Minimal version of Text_IO body for use on LEON3, writes to console
  33 
  34 with System.BB.Board_Parameters;
  35 
  36 package body System.Text_IO is
  37 
  38    -----------
  39    -- Local --
  40    -----------
  41 
  42    UART_Base : constant := System.BB.Board_Parameters.UART_Base;
  43 
  44    type Reserved_24 is array (0 .. 23) of Boolean;
  45    for Reserved_24'Size use 24;
  46    pragma Pack (Reserved_24);
  47 
  48    type FIFO_Count is mod 64;
  49    for FIFO_Count'Size use 6;
  50 
  51    pragma Warnings (Off);
  52    type Parity_Kind is (Even, Odd);
  53 
  54    --  Mapping between bits in a 32-bit register as used in the hardware
  55    --  documentation and bit order as used by Ada. This makes it easier to
  56    --  verify correctness against the AUM. Ranges will need to be reversed,
  57    --  but the compiler will check this.
  58 
  59    Bit00 : constant := 31; Bit01 : constant := 30; Bit02 : constant := 29;
  60    Bit03 : constant := 28; Bit04 : constant := 27; Bit05 : constant := 26;
  61    Bit06 : constant := 25; Bit07 : constant := 24; Bit08 : constant := 23;
  62    Bit09 : constant := 22; Bit10 : constant := 21; Bit11 : constant := 20;
  63    Bit12 : constant := 19; Bit13 : constant := 18; Bit14 : constant := 17;
  64    Bit15 : constant := 16; Bit16 : constant := 15; Bit17 : constant := 14;
  65    Bit18 : constant := 13; Bit19 : constant := 12; Bit20 : constant := 11;
  66    Bit21 : constant := 10; Bit22 : constant := 09; Bit23 : constant := 08;
  67    Bit24 : constant :=  7; Bit25 : constant := 06; Bit26 : constant := 05;
  68    Bit27 : constant :=  4; Bit28 : constant := 03; Bit29 : constant := 02;
  69    Bit30 : constant :=  1; Bit31 : constant := 00;
  70    pragma Warnings (On);
  71 
  72    type UART_Data_Register is
  73       record
  74          FIFO  : Character;
  75          --  Reading and writing accesses receiver resp. transmitter FIFOs
  76 
  77          Reserved : Reserved_24;
  78          --  Not used
  79       end record;
  80 
  81    for UART_Data_Register use
  82       record
  83          Reserved at 0 range Bit31 .. Bit08;
  84          FIFO     at 0 range Bit07 .. Bit00;
  85       end record;
  86 
  87    for UART_Data_Register'Size use 32;
  88 
  89    pragma Suppress_Initialization (UART_Data_Register);
  90 
  91    type Reserved_9 is mod 2**9;
  92    for Reserved_9'Size use 9;
  93 
  94    type UART_Status_Register is
  95       record
  96          Data_Ready                       : Boolean;
  97          Transmitter_Shift_Register_Empty : Boolean;
  98          Transmitter_FIFO_Empty           : Boolean;
  99          Break_Received                   : Boolean;
 100          Overrun                          : Boolean;
 101          Parity_Error                     : Boolean;
 102          Framing_Error                    : Boolean;
 103          Transmitter_FIFO_Half_Full       : Boolean;
 104          Receiver_FIFO_Half_Full          : Boolean;
 105          Transmitter_FIFO_Full            : Boolean;
 106          Receiver_FIFO_Full               : Boolean;
 107          Reserved                         : Reserved_9;
 108          Transmitter_FIFO_Count           : FIFO_Count;
 109          Receiver_FIFO_Count              : FIFO_Count;
 110       end record;
 111 
 112    for UART_Status_Register use
 113       record
 114          Receiver_FIFO_Count              at 0 range Bit31 .. Bit26;
 115          Transmitter_FIFO_Count           at 0 range Bit25 .. Bit20;
 116          Reserved                         at 0 range Bit19 .. Bit11;
 117          Receiver_FIFO_Full               at 0 range Bit10 .. Bit10;
 118          Transmitter_FIFO_Full            at 0 range Bit09 .. Bit09;
 119          Receiver_FIFO_Half_Full          at 0 range Bit08 .. Bit08;
 120          Transmitter_FIFO_Half_Full       at 0 range Bit07 .. Bit07;
 121          Framing_Error                    at 0 range Bit06 .. Bit06;
 122          Parity_Error                     at 0 range Bit05 .. Bit05;
 123          Overrun                          at 0 range Bit04 .. Bit04;
 124          Break_Received                   at 0 range Bit03 .. Bit03;
 125          Transmitter_FIFO_Empty           at 0 range Bit02 .. Bit02;
 126          Transmitter_Shift_Register_Empty at 0 range Bit01 .. Bit01;
 127          Data_Ready                       at 0 range Bit00 .. Bit00;
 128       end record;
 129 
 130    for UART_Status_Register'Size use 32;
 131    pragma Suppress_Initialization (UART_Status_Register);
 132 
 133    UART_1_Data : UART_Data_Register;
 134    pragma Atomic (UART_1_Data);
 135    for UART_1_Data'Address use System'To_Address (UART_Base + 16#00#);
 136 
 137    UART_1_Status : UART_Status_Register;
 138    pragma Atomic (UART_1_Status);
 139    for UART_1_Status'Address use System'To_Address (UART_Base + 16#04#);
 140 
 141    ---------
 142    -- Get --
 143    ---------
 144 
 145    function Get return Character is
 146    begin
 147       --  Will never be called
 148 
 149       raise Program_Error;
 150       return ASCII.NUL;
 151    end Get;
 152 
 153    ----------------
 154    -- Initialize --
 155    ----------------
 156 
 157    procedure Initialize is
 158    begin
 159       Initialized := True;
 160    end Initialize;
 161 
 162    -----------------
 163    -- Is_Rx_Ready --
 164    -----------------
 165 
 166    function Is_Rx_Ready return Boolean is
 167    begin
 168       return False;
 169    end Is_Rx_Ready;
 170 
 171    -----------------
 172    -- Is_Tx_Ready --
 173    -----------------
 174 
 175    function Is_Tx_Ready return Boolean is
 176       UART_Status_Aux : constant UART_Status_Register := UART_1_Status;
 177    begin
 178       return not UART_Status_Aux.Transmitter_FIFO_Full;
 179    end Is_Tx_Ready;
 180 
 181    ---------
 182    -- Put --
 183    ---------
 184 
 185    procedure Put (C : Character) is
 186       UART_Tx : constant UART_Data_Register :=
 187                   (FIFO => C, Reserved => (others => False));
 188    begin
 189       UART_1_Data := UART_Tx;
 190    end Put;
 191 
 192    ----------------------------
 193    -- Use_Cr_Lf_For_New_Line --
 194    ----------------------------
 195 
 196    function Use_Cr_Lf_For_New_Line return Boolean is
 197    begin
 198       return True;
 199    end Use_Cr_Lf_For_New_Line;
 200 end System.Text_IO;