2016-02-17 21:25:26 -04:00
|
|
|
#pragma once
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2015-11-05 23:46:33 -04:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-11-05 23:46:33 -04:00
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
#include "Heat.h"
|
2017-09-08 02:39:35 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
2016-10-29 05:23:31 -03:00
|
|
|
#include "ToneAlarm_Disco.h"
|
2016-07-29 16:31:02 -03:00
|
|
|
#endif
|
2016-03-10 11:28:22 -04:00
|
|
|
#include "ToneAlarm.h"
|
2015-12-16 17:24:11 -04:00
|
|
|
#include "Semaphores.h"
|
2014-08-23 04:52:43 -03:00
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
namespace Linux {
|
|
|
|
|
2015-12-22 09:49:12 -04:00
|
|
|
enum hw_type {
|
|
|
|
UTIL_HARDWARE_RPI1 = 0,
|
|
|
|
UTIL_HARDWARE_RPI2,
|
2020-01-10 09:53:38 -04:00
|
|
|
UTIL_HARDWARE_RPI4,
|
2015-12-22 09:49:12 -04:00
|
|
|
UTIL_HARDWARE_BEBOP,
|
|
|
|
UTIL_HARDWARE_BEBOP2,
|
2016-06-06 19:16:25 -03:00
|
|
|
UTIL_HARDWARE_DISCO,
|
2015-12-22 09:49:12 -04:00
|
|
|
UTIL_NUM_HARDWARES,
|
|
|
|
};
|
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
class Util : public AP_HAL::Util {
|
2013-09-22 03:01:24 -03:00
|
|
|
public:
|
2015-10-20 18:13:25 -03:00
|
|
|
static Util *from(AP_HAL::Util *util) {
|
|
|
|
return static_cast<Util*>(util);
|
2015-09-13 15:28:02 -03:00
|
|
|
}
|
|
|
|
|
2017-04-19 04:19:40 -03:00
|
|
|
void init(int argc, char *const *argv);
|
2019-02-21 19:08:12 -04:00
|
|
|
bool run_debug_shell(AP_HAL::BetterStream *stream) override { return false; }
|
2014-02-22 17:15:39 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
return commandline arguments, if available
|
|
|
|
*/
|
2019-02-21 19:08:12 -04:00
|
|
|
void commandline_arguments(uint8_t &argc, char * const *&argv) override;
|
2014-02-22 17:15:39 -04:00
|
|
|
|
2015-01-19 13:30:18 -04:00
|
|
|
/*
|
2021-11-22 22:40:39 -04:00
|
|
|
get/set system clock in UTC microseconds
|
2015-01-19 13:30:18 -04:00
|
|
|
*/
|
2018-02-16 18:25:36 -04:00
|
|
|
void set_hw_rtc(uint64_t time_utc_usec) override;
|
2021-11-22 22:40:39 -04:00
|
|
|
uint64_t get_hw_rtc() const override;
|
|
|
|
|
2017-04-19 04:19:40 -03:00
|
|
|
const char *get_custom_log_directory() const override final { return custom_log_directory; }
|
|
|
|
const char *get_custom_terrain_directory() const override final { return custom_terrain_directory; }
|
2018-03-28 03:19:37 -03:00
|
|
|
const char *get_custom_storage_directory() const override final { return custom_storage_directory; }
|
2015-06-29 22:42:30 -03:00
|
|
|
|
|
|
|
void set_custom_log_directory(const char *_custom_log_directory) { custom_log_directory = _custom_log_directory; }
|
|
|
|
void set_custom_terrain_directory(const char *_custom_terrain_directory) { custom_terrain_directory = _custom_terrain_directory; }
|
2018-03-28 03:19:37 -03:00
|
|
|
void set_custom_storage_directory(const char *_custom_storage_directory) {
|
|
|
|
custom_storage_directory = _custom_storage_directory;
|
|
|
|
}
|
2021-02-06 02:59:54 -04:00
|
|
|
void set_custom_defaults_path(const char *_custom_defaults) {
|
|
|
|
custom_defaults = _custom_defaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get path to custom defaults file for AP_Param
|
|
|
|
const char* get_custom_defaults_file() const override final {
|
|
|
|
return custom_defaults;
|
|
|
|
}
|
2015-01-19 13:30:18 -04:00
|
|
|
|
2021-10-08 17:40:49 -03:00
|
|
|
/* Parse cpu set in the form 0; 0,2; or 0-2 */
|
2021-09-17 00:28:40 -03:00
|
|
|
bool parse_cpu_set(const char *s, cpu_set_t *cpu_set) const;
|
|
|
|
|
2015-06-27 18:18:09 -03:00
|
|
|
bool is_chardev_node(const char *path);
|
2016-06-15 05:01:14 -03:00
|
|
|
void set_imu_temp(float current) override;
|
|
|
|
void set_imu_target_temp(int8_t *target) override;
|
2015-06-27 18:18:09 -03:00
|
|
|
|
2015-11-05 01:06:15 -04:00
|
|
|
uint32_t available_memory(void) override;
|
2015-10-01 18:19:15 -03:00
|
|
|
|
2018-11-16 17:15:59 -04:00
|
|
|
bool get_system_id(char buf[40]) override;
|
|
|
|
bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
|
2019-03-23 11:36:17 -03: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) override;
|
|
|
|
virtual void *heap_realloc(void *h, void *ptr, size_t new_size) override;
|
|
|
|
#endif // ENABLE_HEAP
|
2018-11-16 17:15:59 -04:00
|
|
|
|
2015-11-05 23:46:33 -04:00
|
|
|
/*
|
|
|
|
* Write a string as specified by @fmt to the file in @path. Note this
|
|
|
|
* should not be used on hot path since it will open, write and close the
|
|
|
|
* file for each call.
|
|
|
|
*/
|
2015-11-10 13:05:19 -04:00
|
|
|
int write_file(const char *path, const char *fmt, ...) FMT_PRINTF(3, 4);
|
2015-11-05 23:46:33 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a string as specified by @fmt from the file in @path. Note this
|
|
|
|
* should not be used on hot path since it will open, read and close the
|
|
|
|
* file for each call.
|
|
|
|
*/
|
|
|
|
int read_file(const char *path, const char *fmt, ...) FMT_SCANF(3, 4);
|
2015-10-01 18:19:15 -03:00
|
|
|
|
2015-12-22 09:49:12 -04:00
|
|
|
int get_hw_arm32();
|
|
|
|
|
2021-04-28 17:49:49 -03:00
|
|
|
bool toneAlarm_init(uint8_t types) override { return _toneAlarm.init(); }
|
2018-07-27 04:12:48 -03:00
|
|
|
void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override {
|
|
|
|
_toneAlarm.set_buzzer_tone(frequency, volume, duration_ms);
|
|
|
|
}
|
2018-07-25 19:28:50 -03:00
|
|
|
|
2021-06-24 13:49:47 -03:00
|
|
|
// fills data with random values of requested size
|
|
|
|
bool get_random_vals(uint8_t* data, size_t size) override;
|
|
|
|
|
2014-11-15 01:51:21 -04:00
|
|
|
private:
|
2017-09-08 02:39:35 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
2016-10-29 05:23:31 -03:00
|
|
|
static ToneAlarm_Disco _toneAlarm;
|
2016-01-10 08:17:33 -04:00
|
|
|
#else
|
2016-07-29 16:14:02 -03:00
|
|
|
static ToneAlarm _toneAlarm;
|
2016-01-10 08:17:33 -04:00
|
|
|
#endif
|
2014-02-22 17:15:39 -04:00
|
|
|
int saved_argc;
|
2017-04-19 04:19:40 -03:00
|
|
|
Heat *_heat;
|
|
|
|
char *const *saved_argv;
|
|
|
|
const char *custom_log_directory = nullptr;
|
|
|
|
const char *custom_terrain_directory = nullptr;
|
2018-03-28 03:19:37 -03:00
|
|
|
const char *custom_storage_directory = nullptr;
|
2021-02-06 02:59:54 -04:00
|
|
|
const char *custom_defaults = HAL_PARAM_DEFAULTS_PATH;
|
2015-12-22 09:49:12 -04:00
|
|
|
static const char *_hw_names[UTIL_NUM_HARDWARES];
|
2019-03-23 11:36:17 -03:00
|
|
|
|
|
|
|
#ifdef ENABLE_HEAP
|
|
|
|
struct heap_allocation_header {
|
|
|
|
size_t allocation_size; // size of allocated block, not including this header
|
|
|
|
};
|
|
|
|
|
|
|
|
struct heap {
|
|
|
|
size_t max_heap_size;
|
|
|
|
size_t current_heap_usage;
|
|
|
|
};
|
|
|
|
#endif // ENABLE_HEAP
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
};
|
2016-07-29 16:14:02 -03:00
|
|
|
|
|
|
|
}
|