예제 #1
0
int mdaq_pwm_setup(uint8_t channel, uint32_t period, uint8_t polarity)
{
#if (!defined MATLAB_MEX_FILE) && (!defined MDL_REF_SIM_TGT)
	period *= PWM_PERIOD_TO_US;
	mdaq_pwm_period[channel] = period;
	ehrpwm_pwm_set_prd(channel, period, polarity);
	ehrpwm_pwm_set_dty(channel, 0);
#endif 
	return 0;
}
예제 #2
0
파일: ehrpwm.c 프로젝트: BorisTw/BBB-kernel
static int ehrpwm_pwm_config(struct pwm_device *p,
	struct pwm_config *c)
{
	int ret = 0;

	switch (c->config_mask) {
	case BIT(PWM_CONFIG_PERIOD_TICKS):
		if (p->max_period_ticks &&
				(p->max_period_ticks >= c->period_ticks))
			p->period_ticks = p->max_period_ticks;
		else
			p->period_ticks = c->period_ticks;

		ret = ehrpwm_pwm_set_prd(p);
		break;

	case BIT(PWM_CONFIG_DUTY_TICKS):
		p->duty_ticks = c->duty_ticks;
		ret = ehrpwm_pwm_set_dty(p);
		break;

	case BIT(PWM_CONFIG_POLARITY):
		p->active_high = c->polarity;
		ret = ehrpwm_pwm_set_pol(p);
		break;

	case BIT(PWM_CONFIG_START):
		 ret = ehrpwm_pwm_start(p);
		 break;

	case BIT(PWM_CONFIG_STOP):
		ret = ehrpwm_pwm_stop(p);
		break;

	default:
		dev_dbg(p->dev, "%s: Invalid configuration\n", __func__);
		ret = -EINVAL;
	}

	return ret;
}