2018-01-05 02:19:51 -04:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-20 10:31:12 -03:00
|
|
|
*
|
2018-01-05 02:19:51 -04:00
|
|
|
* Code by Andrew Tridgell and Siddharth Bharat Purohit
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include "AP_HAL_ChibiOS_Namespace.h"
|
2018-08-07 03:39:42 -03:00
|
|
|
#include "AP_HAL_ChibiOS.h"
|
2018-12-08 22:34:39 -04:00
|
|
|
#include <ch.h>
|
2024-04-06 13:11:57 -03:00
|
|
|
#include <AP_Logger/AP_Logger_config.h>
|
2018-01-05 02:19:51 -04:00
|
|
|
|
2021-01-16 01:01:04 -04:00
|
|
|
class ExpandingString;
|
|
|
|
|
|
|
|
#ifndef HAL_ENABLE_SAVE_PERSISTENT_PARAMS
|
|
|
|
// on F7 and H7 we will try to save key persistent parameters at the
|
|
|
|
// end of the bootloader sector. This enables temperature calibration
|
|
|
|
// data to be saved persistently in the factory
|
2022-08-15 04:00:18 -03:00
|
|
|
#define HAL_ENABLE_SAVE_PERSISTENT_PARAMS (defined(STM32F7) || defined(STM32H7))
|
2021-01-16 01:01:04 -04:00
|
|
|
#endif
|
|
|
|
|
2018-01-13 00:02:05 -04:00
|
|
|
class ChibiOS::Util : public AP_HAL::Util {
|
2018-01-05 02:19:51 -04:00
|
|
|
public:
|
2018-01-28 14:31:21 -04:00
|
|
|
static Util *from(AP_HAL::Util *util) {
|
|
|
|
return static_cast<Util*>(util);
|
|
|
|
}
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
uint32_t available_memory() override;
|
|
|
|
|
2024-01-14 20:34:04 -04:00
|
|
|
// get path to custom defaults file for AP_Param
|
|
|
|
const char* get_custom_defaults_file() const override {
|
|
|
|
return "@ROMFS/defaults.parm";
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:18:28 -04:00
|
|
|
// Special Allocation Routines
|
2018-07-18 21:38:13 -03:00
|
|
|
void *malloc_type(size_t size, AP_HAL::Util::Memory_Type mem_type) override;
|
|
|
|
void free_type(void *ptr, size_t size, AP_HAL::Util::Memory_Type mem_type) override;
|
2018-01-09 17:18:28 -04:00
|
|
|
|
2024-07-05 20:05:51 -03:00
|
|
|
#if ENABLE_HEAP
|
2018-12-08 22:34:39 -04:00
|
|
|
// heap functions, note that a heap once alloc'd cannot be dealloc'd
|
2019-08-13 22:00:17 -03:00
|
|
|
virtual void *allocate_heap_memory(size_t size) override;
|
2022-12-22 18:50:34 -04:00
|
|
|
virtual void *heap_realloc(void *heap, void *ptr, size_t old_size, size_t new_size) override;
|
2020-03-16 04:22:18 -03:00
|
|
|
virtual void *std_realloc(void *ptr, size_t new_size) override;
|
2018-12-08 22:34:39 -04:00
|
|
|
#endif // ENABLE_HEAP
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
/*
|
|
|
|
return state of safety switch, if applicable
|
|
|
|
*/
|
|
|
|
enum safety_state safety_switch_state(void) override;
|
|
|
|
|
2018-06-29 04:54:51 -03:00
|
|
|
// get system ID as a string
|
2022-09-18 14:11:05 -03:00
|
|
|
bool get_system_id(char buf[50]) override;
|
2018-09-28 12:30:48 -03:00
|
|
|
bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
|
|
|
|
|
2021-04-03 19:00:38 -03:00
|
|
|
bool toneAlarm_init(uint8_t types) override;
|
2022-02-12 17:55:17 -04:00
|
|
|
#if HAL_USE_PWM == TRUE
|
|
|
|
bool toneAlarm_init(const PWMConfig& pwm_cfg, PWMDriver* pwm_drv, pwmchannel_t chan, bool active_high);
|
|
|
|
#endif
|
2018-07-27 04:12:26 -03:00
|
|
|
void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override;
|
2021-04-03 19:00:38 -03:00
|
|
|
static uint8_t _toneAlarm_types;
|
2018-02-01 11:25:03 -04:00
|
|
|
|
2019-04-11 06:51:10 -03:00
|
|
|
// return true if the reason for the reboot was a watchdog reset
|
2019-04-19 22:25:18 -03:00
|
|
|
bool was_watchdog_reset() const override;
|
2019-04-19 21:28:15 -03:00
|
|
|
|
2020-03-29 19:27:34 -03:00
|
|
|
#if CH_DBG_ENABLE_STACK_CHECK == TRUE
|
2020-03-27 17:29:12 -03:00
|
|
|
// request information on running threads
|
2020-12-30 02:44:19 -04:00
|
|
|
void thread_info(ExpandingString &str) override;
|
2020-03-29 19:27:34 -03:00
|
|
|
#endif
|
2020-11-21 12:00:11 -04:00
|
|
|
#if CH_CFG_USE_SEMAPHORES
|
|
|
|
// request information on dma contention
|
2020-12-30 02:44:19 -04:00
|
|
|
void dma_info(ExpandingString &str) override;
|
2020-11-21 12:00:11 -04:00
|
|
|
#endif
|
2021-01-22 06:32:30 -04:00
|
|
|
#if CH_CFG_USE_HEAP == TRUE
|
|
|
|
void mem_info(ExpandingString &str) override;
|
|
|
|
#endif
|
2021-01-16 01:01:04 -04:00
|
|
|
|
|
|
|
#if HAL_ENABLE_SAVE_PERSISTENT_PARAMS
|
|
|
|
// apply persistent parameters to current parameters
|
|
|
|
void apply_persistent_params(void) const;
|
|
|
|
#endif
|
|
|
|
|
2021-01-16 18:22:29 -04:00
|
|
|
#if HAL_ENABLE_SAVE_PERSISTENT_PARAMS
|
|
|
|
// save/load key persistent parameters in bootloader sector
|
|
|
|
bool load_persistent_params(ExpandingString &str) const override;
|
2023-05-26 20:02:50 -03:00
|
|
|
bool get_persistent_param_by_name(const char *name, char* value, size_t& len) const override;
|
2021-01-16 18:22:29 -04:00
|
|
|
#endif
|
2022-01-08 06:56:52 -04:00
|
|
|
#if HAL_UART_STATS_ENABLED
|
2020-12-05 15:16:27 -04:00
|
|
|
// request information on uart I/O
|
2024-03-15 11:20:43 -03:00
|
|
|
void uart_info(ExpandingString &str) override;
|
2024-04-06 13:11:57 -03:00
|
|
|
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
// Log UART message for each serial port
|
|
|
|
void uart_log() override;
|
2022-01-08 06:56:52 -04:00
|
|
|
#endif
|
2024-04-06 13:11:57 -03:00
|
|
|
#endif // HAL_UART_STATS_ENABLED
|
|
|
|
|
2022-02-10 10:42:33 -04:00
|
|
|
#if HAL_USE_PWM == TRUE
|
|
|
|
void timer_info(ExpandingString &str) override;
|
|
|
|
#endif
|
2021-10-06 02:37:09 -03:00
|
|
|
// returns random values
|
|
|
|
bool get_random_vals(uint8_t* data, size_t size) override;
|
|
|
|
|
|
|
|
// returns true random values
|
|
|
|
bool get_true_random_vals(uint8_t* data, size_t size, uint32_t timeout_us) override;
|
|
|
|
|
2021-10-24 18:09:18 -03:00
|
|
|
// set armed state
|
|
|
|
void set_soft_armed(const bool b) override;
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
private:
|
2022-02-12 17:55:17 -04:00
|
|
|
#if HAL_USE_PWM == TRUE
|
2018-07-24 22:29:44 -03:00
|
|
|
struct ToneAlarmPwmGroup {
|
|
|
|
pwmchannel_t chan;
|
|
|
|
PWMConfig pwm_cfg;
|
|
|
|
PWMDriver* pwm_drv;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ToneAlarmPwmGroup _toneAlarm_pwm_group;
|
2018-02-09 23:55:22 -04:00
|
|
|
#endif
|
2018-01-05 02:19:51 -04:00
|
|
|
|
2018-06-14 02:31:33 -03:00
|
|
|
/*
|
|
|
|
set HW RTC in UTC microseconds
|
|
|
|
*/
|
|
|
|
void set_hw_rtc(uint64_t time_utc_usec) override;
|
|
|
|
|
|
|
|
/*
|
|
|
|
get system clock in UTC microseconds
|
|
|
|
*/
|
|
|
|
uint64_t get_hw_rtc() const override;
|
2023-04-19 20:32:32 -03:00
|
|
|
#if AP_BOOTLOADER_FLASHING_ENABLED
|
2019-10-24 23:15:25 -03:00
|
|
|
FlashBootloader flash_bootloader() override;
|
2018-08-29 10:16:17 -03:00
|
|
|
#endif
|
2018-12-08 22:34:39 -04:00
|
|
|
|
2024-07-05 20:05:51 -03:00
|
|
|
#if ENABLE_HEAP
|
2018-12-08 22:34:39 -04:00
|
|
|
static memory_heap_t scripting_heap;
|
|
|
|
#endif // ENABLE_HEAP
|
|
|
|
|
2019-05-09 04:49:32 -03:00
|
|
|
// stm32F4 and F7 have 20 total RTC backup registers. We use the first one for boot type
|
|
|
|
// flags, so 19 available for persistent data
|
|
|
|
static_assert(sizeof(persistent_data) <= 19*4, "watchdog persistent data too large");
|
2021-01-16 01:01:04 -04:00
|
|
|
|
|
|
|
#if HAL_ENABLE_SAVE_PERSISTENT_PARAMS
|
|
|
|
// save/load key persistent parameters in bootloader sector
|
|
|
|
bool get_persistent_params(ExpandingString &str) const;
|
|
|
|
#endif
|
2021-09-06 01:46:19 -03:00
|
|
|
|
|
|
|
// log info on stack usage
|
|
|
|
void log_stack_info(void) override;
|
2021-10-23 03:34:35 -03:00
|
|
|
|
2022-08-15 04:22:48 -03:00
|
|
|
#if AP_CRASHDUMP_ENABLED
|
2021-10-23 03:34:35 -03:00
|
|
|
// get last crash dump
|
2021-11-03 13:48:00 -03:00
|
|
|
size_t last_crash_dump_size() const override;
|
|
|
|
void* last_crash_dump_ptr() const override;
|
2021-10-23 03:34:35 -03:00
|
|
|
#endif
|
|
|
|
|
2022-08-16 00:10:27 -03:00
|
|
|
#if HAL_ENABLE_DFU_BOOT
|
|
|
|
void boot_to_dfu() override;
|
|
|
|
#endif
|
2024-03-15 11:20:43 -03:00
|
|
|
|
|
|
|
#if HAL_UART_STATS_ENABLED
|
2024-04-06 13:11:57 -03:00
|
|
|
struct uart_stats {
|
2024-03-15 11:20:43 -03:00
|
|
|
AP_HAL::UARTDriver::StatsTracker serial[HAL_UART_NUM_SERIAL_PORTS];
|
|
|
|
#if HAL_WITH_IO_MCU
|
|
|
|
AP_HAL::UARTDriver::StatsTracker io;
|
|
|
|
#endif
|
|
|
|
uint32_t last_ms;
|
2024-04-06 13:11:57 -03:00
|
|
|
};
|
|
|
|
uart_stats sys_uart_stats;
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
uart_stats log_uart_stats;
|
|
|
|
#endif
|
2024-03-15 11:20:43 -03:00
|
|
|
#endif
|
2018-01-05 02:19:51 -04:00
|
|
|
};
|