1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/***********************************************************************************************************************
* Copyright (c) 2019 by the authors
*
* Author: André Borrmann
* License: MIT / Appache License 2.0
**********************************************************************************************************************/
//! # Console abstraction
//!
//! This crate provides a console abstraction to enable string output to a configurable output channel.
//! It also provides the convinient macros (``print!`` and ``println!``) to output text that are usually not
//! available in ``[no_std]`` environments. However this crate also provide macros to indicate the severity of the
//! message that shall be printed. Those are ``info!``, ``warn!`` and ``error!``.
//!
//! # Dependencies
//! This crate uses macros to provide formatted strings. This formatting requires a memory allocator to
//! be present (as part of the ``alloc`` crate). So when using this crate provide an allocator such as
//! ``ruspiro_allocator``.
//!
//! # Example
//! To actually set an active output channel you need to provide a structure that implements the ``core::fmt::Write``
//! trait.
//!
//! If this trait has been implemented this structure can be used as actual console. To use it there should be the
//! following code written at the earliest possible point in the main crate of the binary (e.g. the kernel)
//!
//! ```ignore
//! use ruspiro_console::*;
//! use ruspiro_uart::*; // as we demonstrate with the Uart as output device/channel.
//!
//! fn main() {
//! let mut uart = Uart1::new(); // create a new uart struct
//! if uart.initialize(250_000_000, 115_200).is_ok() { // initialize the Uart with fixed core rate and baud rate
//! CONSOLE.with_mut(|cons| cons.replace(uart)); // from this point CONSOLE takes ownership of uart
//! }
//!
//! // if everything went fine uart should be assigned to the console for generic output
//! println!("Console is ready and display's through uart");
//! }
//! ```
//! Setting up the logger will also setup the console to use `print!` and `println!` macros, but also allows the usage
//! of `info!`, `warn!` and `error!` macros from teh `log` crate.
//! ```ignore
//! use ruspiro_console::*;
//! use ruspiro_uart::*; // as we demonstrate with the Uart as output device/channel.
//!
//! fn main() {
//! let mut uart = Uart1::new(); // create a new uart struct
//! if uart.initialize(250_000_000, 115_200).is_ok() { // initialize the Uart with fixed core rate and baud rate
//! init_logger(LevelFilter::Error, uart); // from this point the logger takes ownership of uart
//! }
//!
//! // if everything went fine uart should be assigned to the console for generic output
//! println!("Console is ready and display's through uart");
//! }
//! ```
pub extern crate alloc;
pub use *;
use Box;
use fmt;
pub use ;
use Singleton;
/// initializie the logger using the provided `Writer` as the output channel. This should be called as soon as possible
/// in the bare-metal kernel to enable logging.
///
/// A typical use case would be to initialize an UART and pass this (assuming it implements the `Write` trait to this
/// function. As this function stores the actual writer into a thread safe `Singleton` using atomic operations it need
/// to be ensured atomics are available and can be used. On a Raspberry Pi this means, the MMU need to be configured and
/// enabled first.
static LOGGER: Logger = Logger ;
/// The Console singleton used by print! and println! macros
/// The console can be configured without the `init_logger` function if logging is not required but `print!` and
/// `println` macros only.
pub static CONSOLE: = new;
/// The base printing function hidden behind the print! and println! macro. This function forwards all calls to the
/// generic console which writes the string to the assigned output channel.
/// The representation of the abstract console
/// The default console is a kind of fall back that prints nothing...
;