mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
AP_HAL_ChibiOS: refresh SD crash dump hardware state
This commit is contained in:
@@ -708,6 +708,7 @@ static void spi_prepare_peripheral()
|
||||
bouncebuffer_abort(sd_spi_bouncebuffer);
|
||||
sd_spi_device->crashdump_deassert_all_cs();
|
||||
spi_configure(sd_spi_low_config1, sd_spi_low_config2);
|
||||
sd_spi_device->crashdump_restore_sck();
|
||||
}
|
||||
|
||||
static bool spi_reconnect_card()
|
||||
@@ -1150,6 +1151,35 @@ static bool write_blocks(uint32_t sector, uint32_t blocks)
|
||||
|
||||
#endif // CRASHDUMP_SD_SPI
|
||||
|
||||
/* Refresh the bounce buffer that normal transfers may have resized. */
|
||||
static bool refresh_dma_buffer()
|
||||
{
|
||||
struct bouncebuffer_t *bouncebuffer;
|
||||
#if CRASHDUMP_SD_SPI
|
||||
bouncebuffer = sd_spi_bouncebuffer;
|
||||
#else
|
||||
bouncebuffer = sd_sdcp == nullptr ? nullptr : sd_sdcp->bouncebuffer;
|
||||
#endif
|
||||
|
||||
if (bouncebuffer == nullptr) {
|
||||
sd_dma_buf = nullptr;
|
||||
sd_dma_buf_size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *const dma_buf = bouncebuffer->dma_buf;
|
||||
const uint32_t size = bouncebuffer->size & ~(MMCSD_BLOCK_SIZE - 1U);
|
||||
if (dma_buf == nullptr || size < MMCSD_BLOCK_SIZE) {
|
||||
sd_dma_buf = nullptr;
|
||||
sd_dma_buf_size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
sd_dma_buf = dma_buf;
|
||||
sd_dma_buf_size = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t accumulator_capacity()
|
||||
{
|
||||
uint32_t sector;
|
||||
@@ -1404,7 +1434,7 @@ uint32_t crashdump_sd_max_size()
|
||||
|
||||
bool crashdump_sd_start()
|
||||
{
|
||||
if (!sd_is_ready || !sd_fault_write_available || sd_dma_buf == nullptr
|
||||
if (!sd_is_ready || !sd_fault_write_available
|
||||
#if CRASHDUMP_SD_SPI
|
||||
|| sd_mmcp == nullptr || sd_spi_device == nullptr || sd_spip == nullptr
|
||||
#else
|
||||
@@ -1419,6 +1449,9 @@ bool crashdump_sd_start()
|
||||
if (!abort_transfer()) {
|
||||
return false;
|
||||
}
|
||||
if (!refresh_dma_buffer()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sd_write_offset = 0;
|
||||
accumulator_offset = 0;
|
||||
|
||||
@@ -414,9 +414,7 @@ void SPIBus::start_peripheral(void)
|
||||
spi_started = true;
|
||||
}
|
||||
|
||||
/*
|
||||
restore the SPI clock and SCK pin without using RTOS or DMA services
|
||||
*/
|
||||
/* restore the SPI clock without using RTOS or DMA services */
|
||||
void SPIBus::crashdump_prepare_peripheral(void)
|
||||
{
|
||||
const auto &sbus = spi_devices[bus];
|
||||
@@ -450,8 +448,13 @@ void SPIBus::crashdump_prepare_peripheral(void)
|
||||
rccEnableSPI6(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* restore SCK after the crash dump path has configured the SPI peripheral */
|
||||
void SPIBus::crashdump_restore_sck(void)
|
||||
{
|
||||
#if HAL_SPI_SCK_SAVE_RESTORE
|
||||
palSetLineMode(sbus.sck_line, sck_mode);
|
||||
palSetLineMode(spi_devices[bus].sck_line, sck_mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
// restore hardware state needed by the polled crash dump path
|
||||
void crashdump_prepare_peripheral(void);
|
||||
void crashdump_restore_sck(void);
|
||||
|
||||
private:
|
||||
bool spi_started;
|
||||
@@ -156,6 +157,10 @@ public:
|
||||
{
|
||||
bus.crashdump_prepare_peripheral();
|
||||
}
|
||||
void crashdump_restore_sck()
|
||||
{
|
||||
bus.crashdump_restore_sck();
|
||||
}
|
||||
|
||||
ioline_t get_chip_select_line() const { return device_desc.pal_line; }
|
||||
struct bouncebuffer_t *prepare_crashdump_buffer(uint32_t size) {
|
||||
|
||||
Reference in New Issue
Block a user