|
| 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_node) |
| 15 | +#define PSI5_CHANNEL 1 |
| 16 | + |
| 17 | +void tx_cb(const struct device *dev, uint8_t channel_id, enum psi5_status status, void *user_data) |
| 18 | +{ |
| 19 | + LOG_INF("Transmitted data on channel %d", channel_id); |
| 20 | +} |
| 21 | + |
| 22 | +void rx_serial_frame_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame, |
| 23 | + enum psi5_status status, void *user_data) |
| 24 | +{ |
| 25 | + |
| 26 | + if (status == PSI5_RX_SERIAL_FRAME) { |
| 27 | + LOG_INF("Received a frame on channel %d, " |
| 28 | + "id: %d, data: %d, timestamp: %d, slot: %d", |
| 29 | + channel_id, frame->serial.id, frame->serial.data, frame->timestamp, |
| 30 | + frame->slot_number); |
| 31 | + } else { |
| 32 | + LOG_INF("Error received on channel %d", channel_id); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +void rx_data_frame_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame, |
| 37 | + enum psi5_status status, void *user_data) |
| 38 | +{ |
| 39 | + |
| 40 | + if (status == PSI5_RX_DATA_FRAME) { |
| 41 | + LOG_INF("Received a frame on channel %d, " |
| 42 | + "data: %d, timestamp: %d", |
| 43 | + channel_id, frame->data, frame->timestamp); |
| 44 | + } else { |
| 45 | + LOG_INF("Error received on channel %d", channel_id); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +int main(void) |
| 50 | +{ |
| 51 | + const struct device *const dev = DEVICE_DT_GET(PSI5_NODE); |
| 52 | + uint64_t send_data = 0x1234; |
| 53 | + |
| 54 | + psi5_add_rx_callback(dev, PSI5_CHANNEL, rx_serial_frame_cb, rx_data_frame_cb, NULL); |
| 55 | + |
| 56 | + psi5_start_sync(dev, PSI5_CHANNEL); |
| 57 | + |
| 58 | + psi5_send(dev, PSI5_CHANNEL, send_data, K_MSEC(100), tx_cb, NULL); |
| 59 | + |
| 60 | + while (true) { |
| 61 | + /* To transmit and receive data */ |
| 62 | + } |
| 63 | + |
| 64 | + return 0; |
| 65 | +} |
0 commit comments