Skip to content

Commit a5be805

Browse files
committed
Add test for RPDO deadline monitoring
1 parent 465f138 commit a5be805

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/test_pdo.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -857,3 +857,53 @@ TEST_F (PdoTest, SparsePdo)
857857
EXPECT_EQ (0u, result);
858858
EXPECT_EQ (0x1234u, value);
859859
}
860+
861+
TEST_F (PdoTest, RPDOMonitoring)
862+
{
863+
uint8_t pdo[][4] = {
864+
{0x11, 0x22, 0x33, 0x44},
865+
};
866+
867+
net.state = STATE_OP;
868+
869+
net.pdo_rx[0].cobid = 0x201;
870+
net.pdo_rx[0].event_timer = 100;
871+
872+
// Arm RPDO deadline monitoring
873+
co_pdo_rx (&net, 0x201, pdo[0], sizeof (pdo[0]));
874+
EXPECT_TRUE (net.pdo_rx[0].rpdo_monitoring);
875+
876+
// Receive PDO, timer has not expired. Rearm timer.
877+
mock_os_tick_current_result = 50 * 1000;
878+
co_pdo_rx (&net, 0x201, pdo[0], sizeof (pdo[0]));
879+
EXPECT_EQ (0u, mock_co_emcy_tx_calls);
880+
881+
// Timer has not expired
882+
mock_os_tick_current_result = 149 * 1000;
883+
co_pdo_timer (&net, mock_os_tick_current_result);
884+
EXPECT_EQ (0u, mock_co_emcy_tx_calls);
885+
886+
// Timer has expired, should generate EMCY
887+
mock_os_tick_current_result = 150 * 1000;
888+
co_pdo_timer (&net, mock_os_tick_current_result);
889+
EXPECT_EQ (1u, mock_co_emcy_tx_calls);
890+
EXPECT_EQ (0x8250, mock_co_emcy_tx_code);
891+
EXPECT_FALSE (net.pdo_rx[0].rpdo_monitoring);
892+
893+
// Timer still expired, should not generate EMCY
894+
mock_os_tick_current_result = 151 * 1000;
895+
co_pdo_timer (&net, mock_os_tick_current_result);
896+
EXPECT_EQ (1u, mock_co_emcy_tx_calls);
897+
EXPECT_EQ (0x8250, mock_co_emcy_tx_code);
898+
EXPECT_FALSE (net.pdo_rx[0].rpdo_monitoring);
899+
900+
// Receive PDO. Rearm timer.
901+
mock_os_tick_current_result = 160 * 1000;
902+
co_pdo_rx (&net, 0x201, pdo[0], sizeof (pdo[0]));
903+
EXPECT_EQ (1u, mock_co_emcy_tx_calls);
904+
905+
// Receive PDO, timer has not expired
906+
mock_os_tick_current_result = 259 * 1000;
907+
co_pdo_rx (&net, 0x201, pdo[0], sizeof (pdo[0]));
908+
EXPECT_EQ (1u, mock_co_emcy_tx_calls);
909+
}

0 commit comments

Comments
 (0)