Commit Graph

13 Commits

Author SHA1 Message Date
Georgii Staroselskii d214a36e0a AP_HAL_Linux: reset duty cycle before setting period
On kernels 4.7+ duty_cycle should always be less than period.
Otherways, we'll get a EINVAL.

It makes sense to set duty_cycle to 0, as
duty_cycle doesn't really make sense without a proper period.

A proper way to handle these errors might be to call pwm_adjust_config
in every pwmchip backend but it's unrealistic to hope that all vendors
will do it quickly.
2017-10-17 13:28:34 -07:00
Georgii Staroselskii f6858821a6 AP_HAL_Linux: PWM_Sysfs: remove unneeded free() in ~PWM_Sysfs_Base
_export_path and _duty_path will have been already long time gone by the
time dtors kick in.

Probably better to use OwnPtr around those. But it's better to be done
in a separate PR.
2017-09-08 07:26:54 -07:00
Lucas De Marchi c1647b13eb AP_HAL_Linux: fix leaking strings 2016-11-09 11:44:05 -03:00
Mathieu OTHACEHE 0fa441a8a5 PWM_Sysfs: add an init method to do hal dependent stuff.
When PWM_Sysfs_Base constructor is called, global variable hal may not
have been initialized resulting in NULL dereferencing error.

Move hal dependent stuff from contructor to init method.
2016-11-07 14:59:31 -02:00
murata c808ee2f49 Global: To nullptr from NULL.
RC_Channel: To nullptr from NULL.

AC_Fence: To nullptr from NULL.

AC_Avoidance: To nullptr from NULL.

AC_PrecLand: To nullptr from NULL.

DataFlash: To nullptr from NULL.

SITL: To nullptr from NULL.

GCS_MAVLink: To nullptr from NULL.

DataFlash: To nullptr from NULL.

AP_Compass: To nullptr from NULL.

Global: To nullptr from NULL.

Global: To nullptr from NULL.
2016-11-02 16:04:47 -02:00
Mathieu OTHACEHE 152edf7189 Global: remove mode line from headers
Using a global .dir-locals.el file is a better alternative than
reincluding the same emacs header in every file of the project.
2016-10-24 09:42:01 -02:00
Lucas De Marchi 71e10c9132 AP_HAL_Linux: fix include order
Sort include alphabetically and make them in order:

Main header
system headers
library headers
local headers

While reordering, change a include of endian.h to our sparse-endian.h
which is more reliant to toolchain changes.
2016-05-18 23:05:56 -03:00
Lucas De Marchi 45c6b750f2 AP_HAL_Linux: remove ifdef checks for HAL_BOARD_LINUX
Everything inside libraries/AP_HAL_Linux is for Linux boards, there's
not need to add the ifdefs.
2016-05-18 23:05:56 -03:00
Lucas De Marchi 04f601d42f AP_HAL_Linux: PWM_Sysfs: minor changes to Bebop/mainline integration
- Make error path in constructor shorter and earlier. It's calling
    panic() so there's no reason to do anything else

  - We don't need to check variable for NULL when calling free()

  - Change set/get_polarity to use a virtual function; this allows us
    not to fail silently if _polarity_path is NULL for PWM_Sysfs.
    PWM_Sysfs_Bebop just overrides this method and implement an empty
    version.
2015-12-01 07:07:25 +11:00
Julien BERAUD 8733f34ce1 AP_HAL_Linux: PWM_Sysfs for bebop
Modify existing class to create a PWM_Sysfs_Base class and derive it for
Bebop and Pwm_Sysfs (mainline kernel)

use asprintf for path allocation since it doesn't cost so much and is done
only at startup
Note that the constructor of the 2 classes : PWM_Sysfs and PWM_Sysfs_Bebop
allocate the paths and the constructor and desctuctor of class PWM_Sysfs_Base
frees them.
only keep in memory the paths that are needed later, i.e free _export_path,
_duty_path. The remaining path are freed in the destructor
2015-12-01 07:07:25 +11:00
Caio Marcelo de Oliveira Filho 7675913d5b AP_HAL_Linux: use millis/micros/panic functions 2015-11-20 12:31:04 +09:00
Lucas De Marchi c66c61180a AP_HAL_Linux: rework PWM_Sysfs
This include some minor changes on all methods of PWM_Sysfs:

  - Sort headers
  - Add code inside Linux namespace rather than just use the namespace
  - Declare a union pwm_params, that's only used to calculate at compile
    time the maximum stack space we need in our methods: this is a bit
    safer for future extensions
  - Standardize error messages to include the useful params first and
    then the error message
  - Remove log message from hot path
  - Don't abuse macros for checking error - convert the SNPRINTF_CHECK
    macro into proper code, ignoring errors for not enough space since
    they can't happen
  - Fix call to read_file() passing uint8_t for "%u" in get_period()
  - Fix passing char** instead of char* to write_file() in set_polarity()
  - Use strncmp() instead of strncasecmp() since the kernel API uses
    lowercase.
  - Add comments on the 2 main methods of this class
2015-11-10 17:05:34 +11:00
José Roberto de Souza 39bd5fa80e AP_HAL_Linux: Add PWM_Sysfs
This class makes easy to use Linux PWM sysfs interface, available since
Linux 3.10.

More information https://www.kernel.org/doc/Documentation/pwm.txt
2015-11-10 17:05:34 +11:00