world leader in high performance signal processing
Trace:

Differences

This shows you the differences between two versions of the page.

gptimers [2007/10/23 08:11]
vapier created
gptimers [2009/10/21 23:26] (current)
vapier split linux docs into linux-kernel:drivers:gptimers
Line 15: Line 15:
 ===== Linux API ===== ===== Linux API =====
  
-There are a few Linux APIs you need to leverage in order to utilize the timers properly.  We will use timer 5 in the example as it should be readily available on the BF537 stamp board. +See the [[linux-kernel:drivers:gptimers|Linux gptimers API]] page for more info on using the General Purpose Timers under Linux.
- +
-You can convert between units of system clocks and time by using the helper functions ''sclk_to_usecs'' and ''usecs_to_sclk''. +
- +
-==== Pulse Width Count and Capture Mode (WDTH_CAP) ==== +
- +
-Before you can use the gptimers functions, you must first make sure to allocate and portmux the pins.  This can be accomplished via the portmuxing API.  Once you've taken the peripheral for yourself, you enable the IRQ for it Finally you setup the timer and enable it.  Once the timer starts receiving valid wave forms, you'll receive an IRQ for them. +
- +
-<code c> +
-... +
-#include <linux/interrupt.h> +
-#include <asm/gptimers.h> +
-#include <asm/portmux.h> +
-... +
-#define DRIVER_NAME "gptimer_example" +
-... +
-struct gptimer_data { +
- uint32_t period, width; +
-}; +
-static struct gptimer_data data; +
-... +
-static irqreturn_t gptimer_example_irq(int irq, void *dev_id) +
-+
- struct gptimer_data *data = dev_id; +
- +
- /* make sure it was our timer which caused the interrupt */ +
- if (!get_gptimer_intr(TIMER5_id)) +
- return IRQ_NONE; +
- +
- /* read the width/period values that were captured for the waveform */ +
- d->width = get_gptimer_pwidth(TIMER5_id); +
- d->period = get_gptimer_period(TIMER5_id); +
- +
- /* acknowledge the interrupt */ +
- clear_gptimer_intr(TIMER5_id); +
- +
- /* tell the upper layers we took care of things */ +
- return IRQ_HANDLED; +
-+
-... +
-static int __init gptimer_example_init(void) +
-+
- int ret; +
- +
- /* grab the peripheral pins */ +
- ret = peripheral_request(P_TMR5, DRIVER_NAME); +
- if (ret) { +
- printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n"); +
- return ret; +
-+
- +
- /* grab the IRQ for the timer */ +
- ret = request_irq(IRQ_TMR5, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data); +
- if (ret) { +
- printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n"); +
- peripheral_free(P_TMR5); +
- return ret; +
-+
- +
- /* setup the timer and enable it */ +
- set_gptimer_config(TIMER5_id, WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA); +
- enable_gptimers(TIMER5bit); +
- +
- return 0; +
-+
-module_init(gptimer_example_init); +
- +
-static int __exit gptimer_example_exit(void) +
-+
- disable_gptimers(TIMER5bit); +
- free_irq(IRQ_TMR5, &data); +
- peripheral_free(P_TMR5); +
-+
-module_exit(gptimer_example_exit); +
-</code> +