X-Git-Url: http://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/001c4b26dbe4fb07b3ef666bb84512ca78ca8e75..18dbd06e8319bf14015ba8aa8c60bd05914673ae:/src/libs/StepTicker.h diff --git a/src/libs/StepTicker.h b/src/libs/StepTicker.h index bf695fd2..6b9cf623 100644 --- a/src/libs/StepTicker.h +++ b/src/libs/StepTicker.h @@ -7,56 +7,59 @@ -#ifndef STEPTICKER_H -#define STEPTICKER_H +#pragma once #include -#include +#include #include #include #include +#include "ActuatorCoordinates.h" +#include "TSRingBuffer.h" + class StepperMotor; +class Block; + +// handle 2.62 Fixed point +#define STEPTICKER_FPSCALE (1LL<<62) +#define STEPTICKER_FROMFP(x) ((float)(x)/STEPTICKER_FPSCALE) class StepTicker{ public: - friend class StepperMotor; - static StepTicker* global_step_ticker; - StepTicker(); ~StepTicker(); void set_frequency( float frequency ); - void signal_a_move_finished(); - void set_reset_delay( float seconds ); + void set_unstep_time( float microseconds ); int register_motor(StepperMotor* motor); - void add_motor_to_active_list(StepperMotor* motor); - void remove_motor_from_active_list(StepperMotor* motor); - void set_acceleration_ticks_per_second(uint32_t acceleration_ticks_per_second); + float get_frequency() const { return frequency; } + void unstep_tick(); + const Block *get_current_block() const { return current_block; } - void reset_tick(); - void TIMER0_IRQHandler (void); - void PendSV_IRQHandler (void); + void step_tick (void); + void handle_finish (void); + void start(); - void register_acceleration_tick_handler(std::function cb){ - acceleration_tick_handlers.push_back(cb); - } + // whatever setup the block should register this to know when it is done + std::function finished_fnc{nullptr}; + + static StepTicker *getInstance() { return instance; } private: + static StepTicker *instance; + + bool start_next_block(); + float frequency; - uint32_t delay; uint32_t period; - uint32_t acceleration_tick_period; - uint32_t acceleration_tick_cnt; - std::vector> acceleration_tick_handlers; - std::vector motor; - std::bitset<32> active_motor; // limit to 32 motors - std::atomic_uchar do_move_finished; - uint8_t num_motors:5; - volatile bool a_move_finished; - volatile bool do_acceleration_tick; - volatile bool reset_step_pins; -}; + std::array motor; + std::bitset unstep; + Block *current_block; + uint32_t current_tick{0}; - -#endif + struct { + volatile bool running:1; + uint8_t num_motors:4; + }; +};