BeRTOS
ramp.h
Go to the documentation of this file.
00001 
00049 #ifndef ALGO_RAMP_H
00050 #define ALGO_RAMP_H
00051 
00052 #include "hw/hw_stepper.h"
00053 
00054 #include "cfg/cfg_ramp.h"
00055 
00056 #include <cfg/compiler.h>
00057 
00058 
00062 #define TIME2CLOCKS(micros) ((uint32_t)(micros) * (STEPPER_CLOCK / 1000000))
00063 
00067 #define CLOCKS2TIME(clocks) ((uint32_t)(clocks) / (STEPPER_CLOCK / 1000000))
00068 
00072 #define MICROS2FREQ(micros) (1000000UL / ((uint32_t)(micros)))
00073 
00077 #define FREQ2MICROS(hz) (1000000UL / ((uint32_t)(hz)))
00078 
00082 #define FIX_MULT32(a,b)  (((uint64_t)(a)*(uint32_t)(b)) >> 16)
00083 
00092 struct RampPrecalc
00093 {
00094 #if RAMP_USE_FLOATING_POINT
00095     float beta;
00096     float alpha;
00097     float gamma;
00098 #else
00099     uint16_t max_div_min;
00100     uint32_t inv_total_time;
00101 #endif
00102 };
00103 
00104 
00108 struct Ramp
00109 {
00110     uint32_t clocksRamp;
00111     uint16_t clocksMinWL;
00112     uint16_t clocksMaxWL;
00113 
00114     struct RampPrecalc precalc; 
00115 };
00116 
00117 
00118 /*
00119  * Function prototypes
00120  */
00121 void ramp_compute(
00122     struct Ramp * ramp,
00123     uint32_t clocksInRamp,
00124     uint16_t clocksInMinWavelength,
00125     uint16_t clocksInMaxWavelength);
00126 
00127 
00136 void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq);
00137 
00138 
00142 void ramp_default(struct Ramp *ramp);
00143 
00144 
00153 #if RAMP_USE_FLOATING_POINT
00154     float ramp_evaluate(const struct Ramp* ramp, float curClock);
00155 #else
00156     uint16_t ramp_evaluate(const struct Ramp* ramp, uint32_t curClock);
00157 #endif
00158 
00159 
00161 int ramp_testSetup(void);
00162 int ramp_testRun(void);
00163 int ramp_testTearDown(void);
00164 
00165 #endif /* ALGO_RAMP_H */
00166