Contiki 2.6

stepper.h

00001 #ifndef __STEPPER_H__JPA916UOFT__
00002 #define __STEPPER_H__JPA916UOFT__
00003 
00004 #include <AT91SAM7S64.h>
00005 #include <inttypes.h>
00006 #include <limits.h>
00007 
00008 /* Define periods/second */
00009 #define PPS 128
00010 
00011 /* Scaling factor for distance */
00012 #define DIST_SCALE (2 * PPS * PPS)
00013 
00014 /* Scaling factor for velocity */
00015 #define VEL_SCALE PPS
00016 
00017 typedef struct _StepperAccSeq StepperAccSeq;
00018 struct _StepperAccSeq
00019 {
00020   StepperAccSeq *next;
00021   unsigned long period;
00022   long acceleration;
00023 };
00024 
00025 #define STEPPER_ACC_INVALID LONG_MAX
00026 
00027 #define STEPPER_MAX_VELOCITY 4000
00028 #define STEPPER_MAX_ACCELRATION 4000
00029 
00030 typedef void (*StepperUserCallback)(unsigned int stepper_index,
00031                                     unsigned long period);
00032 
00033 
00034 typedef unsigned int StepperResult;
00035 #define STEPPER_OK 0
00036 #define STEPPER_ERR_MEM 1
00037 #define STEPPER_ERR_TOO_LATE 2
00038 #define STEPPER_ERR_INDEX 3
00039 
00040 void
00041 stepper_init(AT91PS_TC timer, unsigned int id);
00042 
00043 void
00044 stepper_init_io(unsigned int stepper_index, uint32_t mask,
00045                 const uint32_t *acc, const uint32_t *run,
00046                 const uint32_t *hold, unsigned int nsteps);
00047 
00048 /* Returns true if the new sequence was actually added or false
00049    if the index is illegal or the first step in the sequence is too soon */
00050 
00051 StepperResult
00052 stepper_add_acc_seq(unsigned int stepper_index, StepperAccSeq *new_seq);
00053 
00054 StepperResult
00055 stepper_add_acc(unsigned int stepper_index, unsigned int period, long acc);
00056 
00057 StepperResult
00058 stepper_insert_callback(unsigned int stepper_index, unsigned int period);
00059 
00060 void
00061 stepper_set_callback_proc(StepperUserCallback callback);
00062 
00063 unsigned long
00064 stepper_current_period();
00065 
00066 long
00067 stepper_current_step(unsigned int stepper_index);
00068 
00069 long long
00070 stepper_step_frac(unsigned int stepper_index);
00071 
00072 long
00073 stepper_current_velocity(unsigned int stepper_index);
00074 
00075 unsigned long
00076 stepper_velocity(unsigned int stepper_index, unsigned long period);
00077 
00078 StepperResult
00079 stepper_state_at(unsigned int stepper_index, unsigned long period,
00080                  long *velocity, long long *position);
00081 
00082 StepperResult
00083 stepper_set_velocity(unsigned int stepper_index, unsigned long *periodp,
00084                      unsigned long max_acc, long final_speed);
00085 
00086 StepperAccSeq *
00087 stepper_allocate_seq();
00088 
00089 void
00090 stepper_free_seq(StepperAccSeq *seq);
00091 
00092 #ifdef TIMING_ERRORS
00093 
00094 void
00095 stepper_timing_errors(unsigned int stepper_index, long *min, long *max);
00096 #endif
00097 
00098 #endif /* __STEPPER_H__JPA916UOFT__ */