File : s-textio-p55.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-2013, 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 with System;
  33 
  34 with Interfaces;
  35 
  36 package body System.Text_IO is
  37    use Interfaces;
  38 
  39    ESCI_CR1 : Unsigned_32;
  40    for ESCI_CR1'Address use 16#FFFB_0000# + 0;
  41    pragma Import (Ada, ESCI_CR1);
  42    pragma Volatile (ESCI_CR1);
  43 
  44    ESCI_CR2 : Unsigned_16;
  45    for ESCI_CR2'Address use 16#FFFB_0000# + 4;
  46    pragma Import (Ada, ESCI_CR2);
  47    pragma Volatile (ESCI_CR2);
  48 
  49    ESCI_DR : Unsigned_16;
  50    for ESCI_DR'Address use 16#FFFB_0000# + 6;
  51    pragma Import (Ada, ESCI_DR);
  52    pragma Volatile (ESCI_DR);
  53 
  54    ESCI_SR : Unsigned_32;
  55    for ESCI_SR'Address use 16#FFFB_0000# + 8;
  56    pragma Import (Ada, ESCI_SR);
  57    pragma Volatile (ESCI_SR);
  58 
  59    RDRF : constant := 16#2000_0000#;
  60    TDRE : constant := 16#8000_0000#;
  61    --  ESCI_SR bits
  62 
  63    SIU_PCR89 : Unsigned_16;
  64    for SIU_PCR89'Address use 16#C3F9_00F2#;
  65    pragma Import (Ada, SIU_PCR89);
  66    pragma Volatile (SIU_PCR89);
  67 
  68    SIU_PCR90 : Unsigned_16;
  69    for SIU_PCR90'Address use 16#C3F9_00F4#;
  70    pragma Import (Ada, SIU_PCR90);
  71    pragma Volatile (SIU_PCR90);
  72 
  73    ---------
  74    -- Get --
  75    ---------
  76 
  77    function Get return Character is
  78    begin
  79       --  Clear rdrf (w1c bit)
  80       ESCI_SR := RDRF;
  81 
  82       --  Send the character
  83 
  84       return Character'Val (ESCI_DR and 16#FF#);
  85    end Get;
  86 
  87    ----------------
  88    -- Initialize --
  89    ----------------
  90 
  91    procedure Initialize is
  92    begin
  93       --  Enable ESCI module
  94       ESCI_CR2 := 16#2000#;
  95 
  96       --  Enable Tx & Rx, 8n1, keep baud rate.
  97       --  Note that br = Fsys/(16 * baud)
  98       ESCI_CR1 := (ESCI_CR1 and 16#FFFF_0000#) or 16#000C#;
  99 
 100       --  Configure pads, enable txda and rxda
 101       SIU_PCR89 := 16#400#;
 102       SIU_PCR90 := 16#400#;
 103 
 104       Initialized := True;
 105    end Initialize;
 106 
 107    -----------------
 108    -- Is_Rx_Ready --
 109    -----------------
 110 
 111    function Is_Rx_Ready return Boolean is
 112    begin
 113       return (ESCI_SR and RDRF) /= 0;
 114    end Is_Rx_Ready;
 115 
 116    -----------------
 117    -- Is_Tx_Ready --
 118    -----------------
 119 
 120    function Is_Tx_Ready return Boolean is
 121    begin
 122       return (ESCI_SR and TDRE) /= 0;
 123    end Is_Tx_Ready;
 124 
 125    ---------
 126    -- Put --
 127    ---------
 128 
 129    procedure Put (C : Character) is
 130    begin
 131       --  Clear tdre (w1c bit)
 132       ESCI_SR := TDRE;
 133 
 134       --  Send the character
 135 
 136       ESCI_DR := Character'Pos (C);
 137    end Put;
 138 
 139    ----------------------------
 140    -- Use_Cr_Lf_For_New_Line --
 141    ----------------------------
 142 
 143    function Use_Cr_Lf_For_New_Line return Boolean is
 144    begin
 145       return True;
 146    end Use_Cr_Lf_For_New_Line;
 147 
 148 end System.Text_IO;