Skip to content

Commit

Permalink
chore: catchup to db4f8ea
Browse files Browse the repository at this point in the history
db4f8ea Fredrik's documentation updates 2022-12-16
96d617d Fix restoring of PDO config

Based-On-Commit: db4f8ea
Change-Id: I3fd3d3863623194e89e8da7eaf09ac3cf39fea8b
  • Loading branch information
rt-labs bot committed Jul 2, 2024
1 parent 5588bb5 commit 26faaf3
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build*/
CMakeFiles/
CMakeCache.txt
install
docs/_build

.cproject
.project
Expand Down Expand Up @@ -38,3 +39,6 @@ install
*.i*86
*.x86_64
*.hex

# Editors
.vscode/
34 changes: 12 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,21 @@ if (CMAKE_PROJECT_NAME STREQUAL CANOPEN AND BUILD_TESTING)
add_gtest(co_test)
endif()

# Doxygen configuration
cmake_policy(SET CMP0057 NEW)
find_package(Doxygen)
if (CMAKE_PROJECT_NAME STREQUAL CANOPEN AND DOXYGEN_FOUND)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
set(DOXYGEN_TYPEDEF_HIDES_STRUCT YES)
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_STRIP_CODE_COMMENTS NO)
set(DOXYGEN_MACRO_EXPANSION YES)
set(DOXYGEN_EXPAND_ONLY_PREDEF YES)
set(DOXYGEN_PREDEFINED CO_EXPORT)
set(DOXYGEN_EXPAND_AS_DEFINED CO_EXPORT)
set(DOXYGEN_COLLABORATION_GRAPH NO)
set(DOXYGEN_INCLUDE_GRAPH NO)
set(DOXYGEN_INCLUDED_BY_GRAPH NO)
set(DOXYGEN_RECURSIVE NO)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
set(DOXYGEN_GENERATE_LATEX YES)
doxygen_add_docs(docs
README.md
include
src
if (CMAKE_PROJECT_NAME STREQUAL CANOPEN)
add_subdirectory(docs)

add_custom_target(codespell
COMMAND codespell
${CANOPEN_SOURCE_DIR}/include/
${CANOPEN_SOURCE_DIR}/docs/
${CANOPEN_SOURCE_DIR}/src/
${CANOPEN_SOURCE_DIR}/test/
--skip *_build*
COMMENT "Running spell check on source code"
)
endif()


include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE "${CANOPEN_SOURCE_DIR}/LICENSE.md")
set (CPACK_PACKAGE_CONTACT [email protected])
Expand Down
16 changes: 9 additions & 7 deletions include/co_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ typedef enum co_mode
/** CANopen stack configuration */
typedef struct co_cfg
{
uint8_t node; /**< Initial node ID */
int bitrate; /**< Initial bitrate (bits per second) */
uint32_t restart_ms; /**< Bus-off recovery delay, zero to disable */
const co_obj_t * od; /**< Application dictionary */
uint8_t node; /**< Initial node ID */
int bitrate; /**< Initial bitrate (bits per second) */
uint32_t restart_ms; /**< Bus-off recovery delay, zero to disable */
const co_obj_t * od; /**< Application dictionary */
const co_default_t * defaults; /**< Dictionary default values */
void * cb_arg; /**< Callback opaque argument */

Expand Down Expand Up @@ -456,8 +456,10 @@ CO_EXPORT int co_pdo_event (co_client_t * client);
*
* @return 0 on success
*/
CO_EXPORT int co_pdo_obj_event (co_client_t * client, uint16_t index,
uint8_t subindex);
CO_EXPORT int co_pdo_obj_event (
co_client_t * client,
uint16_t index,
uint8_t subindex);

/**
* Read dictionary object entry
Expand Down Expand Up @@ -517,7 +519,7 @@ CO_EXPORT int co_sdo_write (
* The application will be notified via the EMCY callback. The node id
* will be the active node id for this node.
*
* @param net network handle
* @param client network handle
* @param code error code, lower 16 bits of error number
* @param info additional info, upper 16 bits of error number
* @param msef manufacturer-specific error code or NULL
Expand Down
4 changes: 2 additions & 2 deletions include/co_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CO_EXPORT extern const co_entry_t OD1003[];
/** Entry descriptor for COB-ID SYNC message object (1005h) */
CO_EXPORT extern const co_entry_t OD1005[];

/** Entry descriptor for Commmunication cycle object (1006h) */
/** Entry descriptor for Communication cycle object (1006h) */
CO_EXPORT extern const co_entry_t OD1006[];

/** Entry descriptor for Synchronous window length object (1007h) */
Expand Down Expand Up @@ -152,7 +152,7 @@ CO_EXPORT uint32_t co_od1005_fn (
uint32_t * value);

/**
* Access function for Commmunication cycle object (1006h)
* Access function for Communication cycle object (1006h)
*
* @param net network handle
* @param event read/write/restore
Expand Down
2 changes: 1 addition & 1 deletion src/co_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const co_entry_t OD1005[] = {
{0x00, OD_RW, DTYPE_UNSIGNED32, 32, 0, NULL},
};

/* Entry descriptor for Commmunication cycle object (1006h) */
/* Entry descriptor for Communication cycle object (1006h) */
const co_entry_t OD1006[] = {
{0x00, OD_RW, DTYPE_UNSIGNED32, 32, 0, NULL},
};
Expand Down
6 changes: 3 additions & 3 deletions src/co_pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static uint32_t co_pdo_comm_set (
{
if (!co_validate_cob_id (*value))
return CO_SDO_ABORT_VALUE;
if (((pdo->cobid | *value) & CO_COBID_INVALID) == 0)
if (((pdo->cobid | *value) & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->cobid = *value;
pdo->sync_counter = 0;
Expand All @@ -197,7 +197,7 @@ static uint32_t co_pdo_comm_set (
pdo->transmission_type = *value & 0xFF;
break;
case 3:
if ((pdo->cobid & CO_COBID_INVALID) == 0)
if ((pdo->cobid & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->inhibit_time = *value & 0xFFFF;
break;
Expand All @@ -207,7 +207,7 @@ static uint32_t co_pdo_comm_set (
case 6:
if (is_rx)
return CO_SDO_ABORT_BAD_SUBINDEX;
if ((pdo->cobid & CO_COBID_INVALID) == 0)
if ((pdo->cobid & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->sync_start = *value & 0xFF;
break;
Expand Down
44 changes: 44 additions & 0 deletions test/test_od.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern "C" uint32_t cb2001 (
}

static const co_default_t od_defaults[] = {
{0x1800, 1, 0x181},
{0x2000, 1, 11},
{0x2000, 2, 22},
{0x2000, 3, 33},
Expand Down Expand Up @@ -290,6 +291,49 @@ TEST_F (OdTest, StoreThenLoadNewOD)
EXPECT_EQ (0, memcmp (expect_str2001, str2001, sizeof(str2001) - 1));
}

TEST_F (OdTest, LoadUpdatedPDOConfig)
{
const co_obj_t * obj1800 = find_obj (0x1800);
uint32_t value;
uint32_t result;

// Defaults contain enabled TPDO
net.defaults = od_defaults;
net.state = STATE_PREOP;

// Set TPDO COB-ID to 0x456

value = 0x80000456;
result = co_od1800_fn (&net, OD_EVENT_WRITE, obj1800, NULL, 1, &value);
EXPECT_EQ (0u, result);

value = 0x00000456;
result = co_od1800_fn (&net, OD_EVENT_WRITE, obj1800, NULL, 1, &value);
EXPECT_EQ (0u, result);

// Store comm parameters
co_od_store (&net, CO_STORE_COMM, 0x1000, 0x1FFF);

// Set TPDO COB-ID to 0x457

value = 0x80000457;
result = co_od1800_fn (&net, OD_EVENT_WRITE, obj1800, NULL, 1, &value);
EXPECT_EQ (0u, result);

value = 0x00000457;
result = co_od1800_fn (&net, OD_EVENT_WRITE, obj1800, NULL, 1, &value);
EXPECT_EQ (0u, result);

// Reset comm parameters while in STATE_INIT
net.state = STATE_INIT;
co_od_reset (&net, CO_STORE_COMM, 0x1000, 0x1FFF);

// TPDO COB-ID should have been restored
result = co_od1800_fn (&net, OD_EVENT_READ, obj1800, NULL, 1, &value);
EXPECT_EQ (0u, result);
EXPECT_EQ (0x456u, value);
}

TEST_F (OdTest, OD1010)
{
const co_obj_t * obj1010 = find_obj (0x1010);
Expand Down

0 comments on commit 26faaf3

Please sign in to comment.