From e4bb6629f38a0cf7cb37d1e9e4b9f17947b32e97 Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Mon, 3 Jun 2024 13:42:25 +0200 Subject: [PATCH 1/6] add .vscode to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b4bbe2cc..911b5097 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ install /doc/latex /doc/html tags +.vscode/ From dc843928ac02ccf0270a7e329d7544767bc2431f Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Mon, 3 Jun 2024 13:43:29 +0200 Subject: [PATCH 2/6] fix spacing in EC_PRINT --- soem/ethercatconfig.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/soem/ethercatconfig.c b/soem/ethercatconfig.c index 4a02c02a..486aa175 100644 --- a/soem/ethercatconfig.c +++ b/soem/ethercatconfig.c @@ -733,7 +733,7 @@ static int ecx_map_sii(ecx_contextt *context, uint16 slave) } context->slavelist[slave].Obits = (uint16)Osize; context->slavelist[slave].Ibits = (uint16)Isize; - EC_PRINT(" ISIZE:%d %d OSIZE:%d\n", + EC_PRINT(" SII ISIZE:%d %d OSIZE:%d\n", context->slavelist[slave].Ibits, Isize,context->slavelist[slave].Obits); return 1; @@ -907,7 +907,7 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap uint16 configadr; uint8 FMMUc; - EC_PRINT(" =Slave %d, INPUT MAPPING\n", slave); + EC_PRINT(" INPUT MAPPING\n"); configadr = context->slavelist[slave].configadr; FMMUc = context->slavelist[slave].FMMUunused; @@ -1024,7 +1024,8 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap } context->slavelist[slave].Istartbit = context->slavelist[slave].FMMU[FMMUc].LogStartbit; - EC_PRINT(" Inputs %p startbit %d\n", + EC_PRINT(" slave %d Inputs %p startbit %d\n", + slave, context->slavelist[slave].inputs, context->slavelist[slave].Istartbit); } From eed3ce32461aee0227129fcd6d7484f523bfab5c Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Mon, 3 Jun 2024 13:43:55 +0200 Subject: [PATCH 3/6] fix newline in printf --- test/simple_ng/simple_ng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simple_ng/simple_ng.c b/test/simple_ng/simple_ng.c index 835d7bcd..8926b932 100644 --- a/test/simple_ng/simple_ng.c +++ b/test/simple_ng/simple_ng.c @@ -222,7 +222,7 @@ fieldbus_dump(Fieldbus *fieldbus) for (n = 0; n < grp->Ibytes; ++n) { printf(" %02X", grp->inputs[n]); } - printf(" T: %lld\r", (long long) fieldbus->DCtime); + printf(" T: %lld\n", (long long) fieldbus->DCtime); return TRUE; } From 966c21d50549aaf9c2e1c427035f0197b7832a1f Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Mon, 3 Jun 2024 13:45:12 +0200 Subject: [PATCH 4/6] run code format on simpletest.c --- test/linux/simple_test/simple_test.c | 259 ++++++++++++++------------- 1 file changed, 130 insertions(+), 129 deletions(-) diff --git a/test/linux/simple_test/simple_test.c b/test/linux/simple_test/simple_test.c index 8b9f70d1..2028e9be 100644 --- a/test/linux/simple_test/simple_test.c +++ b/test/linux/simple_test/simple_test.c @@ -28,22 +28,21 @@ boolean forceByteAlignment = FALSE; void simpletest(char *ifname) { - int i, j, oloop, iloop, chk; - needlf = FALSE; - inOP = FALSE; + int i, j, oloop, iloop, chk; + needlf = FALSE; + inOP = FALSE; printf("Starting simple test\n"); /* initialise SOEM, bind socket to ifname */ if (ec_init(ifname)) { - printf("ec_init on %s succeeded.\n",ifname); + printf("ec_init on %s succeeded.\n", ifname); /* find and auto-config slaves */ - - if ( ec_config_init(FALSE) > 0 ) + if (ec_config_init(FALSE) > 0) { - printf("%d slaves found and configured.\n",ec_slavecount); + printf("%d slaves found and configured.\n", ec_slavecount); if (forceByteAlignment) { @@ -58,16 +57,20 @@ void simpletest(char *ifname) printf("Slaves mapped, state to SAFE_OP.\n"); /* wait for all slaves to reach SAFE_OP state */ - ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4); + ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4); oloop = ec_slave[0].Obytes; - if ((oloop == 0) && (ec_slave[0].Obits > 0)) oloop = 1; - if (oloop > 8) oloop = 8; + if ((oloop == 0) && (ec_slave[0].Obits > 0)) + oloop = 1; + if (oloop > 8) + oloop = 8; iloop = ec_slave[0].Ibytes; - if ((iloop == 0) && (ec_slave[0].Ibits > 0)) iloop = 1; - if (iloop > 8) iloop = 8; + if ((iloop == 0) && (ec_slave[0].Ibits > 0)) + iloop = 1; + if (iloop > 8) + iloop = 8; - printf("segments : %d : %d %d %d %d\n",ec_group[0].nsegments ,ec_group[0].IOsegment[0],ec_group[0].IOsegment[1],ec_group[0].IOsegment[2],ec_group[0].IOsegment[3]); + printf("segments : %d : %d %d %d %d\n", ec_group[0].nsegments, ec_group[0].IOsegment[0], ec_group[0].IOsegment[1], ec_group[0].IOsegment[2], ec_group[0].IOsegment[3]); printf("Request operational state for all slaves\n"); expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC; @@ -85,147 +88,145 @@ void simpletest(char *ifname) ec_send_processdata(); ec_receive_processdata(EC_TIMEOUTRET); ec_statecheck(0, EC_STATE_OPERATIONAL, 50000); - } - while (chk-- && (ec_slave[0].state != EC_STATE_OPERATIONAL)); - if (ec_slave[0].state == EC_STATE_OPERATIONAL ) + } while (chk-- && (ec_slave[0].state != EC_STATE_OPERATIONAL)); + if (ec_slave[0].state == EC_STATE_OPERATIONAL) { printf("Operational state reached for all slaves.\n"); inOP = TRUE; - /* cyclic loop */ - for(i = 1; i <= 10000; i++) + /* cyclic loop */ + for (i = 1; i <= 10000; i++) { ec_send_processdata(); wkc = ec_receive_processdata(EC_TIMEOUTRET); - if(wkc >= expectedWKC) - { - printf("Processdata cycle %4d, WKC %d , O:", i, wkc); - - for(j = 0 ; j < oloop; j++) - { - printf(" %2.2x", *(ec_slave[0].outputs + j)); - } + if (wkc >= expectedWKC) + { + printf("Processdata cycle %4d, WKC %d , O:", i, wkc); - printf(" I:"); - for(j = 0 ; j < iloop; j++) - { - printf(" %2.2x", *(ec_slave[0].inputs + j)); - } - printf(" T:%"PRId64"\r",ec_DCtime); - needlf = TRUE; - } - osal_usleep(5000); + for (j = 0; j < oloop; j++) + { + printf(" %2.2x", *(ec_slave[0].outputs + j)); + } - } - inOP = FALSE; + printf(" I:"); + for (j = 0; j < iloop; j++) + { + printf(" %2.2x", *(ec_slave[0].inputs + j)); + } + printf(" T:%" PRId64 "\r", ec_DCtime); + needlf = TRUE; + } + osal_usleep(5000); } - else + inOP = FALSE; + } + else + { + printf("Not all slaves reached operational state.\n"); + ec_readstate(); + for (i = 1; i <= ec_slavecount; i++) { - printf("Not all slaves reached operational state.\n"); - ec_readstate(); - for(i = 1; i<=ec_slavecount ; i++) - { - if(ec_slave[i].state != EC_STATE_OPERATIONAL) - { - printf("Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n", - i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode)); - } - } + if (ec_slave[i].state != EC_STATE_OPERATIONAL) + { + printf("Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n", + i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode)); + } } - printf("\nRequest init state for all slaves\n"); - ec_slave[0].state = EC_STATE_INIT; - /* request INIT state for all slaves */ - ec_writestate(0); - } - else - { - printf("No slaves found!\n"); - } - printf("End simple test, close socket\n"); - /* stop SOEM, close socket */ - ec_close(); - } - else - { - printf("No socket connection on %s\nExecute as root\n",ifname); - } + } + printf("\nRequest init state for all slaves\n"); + ec_slave[0].state = EC_STATE_INIT; + /* request INIT state for all slaves */ + ec_writestate(0); + } + else + { + printf("No slaves found!\n"); + } + printf("End simple test, close socket\n"); + /* stop SOEM, close socket */ + ec_close(); + } + else + { + printf("No socket connection on %s\nExecute as root\n", ifname); + } } -OSAL_THREAD_FUNC ecatcheck( void *ptr ) +OSAL_THREAD_FUNC ecatcheck(void *ptr) { - int slave; - (void)ptr; /* Not used */ + int slave; + (void)ptr; /* Not used */ - while(1) - { - if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate)) - { - if (needlf) - { - needlf = FALSE; - printf("\n"); - } - /* one ore more slaves are not responding */ - ec_group[currentgroup].docheckstate = FALSE; - ec_readstate(); - for (slave = 1; slave <= ec_slavecount; slave++) + while (1) + { + if (inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate)) + { + if (needlf) + { + needlf = FALSE; + printf("\n"); + } + /* one ore more slaves are not responding */ + ec_group[currentgroup].docheckstate = FALSE; + ec_readstate(); + for (slave = 1; slave <= ec_slavecount; slave++) + { + if ((ec_slave[slave].group == currentgroup) && (ec_slave[slave].state != EC_STATE_OPERATIONAL)) { - if ((ec_slave[slave].group == currentgroup) && (ec_slave[slave].state != EC_STATE_OPERATIONAL)) + ec_group[currentgroup].docheckstate = TRUE; + if (ec_slave[slave].state == (EC_STATE_SAFE_OP + EC_STATE_ERROR)) { - ec_group[currentgroup].docheckstate = TRUE; - if (ec_slave[slave].state == (EC_STATE_SAFE_OP + EC_STATE_ERROR)) - { - printf("ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave); - ec_slave[slave].state = (EC_STATE_SAFE_OP + EC_STATE_ACK); - ec_writestate(slave); - } - else if(ec_slave[slave].state == EC_STATE_SAFE_OP) - { - printf("WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave); - ec_slave[slave].state = EC_STATE_OPERATIONAL; - ec_writestate(slave); - } - else if(ec_slave[slave].state > EC_STATE_NONE) - { - if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) - { - ec_slave[slave].islost = FALSE; - printf("MESSAGE : slave %d reconfigured\n",slave); - } - } - else if(!ec_slave[slave].islost) + printf("ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave); + ec_slave[slave].state = (EC_STATE_SAFE_OP + EC_STATE_ACK); + ec_writestate(slave); + } + else if (ec_slave[slave].state == EC_STATE_SAFE_OP) + { + printf("WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave); + ec_slave[slave].state = EC_STATE_OPERATIONAL; + ec_writestate(slave); + } + else if (ec_slave[slave].state > EC_STATE_NONE) + { + if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) { - /* re-check state */ - ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (ec_slave[slave].state == EC_STATE_NONE) - { - ec_slave[slave].islost = TRUE; - printf("ERROR : slave %d lost\n",slave); - } + ec_slave[slave].islost = FALSE; + printf("MESSAGE : slave %d reconfigured\n", slave); } } - if (ec_slave[slave].islost) + else if (!ec_slave[slave].islost) { - if(ec_slave[slave].state == EC_STATE_NONE) + /* re-check state */ + ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); + if (ec_slave[slave].state == EC_STATE_NONE) { - if (ec_recover_slave(slave, EC_TIMEOUTMON)) - { - ec_slave[slave].islost = FALSE; - printf("MESSAGE : slave %d recovered\n",slave); - } + ec_slave[slave].islost = TRUE; + printf("ERROR : slave %d lost\n", slave); } - else + } + } + if (ec_slave[slave].islost) + { + if (ec_slave[slave].state == EC_STATE_NONE) + { + if (ec_recover_slave(slave, EC_TIMEOUTMON)) { ec_slave[slave].islost = FALSE; - printf("MESSAGE : slave %d found\n",slave); + printf("MESSAGE : slave %d recovered\n", slave); } } + else + { + ec_slave[slave].islost = FALSE; + printf("MESSAGE : slave %d found\n", slave); + } } - if(!ec_group[currentgroup].docheckstate) - printf("OK : all slaves resumed OPERATIONAL.\n"); - } - osal_usleep(10000); - } + } + if (!ec_group[currentgroup].docheckstate) + printf("OK : all slaves resumed OPERATIONAL.\n"); + } + osal_usleep(10000); + } } int main(int argc, char *argv[]) @@ -241,14 +242,14 @@ int main(int argc, char *argv[]) } else { - ec_adaptert * adapter = NULL; + ec_adaptert *adapter = NULL; printf("Usage: simple_test ifname1\nifname = eth0 for example\n"); - printf ("\nAvailable adapters:\n"); - adapter = ec_find_adapters (); + printf("\nAvailable adapters:\n"); + adapter = ec_find_adapters(); while (adapter != NULL) { - printf (" - %s (%s)\n", adapter->name, adapter->desc); + printf(" - %s (%s)\n", adapter->name, adapter->desc); adapter = adapter->next; } ec_free_adapters(adapter); From ba8b7f30c00644bfcd0adfa7417f30b9528239f4 Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Mon, 3 Jun 2024 13:46:11 +0200 Subject: [PATCH 5/6] run code format on simple_ng.c --- test/simple_ng/simple_ng.c | 158 +++++++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 60 deletions(-) diff --git a/test/simple_ng/simple_ng.c b/test/simple_ng/simple_ng.c index 8926b932..45c990a5 100644 --- a/test/simple_ng/simple_ng.c +++ b/test/simple_ng/simple_ng.c @@ -12,33 +12,32 @@ #include #include - -typedef struct { - ecx_contextt context; - char * iface; - uint8 group; - int roundtrip_time; +typedef struct +{ + ecx_contextt context; + char *iface; + uint8 group; + int roundtrip_time; /* Used by the context */ - uint8 map[4096]; - ecx_portt port; - ec_slavet slavelist[EC_MAXSLAVE]; - int slavecount; - ec_groupt grouplist[EC_MAXGROUP]; - uint8 esibuf[EC_MAXEEPBUF]; - uint32 esimap[EC_MAXEEPBITMAP]; - ec_eringt elist; - ec_idxstackT idxstack; - boolean ecaterror; - int64 DCtime; - ec_SMcommtypet SMcommtype[EC_MAX_MAPT]; - ec_PDOassignt PDOassign[EC_MAX_MAPT]; - ec_PDOdesct PDOdesc[EC_MAX_MAPT]; - ec_eepromSMt eepSM; - ec_eepromFMMUt eepFMMU; + uint8 map[4096]; + ecx_portt port; + ec_slavet slavelist[EC_MAXSLAVE]; + int slavecount; + ec_groupt grouplist[EC_MAXGROUP]; + uint8 esibuf[EC_MAXEEPBUF]; + uint32 esimap[EC_MAXEEPBITMAP]; + ec_eringt elist; + ec_idxstackT idxstack; + boolean ecaterror; + int64 DCtime; + ec_SMcommtypet SMcommtype[EC_MAX_MAPT]; + ec_PDOassignt PDOassign[EC_MAX_MAPT]; + ec_PDOdesct PDOdesc[EC_MAX_MAPT]; + ec_eepromSMt eepSM; + ec_eepromFMMUt eepFMMU; } Fieldbus; - static void fieldbus_initialize(Fieldbus *fieldbus, char *iface) { @@ -108,14 +107,16 @@ fieldbus_start(Fieldbus *fieldbus) grp = fieldbus->grouplist + fieldbus->group; printf("Initializing SOEM on '%s'... ", fieldbus->iface); - if (! ecx_init(context, fieldbus->iface)) { + if (!ecx_init(context, fieldbus->iface)) + { printf("no socket connection\n"); return FALSE; } printf("done\n"); printf("Finding autoconfig slaves... "); - if (ecx_config_init(context, FALSE) <= 0) { + if (ecx_config_init(context, FALSE) <= 0) + { printf("no slaves found\n"); return FALSE; } @@ -125,9 +126,11 @@ fieldbus_start(Fieldbus *fieldbus) ecx_config_map_group(context, fieldbus->map, fieldbus->group); printf("mapped %dO+%dI bytes from %d segments", grp->Obytes, grp->Ibytes, grp->nsegments); - if (grp->nsegments > 1) { + if (grp->nsegments > 1) + { /* Show how slaves are distrubuted */ - for (i = 0; i < grp->nsegments; ++i) { + for (i = 0; i < grp->nsegments; ++i) + { printf("%s%d", i == 0 ? " (" : "+", grp->IOsegment[i]); } printf(" slaves)"); @@ -152,11 +155,13 @@ fieldbus_start(Fieldbus *fieldbus) slave->state = EC_STATE_OPERATIONAL; ecx_writestate(context, 0); /* Poll the result ten times before giving up */ - for (i = 0; i < 10; ++i) { + for (i = 0; i < 10; ++i) + { printf("."); fieldbus_roundtrip(fieldbus); ecx_statecheck(context, 0, EC_STATE_OPERATIONAL, EC_TIMEOUTSTATE / 10); - if (slave->state == EC_STATE_OPERATIONAL) { + if (slave->state == EC_STATE_OPERATIONAL) + { printf(" all slaves are now operational\n"); return TRUE; } @@ -164,12 +169,14 @@ fieldbus_start(Fieldbus *fieldbus) printf(" failed,"); ecx_readstate(context); - for (i = 1; i <= fieldbus->slavecount; ++i) { + for (i = 1; i <= fieldbus->slavecount; ++i) + { slave = fieldbus->slavelist + i; - if (slave->state != EC_STATE_OPERATIONAL) { + if (slave->state != EC_STATE_OPERATIONAL) + { printf(" slave %d is 0x%04X (AL-status=0x%04X %s)", - i, slave->state, slave->ALstatuscode, - ec_ALstatuscode2string(slave->ALstatuscode)); + i, slave->state, slave->ALstatuscode, + ec_ALstatuscode2string(slave->ALstatuscode)); } } printf("\n"); @@ -209,20 +216,23 @@ fieldbus_dump(Fieldbus *fieldbus) wkc = fieldbus_roundtrip(fieldbus); expected_wkc = grp->outputsWKC * 2 + grp->inputsWKC; printf("%6d usec WKC %d", fieldbus->roundtrip_time, wkc); - if (wkc < expected_wkc) { + if (wkc < expected_wkc) + { printf(" wrong (expected %d)\n", expected_wkc); return FALSE; } printf(" O:"); - for (n = 0; n < grp->Obytes; ++n) { + for (n = 0; n < grp->Obytes; ++n) + { printf(" %02X", grp->outputs[n]); } printf(" I:"); - for (n = 0; n < grp->Ibytes; ++n) { + for (n = 0; n < grp->Ibytes; ++n) + { printf(" %02X", grp->inputs[n]); } - printf(" T: %lld\n", (long long) fieldbus->DCtime); + printf(" T: %lld\n", (long long)fieldbus->DCtime); return TRUE; } @@ -238,55 +248,74 @@ fieldbus_check_state(Fieldbus *fieldbus) grp = context->grouplist + fieldbus->group; grp->docheckstate = FALSE; ecx_readstate(context); - for (i = 1; i <= fieldbus->slavecount; ++i) { + for (i = 1; i <= fieldbus->slavecount; ++i) + { slave = context->slavelist + i; - if (slave->group != fieldbus->group) { + if (slave->group != fieldbus->group) + { /* This slave is part of another group: do nothing */ - } else if (slave->state != EC_STATE_OPERATIONAL) { + } + else if (slave->state != EC_STATE_OPERATIONAL) + { grp->docheckstate = TRUE; - if (slave->state == EC_STATE_SAFE_OP + EC_STATE_ERROR) { + if (slave->state == EC_STATE_SAFE_OP + EC_STATE_ERROR) + { printf("* Slave %d is in SAFE_OP+ERROR, attempting ACK\n", i); slave->state = EC_STATE_SAFE_OP + EC_STATE_ACK; ecx_writestate(context, i); - } else if(slave->state == EC_STATE_SAFE_OP) { + } + else if (slave->state == EC_STATE_SAFE_OP) + { printf("* Slave %d is in SAFE_OP, change to OPERATIONAL\n", i); slave->state = EC_STATE_OPERATIONAL; ecx_writestate(context, i); - } else if(slave->state > EC_STATE_NONE) { - if (ecx_reconfig_slave(context, i, EC_TIMEOUTRET)) { + } + else if (slave->state > EC_STATE_NONE) + { + if (ecx_reconfig_slave(context, i, EC_TIMEOUTRET)) + { slave->islost = FALSE; printf("* Slave %d reconfigured\n", i); } - } else if(! slave->islost) { + } + else if (!slave->islost) + { ecx_statecheck(context, i, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (slave->state == EC_STATE_NONE) { + if (slave->state == EC_STATE_NONE) + { slave->islost = TRUE; printf("* Slave %d lost\n", i); } } - } else if (slave->islost) { - if(slave->state != EC_STATE_NONE) { + } + else if (slave->islost) + { + if (slave->state != EC_STATE_NONE) + { slave->islost = FALSE; printf("* Slave %d found\n", i); - } else if (ecx_recover_slave(context, i, EC_TIMEOUTRET)) { + } + else if (ecx_recover_slave(context, i, EC_TIMEOUTRET)) + { slave->islost = FALSE; printf("* Slave %d recovered\n", i); } } } - if (! grp->docheckstate) { + if (!grp->docheckstate) + { printf("All slaves resumed OPERATIONAL\n"); } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { Fieldbus fieldbus; - if (argc != 2) { - ec_adaptert * adapter = NULL; + if (argc != 2) + { + ec_adaptert *adapter = NULL; printf("Usage: simple_ng IFNAME1\n" "IFNAME1 is the NIC interface name, e.g. 'eth0'\n"); @@ -302,18 +331,27 @@ main(int argc, char *argv[]) } fieldbus_initialize(&fieldbus, argv[1]); - if (fieldbus_start(&fieldbus)) { + if (fieldbus_start(&fieldbus)) + { int i, min_time, max_time; min_time = max_time = 0; - for (i = 1; i <= 10000; ++i) { + for (i = 1; i <= 10000; ++i) + { printf("Iteration %4d:", i); - if (! fieldbus_dump(&fieldbus)) { + if (!fieldbus_dump(&fieldbus)) + { fieldbus_check_state(&fieldbus); - } else if (i == 1) { + } + else if (i == 1) + { min_time = max_time = fieldbus.roundtrip_time; - } else if (fieldbus.roundtrip_time < min_time) { + } + else if (fieldbus.roundtrip_time < min_time) + { min_time = fieldbus.roundtrip_time; - } else if (fieldbus.roundtrip_time > max_time) { + } + else if (fieldbus.roundtrip_time > max_time) + { max_time = fieldbus.roundtrip_time; } osal_usleep(5000); From e81f94fb50612b9376acf42ac3ae589f784b9536 Mon Sep 17 00:00:00 2001 From: Bartjan van der Meer Date: Thu, 13 Jun 2024 13:43:52 +0200 Subject: [PATCH 6/6] format osal.c --- osal/macosx/osal.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/osal/macosx/osal.c b/osal/macosx/osal.c index d96e9708..a0345c57 100644 --- a/osal/macosx/osal.c +++ b/osal/macosx/osal.c @@ -10,9 +10,9 @@ #include #include -#define USECS_PER_SEC 1000000 +#define USECS_PER_SEC (1000000) -int osal_usleep (uint32 usec) +int osal_usleep(uint32 usec) { struct timespec ts; ts.tv_sec = usec / USECS_PER_SEC; @@ -25,7 +25,7 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz) { struct timespec ts; int return_value; - (void)tz; /* Not used */ + (void)tz; /* Not used */ /* Use clock_gettime to prevent possible live-lock. * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. @@ -50,17 +50,19 @@ ec_timet osal_current_time(void) void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) { - if (end->usec < start->usec) { + if (end->usec < start->usec) + { diff->sec = end->sec - start->sec - 1; diff->usec = end->usec + 1000000 - start->usec; } - else { + else + { diff->sec = end->sec - start->sec; diff->usec = end->usec - start->usec; } } -void osal_timer_start(osal_timert * self, uint32 timeout_usec) +void osal_timer_start(osal_timert *self, uint32 timeout_usec) { struct timeval start_time; struct timeval timeout; @@ -75,7 +77,7 @@ void osal_timer_start(osal_timert * self, uint32 timeout_usec) self->stop_time.usec = stop_time.tv_usec; } -boolean osal_timer_is_expired (osal_timert * self) +boolean osal_timer_is_expired(osal_timert *self) { struct timeval current_time; struct timeval stop_time; @@ -101,15 +103,15 @@ void osal_free(void *ptr) int osal_thread_create(void *thandle, int stacksize, void *func, void *param) { - int ret; - pthread_attr_t attr; - pthread_t *threadp; + int ret; + pthread_attr_t attr; + pthread_t *threadp; threadp = thandle; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, stacksize); ret = pthread_create(threadp, &attr, func, param); - if(ret < 0) + if (ret < 0) { return 0; } @@ -118,24 +120,24 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param) int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) { - int ret; - pthread_attr_t attr; - struct sched_param schparam; - pthread_t *threadp; + int ret; + pthread_attr_t attr; + struct sched_param schparam; + pthread_t *threadp; threadp = thandle; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, stacksize); ret = pthread_create(threadp, &attr, func, param); pthread_attr_destroy(&attr); - if(ret < 0) + if (ret < 0) { return 0; } memset(&schparam, 0, sizeof(schparam)); schparam.sched_priority = 40; ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); - if(ret < 0) + if (ret < 0) { return 0; }