Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec_host_cmd: introduce Host Command state #69560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ enum ec_host_cmd_log_level {
EC_HOST_CMD_DEBUG_MODES /* Number of host command debug modes */
};

enum ec_host_cmd_state {
EC_HOST_CMD_STATE_DISABLED = 0,
EC_HOST_CMD_STATE_RECEIVING,
EC_HOST_CMD_STATE_PROCESSING,
EC_HOST_CMD_STATE_SENDING,
};

typedef void (*ec_host_cmd_user_cb_t)(const struct ec_host_cmd_rx_ctx *rx_ctx, void *user_data);
typedef enum ec_host_cmd_status (*ec_host_cmd_in_progress_cb_t)(void *user_data);

Expand All @@ -98,6 +105,7 @@ struct ec_host_cmd {
*/
ec_host_cmd_user_cb_t user_cb;
void *user_data;
enum ec_host_cmd_state state;
#ifdef CONFIG_EC_HOST_CMD_DEDICATED_THREAD
struct k_thread thread;
#endif /* CONFIG_EC_HOST_CMD_DEDICATED_THREAD */
Expand Down
12 changes: 12 additions & 0 deletions subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ int ec_host_cmd_send_response(enum ec_host_cmd_status status,
struct ec_host_cmd *hc = &ec_host_cmd;
struct ec_host_cmd_tx_buf *tx = &hc->tx;

if (hc->state != EC_HOST_CMD_STATE_PROCESSING) {
LOG_ERR("Unexpected state while sending");
return -ENOTSUP;
}
hc->state = EC_HOST_CMD_STATE_SENDING;

if (status != EC_HOST_CMD_SUCCESS) {
const struct ec_host_cmd_request_header *const rx_header =
(const struct ec_host_cmd_request_header *const)hc->rx_ctx.buf;
Expand Down Expand Up @@ -390,9 +396,13 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void *
.reserved = NULL,
};

__ASSERT(hc->state != EC_HOST_CMD_STATE_DISABLED, "HC backend not initialized");

while (1) {
hc->state = EC_HOST_CMD_STATE_RECEIVING;
/* Wait until RX messages is received on host interface */
k_sem_take(&hc->rx_ready, K_FOREVER);
hc->state = EC_HOST_CMD_STATE_PROCESSING;
niedzwiecki-dawid marked this conversation as resolved.
Show resolved Hide resolved

ec_host_cmd_log_request(rx->buf);

Expand Down Expand Up @@ -485,6 +495,8 @@ int ec_host_cmd_init(struct ec_host_cmd_backend *backend)
return -EIO;
}

hc->state = EC_HOST_CMD_STATE_RECEIVING;

/* Check if a backend uses provided buffers. The buffer pointers can be shifted within the
* buffer to make space for preamble. Make sure the rx/tx pointers are within the provided
* buffers ranges.
Expand Down
Loading