Skip to content

Commit

Permalink
Merge pull request #55 from embedded-office/feature/update-2021-07
Browse files Browse the repository at this point in the history
finish feature/update 2021 07
  • Loading branch information
michael-hillmann authored Jul 21, 2021
2 parents 590685b + 88bce0a commit 33f3325
Show file tree
Hide file tree
Showing 35 changed files with 2,410 additions and 678 deletions.
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@ and starting with version 4.1.0 this project adheres to [Semantic Versioning](ht

## [unreleased]

nothing
- none

## [4.1.6] - 2012-07-21

### Added

- Explain the possible PDO transmission options
- Add Example which describes how to setup and use a dynamic object dictionary
- Add type functions for EMCY COB-ID (1014) and SYNC COB-ID (1005)

### Changed

- Clarify the arguments in type functions read() and write()

### Fixed

- PDO Timer Config when entering the OPERATE state multiple times
- Fix the random bogus frame passed to function when no CAN frame is received
- Fix issues in SDO block upload and download protocol

## [4.1.5] - 2021-02-11

Expand Down Expand Up @@ -113,7 +131,8 @@ nothing
- First Open Source Release.


[unreleased]: https://github.com/embedded-office/canopen-stack/compare/v4.1.5...HEAD
[unreleased]: https://github.com/embedded-office/canopen-stack/compare/v4.1.6...HEAD
[4.1.6]: https://github.com/embedded-office/canopen-stack/compare/v4.1.5...v4.1.6
[4.1.5]: https://github.com/embedded-office/canopen-stack/compare/v4.1.4...v4.1.5
[4.1.4]: https://github.com/embedded-office/canopen-stack/compare/v4.1.3...v4.1.4
[4.1.3]: https://github.com/embedded-office/canopen-stack/compare/v4.1.2...v4.1.3
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.15)
project (CanopenStack VERSION 4.1.5)
project (CanopenStack VERSION 4.1.6)

# Make CANopen library
add_subdirectory(canopen)
Expand Down
36 changes: 32 additions & 4 deletions canopen/include/co_emcy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ extern "C" {
/******************************************************************************
* PUBLIC DEFINES
******************************************************************************/

#define CO_TEMCY (CO_OBJ_TYPE *)&COTEmcy /*!< Object Type EMCY History */

#define CO_EMCY_COBID_OFF ((uint32_t)1 << 31) /*!< marked as unused */
#define CO_EMCY_COBID_EXT ((uint32_t)1 << 29) /*!< extended format */
#define CO_EMCY_COBID_MASK ((uint32_t)0x1FFFFFFF) /*!< identifier mask */

#define CO_TEMCY ((const CO_OBJ_TYPE *)&COTEmcy) /*!< EMCY History */
#define CO_TEMCYID ((const CO_OBJ_TYPE *)&COTEmcyId) /*!< Dynamic COB-ID */

#define CO_EMCY_STORAGE (1+((CO_EMCY_N-1)/8)) /*!< bytes for CO_EMCY_N bit */

Expand Down Expand Up @@ -96,7 +101,7 @@ extern "C" {
/******************************************************************************
* PUBLIC CONSTANTS
******************************************************************************/

/*! \brief OBJECT TYPE EMCY HISTORY
*
* This type is responsible for the access to the EMCY history.
Expand Down Expand Up @@ -318,7 +323,7 @@ int16_t COEmcyGetErr(CO_EMCY *emcy, uint8_t err);
* \retval =1 the error state has changed
*/
int16_t COEmcySetErr(CO_EMCY *emcy, uint8_t err, uint8_t state);

/*! \brief SEND EMCY MESSAGE
*
* This function transmits the EMCY message to the configured CANbus.
Expand Down Expand Up @@ -459,6 +464,29 @@ CO_ERR COTypeEmcyRead(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf, u
*/
CO_ERR COTypeEmcyWrite(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf, uint32_t len);

/*! \brief EMCY COB-ID WRITE ACCESS
*
* This function is responsible for the correct write access for the
* EMCY COB-ID object entry (1014h). The access to bit 0 to 29 is only
* allowed when bit 31 is set to 1.
*
* \param obj
* EMCY COB-ID object entry reference
*
* \param node
* reference to parent node
*
* \param buf
* Pointer to buffer memory
*
* \param len
* Length of buffer memory
*
* \retval CO_ERR_NONE EMCY COB-ID object entry is written
* \retval CO_ERR_OBJ_RANGE an error is detected and function aborted
*/
CO_ERR COTypeEmcyIdWrite(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf, uint32_t len);

#ifdef __cplusplus /* for compatibility with C++ environments */
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions canopen/include/co_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
/******************************************************************************
* PUBLIC DEFINES
******************************************************************************/

#ifndef CO_ERR_BASE
#define CO_ERR_BASE 0x0100 /*!< First CANopen stack error code */
#endif
Expand Down Expand Up @@ -95,7 +95,8 @@ typedef enum CO_ERR_T {
CO_ERR_RPDO_COM_OBJ, /*!< config error in RPDO communication */
CO_ERR_RPDO_MAP_OBJ, /*!< config error in RPDO mapping */

CO_ERR_SDO_ABORT, /*!< error during in SDO request */
CO_ERR_SDO_SILENT, /*!< no SDO response (e.g. block transfer) */
CO_ERR_SDO_ABORT, /*!< error in SDO request with ABORT resp. */
CO_ERR_SDO_READ, /*!< error during in SDO block reading */
CO_ERR_SDO_WRITE, /*!< error during in SDO block writing */

Expand Down
6 changes: 3 additions & 3 deletions canopen/include/co_pdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
#define CO_TPDO_COBID_OFF ((uint32_t)1 << 31) /*!< marked as unused */
#define CO_TPDO_COBID_REMOTE ((uint32_t)1 << 30) /*!< RTR is not allowed */
#define CO_TPDO_COBID_EXT ((uint32_t)1 << 29) /*!< extended format */

#define CO_RPDO_COBID_OFF ((uint32_t)1 << 31) /*!< marked as unused */
#define CO_RPDO_COBID_EXT ((uint32_t)1 << 29) /*!< extended format */

Expand All @@ -47,7 +47,7 @@ extern "C" {
#define CO_TPDO_FLG_S_E 0x05 /*!< PDO synced + event occured */
#define CO_TPDO_FLG_SI_ 0x06 /*!< PDO synced + TX inhibited */
#define CO_TPDO_FLG_SIE 0x07 /*!< PDO synved + event occured + TX inh. */

#define CO_RPDO_FLG__E 0x01 /*!< enabled RPDO */
#define CO_RPDO_FLG_S_ 0x02 /*!< synchronized RPDO */

Expand All @@ -58,7 +58,7 @@ extern "C" {
#define CO_TEVENT ((const CO_OBJ_TYPE *)&COTEvent) /*!< TPDO Event Timer */
#define CO_TPDONUM ((const CO_OBJ_TYPE *)&COTPdoMapN) /*!< Dynamic Map Numbers */
#define CO_TPDOMAP ((const CO_OBJ_TYPE *)&COTPdoMap) /*!< Dynamic Mapping */
#define CO_TPDOID ((const CO_OBJ_TYPE *)&COTPdoId) /*!< Dynamic Identifier */
#define CO_TPDOID ((const CO_OBJ_TYPE *)&COTPdoId) /*!< Dynamic COB-ID */
#define CO_TPDOTYPE ((const CO_OBJ_TYPE *)&COTPdoType) /*!< Dynamic Transm. Type */

/******************************************************************************
Expand Down
16 changes: 11 additions & 5 deletions canopen/include/co_sdo_srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ extern "C" {
#define CO_SDO_ERR_SEQ_NUM 0x05040003 /*!< Invalid Sequence number */
#define CO_SDO_ERR_RD 0x06010001 /*!< Attempt to read a write only object */
#define CO_SDO_ERR_WR 0x06010002 /*!< Attempt to write a read only object */
#define CO_SDO_ERR_OBJ 0x06020000 /*!< Object doesn't exist in dictionary */
#define CO_SDO_ERR_OBJ 0x06020000 /*!< Object doesn't exist in dictionary */
#define CO_SDO_ERR_HW_ACCESS 0x06060000 /*!< Access failed due to an hardware error */
#define CO_SDO_ERR_LEN_HIGH 0x06070012 /*!< Length of parameter too high */
#define CO_SDO_ERR_LEN_SMALL 0x06070013 /*!< Length of parameter too small */
#define CO_SDO_ERR_SUB 0x06090011 /*!< Subindex doesn't exist in dictionary */
#define CO_SDO_ERR_SUB 0x06090011 /*!< Subindex doesn't exist in dictionary */
#define CO_SDO_ERR_RANGE 0x06090030 /*!< Value range of parameter exceeded */
#define CO_SDO_ERR_TOS 0x08000020 /*!< Data can't be transfered or stored */
#define CO_SDO_ERR_TOS_STATE 0x08000022 /*!< Data can't be transfered or stored, */
Expand Down Expand Up @@ -72,7 +73,7 @@ extern "C" {
* designed to provide the feature of changing a SDO identifier.
*/
extern const CO_OBJ_TYPE COTSdoId;

/******************************************************************************
* PUBLIC TYPES
******************************************************************************/
Expand Down Expand Up @@ -127,6 +128,7 @@ typedef struct CO_SDO_BLK_T {
uint32_t Len; /*!< remaining block length in byte */
uint8_t SegNum; /*!< number of segments in block */
uint8_t SegCnt; /*!< current segment number */
uint8_t SegOk; /*!< last successfull sent segment */
uint8_t LastValid; /*!< valid bytes in last segment */

} CO_SDO_BLK;
Expand Down Expand Up @@ -261,10 +263,14 @@ CO_ERR COSdoGetObject(CO_SDO *srv, uint16_t mode);
* \param width
* Parameter size in byte (or 0 if unknown)
*
* \retval =0 Abort for known width
* \param strict
* Controls the lower boundary check. If this argument is false, a width
* smaller than the object size is allowed.
*
* \retval =0 Invalid width, abort frame in SDO server is set
* \retval >0 Size of Object
*/
uint32_t COSdoGetSize(CO_SDO *srv, uint32_t width);
uint32_t COSdoGetSize(CO_SDO *srv, uint32_t width, bool strict);

/*! \brief EXPEDITED UPLOAD PROTOCOL
*
Expand Down
29 changes: 29 additions & 0 deletions canopen/include/co_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ extern "C" {
* PUBLIC DEFINES
******************************************************************************/

#define CO_SYNC_COBID_OFF ((uint32_t)1 << 30) /*!< generator flag */
#define CO_SYNC_COBID_EXT ((uint32_t)1 << 29) /*!< extended format */
#define CO_SYNC_COBID_MASK ((uint32_t)0x1FFFFFFF) /*!< identifier mask */

#define CO_SYNC_FLG_TX 0x01 /*!< message type indication TPDO */
#define CO_SYNC_FLG_RX 0x02 /*!< message type indication: RPDO */

#define CO_TSYNCID ((const CO_OBJ_TYPE *)&COTSyncId) /*!< Dynamic COB-ID */

/******************************************************************************
* PUBLIC TYPES
******************************************************************************/
Expand Down Expand Up @@ -153,6 +159,29 @@ int16_t COSyncUpdate(CO_SYNC *sync, CO_IF_FRM *frm);
*/
void COSyncRestart(CO_SYNC *sync);

/*! \brief SYNC COB-ID WRITE ACCESS
*
* This function is responsible for the correct write access for the
* SYNC COB-ID object entry (1005h). The access to bit 0 to 29 is only
* allowed when bit 30 is set to 0.
*
* \param obj
* SYNC COB-ID object entry reference
*
* \param node
* reference to parent node
*
* \param buf
* Pointer to buffer memory
*
* \param len
* Length of buffer memory
*
* \retval CO_ERR_NONE SYNC COB-ID object entry is written
* \retval CO_ERR_OBJ_RANGE an error is detected and function aborted
*/
CO_ERR COTypeSyncIdWrite(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf, uint32_t len);

/******************************************************************************
* CALLBACK FUNCTIONS
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion canopen/include/co_ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#define CO_VER_MAJOR 4
#define CO_VER_MINOR 1
#define CO_VER_BUILD 5
#define CO_VER_BUILD 6

/******************************************************************************
* PUBLIC FUNCTIONS
Expand Down
22 changes: 12 additions & 10 deletions canopen/source/co_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CONodeInit(CO_NODE *node, CO_NODE_SPEC *spec)
COSdoInit(node->Sdo, node);
COTPdoClear(node->TPdo, node);
CORPdoClear(node->RPdo, node);
COEmcyInit(&node->Emcy, node, spec->EmcyCode);
COEmcyInit(&node->Emcy, node, spec->EmcyCode);
COSyncInit(&node->Sync, node);
COLssInit(&node->Lss, node);
COIfCanEnable(&node->If, node->Baudrate);
Expand Down Expand Up @@ -149,21 +149,23 @@ void CONodeProcess(CO_NODE *node)
allowed = 0;
} else {
allowed = node->Nmt.Allowed;
}

result = COLssCheck(&node->Lss, &frm);
if (result != 0) {
if (result > 0) {
(void)COIfCanSend(&node->If, &frm);
result = COLssCheck(&node->Lss, &frm);
if (result != 0) {
if (result > 0) {
(void)COIfCanSend(&node->If, &frm);
}
allowed = 0;
}
allowed = 0;
}

if ((allowed & CO_SDO_ALLOWED) != 0) {
srv = COSdoCheck(node->Sdo, &frm);
if (srv != 0) {
(void)COSdoResponse(srv);
(void)COIfCanSend(&node->If, &frm);
CO_ERR err = COSdoResponse(srv);
if ((err == CO_ERR_NONE ) ||
(err == CO_ERR_SDO_ABORT)) {
(void)COIfCanSend(&node->If, &frm);
}
allowed = 0;
}
}
Expand Down
31 changes: 30 additions & 1 deletion canopen/source/co_emcy.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
******************************************************************************/

const CO_OBJ_TYPE COTEmcy = { 0, 0, COTypeEmcyRead, COTypeEmcyWrite };
const CO_OBJ_TYPE COTEmcyId = { 0, 0, 0, COTypeEmcyIdWrite };

/******************************************************************************
* FUNCTIONS
Expand Down Expand Up @@ -312,7 +313,7 @@ int16_t COEmcySetErr(CO_EMCY *emcy, uint8_t err, uint8_t state)
*/
void COEmcySend(CO_EMCY *emcy, uint8_t err, CO_EMCY_USR *usr, uint8_t state)
{
CO_IF_FRM frm;
CO_IF_FRM frm;
CO_NODE *node;
CO_DICT *dir;
CO_EMCY_TBL *data;
Expand Down Expand Up @@ -525,3 +526,31 @@ CO_ERR COTypeEmcyWrite(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf,

return (result);
}

/*
* see function definition
*/
CO_ERR COTypeEmcyIdWrite(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buf, uint32_t len)
{
CO_ERR result = CO_ERR_NONE;
uint32_t nid;
uint32_t oid;

(void)len;
(void)node;
nid = *(uint32_t*)buf;
(void)COObjRdDirect(obj, &oid, CO_LONG);

/* when current entry is active, bits 0 to 29 shall not be changed */
if ((oid & CO_EMCY_COBID_OFF) == (uint32_t)0) {
if ((nid & CO_EMCY_COBID_MASK) != (oid & CO_EMCY_COBID_MASK)) {
result = CO_ERR_OBJ_RANGE;
} else {
result = COObjWrDirect(obj, &nid, CO_LONG);
}
} else {
result = COObjWrDirect(obj, &nid, CO_LONG);
}

return (result);
}
12 changes: 6 additions & 6 deletions canopen/source/co_nmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ void CONmtReset(CO_NMT *nmt, CO_NMT_RESET type)
}

if (type == CO_RESET_NODE) {
CONodeParaLoad(nmt->Node, CO_RESET_NODE);
CONodeParaLoad(nmt->Node, CO_RESET_NODE);
}

if (type <= CO_RESET_COM) {
CONodeParaLoad(nmt->Node, CO_RESET_COM);
CONodeParaLoad(nmt->Node, CO_RESET_COM);
err = COLssLoad(&nmt->Node->Baudrate, &nmt->Node->NodeId);
if (err != CO_ERR_NONE) {
nmt->Node->Error = CO_ERR_LSS_LOAD;
Expand Down Expand Up @@ -126,11 +126,11 @@ void CONmtSetMode(CO_NMT *nmt, CO_MODE mode)
CONodeFatalError();
return;
}
if (mode == CO_OPERATIONAL) {
COTPdoInit(nmt->Node->TPdo, nmt->Node);
CORPdoInit(nmt->Node->RPdo, nmt->Node);
}
if (nmt->Mode != mode) {
if (mode == CO_OPERATIONAL) {
COTPdoInit(nmt->Node->TPdo, nmt->Node);
CORPdoInit(nmt->Node->RPdo, nmt->Node);
}
CONmtModeChange(nmt, mode);
}
nmt->Mode = mode;
Expand Down
Loading

0 comments on commit 33f3325

Please sign in to comment.