Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
dfu_command.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Tom van Dijk
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
30 
31 #include "mcu_arch.h"
32 
33 static const char dfu_command_str[] = "#\nbl\n"; // Note: same command resets betaflight to DFU
34 static int dfu_command_state = 0;
35 
36 void dfu_command_event(void) {
37  // Search fifo for command string
38  for (int i = 0; i < VCOM_check_available(); ++i) {
41  if (dfu_command_str[dfu_command_state] == '\0') { // end of command string
42  reset_to_dfu();
43  }
44  } else {
46  }
47  }
48 
49  // Prevent fifo blocking if bytes are not consumed by other process
50  if (!VCOM_check_free_space(1)) {
51  while (VCOM_check_available()) {
52  VCOM_getchar();
53  }
54  }
55 }
56 
57 
VCOM_check_available
int VCOM_check_available(void)
Checks if data available in VCOM buffer.
Definition: usb_ser_hw.c:420
VCOM_check_free_space
bool VCOM_check_free_space(uint16_t len)
Checks if buffer free in VCOM buffer.
Definition: usb_ser_hw.c:409
VCOM_getchar
int VCOM_getchar(void)
Reads one character from VCOM port.
Definition: usb_ser_hw.c:386
dfu_command_state
static int dfu_command_state
Definition: dfu_command.c:34
dfu_command.h
VCOM_peekchar
int VCOM_peekchar(int ofs)
Reads one character from VCOM port without removing it from the queue.
Definition: usb_ser_hw.c:438
dfu_command_str
static const char dfu_command_str[]
Definition: dfu_command.c:33
dfu_command_event
void dfu_command_event(void)
Definition: dfu_command.c:36