2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-08-19 00:37:10 -03:00
|
|
|
|
2014-10-26 16:18:04 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || \
|
2017-12-13 17:31:56 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD
|
2016-07-29 16:14:02 -03:00
|
|
|
#include "RCInput_PRU.h"
|
2015-01-10 19:20:38 -04:00
|
|
|
|
2014-08-19 00:37:10 -03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-08-19 00:37:10 -03:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2014-08-19 00:37:10 -03:00
|
|
|
|
2014-10-07 22:48:46 -03:00
|
|
|
#include "GPIO.h"
|
2016-07-29 20:26:07 -03:00
|
|
|
|
|
|
|
#define RCIN_PRUSS_SHAREDRAM_BASE 0x4a312000
|
2014-08-19 00:37:10 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
using namespace Linux;
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
void RCInput_PRU::init()
|
2014-08-19 00:37:10 -03:00
|
|
|
{
|
2016-10-30 10:22:29 -03:00
|
|
|
int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
|
2014-08-19 00:37:10 -03:00
|
|
|
if (mem_fd == -1) {
|
2015-11-19 23:10:58 -04:00
|
|
|
AP_HAL::panic("Unable to open /dev/mem");
|
2014-08-19 00:37:10 -03:00
|
|
|
}
|
|
|
|
ring_buffer = (volatile struct ring_buffer*) mmap(0, 0x1000, PROT_READ|PROT_WRITE,
|
|
|
|
MAP_SHARED, mem_fd, RCIN_PRUSS_SHAREDRAM_BASE);
|
|
|
|
close(mem_fd);
|
|
|
|
ring_buffer->ring_head = 0;
|
|
|
|
_s0_time = 0;
|
2014-10-07 22:48:46 -03:00
|
|
|
|
|
|
|
// enable the spektrum RC input power
|
|
|
|
hal.gpio->pinMode(BBB_P8_17, HAL_GPIO_OUTPUT);
|
|
|
|
hal.gpio->write(BBB_P8_17, 1);
|
2014-08-19 00:37:10 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
called at 1kHz to check for new pulse capture data from the PRU
|
|
|
|
*/
|
2015-10-20 18:13:25 -03:00
|
|
|
void RCInput_PRU::_timer_tick()
|
2014-08-19 00:37:10 -03:00
|
|
|
{
|
|
|
|
while (ring_buffer->ring_head != ring_buffer->ring_tail) {
|
|
|
|
if (ring_buffer->ring_tail >= NUM_RING_ENTRIES) {
|
|
|
|
// invalid ring_tail from PRU - ignore RC input
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ring_buffer->buffer[ring_buffer->ring_head].pin_value == 1) {
|
|
|
|
// remember the time we spent in the low state
|
|
|
|
_s0_time = ring_buffer->buffer[ring_buffer->ring_head].delta_t;
|
|
|
|
} else {
|
|
|
|
// the pulse value is the sum of the time spent in the low
|
|
|
|
// and high states
|
2014-10-06 23:24:23 -03:00
|
|
|
_process_rc_pulse(_s0_time, ring_buffer->buffer[ring_buffer->ring_head].delta_t);
|
2014-08-19 00:37:10 -03:00
|
|
|
}
|
|
|
|
// move to the next ring buffer entry
|
|
|
|
ring_buffer->ring_head = (ring_buffer->ring_head + 1) % NUM_RING_ENTRIES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-26 16:18:04 -03:00
|
|
|
#endif // CONFIG_HAL_BOARD_SUBTYPE
|