Skip to content

Commit

Permalink
Adding stuff to avoid malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
preston-rogers committed Jul 30, 2024
1 parent 5339af5 commit 03c7b36
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/jsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ bool jsd_init(jsd_t* self, const char* ifname, uint8_t enable_autorecovery) {
self->ecx_context.slavelist[0].state = EC_STATE_OPERATIONAL;

ecx_send_overlap_processdata(&self->ecx_context);
uint64_t *bad_wkc_indices;
*bad_wkc_indices = 0;
uint64 bad_wkc_indices_val = 0;
uint64* bad_wkc_indices = &bad_wkc_indices_val;
ecx_receive_processdata(&self->ecx_context, EC_TIMEOUTRET, bad_wkc_indices);

ecx_writestate(&self->ecx_context, 0);

int attempt = 0;
while (true) {
int sent = ecx_send_overlap_processdata(&self->ecx_context);
uint64_t *bad_wkc_indices;
*bad_wkc_indices = 0;
uint64 bad_wkc_indices_val = 0;
uint64* bad_wkc_indices = &bad_wkc_indices_val;
int wkc = ecx_receive_processdata(&self->ecx_context, EC_TIMEOUTRET, bad_wkc_indices);
ec_state actual_state = ecx_statecheck(
&self->ecx_context, 0, EC_STATE_OPERATIONAL, EC_TIMEOUTSTATE);
Expand Down Expand Up @@ -234,8 +234,8 @@ void jsd_read(jsd_t* self, int timeout_us) {
assert(self);

// Wait for EtherCat frame to return from slaves, with logic for smart prints
uint64* bad_wkc_indices;
*bad_wkc_indices = 0;
uint64 bad_wkc_indices_val = 0;
uint64* bad_wkc_indices = &bad_wkc_indices_val;
self->wkc = ecx_receive_processdata(&self->ecx_context, timeout_us, bad_wkc_indices);
if (self->wkc != self->expected_wkc && self->last_wkc != self->wkc) {
WARNING("ecx_receive_processdata returning bad wkc: %d (expected: %d)",
Expand All @@ -250,7 +250,7 @@ void jsd_read(jsd_t* self, int timeout_us) {
for (slave_idx = 1; slave_idx < num_slaves; slave_idx++) {
ec_slavet* slave = &slaves[slave_idx];
// Go through every bit and see if any device was set to 1 due to bad wkc
bool bad_device_wkc = *bad_wkc_indices & (1 << slave_idx);
bool bad_device_wkc = bad_wkc_indices_val & (1 << slave_idx);
if (bad_device_wkc) {
WARNING("Device (%s) index caused a bad working counter: %d", slave->name, slave_idx);
}
Expand Down

0 comments on commit 03c7b36

Please sign in to comment.