stepcompress: Move code around in stepcompress.c

Just code movement - no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-03-08 11:14:26 -04:00
parent 5e39d346ed
commit d86bf0b927
2 changed files with 51 additions and 51 deletions

View File

@ -261,6 +261,18 @@ stepcompress_free(struct stepcompress *sc)
free(sc); free(sc);
} }
uint32_t
stepcompress_get_oid(struct stepcompress *sc)
{
return sc->oid;
}
int
stepcompress_get_step_dir(struct stepcompress *sc)
{
return sc->sdir;
}
// Determine the "print time" of the last_step_clock // Determine the "print time" of the last_step_clock
static void static void
calc_last_step_print_time(struct stepcompress *sc) calc_last_step_print_time(struct stepcompress *sc)
@ -269,6 +281,16 @@ calc_last_step_print_time(struct stepcompress *sc)
sc->last_step_print_time = sc->mcu_time_offset + (lsc - .5) / sc->mcu_freq; sc->last_step_print_time = sc->mcu_time_offset + (lsc - .5) / sc->mcu_freq;
} }
// Set the conversion rate of 'print_time' to mcu clock
static void
stepcompress_set_time(struct stepcompress *sc
, double time_offset, double mcu_freq)
{
sc->mcu_time_offset = time_offset;
sc->mcu_freq = mcu_freq;
calc_last_step_print_time(sc);
}
// Convert previously scheduled steps into commands for the mcu // Convert previously scheduled steps into commands for the mcu
static int static int
stepcompress_flush(struct stepcompress *sc, uint64_t move_clock) stepcompress_flush(struct stepcompress *sc, uint64_t move_clock)
@ -336,55 +358,6 @@ set_next_step_dir(struct stepcompress *sc, int sdir)
return 0; return 0;
} }
// Reset the internal state of the stepcompress object
int __visible
stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock)
{
int ret = stepcompress_flush(sc, UINT64_MAX);
if (ret)
return ret;
sc->last_step_clock = last_step_clock;
sc->sdir = -1;
calc_last_step_print_time(sc);
return 0;
}
// Queue an mcu command to go out in order with stepper commands
int __visible
stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len)
{
int ret = stepcompress_flush(sc, UINT64_MAX);
if (ret)
return ret;
struct queue_message *qm = message_alloc_and_encode(data, len);
qm->req_clock = sc->last_step_clock;
list_add_tail(&qm->node, &sc->msg_queue);
return 0;
}
// Set the conversion rate of 'print_time' to mcu clock
static void
stepcompress_set_time(struct stepcompress *sc
, double time_offset, double mcu_freq)
{
sc->mcu_time_offset = time_offset;
sc->mcu_freq = mcu_freq;
calc_last_step_print_time(sc);
}
uint32_t
stepcompress_get_oid(struct stepcompress *sc)
{
return sc->oid;
}
int
stepcompress_get_step_dir(struct stepcompress *sc)
{
return sc->sdir;
}
// Maximium clock delta between messages in the queue // Maximium clock delta between messages in the queue
#define CLOCK_DIFF_MAX (3<<28) #define CLOCK_DIFF_MAX (3<<28)
@ -456,6 +429,33 @@ stepcompress_append(struct stepcompress *sc, int sdir
return 0; return 0;
} }
// Reset the internal state of the stepcompress object
int __visible
stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock)
{
int ret = stepcompress_flush(sc, UINT64_MAX);
if (ret)
return ret;
sc->last_step_clock = last_step_clock;
sc->sdir = -1;
calc_last_step_print_time(sc);
return 0;
}
// Queue an mcu command to go out in order with stepper commands
int __visible
stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len)
{
int ret = stepcompress_flush(sc, UINT64_MAX);
if (ret)
return ret;
struct queue_message *qm = message_alloc_and_encode(data, len);
qm->req_clock = sc->last_step_clock;
list_add_tail(&qm->node, &sc->msg_queue);
return 0;
}
/**************************************************************** /****************************************************************
* Step compress synchronization * Step compress synchronization

View File

@ -10,12 +10,12 @@ void stepcompress_fill(struct stepcompress *sc, uint32_t max_error
, uint32_t invert_sdir, uint32_t queue_step_msgid , uint32_t invert_sdir, uint32_t queue_step_msgid
, uint32_t set_next_step_dir_msgid); , uint32_t set_next_step_dir_msgid);
void stepcompress_free(struct stepcompress *sc); void stepcompress_free(struct stepcompress *sc);
int stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock);
int stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len);
uint32_t stepcompress_get_oid(struct stepcompress *sc); uint32_t stepcompress_get_oid(struct stepcompress *sc);
int stepcompress_get_step_dir(struct stepcompress *sc); int stepcompress_get_step_dir(struct stepcompress *sc);
int stepcompress_append(struct stepcompress *sc, int sdir int stepcompress_append(struct stepcompress *sc, int sdir
, double print_time, double step_time); , double print_time, double step_time);
int stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock);
int stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len);
struct serialqueue; struct serialqueue;
struct steppersync *steppersync_alloc( struct steppersync *steppersync_alloc(