1 /*
2  * Copyright (c) 2025 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <assert.h>
10 #include <unistd.h>
11 #include <zephyr/types.h>
12 #include <zephyr/kernel.h>
13 #include <libmctp.h>
14 #include <zephyr/pmci/mctp/mctp_i2c_gpio_controller.h>
15 
16 #include <zephyr/logging/log.h>
17 LOG_MODULE_REGISTER(mctp_i2c_gpio_bus_owner);
18 
19 #define LOCAL_EID 20
20 
21 MCTP_I2C_GPIO_CONTROLLER_DT_DEFINE(mctp_i2c_ctrl, DT_NODELABEL(mctp_i2c));
22 
rx_message(uint8_t eid,bool tag_owner,uint8_t msg_tag,void * data,void * msg,size_t len)23 static void rx_message(uint8_t eid, bool tag_owner, uint8_t msg_tag, void *data, void *msg,
24 		       size_t len)
25 {
26 	LOG_INF("received message %s from endpoint %d to %d, msg_tag %d, len %zu", (char *)msg, eid,
27 		LOCAL_EID, msg_tag, len);
28 }
29 
main(void)30 int main(void)
31 {
32 	int rc;
33 	struct mctp *mctp_ctx;
34 
35 	LOG_INF("MCTP Host EID:%d on %s\n", LOCAL_EID, CONFIG_BOARD_TARGET);
36 
37 	mctp_ctx = mctp_init();
38 	__ASSERT_NO_MSG(mctp_ctx != NULL);
39 	mctp_register_bus(mctp_ctx, &mctp_i2c_ctrl.binding, LOCAL_EID);
40 	mctp_set_rx_all(mctp_ctx, rx_message, NULL);
41 
42 	while (true) {
43 		for (int i = 0; i < mctp_i2c_ctrl.num_endpoints; i++) {
44 
45 			LOG_INF("sending message \"ping\" to endpoint %d",
46 				mctp_i2c_ctrl.endpoint_ids[i]);
47 			rc = mctp_message_tx(mctp_ctx, mctp_i2c_ctrl.endpoint_ids[i], false,
48 					0, "ping", sizeof("ping"));
49 			if (rc != 0) {
50 				LOG_WRN("Failed to send message \"ping\" to endpoint %d,"
51 					" errno %d\n", mctp_i2c_ctrl.endpoint_ids[i], rc);
52 			}
53 
54 			k_msleep(500);
55 		}
56 	}
57 
58 	return 0;
59 }
60