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/>.
|
|
|
|
*
|
|
|
|
* 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>
|
2018-01-05 02:19:51 -04:00
|
|
|
|
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-07-18 21:38:13 -03:00
|
|
|
bool run_debug_shell(AP_HAL::BetterStream *stream) override { return false; }
|
2018-01-05 02:19:51 -04:00
|
|
|
uint32_t available_memory() override;
|
|
|
|
|
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
|
|
|
|
2018-12-08 22:34:39 -04:00
|
|
|
#ifdef ENABLE_HEAP
|
|
|
|
// heap functions, note that a heap once alloc'd cannot be dealloc'd
|
|
|
|
virtual void *allocate_heap_memory(size_t size);
|
|
|
|
virtual void *heap_realloc(void *heap, void *ptr, size_t new_size);
|
|
|
|
#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;
|
|
|
|
|
|
|
|
// IMU temperature control
|
2018-07-18 21:38:13 -03:00
|
|
|
void set_imu_temp(float current) override;
|
|
|
|
void set_imu_target_temp(int8_t *target) override;
|
2018-02-09 23:55:22 -04:00
|
|
|
|
2018-06-29 04:54:51 -03:00
|
|
|
// get system ID as a string
|
|
|
|
bool get_system_id(char buf[40]) override;
|
2018-09-28 12:30:48 -03:00
|
|
|
bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
|
|
|
|
|
2018-02-09 23:55:22 -04:00
|
|
|
#ifdef HAL_PWM_ALARM
|
2018-07-18 21:38:13 -03:00
|
|
|
bool toneAlarm_init() override;
|
2018-07-27 04:12:26 -03:00
|
|
|
void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override;
|
2018-02-09 23:55:22 -04:00
|
|
|
#endif
|
2018-02-01 11:25:03 -04:00
|
|
|
|
2018-12-27 21:05:06 -04:00
|
|
|
#ifdef USE_POSIX
|
|
|
|
/*
|
|
|
|
initialise (or re-initialise) filesystem storage
|
|
|
|
*/
|
|
|
|
bool fs_init(void) override;
|
|
|
|
#endif
|
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
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
private:
|
2018-02-09 23:55:22 -04:00
|
|
|
#ifdef HAL_PWM_ALARM
|
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
|
|
|
|
2019-02-21 17:54:42 -04:00
|
|
|
#if HAL_HAVE_IMU_HEATER
|
2018-01-05 02:19:51 -04:00
|
|
|
struct {
|
|
|
|
int8_t *target;
|
|
|
|
float integrator;
|
|
|
|
uint16_t count;
|
|
|
|
float sum;
|
|
|
|
uint32_t last_update_ms;
|
2019-02-21 17:54:42 -04:00
|
|
|
uint8_t duty_counter;
|
|
|
|
float output;
|
2018-01-05 02:19:51 -04:00
|
|
|
} heater;
|
|
|
|
#endif
|
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;
|
2018-08-29 10:16:17 -03:00
|
|
|
#ifndef HAL_NO_FLASH_SUPPORT
|
2018-06-27 02:59:57 -03:00
|
|
|
bool flash_bootloader() override;
|
2018-08-29 10:16:17 -03:00
|
|
|
#endif
|
2018-12-08 22:34:39 -04:00
|
|
|
|
|
|
|
#ifdef ENABLE_HEAP
|
|
|
|
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");
|
2018-01-05 02:19:51 -04:00
|
|
|
};
|