RCOutput_AioPRU.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // This program is free software: you can redistribute it and/or modify
  2. // it under the terms of the GNU General Public License as published by
  3. // the Free Software Foundation, either version 3 of the License, or
  4. // (at your option) any later version.
  5. // This program is distributed in the hope that it will be useful,
  6. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. // GNU General Public License for more details.
  9. // You should have received a copy of the GNU General Public License
  10. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  11. #pragma once
  12. #include "AP_HAL_Linux.h"
  13. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
  14. #define RCOUT_PRUSS_RAM_BASE 0x4a300000
  15. #define RCOUT_PRUSS_CTRL_BASE 0x4a322000
  16. #define RCOUT_PRUSS_IRAM_BASE 0x4a334000
  17. #else
  18. #define RCOUT_PRUSS_RAM_BASE 0x4a302000
  19. #define RCOUT_PRUSS_CTRL_BASE 0x4a324000
  20. #define RCOUT_PRUSS_IRAM_BASE 0x4a338000
  21. #endif
  22. #define PWM_CHAN_COUNT 12
  23. namespace Linux {
  24. class RCOutput_AioPRU : public AP_HAL::RCOutput {
  25. void init() override;
  26. void set_freq(uint32_t chmask, uint16_t freq_hz) override;
  27. uint16_t get_freq(uint8_t ch) override;
  28. void enable_ch(uint8_t ch) override;
  29. void disable_ch(uint8_t ch) override;
  30. void write(uint8_t ch, uint16_t period_us) override;
  31. uint16_t read(uint8_t ch) override;
  32. void read(uint16_t* period_us, uint8_t len) override;
  33. void cork(void) override;
  34. void push(void) override;
  35. private:
  36. static const uint32_t TICK_PER_US = 200;
  37. static const uint32_t TICK_PER_S = 200000000;
  38. struct pwm {
  39. volatile uint32_t channelenable;
  40. struct {
  41. volatile uint32_t time_high;
  42. volatile uint32_t time_t;
  43. } channel[PWM_CHAN_COUNT];
  44. };
  45. volatile struct pwm *pwm;
  46. uint16_t pending[PWM_CHAN_COUNT];
  47. uint32_t pending_mask;
  48. bool corked;
  49. };
  50. }