-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: Add mctp host and client samples
Samples work by sending MCTP encoded messages over a uart between two boards. Signed-off-by: Tom Burdick <[email protected]>
- Loading branch information
Showing
17 changed files
with
505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Note: The list of ForEachMacros can be obtained using: | ||
# | ||
# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \ | ||
# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \ | ||
# | sort | uniq | ||
# | ||
# References: | ||
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
|
||
--- | ||
BasedOnStyle: LLVM | ||
AlignConsecutiveMacros: AcrossComments | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortEnumsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AttributeMacros: | ||
- __aligned | ||
- __deprecated | ||
- __packed | ||
- __printf_like | ||
- __syscall | ||
- __syscall_always_inline | ||
- __subsystem | ||
BitFieldColonSpacing: After | ||
BreakBeforeBraces: Linux | ||
ColumnLimit: 100 | ||
ConstructorInitializerIndentWidth: 8 | ||
ContinuationIndentWidth: 8 | ||
ForEachMacros: | ||
- 'FOR_EACH' | ||
- 'FOR_EACH_FIXED_ARG' | ||
- 'FOR_EACH_IDX' | ||
- 'FOR_EACH_IDX_FIXED_ARG' | ||
- 'FOR_EACH_NONEMPTY_TERM' | ||
- 'RB_FOR_EACH' | ||
- 'RB_FOR_EACH_CONTAINER' | ||
- 'SYS_DLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_DLIST_FOR_EACH_NODE' | ||
- 'SYS_DLIST_FOR_EACH_NODE_SAFE' | ||
- 'SYS_SFLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_SFLIST_FOR_EACH_NODE' | ||
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE' | ||
- 'SYS_SLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_SLIST_FOR_EACH_NODE' | ||
- 'SYS_SLIST_FOR_EACH_NODE_SAFE' | ||
- '_WAIT_Q_FOR_EACH' | ||
- 'Z_FOR_EACH' | ||
- 'Z_FOR_EACH_ENGINE' | ||
- 'Z_FOR_EACH_EXEC' | ||
- 'Z_FOR_EACH_FIXED_ARG' | ||
- 'Z_FOR_EACH_FIXED_ARG_EXEC' | ||
- 'Z_FOR_EACH_IDX' | ||
- 'Z_FOR_EACH_IDX_EXEC' | ||
- 'Z_FOR_EACH_IDX_FIXED_ARG' | ||
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC' | ||
- 'Z_GENLIST_FOR_EACH_CONTAINER' | ||
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'Z_GENLIST_FOR_EACH_NODE' | ||
- 'Z_GENLIST_FOR_EACH_NODE_SAFE' | ||
- 'STRUCT_SECTION_FOREACH' | ||
- 'TYPE_SECTION_FOREACH' | ||
- 'K_SPINLOCK' | ||
IfMacros: | ||
- 'CHECKIF' | ||
# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520 | ||
#IncludeBlocks: Regroup | ||
IncludeCategories: | ||
- Regex: '^".*\.h"$' | ||
Priority: 0 | ||
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$' | ||
Priority: 1 | ||
- Regex: '^\<zephyr/.*\.h\>$' | ||
Priority: 2 | ||
- Regex: '.*' | ||
Priority: 3 | ||
IndentCaseLabels: false | ||
IndentWidth: 8 | ||
InsertBraces: true | ||
SpaceBeforeParens: ControlStatementsExceptControlMacros | ||
SortIncludes: Never | ||
UseTab: ForContinuationAndIndentation | ||
WhitespaceSensitiveMacros: | ||
- STRINGIFY | ||
- Z_STRINGIFY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
|
||
project(i2c_peripheral) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/ { | ||
aliases { | ||
i2c-target = &arduino_i2c; | ||
}; | ||
}; |
5 changes: 5 additions & 0 deletions
5
samples/modules/mctp/mctp_endpoint/boards/mimxrt1010_evk.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/ { | ||
aliases { | ||
i2c-target = &arduino_i2c; | ||
}; | ||
}; |
10 changes: 10 additions & 0 deletions
10
samples/modules/mctp/mctp_endpoint/boards/mimxrt1060_evk.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/ { | ||
aliases { | ||
i2c-target = &arduino_i2c; | ||
}; | ||
}; | ||
|
||
&arduino_serial { | ||
status = "okay"; | ||
current-speed = <115200>; | ||
}; |
5 changes: 5 additions & 0 deletions
5
samples/modules/mctp/mctp_endpoint/boards/nucleo_f446re.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/ { | ||
aliases { | ||
i2c-target = &arduino_i2c; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CONFIG_SERIAL=y | ||
CONFIG_PICOLIBC=y | ||
CONFIG_MCTP=y | ||
CONFIG_LOG=y | ||
CONFIG_LOG_MODE_IMMEDIATE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <assert.h> | ||
#include <unistd.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/types.h> | ||
#include <libmctp.h> | ||
#include <libmctp-serial.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(mctp_endpoint); | ||
|
||
#include <zephyr/drivers/uart.h> | ||
|
||
static struct mctp_binding_serial *serial; | ||
static struct mctp *mctp_ctx; | ||
|
||
#define LOCAL_HELLO_EID 10 | ||
|
||
#define REMOTE_HELLO_EID 20 | ||
|
||
static int mctp_uart_poll_out(void *data, void *buf, size_t len) | ||
{ | ||
const struct device *uart = data; | ||
|
||
for (size_t i = 0; i < len; i++) { | ||
uart_poll_out(uart, ((uint8_t *)buf)[i]); | ||
} | ||
|
||
return (int)len; | ||
} | ||
|
||
static void rx_message(uint8_t eid, bool tag_owner, | ||
uint8_t msg_tag, void *data, void *msg, | ||
size_t len) | ||
{ | ||
switch (eid) { | ||
case REMOTE_HELLO_EID: | ||
LOG_INF("got mctp message %s for eid %d, replying to 5 with \"world\"", | ||
(char *)msg, eid); | ||
mctp_message_tx(mctp_ctx, LOCAL_HELLO_EID, false, 0, "world", sizeof("world")); | ||
break; | ||
default: | ||
LOG_INF("Unknown endpoint %d", eid); | ||
break; | ||
} | ||
} | ||
|
||
const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(arduino_serial)); | ||
|
||
#define RX_BUF_SZ 128 | ||
|
||
int main(void) | ||
{ | ||
LOG_INF("MCTP Endpoint %d on %s\n", LOCAL_HELLO_EID, CONFIG_BOARD_TARGET); | ||
int rc = 0; | ||
uint8_t rx_buf[RX_BUF_SZ]; | ||
|
||
mctp_ctx = mctp_init(); | ||
assert(mctp_ctx != NULL); | ||
|
||
serial = mctp_serial_init(); | ||
assert(serial); | ||
|
||
mctp_serial_set_tx_fn(serial, mctp_uart_poll_out, (void *)uart); | ||
|
||
mctp_register_bus(mctp_ctx, mctp_binding_serial_core(serial), LOCAL_HELLO_EID); | ||
|
||
mctp_set_rx_all(mctp_ctx, rx_message, NULL); | ||
|
||
/* MCTP poll loop */ | ||
while (true) { | ||
int i; | ||
|
||
for (i = 0; i < RX_BUF_SZ; i++) { | ||
rc = uart_poll_in(uart, &rx_buf[i]); | ||
if (rc != 0) { | ||
break; | ||
} | ||
} | ||
|
||
mctp_serial_rx(serial, rx_buf, i); | ||
k_yield(); | ||
} | ||
|
||
LOG_INF("exiting"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Note: The list of ForEachMacros can be obtained using: | ||
# | ||
# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \ | ||
# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \ | ||
# | sort | uniq | ||
# | ||
# References: | ||
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
|
||
--- | ||
BasedOnStyle: LLVM | ||
AlignConsecutiveMacros: AcrossComments | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortEnumsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AttributeMacros: | ||
- __aligned | ||
- __deprecated | ||
- __packed | ||
- __printf_like | ||
- __syscall | ||
- __syscall_always_inline | ||
- __subsystem | ||
BitFieldColonSpacing: After | ||
BreakBeforeBraces: Linux | ||
ColumnLimit: 100 | ||
ConstructorInitializerIndentWidth: 8 | ||
ContinuationIndentWidth: 8 | ||
ForEachMacros: | ||
- 'FOR_EACH' | ||
- 'FOR_EACH_FIXED_ARG' | ||
- 'FOR_EACH_IDX' | ||
- 'FOR_EACH_IDX_FIXED_ARG' | ||
- 'FOR_EACH_NONEMPTY_TERM' | ||
- 'RB_FOR_EACH' | ||
- 'RB_FOR_EACH_CONTAINER' | ||
- 'SYS_DLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_DLIST_FOR_EACH_NODE' | ||
- 'SYS_DLIST_FOR_EACH_NODE_SAFE' | ||
- 'SYS_SFLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_SFLIST_FOR_EACH_NODE' | ||
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE' | ||
- 'SYS_SLIST_FOR_EACH_CONTAINER' | ||
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'SYS_SLIST_FOR_EACH_NODE' | ||
- 'SYS_SLIST_FOR_EACH_NODE_SAFE' | ||
- '_WAIT_Q_FOR_EACH' | ||
- 'Z_FOR_EACH' | ||
- 'Z_FOR_EACH_ENGINE' | ||
- 'Z_FOR_EACH_EXEC' | ||
- 'Z_FOR_EACH_FIXED_ARG' | ||
- 'Z_FOR_EACH_FIXED_ARG_EXEC' | ||
- 'Z_FOR_EACH_IDX' | ||
- 'Z_FOR_EACH_IDX_EXEC' | ||
- 'Z_FOR_EACH_IDX_FIXED_ARG' | ||
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC' | ||
- 'Z_GENLIST_FOR_EACH_CONTAINER' | ||
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE' | ||
- 'Z_GENLIST_FOR_EACH_NODE' | ||
- 'Z_GENLIST_FOR_EACH_NODE_SAFE' | ||
- 'STRUCT_SECTION_FOREACH' | ||
- 'TYPE_SECTION_FOREACH' | ||
- 'K_SPINLOCK' | ||
IfMacros: | ||
- 'CHECKIF' | ||
# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520 | ||
#IncludeBlocks: Regroup | ||
IncludeCategories: | ||
- Regex: '^".*\.h"$' | ||
Priority: 0 | ||
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$' | ||
Priority: 1 | ||
- Regex: '^\<zephyr/.*\.h\>$' | ||
Priority: 2 | ||
- Regex: '.*' | ||
Priority: 3 | ||
IndentCaseLabels: false | ||
IndentWidth: 8 | ||
InsertBraces: true | ||
SpaceBeforeParens: ControlStatementsExceptControlMacros | ||
SortIncludes: Never | ||
UseTab: ForContinuationAndIndentation | ||
WhitespaceSensitiveMacros: | ||
- STRINGIFY | ||
- Z_STRINGIFY |
Oops, something went wrong.