esp_nano_hosted/include/nh_ctrl_api.h

74 lines
2.4 KiB
C

#ifndef NH_CTRL_API_H
#define NH_CTRL_API_H
#include <stdbool.h>
#include <stdint.h>
typedef enum {
NH_RET_SUCCESS = 0,
NH_RET_FAIL = 1,
NH_RET_TIMEOUT = 2,
} nh_ret_t;
/* OSA */
typedef void *nh_osa_semaphore_t;
typedef nh_ret_t (*nh_osa_semaphore_create_t)(void *handle, nh_osa_semaphore_t *sem);
typedef nh_ret_t (*nh_osa_semaphore_take_t)(void *handle, nh_osa_semaphore_t sem, uint32_t timeout_msec);
typedef nh_ret_t (*nh_osa_semaphore_give_t)(void *handle, nh_osa_semaphore_t sem);
typedef nh_ret_t (*nh_osa_buf_allocate_t)(void *handle, uint8_t **buf, uint32_t buf_size);
typedef nh_ret_t (*nh_osa_buf_free_t)(void *handle, uint8_t *buf);
/* OPS */
typedef nh_ret_t (*nh_ops_spi_xfer_t)(void *handle, uint8_t *tx_data, uint16_t *rx_data, uint16_t len);
typedef nh_ret_t (*nh_ops_hs_poll_t)(void *handle);
typedef nh_ret_t (*nh_ops_drdy_read_t)(void *handle, bool *rdy);
/* Event callbacks */
typedef void (*nh_cb_init_t)(void *handle);
typedef void (*nh_cb_heartbeat_t)(void *handle);
typedef void (*nh_cb_sta_disconn_from_ap_t)(void *handle);
typedef void (*nh_cb_sta_disconn_from_soft_ap_t)(void *handle);
typedef struct {
nh_osa_buf_allocate_t buf_allocate;
nh_osa_buf_free_t buf_free;
nh_osa_semaphore_create_t sem_create;
nh_osa_semaphore_take_t sem_take;
nh_osa_semaphore_give_t sem_give;
} nh_ctrl_api_osa_t;
typedef struct {
nh_ops_spi_xfer_t xfer;
nh_ops_hs_poll_t handshake_poll;
nh_ops_drdy_read_t data_ready_read;
} nh_ctrl_api_ops_t;
typedef struct {
nh_cb_init_t init;
nh_cb_heartbeat_t heartbeat;
nh_cb_sta_disconn_from_ap_t sta_disconn_from_ap;
nh_cb_sta_disconn_from_soft_ap_t sta_disconn_from_soft_ap;
} nh_ctrl_api_cb_t;
typedef struct {
nh_ctrl_api_osa_t osa;
nh_ctrl_api_ops_t ops;
nh_ctrl_api_cb_t cb;
void *user_data;
/* Private states */
uint8_t *p_buf_tx;
uint8_t *p_buf_rx;
bool p_flag_request; /* !! Guarded by: p_semaphore_request */
nh_osa_semaphore_t p_semaphore_event;
nh_osa_semaphore_t p_semaphore_request;
nh_osa_semaphore_t p_semaphore_response;
} nh_ctrl_api_t;
nh_ret_t nh_ctrl_api_init(nh_ctrl_api_t *api);
void nh_ctrl_api_task(nh_ctrl_api_t *api);
void nh_ctrl_api_inject_data_ready(nh_ctrl_api_t *api);
#endif // NH_CTRL_API_H