File : s-textio-sam4s.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-2014, 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 SAM4S, using UART1
33
34 with System.SAM4S; use System.SAM4S;
35
36 package body System.Text_IO is
37
38 Baudrate : constant := 115_200;
39 -- Bitrate to use
40
41 ---------
42 -- Get --
43 ---------
44
45 function Get return Character is
46 (Character'Val (UART1.UART_RHR and 16#FF#));
47
48 ----------------
49 -- Initialize --
50 ----------------
51
52 procedure Initialize is
53 PB2 : constant := 2 ** 2; -- RX line
54 PB3 : constant := 2 ** 3; -- TX line
55
56 Uart_Ports : constant := PB2 + PB3;
57
58 begin
59 Initialized := True;
60
61 -- Init uart1
62
63 -- Power-up clocks
64
65 PMC.PMC_PCER0 := 2 ** UART1_ID + 2 ** PIOB_ID;
66
67 -- Setup IO pins
68
69 PIOB.PDR := Uart_Ports;
70 PIOB.ODR := Uart_Ports;
71 PIOB.PUER := PB3;
72 PIOB.MDDR := Uart_Ports;
73 PIOB.ABCDSR1 := PIOB.ABCDSR1 and not Uart_Ports;
74 PIOB.ABCDSR2 := PIOB.ABCDSR2 and not Uart_Ports;
75
76 UART1.UART_BRGR := 120_000_000 / (16 * Baudrate);
77 UART1.UART_MR := UART_MR.CHMODE_NORMAL or UART_MR.PAR_NO;
78 UART1.UART_CR := UART_CR.TXEN or UART_CR.RXEN;
79 end Initialize;
80
81 -----------------
82 -- Is_Tx_Ready --
83 -----------------
84
85 function Is_Tx_Ready return Boolean is
86 ((UART1.UART_SR and UART_SR.TXRDY) /= 0);
87
88 -----------------
89 -- Is_Rx_Ready --
90 -----------------
91
92 function Is_Rx_Ready return Boolean is
93 ((UART1.UART_SR and UART_SR.RXRDY) /= 0);
94
95 ---------
96 -- Put --
97 ---------
98
99 procedure Put (C : Character) is
100 begin
101 UART1.UART_THR := Character'Pos (C);
102 end Put;
103
104 ----------------------------
105 -- Use_Cr_Lf_For_New_Line --
106 ----------------------------
107
108 function Use_Cr_Lf_For_New_Line return Boolean is (True);
109 end System.Text_IO;