Skip to content

Commit 1b07023

Browse files
elupushefloryd
authored andcommitted
Switch to using ticks instead of time in osal
1 parent 249c12c commit 1b07023

24 files changed

+93
-78
lines changed

src/co_emcy.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#define os_channel_send mock_os_channel_send
1818
#define os_channel_get_state mock_os_channel_get_state
1919
#define os_channel_bus_on mock_os_channel_bus_on
20-
#define os_get_current_time_us mock_os_get_current_time_us
20+
#define os_tick_current mock_os_tick_current
21+
#define os_tick_from_us mock_os_tick_from_us
2122
#endif
2223

2324
#include "co_emcy.h"
@@ -232,7 +233,7 @@ int co_emcy_tx (co_net_t * net, uint16_t code, uint16_t info, uint8_t msef[5])
232233
uint8_t msg[8] = {0};
233234
uint8_t * p = msg;
234235
uint8_t reg;
235-
uint32_t now;
236+
os_tick_t now;
236237
bool error_behavior = false;
237238

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

265266
/* Send EMCY if inhibit time has expired */
266-
now = os_get_current_time_us();
267+
now = os_tick_current();
267268
if (co_is_expired (now, net->emcy.timestamp, 100 * net->emcy.inhibit))
268269
{
269270
LOG_ERROR (CO_EMCY_LOG, "emcy %x\n", code);
@@ -325,7 +326,7 @@ int co_emcy_rx (co_net_t * net, uint32_t id, uint8_t * msg, size_t dlc)
325326
void co_emcy_handle_can_state (co_net_t * net)
326327
{
327328
int status;
328-
uint32_t now = os_get_current_time_us();;
329+
os_tick_t now = os_tick_current();
329330
os_channel_state_t previous = net->emcy.state;
330331

331332
/* Get current state */

src/co_heartbeat.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
#ifdef UNIT_TEST
1717
#define os_channel_send mock_os_channel_send
18-
#define os_get_current_time_us mock_os_get_current_time_us
18+
#define os_tick_current mock_os_tick_current
19+
#define os_tick_from_us mock_os_tick_from_us
1920
#define co_emcy_tx mock_co_emcy_tx
2021
#endif
2122

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

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

124-
int co_heartbeat_timer (co_net_t * net, uint32_t now)
125+
int co_heartbeat_timer (co_net_t * net, os_tick_t now)
125126
{
126127
unsigned int ix;
127128
bool heartbeat_error = false;

src/co_heartbeat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int co_heartbeat_rx (co_net_t * net, uint8_t node, void * msg, size_t dlc);
5656
*
5757
* @return 0 on success, -1 on failure
5858
*/
59-
int co_heartbeat_timer (co_net_t * net, uint32_t now);
59+
int co_heartbeat_timer (co_net_t * net, os_tick_t now);
6060

6161
#ifdef __cplusplus
6262
}

src/co_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void co_handle_rx (co_net_t * net)
9898

9999
void co_handle_periodic (co_net_t * net)
100100
{
101-
uint32_t now = os_get_current_time_us();
101+
os_tick_t now = os_tick_current();
102102

103103
co_sdo_server_timer (net, now);
104104
co_sdo_client_timer (net, now);
@@ -278,7 +278,7 @@ int co_sdo_read (
278278
job->sdo.data = data;
279279
job->sdo.remain = size;
280280
job->callback = co_job_callback;
281-
job->timestamp = os_get_current_time_us();
281+
job->timestamp = os_tick_current();
282282
job->type = CO_JOB_SDO_READ;
283283

284284
os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
@@ -307,7 +307,7 @@ int co_sdo_write (
307307
job->sdo.data = (uint8_t *)data;
308308
job->sdo.remain = size;
309309
job->callback = co_job_callback;
310-
job->timestamp = os_get_current_time_us();
310+
job->timestamp = os_tick_current();
311311
job->type = CO_JOB_SDO_WRITE;
312312

313313
os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);

src/co_main.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct co_pdo
7474
uint8_t sync_counter;
7575
uint16_t inhibit_time;
7676
uint16_t event_timer;
77-
uint32_t timestamp;
77+
os_tick_t timestamp;
7878
uint64_t frame;
7979
size_t bitlength;
8080
uint8_t number_of_mappings;
@@ -149,7 +149,7 @@ typedef struct co_job
149149
co_emcy_job_t emcy;
150150
co_pdo_job_t pdo;
151151
};
152-
uint32_t timestamp;
152+
os_tick_t timestamp;
153153
struct co_client * client;
154154
void (*callback) (struct co_job * job);
155155
int result;
@@ -169,7 +169,7 @@ typedef struct co_heartbeat
169169
uint8_t node;
170170
bool is_alive;
171171
uint16_t time;
172-
uint32_t timestamp;
172+
os_tick_t timestamp;
173173
} co_heartbeat_t;
174174

175175
/** Node guarding state */
@@ -179,7 +179,7 @@ typedef struct co_node_guard
179179
uint16_t guard_time;
180180
uint8_t life_time_factor;
181181
uint8_t toggle;
182-
uint32_t timestamp;
182+
os_tick_t timestamp;
183183
} co_node_guard_t;
184184

185185
/** LSS states */
@@ -206,14 +206,14 @@ typedef struct co_sync
206206
uint8_t counter;
207207
uint8_t overflow;
208208
uint32_t period;
209-
uint32_t timestamp;
209+
os_tick_t timestamp;
210210
} co_sync_t;
211211

212212
/** EMCY state */
213213
typedef struct co_emcy
214214
{
215215
uint32_t cobid; /**< EMCY COB ID */
216-
uint32_t timestamp; /**< Timestamp of last EMCY */
216+
os_tick_t timestamp; /**< Timestamp of last EMCY */
217217
uint32_t bus_off_timestamp; /**< Timestamp of bus-off event */
218218
uint16_t inhibit; /**< Inhibit time [100 us] */
219219
uint8_t error; /**< Error register */
@@ -238,9 +238,9 @@ struct co_net
238238
co_emcy_t emcy; /**< EMCY state */
239239
co_sync_t sync; /**< SYNC state */
240240
co_state_t state; /**< NMT state */
241-
uint32_t hb_timestamp; /**< Heartbeat producer timestamp */
241+
os_tick_t hb_timestamp; /**< Heartbeat producer timestamp */
242242
uint32_t hb_time; /**< Heartbeat producer time */
243-
uint32_t sync_timestamp; /**< Timestamp of last SYNC */
243+
os_tick_t sync_timestamp; /**< Timestamp of last SYNC */
244244
uint32_t sync_window; /**< Synchronous window length */
245245
uint32_t restart_ms; /**< Delay before attempting to recover from bus-off */
246246
co_pdo_t pdo_tx[MAX_TX_PDO]; /**< TPDOs */

src/co_node_guard.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#ifdef UNIT_TEST
1717
#define os_channel_send mock_os_channel_send
1818
#define os_channel_receive mock_os_channel_receive
19-
#define os_get_current_time_us mock_os_get_current_time_us
19+
#define os_tick_current mock_os_tick_current
20+
#define os_tick_from_us mock_os_tick_from_us
2021
#endif
2122

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

8687
net->node_guard.is_alive = true;
87-
net->node_guard.timestamp = os_get_current_time_us();
88+
net->node_guard.timestamp = os_tick_current();
8889

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

116-
int co_node_guard_timer (co_net_t * net, uint32_t now)
117+
int co_node_guard_timer (co_net_t * net, os_tick_t now)
117118
{
118119
uint32_t guard_factor =
119120
(net->node_guard.guard_time * net->node_guard.life_time_factor);

src/co_node_guard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int co_node_guard_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc);
5555
*
5656
* @return 0 on success, -1 on failure
5757
*/
58-
int co_node_guard_timer (co_net_t * net, uint32_t now);
58+
int co_node_guard_timer (co_net_t * net, os_tick_t now);
5959

6060
#ifdef __cplusplus
6161
}

src/co_pdo.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
#ifdef UNIT_TEST
1717
#define os_channel_send mock_os_channel_send
18-
#define os_get_current_time_us mock_os_get_current_time_us
18+
#define os_tick_current mock_os_tick_current
19+
#define os_tick_from_us mock_os_tick_from_us
1920
#define co_obj_find mock_co_obj_find
2021
#define co_entry_find mock_co_entry_find
2122
#define co_emcy_tx mock_co_emcy_tx
@@ -532,7 +533,7 @@ uint32_t co_od1A00_fn (
532533
static void co_pdo_transmit (co_net_t * net, co_pdo_t * pdo)
533534
{
534535
size_t dlc;
535-
uint32_t now = os_get_current_time_us();
536+
os_tick_t now = os_tick_current();
536537

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

552-
int co_pdo_timer (co_net_t * net, uint32_t now)
553+
int co_pdo_timer (co_net_t * net, os_tick_t now)
553554
{
554555
unsigned int ix;
555556

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

662-
net->sync_timestamp = os_get_current_time_us();
663+
net->sync_timestamp = os_tick_current();
663664

664665
/* Transmit TPDOs */
665666
for (ix = 0; ix < MAX_TX_PDO; ix++)
@@ -735,7 +736,7 @@ int co_pdo_sync (co_net_t * net, uint8_t * msg, size_t dlc)
735736
void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
736737
{
737738
unsigned int ix;
738-
uint32_t now;
739+
os_tick_t now;
739740

740741
/* Check state */
741742
if (net->state != STATE_OP)
@@ -762,7 +763,7 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
762763
/* Transmit value sampled at previous SYNC */
763764
dlc = CO_BYTELENGTH (pdo->bitlength);
764765
os_channel_send (net->channel, pdo->cobid, &pdo->frame, dlc);
765-
pdo->timestamp = os_get_current_time_us();
766+
pdo->timestamp = os_tick_current();
766767
pdo->queued = false;
767768
}
768769
}
@@ -787,14 +788,14 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
787788
if (pdo->transmission_type <= CO_PDO_TT_CYCLIC_MAX && net->sync_window > 0)
788789
{
789790
/* Check that sync window has not expired */
790-
now = os_get_current_time_us();
791+
now = os_tick_current();
791792
if (co_is_expired (now, net->sync_timestamp, net->sync_window))
792793
continue;
793794
}
794795

795796
/* Buffer frame */
796797
memcpy (&pdo->frame, msg, dlc);
797-
pdo->timestamp = os_get_current_time_us();
798+
pdo->timestamp = os_tick_current();
798799

799800
if (IS_EVENT (pdo->transmission_type))
800801
{

src/co_pdo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc);
103103
*
104104
* @return 0 on success, -1 on failure
105105
*/
106-
int co_pdo_timer (co_net_t * net, uint32_t now);
106+
int co_pdo_timer (co_net_t * net, os_tick_t now);
107107

108108
/**
109109
* PDO trigger

0 commit comments

Comments
 (0)