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
36 * \author Daniele Basile <asterix@develer.com>
43 #include <hw/hw_cpufreq.h>
45 #include <cfg/macros.h>
47 #include <drv/timer.h>
49 #warning TODO:This is an example implentation, you must implement it!
51 #define STEPPER_STROBE_INIT \
53 /* put init code for strobe */ \
57 #define STEPPER_STROBE_ON do { /* Implement me! */ } while(0)
58 #define STEPPER_STROBE_OFF do { /* Implement me! */ } while(0)
61 * CPU clock frequency is divided by 2^STEPPER_PRESCALER_LOG2 to
62 * obtain stepper clock.
64 #define STEPPER_PRESCALER_LOG2 1
67 * Stepper timer clock frequency.
69 #define STEPPER_CLOCK ((CPU_FREQ) >> STEPPER_PRESCALER_LOG2)
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).
76 #define STEPPER_RESET_DELAY 1
79 * Pins define for each stepper
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
87 /* put here other stepper motor */
89 #define STEPPER_1_SET do { /* Implement me! */ } while(0)
90 /* add here the set for other stepper motor */
92 #define STEPPER_1_CLEAR do { /* Implement me! */ } while(0)
93 /* add here the clear for other stepper motor */
96 * Generic macro definition
102 #define STEPPER_PIN_INIT_MACRO(port, index) do { \
103 /* Add here init pin code */ \
107 * Stepper commands macros
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)
122 * Reset stepper macro
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); \
132 * Set half or full step macro
134 #define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \
136 STEPPER_SET_HALF(index); \
138 STEPPER_SET_FULL(index); \
142 * Set control status macro
144 #warning TODO: This macro is not implemented (see below)
146 #define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \
148 /* WARNING This macros not implemented */ \
150 /* WARNING This macros not implemented */ \
154 * Set current power macro
156 #warning TODO: This macro is not implemented (see below)
158 #define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \
160 /* WARNING This macrois not implemented */ \
162 /* WARNING This macrois not implemented */ \
166 * Set rotation of stepper motor
167 * - dir = 1: positive rotation
168 * - dir = 0: no motor moviment
169 * - dir = -1: negative rotation
172 #define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \
176 STEPPER_SET_CW(index); \
179 STEPPER_SET_CCW(index); \
188 * Define macros for manage low level of stepper.
191 #define STEPPER_INIT() do { \
192 STEPPER_PIN_INIT_MACRO(A, 1); \
193 /* Add here code for other stepper motor */ \
198 * Enable select stepper motor
200 #define STEPPER_ENABLE(index) do { \
204 STEPPER_SET_ENABLE(1); \
206 /* Add here code for other stepper motor */ \
211 * Enable all stepper connect to micro
213 #define STEPPER_ENABLE_ALL() do { \
214 STEPPER_SET_ENABLE(1); \
215 /* Add here code for other stepper motor */ \
219 * Disable select stepper motor
221 #define STEPPER_DISABLE(index) do { \
225 STEPPER_SET_DISABLE(1); \
227 /* Add here code for other stepper motor */ \
232 * Disable all stepper connect to micro
234 #define STEPPER_DISABLE_ALL() do { \
235 STEPPER_SET_DISABLE(1); \
236 /* Add here code for other stepper motor */ \
240 * Reset selected stepper motor
242 #define STEPPER_RESET(index) do { \
246 STEPPER_RESET_MACRO(1); \
248 /* Add here code for other stepper motor */ \
253 * Reset all stepper motor
255 #define STEPPER_RESET_ALL() do { \
256 STEPPER_RESET_MACRO(1) \
257 /* Add here code for other stepper motor */ \
260 // Set half/full step macros
261 #define STEPPER_SET_HALF_STEP(index, flag) do { \
265 STEPPER_SET_STEP_MODE_MACRO(1, flag); \
267 /* Add here code for other stepper motor */ \
273 #define STEPPER_SET_CONTROL_BIT(index, flag) do { \
277 STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \
279 /* Add here code for other stepper motor */ \
284 // Set stepper power current
285 #define STEPPER_SET_POWER_CURRENT(index, flag) do { \
289 STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \
291 /* Add here code for other stepper motor */ \
295 // Set rotation dirction of stepper motor
296 #define STEPPER_SET_DIRECTION(index, dir) do { \
300 STEPPER_SET_DIRECTION_MACRO(1, dir); \
302 /* Add here code for other stepper motor */ \
306 #endif /* HW_STEPPER_H */