Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Intel Corporation |
Henrik Brix Andersen | 77b8440 | 2020-06-06 21:38:38 +0200 | [diff] [blame] | 3 | * Copyright (c) 2020-2021 Vestas Wind Systems A/S |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | */ |
| 7 | |
| 8 | #include <syscall_handler.h> |
Anas Nashif | 5843884 | 2019-06-25 15:53:58 -0400 | [diff] [blame] | 9 | #include <drivers/pwm.h> |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 10 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 11 | static inline int z_vrfy_pwm_pin_set_cycles(const struct device *dev, |
| 12 | uint32_t pwm, |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 13 | uint32_t period, uint32_t pulse, |
Henrik Brix Andersen | db611e6 | 2019-11-13 14:46:37 +0100 | [diff] [blame] | 14 | pwm_flags_t flags) |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 15 | { |
Andrew Boie | 8345e5e | 2018-05-04 15:57:57 -0700 | [diff] [blame] | 16 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_set)); |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 17 | return z_impl_pwm_pin_set_cycles((const struct device *)dev, pwm, |
| 18 | period, |
Henrik Brix Andersen | db611e6 | 2019-11-13 14:46:37 +0100 | [diff] [blame] | 19 | pulse, flags); |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 20 | } |
Andy Ross | 075c94f | 2019-08-13 11:34:34 -0700 | [diff] [blame] | 21 | #include <syscalls/pwm_pin_set_cycles_mrsh.c> |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 22 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 23 | static inline int z_vrfy_pwm_get_cycles_per_sec(const struct device *dev, |
| 24 | uint32_t pwm, |
| 25 | uint64_t *cycles) |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 26 | { |
Andrew Boie | 8345e5e | 2018-05-04 15:57:57 -0700 | [diff] [blame] | 27 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, get_cycles_per_sec)); |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 28 | Z_OOPS(Z_SYSCALL_MEMORY_WRITE(cycles, sizeof(uint64_t))); |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 29 | return z_impl_pwm_get_cycles_per_sec((const struct device *)dev, |
| 30 | pwm, (uint64_t *)cycles); |
Andrew Boie | 0f66b9f | 2017-10-25 11:27:37 -0700 | [diff] [blame] | 31 | } |
Andy Ross | 075c94f | 2019-08-13 11:34:34 -0700 | [diff] [blame] | 32 | #include <syscalls/pwm_get_cycles_per_sec_mrsh.c> |
Henrik Brix Andersen | 77b8440 | 2020-06-06 21:38:38 +0200 | [diff] [blame] | 33 | |
| 34 | #ifdef CONFIG_PWM_CAPTURE |
| 35 | |
| 36 | static inline int z_vrfy_pwm_pin_enable_capture(const struct device *dev, |
| 37 | uint32_t pwm) |
| 38 | { |
| 39 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_enable_capture)); |
| 40 | return z_impl_pwm_pin_enable_capture((const struct device *)dev, pwm); |
| 41 | } |
| 42 | #include <syscalls/pwm_pin_enable_capture_mrsh.c> |
| 43 | |
| 44 | static inline int z_vrfy_pwm_pin_disable_capture(const struct device *dev, |
| 45 | uint32_t pwm) |
| 46 | { |
| 47 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_disable_capture)); |
| 48 | return z_impl_pwm_pin_disable_capture((const struct device *)dev, pwm); |
| 49 | } |
| 50 | #include <syscalls/pwm_pin_disable_capture_mrsh.c> |
| 51 | |
| 52 | static inline int z_vrfy_pwm_pin_capture_cycles(const struct device *dev, |
| 53 | uint32_t pwm, pwm_flags_t flags, |
| 54 | uint32_t *period_cycles, |
| 55 | uint32_t *pulse_cycles, |
| 56 | k_timeout_t timeout) |
| 57 | { |
| 58 | uint32_t period; |
| 59 | uint32_t pulse; |
| 60 | int err; |
| 61 | |
| 62 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_configure_capture)); |
| 63 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_enable_capture)); |
| 64 | Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_disable_capture)); |
| 65 | |
| 66 | err = z_impl_pwm_pin_capture_cycles((const struct device *)dev, pwm, |
| 67 | flags, &period, &pulse, timeout); |
| 68 | if (period_cycles != NULL) { |
| 69 | Z_OOPS(z_user_to_copy(period_cycles, &period, |
| 70 | sizeof(*period_cycles))); |
| 71 | } |
| 72 | |
| 73 | if (pulse_cycles != NULL) { |
| 74 | Z_OOPS(z_user_to_copy(pulse_cycles, &pulse, |
| 75 | sizeof(*pulse_cycles))); |
| 76 | } |
| 77 | |
| 78 | return err; |
| 79 | } |
| 80 | #include <syscalls/pwm_pin_capture_cycles_mrsh.c> |
| 81 | |
| 82 | #endif /* CONFIG_PWM_CAPTURE */ |