Skip to content

Commit

Permalink
change: adding pool_type to hw send routines
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-burger committed Aug 22, 2024
1 parent 6cad1f4 commit b42c657
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
9 changes: 8 additions & 1 deletion include/libethercat/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
/*!
Expand Down
11 changes: 6 additions & 5 deletions src/hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/hw_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/hw_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions src/hw_pikeos.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include <drv/sbuf_common_svc.h>

// 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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/hw_sock_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#include <inttypes.h>

// 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);
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions src/hw_sock_raw_mmaped.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#include <errno.h>

// 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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b42c657

Please sign in to comment.