esp_nano_hosted/include/nh_shared_if.h

42 lines
1.5 KiB
C

#ifndef NH_SHARED_IF_H
#define NH_SHARED_IF_H
#include "nh_common.h"
/* OPS */
typedef nh_ret_t (*nh_shared_if_ops_spi_xfer_t)(void *handle, uint8_t *tx_data, uint8_t *rx_data, uint32_t len);
typedef nh_ret_t (*nh_shared_if_ops_reset_t)(void *handle);
typedef nh_ret_t (*nh_shared_if_ops_hs_poll_t)(void *handle);
typedef nh_ret_t (*nh_shared_if_ops_drdy_read_t)(void *handle, bool *rdy);
typedef struct {
nh_shared_if_ops_spi_xfer_t xfer;
nh_shared_if_ops_reset_t reset;
nh_shared_if_ops_hs_poll_t handshake_poll;
nh_shared_if_ops_drdy_read_t data_ready_read;
void *user_data;
} nh_shared_if_ops_t;
typedef struct {
nh_shared_if_ops_t ops;
nh_osa_t *osa;
/* Private states */
nh_osa_semaphore_t p_semaphore_xfer_req;
nh_osa_semaphore_t p_semaphore_tx;
uint8_t *p_buf_frame_tx; /* SPI TX frame, guarded */
uint8_t *p_buf_frame_rx; /* SPI RX frame, guarded */
uint8_t *p_buf_ctrl_tx; /* Control API TX payload */
uint8_t *p_buf_ctrl_rx; /* Control API RX payload */
} nh_shared_if_t;
nh_ret_t nh_shared_if_init(nh_shared_if_t *shared_if);
void nh_shared_if_task(nh_shared_if_t *shared_if);
void nh_shared_if_inject_data_ready(nh_shared_if_t *shared_if);
/* Internal APIs */
nh_ret_t nh_shared_if_ctrl_send(nh_shared_if_t *shared_if, uint8_t *tx_payload, uint32_t len, uint32_t timeout_ms);
nh_ret_t nh_shared_if_ctrl_recv(nh_shared_if_t *shared_if, uint8_t *rx_payload, uint32_t *len, uint32_t timeout_ms);
#endif // NH_SHARED_IF_H