made most internal function static to allow gcc to inline them
This commit is contained in:
parent
d21a791eae
commit
9c8c259153
11
gcode.c
11
gcode.c
@ -75,10 +75,9 @@ static parser_state_t gc;
|
|||||||
|
|
||||||
#define FAIL(status) gc.status_code = status;
|
#define FAIL(status) gc.status_code = status;
|
||||||
|
|
||||||
int next_statement(char *letter, double *double_ptr, char *line, uint8_t *char_counter);
|
static int next_statement(char *letter, double *double_ptr, char *line, uint8_t *char_counter);
|
||||||
|
|
||||||
|
static void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2)
|
||||||
void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2)
|
|
||||||
{
|
{
|
||||||
gc.plane_axis_0 = axis_0;
|
gc.plane_axis_0 = axis_0;
|
||||||
gc.plane_axis_1 = axis_1;
|
gc.plane_axis_1 = axis_1;
|
||||||
@ -93,13 +92,13 @@ void gc_init() {
|
|||||||
gc.absolute_mode = true;
|
gc.absolute_mode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float to_millimeters(double value) {
|
static float to_millimeters(double value) {
|
||||||
return(gc.inches_mode ? (value * MM_PER_INCH) : value);
|
return(gc.inches_mode ? (value * MM_PER_INCH) : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the angle in radians of deviance from the positive y axis. negative angles to the left of y-axis,
|
// Find the angle in radians of deviance from the positive y axis. negative angles to the left of y-axis,
|
||||||
// positive to the right.
|
// positive to the right.
|
||||||
double theta(double x, double y)
|
static double theta(double x, double y)
|
||||||
{
|
{
|
||||||
double theta = atan(x/fabs(y));
|
double theta = atan(x/fabs(y));
|
||||||
if (y>0) {
|
if (y>0) {
|
||||||
@ -387,7 +386,7 @@ uint8_t gc_execute_line(char *line) {
|
|||||||
// Parses the next statement and leaves the counter on the first character following
|
// Parses the next statement and leaves the counter on the first character following
|
||||||
// the statement. Returns 1 if there was a statements, 0 if end of string was reached
|
// the statement. Returns 1 if there was a statements, 0 if end of string was reached
|
||||||
// or there was an error (check state.status_code).
|
// or there was an error (check state.status_code).
|
||||||
int next_statement(char *letter, double *double_ptr, char *line, uint8_t *char_counter) {
|
static int next_statement(char *letter, double *double_ptr, char *line, uint8_t *char_counter) {
|
||||||
if (line[*char_counter] == 0) {
|
if (line[*char_counter] == 0) {
|
||||||
return(0); // No more statements
|
return(0); // No more statements
|
||||||
}
|
}
|
||||||
|
24
planner.c
24
planner.c
@ -47,7 +47,7 @@ static uint8_t acceleration_manager_enabled; // Acceleration management active
|
|||||||
|
|
||||||
// Calculates the distance (not time) it takes to accelerate from initial_rate to target_rate using the
|
// Calculates the distance (not time) it takes to accelerate from initial_rate to target_rate using the
|
||||||
// given acceleration:
|
// given acceleration:
|
||||||
double estimate_acceleration_distance(double initial_rate, double target_rate, double acceleration) {
|
static double estimate_acceleration_distance(double initial_rate, double target_rate, double acceleration) {
|
||||||
return(
|
return(
|
||||||
(target_rate*target_rate-initial_rate*initial_rate)/
|
(target_rate*target_rate-initial_rate*initial_rate)/
|
||||||
(2L*acceleration)
|
(2L*acceleration)
|
||||||
@ -70,7 +70,7 @@ double estimate_acceleration_distance(double initial_rate, double target_rate, d
|
|||||||
// a total travel of distance. This can be used to compute the intersection point between acceleration and
|
// a total travel of distance. This can be used to compute the intersection point between acceleration and
|
||||||
// deceleration in the cases where the trapezoid has no plateau (i.e. never reaches maximum speed)
|
// deceleration in the cases where the trapezoid has no plateau (i.e. never reaches maximum speed)
|
||||||
|
|
||||||
double intersection_distance(double initial_rate, double final_rate, double acceleration, double distance) {
|
static double intersection_distance(double initial_rate, double final_rate, double acceleration, double distance) {
|
||||||
return(
|
return(
|
||||||
(2*acceleration*distance-initial_rate*initial_rate+final_rate*final_rate)/
|
(2*acceleration*distance-initial_rate*initial_rate+final_rate*final_rate)/
|
||||||
(4*acceleration)
|
(4*acceleration)
|
||||||
@ -89,7 +89,7 @@ double intersection_distance(double initial_rate, double final_rate, double acce
|
|||||||
// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
|
// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
|
||||||
// The factors represent a factor of braking and must be in the range 0.0-1.0.
|
// The factors represent a factor of braking and must be in the range 0.0-1.0.
|
||||||
|
|
||||||
void calculate_trapezoid_for_block(block_t *block, double entry_factor, double exit_factor) {
|
static void calculate_trapezoid_for_block(block_t *block, double entry_factor, double exit_factor) {
|
||||||
block->initial_rate = ceil(block->nominal_rate*entry_factor);
|
block->initial_rate = ceil(block->nominal_rate*entry_factor);
|
||||||
block->final_rate = ceil(block->nominal_rate*exit_factor);
|
block->final_rate = ceil(block->nominal_rate*exit_factor);
|
||||||
int32_t acceleration_per_minute = block->rate_delta*ACCELERATION_TICKS_PER_SECOND*60.0;
|
int32_t acceleration_per_minute = block->rate_delta*ACCELERATION_TICKS_PER_SECOND*60.0;
|
||||||
@ -116,7 +116,7 @@ void calculate_trapezoid_for_block(block_t *block, double entry_factor, double e
|
|||||||
|
|
||||||
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
||||||
// acceleration within the allotted distance.
|
// acceleration within the allotted distance.
|
||||||
double max_allowable_speed(double acceleration, double target_velocity, double distance) {
|
static double max_allowable_speed(double acceleration, double target_velocity, double distance) {
|
||||||
return(
|
return(
|
||||||
sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance)
|
sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance)
|
||||||
);
|
);
|
||||||
@ -125,7 +125,7 @@ double max_allowable_speed(double acceleration, double target_velocity, double d
|
|||||||
// "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
|
// "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
|
||||||
// This method will calculate the junction jerk as the euclidean distance between the nominal
|
// This method will calculate the junction jerk as the euclidean distance between the nominal
|
||||||
// velocities of the respective blocks.
|
// velocities of the respective blocks.
|
||||||
double junction_jerk(block_t *before, block_t *after) {
|
static double junction_jerk(block_t *before, block_t *after) {
|
||||||
return(sqrt(
|
return(sqrt(
|
||||||
pow(before->speed_x-after->speed_x, 2)+
|
pow(before->speed_x-after->speed_x, 2)+
|
||||||
pow(before->speed_y-after->speed_y, 2)+
|
pow(before->speed_y-after->speed_y, 2)+
|
||||||
@ -135,7 +135,7 @@ double junction_jerk(block_t *before, block_t *after) {
|
|||||||
|
|
||||||
// Calculate a braking factor to reach baseline speed which is max_jerk/2, e.g. the
|
// Calculate a braking factor to reach baseline speed which is max_jerk/2, e.g. the
|
||||||
// speed under which you cannot exceed max_jerk no matter what you do.
|
// speed under which you cannot exceed max_jerk no matter what you do.
|
||||||
double factor_for_safe_speed(block_t *block) {
|
static double factor_for_safe_speed(block_t *block) {
|
||||||
if(settings.max_jerk < block->nominal_speed) {
|
if(settings.max_jerk < block->nominal_speed) {
|
||||||
return(settings.max_jerk/block->nominal_speed);
|
return(settings.max_jerk/block->nominal_speed);
|
||||||
} else {
|
} else {
|
||||||
@ -144,7 +144,7 @@ double factor_for_safe_speed(block_t *block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
|
// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
|
||||||
void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
static void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
||||||
if(!current) { return; }
|
if(!current) { return; }
|
||||||
|
|
||||||
double entry_factor = 1.0;
|
double entry_factor = 1.0;
|
||||||
@ -181,7 +181,7 @@ void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *n
|
|||||||
|
|
||||||
// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
|
// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
|
||||||
// implements the reverse pass.
|
// implements the reverse pass.
|
||||||
void planner_reverse_pass() {
|
static void planner_reverse_pass() {
|
||||||
auto int8_t block_index = block_buffer_head;
|
auto int8_t block_index = block_buffer_head;
|
||||||
block_t *block[3] = {NULL, NULL, NULL};
|
block_t *block[3] = {NULL, NULL, NULL};
|
||||||
while(block_index != block_buffer_tail) {
|
while(block_index != block_buffer_tail) {
|
||||||
@ -198,7 +198,7 @@ void planner_reverse_pass() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The kernel called by planner_recalculate() when scanning the plan from first to last entry.
|
// The kernel called by planner_recalculate() when scanning the plan from first to last entry.
|
||||||
void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
static void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
||||||
if(!current) { return; }
|
if(!current) { return; }
|
||||||
// If the previous block is an acceleration block, but it is not long enough to
|
// If the previous block is an acceleration block, but it is not long enough to
|
||||||
// complete the full speed change within the block, we need to adjust out entry
|
// complete the full speed change within the block, we need to adjust out entry
|
||||||
@ -216,7 +216,7 @@ void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *n
|
|||||||
|
|
||||||
// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
|
// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
|
||||||
// implements the forward pass.
|
// implements the forward pass.
|
||||||
void planner_forward_pass() {
|
static void planner_forward_pass() {
|
||||||
int8_t block_index = block_buffer_tail;
|
int8_t block_index = block_buffer_tail;
|
||||||
block_t *block[3] = {NULL, NULL, NULL};
|
block_t *block[3] = {NULL, NULL, NULL};
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ void planner_forward_pass() {
|
|||||||
// Recalculates the trapezoid speed profiles for all blocks in the plan according to the
|
// Recalculates the trapezoid speed profiles for all blocks in the plan according to the
|
||||||
// entry_factor for each junction. Must be called by planner_recalculate() after
|
// entry_factor for each junction. Must be called by planner_recalculate() after
|
||||||
// updating the blocks.
|
// updating the blocks.
|
||||||
void planner_recalculate_trapezoids() {
|
static void planner_recalculate_trapezoids() {
|
||||||
int8_t block_index = block_buffer_tail;
|
int8_t block_index = block_buffer_tail;
|
||||||
block_t *current;
|
block_t *current;
|
||||||
block_t *next = NULL;
|
block_t *next = NULL;
|
||||||
@ -266,7 +266,7 @@ void planner_recalculate_trapezoids() {
|
|||||||
//
|
//
|
||||||
// 3. Recalculate trapezoids for all blocks.
|
// 3. Recalculate trapezoids for all blocks.
|
||||||
|
|
||||||
void planner_recalculate() {
|
static void planner_recalculate() {
|
||||||
planner_reverse_pass();
|
planner_reverse_pass();
|
||||||
planner_forward_pass();
|
planner_forward_pass();
|
||||||
planner_recalculate_trapezoids();
|
planner_recalculate_trapezoids();
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
static char line[LINE_BUFFER_SIZE];
|
static char line[LINE_BUFFER_SIZE];
|
||||||
static uint8_t char_counter;
|
static uint8_t char_counter;
|
||||||
|
|
||||||
void status_message(int status_code) {
|
static void status_message(int status_code) {
|
||||||
if (status_code == 0) {
|
if (status_code == 0) {
|
||||||
printPgmString(PSTR("ok\n\r"));
|
printPgmString(PSTR("ok\n\r"));
|
||||||
} else {
|
} else {
|
||||||
|
10
stepper.c
10
stepper.c
@ -80,7 +80,7 @@ static uint32_t trapezoid_adjusted_rate; // The current rate of step_events
|
|||||||
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
||||||
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
||||||
|
|
||||||
void set_step_events_per_minute(uint32_t steps_per_minute);
|
static void set_step_events_per_minute(uint32_t steps_per_minute);
|
||||||
|
|
||||||
void st_wake_up() {
|
void st_wake_up() {
|
||||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||||
@ -88,7 +88,7 @@ void st_wake_up() {
|
|||||||
|
|
||||||
// Initializes the trapezoid generator from the current block. Called whenever a new
|
// Initializes the trapezoid generator from the current block. Called whenever a new
|
||||||
// block begins.
|
// block begins.
|
||||||
void trapezoid_generator_reset() {
|
static void trapezoid_generator_reset() {
|
||||||
trapezoid_adjusted_rate = current_block->initial_rate;
|
trapezoid_adjusted_rate = current_block->initial_rate;
|
||||||
trapezoid_tick_cycle_counter = 0; // Always start a new trapezoid with a full acceleration tick
|
trapezoid_tick_cycle_counter = 0; // Always start a new trapezoid with a full acceleration tick
|
||||||
set_step_events_per_minute(trapezoid_adjusted_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
@ -97,7 +97,7 @@ void trapezoid_generator_reset() {
|
|||||||
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
|
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
|
||||||
// interrupt. It can be assumed that the trapezoid-generator-parameters and the
|
// interrupt. It can be assumed that the trapezoid-generator-parameters and the
|
||||||
// current_block stays untouched by outside handlers for the duration of this function call.
|
// current_block stays untouched by outside handlers for the duration of this function call.
|
||||||
void trapezoid_generator_tick() {
|
static void trapezoid_generator_tick() {
|
||||||
if (current_block) {
|
if (current_block) {
|
||||||
if (step_events_completed < current_block->accelerate_until) {
|
if (step_events_completed < current_block->accelerate_until) {
|
||||||
trapezoid_adjusted_rate += current_block->rate_delta;
|
trapezoid_adjusted_rate += current_block->rate_delta;
|
||||||
@ -248,7 +248,7 @@ void st_synchronize()
|
|||||||
|
|
||||||
// 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.
|
||||||
// Returns the actual number of cycles per interrupt
|
// Returns the actual number of cycles per interrupt
|
||||||
uint32_t config_step_timer(uint32_t cycles)
|
static uint32_t config_step_timer(uint32_t cycles)
|
||||||
{
|
{
|
||||||
uint16_t ceiling;
|
uint16_t ceiling;
|
||||||
uint16_t prescaler;
|
uint16_t prescaler;
|
||||||
@ -286,7 +286,7 @@ uint32_t config_step_timer(uint32_t cycles)
|
|||||||
return(actual_cycles);
|
return(actual_cycles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_step_events_per_minute(uint32_t steps_per_minute) {
|
static void set_step_events_per_minute(uint32_t steps_per_minute) {
|
||||||
if (steps_per_minute < MINIMUM_STEPS_PER_MINUTE) { steps_per_minute = MINIMUM_STEPS_PER_MINUTE; }
|
if (steps_per_minute < MINIMUM_STEPS_PER_MINUTE) { steps_per_minute = MINIMUM_STEPS_PER_MINUTE; }
|
||||||
cycles_per_step_event = config_step_timer((TICKS_PER_MICROSECOND*1000000*60)/steps_per_minute);
|
cycles_per_step_event = config_step_timer((TICKS_PER_MICROSECOND*1000000*60)/steps_per_minute);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user