2015-02-27 17:37:37 -04:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-02-27 17:37:37 -04:00
|
|
|
|
2016-12-29 10:37:03 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
|
2017-12-13 15:35:47 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2015-02-27 17:37:37 -04: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>
|
2015-02-27 17:37:37 -04:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2015-02-27 17:37:37 -04:00
|
|
|
|
|
|
|
#include "RCInput.h"
|
|
|
|
#include "RCInput_AioPRU.h"
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
using namespace Linux;
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
void RCInput_AioPRU::init()
|
2015-02-27 17:37:37 -04:00
|
|
|
{
|
2016-10-30 10:22:29 -03:00
|
|
|
int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
|
2015-02-27 17:37:37 -04:00
|
|
|
if (mem_fd == -1) {
|
2015-11-19 23:10:58 -04:00
|
|
|
AP_HAL::panic("Unable to open /dev/mem");
|
2015-02-27 17:37:37 -04:00
|
|
|
}
|
|
|
|
ring_buffer = (volatile struct ring_buffer*) mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, RCIN_PRUSS_RAM_BASE);
|
|
|
|
close(mem_fd);
|
|
|
|
ring_buffer->ring_head = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
called at 1kHz to check for new pulse capture data from the PRU
|
|
|
|
*/
|
2015-10-20 18:13:25 -03:00
|
|
|
void RCInput_AioPRU::_timer_tick()
|
2015-02-27 17:37:37 -04: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;
|
|
|
|
}
|
|
|
|
_process_rc_pulse((ring_buffer->buffer[ring_buffer->ring_head].s1_t) / TICK_PER_US,
|
|
|
|
(ring_buffer->buffer[ring_buffer->ring_head].s0_t) / TICK_PER_US);
|
|
|
|
// move to the next ring buffer entry
|
|
|
|
ring_buffer->ring_head = (ring_buffer->ring_head + 1) % NUM_RING_ENTRIES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CONFIG_HAL_BOARD_SUBTYPE
|