mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-10-26 07:46:11 +01:00
steppersync: Add new 'struct steppersyncmgr'
Add a new C based mechanism for tracking all the 'struct steppersync' instances. This simplifies memory management. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -61,9 +61,6 @@ defs_stepcompress = """
|
||||
"""
|
||||
|
||||
defs_steppersync = """
|
||||
struct steppersync *steppersync_alloc(struct serialqueue *sq
|
||||
, struct stepcompress **sc_list, int sc_num, int move_num);
|
||||
void steppersync_free(struct steppersync *ss);
|
||||
void steppersync_set_time(struct steppersync *ss
|
||||
, double time_offset, double mcu_freq);
|
||||
void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock);
|
||||
@@ -71,6 +68,11 @@ defs_steppersync = """
|
||||
, double gen_steps_time, uint64_t flush_clock);
|
||||
int32_t steppersync_finalize_gen_steps(struct steppersync *ss
|
||||
, uint64_t flush_clock);
|
||||
struct steppersyncmgr *steppersyncmgr_alloc(void);
|
||||
void steppersyncmgr_free(struct steppersyncmgr *ssm);
|
||||
struct steppersync *steppersyncmgr_alloc_steppersync(
|
||||
struct steppersyncmgr *ssm, struct serialqueue *sq
|
||||
, struct stepcompress **sc_list, int sc_num, int move_num);
|
||||
"""
|
||||
|
||||
defs_itersolve = """
|
||||
|
||||
@@ -19,7 +19,14 @@
|
||||
#include "stepcompress.h" // stepcompress_flush
|
||||
#include "steppersync.h" // steppersync_alloc
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* StepperSync - sort move queue for a micro-controller
|
||||
****************************************************************/
|
||||
|
||||
struct steppersync {
|
||||
// List node for storage in steppersyncmgr list
|
||||
struct list_node ssm_node;
|
||||
// Serial port
|
||||
struct serialqueue *sq;
|
||||
struct command_queue *cq;
|
||||
@@ -32,7 +39,7 @@ struct steppersync {
|
||||
};
|
||||
|
||||
// Allocate a new 'steppersync' object
|
||||
struct steppersync * __visible
|
||||
static struct steppersync *
|
||||
steppersync_alloc(struct serialqueue *sq, struct stepcompress **sc_list
|
||||
, int sc_num, int move_num)
|
||||
{
|
||||
@@ -53,7 +60,7 @@ steppersync_alloc(struct serialqueue *sq, struct stepcompress **sc_list
|
||||
}
|
||||
|
||||
// Free memory associated with a 'steppersync' object
|
||||
void __visible
|
||||
static void
|
||||
steppersync_free(struct steppersync *ss)
|
||||
{
|
||||
if (!ss)
|
||||
@@ -187,3 +194,48 @@ steppersync_finalize_gen_steps(struct steppersync *ss, uint64_t flush_clock)
|
||||
steppersync_flush(ss, flush_clock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* StepperSyncMgr - manage a list of steppersync
|
||||
****************************************************************/
|
||||
|
||||
struct steppersyncmgr {
|
||||
struct list_head ss_list;
|
||||
};
|
||||
|
||||
// Allocate a new 'steppersyncmgr' object
|
||||
struct steppersyncmgr * __visible
|
||||
steppersyncmgr_alloc(void)
|
||||
{
|
||||
struct steppersyncmgr *ssm = malloc(sizeof(*ssm));
|
||||
memset(ssm, 0, sizeof(*ssm));
|
||||
list_init(&ssm->ss_list);
|
||||
return ssm;
|
||||
}
|
||||
|
||||
// Free memory associated with a 'steppersync' object
|
||||
void __visible
|
||||
steppersyncmgr_free(struct steppersyncmgr *ssm)
|
||||
{
|
||||
if (!ssm)
|
||||
return;
|
||||
while (!list_empty(&ssm->ss_list)) {
|
||||
struct steppersync *ss = list_first_entry(
|
||||
&ssm->ss_list, struct steppersync, ssm_node);
|
||||
list_del(&ss->ssm_node);
|
||||
steppersync_free(ss);
|
||||
}
|
||||
free(ssm);
|
||||
}
|
||||
|
||||
// Allocate a new 'steppersync' object
|
||||
struct steppersync * __visible
|
||||
steppersyncmgr_alloc_steppersync(
|
||||
struct steppersyncmgr *ssm, struct serialqueue *sq
|
||||
, struct stepcompress **sc_list, int sc_num, int move_num)
|
||||
{
|
||||
struct steppersync *ss = steppersync_alloc(sq, sc_list, sc_num, move_num);
|
||||
list_add_tail(&ss->ssm_node, &ssm->ss_list);
|
||||
return ss;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
|
||||
#include <stdint.h> // uint64_t
|
||||
|
||||
struct serialqueue;
|
||||
struct steppersync *steppersync_alloc(
|
||||
struct serialqueue *sq, struct stepcompress **sc_list, int sc_num
|
||||
, int move_num);
|
||||
void steppersync_free(struct steppersync *ss);
|
||||
struct steppersync;
|
||||
void steppersync_set_time(struct steppersync *ss, double time_offset
|
||||
, double mcu_freq);
|
||||
void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock);
|
||||
@@ -16,4 +12,11 @@ void steppersync_start_gen_steps(struct steppersync *ss, double gen_steps_time
|
||||
int32_t steppersync_finalize_gen_steps(struct steppersync *ss
|
||||
, uint64_t flush_clock);
|
||||
|
||||
struct steppersyncmgr *steppersyncmgr_alloc(void);
|
||||
void steppersyncmgr_free(struct steppersyncmgr *ssm);
|
||||
struct serialqueue;
|
||||
struct steppersync *steppersyncmgr_alloc_steppersync(
|
||||
struct steppersyncmgr *ssm, struct serialqueue *sq
|
||||
, struct stepcompress **sc_list, int sc_num, int move_num);
|
||||
|
||||
#endif // steppersync.h
|
||||
|
||||
@@ -29,6 +29,8 @@ class PrinterMotionQueuing:
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves
|
||||
# C steppersync tracking
|
||||
self.steppersyncmgr = ffi_main.gc(ffi_lib.steppersyncmgr_alloc(),
|
||||
ffi_lib.steppersyncmgr_free)
|
||||
self.stepcompress = []
|
||||
self.steppersyncs = []
|
||||
self.steppersync_start_gen_steps = ffi_lib.steppersync_start_gen_steps
|
||||
@@ -84,10 +86,9 @@ class PrinterMotionQueuing:
|
||||
if sc_mcu is mcu:
|
||||
stepqueues.append(sc)
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
ss = ffi_main.gc(
|
||||
ffi_lib.steppersync_alloc(serialqueue, stepqueues, len(stepqueues),
|
||||
move_count),
|
||||
ffi_lib.steppersync_free)
|
||||
ss = ffi_lib.steppersyncmgr_alloc_steppersync(
|
||||
self.steppersyncmgr, serialqueue, stepqueues, len(stepqueues),
|
||||
move_count)
|
||||
self.steppersyncs.append((mcu, ss))
|
||||
mcu_freq = float(mcu.seconds_to_clock(1.))
|
||||
ffi_lib.steppersync_set_time(ss, 0., mcu_freq)
|
||||
|
||||
Reference in New Issue
Block a user