X-Git-Url: http://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/d6023ce63e778daf40edccf7d855b0a15a600f53..8b260c2c2f391324244eba299ef92e4186813a7b:/src/libs/StepTicker.h diff --git a/src/libs/StepTicker.h b/src/libs/StepTicker.h index 39c9706f..951d90d4 100644 --- a/src/libs/StepTicker.h +++ b/src/libs/StepTicker.h @@ -7,59 +7,77 @@ -#ifndef STEPTICKER_H -#define STEPTICKER_H +#pragma once #include -#include +#include #include #include #include +#include "ActuatorCoordinates.h" + class StepperMotor; +class Block; class StepTicker{ public: - 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 reset_tick(); - uint32_t get_tick_cnt() const { return tick_cnt; } - uint32_t ticks_since(uint32_t last) const { return (tick_cnt>=last) ? tick_cnt-last : (UINT32_MAX-last) + tick_cnt + 1; } + void unstep_tick(); void TIMER0_IRQHandler (void); void PendSV_IRQHandler (void); - void register_acceleration_tick_handler(std::function cb){ - acceleration_tick_handlers.push_back(cb); - } - void acceleration_tick(); + void start(); + void copy_block(Block *block); + void set_next_block(Block *block) { next_block= block; } + bool is_next_block() const { return next_block != nullptr; } + + // whatever setup the block should register this to know when it is done + std::function finished_fnc{nullptr}; - friend class StepperMotor; + static StepTicker *getInstance() { return instance; } private: + static StepTicker *instance; + float frequency; - uint32_t delay; uint32_t period; - volatile uint32_t tick_cnt; - std::vector> acceleration_tick_handlers; - std::vector motor; - std::bitset<32> active_motor; // limit to 32 motors + std::array motor; std::atomic_uchar do_move_finished; - uint8_t num_motors; - volatile bool a_move_finished; - volatile bool reset_step_pins; -}; + std::bitset unstep; + // this is tick info needed for this block. applies to all motors + struct block_info_t { + uint32_t accelerate_until; + uint32_t decelerate_after; + uint32_t maximum_rate; + uint32_t deceleration_per_tick; + uint32_t total_move_ticks; + }; + block_info_t block_info; + Block *next_block{nullptr}; + // this is the data needed to determine when each motor needs to be issued a step + struct tickinfo_t { + float steps_per_tick; // 2.30 fixed point + float counter; // 2.30 fixed point + float acceleration_change; // 1.30 fixed point signed + float axis_ratio; + uint32_t steps_to_move; + uint32_t step_count; + uint32_t next_accel_event; + }; + std::array tick_info; -#endif + struct { + volatile bool move_issued:1; + uint8_t num_motors:4; + }; +};