updated struct types to use typedefs and conform to Micael Barrs Embedded C Coding Standard

This commit is contained in:
Simen Svale Skogsrud 2011-01-25 22:51:37 +01:00
parent 4dbe7c4833
commit 25383790e2
6 changed files with 25 additions and 26 deletions

View File

@ -26,7 +26,7 @@
#include "wiring_serial.h" #include "wiring_serial.h"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
struct Settings settings; settings_t settings;
void reset_settings() { void reset_settings() {
settings.steps_per_mm[0] = X_STEPS_PER_MM; settings.steps_per_mm[0] = X_STEPS_PER_MM;
@ -62,7 +62,7 @@ int read_settings() {
uint8_t version = eeprom_get_char(0); uint8_t version = eeprom_get_char(0);
if (version != SETTINGS_VERSION) { return(FALSE); } if (version != SETTINGS_VERSION) { return(FALSE); }
// Read settings-record and check checksum // Read settings-record and check checksum
if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(struct Settings)))) { if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t)))) {
return(FALSE); return(FALSE);
} }
return(TRUE); return(TRUE);
@ -70,7 +70,7 @@ int read_settings() {
void write_settings() { void write_settings() {
eeprom_put_char(0, SETTINGS_VERSION); eeprom_put_char(0, SETTINGS_VERSION);
memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(struct Settings)); memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t));
} }
// A helper method to set settings from command line // A helper method to set settings from command line

View File

@ -63,7 +63,7 @@
#define SETTINGS_VERSION 2 #define SETTINGS_VERSION 2
// Current global settings (persisted in EEPROM from byte 1 onwards) // Current global settings (persisted in EEPROM from byte 1 onwards)
struct Settings { typedef struct {
double steps_per_mm[3]; double steps_per_mm[3];
uint8_t microsteps; uint8_t microsteps;
uint8_t pulse_microseconds; uint8_t pulse_microseconds;
@ -73,8 +73,8 @@ struct Settings {
double mm_per_arc_segment; double mm_per_arc_segment;
double acceleration; double acceleration;
double max_jerk; double max_jerk;
}; } settings_t;
extern struct Settings settings; extern settings_t settings;
// Initialize the configuration subsystem (load settings from EEPROM) // Initialize the configuration subsystem (load settings from EEPROM)
void config_init(); void config_init();

View File

@ -74,7 +74,7 @@
#define SPINDLE_DIRECTION_CW 0 #define SPINDLE_DIRECTION_CW 0
#define SPINDLE_DIRECTION_CCW 1 #define SPINDLE_DIRECTION_CCW 1
struct ParserState { typedef struct {
uint8_t status_code; uint8_t status_code;
uint8_t motion_mode; /* {G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89} */ uint8_t motion_mode; /* {G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89} */
@ -87,10 +87,9 @@ struct ParserState {
double position[3]; /* Where the interpreter considers the tool to be at this point in the code */ double position[3]; /* Where the interpreter considers the tool to be at this point in the code */
uint8_t tool; uint8_t tool;
int16_t spindle_speed; /* RPM/100 */ int16_t spindle_speed; /* RPM/100 */
uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // The axes of the selected plane uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // The axes of the selected plane
} parser_state_t;
}; parser_state_t gc;
struct ParserState gc;
#define FAIL(status) gc.status_code = status; #define FAIL(status) gc.status_code = status;

View File

@ -39,7 +39,7 @@ void set_step_events_per_minute(uint32_t steps_per_minute);
#define MINIMUM_STEPS_PER_MINUTE 1200 #define MINIMUM_STEPS_PER_MINUTE 1200
#define CYCLES_PER_ACCELERATION_TICK ((TICKS_PER_MICROSECOND*1000000)/ACCELERATION_TICKS_PER_SECOND) #define CYCLES_PER_ACCELERATION_TICK ((TICKS_PER_MICROSECOND*1000000)/ACCELERATION_TICKS_PER_SECOND)
struct Block *current_block; // A convenience pointer to the block currently being traced block_t *current_block; // A convenience pointer to the block currently being traced
// Variables used by The Stepper Driver Interrupt // Variables used by The Stepper Driver Interrupt
uint8_t out_bits; // The next stepping-bits to be output uint8_t out_bits; // The next stepping-bits to be output

View File

@ -60,7 +60,7 @@
#include "config.h" #include "config.h"
#include "wiring_serial.h" #include "wiring_serial.h"
struct Block block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
volatile int block_buffer_head; // Index of the next block to be pushed volatile int block_buffer_head; // Index of the next block to be pushed
volatile int block_buffer_tail; // Index of the block to process now volatile int block_buffer_tail; // Index of the block to process now
uint8_t acceleration_management; // Acceleration management active? uint8_t acceleration_management; // Acceleration management active?
@ -113,7 +113,7 @@ inline double intersection_distance(double initial_rate, double final_rate, doub
time --> time -->
*/ */
void calculate_trapezoid_for_block(struct Block *block, double entry_factor, double exit_factor) { 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);
int32_t final_rate = ceil(block->nominal_rate*entry_factor); int32_t final_rate = ceil(block->nominal_rate*entry_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;
@ -149,7 +149,7 @@ inline double max_allowable_speed(double acceleration, double target_velocity, 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.
inline double junction_jerk(struct Block *before, struct Block *after) { inline 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)+
@ -158,7 +158,7 @@ inline double junction_jerk(struct Block *before, struct Block *after) {
} }
// 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(struct Block *previous, struct Block *current, struct Block *next) { 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;
@ -197,7 +197,7 @@ void planner_reverse_pass_kernel(struct Block *previous, struct Block *current,
// implements the reverse pass. // implements the reverse pass.
void planner_reverse_pass() { void planner_reverse_pass() {
auto int8_t block_index = block_buffer_head; auto int8_t block_index = block_buffer_head;
struct Block *block[3] = {NULL, NULL, NULL}; block_t *block[3] = {NULL, NULL, NULL};
while(block_index != block_buffer_tail) { while(block_index != block_buffer_tail) {
block[2]= block[1]; block[2]= block[1];
block[1]= block[0]; block[1]= block[0];
@ -209,7 +209,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(struct Block *previous, struct Block *current, struct Block *next) { 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
@ -229,7 +229,7 @@ void planner_forward_pass_kernel(struct Block *previous, struct Block *current,
// implements the forward pass. // implements the forward pass.
void planner_forward_pass() { void planner_forward_pass() {
int8_t block_index = block_buffer_tail; int8_t block_index = block_buffer_tail;
struct Block *block[3] = {NULL, NULL, NULL}; block_t *block[3] = {NULL, NULL, NULL};
while(block_index != block_buffer_head) { while(block_index != block_buffer_head) {
block[0] = block[1]; block[0] = block[1];
@ -246,8 +246,8 @@ void planner_forward_pass() {
// updating the blocks. // updating the blocks.
void planner_recalculate_trapezoids() { void planner_recalculate_trapezoids() {
int8_t block_index = block_buffer_tail; int8_t block_index = block_buffer_tail;
struct Block *current; block_t *current;
struct Block *next = NULL; block_t *next = NULL;
while(block_index != block_buffer_head) { while(block_index != block_buffer_head) {
current = next; current = next;
@ -262,7 +262,7 @@ void planner_recalculate_trapezoids() {
// Recalculates the motion plan according to the following algorithm: // Recalculates the motion plan according to the following algorithm:
// //
// 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. Block.entry_factor) // 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. block_t.entry_factor)
// so that: // so that:
// a. The junction jerk is within the set limit // a. The junction jerk is within the set limit
// b. No speed reduction within one block requires faster deceleration than the one, true constant // b. No speed reduction within one block requires faster deceleration than the one, true constant
@ -313,7 +313,7 @@ void plan_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_
// Rest here until there is room in the buffer. // Rest here until there is room in the buffer.
while(block_buffer_tail == next_buffer_head) { sleep_mode(); } while(block_buffer_tail == next_buffer_head) { sleep_mode(); }
// Prepare to set up new block // Prepare to set up new block
struct Block *block = &block_buffer[block_buffer_head]; block_t *block = &block_buffer[block_buffer_head];
// Number of steps for each axis // Number of steps for each axis
block->steps_x = labs(steps_x); block->steps_x = labs(steps_x);
block->steps_y = labs(steps_y); block->steps_y = labs(steps_y);

View File

@ -32,7 +32,7 @@
// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
// the source g-code and may never actually be reached if acceleration management is active. // the source g-code and may never actually be reached if acceleration management is active.
struct Block { typedef struct {
// Fields used by the bresenham algorithm for tracing the line // Fields used by the bresenham algorithm for tracing the line
uint32_t steps_x, steps_y, steps_z; // Step count along each axis uint32_t steps_x, steps_y, steps_z; // Step count along each axis
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
@ -52,9 +52,9 @@ struct Block {
int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive) int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive)
uint32_t accelerate_until; // The index of the step event on which to stop acceleration uint32_t accelerate_until; // The index of the step event on which to stop acceleration
uint32_t decelerate_after; // The index of the step event on which to start decelerating uint32_t decelerate_after; // The index of the step event on which to start decelerating
}; } block_t;
extern struct Block block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions 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_head; // Index of the next block to be pushed
extern volatile int block_buffer_tail; // Index of the block to process now extern volatile int block_buffer_tail; // Index of the block to process now