57 lines
1.9 KiB
C
57 lines
1.9 KiB
C
#ifndef NH_SHARED_IF_H
|
|
#define NH_SHARED_IF_H
|
|
|
|
#include "nh_common.h"
|
|
#include "nh_helper_event.h"
|
|
#include "nh_helper_serial.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_drdy_read_t)(void *handle, bool *rdy);
|
|
typedef nh_ret_t (*nh_shared_if_ops_hs_poll_t)(void *handle, uint32_t timeout_ms);
|
|
|
|
/* Event callbacks */
|
|
typedef void (*nh_shared_if_cb_event_init_t)(void *handle, nh_event_init_t *init_event);
|
|
|
|
typedef struct {
|
|
nh_shared_if_ops_spi_xfer_t xfer;
|
|
nh_shared_if_ops_reset_t reset;
|
|
nh_shared_if_ops_drdy_read_t drdy_read;
|
|
nh_shared_if_ops_hs_poll_t hs_poll;
|
|
} nh_shared_if_ops_t;
|
|
|
|
typedef struct {
|
|
nh_shared_if_cb_event_init_t init;
|
|
} nh_shared_if_cb_t;
|
|
|
|
typedef struct {
|
|
nh_shared_if_ops_t ops;
|
|
nh_shared_if_cb_t cb;
|
|
void *user_data;
|
|
|
|
nh_osa_t *osa;
|
|
|
|
/* Private states */
|
|
nh_osa_semaphore_t p_semaphore_xfer_req;
|
|
|
|
nh_osa_queue_t p_queue_tx;
|
|
nh_osa_queue_t p_queue_rx_data;
|
|
nh_osa_queue_t p_queue_rx_serial;
|
|
|
|
uint8_t *p_buf_frame_tx; /* SPI TX frame */
|
|
uint8_t *p_buf_frame_rx; /* SPI RX frame */
|
|
} 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_serial_if_send(nh_shared_if_t *shared_if, uint8_t *tx_payload, uint32_t len, uint32_t timeout_ms);
|
|
nh_ret_t nh_shared_if_serial_if_recv(nh_shared_if_t *shared_if, nh_serial_ep_type_t *ep_type, uint8_t **rx_payload,
|
|
uint32_t *len, uint32_t timeout_ms);
|
|
nh_ret_t nh_shared_if_serial_if_free(nh_shared_if_t *shared_if, uint8_t *rx_payload);
|
|
|
|
#endif // NH_SHARED_IF_H
|