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