stepper_at91.h
Go to the documentation of this file.00001
00040 #include <cfg/compiler.h>
00041 #include <cfg/macros.h>
00042 #include <drv/stepper.h>
00043 #include <io/arm.h>
00044
00055 #if STEPPER_PRESCALER_LOG2 == 1
00056 #define STEPPER_MCK_PRESCALER TC_CLKS_MCK2
00057 #elif STEPPER_PRESCALER_LOG2 == 3
00058 #define STEPPER_MCK_PRESCALER TC_CLKS_MCK8
00059 #elif STEPPER_PRESCALER_LOG2 == 5
00060 #define STEPPER_MCK_PRESCALER TC_CLKS_MCK32
00061 #elif STEPPER_PRESCALER_LOG2 == 7
00062 #define STEPPER_MCK_PRESCALER TC_CLKS_MCK128
00063 #elif STEPPER_PRESCALER_LOG2 == 10
00064 #define STEPPER_MCK_PRESCALER TC_CLKS_MCK1024
00065 #else
00066 #error Unsupported stepper prescaler value.
00067 #endif
00068
00072 enum
00073 {
00074 TC_TIOA0 = 0,
00075 TC_TIOB0,
00076 TC_TIOA1,
00077 TC_TIOB1,
00078 TC_TIOA2,
00079 TC_TIOB2,
00080
00081 TC_CNT
00082 };
00083
00087 typedef void (*irq_t)(void);
00088
00092 typedef struct TimerCounter
00093 {
00094 int timer_id;
00095 uint32_t blk_ctrl_set;
00096 reg32_t *chl_mode_reg;
00097 reg32_t *chl_ctrl_reg;
00098 reg32_t *comp_reg;
00099 reg32_t *comp_c_reg;
00100 reg32_t *count_val_reg;
00101 uint32_t comp_effect_mask;
00102 uint32_t comp_effect_set;
00103 uint32_t comp_effect_clear;
00104 uint32_t comp_effect_c_mask;
00105 uint32_t comp_effect_c_clear;
00106 uint32_t ext_event_set;
00107 reg32_t *irq_enable_reg;
00108 reg32_t *irq_disable_reg;
00109 uint32_t irq_set_mask;
00110 reg32_t *irq_mask_reg;
00111 irq_t isr;
00112 reg32_t *status_reg;
00113 int tio_pin;
00114 stepper_isr_t callback;
00115 struct Stepper *motor;
00116
00117 } TimerCounter;
00118
00122 INLINE void stepper_tc_irq_enable(struct TimerCounter *timer)
00123 {
00124 *timer->irq_enable_reg = timer->irq_set_mask;
00125 }
00126
00130 INLINE void stepper_tc_irq_disable(struct TimerCounter *timer)
00131 {
00132 *timer->irq_disable_reg = timer->irq_set_mask;
00133 }
00134
00138 INLINE void stepper_tc_setDelay(struct TimerCounter *timer, stepper_time_t delay)
00139 {
00140 *timer->comp_reg += delay;
00141 }
00142
00143
00147 INLINE void stepper_tc_resetTimer(struct TimerCounter *timer)
00148 {
00149 *timer->comp_reg = 0;
00150 }
00151
00155 INLINE void FAST_FUNC stepper_tc_doPulse(struct TimerCounter *timer)
00156 {
00157 *timer->chl_mode_reg &= ~timer->comp_effect_mask;
00158 *timer->chl_mode_reg |= timer->comp_effect_set;
00159 }
00160
00164 INLINE void FAST_FUNC stepper_tc_skipPulse(struct TimerCounter *timer)
00165 {
00166 *timer->chl_mode_reg &= ~timer->comp_effect_mask;
00167 }
00168
00169 void stepper_tc_setup(int index, stepper_isr_t callback, struct Stepper *motor);
00170 void stepper_tc_init(void);
00171
00172
00173
00174
00175
00176
00177 void stepper_timer_test_brute(void);
00178
00179
00180
00181
00182
00183
00184
00185 void stepper_timer_test_prestepper(struct Stepper *local_motor, struct StepperConfig *local_cfg, int index);