mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-06 16:49:51 +08:00
Move board reset and entering bootloader to to board_common api
Define modes of reset and way to tell the system to enter the bootloader via an api defined in board_common.h If hardware or simulation deo not support the reset or bootloader API and can define BOARD_HAS_NO_RESET and BOARD_HAS_NO_BOOTLOADER respectivly.
This commit is contained in:
committed by
Lorenz Meier
parent
523688e43c
commit
3692a62c35
@@ -185,6 +185,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
typedef enum board_reset_e {
|
||||
board_reset_normal = 0,
|
||||
board_reset_extended = 1,
|
||||
board_reset_enter_bootloader = 2
|
||||
} board_reset_e;
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
@@ -241,3 +249,30 @@ __EXPORT int board_get_dma_usage(uint16_t *dma_total, uint16_t *dma_used, uint16
|
||||
__EXPORT void board_rc_input(bool invert_on);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_reset
|
||||
*
|
||||
* Description:
|
||||
* All boards my optionally provide this API to reset the board
|
||||
*
|
||||
************************************************************************************/
|
||||
#if defined(BOARD_HAS_NO_RESET)
|
||||
# define board_system_reset(status)
|
||||
#else
|
||||
__EXPORT void board_system_reset(int status) noreturn_function;
|
||||
#endif
|
||||
/************************************************************************************
|
||||
* Name: board_set_bootload_mode
|
||||
*
|
||||
* Description:
|
||||
* All boards my optionally provide this API to enter configure the entry to
|
||||
* boot loade mode on the next system reset.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(BOARD_HAS_NO_BOOTLOADER)
|
||||
# define board_set_bootload_mode(mode)
|
||||
#else
|
||||
__EXPORT int board_set_bootload_mode(board_reset_e mode);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2017 PX4 Development Team. All rights reserved.
|
||||
* Author: @author David Sidrane <david_s5@nscdg.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file board_reset.c
|
||||
* Implementation of STM32 based Board RESET API
|
||||
*/
|
||||
|
||||
#include <px4_config.h>
|
||||
#include <errno.h>
|
||||
#include <stm32_pwr.h>
|
||||
#include <nuttx/board.h>
|
||||
|
||||
|
||||
int board_set_bootload_mode(board_reset_e mode)
|
||||
{
|
||||
uint32_t regvalue = 0;
|
||||
|
||||
switch (mode) {
|
||||
case board_reset_normal:
|
||||
case board_reset_extended:
|
||||
break;
|
||||
|
||||
case board_reset_enter_bootloader:
|
||||
regvalue = 0xb007b007;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
stm32_pwr_enablebkp(true);
|
||||
*(uint32_t *)STM32_BKP_BASE = regvalue;
|
||||
stm32_pwr_enablebkp(false);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void board_system_reset(int status)
|
||||
{
|
||||
board_reset(status);
|
||||
|
||||
while (1);
|
||||
}
|
||||
Reference in New Issue
Block a user