Merge branch "preempt" in "trunk".
[bertos.git] / bertos / cpu / avr / drv / stepper_avr.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief Low-level stepper timer module for AVR (inplementation).
34  *
35  * \version $Id$
36  *
37  * \author Daniele Basile <asterix@develer.com>
38  *
39  */
40
41 #ifndef DRV_STEPPER_AVR_H
42 #define DRV_STEPPER_AVR_H
43
44
45 #include <cfg/compiler.h>
46 #include <cfg/macros.h>
47
48 #include <drv/stepper.h>
49
50 #warning TODO:This is an example, you must implement it!
51
52 /**
53  * IRQ callback function type definition.
54  */
55 typedef void (*irq_t)(void);
56
57 /**
58  * Timer contex structure.
59  */
60 typedef struct TimerCounter
61 {
62         int timer_id;                  ///< Timer counter ID
63         irq_t isr;                     ///< IRQ handler
64         stepper_isr_t callback;        ///< Interrupt callback pointer
65         struct Stepper *motor;         ///< Stepper context structure
66
67 } TimerCounter;
68
69 /**
70  * Enable interrupt for timer counter compare event.
71  */
72 INLINE void stepper_tc_irq_enable(struct TimerCounter *timer)
73 {
74                 /* put here code to enable timer irq */
75
76                 //Only for test remove when implement this function
77                 (void)timer;
78 }
79
80
81 /**
82  * Disable interrupt for timer counter compare event.
83  */
84 INLINE void  stepper_tc_irq_disable(struct TimerCounter *timer)
85 {
86                 /* put here code to disable timer irq */
87
88                 //Only for test remove when implement this function
89                 (void)timer;
90 }
91
92 /**
93  * Set delay for next interrupt compare event.
94  */
95 INLINE void  stepper_tc_setDelay(struct TimerCounter *timer, stepper_time_t delay)
96 {
97                 /* put here code to set the delay for next irq */
98
99                 //Only for test remove when implement this function
100                 (void)timer;
101                 (void)delay;
102 }
103
104
105 /**
106  * Set delay for next interrupt compare event.
107  */
108 INLINE void  stepper_tc_resetTimer(struct TimerCounter *timer)
109 {
110                 /* put here code to reset the timer */
111
112                 //Only for test remove when implement this function
113                 (void)timer;
114 }
115
116 /**
117  * Programm timer counter to generate a pulse on select TIO output.
118  */
119 INLINE void FAST_FUNC stepper_tc_doPulse(struct TimerCounter *timer)
120 {
121                 /* put here code to generate a pulse */
122
123                 //Only for test remove when implement this function
124                 (void)timer;
125 }
126
127 /**
128  * Programm timer counter to not generate a pulse on select TIO output.
129  */
130 INLINE void FAST_FUNC stepper_tc_skipPulse(struct TimerCounter *timer)
131 {
132                 /* put here code to skip a pulse */
133
134                 //Only for test remove when implement this function
135                 (void)timer;
136 }
137
138 void stepper_tc_setup(int index, stepper_isr_t callback, struct Stepper *motor);
139 void stepper_tc_init(void);
140
141 #endif /*DRV_STEPPER_AVR_H */