Blame view
Documentation/blackfin/gptimers-example.c
2 KB
4b60779d5
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* * Simple gptimers example * http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gptimers * * Copyright 2007-2009 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ #include <linux/interrupt.h> #include <linux/module.h> #include <asm/gptimers.h> #include <asm/portmux.h> /* ... random driver includes ... */ #define DRIVER_NAME "gptimer_example" |
4ae711f4a
|
19 20 21 22 23 |
#ifdef IRQ_TIMER5 #define SAMPLE_IRQ_TIMER IRQ_TIMER5 #else #define SAMPLE_IRQ_TIMER IRQ_TIMER2 #endif |
4b60779d5
|
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
struct gptimer_data { uint32_t period, width; }; static struct gptimer_data data; /* ... random driver state ... */ 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 */ data->width = get_gptimer_pwidth(TIMER5_id); data->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; } /* ... random driver code ... */ 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 "); return ret; } /* grab the IRQ for the timer */ |
4ae711f4a
|
65 66 |
ret = request_irq(SAMPLE_IRQ_TIMER, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data); |
4b60779d5
|
67 68 69 70 71 72 73 74 |
if (ret) { printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed "); peripheral_free(P_TMR5); return ret; } /* setup the timer and enable it */ |
4ae711f4a
|
75 76 |
set_gptimer_config(TIMER5_id, WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA); |
4b60779d5
|
77 78 79 80 81 82 83 84 85 |
enable_gptimers(TIMER5bit); return 0; } module_init(gptimer_example_init); static void __exit gptimer_example_exit(void) { disable_gptimers(TIMER5bit); |
4ae711f4a
|
86 |
free_irq(SAMPLE_IRQ_TIMER, &data); |
4b60779d5
|
87 88 89 90 91 |
peripheral_free(P_TMR5); } module_exit(gptimer_example_exit); MODULE_LICENSE("BSD"); |