RCOutput_PRU.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "AP_HAL_Linux.h"
  3. #define RCOUT_PRUSS_SHAREDRAM_BASE 0x4a310000
  4. #define MAX_PWMS 12
  5. #define PWM_CMD_MAGIC 0xf00fbaaf
  6. #define PWM_REPLY_MAGIC 0xbaaff00f
  7. #define PWM_CMD_CONFIG 0 /* full configuration in one go */
  8. #define PWM_CMD_ENABLE 1 /* enable a pwm */
  9. #define PWM_CMD_DISABLE 2 /* disable a pwm */
  10. #define PWM_CMD_MODIFY 3 /* modify a pwm */
  11. #define PWM_CMD_SET 4 /* set a pwm output explicitly */
  12. #define PWM_CMD_CLR 5 /* clr a pwm output explicitly */
  13. #define PWM_CMD_TEST 6 /* various crap */
  14. namespace Linux {
  15. class RCOutput_PRU : public AP_HAL::RCOutput {
  16. void init() override;
  17. void set_freq(uint32_t chmask, uint16_t freq_hz) override;
  18. uint16_t get_freq(uint8_t ch) override;
  19. void enable_ch(uint8_t ch) override;
  20. void disable_ch(uint8_t ch) override;
  21. void write(uint8_t ch, uint16_t period_us) override;
  22. uint16_t read(uint8_t ch) override;
  23. void read(uint16_t* period_us, uint8_t len) override;
  24. void cork(void) override;
  25. void push(void) override;
  26. private:
  27. static const int TICK_PER_US=200;
  28. static const int TICK_PER_S=200000000;
  29. struct pwm_cmd {
  30. uint32_t magic;
  31. uint32_t enmask; /* enable mask */
  32. uint32_t offmsk; /* state when pwm is off */
  33. uint32_t periodhi[MAX_PWMS][2];
  34. uint32_t hilo_read[MAX_PWMS][2];
  35. uint32_t enmask_read;
  36. };
  37. volatile struct pwm_cmd *sharedMem_cmd;
  38. uint16_t pending[MAX_PWMS];
  39. bool corked;
  40. uint32_t pending_mask;
  41. };
  42. }