use real time
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/timekeeping.h>
|
||||
|
||||
#include "ls7366r.h"
|
||||
|
||||
@ -45,14 +46,14 @@ struct counter_irq_data {
|
||||
struct work_struct work;
|
||||
u64 timestamp;
|
||||
struct spi_device *client;
|
||||
u64 last_timestamp;
|
||||
struct timespec64 current_timestamp;
|
||||
struct timespec64 last_timestamp;
|
||||
u32 last_value;
|
||||
};
|
||||
static struct counter_irq_data counter_irq_wq_data;
|
||||
|
||||
static void counter_worker(struct work_struct *work) {
|
||||
struct counter_irq_data *data = container_of(work, struct counter_irq_data, work);
|
||||
u64 ts = data->timestamp;
|
||||
|
||||
u32 counter_value;
|
||||
int ret = read_otr(data->client, &counter_value);
|
||||
@ -64,16 +65,23 @@ static void counter_worker(struct work_struct *work) {
|
||||
|
||||
if (data->last_value) {
|
||||
u32 period = counter_value - data->last_value;
|
||||
u64 duration = ts - data->last_timestamp;
|
||||
printk("counter %llu %llu %u\n", ts, duration, period);
|
||||
struct timespec64 duration = timespec64_sub(data->current_timestamp, data->last_timestamp);
|
||||
printk("counter %lld.%09lu %lld.%09lu %u\n",
|
||||
(s64)((data->current_timestamp).tv_sec),
|
||||
((data->current_timestamp).tv_nsec),
|
||||
(s64)duration.tv_sec,
|
||||
duration.tv_nsec,
|
||||
period);
|
||||
|
||||
|
||||
}
|
||||
data->last_value = counter_value;
|
||||
data->last_timestamp = ts;
|
||||
data->last_timestamp = data->current_timestamp;
|
||||
}
|
||||
|
||||
// ISR
|
||||
static irqreturn_t counter_isr(int irq, void *dev_id) {
|
||||
counter_irq_wq_data.timestamp = ktime_get();
|
||||
ktime_get_real_ts64(&counter_irq_wq_data.current_timestamp);
|
||||
schedule_work(&counter_irq_wq_data.work);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
@ -86,7 +94,6 @@ static int dt_interrupt_probe(struct platform_device *pdev) {
|
||||
INIT_WORK(&counter_irq_wq_data.work, counter_worker);
|
||||
counter_irq_wq_data.client = ls7366r_spi_client;
|
||||
counter_irq_wq_data.last_value = 0;
|
||||
counter_irq_wq_data.last_timestamp = 0;
|
||||
|
||||
counter_interrupt = gpiod_get(dev, "intr", GPIOD_IN);
|
||||
if (IS_ERR(counter_interrupt)) {
|
||||
|
Reference in New Issue
Block a user