4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
33 * \brief Stepper hardware-specific definitions
37 * \author Daniele Basile <asterix@develer.com>
44 #include <hw/hw_cpufreq.h>
46 #include <cfg/macros.h>
48 #include <drv/timer.h>
50 #warning TODO:This is an example implentation, you must implement it!
52 #define STEPPER_STROBE_INIT \
54 /* put init code for strobe */ \
58 #define STEPPER_STROBE_ON do { /* Implement me! */ } while(0)
59 #define STEPPER_STROBE_OFF do { /* Implement me! */ } while(0)
62 * CPU clock frequency is divided by 2^STEPPER_PRESCALER_LOG2 to
63 * obtain stepper clock.
65 #define STEPPER_PRESCALER_LOG2 1
68 * Stepper timer clock frequency.
70 #define STEPPER_CLOCK ((CPU_FREQ) >> STEPPER_PRESCALER_LOG2)
73 * us delay to reset a stepper motor.
74 * This is the time neccessary to reset
75 * the stepper controll chip. (see datasheet for more detail).
77 #define STEPPER_RESET_DELAY 1
80 * Pins define for each stepper
82 #define STEPPER_1_CW_CCW_PIN 0
83 #define STEPPER_1_HALF_FULL_PIN 0
84 #define STEPPER_1_CONTROL_PIN 0
85 #define STEPPER_1_ENABLE_PIN 0
86 #define STEPPER_1_RESET_PIN 0
88 /* put here other stepper motor */
90 #define STEPPER_1_SET do { /* Implement me! */ } while(0)
91 /* add here the set for other stepper motor */
93 #define STEPPER_1_CLEAR do { /* Implement me! */ } while(0)
94 /* add here the clear for other stepper motor */
97 * Generic macro definition
103 #define STEPPER_PIN_INIT_MACRO(port, index) do { \
104 /* Add here init pin code */ \
108 * Stepper commands macros
110 #define STEPPER_SET_CW(index) do { /* Implement me! */ } while (0)
111 #define STEPPER_SET_CCW(index) do { /* Implement me! */ } while (0)
112 #define STEPPER_SET_HALF(index) do { /* Implement me! */ } while (0)
113 #define STEPPER_SET_FULL(index) do { /* Implement me! */ } while (0)
114 #define STEPPER_SET_CONTROL_LOW(index) do { /* Implement me! */ } while (0)
115 #define STEPPER_SET_CONTROL_HIGHT(index) do { /* Implement me! */ } while (0)
116 #define STEPPER_SET_ENABLE(index) do { /* Implement me! */ } while (0)
117 #define STEPPER_SET_DISABLE(index) do { /* Implement me! */ } while (0)
118 #define STEPPER_SET_RESET_ENABLE(index) do { /* Implement me! */ } while (0)
119 #define STEPPER_SET_RESET_DISABLE(index) do { /* Implement me! */ } while (0)
123 * Reset stepper macro
126 #define STEPPER_RESET_MACRO(index) do { \
127 STEPPER_SET_RESET_ENABLE(index); \
128 timer_udelay(STEPPER_RESET_DELAY); \
129 STEPPER_SET_RESET_DISABLE(index); \
133 * Set half or full step macro
135 #define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \
137 STEPPER_SET_HALF(index); \
139 STEPPER_SET_FULL(index); \
143 * Set control status macro
145 #warning TODO: This macro is not implemented (see below)
147 #define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \
149 /* WARNING This macros not implemented */ \
151 /* WARNING This macros not implemented */ \
155 * Set current power macro
157 #warning TODO: This macro is not implemented (see below)
159 #define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \
161 /* WARNING This macrois not implemented */ \
163 /* WARNING This macrois not implemented */ \
167 * Set rotation of stepper motor
168 * - dir = 1: positive rotation
169 * - dir = 0: no motor moviment
170 * - dir = -1: negative rotation
173 #define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \
177 STEPPER_SET_CW(index); \
180 STEPPER_SET_CCW(index); \
189 * Define macros for manage low level of stepper.
192 #define STEPPER_INIT() do { \
193 STEPPER_PIN_INIT_MACRO(A, 1); \
194 /* Add here code for other stepper motor */ \
199 * Enable select stepper motor
201 #define STEPPER_ENABLE(index) do { \
205 STEPPER_SET_ENABLE(1); \
207 /* Add here code for other stepper motor */ \
212 * Enable all stepper connect to micro
214 #define STEPPER_ENABLE_ALL() do { \
215 STEPPER_SET_ENABLE(1); \
216 /* Add here code for other stepper motor */ \
220 * Disable select stepper motor
222 #define STEPPER_DISABLE(index) do { \
226 STEPPER_SET_DISABLE(1); \
228 /* Add here code for other stepper motor */ \
233 * Disable all stepper connect to micro
235 #define STEPPER_DISABLE_ALL() do { \
236 STEPPER_SET_DISABLE(1); \
237 /* Add here code for other stepper motor */ \
241 * Reset selected stepper motor
243 #define STEPPER_RESET(index) do { \
247 STEPPER_RESET_MACRO(1); \
249 /* Add here code for other stepper motor */ \
254 * Reset all stepper motor
256 #define STEPPER_RESET_ALL() do { \
257 STEPPER_RESET_MACRO(1) \
258 /* Add here code for other stepper motor */ \
261 // Set half/full step macros
262 #define STEPPER_SET_HALF_STEP(index, flag) do { \
266 STEPPER_SET_STEP_MODE_MACRO(1, flag); \
268 /* Add here code for other stepper motor */ \
274 #define STEPPER_SET_CONTROL_BIT(index, flag) do { \
278 STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \
280 /* Add here code for other stepper motor */ \
285 // Set stepper power current
286 #define STEPPER_SET_POWER_CURRENT(index, flag) do { \
290 STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \
292 /* Add here code for other stepper motor */ \
296 // Set rotation dirction of stepper motor
297 #define STEPPER_SET_DIRECTION(index, dir) do { \
301 STEPPER_SET_DIRECTION_MACRO(1, dir); \
303 /* Add here code for other stepper motor */ \
307 #endif /* HW_STEPPER_H */