Initial commit (autogenerated files)
[rmslog.git] / rmslog / hw / hw_stepper.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  * All Rights Reserved.
31  * -->
32  *
33  * \brief Stepper hardware-specific definitions
34  *
35  *
36  * \author Daniele Basile <asterix@develer.com>
37  */
38
39
40 #ifndef HW_STEPPER_H
41 #define HW_STEPPER_H
42
43 #include <hw/hw_cpufreq.h>
44
45 #include <cfg/macros.h>
46
47 #include <drv/timer.h>
48
49 #warning TODO:This is an example implentation, you must implement it!
50
51 #define STEPPER_STROBE_INIT \
52 do { \
53                 /* put init code for strobe */ \
54 } while (0)
55
56
57 #define STEPPER_STROBE_ON       do { /* Implement me! */ } while(0)
58 #define STEPPER_STROBE_OFF      do { /* Implement me! */ } while(0)
59
60 /**
61  * CPU clock frequency is divided by 2^STEPPER_PRESCALER_LOG2 to
62  * obtain stepper clock.
63  */
64 #define STEPPER_PRESCALER_LOG2    1
65
66 /**
67  * Stepper timer clock frequency.
68  */
69 #define STEPPER_CLOCK ((CPU_FREQ) >> STEPPER_PRESCALER_LOG2)
70
71 /**
72  * us delay to reset a stepper motor.
73  * This is the time neccessary to reset
74  * the stepper controll chip. (see datasheet for more detail).
75  */
76 #define STEPPER_RESET_DELAY 1
77
78 /*
79  * Pins define for each stepper
80  */
81 #define STEPPER_1_CW_CCW_PIN             0
82 #define STEPPER_1_HALF_FULL_PIN          0
83 #define STEPPER_1_CONTROL_PIN            0
84 #define STEPPER_1_ENABLE_PIN             0
85 #define STEPPER_1_RESET_PIN              0
86
87 /* put here other stepper motor */
88
89 #define STEPPER_1_SET            do { /* Implement me! */ } while(0)
90 /* add here the set for other stepper motor */
91
92 #define STEPPER_1_CLEAR          do { /* Implement me! */ } while(0)
93 /* add here the clear for other stepper motor */
94
95 /*
96  * Generic macro definition
97  */
98
99 /*
100  * Stepper init macro
101  */
102 #define STEPPER_PIN_INIT_MACRO(port, index) do { \
103                 /* Add here init pin code */ \
104         } while (0)
105
106 /*
107  * Stepper commands macros
108  */
109 #define STEPPER_SET_CW(index)             do { /* Implement me! */ } while (0)
110 #define STEPPER_SET_CCW(index)            do { /* Implement me! */ } while (0)
111 #define STEPPER_SET_HALF(index)           do { /* Implement me! */ } while (0)
112 #define STEPPER_SET_FULL(index)           do { /* Implement me! */ } while (0)
113 #define STEPPER_SET_CONTROL_LOW(index)    do { /* Implement me! */ } while (0)
114 #define STEPPER_SET_CONTROL_HIGHT(index)  do { /* Implement me! */ } while (0)
115 #define STEPPER_SET_ENABLE(index)         do { /* Implement me! */ } while (0)
116 #define STEPPER_SET_DISABLE(index)        do { /* Implement me! */ } while (0)
117 #define STEPPER_SET_RESET_ENABLE(index)   do { /* Implement me! */ } while (0)
118 #define STEPPER_SET_RESET_DISABLE(index)  do { /* Implement me! */ } while (0)
119
120
121 /*
122  * Reset stepper macro
123  */
124
125 #define STEPPER_RESET_MACRO(index) do { \
126                 STEPPER_SET_RESET_ENABLE(index); \
127                 timer_udelay(STEPPER_RESET_DELAY); \
128                 STEPPER_SET_RESET_DISABLE(index); \
129         } while (0)
130
131 /*
132  * Set half or full step macro
133  */
134 #define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \
135                 if (flag) \
136                         STEPPER_SET_HALF(index); \
137                 else \
138                         STEPPER_SET_FULL(index); \
139         } while (0)
140
141 /*
142  * Set control status macro
143  */
144 #warning TODO: This macro is not implemented (see below)
145
146 #define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \
147                 /* if (flag) */ \
148                         /* WARNING This macros not implemented */ \
149                 /* else */ \
150                         /* WARNING This macros not implemented */ \
151         } while (0)
152
153 /*
154  * Set current power macro
155  */
156 #warning TODO: This macro is not implemented (see below)
157
158 #define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \
159                 /* if (flag) */ \
160                         /* WARNING This macrois not implemented */ \
161                 /* else */ \
162                         /* WARNING This macrois not implemented */ \
163         } while (0)
164
165 /*
166  * Set rotation of stepper motor
167  * - dir = 1: positive rotation
168  * - dir = 0: no motor moviment
169  * - dir = -1: negative rotation
170  *
171  */
172 #define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \
173                 switch (dir) \
174                 { \
175                 case 1: \
176                         STEPPER_SET_CW(index); \
177                         break; \
178                 case -1: \
179                         STEPPER_SET_CCW(index); \
180                         break; \
181                 case 0: \
182                         break; \
183                 } \
184         } while (0)
185
186
187 /*
188  * Define macros for manage low level of stepper.
189  */
190
191 #define STEPPER_INIT()  do { \
192                 STEPPER_PIN_INIT_MACRO(A, 1); \
193                 /* Add here code for other stepper motor */ \
194         } while (0)
195
196
197 /*
198  * Enable select stepper motor
199  */
200 #define STEPPER_ENABLE(index) do { \
201                 switch (index) \
202                 { \
203                 case 1: \
204                         STEPPER_SET_ENABLE(1); \
205                         break; \
206                         /* Add here code for other stepper motor */ \
207                 } \
208         } while (0)
209
210 /*
211  * Enable all stepper connect to micro
212  */
213 #define STEPPER_ENABLE_ALL() do { \
214                 STEPPER_SET_ENABLE(1); \
215                 /* Add here code for other stepper motor */ \
216         } while (0)
217
218 /*
219  * Disable select stepper motor
220  */
221 #define STEPPER_DISABLE(index) do { \
222                 switch (index) \
223                 { \
224                 case 1: \
225                         STEPPER_SET_DISABLE(1); \
226                         break; \
227                         /* Add here code for other stepper motor */ \
228                 } \
229         } while (0)
230
231 /*
232  * Disable all stepper connect to micro
233  */
234 #define STEPPER_DISABLE_ALL() do { \
235                 STEPPER_SET_DISABLE(1); \
236                 /* Add here code for other stepper motor */ \
237         } while (0)
238
239 /*
240  * Reset selected stepper motor
241  */
242 #define STEPPER_RESET(index) do { \
243                 switch (index) \
244                 { \
245                 case 1: \
246                         STEPPER_RESET_MACRO(1); \
247                         break; \
248                         /* Add here code for other stepper motor */ \
249                 } \
250         } while (0)
251
252 /*
253  * Reset all stepper motor
254  */
255 #define STEPPER_RESET_ALL() do { \
256                 STEPPER_RESET_MACRO(1) \
257                 /* Add here code for other stepper motor */ \
258         } while (0)
259
260 // Set half/full step macros
261 #define STEPPER_SET_HALF_STEP(index, flag) do { \
262                 switch (index) \
263                 { \
264                 case 1: \
265                         STEPPER_SET_STEP_MODE_MACRO(1, flag); \
266                         break; \
267                         /* Add here code for other stepper motor */ \
268                 } \
269         } while (0)
270
271
272 // Control status
273 #define STEPPER_SET_CONTROL_BIT(index, flag) do { \
274                 switch (index) \
275                 { \
276                 case 1: \
277                         STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \
278                         break; \
279                         /* Add here code for other stepper motor */ \
280                 } \
281         } while (0)
282
283
284 // Set stepper power current
285 #define STEPPER_SET_POWER_CURRENT(index, flag) do { \
286                 switch (index) \
287                 { \
288                 case 1: \
289                         STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \
290                         break; \
291                         /* Add here code for other stepper motor */ \
292                 } \
293         } while (0)
294
295 // Set rotation dirction of stepper motor
296 #define STEPPER_SET_DIRECTION(index, dir) do { \
297                 switch (index) \
298                 { \
299                 case 1: \
300                         STEPPER_SET_DIRECTION_MACRO(1, dir); \
301                         break; \
302                         /* Add here code for other stepper motor */ \
303                 } \
304         } while (0)
305
306 #endif /* HW_STEPPER_H */
307
308