Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

congnguyenhuu
Copy link
Collaborator

@congnguyenhuu congnguyenhuu commented Oct 15, 2024

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

@congnguyenhuu congnguyenhuu changed the title Nxp S32 introduce support psi5 NXP S32 introduce support PSI5 Oct 15, 2024
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch from 0ee0652 to b50ef76 Compare October 15, 2024 06:00
@zephyrbot
Copy link
Collaborator

zephyrbot commented Oct 15, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_nxp zephyrproject-rtos/hal_nxp@fc8aa27 zephyrproject-rtos/hal_nxp@7a52cbb (master) zephyrproject-rtos/[email protected]

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-hal_nxp DNM This PR should not be merged (Do Not Merge) labels Oct 15, 2024
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch 2 times, most recently from acc9b3e to 5a072e9 Compare October 24, 2024 07:20
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch 3 times, most recently from 101fad8 to dfebc33 Compare November 1, 2024 02:41
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch from dfebc33 to 69e051a Compare November 22, 2024 10:27
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch 3 times, most recently from 402551c to 9a0367b Compare December 5, 2024 07:52
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch 3 times, most recently from 4ce3d57 to eca2db8 Compare December 12, 2024 07:58
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch 4 times, most recently from 147bb43 to 05f2644 Compare January 10, 2025 09:43
@congnguyenhuu congnguyenhuu marked this pull request as ready for review January 15, 2025 03:15
@congnguyenhuu
Copy link
Collaborator Author

Addressed review comments from Kartben in SENT PR

@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch from 5d094e2 to 285c5ba Compare June 26, 2025 16:13
Dat-NguyenDuy
Dat-NguyenDuy previously approved these changes Jun 27, 2025
manuargue
manuargue previously approved these changes Jun 27, 2025
@congnguyenhuu congnguyenhuu dismissed stale reviews from manuargue and Dat-NguyenDuy via dfcc275 June 27, 2025 05:40
@congnguyenhuu congnguyenhuu force-pushed the nxp-s32-introduce-support-psi5 branch from 285c5ba to dfcc275 Compare June 27, 2025 05:40
Dat-NguyenDuy
Dat-NguyenDuy previously approved these changes Jun 27, 2025
manuargue
manuargue previously approved these changes Jun 27, 2025
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]>
@github-actions github-actions bot removed the DNM (manifest) This PR should not be merged (controlled by action-manifest) label Jun 27, 2025
Copy link

/** Serial message data */
uint16_t data;
} serial;
};
Copy link
Collaborator

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.

Copy link
Member

@dleach02 dleach02 Jun 27, 2025

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.

Copy link
Collaborator

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

Copy link
Member

@manuargue manuargue Jun 28, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.