Skip to content

Commit

Permalink
feat(generic): Preliminary support for 64-bit floats
Browse files Browse the repository at this point in the history
To use this, declare a PDO in `ethercat.xml` with
`halType="float-double-ieee"`.

This is currently *completely* untested.  It compiles.  That's all I can
promise.

Issue #115
  • Loading branch information
scottlaird committed Jan 3, 2024
1 parent afaaedb commit baf4e55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/devices/lcec_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int lcec_generic_init(int comp_id, struct lcec_slave *slave, ec_pdo_entry_reg_t

case HAL_FLOAT:
// check data size
if (hal_data->bitLength > 32) {
if ((hal_data->bitLength > 32) && (hal_data->subType != lcecPdoEntTypeFloatDoubleIeee)) {
rtapi_print_msg(RTAPI_MSG_WARN, LCEC_MSG_PFX "unable to export pin %s.%s.%s.%s: invalid process data bitlen!\n", LCEC_MODULE_NAME, master->name, slave->name, hal_data->name);
continue;
}
Expand Down Expand Up @@ -133,6 +133,8 @@ void lcec_generic_read(struct lcec_slave *slave, long period) {
fval = lcec_generic_read_u32(pd, hal_data);
} else if(hal_data->subType == lcecPdoEntTypeFloatIeee){
fval = EC_READ_REAL(&pd[hal_data->pdo_os]);
} else if(hal_data->subType == lcecPdoEntTypeFloatDoubleIeee){
fval = EC_READ_LREAL(&pd[hal_data->pdo_os]);
} else {
fval = lcec_generic_read_s32(pd, hal_data);
}
Expand Down Expand Up @@ -187,6 +189,8 @@ void lcec_generic_write(struct lcec_slave *slave, long period) {
lcec_generic_write_u32(pd, hal_data, (hal_u32_t) fval);
} else if(hal_data->subType == lcecPdoEntTypeFloatIeee){
EC_WRITE_REAL(&pd[hal_data->pdo_os], fval);
} else if(hal_data->subType == lcecPdoEntTypeFloatDoubleIeee){
EC_WRITE_LREAL(&pd[hal_data->pdo_os], fval);
} else {
lcec_generic_write_s32(pd, hal_data, (hal_s32_t) fval);
}
Expand Down
12 changes: 11 additions & 1 deletion src/lcec_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ static void parsePdoEntryAttrs(LCEC_CONF_XML_INST_T *inst, int next, const char
p->subType = lcecPdoEntTypeSimple;
p->halType = HAL_U32;
continue;
}
}
if (strcasecmp(val, "float") == 0) {
p->subType = lcecPdoEntTypeFloatSigned;
p->halType = HAL_FLOAT;
Expand All @@ -960,6 +960,11 @@ static void parsePdoEntryAttrs(LCEC_CONF_XML_INST_T *inst, int next, const char
p->halType = HAL_FLOAT;
continue;
}
if (strcasecmp(val, "float-double-ieee") == 0) {
p->subType = lcecPdoEntTypeFloatDoubleIeee;
p->halType = HAL_FLOAT;
continue;
}
fprintf(stderr, "%s: ERROR: Invalid pdoEntry halType %s\n", modname, val);
XML_StopParser(inst->parser, 0);
return;
Expand Down Expand Up @@ -1103,6 +1108,11 @@ static void parseComplexEntryAttrs(LCEC_CONF_XML_INST_T *inst, int next, const c
p->halType = HAL_FLOAT;
continue;
}
if (strcasecmp(val, "float-double-ieee") == 0) {
p->subType = lcecPdoEntTypeFloatDoubleIeee;
p->halType = HAL_FLOAT;
continue;
}
fprintf(stderr, "%s: ERROR: Invalid complexEntry halType %s\n", modname, val);
XML_StopParser(inst->parser, 0);
return;
Expand Down
3 changes: 2 additions & 1 deletion src/lcec_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ typedef enum {
lcecPdoEntTypeFloatSigned,
lcecPdoEntTypeFloatUnsigned,
lcecPdoEntTypeComplex,
lcecPdoEntTypeFloatIeee
lcecPdoEntTypeFloatIeee,
lcecPdoEntTypeFloatDoubleIeee,
} LCEC_PDOENT_TYPE_T;

typedef struct {
Expand Down

0 comments on commit baf4e55

Please sign in to comment.