CANopenNode / CANopenNode

CANopen protocol stack
https://canopennode.github.io/CANopenNode/index.html
Apache License 2.0
1.43k stars 644 forks source link

FOR BIG_ENDIAN architecture CANopenNode stack compilation failing #379

Closed vikas-yadav77 closed 2 years ago

vikas-yadav77 commented 2 years ago

Hi,

I am compiling CANopenNode stack on BIGENDIAN machine where __BYTE_ORDER == __BIG_ENDIAN. During compilation I am getting below error, Do we need to change dataOD to dataTPDO or is there any code part missing in TPDO functionality for BIG_ENDIAN architecture

CANopenNode/301/CO_PDO.c:1269:27: error: ‘dataOD’ undeclared (first use in this function); did you mean ‘dataTPDO’? 1269 | uint8_t *lo = dataOD; | ^~ | dataTPDO CANopenNode/301/CO_PDO.c:1269:27: note: each undeclared identifier is reported only once for each function it appears in make: *** [Makefile:76: CANopenNode/301/CO_PDO.o] Error 1

NebulaDev16 commented 2 years ago

In addition to above question, we have 2 more questions here:

  1. We could not find usage of OD_attributes_t fields "ODA_TSRDO" OR "ODA_RSRDO" in the canOpenNode stack. Can we use them for internal purposes?

  2. We were also referring CANOpen 301 standard for endianness. In Section 7, we found that it expects the numerical data to be transferred at little endian format. Is this understanding correct? Please find screenshot below:

image

@martinwag - quick response is highly appreciated.

martinwag commented 2 years ago

Hi, quick response but I can't really help you there...

  1. I don't know. Seems not to be part of V1.x stack, so I don't have those attributes.
  2. I would read it the same -- numerical data is supposed to be encoded in little endian on the bus. If I remember correctly, V1.x stack has functions to swap those on big endian systems before sending.
NebulaDev16 commented 2 years ago

Thanks for your response.

While exploring on the big-endian data conversion feature, we have one observation around SDO transactions, As we know SDO Packet is formatted as follows: 1st byte - Command Buffer, 2nd& 3rd Byte - Index , 4th Byte - SubIndex, 5-8th Byte - Data

Index always handled in little endian format and data bytes are swapped.

So in below cases , we see that Data Bytes(5-8th Bytes) are also Swapped in case of big endian architecture.

  1. In SDO Segmented transfer, Data Bytes may contain the data size of SDO transfer
  2. In case of failed SDO transactions, Data Bytes will contain the abort code. As Data size and abort code is part of CAN Open Protocol related data, do we really need to swap them ?

@CANopenNode @martinwag - quick response is highly appreciated.

martinwag commented 2 years ago

CANopen defines endianes on bus as little-endian (301-7.1.1). You need to ensure that all values > 1 byte are encoded in that way, otherwise you will have compatibility problems. I did not do any analysis of endianes swapping in CANopenNode as our processor uses little endian anyway. So I don't have any clue if this is done correctly in all the possible places.

CANopenNode commented 2 years ago

I think yes, but please verify correctness of byte order also by observing raw CANopen messages.