Commit 8468c898 authored by Jorge Machado's avatar Jorge Machado

Fix 8ns glitch

parent 708189b9
......@@ -24,6 +24,8 @@
#include <linux/fmc.h>
#include <linux/fmc-sdb.h>
#include <linux/delay.h>
#include "fmc-dio.h"
#ifdef DIO_STAT
......@@ -105,6 +107,7 @@ static int fmc_dio_int_cmd_pulse(struct fmc_dio *dev,
uint32_t reg;
int ch;
struct regmap_common dio;
uint32_t pulse_per_loaded;
dio = get_regmap_common(dev->version);
......@@ -123,17 +126,27 @@ static int fmc_dio_int_cmd_pulse(struct fmc_dio *dev,
writel(reg | (1 << 4*ch), base + dio.iomode_reg);
/* Clear width and period registers */
pulse_per_loaded = readl(base + map->pulse_per);
writel(0, base + map->pulse_per);
writel(1, base + map->pulse); //Set to 1 to avoid 3 second pulse due to compensation into gw
writel(1 << ch, base + dio.latch_reg);
writel(1 << ch, base + dio.pulse_reg);
atomic_set(&c->count, 0);
writel(ts[1].tv_nsec / 8, base + map->pulse); /* width */
if(cmd->flags & WR_DIO_F_REL)
{
pulse_per_loaded *= 8;
msleep(pulse_per_loaded/1000000);
}
if(cmd->value == 0)
if(cmd->value == 0 && cmd->flags & WR_DIO_F_LOOP)
return 0;
writel(ts[1].tv_nsec / 8, base + map->pulse); /* width */
//if(cmd->value == 0)
// return 0;
if (cmd->flags & WR_DIO_F_NOW) {
/* Generate a pulse train from current time in V2 DIO version*/
......@@ -141,9 +154,9 @@ static int fmc_dio_int_cmd_pulse(struct fmc_dio *dev,
if (cmd->flags & WR_DIO_F_LOOP && cmd->value != 1) {
writel(ts[2].tv_nsec / 8, base + map->pulse_per);
c->target_channel = ch;
if (cmd->value > 1) {
cmd->value-=2;
}
atomic_set(&c->count, cmd->value);
}
}
......@@ -176,9 +189,7 @@ static int fmc_dio_int_cmd_pulse(struct fmc_dio *dev,
}
else {
writel(ts[2].tv_nsec / 8, base + map->pulse_per);
if (cmd->value > 1) {
cmd->value-=1;
}
cmd->value-=2;
}
atomic_set(&c->count, cmd->value);
......@@ -402,6 +413,7 @@ static int fmc_dio_int_cmd_irq(struct fmc_dio *dev,
uint32_t reg;
int ch;
struct regmap_common dio;
uint32_t pulse_per_loaded;
if(dev->version != 1)
return -ENOTSUPP;
......@@ -419,6 +431,21 @@ static int fmc_dio_int_cmd_irq(struct fmc_dio *dev,
ts = cmd->t;
pulse_per_loaded = readl(base + map->pulse_per);
writel(0, base + map->pulse_per);
writel(1, base + map->pulse); //Set to 1 to avoid 3 second pulse due to compensation into gw
writel(1 << ch, base + dio.latch_reg);
atomic_set(&c->count, 0);
if(cmd->flags & WR_DIO_F_REL)
{
pulse_per_loaded *= 8;
msleep(pulse_per_loaded/1000000);
}
if(cmd->value == 0 && cmd->flags & WR_DIO_F_LOOP)
return 0;
/* First, configure the IRQ channel */
reg = readl(base + dio.iomode_reg);
writel((reg | CHANNEL_5_IRQ_EN_MASK), base + dio.iomode_reg);
......@@ -429,9 +456,9 @@ static int fmc_dio_int_cmd_irq(struct fmc_dio *dev,
if (cmd->flags & WR_DIO_F_LOOP && cmd->value != 1) {
writel(ts[1].tv_nsec / 8, base + map->pulse_per);
c->target_channel = ch;
if (cmd->value > 1) {
cmd->value-=2;
}
atomic_set(&c->count, cmd->value);
}
writel(1 << ch, base + dio.pulse_reg);
......@@ -456,9 +483,7 @@ static int fmc_dio_int_cmd_irq(struct fmc_dio *dev,
/* Configure period */
writel( (ts[1].tv_nsec / 8) + (ts[1].tv_sec * 1000000000 / 8), base + map->pulse_per);
if (cmd->value > 1) {
cmd->value-=2;
}
atomic_set(&c->count, cmd->value);
c->prevts = ts[0]; /* our current setpoint */
......
......@@ -129,7 +129,7 @@ static int scan_pulse(int argc, char **argv)
}
if (cmd->t[2].tv_nsec < 1000000)
{
fprintf(stderr, "%s: %s: Frequency is greater than 1 kHz \n",
fprintf(stderr, "%s: %s: Frequency is greater than 1 kHz or higher than 1 s\n",
prgname, argv[0]);
return -1;
}
......@@ -459,7 +459,7 @@ static int scan_irq(int argc, char **argv)
prgname, argv[0], argv[1]);
return -1;
}
if(cmd->t[1].tv_nsec < 1000000 || cmd->t[1].tv_sec < 2)
if(cmd->t[1].tv_nsec < 1000000 || cmd->t[1].tv_sec > 2)
{
fprintf(stderr, "%s: %s: Frequency is greater than 1 kHz and lower than 0.5 Hz\n",
prgname, argv[0]);
......
Markdown is supported
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