source: mainline/boot/arch/arm32/src/putchar.c@ 9780584

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9780584 was 7a99507, checked in by Jiri Svoboda <jiri@…>, 9 years ago

Clear up stdint vs stddef in boot, missing includes, etc.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2007 Michal Kebrt
3 * Copyright (c) 2009 Vineeth Pillai
4 * Copyright (c) 2010 Jiri Svoboda
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup arm32boot
32 * @{
33 */
34/** @file
35 * @brief bootloader output logic
36 */
37
38#include <arch/main.h>
39#include <putchar.h>
40#include <stddef.h>
41#include <stdint.h>
42#include <str.h>
43
44#ifdef MACHINE_beaglebone
45
46/** Send a byte to the am335x serial console.
47 *
48 * @param byte Byte to send.
49 */
50static void scons_sendb_bbone(uint8_t byte)
51{
52 volatile uint32_t *thr =
53 (volatile uint32_t *) BBONE_SCONS_THR;
54 volatile uint32_t *ssr =
55 (volatile uint32_t *) BBONE_SCONS_SSR;
56
57 /* Wait until transmitter is empty */
58 while (*ssr & BBONE_TXFIFO_FULL);
59
60 /* Transmit byte */
61 *thr = (uint32_t) byte;
62}
63
64#endif
65
66#ifdef MACHINE_beagleboardxm
67
68/** Send a byte to the amdm37x serial console.
69 *
70 * @param byte Byte to send.
71 */
72static void scons_sendb_bbxm(uint8_t byte)
73{
74 volatile uint32_t *thr =
75 (volatile uint32_t *)BBXM_SCONS_THR;
76 volatile uint32_t *ssr =
77 (volatile uint32_t *)BBXM_SCONS_SSR;
78
79 /* Wait until transmitter is empty. */
80 while ((*ssr & BBXM_THR_FULL) == 1) ;
81
82 /* Transmit byte. */
83 *thr = (uint32_t) byte;
84}
85
86#endif
87
88#ifdef MACHINE_gta02
89
90/** Send a byte to the gta02 serial console.
91 *
92 * @param byte Byte to send.
93 */
94static void scons_sendb_gta02(uint8_t byte)
95{
96 volatile uint32_t *utrstat;
97 volatile uint32_t *utxh;
98
99 utrstat = (volatile uint32_t *) GTA02_SCONS_UTRSTAT;
100 utxh = (volatile uint32_t *) GTA02_SCONS_UTXH;
101
102 /* Wait until transmitter is empty. */
103 while ((*utrstat & S3C24XX_UTXH_TX_EMPTY) == 0)
104 ;
105
106 /* Transmit byte. */
107 *utxh = (uint32_t) byte;
108}
109
110#endif
111
112#ifdef MACHINE_integratorcp
113
114/** Send a byte to the IntegratorCP serial console.
115 *
116 * @param byte Byte to send.
117 */
118static void scons_sendb_icp(uint8_t byte)
119{
120 *((volatile uint8_t *) ICP_SCONS_ADDR) = byte;
121}
122
123#endif
124
125#ifdef MACHINE_raspberrypi
126
127static int raspi_init;
128
129static inline void write32(uint32_t addr, uint32_t data)
130{
131 *(volatile uint32_t *)(addr) = data;
132}
133
134static inline uint32_t read32(uint32_t addr)
135{
136 return *(volatile uint32_t *)(addr);
137}
138
139static void scons_init_raspi(void)
140{
141 write32(BCM2835_UART0_CR, 0x0); /* Disable UART */
142 write32(BCM2835_UART0_ICR, 0x7f); /* Clear interrupts */
143 write32(BCM2835_UART0_IBRD, 1); /* Set integer baud rate */
144 write32(BCM2835_UART0_FBRD, 40); /* Set fractional baud rate */
145 write32(BCM2835_UART0_LCRH,
146 BCM2835_UART0_LCRH_FEN | /* Enable FIFOs */
147 BCM2835_UART0_LCRH_WL8); /* Word length: 8 */
148 write32(BCM2835_UART0_CR,
149 BCM2835_UART0_CR_UARTEN | /* Enable UART */
150 BCM2835_UART0_CR_TXE | /* Enable TX */
151 BCM2835_UART0_CR_RXE); /* Enable RX */
152}
153
154static void scons_sendb_raspi(uint8_t byte)
155{
156 if (!raspi_init) {
157 scons_init_raspi();
158 raspi_init = 1;
159 }
160
161 while (read32(BCM2835_UART0_FR) & BCM2835_UART0_FR_TXFF);
162
163 write32(BCM2835_UART0_DR, byte);
164}
165#endif
166
167/** Send a byte to the serial console.
168 *
169 * @param byte Byte to send.
170 */
171static void scons_sendb(uint8_t byte)
172{
173#ifdef MACHINE_beaglebone
174 scons_sendb_bbone(byte);
175#endif
176#ifdef MACHINE_beagleboardxm
177 scons_sendb_bbxm(byte);
178#endif
179#ifdef MACHINE_gta02
180 scons_sendb_gta02(byte);
181#endif
182#ifdef MACHINE_integratorcp
183 scons_sendb_icp(byte);
184#endif
185#ifdef MACHINE_raspberrypi
186 scons_sendb_raspi(byte);
187#endif
188}
189
190/** Display a character
191 *
192 * @param ch Character to display
193 */
194void putchar(const wchar_t ch)
195{
196 if (ch == '\n')
197 scons_sendb('\r');
198
199 if (ascii_check(ch))
200 scons_sendb((uint8_t) ch);
201 else
202 scons_sendb(U_SPECIAL);
203}
204
205/** @}
206 */
Note: See TracBrowser for help on using the repository browser.