RCInput_ZYNQ.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "RCInput_ZYNQ.h"
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <poll.h>
  5. #include <stdint.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/mman.h>
  10. #include <sys/stat.h>
  11. #include <sys/time.h>
  12. #include <unistd.h>
  13. #include <AP_HAL/AP_HAL.h>
  14. #include "GPIO.h"
  15. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ
  16. #define RCIN_ZYNQ_PULSE_INPUT_BASE 0x43ca0000
  17. #else
  18. #define RCIN_ZYNQ_PULSE_INPUT_BASE 0x43c10000
  19. #endif
  20. extern const AP_HAL::HAL& hal;
  21. using namespace Linux;
  22. void RCInput_ZYNQ::init()
  23. {
  24. int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
  25. if (mem_fd == -1) {
  26. AP_HAL::panic("Unable to open /dev/mem");
  27. }
  28. pulse_input = (volatile uint32_t*) mmap(0, 0x1000, PROT_READ|PROT_WRITE,
  29. MAP_SHARED, mem_fd, RCIN_ZYNQ_PULSE_INPUT_BASE);
  30. close(mem_fd);
  31. _s0_time = 0;
  32. }
  33. /*
  34. called at 1kHz to check for new pulse capture data from the PL pulse timer
  35. */
  36. void RCInput_ZYNQ::_timer_tick()
  37. {
  38. uint32_t v;
  39. // all F's means no samples available
  40. while((v = *pulse_input) != 0xffffffff) {
  41. // Hi bit indicates pin state, low bits denote pulse length
  42. if(v & 0x80000000)
  43. _s0_time = (v & 0x7fffffff)/TICK_PER_US;
  44. else
  45. _process_rc_pulse(_s0_time, (v & 0x7fffffff)/TICK_PER_US);
  46. }
  47. }