APM:Libraries
RCInput_AioPRU.cpp
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 
12 
13 #include <AP_HAL/AP_HAL.h>
14 
15 #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
16  CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
17  CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
18 
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <poll.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/mman.h>
27 #include <sys/stat.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30 
31 #include "RCInput.h"
32 #include "RCInput_AioPRU.h"
33 
34 extern const AP_HAL::HAL& hal;
35 
36 using namespace Linux;
37 
39 {
40  int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
41  if (mem_fd == -1) {
42  AP_HAL::panic("Unable to open /dev/mem");
43  }
44  ring_buffer = (volatile struct ring_buffer*) mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, RCIN_PRUSS_RAM_BASE);
45  close(mem_fd);
47 }
48 
49 /*
50  called at 1kHz to check for new pulse capture data from the PRU
51  */
53 {
56  // invalid ring_tail from PRU - ignore RC input
57  return;
58  }
61  // move to the next ring buffer entry
63  }
64 }
65 
66 #endif // CONFIG_HAL_BOARD_SUBTYPE
static const uint32_t TICK_PER_US
int open(const char *pathname, int flags)
POSIX Open a file with integer mode flags.
Definition: posix.c:885
void _process_rc_pulse(uint16_t width_s0, uint16_t width_s1)
Definition: RCInput.cpp:308
#define RCIN_PRUSS_RAM_BASE
int close(int fileno)
POSIX Close a file with fileno handel.
Definition: posix.c:675
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
static const uint32_t NUM_RING_ENTRIES
struct Linux::RCInput_AioPRU::ring_buffer::@98 buffer[NUM_RING_ENTRIES]
void panic(const char *errormsg,...) FMT_PRINTF(1
Definition: system.cpp:140