test prog implementation moved to real driver/board implementations
This commit is contained in:
@@ -157,7 +157,13 @@ int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data)
|
||||
case DRIVER_TYPE_PWM:
|
||||
if(cmd == IOCTL_PWM_SET_DUTY_CYCLE) {
|
||||
unsigned int *duty = (unsigned int *)data;
|
||||
pwm_set_duty_cycle((const struct pwm *)(driver->device_driver), *duty);
|
||||
return pwm_set_duty_cycle((const struct pwm *)(driver->device_driver), *duty);
|
||||
}
|
||||
else if(cmd == IOCTL_PWM_GET_PERIOD_NS) {
|
||||
return pwm_get_period_ns((const struct pwm *)(driver->device_driver));
|
||||
}
|
||||
else if(cmd == IOCTL_PWM_GET_PULSE_WIDTH_NS) {
|
||||
return pwm_get_pulse_width_ns((const struct pwm *)(driver->device_driver));
|
||||
}
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
|
@@ -14,22 +14,28 @@ typedef int (*pwm_fp_open_t)(const void*);
|
||||
//! \brief Function pointer to the close function.
|
||||
typedef int (*pwm_fp_close_t)(const void*);
|
||||
|
||||
//! \brief Function pointer to the read function.
|
||||
typedef int (*pwm_fp_set_duty_cycle_t)(const void*, unsigned int duty_cycle_percent);
|
||||
|
||||
typedef int (*pwm_fp_get_period_ns_t)(const void*);
|
||||
typedef int (*pwm_fp_get_pulse_width_ns_t)(const void*);
|
||||
|
||||
struct pwm_fp {
|
||||
const pwm_fp_open_t open;
|
||||
const pwm_fp_close_t close;
|
||||
const pwm_fp_set_duty_cycle_t set_duty_cycle;
|
||||
const pwm_fp_get_period_ns_t get_period;
|
||||
const pwm_fp_get_pulse_width_ns_t get_pulse_width;
|
||||
};
|
||||
|
||||
struct pwm {
|
||||
const void *arch_dep_device; //!< Architecture depended pwm device (i.e. stm32f10x_pwm_t).
|
||||
const struct pwm_fp *fp; //!< Function pointer for the pwm driver access.
|
||||
const struct pwm_fp *fp; //!< Function pointer for the pwm driver access.
|
||||
};
|
||||
|
||||
int pwm_open(const struct pwm *device);
|
||||
int pwm_close(const struct pwm *device);
|
||||
int pwm_set_duty_cycle(const struct pwm *device, unsigned int duty_cycle_percent);
|
||||
int pwm_get_period_ns(const struct pwm *device);
|
||||
int pwm_get_pulse_width_ns(const struct pwm *device);
|
||||
|
||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_PWM_H_ */
|
||||
|
@@ -31,3 +31,19 @@ int pwm_set_duty_cycle(const struct pwm *device, unsigned int duty_cycle_percent
|
||||
pwm_fp_set_duty_cycle_t set = device->fp->set_duty_cycle;
|
||||
return set(device->arch_dep_device, duty_cycle_percent);
|
||||
}
|
||||
|
||||
int pwm_get_period_ns(const struct pwm *device)
|
||||
{
|
||||
if(NULL == device)
|
||||
return -1;
|
||||
pwm_fp_get_period_ns_t get = device->fp->get_period;
|
||||
return get(device->arch_dep_device);
|
||||
}
|
||||
|
||||
int pwm_get_pulse_width_ns(const struct pwm *device)
|
||||
{
|
||||
if(NULL == device)
|
||||
return -1;
|
||||
pwm_fp_get_pulse_width_ns_t get = device->fp->get_pulse_width;
|
||||
return get(device->arch_dep_device);
|
||||
}
|
||||
|
@@ -8,7 +8,9 @@
|
||||
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||
|
||||
#define IOCTL_PWM_SET_DUTY_CYCLE 0
|
||||
#define IOCTL_PWM_SET_DUTY_CYCLE 0
|
||||
#define IOCTL_PWM_GET_PERIOD_NS 1
|
||||
#define IOCTL_PWM_GET_PULSE_WIDTH_NS 2
|
||||
|
||||
enum driver_type {
|
||||
DRIVER_TYPE_ADC,
|
||||
|
Reference in New Issue
Block a user