Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mctp_uart.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_PMCI_MCTP_MCTP_UART_H_
15#define ZEPHYR_INCLUDE_PMCI_MCTP_MCTP_UART_H_
16
17#include <stdint.h>
18#include <zephyr/kernel.h>
19#include <zephyr/device.h>
20#include <libmctp.h>
21
27 struct mctp_binding binding;
28 const struct device *dev;
29
30 /* receive buffers and state */
31 struct k_sem rx_disabled;
32 uint8_t rx_buf[2][256];
33 bool rx_buf_used[2];
34 struct mctp_pktbuf *rx_pkt;
35 uint8_t rx_exp_len;
36 uint16_t rx_fcs;
37 uint16_t rx_fcs_calc;
38 enum {
39 STATE_WAIT_SYNC_START,
40 STATE_WAIT_REVISION,
41 STATE_WAIT_LEN,
42 STATE_DATA,
43 STATE_DATA_ESCAPED,
44 STATE_WAIT_FCS1,
45 STATE_WAIT_FCS2,
46 STATE_WAIT_SYNC_END,
47 } rx_state;
48 int rx_res;
49
50 /* staging buffer for tx */
51 struct k_sem tx_done;
52 uint8_t tx_buf[256];
53 int tx_res;
54 bool waiting;
55
56 /* Keep track of all UART bindings */
57 sys_snode_t node;
58
59 uint8_t tx_storage[MCTP_PKTBUF_SIZE(MCTP_PACKET_SIZE(MCTP_BTU))] PKTBUF_STORAGE_ALIGN;
60
62};
63
72
86
88int mctp_uart_start(struct mctp_binding *binding);
89int mctp_uart_tx(struct mctp_binding *binding, struct mctp_pktbuf *pkt);
91
98#define MCTP_UART_DT_DEFINE(_name, _dev) \
99 struct mctp_binding_uart _name = { \
100 .binding = \
101 { \
102 .name = STRINGIFY(_name), .version = 1, \
103 .pkt_size = MCTP_PACKET_SIZE(MCTP_BTU), \
104 .pkt_header = 0, .pkt_trailer = 0, \
105 .tx_storage = _name.tx_storage, \
106 .start = mctp_uart_start, .tx = mctp_uart_tx, \
107 }, \
108 .dev = _dev, \
109 .rx_state = STATE_WAIT_SYNC_START, \
110 .rx_pkt = NULL, \
111 .rx_res = 0, \
112 .tx_res = 0, \
113 };
114
115#endif /* ZEPHYR_INCLUDE_PMCI_MCTP_MCTP_UART_H_ */
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
Public kernel APIs.
void mctp_uart_start_rx(struct mctp_binding_uart *uart)
Start the receive of mctp messages.
int mctp_uart_stop_rx(struct mctp_binding_uart *uart)
Stop the receive of mctp messages.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Semaphore structure.
Definition kernel.h:3798
An MCTP binding for Zephyr's asynchronous UART interface.
Definition mctp_uart.h:25