Contiki 2.5
stepper-interrupt.h
1 #ifndef __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__
2 #define __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__
3 
4 #include <stepper.h>
5 
6 /* Timer frequency */
7 #define TIMER_FREQ 748800
8 
9 typedef struct _StepperContext StepperContext;
10 typedef struct _StepperState StepperState;
11 typedef struct _StepperTimerStep StepperTimerStep;
12 
13 #define MAX_STEPS_PER_PERIOD 40
14 #define NUM_STEPPERS 2
15 
16 #define STEPPER_MAX_VELOCITY 4000
17 #define STEPPER_MAX_ACCELRATION 4000
18 
19 
20 #define TIMING_ERRORS
21 
22 struct _StepperState
23 {
24  long step_count;
25  uint32_t io_mask;
26  const uint32_t *acc_steps; /* Stepping sequence when accelerating */
27  const uint32_t *run_steps; /* Stepping sequence when running */
28  const uint32_t *hold_steps; /* Stepping sequence when stationary */
29  uint8_t current_step; /* in stepping sequence */
30  uint8_t sequence_length;
31 
32  long velocity; /* steps/second * PPS */
33  long acceleration; /* steps/second^2 */
34  long step_full; /* steps, same as step_count at period boundaries */
35  long step_frac; /* (steps * PPS^2 * 2) % steps * PPS^2 */
36 
37  long n_steps; /* full steps to move during this period */
38 
39  StepperAccSeq *acceleration_sequence;
40 
41 #ifdef TIMING_ERRORS
42  long err_max;
43  long err_min;
44 #endif
45 };
46 
47 #define STEPPER_POWER_ACC 30
48 #define STEPPER_POWER_RUN 20
49 #define STEPPER_POWER_HOLD 10
50 #define STEPPER_POWER_OFF 0
51 
52 #define STEPPER_DIRECTION_NONE 0
53 #define STEPPER_DIRECTION_FORWARD 1
54 #define STEPPER_DIRECTION_BACKWARD 2
55 
56 struct _StepperTimerStep
57 {
58  StepperTimerStep *next;
59  StepperState *state;
60  uint16_t time;
61  uint8_t direction;
62  uint8_t power;
63 };
64 
65 
66 struct _StepperContext
67 {
68  unsigned int flags;
69  unsigned long period_count;
70  AT91PS_TC timer_channel;
71  StepperState steppers[NUM_STEPPERS];
72  StepperTimerStep *steps;
73  StepperTimerStep *current_step;
74  StepperUserCallback user_callback;
75 };
76 
77 extern StepperContext stepper_context;
78 #endif /* __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__ */
79 
80 void stepper_timer_interrupt(void);