From b42c657cc8ffdc36566154978079cf889470d6a5 Mon Sep 17 00:00:00 2001 From: Robert Burger Date: Thu, 22 Aug 2024 06:21:51 +0200 Subject: [PATCH] change: adding pool_type to hw send routines --- include/libethercat/hw.h | 9 ++++++++- src/hw.c | 11 ++++++----- src/hw_bpf.c | 2 +- src/hw_file.c | 7 +++++-- src/hw_pikeos.c | 7 +++++-- src/hw_sock_raw.c | 7 +++++-- src/hw_sock_raw_mmaped.c | 7 +++++-- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/include/libethercat/hw.h b/include/libethercat/hw.h index e52070e..6a3fef4 100644 --- a/include/libethercat/hw.h +++ b/include/libethercat/hw.h @@ -70,6 +70,12 @@ struct ec; struct hw_common; +//! Flag to distinguish the pool types during processing +typedef enum pooltype { + POOL_HIGH, + POOL_LOW, +} pooltype_t; //!< \brief pool type struct type. + // //! Receive a frame from an EtherCAT hw device. /*! * \param[in] phw Pointer to hw handle. @@ -82,10 +88,11 @@ typedef int (*hw_device_recv_t)(struct hw_common *phw); /*! * \param[in] phw Pointer to hw handle. * \param[in] pframe Pointer to frame buffer. + * \param[in] pool_type Pool type to distinguish between high and low prio frames. * * \return 0 or negative error code */ -typedef int (*hw_device_send_t)(struct hw_common *phw, ec_frame_t *pframe); +typedef int (*hw_device_send_t)(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type); //! Doing internal stuff when finished sending frames /*! diff --git a/src/hw.c b/src/hw.c index d7e8ca3..e44ec01 100644 --- a/src/hw.c +++ b/src/hw.c @@ -144,11 +144,12 @@ void hw_process_rx_frame(struct hw_common *phw, ec_frame_t *pframe) { } //! internal tx func -static void hw_tx_pool(struct hw_common *phw, pool_t *pool) { +static void hw_tx_pool(struct hw_common *phw, pooltype_t pool_type) { assert(phw != NULL); osal_bool_t sent = OSAL_FALSE; ec_frame_t *pframe = NULL; + pool_t *pool = pool_type == POOL_HIGH ? &phw->tx_high : &phw->tx_low; (void)phw->get_tx_buffer(phw, &pframe); @@ -170,7 +171,7 @@ static void hw_tx_pool(struct hw_common *phw, pool_t *pool) { if ((len == 0u) || ((pframe->len + len) > phw->mtu_size)) { if (pframe->len != sizeof(ec_frame_t)) { - (void)phw->send(phw, pframe); + (void)phw->send(phw, pframe, pool_type); sent = OSAL_TRUE; (void)phw->get_tx_buffer(phw, &pframe); pdg = ec_datagram_first(pframe); @@ -210,7 +211,7 @@ int hw_tx_low(struct hw_common *phw) { int ret = EC_OK; osal_mutex_lock(&phw->hw_lock); - hw_tx_pool(phw, &phw->tx_low); + hw_tx_pool(phw, POOL_LOW); osal_mutex_unlock(&phw->hw_lock); return ret; @@ -229,8 +230,8 @@ int hw_tx(struct hw_common *phw) { osal_mutex_lock(&phw->hw_lock); osal_timer_init(&phw->next_cylce_start, phw->pec->main_cycle_interval); - hw_tx_pool(phw, &phw->tx_high); - hw_tx_pool(phw, &phw->tx_low); + hw_tx_pool(phw, POOL_HIGH); + hw_tx_pool(phw, POOL_LOW); osal_mutex_unlock(&phw->hw_lock); diff --git a/src/hw_bpf.c b/src/hw_bpf.c index beb0d7b..0a5ba5f 100644 --- a/src/hw_bpf.c +++ b/src/hw_bpf.c @@ -62,7 +62,7 @@ static struct bpf_insn insns[] = { }; // forward declarations -int hw_device_bpf_send(hw_t *phw, ec_frame_t *pframe); +int hw_device_bpf_send(hw_t *phw, ec_frame_t *pframe, pooltype_t pool_type); int hw_device_bpf_recv(hw_t *phw); void hw_device_bpf_send_finished(hw_t *phw); int hw_device_bpf_get_tx_buffer(hw_t *phw, ec_frame_t **ppframe); diff --git a/src/hw_file.c b/src/hw_file.c index 5e6b7d8..bf3b9df 100644 --- a/src/hw_file.c +++ b/src/hw_file.c @@ -73,7 +73,7 @@ #define ETHERCAT_DEVICE_GET_POLLING _IOR (ETHERCAT_DEVICE_MAGIC, 2, unsigned int) // forward declarations -int hw_device_file_send(struct hw_common *phw, ec_frame_t *pframe); +int hw_device_file_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type); int hw_device_file_recv(struct hw_common *phw); void hw_device_file_send_finished(struct hw_common *phw); int hw_device_file_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe); @@ -256,13 +256,16 @@ int hw_device_file_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe) { /*! * \param[in] phw Pointer to hw handle. * \param[in] pframe Pointer to frame buffer. + * \param[in] pool_type Pool type to distinguish between high and low prio frames. * * \return 0 or negative error code */ -int hw_device_file_send(struct hw_common *phw, ec_frame_t *pframe) { +int hw_device_file_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type) { assert(phw != NULL); assert(pframe != NULL); + (void)pool_type; + int ret = EC_OK; struct hw_file *phw_file = container_of(phw, struct hw_file, common); diff --git a/src/hw_pikeos.c b/src/hw_pikeos.c index c8d4c5c..58bc15d 100644 --- a/src/hw_pikeos.c +++ b/src/hw_pikeos.c @@ -61,7 +61,7 @@ #include // forward declarations -int hw_device_pikeos_send(struct hw_common *phw, ec_frame_t *pframe); +int hw_device_pikeos_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type); int hw_device_pikeos_recv(struct hw_common *phw); void hw_device_pikeos_send_finished(struct hw_common *phw); int hw_device_pikeos_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe); @@ -324,13 +324,16 @@ int hw_device_pikeos_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe) /*! * \param[in] phw Pointer to hw handle. * \param[in] pframe Pointer to frame buffer. + * \param[in] pool_type Pool type to distinguish between high and low prio frames. * * \return 0 or negative error code */ -int hw_device_pikeos_send(struct hw_common *phw, ec_frame_t *pframe) { +int hw_device_pikeos_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type) { assert(phw != NULL); assert(pframe != NULL); + (void)pool_type; + struct hw_pikeos *phw_pikeos = container_of(phw, struct hw_pikeos, common); int ret = EC_OK; diff --git a/src/hw_sock_raw.c b/src/hw_sock_raw.c index 18f3e11..f43017b 100644 --- a/src/hw_sock_raw.c +++ b/src/hw_sock_raw.c @@ -66,7 +66,7 @@ #include // forward declarations -int hw_device_sock_raw_send(struct hw_common *phw, ec_frame_t *pframe); +int hw_device_sock_raw_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type); int hw_device_sock_raw_recv(struct hw_common *phw); void hw_device_sock_raw_send_finished(struct hw_common *phw); int hw_device_sock_raw_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe); @@ -290,13 +290,16 @@ int hw_device_sock_raw_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe /*! * \param[in] phw Pointer to hw handle. * \param[in] pframe Pointer to frame buffer. + * \param[in] pool_type Pool type to distinguish between high and low prio frames. * * \return 0 or negative error code */ -int hw_device_sock_raw_send(struct hw_common *phw, ec_frame_t *pframe) { +int hw_device_sock_raw_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type) { assert(phw != NULL); assert(pframe != NULL); + (void)pool_type; + int ret = EC_OK; struct hw_sock_raw *phw_sock_raw = container_of(phw, struct hw_sock_raw, common); diff --git a/src/hw_sock_raw_mmaped.c b/src/hw_sock_raw_mmaped.c index a7c17a6..079588c 100644 --- a/src/hw_sock_raw_mmaped.c +++ b/src/hw_sock_raw_mmaped.c @@ -65,7 +65,7 @@ #include // forward declarations -int hw_device_sock_raw_mmaped_send(struct hw_common *phw, ec_frame_t *pframe); +int hw_device_sock_raw_mmaped_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type); int hw_device_sock_raw_mmaped_recv(struct hw_common *phw); void hw_device_sock_raw_mmaped_send_finished(struct hw_common *phw); int hw_device_sock_raw_mmaped_get_tx_buffer(struct hw_common *phw, ec_frame_t **ppframe); @@ -365,13 +365,16 @@ int hw_device_sock_raw_mmaped_get_tx_buffer(struct hw_common *phw, ec_frame_t ** /*! * \param[in] phw Pointer to hw handle. * \param[in] pframe Pointer to frame buffer. + * \param[in] pool_type Pool type to distinguish between high and low prio frames. * * \return 0 or negative error code */ -int hw_device_sock_raw_mmaped_send(struct hw_common *phw, ec_frame_t *pframe) { +int hw_device_sock_raw_mmaped_send(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type) { assert(phw != NULL); assert(pframe != NULL); + (void)pool_type; + int ret = EC_OK; struct hw_sock_raw_mmaped *phw_sock_raw_mmaped = container_of(phw, struct hw_sock_raw_mmaped, common);