Contiki 2.5
stepper.h
1 #ifndef __STEPPER_H__JPA916UOFT__
2 #define __STEPPER_H__JPA916UOFT__
3 
4 #include <AT91SAM7S64.h>
5 #include <inttypes.h>
6 #include <limits.h>
7 
8 /* Define periods/second */
9 #define PPS 128
10 
11 /* Scaling factor for distance */
12 #define DIST_SCALE (2 * PPS * PPS)
13 
14 /* Scaling factor for velocity */
15 #define VEL_SCALE PPS
16 
17 typedef struct _StepperAccSeq StepperAccSeq;
18 struct _StepperAccSeq
19 {
20  StepperAccSeq *next;
21  unsigned long period;
22  long acceleration;
23 };
24 
25 #define STEPPER_ACC_INVALID LONG_MAX
26 
27 #define STEPPER_MAX_VELOCITY 4000
28 #define STEPPER_MAX_ACCELRATION 4000
29 
30 typedef void (*StepperUserCallback)(unsigned int stepper_index,
31  unsigned long period);
32 
33 
34 typedef unsigned int StepperResult;
35 #define STEPPER_OK 0
36 #define STEPPER_ERR_MEM 1
37 #define STEPPER_ERR_TOO_LATE 2
38 #define STEPPER_ERR_INDEX 3
39 
40 void
41 stepper_init(AT91PS_TC timer, unsigned int id);
42 
43 void
44 stepper_init_io(unsigned int stepper_index, uint32_t mask,
45  const uint32_t *acc, const uint32_t *run,
46  const uint32_t *hold, unsigned int nsteps);
47 
48 /* Returns true if the new sequence was actually added or false
49  if the index is illegal or the first step in the sequence is too soon */
50 
51 StepperResult
52 stepper_add_acc_seq(unsigned int stepper_index, StepperAccSeq *new_seq);
53 
54 StepperResult
55 stepper_add_acc(unsigned int stepper_index, unsigned int period, long acc);
56 
57 StepperResult
58 stepper_insert_callback(unsigned int stepper_index, unsigned int period);
59 
60 void
61 stepper_set_callback_proc(StepperUserCallback callback);
62 
63 unsigned long
64 stepper_current_period();
65 
66 long
67 stepper_current_step(unsigned int stepper_index);
68 
69 long long
70 stepper_step_frac(unsigned int stepper_index);
71 
72 long
73 stepper_current_velocity(unsigned int stepper_index);
74 
75 unsigned long
76 stepper_velocity(unsigned int stepper_index, unsigned long period);
77 
78 StepperResult
79 stepper_state_at(unsigned int stepper_index, unsigned long period,
80  long *velocity, long long *position);
81 
82 StepperResult
83 stepper_set_velocity(unsigned int stepper_index, unsigned long *periodp,
84  unsigned long max_acc, long final_speed);
85 
86 StepperAccSeq *
87 stepper_allocate_seq();
88 
89 void
90 stepper_free_seq(StepperAccSeq *seq);
91 
92 #ifdef TIMING_ERRORS
93 
94 void
95 stepper_timing_errors(unsigned int stepper_index, long *min, long *max);
96 #endif
97 
98 #endif /* __STEPPER_H__JPA916UOFT__ */