Commit Graph

222 Commits

Author SHA1 Message Date
Andrew Tridgell 7e264b44df HAL_Linux: fixed functor comparison 2015-05-26 15:14:50 +10:00
Lucas De Marchi 4c97d92982 AP_HAL_Linux: use functor macros
Functor is not yet being used but let's make is macro fallback to the
previous Delegate implementation for easy of transition between the two.
2015-05-26 13:46:53 +10:00
Andrew Tridgell 0619247992 HAL_Linux: don't advance time in delay() and delay_microseconds()
this could cause time to go backwards in Replay. Thanks to Peter for
finding this
2015-05-19 13:17:15 +10:00
Andrew Tridgell b09fcfc20e HAL_Linux: cope with systems without I2C_RDRW_IOCTL_MAX_MSGS
such as my ubuntu 14.04 laptop :-)
2015-05-05 21:42:46 +10:00
Lucas De Marchi d640bc8345 AP_HAL_Linux: use kernel's limit of msgs per I2C transaction
Instead of hardcoding 8 as the limit for I2C msgs, use whatever the
kernel exported to us.  In upstream this is 42 so it means we can group
together 21 addr/data pair instead of only 8.
2015-05-05 09:56:44 +10:00
Andrew Tridgell 179e47c618 HAL_Linux: prevent time from going backwards in Replay 2015-04-20 15:12:51 +10:00
Staroselskii Georgii dff430e136 AP_HAL_Linux: added UART port for second GPS 2015-04-14 15:59:34 +10:00
Staroselskii Georgii da6316ed4c AP_HAL_Linux: fixed TCP client connection in LinuxUARTDriver 2015-04-14 15:59:33 +10:00
Staroselskii Georgii 716fd56c62 AP_HAL_Linux: added support for dynamic speed configration in LinuxSPIUARTDriver 2015-04-14 10:45:49 +10:00
Staroselskii Georgii baf2b4da4e AP_HAL_Linux: renamed AnalogIn_Navio 2015-04-14 10:16:26 +10:00
Staroselskii Georgii 930aeaf556 AP_HAL_Linux: add RPi version runtime detection 2015-04-14 10:16:25 +10:00
Mikhail Avkhimenia c11304ba7a AP_HAL_Linux: change GPIO register address for Raspberry Pi 2 2015-04-14 10:16:25 +10:00
Staroselskii Georgii 641fa05028 AP_HAL_Linux: added buffering in RCOutput_Navio 2015-04-14 10:16:25 +10:00
Staroselskii Georgii e6c2977da2 AP_HAL_Linux: fixed style in RCOutput_Navio 2015-04-14 10:16:25 +10:00
Staroselskii Georgii 024825f95a AP_HAL_Linux: fixed PCA9685 initialization for RCOutput_Navio 2015-04-14 10:16:25 +10:00
Staroselskii Georgii 2a137b6ea9 AP_HAL_Linux: fixed RCInput initialization on NavIO 2015-04-14 10:16:24 +10:00
Andrew Tridgell 7f7d92913e HAL_Linux: allow running as non-root
this is needed for Replay, plus is very useful for debugging
2015-04-14 09:25:35 +10:00
Lucas De Marchi f049c8e4c5 AP_HAL_Linux: remove needless call to mlockall()
All threads share the same address space and have the same pages locked
into memory so it's not necessary to call mlockall() for each of them.

Grepping /proc/<tid>/status gives the same VmLck for all of them, even
when only the main thread locks the memory:

    # for i in `seq 477 482`; do \
	name=$(cat /proc/$i/comm); \
	vm=$(cat /proc/$i/status |grep VmLck); \
        echo -e "$name\t$vm"; \
    done
    ArduCopter.elf  VmLck:     57868 kB
    sched-timer     VmLck:     57868 kB
    sched-uart      VmLck:     57868 kB
    sched-rcin      VmLck:     57868 kB
    sched-tonealarm VmLck:     57868 kB
    sched-io        VmLck:     57868 kB
2015-04-14 09:17:21 +10:00
Lucas De Marchi b7355dc62b AP_HAL_Linux: set thread name for ease debug
Use pthread_setname_np() to set thread name so it's easier to debug
what't going on with each of them. This is the example output of the
relevant par of "ps -Leo class,rtprio,wchan,comm":

FF      12 futex_ ArduCopter.elf
FF      15 usleep sched-timer
FF      14 hrtime sched-uart
FF      13 poll_s sched-rcin
FF      11 hrtime sched-tonealarm
FF      10 hrtime sched-io
2015-04-14 09:17:21 +10:00
Lucas De Marchi 2c48434110 AP_HAL_Linux: use a table to initialize threads
Refactor function calls into a table and pass in the name so it can be
used in error message.
2015-04-14 09:17:21 +10:00
Lucas De Marchi e3d78b8960 AP_HAL_Linux: fix passing callback to member function
It's undefined behavior to pass the callback to pthread to a class
member like we were doing. Refactor the code so the callbacks are static
members.

This fixes the following warnings:

libraries/AP_HAL_Linux/Scheduler.cpp: In member function 'virtual void Linux::LinuxScheduler::init(void*)':
/home/lucas/p/dronecode/ardupilot/libraries/AP_HAL_Linux/Scheduler.cpp:61:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_timer_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:65:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_uart_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:69:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_rcin_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:73:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_tonealarm_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:77:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_io_thread);
2015-04-14 09:17:20 +10:00
Lucas De Marchi 62c2f737d5 AP_HAL_Linux: fix setting RT priorities
LinuxScheduler::init() was not really working as it should. This was the
result of "ps -Leo class,rtprio,wchan,comm | grep ArduCopter":

FF      12 futex_ ArduCopter.elf
FF      12 usleep ArduCopter.elf
FF      12 hrtime ArduCopter.elf
FF      12 poll_s ArduCopter.elf
FF      12 hrtime ArduCopter.elf
FF      12 hrtime ArduCopter.elf

As can be seen all the threads run with the same priority, the one of the main
thread. There were basically 2 mistakes:

	1) pthread_attr_setschedpolicy() needs to be called before
	   pthread_attr_setschedparam(). Otherwise the latter will just return
	   an error and not set the priority

	2) pthread_create() defaults to ignore the priority and inherit the
	   it from the parent thread. pthread_attr_setinheritsched() needs to
	   be called to change the behavior to PTHREAD_EXPLICIT_SCHED. See
	   pthread_attr_setinheritsched(3) for an example program to test the
	   behaviors.

Also, it's undefined behavior to call pthread_attr_init() several times on the
same pthread_attr_t. Although we could reutilize the same attribute without
calling  pthread_attr_init() again, lets refactor the code a little bit, so all
the pthread calls are in a single place. Then also call pthread_attr_destroy()
when we are done.
2015-04-14 09:17:20 +10:00
Lucas De Marchi 29b667efdf AP_HAL_Linux: remove useless mlock of stack
In Linux the default stack size is always greater than 32k, either 2MB
or 8MB depending on the architecture. There's no point in creating a
function to lock 32k.
2015-04-14 09:17:20 +10:00
mirkix 445f358839 AP_HAL_Linux: Fix compiler warning of MAX_PWMS redefinition (previously defined) 2015-04-06 15:34:50 -07:00
mirkix d4d42599b0 AP_HAL_Linux: Add RcInput and RcOutput with only one PRU when using a BBB. BBBMINI use the RC AIO PRU firmware already 2015-03-16 09:33:54 +11:00
mirkix a6b018eab9 AP_HAL_Linux: BBBMINI use kernel CS now 2015-03-16 09:15:06 +11:00
Staroselskii Georgii 75cd41a7c1 AP_HAL_Linux: added NavioAnalogIn 2015-02-12 12:57:45 +11:00
Staroselskii Georgii 195aa5fc6b AP_HAL_Linux: take the semaphore in SPIUARTDriver for shorter periods of time 2015-02-12 12:52:56 +11:00
Staroselskii Georgii 64da7f0360 AP_HAL_Linux: fix macro that defines number of I/O callbacks 2015-02-12 12:52:56 +11:00
Staroselskii Georgii 5b21bd2f1d AP_HAL_Linux: make Ublox transactions shorter 2015-02-12 12:52:56 +11:00
Staroselskii Georgii 4034004194 AP_HAL_Linux: switch NavIO to kernel CS handling 2015-02-12 12:52:56 +11:00
Andrew Tridgell 33a3254d8b HAL_Linux: accept a smaller sync pulse width 2015-02-08 21:47:28 +11:00
Andrew Tridgell 61be4ce2d2 HAL_Linux: fixed #if for linux builds 2015-01-22 15:58:20 +11:00
Víctor Mayoral Vilches 2b74d018fe HAL_Linux: Adjust set_system_clock
Do nothing for HAL_BOARD_SUBTYPE_NONE.
2015-01-22 15:43:16 +11:00
Víctor Mayoral Vilches 974f243c7e HAL_Linux: Add set_system_clock 2015-01-22 15:43:16 +11:00
mirkix c58a022111 AP_HAL_Linux: add support for BBBMINI, simple ArduPilot DIY Cape for the BeagleBone Black 2015-01-12 21:36:40 +13:00
Mikhail Avkhimenia 954b0795d4 HAL_Linux: Enable PCA9685 output after its setup 2015-01-09 06:38:21 +11:00
Andrew Tridgell 4da0a24887 HAL_Linux: use common RingBuffer.h 2015-01-07 08:41:14 +11:00
Staroselskii Georgii e4a21f291d AP_HAL_Linux: added LinuxSPIUARTDriver that can handle SPI-driven Ublox 2015-01-07 08:41:12 +11:00
Staroselskii Georgii 2b589d4604 AP_HAL_Linux: enable output for PCA9685 PWM in NavioRCOuput 2015-01-07 08:41:12 +11:00
Andrew Tridgell 193bda068c HAL_Linux: run IO processes when we do a stop_clock()
this has the effect of allowing logging to progress in Replay where we
are running at much more than realtime speeds
2014-12-08 11:24:39 +11:00
John Williams d0e467aea0 AP_HAL_Linux: Bypass manual CS assertion for SPI_CS_KERNEL mode
Missed from initial patch series

Signed-off-by: John Williams <john@whelanwilliams.net>
2014-11-27 15:57:12 +11:00
Mikhail Avkhimenia 955753f3f0 HAL_Linux: Optimize bandwidth for RCOutput_Navio
40% less bytes in I2C transactions for PCA9685.
2014-11-26 11:14:44 +11:00
Mikhail Avkhimenia 50459bdca0 HAL_Linux: Enable external clk for RCOutput_Navio
That should fix PWM value drifts.
2014-11-26 11:14:44 +11:00
Andrew Tridgell 22cb1c8525 HAL_Linux: tidy up SPI debugging a bit 2014-11-26 10:16:39 +11:00
John Williams 0fe3959d7e AP_HAL_Linux: Add support for in-kernel SPI CS handling
Add support for /dev/spidev<bus>.<cs> in-kernel SPI CS handling, and convert
existing SPI devices over.

 * Add a new member _subdev to the LinuxSPIDeviceDriver class, and initialiser
   in LinuxSPIDevice constructor.  Use subdev 0 for GPIO-managed CS
 * Extend the _cs_pin to signed 16 bits and define SPI_CS_KERNEL (-1) for
   kernel-managed CS
 * Move to per-device file descriptors (required for in-kernel CS)
 * Extend spidev filenames to include bus and subdevice numbers, possibly
   longer than 1 digit each
 * Allow support for platforms enumerating /dev/spidevNNN from non-zero bases
 * Convert existing users over to the new API

Signed-off-by: John Williams <john@whelanwilliams.net>
2014-11-26 09:55:09 +11:00
Andrew Tridgell 7497b4dfb1 HAL_Linux: fixed Replay with new AP_InertialSensor library 2014-11-16 12:30:50 +11:00
bugobliterator 9d39c0407e HAL_Linux: added ToneAlarmDriver.h 2014-11-15 21:25:55 +11:00
bugobliterator 329c1f5190 HAL_Linux:create ToneAlarmDriver as a separate class
ToneAlarm is now declared as a separate class instance of which is added as a private member of LinuxUtil
Some minor fixes in this patch include changing return type of tonealarm_init() to bool and use dprintf
2014-11-15 16:59:06 +11:00
bugobliterator f058131140 HAL_Linux Scheduler: reduce the delay inside tonealarm thread
Since the tonealarm is now passthrough the delay inside the thread needs to be reduced for precise tune generation
2014-11-15 16:59:06 +11:00