BeRTOS
hw_stepper.h
Go to the documentation of this file.
00001 
00040 #ifndef HW_STEPPER_H
00041 #define HW_STEPPER_H
00042 
00043 #include <hw/hw_cpufreq.h>
00044 
00045 #include <cfg/macros.h>
00046 
00047 #include <drv/timer.h>
00048 
00049 #warning TODO:This is an example implentation, you must implement it!
00050 
00051 #define STEPPER_STROBE_INIT \
00052 do { \
00053         /* put init code for strobe */ \
00054 } while (0)
00055 
00056 
00057 #define STEPPER_STROBE_ON       do { /* Implement me! */ } while(0)
00058 #define STEPPER_STROBE_OFF      do { /* Implement me! */ } while(0)
00059 
00064 #define STEPPER_PRESCALER_LOG2    1
00065 
00069 #define STEPPER_CLOCK ((CPU_FREQ) >> STEPPER_PRESCALER_LOG2)
00070 
00076 #define STEPPER_RESET_DELAY 1
00077 
00078 /*
00079  * Pins define for each stepper
00080  */
00081 #define STEPPER_1_CW_CCW_PIN             0
00082 #define STEPPER_1_HALF_FULL_PIN          0
00083 #define STEPPER_1_CONTROL_PIN            0
00084 #define STEPPER_1_ENABLE_PIN             0
00085 #define STEPPER_1_RESET_PIN              0
00086 
00087 /* put here other stepper motor */
00088 
00089 #define STEPPER_1_SET            do { /* Implement me! */ } while(0)
00090 /* add here the set for other stepper motor */
00091 
00092 #define STEPPER_1_CLEAR          do { /* Implement me! */ } while(0)
00093 /* add here the clear for other stepper motor */
00094 
00095 /*
00096  * Generic macro definition
00097  */
00098 
00099 /*
00100  * Stepper init macro
00101  */
00102 #define STEPPER_PIN_INIT_MACRO(port, index) do { \
00103         /* Add here init pin code */ \
00104     } while (0)
00105 
00106 /*
00107  * Stepper commands macros
00108  */
00109 #define STEPPER_SET_CW(index)             do { /* Implement me! */ } while (0)
00110 #define STEPPER_SET_CCW(index)            do { /* Implement me! */ } while (0)
00111 #define STEPPER_SET_HALF(index)           do { /* Implement me! */ } while (0)
00112 #define STEPPER_SET_FULL(index)           do { /* Implement me! */ } while (0)
00113 #define STEPPER_SET_CONTROL_LOW(index)    do { /* Implement me! */ } while (0)
00114 #define STEPPER_SET_CONTROL_HIGHT(index)  do { /* Implement me! */ } while (0)
00115 #define STEPPER_SET_ENABLE(index)         do { /* Implement me! */ } while (0)
00116 #define STEPPER_SET_DISABLE(index)        do { /* Implement me! */ } while (0)
00117 #define STEPPER_SET_RESET_ENABLE(index)   do { /* Implement me! */ } while (0)
00118 #define STEPPER_SET_RESET_DISABLE(index)  do { /* Implement me! */ } while (0)
00119 
00120 
00121 /*
00122  * Reset stepper macro
00123  */
00124 
00125 #define STEPPER_RESET_MACRO(index) do { \
00126         STEPPER_SET_RESET_ENABLE(index); \
00127         timer_udelay(STEPPER_RESET_DELAY); \
00128         STEPPER_SET_RESET_DISABLE(index); \
00129     } while (0)
00130 
00131 /*
00132  * Set half or full step macro
00133  */
00134 #define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \
00135         if (flag) \
00136             STEPPER_SET_HALF(index); \
00137         else \
00138             STEPPER_SET_FULL(index); \
00139     } while (0)
00140 
00141 /*
00142  * Set control status macro
00143  */
00144 #warning TODO: This macro is not implemented (see below)
00145 
00146 #define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \
00147         /* if (flag) */ \
00148             /* WARNING This macros not implemented */ \
00149         /* else */ \
00150             /* WARNING This macros not implemented */ \
00151     } while (0)
00152 
00153 /*
00154  * Set current power macro
00155  */
00156 #warning TODO: This macro is not implemented (see below)
00157 
00158 #define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \
00159         /* if (flag) */ \
00160             /* WARNING This macrois not implemented */ \
00161         /* else */ \
00162             /* WARNING This macrois not implemented */ \
00163     } while (0)
00164 
00165 /*
00166  * Set rotation of stepper motor
00167  * - dir = 1: positive rotation
00168  * - dir = 0: no motor moviment
00169  * - dir = -1: negative rotation
00170  *
00171  */
00172 #define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \
00173         switch (dir) \
00174         { \
00175         case 1: \
00176             STEPPER_SET_CW(index); \
00177             break; \
00178         case -1: \
00179             STEPPER_SET_CCW(index); \
00180             break; \
00181         case 0: \
00182             break; \
00183         } \
00184     } while (0)
00185 
00186 
00187 /*
00188  * Define macros for manage low level of stepper.
00189  */
00190 
00191 #define STEPPER_INIT()  do { \
00192         STEPPER_PIN_INIT_MACRO(A, 1); \
00193         /* Add here code for other stepper motor */ \
00194     } while (0)
00195 
00196 
00197 /*
00198  * Enable select stepper motor
00199  */
00200 #define STEPPER_ENABLE(index) do { \
00201         switch (index) \
00202         { \
00203         case 1: \
00204             STEPPER_SET_ENABLE(1); \
00205             break; \
00206             /* Add here code for other stepper motor */ \
00207         } \
00208     } while (0)
00209 
00210 /*
00211  * Enable all stepper connect to micro
00212  */
00213 #define STEPPER_ENABLE_ALL() do { \
00214         STEPPER_SET_ENABLE(1); \
00215         /* Add here code for other stepper motor */ \
00216     } while (0)
00217 
00218 /*
00219  * Disable select stepper motor
00220  */
00221 #define STEPPER_DISABLE(index) do { \
00222         switch (index) \
00223         { \
00224         case 1: \
00225             STEPPER_SET_DISABLE(1); \
00226             break; \
00227             /* Add here code for other stepper motor */ \
00228         } \
00229     } while (0)
00230 
00231 /*
00232  * Disable all stepper connect to micro
00233  */
00234 #define STEPPER_DISABLE_ALL() do { \
00235         STEPPER_SET_DISABLE(1); \
00236         /* Add here code for other stepper motor */ \
00237     } while (0)
00238 
00239 /*
00240  * Reset selected stepper motor
00241  */
00242 #define STEPPER_RESET(index) do { \
00243         switch (index) \
00244         { \
00245         case 1: \
00246             STEPPER_RESET_MACRO(1); \
00247             break; \
00248             /* Add here code for other stepper motor */ \
00249         } \
00250     } while (0)
00251 
00252 /*
00253  * Reset all stepper motor
00254  */
00255 #define STEPPER_RESET_ALL() do { \
00256         STEPPER_RESET_MACRO(1) \
00257         /* Add here code for other stepper motor */ \
00258     } while (0)
00259 
00260 // Set half/full step macros
00261 #define STEPPER_SET_HALF_STEP(index, flag) do { \
00262         switch (index) \
00263         { \
00264         case 1: \
00265             STEPPER_SET_STEP_MODE_MACRO(1, flag); \
00266             break; \
00267             /* Add here code for other stepper motor */ \
00268         } \
00269     } while (0)
00270 
00271 
00272 // Control status
00273 #define STEPPER_SET_CONTROL_BIT(index, flag) do { \
00274         switch (index) \
00275         { \
00276         case 1: \
00277             STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \
00278             break; \
00279             /* Add here code for other stepper motor */ \
00280         } \
00281     } while (0)
00282 
00283 
00284 // Set stepper power current
00285 #define STEPPER_SET_POWER_CURRENT(index, flag) do { \
00286         switch (index) \
00287         { \
00288         case 1: \
00289             STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \
00290             break; \
00291             /* Add here code for other stepper motor */ \
00292         } \
00293     } while (0)
00294 
00295 // Set rotation dirction of stepper motor
00296 #define STEPPER_SET_DIRECTION(index, dir) do { \
00297         switch (index) \
00298         { \
00299         case 1: \
00300             STEPPER_SET_DIRECTION_MACRO(1, dir); \
00301             break; \
00302             /* Add here code for other stepper motor */ \
00303         } \
00304     } while (0)
00305 
00306 #endif /* HW_STEPPER_H */
00307 
00308