refactoring that improved compartmentalization between stepper and stepper_plan modules

This commit is contained in:
Simen Svale Skogsrud 2011-02-06 23:52:12 +01:00
parent 52dda8713e
commit ba13ddadd0
3 changed files with 22 additions and 9 deletions

View File

@ -144,9 +144,8 @@ SIGNAL(TIMER1_COMPA_vect)
// If there is no current block, attempt to pop one from the buffer // If there is no current block, attempt to pop one from the buffer
if (current_block == NULL) { if (current_block == NULL) {
// Anything in the buffer? // Anything in the buffer?
if (block_buffer_head != block_buffer_tail) { current_block = plan_get_current_block();
// Retrieve a new line and get ready to step it if (current_block != NULL) {
current_block = &block_buffer[block_buffer_tail];
trapezoid_generator_reset(); trapezoid_generator_reset();
counter_x = -(current_block->step_event_count >> 1); counter_x = -(current_block->step_event_count >> 1);
counter_y = counter_x; counter_y = counter_x;
@ -184,8 +183,7 @@ SIGNAL(TIMER1_COMPA_vect)
// printInteger(current_block->rate_delta); // printInteger(current_block->rate_delta);
// printString(" <-- delta\n\r"); // printString(" <-- delta\n\r");
current_block = NULL; current_block = NULL;
// move the block buffer tail to the next instruction plan_discard_current_block();
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
} }
} else { } else {
out_bits = 0; out_bits = 0;
@ -252,7 +250,7 @@ void st_init()
// Block until all buffered steps are executed // Block until all buffered steps are executed
void st_synchronize() void st_synchronize()
{ {
while(block_buffer_tail != block_buffer_head) { sleep_mode(); } while(plan_get_current_block()) { sleep_mode(); }
} }
// Configures the prescaler and ceiling of timer 1 to produce the given rate as accurately as possible. // Configures the prescaler and ceiling of timer 1 to produce the given rate as accurately as possible.

View File

@ -351,6 +351,17 @@ int plan_is_acceleration_manager_enabled() {
return(acceleration_manager_enabled); return(acceleration_manager_enabled);
} }
inline void plan_discard_current_block() {
if (block_buffer_head != block_buffer_tail) {
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
}
}
inline block_t *plan_get_current_block() {
if (block_buffer_head == block_buffer_tail) { return(NULL); }
return(&block_buffer[block_buffer_tail]);
}
// Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in
// mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
// calculation the caller must also provide the physical length of the line in millimeters. // calculation the caller must also provide the physical length of the line in millimeters.

View File

@ -56,9 +56,6 @@ typedef struct {
uint32_t exit_rate; uint32_t exit_rate;
} block_t; } block_t;
extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
extern volatile int block_buffer_head; // Index of the next block to be pushed
extern volatile int block_buffer_tail; // Index of the block to process now
extern int32_t position[3]; extern int32_t position[3];
// Initialize the motion plan subsystem // Initialize the motion plan subsystem
@ -71,6 +68,13 @@ void plan_init();
// calculation the caller must also provide the physical length of the line in millimeters. // calculation the caller must also provide the physical length of the line in millimeters.
void plan_buffer_line(double x, double y, double z, double feed_rate, int invert_feed_rate); void plan_buffer_line(double x, double y, double z, double feed_rate, int invert_feed_rate);
// Call when the current block is no longer needed. Discards the block and makes the memory
// availible for new blocks.
inline void plan_discard_current_block();
// Gets the current block. Returns NULL if buffer empty
inline block_t *plan_get_current_block();
// Enables acceleration-management for upcoming blocks // Enables acceleration-management for upcoming blocks
void plan_set_acceleration_manager_enabled(int enabled); void plan_set_acceleration_manager_enabled(int enabled);
// Is acceleration-management currently enabled? // Is acceleration-management currently enabled?