Skip to content

Commit

Permalink
Wideregistersupport (#6)
Browse files Browse the repository at this point in the history
* fixes for multiple pdos of same data direction and for undeclared IO variables in PLC program

* wide register support, 32, 64bit

---------

Authored-by: r2k
  • Loading branch information
r2k-in-the-vortex authored Dec 7, 2023
1 parent ee50087 commit d1586a6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
30 changes: 25 additions & 5 deletions src/ecat_handler/ecat_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,9 @@ int NameTypeAndPrefix(PdoRegistryEntry *pdo, char *name, char *prefix, char *dty
} else if (pdo->bitlength == 32){
strcpy(dtype, "DINT");
strcpy(prefix, "D");
log_error("Bitlen %i not implemented and not supported", pdo->bitlength);
return -1;
} else if (pdo->bitlength == 64){
strcpy(dtype, "LINT");
strcpy(prefix, "L");
log_error("Bitlen %i not implemented and not supported", pdo->bitlength);
return -1;
} else{
log_error("Bitlen %i not implemented and not supported", pdo->bitlength);
return -1;
Expand Down Expand Up @@ -511,7 +507,11 @@ int EtherCATcyclic(int buffersize,
int8var_call_back byte_input,
int8var_call_back byte_output,
int16var_call_back word_input,
int16var_call_back word_output){
int16var_call_back word_output,
int32var_call_back dword_input,
int32var_call_back dword_output,
int64var_call_back lword_input,
int64var_call_back lword_output){

if(!config_done)return 0;
if(!msgonce){
Expand Down Expand Up @@ -579,6 +579,16 @@ int EtherCATcyclic(int buffersize,
if(!config->config_only_flag && ptr){
*ptr = EC_READ_U16(domain1_pd + pdo.offset);
}
} else if(pdo.bitlength == 32){
uint32_t *ptr = dword_input(i);
if(!config->config_only_flag && ptr){
*ptr = EC_READ_U32(domain1_pd + pdo.offset);
}
} else if(pdo.bitlength == 64){
uint64_t *ptr = lword_input(i);
if(!config->config_only_flag && ptr){
*ptr = EC_READ_U64(domain1_pd + pdo.offset);
}
}
}

Expand All @@ -604,6 +614,16 @@ int EtherCATcyclic(int buffersize,
if(!config->config_only_flag && ptrout){
EC_WRITE_U16(domain1_pd + pdo.offset, *ptrout);
}
} else if(pdo.bitlength == 32){
uint32_t *ptrout = dword_output(i);
if(!config->config_only_flag && ptrout){
EC_WRITE_U32(domain1_pd + pdo.offset, *ptrout);
}
} else if(pdo.bitlength == 64){
uint64_t *ptrout = lword_output(i);
if(!config->config_only_flag && ptrout){
EC_WRITE_U64(domain1_pd + pdo.offset, *ptrout);
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/ecat_handler/ecat_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ extern "C"{
typedef u_int8_t *(*boolvar_call_back) (int, int);
typedef u_int8_t *(*int8var_call_back) (int);
typedef u_int16_t *(*int16var_call_back) (int);
typedef u_int32_t *(*int32var_call_back) (int);
typedef u_int64_t *(*int64var_call_back) (int);
typedef int logger_callback(char*);


Expand All @@ -117,7 +119,11 @@ int EtherCATcyclic(int buffersize,
int8var_call_back byte_input,
int8var_call_back byte_output,
int16var_call_back word_input,
int16var_call_back word_output);
int16var_call_back word_output,
int32var_call_back dword_input,
int32var_call_back dword_output,
int64var_call_back lword_input,
int64var_call_back lword_output);

void terminate_handler();

Expand Down
18 changes: 11 additions & 7 deletions src/ethercat_src.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ int ethercat_configure(char *paramsfile, type_logger_callback logfptr){
}

int ethercat_callcyclic(int buffersize,
boolvar_call_back bool_input,
boolvar_call_back bool_output,
int8var_call_back byte_input,
int8var_call_back byte_output,
int16var_call_back word_input,
int16var_call_back word_output){
return EtherCATcyclic(buffersize, bool_input, bool_output, byte_input, byte_output, word_input, word_output);
boolvar_call_back bool_input,
boolvar_call_back bool_output,
int8var_call_back byte_input,
int8var_call_back byte_output,
int16var_call_back word_input,
int16var_call_back word_output,
int32var_call_back dword_input,
int32var_call_back dword_output,
int64var_call_back lword_input,
int64var_call_back lword_output){
return EtherCATcyclic(buffersize, bool_input, bool_output, byte_input, byte_output, word_input, word_output, dword_input, dword_output, lword_input, lword_output);
}

int ethercat_read_sdo(){
Expand Down
8 changes: 7 additions & 1 deletion src/ethercat_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extern "C"{
typedef u_int8_t *(*boolvar_call_back) (int, int);
typedef u_int8_t *(*int8var_call_back) (int);
typedef u_int16_t *(*int16var_call_back) (int);
typedef u_int32_t *(*int32var_call_back) (int);
typedef u_int64_t *(*int64var_call_back) (int);
typedef void (*type_logger_callback) (unsigned char*);

// Setup before realtime
Expand All @@ -19,7 +21,11 @@ int ethercat_callcyclic(int buffersize,
int8var_call_back byte_input,
int8var_call_back byte_output,
int16var_call_back word_input,
int16var_call_back word_output);
int16var_call_back word_output,
int32var_call_back dword_input,
int32var_call_back dword_output,
int64var_call_back lword_input,
int64var_call_back lword_output);

// CoE access
int ethercat_read_sdo();
Expand Down
16 changes: 15 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@

uint8_t shortvar = 0;
uint16_t longvar = 0;
uint32_t dwordvar = 0;
uint64_t lwordvar = 0;
uint8_t *bool_input_call_back(int a, int b){ return &shortvar; }
uint8_t *bool_output_call_back(int a, int b){ return &shortvar; }
uint8_t *byte_input_call_back(int a){ return &shortvar; }
uint8_t *byte_output_call_back(int a){ return &shortvar; }
uint16_t *int_input_call_back(int a){ return &longvar; }
uint16_t *int_output_call_back(int a){ return &longvar; }
uint32_t *dint_input_call_back(int a){ return &dwordvar; }
uint32_t *dint_output_call_back(int a){ return &dwordvar; }
uint64_t *lint_input_call_back(int a){ return &lwordvar; }
uint64_t *lint_output_call_back(int a){ return &lwordvar; }
void logger_callbackf(unsigned char *msg){ printf("PLC log: %s", msg); }

//-----------------------------------------------------------------------------
Expand All @@ -58,6 +64,10 @@ int main (int argc, char **argv){
int8var_call_back byte_output_callback = byte_output_call_back;
int16var_call_back int_input_callback = int_input_call_back;
int16var_call_back int_output_callback = int_output_call_back;
int32var_call_back dint_input_callback = dint_input_call_back;
int32var_call_back dint_output_callback = dint_output_call_back;
int64var_call_back lint_input_callback = lint_input_call_back;
int64var_call_back lint_output_callback = lint_output_call_back;

for (int i = 0; i < 100; i++){
ethercat_callcyclic(BUFFER_SIZE,
Expand All @@ -66,7 +76,11 @@ int main (int argc, char **argv){
byte_input_callback,
byte_output_callback,
int_input_callback,
int_output_callback);
int_output_callback,
dint_input_callback,
dint_output_callback,
lint_input_callback,
lint_output_callback);

sleepms(100);
}
Expand Down

0 comments on commit d1586a6

Please sign in to comment.