Paparazzi UAS
v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerator
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
m
n
p
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
v
w
z
Enumerator
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
usbStorage.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2014-2015 Gautier Hattenberger, Alexandre Bustico
3
*
4
* This file is part of paparazzi.
5
*
6
* paparazzi is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* paparazzi is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with paparazzi; see the file COPYING. If not, write to
18
* the Free Software Foundation, 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
20
*/
21
22
/*
23
* @file modules/loggers/sdlog_chibios/usbStorage.c
24
*
25
*/
26
27
#include <ch.h>
28
#include <hal.h>
29
#include "
usb_msd.h
"
30
#include "
usbStorage.h
"
31
#include "
modules/loggers/sdlog_chibios.h
"
32
#include <stdio.h>
33
#include <string.h>
34
#include "
main_chibios.h
"
35
#include "
mcu.h
"
36
#include "
mcu_periph/sdio.h
"
37
#include "
led.h
"
38
39
/* Default disable USB on boot enable */
40
#ifndef SDLOG_USB_VBUS_BOOT
41
#define SDLOG_USB_VBUS_BOOT false
42
#endif
43
44
static
void
thdUsbStorage
(
void
*arg);
45
static
thread_t
*
usbStorageThreadPtr
=
NULL
;
46
/* USB mass storage driver */
47
static
bool
isRunning
=
false
;
48
float
usb_storage_status
= 0;
49
static
BSEMAPHORE_DECL
(
bs_start_msd
,
true
);
50
51
/* Turns on a LED when there is I/O activity on the USB port */
52
static
void
usbActivity
(
bool
active
__attribute__
((unused)))
53
{
54
#ifdef SDLOG_USB_LED
55
if
(active) {
56
LED_ON
(
SDLOG_USB_LED
);
57
}
else
{
58
LED_OFF
(
SDLOG_USB_LED
);
59
}
60
#endif
61
}
52
static
void
usbActivity
(
bool
active
__attribute__
((unused))) {
…
}
62
63
/* USB mass storage configuration */
64
static
USBMassStorageConfig
msdConfig
= {
65
&
USBD1
,
66
(
BaseBlockDevice
*) &
SDLOG_SDIO
,
67
USB_MS_DATA_EP
,
68
&
usbActivity
,
69
"Pprz_sd"
,
70
"AutoPilot"
,
71
"0.2"
72
};
64
static
USBMassStorageConfig
msdConfig
= {
…
};
73
74
75
static
THD_WORKING_AREA
(
waThdUsbStorage
, 4096);
76
void
usbStorageStartPolling
(
void
)
77
{
78
usbStorageThreadPtr
=
chThdCreateStatic
(
waThdUsbStorage
,
sizeof
(
waThdUsbStorage
),
79
NORMALPRIO
+ 2,
thdUsbStorage
,
NULL
);
80
81
}
76
void
usbStorageStartPolling
(
void
) {
…
}
82
83
84
void
usbStorageWaitForDeconnexion
(
void
)
85
{
86
if
(
usbStorageThreadPtr
!=
NULL
) {
87
chThdWait
(
usbStorageThreadPtr
);
88
}
89
usbStorageThreadPtr
=
NULL
;
90
}
84
void
usbStorageWaitForDeconnexion
(
void
) {
…
}
91
92
void
usbStorageStop
(
void
)
93
{
94
if
(
usbStorageThreadPtr
!=
NULL
) {
95
chThdTerminate
(
usbStorageThreadPtr
);
96
}
97
}
92
void
usbStorageStop
(
void
) {
…
}
98
99
100
static
void
thdUsbStorage
(
void
*arg)
101
{
102
(
void
) arg;
103
104
chRegSetThreadName
(
"UsbStorage:polling"
);
105
event_listener_t
connected;
106
107
#if SDLOG_USB_VBUS_BOOT
108
// Enable usb power with boot
109
if
(
palReadPad
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
) ==
PAL_LOW
)
110
#endif
111
112
{
113
#if HAL_USE_SERIAL_USB
114
// serial usb is used, so the usb vbus detection can't be used
115
chBSemWait
(&
bs_start_msd
);
116
#else
117
palEnablePadEvent
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
,
PAL_EVENT_MODE_BOTH_EDGES
);
118
// wait transition to HIGH with rebound management
119
do
{
120
palWaitPadTimeout
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
,
TIME_INFINITE
);
121
chThdSleepMilliseconds
(10);
122
}
while
(
palReadPad
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
) ==
PAL_LOW
);
123
124
#endif
125
}
126
127
isRunning
=
true
;
128
usb_storage_status
= 1;
129
chRegSetThreadName
(
"UsbStorage:connected"
);
130
131
/* Stop the logs*/
132
// it's not a powerloss, wa have time to flush the ram buffer
133
sdlog_chibios_finish
(
true
);
134
135
136
/* connect sdcard sdc interface sdio */
137
if
(
sdio_connect
(&
SDLOG_SDIO
) ==
false
) {
138
chThdExit
(
MSG_TIMEOUT
);
139
}
140
141
/* initialize the USB mass storage driver */
142
init_msd_driver
(
NULL
, &
msdConfig
);
143
144
/* wait for a real usb storage connexion before shutting down autopilot */
145
msd_register_evt_connected
(&connected,
EVENT_MASK
(1));
146
chEvtWaitOne
(
EVENT_MASK
(1));
147
148
/* stop autopilot */
149
pprz_terminate_autopilot_threads
();
150
151
/* wait until usb-storage is unmount and usb cable is unplugged*/
152
while
(!
chThdShouldTerminateX
() &&
palReadPad
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
)) {
153
chThdSleepMilliseconds
(10);
154
}
155
156
deinit_msd_driver
();
157
158
chThdSleepMilliseconds
(500);
159
160
mcu_reboot
(
MCU_REBOOT_FAST
);
161
}
100
static
void
thdUsbStorage
(
void
*arg) {
…
}
162
163
bool
usbStorageIsItRunning
(
void
)
164
{
165
return
isRunning
;
166
}
163
bool
usbStorageIsItRunning
(
void
) {
…
}
167
168
/*
169
* Enable USB storage only if USB is plugged.
170
*/
171
void
usbStorage_enable_usb_storage
(
float
e) {
172
if
(e > 0.5 &&
palReadPad
(
SDLOG_USB_VBUS_PORT
,
SDLOG_USB_VBUS_PIN
) ==
PAL_HIGH
) {
173
chBSemSignal
(&
bs_start_msd
);
174
}
else
{
175
usb_storage_status
= 0;
176
}
177
}
171
void
usbStorage_enable_usb_storage
(
float
e) {
…
}
SDLOG_USB_VBUS_PIN
#define SDLOG_USB_VBUS_PIN
Definition
board.h:538
SDLOG_USB_LED
#define SDLOG_USB_LED
Definition
board.h:536
SDLOG_USB_VBUS_PORT
#define SDLOG_USB_VBUS_PORT
Definition
board.h:537
LED_ON
#define LED_ON(i)
Definition
led_hw.h:51
LED_OFF
#define LED_OFF(i)
Definition
led_hw.h:52
mcu_reboot
void mcu_reboot(enum reboot_state_t reboot_state)
Reboot the MCU.
Definition
mcu_arch.c:206
MCU_REBOOT_FAST
@ MCU_REBOOT_FAST
Fast reboot (skip bootloader)
Definition
mcu.h:45
led.h
arch independent LED (Light Emitting Diodes) API
pprz_terminate_autopilot_threads
void pprz_terminate_autopilot_threads(void)
Terminate all autopilot threads Wait until proper stop.
Definition
main_chibios.c:171
main_chibios.h
foo
uint16_t foo
Definition
main_demo5.c:58
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
sdio.h
arch independent SDIO API
sdio_connect
bool sdio_connect(SDCDriver *sdc)
Connect a SD card on SDIO peripheral.
Definition
sdio_arch.c:48
sdlog_chibios_finish
void sdlog_chibios_finish(const bool flush)
Definition
sdlog_chibios.c:207
sdlog_chibios.h
USBMassStorageConfig
Driver configuration structure.
Definition
usb_msd.h:123
thdUsbStorage
static void thdUsbStorage(void *arg)
Definition
usbStorage.c:100
usbStorageStartPolling
void usbStorageStartPolling(void)
Definition
usbStorage.c:76
usb_storage_status
float usb_storage_status
Definition
usbStorage.c:48
usbStorageThreadPtr
static thread_t * usbStorageThreadPtr
Definition
usbStorage.c:45
msdConfig
static USBMassStorageConfig msdConfig
Definition
usbStorage.c:64
isRunning
static bool isRunning
Definition
usbStorage.c:47
THD_WORKING_AREA
static THD_WORKING_AREA(waThdUsbStorage, 4096)
usbStorageWaitForDeconnexion
void usbStorageWaitForDeconnexion(void)
Definition
usbStorage.c:84
usbStorageIsItRunning
bool usbStorageIsItRunning(void)
Definition
usbStorage.c:163
usbActivity
static void usbActivity(bool active)
Definition
usbStorage.c:52
usbStorage_enable_usb_storage
void usbStorage_enable_usb_storage(float e)
Definition
usbStorage.c:171
BSEMAPHORE_DECL
static BSEMAPHORE_DECL(bs_start_msd, true)
usbStorageStop
void usbStorageStop(void)
Definition
usbStorage.c:92
usbStorage.h
init_msd_driver
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
Definition
usb_msd.c:1126
msd_register_evt_connected
void msd_register_evt_connected(event_listener_t *elp, eventmask_t mask)
register connected event source in local event mask
Definition
usb_msd.c:1144
deinit_msd_driver
void deinit_msd_driver(void)
Definition
usb_msd.c:1121
usb_msd.h
USB_MS_DATA_EP
#define USB_MS_DATA_EP
Definition
usb_msd.h:40
sw
airborne
modules
loggers
sdlog_chibios
usbStorage.c
Generated on Fri Apr 4 2025 14:56:51 for Paparazzi UAS by
1.9.8