RCInput_AioPRU.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /*
  13. This class implements RCInput on the BeagleBoneBlack with a PRU
  14. doing the edge detection of the PPM sum input
  15. */
  16. #include "AP_HAL_Linux.h"
  17. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
  18. #define RCIN_PRUSS_RAM_BASE 0x4a301000
  19. #else
  20. #define RCIN_PRUSS_RAM_BASE 0x4a303000
  21. #endif
  22. // we use 300 ring buffer entries to guarantee that a full 25 byte
  23. // frame of 12 bits per byte
  24. namespace Linux {
  25. class RCInput_AioPRU : public RCInput {
  26. public:
  27. void init() override;
  28. void _timer_tick(void) override;
  29. protected:
  30. static const uint32_t TICK_PER_US = 200;
  31. static const uint32_t NUM_RING_ENTRIES = 300;
  32. // shared ring buffer with the PRU which records pin transitions
  33. struct ring_buffer {
  34. volatile uint16_t ring_head; // owned by ARM CPU
  35. volatile uint16_t ring_tail; // owned by the PRU
  36. struct {
  37. volatile uint32_t s1_t; // 5ns per tick
  38. volatile uint32_t s0_t; // 5ns per tick
  39. } buffer[NUM_RING_ENTRIES];
  40. };
  41. volatile struct ring_buffer *ring_buffer;
  42. };
  43. }