APM:Libraries
Util.h
Go to the documentation of this file.
1 /*
2  * This file is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This file is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Code by Andrew Tridgell and Siddharth Bharat Purohit
16  */
17 #pragma once
18 
19 #include <AP_HAL/AP_HAL.h>
21 #include "Semaphores.h"
22 #include "ToneAlarm.h"
23 
24 // this checks an address is in main memory and 16 bit aligned
25 #define IS_DMA_SAFE(addr) ((uint32_t(addr) & 0xF0000001) == 0x20000000)
26 
27 class ChibiOS::Util : public AP_HAL::Util {
28 public:
29  static Util *from(AP_HAL::Util *util) {
30  return static_cast<Util*>(util);
31  }
32 
33  bool run_debug_shell(AP_HAL::BetterStream *stream) { return false; }
34  AP_HAL::Semaphore *new_semaphore(void) override { return new ChibiOS::Semaphore; }
35  uint32_t available_memory() override;
36 
37  // Special Allocation Routines
38  void *malloc_type(size_t size, AP_HAL::Util::Memory_Type mem_type);
39  void free_type(void *ptr, size_t size, AP_HAL::Util::Memory_Type mem_type);
40 
41  /*
42  return state of safety switch, if applicable
43  */
44  enum safety_state safety_switch_state(void) override;
45 
46  // IMU temperature control
47  void set_imu_temp(float current);
48  void set_imu_target_temp(int8_t *target);
49 
50 #ifdef HAL_PWM_ALARM
51  bool toneAlarm_init();
52  void toneAlarm_set_tune(uint8_t tone);
53  void _toneAlarm_timer_tick();
54 
55  static ToneAlarm& get_ToneAlarm() { return _toneAlarm; }
56 #endif
57 
58 private:
59 #ifdef HAL_PWM_ALARM
60  static ToneAlarm _toneAlarm;
61 #endif
62  void* try_alloc_from_ccm_ram(size_t size);
63  uint32_t available_memory_in_ccm_ram(void);
64 
65 #if HAL_WITH_IO_MCU && HAL_HAVE_IMU_HEATER
66  struct {
67  int8_t *target;
68  float integrator;
69  uint16_t count;
70  float sum;
71  uint32_t last_update_ms;
72  } heater;
73 #endif
74 };
virtual void _toneAlarm_timer_tick()
Definition: Util.h:80
AP_HAL::Semaphore * new_semaphore(void) override
Definition: Util.h:34
enum safety_state safety_switch_state(void) override
Definition: Util.cpp:87
uint32_t available_memory_in_ccm_ram(void)
void * try_alloc_from_ccm_ram(size_t size)
Definition: Util.cpp:72
void * malloc_type(size_t size, AP_HAL::Util::Memory_Type mem_type)
Definition: Util.cpp:55
bool run_debug_shell(AP_HAL::BetterStream *stream)
Definition: Util.h:33
virtual void toneAlarm_set_tune(uint8_t tune)
Definition: Util.h:79
static Util * from(AP_HAL::Util *util)
Definition: Util.h:29
safety_state
Definition: Util.h:35
void set_imu_target_temp(int8_t *target)
Definition: Util.cpp:139
void set_imu_temp(float current)
Definition: Util.cpp:96
void free_type(void *ptr, size_t size, AP_HAL::Util::Memory_Type mem_type)
Definition: Util.cpp:64
uint32_t available_memory() override
Definition: Util.cpp:45
virtual bool toneAlarm_init()
Definition: Util.h:78