APM:Libraries
RCInput_ZYNQ.cpp
Go to the documentation of this file.
1 #include "RCInput_ZYNQ.h"
2 
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <poll.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/stat.h>
12 #include <sys/time.h>
13 #include <unistd.h>
14 
15 #include <AP_HAL/AP_HAL.h>
16 
17 #include "GPIO.h"
18 
19 #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ
20 #define RCIN_ZYNQ_PULSE_INPUT_BASE 0x43ca0000
21 #else
22 #define RCIN_ZYNQ_PULSE_INPUT_BASE 0x43c10000
23 #endif
24 
25 extern const AP_HAL::HAL& hal;
26 
27 using namespace Linux;
28 
30 {
31  int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
32  if (mem_fd == -1) {
33  AP_HAL::panic("Unable to open /dev/mem");
34  }
35  pulse_input = (volatile uint32_t*) mmap(0, 0x1000, PROT_READ|PROT_WRITE,
36  MAP_SHARED, mem_fd, RCIN_ZYNQ_PULSE_INPUT_BASE);
37  close(mem_fd);
38 
39  _s0_time = 0;
40 }
41 
42 /*
43  called at 1kHz to check for new pulse capture data from the PL pulse timer
44  */
46 {
47  uint32_t v;
48 
49  // all F's means no samples available
50  while((v = *pulse_input) != 0xffffffff) {
51  // Hi bit indicates pin state, low bits denote pulse length
52  if(v & 0x80000000)
53  _s0_time = (v & 0x7fffffff)/TICK_PER_US;
54  else
55  _process_rc_pulse(_s0_time, (v & 0x7fffffff)/TICK_PER_US);
56  }
57 }
void _timer_tick(void)
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
volatile uint32_t * pulse_input
Definition: RCInput_ZYNQ.h:27
int close(int fileno)
POSIX Close a file with fileno handel.
Definition: posix.c:675
float v
Definition: Printf.cpp:15
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
#define RCIN_ZYNQ_PULSE_INPUT_BASE
static const int TICK_PER_US
Definition: RCInput_ZYNQ.h:19
void panic(const char *errormsg,...) FMT_PRINTF(1
Definition: system.cpp:140