-
Notifications
You must be signed in to change notification settings - Fork 7.6k
NXP S32 introduce support PSI5 #79824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NXP S32 introduce support PSI5 #79824
Conversation
0ee0652
to
b50ef76
Compare
The following west manifest projects have changed revision in this Pull Request:
✅ All manifest checks OK Note: This message is automatically posted and updated by the Manifest GitHub Action. |
acc9b3e
to
5a072e9
Compare
101fad8
to
dfebc33
Compare
dfebc33
to
69e051a
Compare
402551c
to
9a0367b
Compare
4ce3d57
to
eca2db8
Compare
147bb43
to
05f2644
Compare
b63a915
to
5d094e2
Compare
Addressed review comments from Kartben in SENT PR |
5d094e2
to
285c5ba
Compare
dfcc275
285c5ba
to
dfcc275
Compare
This driver allows to communication (send, receive) with PSI5 device Signed-off-by: Cong Nguyen Huu <[email protected]>
enable support psi5 Signed-off-by: Cong Nguyen Huu <[email protected]>
Create test, sample for psi5 driver Signed-off-by: Cong Nguyen Huu <[email protected]>
9b18b84
dfcc275
to
9b18b84
Compare
|
/** Serial message data */ | ||
uint16_t data; | ||
} serial; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@congnguyenhuu and @mmahadevan108 and @dleach02 I'm a little concerned on this struct. The union type is 32-bit value, yet the serial
struct is only 24-bits in size. The union will promise a minimum of 32-bits, but when accessing the serial
struct I believe this is going to end up with some undefined behavior and padding. Are you sure this is what you want?
It's easily fixed with something like:
struct {
/** Serial message ID */
uint8_t id;
/** Serial message data */
uint16_t data;
uint8_t rsvd;
} serial;
Otherwise, the compiler may add the padding where the cacheline is, and it's likely between the id
and the data
type. Additionally because it falls within the uint32_t
reading beyond uint16_t data
type (because the name collides with the uint32_t version) won't trigger asan or ubsan for the memory overflow. Again just checking that you really want to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkalowsk This might vary between architectures but this is talking to an on-chip IP block so different architectures is not an issue. But I generally agree though that the sub structure should put the uint8 rsvd field where it explicitly expects it in the byte stream. It could be before the id, between the id & data, or after as you suggested.
But having said that, as implemented, it works with the underlying hardware so the alignment likely meets the expectations of the HAL functions and the IP on chip. We would like to get this merged within the scope of the merge window because it also involved a HAL update that has been merged which complicates things. The risk/exposure to the rest of Zephyr is zero since this is the first introduction of a driver framework for this IP and as such, only exposes the NXP S32 parts.
If we determine there is a bug here, we can patch it after the feature freeze.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dleach02 I understand your concern and desire to get this merged. And you call out the alternate case I am concerned about.
struct {
/** Serial message ID */
uint8_t id;
/** Serial message data */
uint16_t data;
+ uint8_t rsvd;
} serial;
and
struct {
/** Serial message ID */
uint8_t id;
+ uint8_t rsvd;
/** Serial message data */
uint16_t data;
} serial;
both have different meanings and support/output. I'm not sure I follow the argument that this is an IP block only so it's correct. The compiler will still need to provide the data structure implementation to be used. Running this through CompilerExplorer in a simplified example shows my concern as the second is the case being generated: https://gcc.godbolt.org/z/Prb9b1bjn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serial
and data
represent mutually exclusive frame formats, meaning the union is used to hold either a serial frame or a data frame, and they are never meant to be read or written together. So assuming that the consumer follow the intended use, there won't be undefined behaviors due to padding, neither aliasing risks.
That said, I noticed this hasn't been properly documented so it opens possibility of misuse. Additionally, using a tagged union could improve code clarity without sacrificing compactness or requiring to model each frame type as a complete separate struct. For example:
struct psi5_frame {
enum psi5_frame_type type;
union {
struct {
uint32_t payload;
} data; /* access this when .type is PSI5_DATA_FRAME */
struct {
uint8_t id;
uint16_t payload;
} serial; /* access this when .type is PSI5_SERIAL_FRAME_4_BIT_ID or PSI5_SERIAL_FRAME_8_BIT_ID */
};
uint32_t timestamp;
uint8_t crc;
uint8_t slot_number;
};
As a side note, the naming chosen for "data" and "serial" frames is a bit misleading, given that both frame types carry data, except that the former is transmitted periodically (sensor measurements) and the latter is assembled over multiple frames (sensor diagnostics and metadata). I would suggest this to be addressed as well.
Introduce support Peripheral Sensor Interface (PSI5) driver on S32Z. This driver allows to communication (send, receive) with PSI5 device.
The test result: PSI5-TESTING-RESULT.pptx
RFC: #83982