Skip to content

Commit

Permalink
Static SerialPageManager is more optimal
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 11, 2020
1 parent c4a86bd commit 62f07aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
28 changes: 28 additions & 0 deletions Marlin/src/feature/direct_stepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@

namespace DirectStepping {

template<typename Cfg>
State SerialPageManager<Cfg>::state;

template<typename Cfg>
volatile bool SerialPageManager<Cfg>::fatal_error;

template<typename Cfg>
volatile PageState SerialPageManager<Cfg>::page_states[Cfg::NUM_PAGES];

template<typename Cfg>
volatile bool SerialPageManager<Cfg>::page_states_dirty;

template<typename Cfg>
millis_t SerialPageManager<Cfg>::next_response;

template<typename Cfg>
uint8_t SerialPageManager<Cfg>::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE],
SerialPageManager<Cfg>::checksum;

template<typename Cfg>
write_byte_idx_t SerialPageManager<Cfg>::write_byte_idx;

template<typename Cfg>
page_idx_t SerialPageManager<Cfg>::write_page_idx;

template<typename Cfg>
write_byte_idx_t SerialPageManager<Cfg>::write_page_size;

template <typename Cfg>
void SerialPageManager<Cfg>::init() {
for (int i = 0 ; i < Cfg::NUM_PAGES ; i++)
Expand Down
32 changes: 16 additions & 16 deletions Marlin/src/feature/direct_stepping.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ namespace DirectStepping {

typedef typename Cfg::page_idx_t page_idx_t;

bool maybe_store_rxd_char(uint8_t c);
void write_responses();
static bool maybe_store_rxd_char(uint8_t c);
static void write_responses();

// common methods for page managers
void init();
uint8_t *get_page(const page_idx_t page_idx);
void free_page(const page_idx_t page_idx);
static void init();
static uint8_t *get_page(const page_idx_t page_idx);
static void free_page(const page_idx_t page_idx);

protected:

typedef typename Cfg::write_byte_idx_t write_byte_idx_t;

State state;
volatile bool fatal_error;
static State state;
static volatile bool fatal_error;

volatile PageState page_states[Cfg::NUM_PAGES];
volatile bool page_states_dirty;
millis_t next_response;
static volatile PageState page_states[Cfg::NUM_PAGES];
static volatile bool page_states_dirty;
static millis_t next_response;

uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
uint8_t checksum;
write_byte_idx_t write_byte_idx;
page_idx_t write_page_idx;
write_byte_idx_t write_page_size;
static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
static uint8_t checksum;
static write_byte_idx_t write_byte_idx;
static page_idx_t write_page_idx;
static write_byte_idx_t write_page_size;

void set_page_state(const page_idx_t page_idx, const PageState page_state);
static void set_page_state(const page_idx_t page_idx, const PageState page_state);
};

template<bool b, typename T, typename F> struct TypeSelector { typedef T type;} ;
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,9 @@ void Stepper::pulse_phase_isr() {
PAGE_PULSE_PREP(E);

page_step_state.segment_steps++;

#elif STEPPER_PAGE_FORMAT == SP_4x1_512

#define PAGE_PULSE_PREP(AXIS, BITS) do{ \
step_needed[_AXIS(AXIS)] = (steps >> BITS) & 0x1; \
if (step_needed[_AXIS(AXIS)]) \
Expand All @@ -1674,8 +1676,9 @@ void Stepper::pulse_phase_isr() {
PAGE_PULSE_PREP(E, 0);

page_step_state.segment_idx++;

#else
#error "Unknown direct-stepping page format"
#error "Unknown direct stepping page format!"
#endif
}

Expand Down Expand Up @@ -1796,8 +1799,6 @@ uint32_t Stepper::block_phase_isr() {
#elif STEPPER_PAGE_FORMAT == SP_4x1_512 || STEPPER_PAGE_FORMAT == SP_4x2_256
#define PAGE_SEGMENT_UPDATE_POS(AXIS) \
count_position[_AXIS(AXIS)] += page_step_state.bd[_AXIS(AXIS)] * count_direction[_AXIS(AXIS)];
#else
#error "Unknown page format"
#endif

if (IS_PAGE(current_block)) {
Expand Down

0 comments on commit 62f07aa

Please sign in to comment.