* Fwd: iio_trigger doesn't work [not found] <CAEE_umptNVPOYeTANC4mtAo8AxizmFkrFoa0eLGoLFtTRgWzng@mail.gmail.com> @ 2012-09-19 15:57 ` Denis Ciocca 2012-09-19 16:14 ` Jonathan Cameron 2012-09-19 17:13 ` Lars-Peter Clausen 0 siblings, 2 replies; 7+ messages in thread From: Denis Ciocca @ 2012-09-19 15:57 UTC (permalink / raw) To: linux-iio Hi everybody, I write in this mailing list because I have some problems to understand the trigger event catch and I ask for your help. I write a little driver for accelerometer and the core driver works, but now I want to write trigger code. What I understand is that: 1. register iio_trigger; 2. associate iio_trigger to iio_dev; 3. associate pollfunc with iio_alloc_pollfunc to iio_info; when trigger occuring (in my example at hrtimers), I call iio_trigger_poll() function and I expect which handler function declared inside iio_alloc_pollfunc(...) is called. This does not happen! What I'm doing wrong? There is some documentation about this? Thanks, Denis ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-19 15:57 ` Fwd: iio_trigger doesn't work Denis Ciocca @ 2012-09-19 16:14 ` Jonathan Cameron 2012-09-19 17:13 ` Lars-Peter Clausen 1 sibling, 0 replies; 7+ messages in thread From: Jonathan Cameron @ 2012-09-19 16:14 UTC (permalink / raw) To: Denis Ciocca, linux-iio Denis Ciocca <denis.ciocca@gmail.com> wrote: >Hi everybody, > >I write in this mailing list because I have some problems to >understand the trigger event catch and I ask for your help. > >I write a little driver for accelerometer and the core driver works, >but now I want to write trigger code. What I understand is that: > >1. register iio_trigger; >2. associate iio_trigger to iio_dev; >3. associate pollfunc with iio_alloc_pollfunc to iio_info; Buffer set up and enabled? > >when trigger occuring (in my example at hrtimers), I call >iio_trigger_poll() function and I expect which handler function >declared inside iio_alloc_pollfunc(...) is called. >This does not happen! Superficially looks correct. Verify the trigger association worked by checking current_trigger under sysfs entry for the iio device. Otherwise either post code or insert some printk statements to see where things are going. > >What I'm doing wrong? >There is some documentation about this? Kind of in code... generic_buffer.c for userspace side and dummy driver for kernel side. Text docs rotted so until someone has time to update heavily commented examples were more useful. > >Thanks, > >Denis >-- >To unsubscribe from this list: send the line "unsubscribe linux-iio" in >the body of a message to majordomo@vger.kernel.org >More majordomo info at http://vger.kernel.org/majordomo-info.html -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-19 15:57 ` Fwd: iio_trigger doesn't work Denis Ciocca 2012-09-19 16:14 ` Jonathan Cameron @ 2012-09-19 17:13 ` Lars-Peter Clausen 2012-09-20 7:43 ` Denis Ciocca 1 sibling, 1 reply; 7+ messages in thread From: Lars-Peter Clausen @ 2012-09-19 17:13 UTC (permalink / raw) To: Denis Ciocca; +Cc: linux-iio On 09/19/2012 05:57 PM, Denis Ciocca wrote: > Hi everybody, > > [...] > > What I'm doing wrong? Hi, answering this certainly becomes easier if you'd post the code in question. :) - Lars ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-19 17:13 ` Lars-Peter Clausen @ 2012-09-20 7:43 ` Denis Ciocca 2012-09-20 11:44 ` Lars-Peter Clausen 0 siblings, 1 reply; 7+ messages in thread From: Denis Ciocca @ 2012-09-20 7:43 UTC (permalink / raw) To: linux-iio a little bit of code: accelerometer_core.c ** static irqreturn_t acc_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct acc_data *adata = iio_priv(indio_dev); struct iio_buffer *buffer = indio_dev->buffer; pr_info("test.\n"); iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED; } static int __devinit acc_probe(struct i2c_client *client, const struct i2c_device_id *id) { ... err = acc_probe_trigger(indio_dev); if(err < 0) { pr_err("%s(0x%x): acc_probe_trigger failed.\n", client->name, (u8)client->addr); goto acc_probe_trigger_error; } indio_dev->pollfunc = iio_alloc_pollfunc( &iio_pollfunc_store_time, &acc_trigger_handler, IRQF_ONESHOT, indio_dev, "consumer%d", indio_dev->id); if(indio_dev->pollfunc == NULL) { ret = -ENOMEM; goto iio_alloc_pollfunc_error; } indio_dev->modes |= INDIO_BUFFER_TRIGGERED; ... } ** accelerometer_trigger.c static enum hrtimer_restart iio_trig_hrtimer_trig(struct hrtimer *time) { struct acc_data *adata = container_of(time, struct acc_data, timer); ktime_t period; period = ktime_set(0, NSEC_PER_SEC / adata->odr); hrtimer_forward_now(&adata->timer, period); pr_info("prova\n"); iio_trigger_poll_chained(adata->trig, iio_get_time_ns()); return HRTIMER_RESTART; } static const struct iio_trigger_ops iio_acc_trigger_ops = { .owner = THIS_MODULE, }; int acc_probe_trigger(struct iio_dev *indio_dev) { struct acc_data *adata; int err; adata = iio_priv(indio_dev); pr_info("%s(0x%x): trigger probe start.\n", adata->client->name, (u8)adata->client->addr); adata->trig = iio_trigger_alloc("%s-periodic_task-%d", indio_dev->name, indio_dev->id); if(adata->trig == NULL) { err = -ENOMEM; pr_err("%s(0x%x): failed to allocate iio trigger." "\n", adata->client->name, (u8)adata->client->addr); goto iio_trigger_alloc_error; } adata->trig->private_data = indio_dev; adata->trig->ops = &iio_acc_trigger_ops; adata->trig->dev.parent = &adata->client->dev; hrtimer_init(&adata->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); adata->timer.function = iio_trig_hrtimer_trig; err = iio_trigger_register(adata->trig); if (err < 0) { pr_err("%s(0x%x): failed to register iio trigger." "\n", adata->client->name, (u8)adata->client->addr); goto iio_trigger_register_error; } indio_dev->trig = adata->trig; hrtimer_start(&adata->timer, ktime_set(0, NSEC_PER_SEC/adata->odr), HRTIMER_MODE_REL); return 0; iio_trigger_register_error: iio_trigger_free(adata->trig); iio_trigger_alloc_error: return err; } I expect the message by pr_info is printed every delta time, but it doesn't work. Can you help me? It is mandatory use buffer? This is only an example, I am not expected that is useful. Sorry for the code style but I am newby. Thanks Denis 2012/9/19 Lars-Peter Clausen <lars@metafoo.de>: > On 09/19/2012 05:57 PM, Denis Ciocca wrote: >> Hi everybody, >> >> [...] >> >> What I'm doing wrong? > > Hi, > > answering this certainly becomes easier if you'd post the code in > question. :) > > - Lars ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-20 7:43 ` Denis Ciocca @ 2012-09-20 11:44 ` Lars-Peter Clausen 2012-09-20 12:44 ` Denis Ciocca 0 siblings, 1 reply; 7+ messages in thread From: Lars-Peter Clausen @ 2012-09-20 11:44 UTC (permalink / raw) To: Denis Ciocca; +Cc: linux-iio On 09/20/2012 09:43 AM, Denis Ciocca wrote: > a little bit of code: > > accelerometer_core.c > > ** > static irqreturn_t acc_trigger_handler(int irq, void *p) > { > struct iio_poll_func *pf = p; > struct iio_dev *indio_dev = pf->indio_dev; > struct acc_data *adata = iio_priv(indio_dev); > struct iio_buffer *buffer = indio_dev->buffer; > > pr_info("test.\n"); > > iio_trigger_notify_done(indio_dev->trig); > return IRQ_HANDLED; > } > > static int __devinit acc_probe(struct i2c_client *client, > const struct i2c_device_id *id) > { > ... > err = acc_probe_trigger(indio_dev); > if(err < 0) > { > pr_err("%s(0x%x): acc_probe_trigger failed.\n", > client->name, (u8)client->addr); > goto acc_probe_trigger_error; > } > indio_dev->pollfunc = iio_alloc_pollfunc( > &iio_pollfunc_store_time, > &acc_trigger_handler, > IRQF_ONESHOT, > indio_dev, > "consumer%d", > indio_dev->id); > if(indio_dev->pollfunc == NULL) > { > ret = -ENOMEM; > goto iio_alloc_pollfunc_error; > } > indio_dev->modes |= INDIO_BUFFER_TRIGGERED; > ... > } > ** > > > accelerometer_trigger.c > > static enum hrtimer_restart iio_trig_hrtimer_trig(struct hrtimer *time) > { > struct acc_data *adata = container_of(time, struct acc_data, timer); > ktime_t period; > > period = ktime_set(0, NSEC_PER_SEC / adata->odr); > hrtimer_forward_now(&adata->timer, period); > pr_info("prova\n"); > iio_trigger_poll_chained(adata->trig, iio_get_time_ns()); > return HRTIMER_RESTART; > } > > static const struct iio_trigger_ops iio_acc_trigger_ops = { > .owner = THIS_MODULE, > }; > > int acc_probe_trigger(struct iio_dev *indio_dev) > { > struct acc_data *adata; > int err; > > adata = iio_priv(indio_dev); > pr_info("%s(0x%x): trigger probe start.\n", adata->client->name, > (u8)adata->client->addr); > > adata->trig = iio_trigger_alloc("%s-periodic_task-%d", > indio_dev->name, indio_dev->id); > if(adata->trig == NULL) > { > err = -ENOMEM; > pr_err("%s(0x%x): failed to allocate iio trigger." > "\n", adata->client->name, (u8)adata->client->addr); > goto iio_trigger_alloc_error; > } > > adata->trig->private_data = indio_dev; > adata->trig->ops = &iio_acc_trigger_ops; > adata->trig->dev.parent = &adata->client->dev; > > hrtimer_init(&adata->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); > adata->timer.function = iio_trig_hrtimer_trig; > > err = iio_trigger_register(adata->trig); > if (err < 0) > { > pr_err("%s(0x%x): failed to register iio trigger." > "\n", adata->client->name, (u8)adata->client->addr); > goto iio_trigger_register_error; > } > indio_dev->trig = adata->trig; > hrtimer_start(&adata->timer, ktime_set(0, NSEC_PER_SEC/adata->odr), > HRTIMER_MODE_REL); > return 0; > > iio_trigger_register_error: > iio_trigger_free(adata->trig); > iio_trigger_alloc_error: > return err; > } > > > I expect the message by pr_info is printed every delta time, but it > doesn't work. Can you help me? It is mandatory use buffer? Yes, you need a buffer. The trigger won't be activated until the buffer is active. To activate the buffer you need to select at least one scan element in the scan_elements subfolder of you IIO device, then set the buffer size by writing to buffer/length and finally write a 1 to buffer/enable. Now you should see your acc_trigger_handler being called. Btw. Marten Svanfeldt wrote a generic higres timer trigger for IIO. Unfortunately this driver is not ready for mainline yet, but I've pushed it to https://github.com/lclausen-adi/linux-2.6/commit/6f34757 in case you want to take a look at it or use it. - Lars ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-20 11:44 ` Lars-Peter Clausen @ 2012-09-20 12:44 ` Denis Ciocca 2012-09-20 13:12 ` Lars-Peter Clausen 0 siblings, 1 reply; 7+ messages in thread From: Denis Ciocca @ 2012-09-20 12:44 UTC (permalink / raw) To: Lars-Peter Clausen; +Cc: linux-iio > Yes, you need a buffer. The trigger won't be activated until the buffer is > active. To activate the buffer you need to select at least one scan element > in the scan_elements subfolder of you IIO device, then set the buffer size > by writing to buffer/length and finally write a 1 to buffer/enable. Now you > should see your acc_trigger_handler being called. I don't understand what you mean with: "select at least one scan element in the scan_elements subfolder" I have seen the adis16240 accelerometer driver for example but I don't saw anything about scan element. Can you be more specific? > Btw. Marten Svanfeldt wrote a generic higres timer trigger for IIO. > Unfortunately this driver is not ready for mainline yet, but I've pushed it > to https://github.com/lclausen-adi/linux-2.6/commit/6f34757 in case you want > to take a look at it or use it. Now I look! Thanks ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: iio_trigger doesn't work 2012-09-20 12:44 ` Denis Ciocca @ 2012-09-20 13:12 ` Lars-Peter Clausen 0 siblings, 0 replies; 7+ messages in thread From: Lars-Peter Clausen @ 2012-09-20 13:12 UTC (permalink / raw) To: Denis Ciocca; +Cc: linux-iio On 09/20/2012 02:44 PM, Denis Ciocca wrote: >> Yes, you need a buffer. The trigger won't be activated until the buffer is >> active. To activate the buffer you need to select at least one scan element >> in the scan_elements subfolder of you IIO device, then set the buffer size >> by writing to buffer/length and finally write a 1 to buffer/enable. Now you >> should see your acc_trigger_handler being called. > > I don't understand what you mean with: > "select at least one scan element in the scan_elements subfolder" > I have seen the adis16240 accelerometer driver for example but I don't saw > anything about scan element. Can you be more specific? So each channel has a scan index. And for each channel you can enable whether the channel should be sampled in buffered mode or not. There is a sysfs file for each channel which allows you to do this in the scan_elements subfolder. In order to start sampling you have to enable at least one scan_element by writing a 1 to its enable attribute. - Lars ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-09-20 13:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAEE_umptNVPOYeTANC4mtAo8AxizmFkrFoa0eLGoLFtTRgWzng@mail.gmail.com>
2012-09-19 15:57 ` Fwd: iio_trigger doesn't work Denis Ciocca
2012-09-19 16:14 ` Jonathan Cameron
2012-09-19 17:13 ` Lars-Peter Clausen
2012-09-20 7:43 ` Denis Ciocca
2012-09-20 11:44 ` Lars-Peter Clausen
2012-09-20 12:44 ` Denis Ciocca
2012-09-20 13:12 ` Lars-Peter Clausen
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.