Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/co_emcy.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#define os_channel_send mock_os_channel_send
#define os_channel_get_state mock_os_channel_get_state
#define os_channel_bus_on mock_os_channel_bus_on
#define os_get_current_time_us mock_os_get_current_time_us
#define os_tick_current mock_os_tick_current
#define os_tick_from_us mock_os_tick_from_us
#endif

#include "co_emcy.h"
Expand Down Expand Up @@ -232,7 +233,7 @@ int co_emcy_tx (co_net_t * net, uint16_t code, uint16_t info, uint8_t msef[5])
uint8_t msg[8] = {0};
uint8_t * p = msg;
uint8_t reg;
uint32_t now;
os_tick_t now;
bool error_behavior = false;

if (net->number_of_errors < MAX_ERRORS)
Expand Down Expand Up @@ -263,7 +264,7 @@ int co_emcy_tx (co_net_t * net, uint16_t code, uint16_t info, uint8_t msef[5])
}

/* Send EMCY if inhibit time has expired */
now = os_get_current_time_us();
now = os_tick_current();
if (co_is_expired (now, net->emcy.timestamp, 100 * net->emcy.inhibit))
{
LOG_ERROR (CO_EMCY_LOG, "emcy %x\n", code);
Expand Down Expand Up @@ -325,7 +326,7 @@ int co_emcy_rx (co_net_t * net, uint32_t id, uint8_t * msg, size_t dlc)
void co_emcy_handle_can_state (co_net_t * net)
{
int status;
uint32_t now = os_get_current_time_us();;
os_tick_t now = os_tick_current();
os_channel_state_t previous = net->emcy.state;

/* Get current state */
Expand Down
7 changes: 4 additions & 3 deletions src/co_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

#ifdef UNIT_TEST
#define os_channel_send mock_os_channel_send
#define os_get_current_time_us mock_os_get_current_time_us
#define os_tick_current mock_os_tick_current
#define os_tick_from_us mock_os_tick_from_us
#define co_emcy_tx mock_co_emcy_tx
#endif

Expand Down Expand Up @@ -112,7 +113,7 @@ int co_heartbeat_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc)
{
co_heartbeat_t * heartbeat = &net->heartbeat[ix];

heartbeat->timestamp = os_get_current_time_us();
heartbeat->timestamp = os_tick_current();
heartbeat->is_alive = true;
LOG_DEBUG (CO_HEARTBEAT_LOG, "node %d got heartbeat\n", heartbeat->node);
}
Expand All @@ -121,7 +122,7 @@ int co_heartbeat_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc)
return 0;
}

int co_heartbeat_timer (co_net_t * net, uint32_t now)
int co_heartbeat_timer (co_net_t * net, os_tick_t now)
{
unsigned int ix;
bool heartbeat_error = false;
Expand Down
2 changes: 1 addition & 1 deletion src/co_heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int co_heartbeat_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc);
*
* @return 0 on success, -1 on failure
*/
int co_heartbeat_timer (co_net_t * net, uint32_t now);
int co_heartbeat_timer (co_net_t * net, os_tick_t now);

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions src/co_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void co_handle_rx (co_net_t * net)

void co_handle_periodic (co_net_t * net)
{
uint32_t now = os_get_current_time_us();
os_tick_t now = os_tick_current();

co_sdo_server_timer (net, now);
co_sdo_client_timer (net, now);
Expand Down Expand Up @@ -278,7 +278,7 @@ int co_sdo_read (
job->sdo.data = data;
job->sdo.remain = size;
job->callback = co_job_callback;
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();
job->type = CO_JOB_SDO_READ;

os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
Expand Down Expand Up @@ -307,7 +307,7 @@ int co_sdo_write (
job->sdo.data = (uint8_t *)data;
job->sdo.remain = size;
job->callback = co_job_callback;
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();
job->type = CO_JOB_SDO_WRITE;

os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
Expand Down
16 changes: 8 additions & 8 deletions src/co_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef struct co_pdo
uint8_t sync_counter;
uint16_t inhibit_time;
uint16_t event_timer;
uint32_t timestamp;
os_tick_t timestamp;
uint64_t frame;
size_t bitlength;
uint8_t number_of_mappings;
Expand Down Expand Up @@ -149,7 +149,7 @@ typedef struct co_job
co_emcy_job_t emcy;
co_pdo_job_t pdo;
};
uint32_t timestamp;
os_tick_t timestamp;
struct co_client * client;
void (*callback) (struct co_job * job);
int result;
Expand All @@ -169,7 +169,7 @@ typedef struct co_heartbeat
uint8_t node;
bool is_alive;
uint16_t time;
uint32_t timestamp;
os_tick_t timestamp;
} co_heartbeat_t;

/** Node guarding state */
Expand All @@ -179,7 +179,7 @@ typedef struct co_node_guard
uint16_t guard_time;
uint8_t life_time_factor;
uint8_t toggle;
uint32_t timestamp;
os_tick_t timestamp;
} co_node_guard_t;

/** LSS states */
Expand All @@ -206,14 +206,14 @@ typedef struct co_sync
uint8_t counter;
uint8_t overflow;
uint32_t period;
uint32_t timestamp;
os_tick_t timestamp;
} co_sync_t;

/** EMCY state */
typedef struct co_emcy
{
uint32_t cobid; /**< EMCY COB ID */
uint32_t timestamp; /**< Timestamp of last EMCY */
os_tick_t timestamp; /**< Timestamp of last EMCY */
uint32_t bus_off_timestamp; /**< Timestamp of bus-off event */
uint16_t inhibit; /**< Inhibit time [100 us] */
uint8_t error; /**< Error register */
Expand All @@ -238,9 +238,9 @@ struct co_net
co_emcy_t emcy; /**< EMCY state */
co_sync_t sync; /**< SYNC state */
co_state_t state; /**< NMT state */
uint32_t hb_timestamp; /**< Heartbeat producer timestamp */
os_tick_t hb_timestamp; /**< Heartbeat producer timestamp */
uint32_t hb_time; /**< Heartbeat producer time */
uint32_t sync_timestamp; /**< Timestamp of last SYNC */
os_tick_t sync_timestamp; /**< Timestamp of last SYNC */
uint32_t sync_window; /**< Synchronous window length */
uint32_t restart_ms; /**< Delay before attempting to recover from bus-off */
co_pdo_t pdo_tx[MAX_TX_PDO]; /**< TPDOs */
Expand Down
7 changes: 4 additions & 3 deletions src/co_node_guard.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#ifdef UNIT_TEST
#define os_channel_send mock_os_channel_send
#define os_channel_receive mock_os_channel_receive
#define os_get_current_time_us mock_os_get_current_time_us
#define os_tick_current mock_os_tick_current
#define os_tick_from_us mock_os_tick_from_us
#endif

#include "co_node_guard.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ int co_node_guard_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
return -1;

net->node_guard.is_alive = true;
net->node_guard.timestamp = os_get_current_time_us();
net->node_guard.timestamp = os_tick_current();

/* Heartbeat producer (heartbeat is prioritised over node guarding)*/
if (net->hb_time == 0)
Expand Down Expand Up @@ -113,7 +114,7 @@ int co_node_guard_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
return 0;
}

int co_node_guard_timer (co_net_t * net, uint32_t now)
int co_node_guard_timer (co_net_t * net, os_tick_t now)
{
uint32_t guard_factor =
(net->node_guard.guard_time * net->node_guard.life_time_factor);
Expand Down
2 changes: 1 addition & 1 deletion src/co_node_guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int co_node_guard_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc);
*
* @return 0 on success, -1 on failure
*/
int co_node_guard_timer (co_net_t * net, uint32_t now);
int co_node_guard_timer (co_net_t * net, os_tick_t now);

#ifdef __cplusplus
}
Expand Down
17 changes: 9 additions & 8 deletions src/co_pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

#ifdef UNIT_TEST
#define os_channel_send mock_os_channel_send
#define os_get_current_time_us mock_os_get_current_time_us
#define os_tick_current mock_os_tick_current
#define os_tick_from_us mock_os_tick_from_us
#define co_obj_find mock_co_obj_find
#define co_entry_find mock_co_entry_find
#define co_emcy_tx mock_co_emcy_tx
Expand Down Expand Up @@ -532,7 +533,7 @@ uint32_t co_od1A00_fn (
static void co_pdo_transmit (co_net_t * net, co_pdo_t * pdo)
{
size_t dlc;
uint32_t now = os_get_current_time_us();
os_tick_t now = os_tick_current();

if (IS_EVENT (pdo->transmission_type) && pdo->inhibit_time > 0)
{
Expand All @@ -549,7 +550,7 @@ static void co_pdo_transmit (co_net_t * net, co_pdo_t * pdo)
pdo->queued = false;
}

int co_pdo_timer (co_net_t * net, uint32_t now)
int co_pdo_timer (co_net_t * net, os_tick_t now)
{
unsigned int ix;

Expand Down Expand Up @@ -659,7 +660,7 @@ int co_pdo_sync (co_net_t * net, uint8_t * msg, size_t dlc)
if (net->state != STATE_OP)
return -1;

net->sync_timestamp = os_get_current_time_us();
net->sync_timestamp = os_tick_current();

/* Transmit TPDOs */
for (ix = 0; ix < MAX_TX_PDO; ix++)
Expand Down Expand Up @@ -735,7 +736,7 @@ int co_pdo_sync (co_net_t * net, uint8_t * msg, size_t dlc)
void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
{
unsigned int ix;
uint32_t now;
os_tick_t now;

/* Check state */
if (net->state != STATE_OP)
Expand All @@ -762,7 +763,7 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
/* Transmit value sampled at previous SYNC */
dlc = CO_BYTELENGTH (pdo->bitlength);
os_channel_send (net->channel, pdo->cobid, &pdo->frame, dlc);
pdo->timestamp = os_get_current_time_us();
pdo->timestamp = os_tick_current();
pdo->queued = false;
}
}
Expand All @@ -787,14 +788,14 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
if (pdo->transmission_type <= CO_PDO_TT_CYCLIC_MAX && net->sync_window > 0)
{
/* Check that sync window has not expired */
now = os_get_current_time_us();
now = os_tick_current();
if (co_is_expired (now, net->sync_timestamp, net->sync_window))
continue;
}

/* Buffer frame */
memcpy (&pdo->frame, msg, dlc);
pdo->timestamp = os_get_current_time_us();
pdo->timestamp = os_tick_current();

if (IS_EVENT (pdo->transmission_type))
{
Expand Down
2 changes: 1 addition & 1 deletion src/co_pdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc);
*
* @return 0 on success, -1 on failure
*/
int co_pdo_timer (co_net_t * net, uint32_t now);
int co_pdo_timer (co_net_t * net, os_tick_t now);

/**
* PDO trigger
Expand Down
4 changes: 2 additions & 2 deletions src/co_sdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int co_sdo_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc);
*
* @return 0 on success, -1 on failure
*/
int co_sdo_server_timer (co_net_t * net, uint32_t now);
int co_sdo_server_timer (co_net_t * net, os_tick_t now);

/**
* SDO client timer
Expand All @@ -139,7 +139,7 @@ int co_sdo_server_timer (co_net_t * net, uint32_t now);
*
* @return 0 on success, -1 on failure
*/
int co_sdo_client_timer (co_net_t * net, uint32_t now);
int co_sdo_client_timer (co_net_t * net, os_tick_t now);

/**
* Issue SDO request
Expand Down
3 changes: 2 additions & 1 deletion src/co_sdo_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define os_channel_receive mock_os_channel_receive
#define co_obj_find mock_co_obj_find
#define co_entry_find mock_co_entry_find
#define os_tick_from_us mock_os_tick_from_us
#endif

#include "co_sdo.h"
Expand Down Expand Up @@ -314,7 +315,7 @@ void co_sdo_issue (co_net_t * net, co_job_t * job)
os_channel_send (net->channel, 0x600 + job->sdo.node, msg, sizeof (msg));
}

int co_sdo_client_timer (co_net_t * net, uint32_t now)
int co_sdo_client_timer (co_net_t * net, os_tick_t now)
{
co_job_t * job = net->job_client;

Expand Down
13 changes: 7 additions & 6 deletions src/co_sdo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
********************************************************************/

#ifdef UNIT_TEST
#define os_get_current_time_us mock_os_get_current_time_us
#define os_tick_current mock_os_tick_current
#define os_tick_from_us mock_os_tick_from_us
#define os_channel_send mock_os_channel_send
#define os_channel_receive mock_os_channel_receive
#define co_obj_find mock_co_obj_find
Expand Down Expand Up @@ -128,7 +129,7 @@ static int co_sdo_rx_upload_init_req (
job->type = CO_JOB_SDO_UPLOAD;
job->sdo.index = co_fetch_uint16 (&data[1]);
job->sdo.subindex = data[3];
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();

/* Find requested object */
obj = co_obj_find (net, job->sdo.index);
Expand Down Expand Up @@ -281,7 +282,7 @@ static int co_sdo_rx_upload_seg_req (

job->sdo.data += size;
job->sdo.remain -= size;
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();
}

os_channel_send (net->channel, 0x580 + net->node, msg, sizeof (msg));
Expand All @@ -305,7 +306,7 @@ static int co_sdo_rx_download_init_req (
job->type = CO_JOB_SDO_DOWNLOAD;
job->sdo.index = co_fetch_uint16 (&data[1]);
job->sdo.subindex = data[3];
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();

/* Find requested object */
obj = co_obj_find (net, job->sdo.index);
Expand Down Expand Up @@ -458,7 +459,7 @@ static int co_sdo_rx_download_seg_req (

job->sdo.data += size;
job->sdo.remain -= size;
job->timestamp = os_get_current_time_us();
job->timestamp = os_tick_current();

if (data[0] & CO_SDO_C)
{
Expand Down Expand Up @@ -572,7 +573,7 @@ int co_sdo_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc)
}
}

int co_sdo_server_timer (co_net_t * net, uint32_t now)
int co_sdo_server_timer (co_net_t * net, os_tick_t now)
{
co_job_t * job = &net->job_sdo_server;

Expand Down
Loading