File : s-textio-tms570-sci.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 -- Minimal version of Text_IO body for use on TMS570LS31x, using SCI/LIN
33
34 with Interfaces; use Interfaces;
35
36 package body System.Text_IO is
37
38 SCI_BASE : constant := 16#FFF7_E400#;
39 -- SCI base address
40
41 SCIGCR0 : Unsigned_32;
42 for SCIGCR0'Address use SCI_BASE + 16#00#;
43 pragma Volatile (SCIGCR0);
44 pragma Import (Ada, SCIGCR0);
45
46 SCIGCR1 : Unsigned_32;
47 for SCIGCR1'Address use SCI_BASE + 16#04#;
48 pragma Volatile (SCIGCR1);
49 pragma Import (Ada, SCIGCR1);
50
51 SCIFLR : Unsigned_32;
52 for SCIFLR'Address use SCI_BASE + 16#1C#;
53 pragma Volatile (SCIFLR);
54 pragma Import (Ada, SCIFLR);
55
56 TX_READY : constant := 16#100#;
57 RX_READY : constant := 16#200#;
58
59 BRS : Unsigned_32;
60 for BRS'Address use SCI_BASE + 16#2C#;
61 pragma Volatile (BRS);
62 pragma Import (Ada, BRS);
63
64 SCIFORMAT : Unsigned_32;
65 for SCIFORMAT'Address use SCI_BASE + 16#28#;
66 pragma Volatile (SCIFORMAT);
67 pragma Import (Ada, SCIFORMAT);
68
69 SCIRD : Unsigned_32;
70 for SCIRD'Address use SCI_BASE + 16#34#;
71 pragma Volatile (SCIRD);
72 pragma Import (Ada, SCIRD);
73
74 SCITD : Unsigned_32;
75 for SCITD'Address use SCI_BASE + 16#38#;
76 pragma Volatile (SCITD);
77 pragma Import (Ada, SCITD);
78
79 SCIPIO0 : Unsigned_32;
80 for SCIPIO0'Address use SCI_BASE + 16#3C#;
81 pragma Volatile (SCIPIO0);
82 pragma Import (Ada, SCIPIO0);
83
84 SCIPIO8 : Unsigned_32;
85 for SCIPIO8'Address use SCI_BASE + 16#5C#;
86 pragma Volatile (SCIPIO8);
87 pragma Import (Ada, SCIPIO8);
88
89 ---------
90 -- Get --
91 ---------
92
93 function Get return Character is
94 begin
95 return Character'Val (SCIRD and 16#FF#);
96 end Get;
97
98 ----------------
99 -- Initialize --
100 ----------------
101
102 procedure Initialize is
103 begin
104 -- Bring out of reset
105 SCIGCR0 := 1;
106
107 -- 8n1, enable RX and TX, async, idle-line mode, SWnRST, internal clk
108 -- NOTE: SPNU499A (Nov 2012) is incorrect on COMM MODE: Idle line mode
109 -- value is 0.
110 SCIGCR1 := 16#03_00_00_22#;
111
112 -- Baud rate. PLLCLK=180Mhz, VCLK = PLLCLK / 2
113 declare
114 Baud : constant := 115200;
115 VCLK : constant := 90_000_000;
116 P : constant := VCLK / (16 * Baud) - 1;
117 M : constant := (VCLK / Baud) rem 16;
118 begin
119 BRS := P + M * 2**24;
120 end;
121
122 -- 8 bits
123 SCIFORMAT := 7;
124
125 -- Enable Tx and Rx pins, pull-up
126 SCIPIO0 := 2#110#;
127 SCIPIO8 := 2#110#;
128
129 -- Enable SCI
130 SCIGCR1 := SCIGCR1 or 16#80#;
131
132 Initialized := True;
133 end Initialize;
134
135 -----------------
136 -- Is_Tx_Ready --
137 -----------------
138
139 function Is_Tx_Ready return Boolean is
140 ((SCIFLR and TX_READY) /= 0);
141
142 -----------------
143 -- Is_Rx_Ready --
144 -----------------
145
146 function Is_Rx_Ready return Boolean is
147 ((SCIFLR and RX_READY) /= 0);
148
149 ---------
150 -- Put --
151 ---------
152
153 procedure Put (C : Character) is
154 begin
155 SCITD := Character'Pos (C);
156 end Put;
157
158 ----------------------------
159 -- Use_Cr_Lf_For_New_Line --
160 ----------------------------
161
162 function Use_Cr_Lf_For_New_Line return Boolean is
163 begin
164 return True;
165 end Use_Cr_Lf_For_New_Line;
166 end System.Text_IO;