1
1
#![ no_std]
2
2
#![ no_main]
3
- #![ feature( asm, const_fn, lang_items, compiler_builtins_lib) ]
3
+ #![ feature( asm, const_fn, lang_items, compiler_builtins_lib) ]
4
4
5
- extern crate cortexm3;
6
5
extern crate capsules;
7
6
extern crate compiler_builtins;
7
+ extern crate cortexm3;
8
8
#[ allow( unused_imports) ]
9
- #[ macro_use( debug, static_init) ]
9
+ #[ macro_use( debug, static_init) ]
10
10
extern crate kernel;
11
11
extern crate stm32;
12
12
extern crate stm32f1;
@@ -32,27 +32,26 @@ static mut APP_MEMORY: [u8; 10240] = [0; 10240];
32
32
// Actual memory for holding the active process structures.
33
33
static mut PROCESSES : [ Option < kernel:: Process < ' static > > ; NUM_PROCS ] = [ None , None , None , None ] ;
34
34
35
-
36
35
/// A structure representing this platform that holds references to all
37
36
/// capsules for this platform.
38
37
struct NucleoF103 {
39
38
console : & ' static capsules:: console:: Console < ' static , stm32:: usart:: USART > ,
40
- alarm : & ' static capsules:: alarm:: AlarmDriver < ' static ,
41
- VirtualMuxAlarm < ' static ,
42
- stm32:: timer:: AlarmTimer > > ,
39
+ alarm : & ' static capsules:: alarm:: AlarmDriver <
40
+ ' static ,
41
+ VirtualMuxAlarm < ' static , stm32:: timer:: AlarmTimer > ,
42
+ > ,
43
43
button : & ' static capsules:: button:: Button < ' static , stm32:: gpio:: GPIOPin > ,
44
44
gpio : & ' static capsules:: gpio:: GPIO < ' static , stm32:: gpio:: GPIOPin > ,
45
45
led : & ' static capsules:: led:: LED < ' static , stm32:: gpio:: GPIOPin > ,
46
46
ipc : kernel:: ipc:: IPC ,
47
47
}
48
48
49
-
50
49
/// Mapping of integer syscalls to objects that implement syscalls.
51
50
impl Platform for NucleoF103 {
52
51
fn with_driver < F , R > ( & self , driver_num : usize , f : F ) -> R
53
- where F : FnOnce ( Option < & kernel:: Driver > ) -> R
52
+ where
53
+ F : FnOnce ( Option < & kernel:: Driver > ) -> R ,
54
54
{
55
-
56
55
match driver_num {
57
56
capsules:: console:: DRIVER_NUM => f ( Some ( self . console ) ) ,
58
57
capsules:: alarm:: DRIVER_NUM => f ( Some ( self . alarm ) ) ,
@@ -81,75 +80,98 @@ pub unsafe fn reset_handler() {
81
80
82
81
let console = static_init ! (
83
82
capsules:: console:: Console <stm32:: usart:: USART >,
84
- capsules:: console:: Console :: new( & stm32:: usart:: USART2 ,
85
- 115200 ,
86
- & mut capsules:: console:: WRITE_BUF ,
87
- kernel:: Grant :: create( ) ) ) ;
83
+ capsules:: console:: Console :: new(
84
+ & stm32:: usart:: USART2 ,
85
+ 115200 ,
86
+ & mut capsules:: console:: WRITE_BUF ,
87
+ kernel:: Grant :: create( )
88
+ )
89
+ ) ;
88
90
hil:: uart:: UART :: set_client ( & stm32:: usart:: USART2 , console) ;
89
91
stm32:: usart:: USART2 . specify_pins ( & stm32:: gpio:: PA [ 3 ] , & stm32:: gpio:: PA [ 2 ] ) ;
90
92
91
93
// Alarm
92
94
let alarm_timer = & stm32:: timer:: TIMER2 ;
93
95
let mux_alarm = static_init ! (
94
96
MuxAlarm <' static , stm32:: timer:: AlarmTimer >,
95
- MuxAlarm :: new( alarm_timer) ) ;
97
+ MuxAlarm :: new( alarm_timer)
98
+ ) ;
96
99
alarm_timer. configure ( mux_alarm) ;
97
100
let virtual_alarm1 = static_init ! (
98
101
VirtualMuxAlarm <' static , stm32:: timer:: AlarmTimer >,
99
- VirtualMuxAlarm :: new( mux_alarm) ) ;
102
+ VirtualMuxAlarm :: new( mux_alarm)
103
+ ) ;
100
104
let alarm = static_init ! (
101
105
capsules:: alarm:: AlarmDriver <' static , VirtualMuxAlarm <' static , stm32:: timer:: AlarmTimer >>,
102
- capsules:: alarm:: AlarmDriver :: new( virtual_alarm1, kernel:: Grant :: create( ) ) ) ;
106
+ capsules:: alarm:: AlarmDriver :: new( virtual_alarm1, kernel:: Grant :: create( ) )
107
+ ) ;
103
108
virtual_alarm1. set_client ( alarm) ;
104
109
105
110
// LEDs
106
111
let led_pins = static_init ! (
107
112
[ ( & ' static stm32:: gpio:: GPIOPin , capsules:: led:: ActivationMode ) ; 1 ] ,
108
- [ ( & stm32:: gpio:: PA [ 5 ] , capsules:: led:: ActivationMode :: ActiveHigh ) ] ) ;
113
+ [
114
+ (
115
+ & stm32:: gpio:: PA [ 5 ] ,
116
+ capsules:: led:: ActivationMode :: ActiveHigh
117
+ )
118
+ ]
119
+ ) ;
109
120
let led = static_init ! (
110
121
capsules:: led:: LED <' static , stm32:: gpio:: GPIOPin >,
111
- capsules:: led:: LED :: new( led_pins) ) ;
122
+ capsules:: led:: LED :: new( led_pins)
123
+ ) ;
112
124
113
125
// Buttons
114
126
let button_pins = static_init ! (
115
127
[ ( & ' static stm32:: gpio:: GPIOPin , capsules:: button:: GpioMode ) ; 1 ] ,
116
- [ ( & stm32:: gpio:: PC [ 13 ] , capsules:: button:: GpioMode :: LowWhenPressed ) ] ) ;
128
+ [
129
+ (
130
+ & stm32:: gpio:: PC [ 13 ] ,
131
+ capsules:: button:: GpioMode :: LowWhenPressed
132
+ )
133
+ ]
134
+ ) ;
117
135
let button = static_init ! (
118
136
capsules:: button:: Button <' static , stm32:: gpio:: GPIOPin >,
119
- capsules:: button:: Button :: new( button_pins, kernel:: Grant :: create( ) ) ) ;
137
+ capsules:: button:: Button :: new( button_pins, kernel:: Grant :: create( ) )
138
+ ) ;
120
139
for & ( btn, _) in button_pins. iter ( ) {
121
140
btn. set_client ( button) ;
122
141
}
123
142
124
143
// set GPIO driver controlling remaining GPIO pins
125
144
let gpio_pins = static_init ! (
126
- [ & ' static stm32:: gpio:: GPIOPin ; 19 ] , [
127
- // &stm32::gpio::PA[3], // D0 (RX)
128
- // &stm32::gpio::PA[2], // D1 (TX)
129
- & stm32:: gpio:: PA [ 10 ] , // D2
130
- & stm32:: gpio:: PB [ 3 ] , // D3
131
- & stm32:: gpio:: PB [ 5 ] , // D4
132
- & stm32:: gpio:: PB [ 4 ] , // D5
133
- & stm32:: gpio:: PB [ 10 ] , // D6
134
- & stm32:: gpio:: PA [ 8 ] , // D7
135
- & stm32:: gpio:: PA [ 9 ] , // D8
136
- & stm32:: gpio:: PC [ 7 ] , // D9
137
- & stm32:: gpio:: PB [ 6 ] , // D10
138
- & stm32:: gpio:: PA [ 7 ] , // D11
139
- & stm32:: gpio:: PA [ 6 ] , // D12
140
- // &stm32::gpio::PA[5], // D13 (LED)
141
- & stm32:: gpio:: PB [ 9 ] , // D14
142
- & stm32:: gpio:: PB [ 8 ] , // D15
143
- & stm32:: gpio:: PA [ 0 ] , // A0
144
- & stm32:: gpio:: PA [ 1 ] , // A1
145
- & stm32:: gpio:: PA [ 4 ] , // A2
146
- & stm32:: gpio:: PB [ 0 ] , // A3
147
- & stm32:: gpio:: PC [ 1 ] , // A4
148
- & stm32:: gpio:: PC [ 0 ] , // A5
149
- ] ) ;
145
+ [ & ' static stm32:: gpio:: GPIOPin ; 19 ] ,
146
+ [
147
+ // &stm32::gpio::PA[3], // D0 (RX)
148
+ // &stm32::gpio::PA[2], // D1 (TX)
149
+ & stm32:: gpio:: PA [ 10 ] , // D2
150
+ & stm32:: gpio:: PB [ 3 ] , // D3
151
+ & stm32:: gpio:: PB [ 5 ] , // D4
152
+ & stm32:: gpio:: PB [ 4 ] , // D5
153
+ & stm32:: gpio:: PB [ 10 ] , // D6
154
+ & stm32:: gpio:: PA [ 8 ] , // D7
155
+ & stm32:: gpio:: PA [ 9 ] , // D8
156
+ & stm32:: gpio:: PC [ 7 ] , // D9
157
+ & stm32:: gpio:: PB [ 6 ] , // D10
158
+ & stm32:: gpio:: PA [ 7 ] , // D11
159
+ & stm32:: gpio:: PA [ 6 ] , // D12
160
+ // &stm32::gpio::PA[5], // D13 (LED)
161
+ & stm32:: gpio:: PB [ 9 ] , // D14
162
+ & stm32:: gpio:: PB [ 8 ] , // D15
163
+ & stm32:: gpio:: PA [ 0 ] , // A0
164
+ & stm32:: gpio:: PA [ 1 ] , // A1
165
+ & stm32:: gpio:: PA [ 4 ] , // A2
166
+ & stm32:: gpio:: PB [ 0 ] , // A3
167
+ & stm32:: gpio:: PC [ 1 ] , // A4
168
+ & stm32:: gpio:: PC [ 0 ] // A5
169
+ ]
170
+ ) ;
150
171
let gpio = static_init ! (
151
172
capsules:: gpio:: GPIO <' static , stm32:: gpio:: GPIOPin >,
152
- capsules:: gpio:: GPIO :: new( gpio_pins) ) ;
173
+ capsules:: gpio:: GPIO :: new( gpio_pins)
174
+ ) ;
153
175
for pin in gpio_pins. iter ( ) {
154
176
pin. set_client ( gpio) ;
155
177
}
@@ -165,9 +187,7 @@ pub unsafe fn reset_handler() {
165
187
166
188
nucleo. console . initialize ( ) ;
167
189
// Attach the kernel debug interface to this console
168
- let kc = static_init ! (
169
- capsules:: console:: App ,
170
- capsules:: console:: App :: default ( ) ) ;
190
+ let kc = static_init ! ( capsules:: console:: App , capsules:: console:: App :: default ( ) ) ;
171
191
kernel:: debug:: assign_console_driver ( Some ( nucleo. console ) , kc) ;
172
192
173
193
debug ! ( "Initialization complete. Entering main loop ..." ) ;
@@ -178,9 +198,11 @@ pub unsafe fn reset_handler() {
178
198
/// This symbol is defined in the linker script.
179
199
static _sapps: u8 ;
180
200
}
181
- kernel:: process:: load_processes ( & _sapps as * const u8 ,
182
- & mut APP_MEMORY ,
183
- & mut PROCESSES ,
184
- FAULT_RESPONSE ) ;
201
+ kernel:: process:: load_processes (
202
+ & _sapps as * const u8 ,
203
+ & mut APP_MEMORY ,
204
+ & mut PROCESSES ,
205
+ FAULT_RESPONSE ,
206
+ ) ;
185
207
kernel:: main ( & nucleo, & mut chip, & mut PROCESSES , & nucleo. ipc ) ;
186
208
}
0 commit comments