1 /*
2  * Copyright 2025 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(psi5_sample, LOG_LEVEL_DBG);
9 
10 #include <zephyr/kernel.h>
11 
12 #include <zephyr/drivers/psi5/psi5.h>
13 
14 #define PSI5_NODE          DT_ALIAS(psi5_0)
15 #define PSI5_CHANNEL       1
16 #define PSI5_MAX_RX_BUFFER 1
17 
18 struct psi5_frame serial_frame[PSI5_MAX_RX_BUFFER];
19 
20 struct psi5_frame data_frame[PSI5_MAX_RX_BUFFER];
21 
tx_cb(const struct device * dev,uint8_t channel_id,int status,void * user_data)22 void tx_cb(const struct device *dev, uint8_t channel_id, int status, void *user_data)
23 {
24 	LOG_INF("Transmitted data on channel %d", channel_id);
25 }
26 
rx_serial_frame_cb(const struct device * dev,uint8_t channel_id,uint32_t num_frame,void * user_data)27 void rx_serial_frame_cb(const struct device *dev, uint8_t channel_id, uint32_t num_frame,
28 			void *user_data)
29 {
30 
31 	if (num_frame == PSI5_MAX_RX_BUFFER) {
32 		LOG_INF("Received a frame on channel %d, "
33 			"id: %d, data: 0x%X, timestamp: 0x%X, slot: %d",
34 			channel_id, serial_frame->serial.id, serial_frame->serial.data,
35 			serial_frame->timestamp, serial_frame->slot_number);
36 	} else {
37 		LOG_INF("Error received on channel %d", channel_id);
38 	}
39 }
40 
rx_data_frame_cb(const struct device * dev,uint8_t channel_id,uint32_t num_frame,void * user_data)41 void rx_data_frame_cb(const struct device *dev, uint8_t channel_id, uint32_t num_frame,
42 		      void *user_data)
43 {
44 
45 	if (num_frame == PSI5_MAX_RX_BUFFER) {
46 		LOG_INF("Received a frame on channel %d, "
47 			"data: 0x%X, timestamp: 0x%X",
48 			channel_id, data_frame->data, data_frame->timestamp);
49 	} else {
50 		LOG_INF("Error received on channel %d", channel_id);
51 	}
52 }
53 
54 struct psi5_rx_callback_config serial_cb_cfg = {
55 	.callback = rx_serial_frame_cb,
56 	.frame = &serial_frame[0],
57 	.max_num_frame = PSI5_MAX_RX_BUFFER,
58 	.user_data = NULL,
59 };
60 
61 struct psi5_rx_callback_config data_cb_cfg = {
62 	.callback = rx_data_frame_cb,
63 	.frame = &data_frame[0],
64 	.max_num_frame = PSI5_MAX_RX_BUFFER,
65 	.user_data = NULL,
66 };
67 
68 struct psi5_rx_callback_configs callback_configs = {
69 	.serial_frame = &serial_cb_cfg,
70 	.data_frame = &data_cb_cfg,
71 };
72 
main(void)73 int main(void)
74 {
75 	const struct device *const dev = DEVICE_DT_GET(PSI5_NODE);
76 	uint64_t send_data = 0x1234;
77 
78 	psi5_register_callback(dev, PSI5_CHANNEL, callback_configs);
79 
80 	psi5_start_sync(dev, PSI5_CHANNEL);
81 
82 	psi5_send(dev, PSI5_CHANNEL, send_data, K_MSEC(100), tx_cb, NULL);
83 
84 	while (true) {
85 		/* To transmit and receive data */
86 	}
87 
88 	return 0;
89 }
90