stepper_at91.h

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