Paparazzi UAS  v5.17_devel-24-g2ae834f
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
void dfu_command_event(void)
Definition: dfu_command.c:36
bool VCOM_check_free_space(uint16_t len)
Checks if buffer free in VCOM buffer.
Definition: usb_ser_hw.c:409
int VCOM_getchar(void)
Reads one character from VCOM port.
Definition: usb_ser_hw.c:386
static const char dfu_command_str[]
Definition: dfu_command.c:33
static int dfu_command_state
Definition: dfu_command.c:34
int VCOM_peekchar(int ofs)
Reads one character from VCOM port without removing it from the queue.
Definition: usb_ser_hw.c:438
int VCOM_check_available(void)
Checks if data available in VCOM buffer.
Definition: usb_ser_hw.c:420