1 /*
2  * Copyright (c) 2017 Intel Corporation
3  * Copyright (c) 2020-2021 Vestas Wind Systems A/S
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/internal/syscall_handler.h>
9 #include <zephyr/drivers/pwm.h>
10 
z_vrfy_pwm_set_cycles(const struct device * dev,uint32_t channel,uint32_t period,uint32_t pulse,pwm_flags_t flags)11 static inline int z_vrfy_pwm_set_cycles(const struct device *dev,
12 					uint32_t channel, uint32_t period,
13 					uint32_t pulse, pwm_flags_t flags)
14 {
15 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, set_cycles));
16 	return z_impl_pwm_set_cycles((const struct device *)dev, channel,
17 					 period, pulse, flags);
18 }
19 #include <syscalls/pwm_set_cycles_mrsh.c>
20 
z_vrfy_pwm_get_cycles_per_sec(const struct device * dev,uint32_t channel,uint64_t * cycles)21 static inline int z_vrfy_pwm_get_cycles_per_sec(const struct device *dev,
22 						uint32_t channel,
23 						uint64_t *cycles)
24 {
25 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, get_cycles_per_sec));
26 	K_OOPS(K_SYSCALL_MEMORY_WRITE(cycles, sizeof(uint64_t)));
27 	return z_impl_pwm_get_cycles_per_sec((const struct device *)dev,
28 					     channel, (uint64_t *)cycles);
29 }
30 #include <syscalls/pwm_get_cycles_per_sec_mrsh.c>
31 
32 #ifdef CONFIG_PWM_CAPTURE
33 
z_vrfy_pwm_enable_capture(const struct device * dev,uint32_t channel)34 static inline int z_vrfy_pwm_enable_capture(const struct device *dev,
35 					    uint32_t channel)
36 {
37 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, enable_capture));
38 	return z_impl_pwm_enable_capture((const struct device *)dev, channel);
39 }
40 #include <syscalls/pwm_enable_capture_mrsh.c>
41 
z_vrfy_pwm_disable_capture(const struct device * dev,uint32_t channel)42 static inline int z_vrfy_pwm_disable_capture(const struct device *dev,
43 					     uint32_t channel)
44 {
45 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, disable_capture));
46 	return z_impl_pwm_disable_capture((const struct device *)dev, channel);
47 }
48 #include <syscalls/pwm_disable_capture_mrsh.c>
49 
z_vrfy_pwm_capture_cycles(const struct device * dev,uint32_t channel,pwm_flags_t flags,uint32_t * period_cycles,uint32_t * pulse_cycles,k_timeout_t timeout)50 static inline int z_vrfy_pwm_capture_cycles(const struct device *dev,
51 					    uint32_t channel, pwm_flags_t flags,
52 					    uint32_t *period_cycles,
53 					    uint32_t *pulse_cycles,
54 					    k_timeout_t timeout)
55 {
56 	uint32_t period;
57 	uint32_t pulse;
58 	int err;
59 
60 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, configure_capture));
61 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, enable_capture));
62 	K_OOPS(K_SYSCALL_DRIVER_PWM(dev, disable_capture));
63 
64 	err = z_impl_pwm_capture_cycles((const struct device *)dev, channel,
65 					flags, &period, &pulse, timeout);
66 	if (period_cycles != NULL) {
67 		K_OOPS(k_usermode_to_copy(period_cycles, &period,
68 				      sizeof(*period_cycles)));
69 	}
70 
71 	if (pulse_cycles != NULL) {
72 		K_OOPS(k_usermode_to_copy(pulse_cycles, &pulse,
73 				      sizeof(*pulse_cycles)));
74 	}
75 
76 	return err;
77 }
78 #include <syscalls/pwm_capture_cycles_mrsh.c>
79 
80 #endif /* CONFIG_PWM_CAPTURE */
81