Commit c75128e5 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Don't build joystick code on BSD.

Add 't_off' parameter to am335 pwm block.
t_off will be the minimum time the bridge is switched low per pwm period.
(To allow boost C to recharge)
parent f3e2571a
COMMAND_TARGETS += $(LIBDIR)/libcommand.la COMMAND_TARGETS += $(LIBDIR)/libcommand.la
COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send $(DIR)/command_joystick COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send
ifneq ($(OS), FreeBSD)
COMMAND_TARGETS += $(DIR)/command_joystick
endif
ARCHSRCS := $(DIR)/command.c $(DIR)/command_tcp.c ARCHSRCS := $(DIR)/command.c $(DIR)/command_tcp.c
......
...@@ -28,6 +28,7 @@ struct controller_block_private { ...@@ -28,6 +28,7 @@ struct controller_block_private {
float tbprd; // period float tbprd; // period
double freq; double freq;
double t_off;
bool sym; bool sym;
void *base; void *base;
...@@ -63,16 +64,19 @@ static void set_freq(struct controller_block *pwm) ...@@ -63,16 +64,19 @@ static void set_freq(struct controller_block *pwm)
int clkdiv = 0; int clkdiv = 0;
int div = 1; int div = 1;
double period, freq; double period, freq;
double t_off;
uint16_t tbprd; uint16_t tbprd;
uint16_t aqctl; uint16_t aqctl;
/* double divider for symmetric use */ /* double divider for symmetric use */
period = AM335X_SYSCLK / (priv->freq * ( priv->sym ? 2.0 : 1.0)); period = AM335X_SYSCLK / (priv->freq * ( priv->sym ? 2.0 : 1.0));
t_off = AM335X_SYSCLK * priv->t_off / (priv->sym ? 2.0 : 1.0);
while (period > AM335X_PWMSS_EPWM_TBPRD_MAX) { while (period > AM335X_PWMSS_EPWM_TBPRD_MAX) {
clkdiv++; clkdiv++;
div *= 2; div *= 2;
period /= 2.0; period /= 2.0;
t_off /= 2.0;
if (clkdiv == AM335X_PWMSS_EPWM_TBCTL_CLKDIV_MAX) if (clkdiv == AM335X_PWMSS_EPWM_TBCTL_CLKDIV_MAX)
break; break;
} }
...@@ -126,13 +130,14 @@ static void set_freq(struct controller_block *pwm) ...@@ -126,13 +130,14 @@ static void set_freq(struct controller_block *pwm)
am335x_write16(base, AM335X_PWMSS_REG_EPWM_CMPA, 0); am335x_write16(base, AM335X_PWMSS_REG_EPWM_CMPA, 0);
am335x_write16(base, AM335X_PWMSS_REG_EPWM_CMPB, 0); am335x_write16(base, AM335X_PWMSS_REG_EPWM_CMPB, 0);
priv->tbprd = tbprd; t_off = ceil(t_off);
priv->tbprd = fmax(tbprd - (priv->t_off != 0.0 ? t_off : 0.0), 0.0);
freq = AM335X_SYSCLK / (tbprd * div * ( priv->sym ? 2.0 : 1.0)); freq = AM335X_SYSCLK / (tbprd * div * ( priv->sym ? 2.0 : 1.0));
log_send(LOG_T_DEBUG, log_send(LOG_T_DEBUG,
"%s: Frequency: %gHz, period: %d ticks, divider: %d", "%s: Frequency: %gHz, period: %d ticks (%d available), divider: %d",
pwm->name, freq, tbprd, div); pwm->name, freq, tbprd, (int)priv->tbprd, div);
priv->freq = freq; priv->freq = freq;
} }
...@@ -152,9 +157,19 @@ static int param_set_sym(struct controller_block *pwm, char *param, int argc, ...@@ -152,9 +157,19 @@ static int param_set_sym(struct controller_block *pwm, char *param, int argc,
return 0; return 0;
} }
static int param_set_t_off(struct controller_block *pwm, char *param, int argc,
va_list val)
{
pwm->private->t_off = va_arg(val, double);
set_freq(pwm);
return 0;
}
static struct controller_block_param_list params[] = { static struct controller_block_param_list params[] = {
{ "frequency", false, param_set_freq, .args = { "double", NULL } }, { "frequency", false, param_set_freq, .args = { "double", NULL } },
{ "symmetrical", false, param_set_sym, .args = { "int", NULL } }, { "symmetrical", false, param_set_sym, .args = { "int", NULL } },
{ "t_off", false, param_set_t_off, .args = { "double", NULL } },
{ NULL }, { NULL },
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment