static analysis: add 'U' of unsigned [MISRA 2012 Rule 10.4, required]
This commit is contained in:
parent
dc10900ad5
commit
446925be63
25 changed files with 633 additions and 633 deletions
|
|
@ -129,7 +129,7 @@ static ODR_t OD_write_1014(OD_stream_t *stream, const void *buf,
|
|||
static ODR_t OD_read_1014_default(OD_stream_t *stream, void *buf,
|
||||
OD_size_t count, OD_size_t *countRead)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count < sizeof(uint32_t)) || (countRead == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -137,8 +137,8 @@ static ODR_t OD_read_1014_default(OD_stream_t *stream, void *buf,
|
|||
|
||||
CO_EM_t *em = (CO_EM_t *)stream->object;
|
||||
|
||||
uint32_t COB_IDEmergency32 = em->producerEnabled ? 0 : 0x80000000;
|
||||
COB_IDEmergency32 |= CO_CAN_ID_EMERGENCY + em->nodeId;
|
||||
uint32_t COB_IDEmergency32 = em->producerEnabled ? 0U : 0x80000000U;
|
||||
(void)CO_setUint32(buf, COB_IDEmergency32);
|
||||
|
||||
*countRead = sizeof(uint32_t);
|
||||
|
|
@ -375,11 +375,11 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
/* verify arguments */
|
||||
if ((em == NULL) || (OD_1001_errReg == NULL)
|
||||
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
|
||||
|| ((fifo == NULL) && (fifoSize >= 2))
|
||||
|| ((fifo == NULL) && (fifoSize >= 2U))
|
||||
#endif
|
||||
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
|
||||
|| (OD_1014_cobIdEm == NULL) || (CANdevTx == NULL)
|
||||
|| (nodeId < 1) || (nodeId > 127)
|
||||
|| (nodeId < 1U) || (nodeId > 127U)
|
||||
#endif
|
||||
#if (CO_CONFIG_EM) & CO_CONFIG_EM_HISTORY
|
||||
|| OD_1003_preDefErr == NULL
|
||||
|
|
@ -414,7 +414,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
uint32_t COB_IDEmergency32;
|
||||
ODR_t odRet;
|
||||
odRet = OD_get_u32(OD_1014_cobIdEm, 0, &COB_IDEmergency32, true);
|
||||
if ((odRet != ODR_OK) || ((COB_IDEmergency32 & 0x7FFFF800) != 0)) {
|
||||
if ((odRet != ODR_OK) || ((COB_IDEmergency32 & 0x7FFFF800U) != 0U)) {
|
||||
if (errInfo != NULL) { *errInfo = OD_getIndex(OD_1014_cobIdEm); }
|
||||
/* don't break a program, if only value of a parameter is wrong */
|
||||
if (odRet != ODR_OK) { return CO_ERROR_OD_PARAMETERS; }
|
||||
|
|
@ -442,7 +442,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
if (producerCanId == CO_CAN_ID_EMERGENCY) producerCanId += nodeId;
|
||||
#else
|
||||
uint16_t producerCanId = CO_CAN_ID_EMERGENCY + nodeId;
|
||||
em->producerEnabled = (COB_IDEmergency32 & 0x80000000) == 0;
|
||||
em->producerEnabled = (COB_IDEmergency32 & 0x80000000U) == 0U;
|
||||
|
||||
em->OD_1014_extension.object = em;
|
||||
em->OD_1014_extension.read = OD_read_1014_default;
|
||||
|
|
@ -634,7 +634,7 @@ void CO_EM_process(CO_EM_t *em,
|
|||
|
||||
/* post-process Emergency message in fifo buffer. */
|
||||
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
|
||||
if (em->fifoSize >= 2) {
|
||||
if (em->fifoSize >= 2U) {
|
||||
uint8_t fifoPpPtr = em->fifoPpPtr;
|
||||
|
||||
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PROD_INHIBIT
|
||||
|
|
@ -670,16 +670,16 @@ void CO_EM_process(CO_EM_t *em,
|
|||
#endif
|
||||
|
||||
/* increment pointer */
|
||||
em->fifoPpPtr = (++fifoPpPtr < em->fifoSize) ? fifoPpPtr : 0;
|
||||
em->fifoPpPtr = (++fifoPpPtr < em->fifoSize) ? fifoPpPtr : 0U;
|
||||
|
||||
/* verify message buffer overflow. Clear error condition if all
|
||||
* messages from fifo buffer are processed */
|
||||
if (em->fifoOverflow == 1) {
|
||||
if (em->fifoOverflow == 1U) {
|
||||
em->fifoOverflow = 2;
|
||||
CO_errorReport(em, CO_EM_EMERGENCY_BUFFER_FULL,
|
||||
CO_EMC_GENERIC, 0);
|
||||
}
|
||||
else if ((em->fifoOverflow == 2) && (em->fifoPpPtr == em->fifoWrPtr)) {
|
||||
else if ((em->fifoOverflow == 2U) && (em->fifoPpPtr == em->fifoWrPtr)) {
|
||||
em->fifoOverflow = 0;
|
||||
CO_errorReset(em, CO_EM_EMERGENCY_BUFFER_FULL, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,15 +40,15 @@
|
|||
#define CO_CONFIG_EM_ERR_STATUS_BITS_COUNT (10*8)
|
||||
#endif
|
||||
#ifndef CO_CONFIG_ERR_CONDITION_GENERIC
|
||||
#define CO_CONFIG_ERR_CONDITION_GENERIC (em->errorStatusBits[5] != 0)
|
||||
#define CO_CONFIG_ERR_CONDITION_GENERIC (em->errorStatusBits[5] != 0U)
|
||||
#endif
|
||||
#ifndef CO_CONFIG_ERR_CONDITION_COMMUNICATION
|
||||
#define CO_CONFIG_ERR_CONDITION_COMMUNICATION (em->errorStatusBits[2] \
|
||||
|| em->errorStatusBits[3])
|
||||
#define CO_CONFIG_ERR_CONDITION_COMMUNICATION ((em->errorStatusBits[2] != 0U) \
|
||||
|| (em->errorStatusBits[3] != 0U))
|
||||
#endif
|
||||
#ifndef CO_CONFIG_ERR_CONDITION_MANUFACTURER
|
||||
#define CO_CONFIG_ERR_CONDITION_MANUFACTURER (em->errorStatusBits[8] \
|
||||
|| em->errorStatusBits[9])
|
||||
#define CO_CONFIG_ERR_CONDITION_MANUFACTURER (( em->errorStatusBits[8] != 0U) \
|
||||
|| (em->errorStatusBits[9] != 0U))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static void CO_HBcons_receive(void *object, void *msg) {
|
|||
uint8_t DLC = CO_CANrxMsg_readDLC(msg);
|
||||
uint8_t *data = CO_CANrxMsg_readData(msg);
|
||||
|
||||
if (DLC == 1) {
|
||||
if (DLC == 1U) {
|
||||
/* copy data and set 'new message' flag. */
|
||||
HBconsNode->NMTstate = (CO_NMT_internalState_t)data[0];
|
||||
CO_FLAG_SET(HBconsNode->CANrxNew);
|
||||
|
|
@ -89,7 +89,7 @@ static ODR_t OD_write_1016(OD_stream_t *stream, const void *buf,
|
|||
CO_HBconsumer_t *HBcons = stream->object;
|
||||
|
||||
if ((stream == NULL) || (buf == NULL)
|
||||
|| (stream->subIndex < 1)
|
||||
|| (stream->subIndex < 1U)
|
||||
|| (stream->subIndex > HBcons->numberOfMonitoredNodes)
|
||||
|| (count != sizeof(uint32_t)) || (countWritten == NULL)
|
||||
) {
|
||||
|
|
@ -97,9 +97,9 @@ static ODR_t OD_write_1016(OD_stream_t *stream, const void *buf,
|
|||
}
|
||||
|
||||
uint32_t val = CO_getUint32(buf);
|
||||
uint8_t nodeId = (val >> 16) & 0xFF;
|
||||
uint16_t time = val & 0xFFFF;
|
||||
CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, stream->subIndex - 1,
|
||||
uint8_t nodeId = (val >> 16) & 0xFFU;
|
||||
uint16_t time = val & 0xFFFFU;
|
||||
CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, stream->subIndex - 1U,
|
||||
nodeId, time);
|
||||
if (ret != CO_ERROR_NO) {
|
||||
return ODR_PAR_INCOMPAT;
|
||||
|
|
@ -139,19 +139,19 @@ CO_ReturnError_t CO_HBconsumer_init(CO_HBconsumer_t *HBcons,
|
|||
|
||||
/* get actual number of monitored nodes */
|
||||
HBcons->numberOfMonitoredNodes =
|
||||
((OD_1016_HBcons->subEntriesCount-1) < monitoredNodesCount) ?
|
||||
(OD_1016_HBcons->subEntriesCount-1) : monitoredNodesCount;
|
||||
((OD_1016_HBcons->subEntriesCount-1U) < monitoredNodesCount) ?
|
||||
(OD_1016_HBcons->subEntriesCount-1U) : monitoredNodesCount;
|
||||
|
||||
for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) {
|
||||
uint32_t val;
|
||||
odRet = OD_get_u32(OD_1016_HBcons, i + 1, &val, true);
|
||||
odRet = OD_get_u32(OD_1016_HBcons, i + 1U, &val, true);
|
||||
if (odRet != ODR_OK) {
|
||||
if (errInfo != NULL) { *errInfo = OD_getIndex(OD_1016_HBcons); }
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
uint8_t nodeId = (val >> 16) & 0xFF;
|
||||
uint16_t time = val & 0xFFFF;
|
||||
uint8_t nodeId = (val >> 16) & 0xFFU;
|
||||
uint16_t time = val & 0xFFFFU;
|
||||
CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, i, nodeId, time);
|
||||
if (ret != CO_ERROR_NO) {
|
||||
if (errInfo != NULL) { *errInfo = OD_getIndex(OD_1016_HBcons); }
|
||||
|
|
@ -190,10 +190,10 @@ static CO_ReturnError_t CO_HBconsumer_initEntry(CO_HBconsumer_t *HBcons,
|
|||
}
|
||||
|
||||
/* verify for duplicate entries */
|
||||
if((consumerTime_ms != 0) && (nodeId != 0)) {
|
||||
if((consumerTime_ms != 0U) && (nodeId != 0U)) {
|
||||
for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) {
|
||||
CO_HBconsNode_t node = HBcons->monitoredNodes[i];
|
||||
if((idx != i) && (node.time_us != 0) && (node.nodeId == nodeId)) {
|
||||
if((idx != i) && (node.time_us != 0U) && (node.nodeId == nodeId)) {
|
||||
ret = CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
}
|
||||
|
|
@ -214,8 +214,8 @@ static CO_ReturnError_t CO_HBconsumer_initEntry(CO_HBconsumer_t *HBcons,
|
|||
CO_FLAG_CLEAR(monitoredNode->CANrxNew);
|
||||
|
||||
/* is channel used */
|
||||
if ((monitoredNode->nodeId != 0) && (monitoredNode->time_us != 0)) {
|
||||
COB_ID = monitoredNode->nodeId + CO_CAN_ID_HEARTBEAT;
|
||||
if ((monitoredNode->nodeId != 0U) && (monitoredNode->time_us != 0U)) {
|
||||
monitoredNode->HBstate = CO_HBconsumer_UNKNOWN;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ static void CO_NMT_receive(void *object, void *msg) {
|
|||
|
||||
CO_NMT_t *NMT = (CO_NMT_t*)object;
|
||||
|
||||
if ((DLC == 2) && ((nodeId == 0) || (nodeId == NMT->nodeId))) {
|
||||
if ((DLC == 2U) && ((nodeId == 0U) || (nodeId == NMT->nodeId))) {
|
||||
NMT->internalCommand = command;
|
||||
|
||||
#if (CO_CONFIG_NMT) & CO_CONFIG_FLAG_CALLBACK_PRE
|
||||
|
|
@ -62,7 +62,7 @@ static void CO_NMT_receive(void *object, void *msg) {
|
|||
static ODR_t OD_write_1017(OD_stream_t *stream, const void *buf,
|
||||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count != sizeof(uint16_t)) || (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -71,7 +71,7 @@ static ODR_t OD_write_1017(OD_stream_t *stream, const void *buf,
|
|||
CO_NMT_t *NMT = (CO_NMT_t *)stream->object;
|
||||
|
||||
/* update object, send Heartbeat immediately */
|
||||
NMT->HBproducerTime_us = (uint32_t)CO_getUint16(buf) * 1000;
|
||||
NMT->HBproducerTime_us = (uint32_t)CO_getUint16(buf) * 1000U;
|
||||
NMT->HBproducerTimer = 0;
|
||||
|
||||
/* write value to the original location in the Object Dictionary */
|
||||
|
|
@ -129,7 +129,7 @@ CO_ReturnError_t CO_NMT_init(CO_NMT_t *NMT,
|
|||
if (errInfo != NULL) { *errInfo = OD_getIndex(OD_1017_ProducerHbTime); }
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
NMT->HBproducerTime_us = (uint32_t)HBprodTime_ms * 1000;
|
||||
NMT->HBproducerTime_us = (uint32_t)HBprodTime_ms * 1000U;
|
||||
|
||||
NMT->OD_1017_extension.object = NMT;
|
||||
NMT->OD_1017_extension.read = OD_readOriginal;
|
||||
|
|
@ -229,13 +229,13 @@ CO_NMT_reset_cmd_t CO_NMT_process(CO_NMT_t *NMT,
|
|||
bool_t NNTinit = NMTstateCpy == CO_NMT_INITIALIZING;
|
||||
|
||||
NMT->HBproducerTimer = (NMT->HBproducerTimer > timeDifference_us )
|
||||
? (NMT->HBproducerTimer - timeDifference_us) : 0;
|
||||
? (NMT->HBproducerTimer - timeDifference_us) : 0U;
|
||||
|
||||
/* Send heartbeat producer message if:
|
||||
* - First start, send bootup message or
|
||||
* - HB producer enabled and: Timer expired or NMT->operatingState changed*/
|
||||
if (NNTinit || ((NMT->HBproducerTime_us != 0)
|
||||
&& ((NMT->HBproducerTimer == 0)
|
||||
if (NNTinit || ((NMT->HBproducerTime_us != 0U)
|
||||
&& ((NMT->HBproducerTimer == 0U)
|
||||
|| (NMTstateCpy != NMT->operatingStatePrev))
|
||||
)) {
|
||||
NMT->HB_TXbuff->data[0] = (uint8_t) NMTstateCpy;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ static void CO_ngs_receive(void *object, void *msg) {
|
|||
static ODR_t OD_write_100C(OD_stream_t *stream, const void *buf,
|
||||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count != sizeof(uint16_t)) || (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -59,11 +59,11 @@ static ODR_t OD_write_100C(OD_stream_t *stream, const void *buf,
|
|||
CO_nodeGuardingSlave_t *ngs = (CO_nodeGuardingSlave_t *)stream->object;
|
||||
|
||||
/* update objects */
|
||||
ngs->guardTime_us = (uint32_t)CO_getUint16(buf) * 1000;
|
||||
ngs->guardTime_us = (uint32_t)CO_getUint16(buf) * 1000U;
|
||||
ngs->lifeTime_us = ngs->guardTime_us * ngs->lifeTimeFactor;
|
||||
|
||||
/* reset running timer */
|
||||
if (ngs->lifeTimer > 0) {
|
||||
if (ngs->lifeTimer > 0U) {
|
||||
ngs->lifeTimer = ngs->lifeTime_us;
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ static ODR_t OD_write_100C(OD_stream_t *stream, const void *buf,
|
|||
static ODR_t OD_write_100D(OD_stream_t *stream, const void *buf,
|
||||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count != sizeof(uint8_t)) || (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -93,7 +93,7 @@ static ODR_t OD_write_100D(OD_stream_t *stream, const void *buf,
|
|||
ngs->lifeTime_us = ngs->guardTime_us * ngs->lifeTimeFactor;
|
||||
|
||||
/* reset running timer */
|
||||
if (ngs->lifeTimer > 0) {
|
||||
if (ngs->lifeTimer > 0U) {
|
||||
ngs->lifeTimer = ngs->lifeTime_us;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ CO_ReturnError_t CO_nodeGuardingSlave_init(CO_nodeGuardingSlave_t *ngs,
|
|||
if (errInfo != NULL) *errInfo = OD_getIndex(OD_100C_GuardTime);
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
ngs->guardTime_us = (uint32_t)guardTime_ms * 1000;
|
||||
ngs->guardTime_us = (uint32_t)guardTime_ms * 1000U;
|
||||
|
||||
ngs->OD_100C_extension.object = ngs;
|
||||
ngs->OD_100C_extension.read = OD_readOriginal;
|
||||
|
|
@ -219,7 +219,7 @@ void CO_nodeGuardingSlave_process(CO_nodeGuardingSlave_t *ngs,
|
|||
/* send response */
|
||||
ngs->CANtxBuff->data[0] = (uint8_t) NMTstate;
|
||||
if (ngs->toggle) {
|
||||
ngs->CANtxBuff->data[0] |= 0x80;
|
||||
ngs->CANtxBuff->data[0] |= 0x80U;
|
||||
ngs->toggle = false;
|
||||
}
|
||||
else {
|
||||
|
|
@ -237,7 +237,7 @@ void CO_nodeGuardingSlave_process(CO_nodeGuardingSlave_t *ngs,
|
|||
}
|
||||
|
||||
/* verify "Life time" timeout and update the timer */
|
||||
else if (ngs->lifeTimer > 0) {
|
||||
else if (ngs->lifeTimer > 0U) {
|
||||
if (timeDifference_us < ngs->lifeTimer) {
|
||||
ngs->lifeTimer -= timeDifference_us;
|
||||
#if (CO_CONFIG_NMT) & CO_CONFIG_FLAG_TIMERNEXT
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ ODR_t OD_readOriginal(OD_stream_t *stream, void *buf,
|
|||
|
||||
/* If previous read was partial or OD variable length is larger than
|
||||
* current buffer size, then data was (will be) read in several segments */
|
||||
if ((stream->dataOffset > 0) || (dataLenToCopy > count)) {
|
||||
if ((stream->dataOffset > 0U) || (dataLenToCopy > count)) {
|
||||
if (stream->dataOffset >= dataLenToCopy) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ ODR_t OD_writeOriginal(OD_stream_t *stream, const void *buf,
|
|||
/* If previous write was partial or OD variable length is larger than
|
||||
* current buffer size, then data was (will be) written in several
|
||||
* segments */
|
||||
if ((stream->dataOffset > 0) || (dataLenToCopy > count)) {
|
||||
if ((stream->dataOffset > 0U) || (dataLenToCopy > count)) {
|
||||
if (stream->dataOffset >= dataLenToCopy) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
|
@ -141,12 +141,12 @@ static ODR_t OD_writeDisabled(OD_stream_t *stream, const void *buf,
|
|||
|
||||
/******************************************************************************/
|
||||
OD_entry_t *OD_find(OD_t *od, uint16_t index) {
|
||||
if ((od == NULL) || (od->size == 0)) {
|
||||
if ((od == NULL) || (od->size == 0U)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint16_t min = 0;
|
||||
uint16_t max = od->size - 1;
|
||||
uint16_t max = od->size - 1U;
|
||||
|
||||
/* Fast search in ordered Object Dictionary. If indexes are mixed,
|
||||
* this won't work. If Object Dictionary has up to N entries, then the
|
||||
|
|
@ -161,10 +161,10 @@ OD_entry_t *OD_find(OD_t *od, uint16_t index) {
|
|||
}
|
||||
|
||||
if (index < entry->index) {
|
||||
max = (cur > 0) ? (cur - 1) : cur;
|
||||
max = (cur > 0U) ? (cur - 1U) : cur;
|
||||
}
|
||||
else {
|
||||
min = cur + 1;
|
||||
min = cur + 1U;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ ODR_t OD_getSub(const OD_entry_t *entry, uint8_t subIndex,
|
|||
/* attribute, dataOrig and dataLength, depends on object type */
|
||||
switch (entry->odObjectType & ODT_TYPE_MASK) {
|
||||
case ODT_VAR: {
|
||||
if (subIndex > 0) { return ODR_SUB_NOT_EXIST; }
|
||||
if (subIndex > 0U) { return ODR_SUB_NOT_EXIST; }
|
||||
CO_PROGMEM OD_obj_var_t *odo = entry->odObject;
|
||||
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ ODR_t OD_getSub(const OD_entry_t *entry, uint8_t subIndex,
|
|||
if (subIndex >= entry->subEntriesCount) { return ODR_SUB_NOT_EXIST; }
|
||||
CO_PROGMEM OD_obj_array_t *odo = entry->odObject;
|
||||
|
||||
if (subIndex == 0) {
|
||||
if (subIndex == 0U) {
|
||||
stream->attribute = odo->attribute0;
|
||||
stream->dataOrig = odo->dataOrig0;
|
||||
stream->dataLength = 1;
|
||||
|
|
@ -342,10 +342,10 @@ void *OD_getPtr(const OD_entry_t *entry, uint8_t subIndex, OD_size_t len,
|
|||
errCopy = OD_getSub(entry, subIndex, &io, true);
|
||||
|
||||
if (errCopy == ODR_OK) {
|
||||
if ((stream->dataOrig == NULL) || (stream->dataLength == 0)) {
|
||||
if ((stream->dataOrig == NULL) || (stream->dataLength == 0U)) {
|
||||
errCopy = ODR_DEV_INCOMPAT;
|
||||
}
|
||||
else if ((len != 0) && (len != stream->dataLength)) {
|
||||
else if ((len != 0U) && (len != stream->dataLength)) {
|
||||
errCopy = ODR_TYPE_MISMATCH;
|
||||
}
|
||||
else { /* MISRA C 2004 14.10 */ }
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ typedef uint8_t OD_attr_t;
|
|||
|
||||
#ifndef OD_FLAGS_PDO_SIZE
|
||||
/** Size of of flagsPDO variable inside @ref OD_extension_t, from 0 to 32. */
|
||||
#define OD_FLAGS_PDO_SIZE 4
|
||||
#define OD_FLAGS_PDO_SIZE 4U
|
||||
#endif
|
||||
|
||||
#ifndef CO_PROGMEM
|
||||
|
|
@ -118,17 +118,17 @@ typedef enum {
|
|||
* Attributes (bit masks) for OD sub-object.
|
||||
*/
|
||||
typedef enum {
|
||||
ODA_SDO_R = 0x01, /**< SDO server may read from the variable */
|
||||
ODA_SDO_W = 0x02, /**< SDO server may write to the variable */
|
||||
ODA_SDO_RW = 0x03, /**< SDO server may read from or write to the variable */
|
||||
ODA_TPDO = 0x04, /**< Variable is mappable into TPDO (can be read) */
|
||||
ODA_RPDO = 0x08, /**< Variable is mappable into RPDO (can be written) */
|
||||
ODA_TRPDO = 0x0C, /**< Variable is mappable into TPDO or RPDO */
|
||||
ODA_TSRDO = 0x10, /**< Variable is mappable into transmitting SRDO */
|
||||
ODA_RSRDO = 0x20, /**< Variable is mappable into receiving SRDO */
|
||||
ODA_TRSRDO = 0x30, /**< Variable is mappable into tx or rx SRDO */
|
||||
ODA_MB = 0x40, /**< Variable is multi-byte ((u)int16_t to (u)int64_t) */
|
||||
ODA_STR = 0x80 /**< Shorter value, than specified variable size, may be
|
||||
ODA_SDO_R = 0x01U, /**< SDO server may read from the variable */
|
||||
ODA_SDO_W = 0x02U, /**< SDO server may write to the variable */
|
||||
ODA_SDO_RW = 0x03U, /**< SDO server may read from or write to the variable */
|
||||
ODA_TPDO = 0x04U, /**< Variable is mappable into TPDO (can be read) */
|
||||
ODA_RPDO = 0x08U, /**< Variable is mappable into RPDO (can be written) */
|
||||
ODA_TRPDO = 0x0CU, /**< Variable is mappable into TPDO or RPDO */
|
||||
ODA_TSRDO = 0x10U, /**< Variable is mappable into transmitting SRDO */
|
||||
ODA_RSRDO = 0x20U, /**< Variable is mappable into receiving SRDO */
|
||||
ODA_TRSRDO = 0x30U, /**< Variable is mappable into tx or rx SRDO */
|
||||
ODA_MB = 0x40U, /**< Variable is multi-byte ((u)int16_t to (u)int64_t) */
|
||||
ODA_STR = 0x80U /**< Shorter value, than specified variable size, may be
|
||||
written to the variable. SDO write will fill remaining memory with zeroes.
|
||||
Attribute is used for VISIBLE_STRING and UNICODE_STRING. */
|
||||
} OD_attributes_t;
|
||||
|
|
@ -437,7 +437,7 @@ ODR_t OD_getSub(const OD_entry_t *entry, uint8_t subIndex,
|
|||
* @return OD index
|
||||
*/
|
||||
static inline uint16_t OD_getIndex(const OD_entry_t *entry) {
|
||||
return (entry != NULL) ? entry->index : 0;
|
||||
return (entry != NULL) ? entry->index : 0U;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -467,7 +467,7 @@ static inline bool_t OD_mappable(OD_stream_t *stream) {
|
|||
* @param stream Object Dictionary stream object.
|
||||
*/
|
||||
static inline void OD_rwRestart(OD_stream_t *stream) {
|
||||
if (stream != NULL) { stream->dataOffset = 0; }
|
||||
if (stream != NULL) { stream->dataOffset = 0U; }
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -509,9 +509,9 @@ static inline uint8_t *OD_getFlagsPDO(OD_entry_t *entry) {
|
|||
*/
|
||||
static inline void OD_requestTPDO(uint8_t *flagsPDO, uint8_t subIndex) {
|
||||
#if OD_FLAGS_PDO_SIZE > 0
|
||||
if ((flagsPDO != NULL) && (subIndex < (OD_FLAGS_PDO_SIZE * 8))) {
|
||||
if ((flagsPDO != NULL) && (subIndex < (OD_FLAGS_PDO_SIZE * 8U))) {
|
||||
/* clear subIndex-th bit */
|
||||
uint8_t mask = ~(1 << (subIndex & 0x07));
|
||||
uint8_t mask = ~(1U << (subIndex & 0x07U));
|
||||
flagsPDO[subIndex >> 3] &= mask;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -531,10 +531,10 @@ static inline void OD_requestTPDO(uint8_t *flagsPDO, uint8_t subIndex) {
|
|||
*/
|
||||
static inline bool_t OD_TPDOtransmitted(uint8_t *flagsPDO, uint8_t subIndex) {
|
||||
#if OD_FLAGS_PDO_SIZE > 0
|
||||
if ((flagsPDO != NULL) && (subIndex < (OD_FLAGS_PDO_SIZE * 8))) {
|
||||
if ((flagsPDO != NULL) && (subIndex < (OD_FLAGS_PDO_SIZE * 8U))) {
|
||||
/* return true, if subIndex-th bit is set */
|
||||
uint8_t mask = 1 << (subIndex & 0x07);
|
||||
if ((flagsPDO[subIndex >> 3] & mask) != 0) {
|
||||
uint8_t mask = 1U << (subIndex & 0x07U);
|
||||
if ((flagsPDO[subIndex >> 3] & mask) != 0U) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
132
301/CO_PDO.c
132
301/CO_PDO.c
|
|
@ -102,7 +102,7 @@ static ODR_t PDOconfigMap(CO_PDO_common_t *PDO,
|
|||
}
|
||||
|
||||
/* is there a reference to the dummy entry */
|
||||
if ((index < 0x20) && (subIndex == 0)) {
|
||||
if ((index < 0x20U) && (subIndex == 0U)) {
|
||||
OD_stream_t *stream = &OD_IO->stream;
|
||||
(void)memset(stream, 0, sizeof(OD_stream_t));
|
||||
stream->dataLength = stream->dataOffset = mappedLength;
|
||||
|
|
@ -121,8 +121,8 @@ static ODR_t PDOconfigMap(CO_PDO_common_t *PDO,
|
|||
|
||||
/* verify access attributes, byte alignment and length */
|
||||
OD_attr_t testAttribute = isRPDO ? ODA_RPDO : ODA_TPDO;
|
||||
if (((OD_IOcopy.stream.attribute & testAttribute) == 0)
|
||||
|| ((mappedLengthBits & 0x07) != 0)
|
||||
if (((OD_IOcopy.stream.attribute & testAttribute) == 0U)
|
||||
|| ((mappedLengthBits & 0x07U) != 0U)
|
||||
|| (OD_IOcopy.stream.dataLength < mappedLength)
|
||||
) {
|
||||
return ODR_NO_MAP; /* Object cannot be mapped to the PDO. */
|
||||
|
|
@ -135,10 +135,10 @@ static ODR_t PDOconfigMap(CO_PDO_common_t *PDO,
|
|||
/* get TPDO request flag byte from extension */
|
||||
#if OD_FLAGS_PDO_SIZE > 0
|
||||
if (!isRPDO) {
|
||||
if ((subIndex < (OD_FLAGS_PDO_SIZE * 8)) && (entry->extension != NULL)) {
|
||||
if ((subIndex < (OD_FLAGS_PDO_SIZE * 8U)) && (entry->extension != NULL)) {
|
||||
PDO->flagPDObyte[mapIndex] =
|
||||
&entry->extension->flagsPDO[subIndex >> 3];
|
||||
PDO->flagPDObitmask[mapIndex] = 1 << (subIndex & 0x07);
|
||||
PDO->flagPDObitmask[mapIndex] = 1U << (subIndex & 0x07U);
|
||||
}
|
||||
else {
|
||||
PDO->flagPDObyte[mapIndex] = NULL;
|
||||
|
|
@ -185,7 +185,7 @@ static CO_ReturnError_t PDO_initMapping(CO_PDO_common_t *PDO,
|
|||
OD_IO_t *OD_IO = &PDO->OD_IO[i];
|
||||
uint32_t map = 0;
|
||||
|
||||
odRet = OD_get_u32(OD_PDOMapPar, i + 1, &map, true);
|
||||
odRet = OD_get_u32(OD_PDOMapPar, i + 1U, &map, true);
|
||||
if (odRet == ODR_SUB_NOT_EXIST) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ static CO_ReturnError_t PDO_initMapping(CO_PDO_common_t *PDO,
|
|||
/* indicate erroneous mapping in initialization phase */
|
||||
OD_IO->stream.dataLength = 0;
|
||||
OD_IO->stream.dataOffset = 0xFF;
|
||||
if (*erroneousMap == 0) { *erroneousMap = map; }
|
||||
if (*erroneousMap == 0U) { *erroneousMap = map; }
|
||||
}
|
||||
|
||||
if (i < mappedObjectsCount) {
|
||||
|
|
@ -209,12 +209,12 @@ static CO_ReturnError_t PDO_initMapping(CO_PDO_common_t *PDO,
|
|||
}
|
||||
}
|
||||
if ((pdoDataLength > CO_PDO_MAX_SIZE)
|
||||
|| ((pdoDataLength == 0) && (mappedObjectsCount > 0))
|
||||
|| ((pdoDataLength == 0U) && (mappedObjectsCount > 0U))
|
||||
) {
|
||||
if (*erroneousMap == 0) { *erroneousMap = 1; }
|
||||
if (*erroneousMap == 0U) { *erroneousMap = 1; }
|
||||
}
|
||||
|
||||
if (*erroneousMap == 0) {
|
||||
if (*erroneousMap == 0U) {
|
||||
PDO->dataLength = (CO_PDO_size_t)pdoDataLength;
|
||||
PDO->mappedObjectsCount = mappedObjectsCount;
|
||||
}
|
||||
|
|
@ -242,11 +242,11 @@ static ODR_t OD_write_PDO_mapping(OD_stream_t *stream, const void *buf,
|
|||
CO_PDO_common_t *PDO = stream->object;
|
||||
|
||||
/* PDO must be disabled before mapping configuration */
|
||||
if ((PDO->valid) || ((PDO->mappedObjectsCount != 0) && (stream->subIndex > 0))) {
|
||||
if ((PDO->valid) || ((PDO->mappedObjectsCount != 0U) && (stream->subIndex > 0U))) {
|
||||
return ODR_UNSUPP_ACCESS;
|
||||
}
|
||||
|
||||
if (stream->subIndex == 0) {
|
||||
if (stream->subIndex == 0U) {
|
||||
uint8_t mappedObjectsCount = CO_getUint8(buf);
|
||||
size_t pdoDataLength = 0;
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ static ODR_t OD_write_PDO_mapping(OD_stream_t *stream, const void *buf,
|
|||
if (pdoDataLength > CO_PDO_MAX_SIZE) {
|
||||
return ODR_MAP_LEN;
|
||||
}
|
||||
if ((pdoDataLength == 0) && (mappedObjectsCount > 0)) {
|
||||
if ((pdoDataLength == 0U) && (mappedObjectsCount > 0U)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ static ODR_t OD_write_PDO_mapping(OD_stream_t *stream, const void *buf,
|
|||
}
|
||||
else {
|
||||
uint32_t val = CO_getUint32(buf);
|
||||
ODR_t odRet = PDOconfigMap(PDO, val, stream->subIndex-1,
|
||||
ODR_t odRet = PDOconfigMap(PDO, val, stream->subIndex-1U,
|
||||
PDO->isRPDO, PDO->OD);
|
||||
if (odRet != ODR_OK) {
|
||||
return odRet;
|
||||
|
|
@ -416,15 +416,15 @@ static ODR_t OD_read_PDO_commParam(OD_stream_t *stream, void *buf,
|
|||
ODR_t returnCode = OD_readOriginal(stream, buf, count, countRead);
|
||||
|
||||
/* When reading COB_ID, add Node-Id to the read value, if necessary */
|
||||
if ((returnCode == ODR_OK) && (stream->subIndex == 1) && (*countRead == 4)) {
|
||||
if ((returnCode == ODR_OK) && (stream->subIndex == 1U) && (*countRead == 4U)) {
|
||||
/* Only common part of the CO_RPDO_t or CO_TPDO_t will be used */
|
||||
CO_PDO_common_t *PDO = stream->object;
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
|
||||
/* If default CAN-ID is stored in OD (without Node-ID), add Node-ID */
|
||||
if ((CAN_ID != 0) && (CAN_ID == (PDO->preDefinedCanId & 0xFF80))) {
|
||||
COB_ID = (COB_ID & 0xFFFF0000) | PDO->preDefinedCanId;
|
||||
if ((CAN_ID != 0U) && (CAN_ID == (PDO->preDefinedCanId & 0xFF80U))) {
|
||||
COB_ID = (COB_ID & 0xFFFF0000U) | PDO->preDefinedCanId;
|
||||
}
|
||||
|
||||
/* If PDO is not valid, set bit 31 */
|
||||
|
|
@ -522,7 +522,7 @@ static ODR_t OD_write_14xx(OD_stream_t *stream, const void *buf,
|
|||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
/* "count" is also verified in *_init() function */
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4)) {
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4U)) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
||||
|
|
@ -534,16 +534,16 @@ static ODR_t OD_write_14xx(OD_stream_t *stream, const void *buf,
|
|||
switch (stream->subIndex) {
|
||||
case 1: { /* COB-ID used by PDO */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* bits 11...29 must be zero, PDO must be disabled on change,
|
||||
* CAN_ID == 0 is not allowed, mapping must be configured before
|
||||
* enabling the PDO */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| (valid && PDO->valid && (CAN_ID != PDO->configuredCanId))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
|| (valid && (PDO->mappedObjectsCount == 0))
|
||||
|| (valid && (PDO->mappedObjectsCount == 0U))
|
||||
) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
|
|
@ -612,7 +612,7 @@ static ODR_t OD_write_14xx(OD_stream_t *stream, const void *buf,
|
|||
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_TIMERS_ENABLE
|
||||
case 5: { /* event-timer */
|
||||
uint32_t eventTime = CO_getUint16(buf);
|
||||
RPDO->timeoutTime_us = eventTime * 1000;
|
||||
RPDO->timeoutTime_us = eventTime * 1000U;
|
||||
RPDO->timeoutTimer = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -678,29 +678,29 @@ CO_ReturnError_t CO_RPDO_init(CO_RPDO_t *RPDO,
|
|||
odRet = OD_get_u32(OD_14xx_RPDOCommPar, 1, &COB_ID, true);
|
||||
if (odRet != ODR_OK) {
|
||||
if (errInfo != NULL) {
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_14xx_RPDOCommPar)) << 8) | 1;
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_14xx_RPDOCommPar)) << 8) | 1U;
|
||||
}
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
if (valid && ((PDO->mappedObjectsCount == 0) || (CAN_ID == 0))) {
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
if (valid && ((PDO->mappedObjectsCount == 0U) || (CAN_ID == 0U))) {
|
||||
valid = false;
|
||||
if (erroneousMap == 0) { erroneousMap = 1; }
|
||||
if (erroneousMap == 0U) { erroneousMap = 1; }
|
||||
}
|
||||
|
||||
if (erroneousMap != 0) {
|
||||
if (erroneousMap != 0U) {
|
||||
CO_errorReport(PDO->em,
|
||||
CO_EM_PDO_WRONG_MAPPING, CO_EMC_PROTOCOL_ERROR,
|
||||
(erroneousMap != 1) ? erroneousMap : COB_ID);
|
||||
(erroneousMap != 1U) ? erroneousMap : COB_ID);
|
||||
}
|
||||
if (!valid) {
|
||||
CAN_ID = 0;
|
||||
}
|
||||
|
||||
/* If default CAN-ID is stored in OD (without Node-ID), add Node-ID */
|
||||
if ((CAN_ID != 0) && (CAN_ID == (preDefinedCanId & 0xFF80))) {
|
||||
if ((CAN_ID != 0U) && (CAN_ID == (preDefinedCanId & 0xFF80U))) {
|
||||
CAN_ID = preDefinedCanId;
|
||||
}
|
||||
|
||||
|
|
@ -725,7 +725,7 @@ CO_ReturnError_t CO_RPDO_init(CO_RPDO_t *RPDO,
|
|||
odRet = OD_get_u8(OD_14xx_RPDOCommPar, 2, &transmissionType, true);
|
||||
if (odRet != ODR_OK) {
|
||||
if (errInfo != NULL) {
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_14xx_RPDOCommPar)) << 8) | 2;
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_14xx_RPDOCommPar)) << 8) | 2U;
|
||||
}
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
|
@ -739,7 +739,7 @@ CO_ReturnError_t CO_RPDO_init(CO_RPDO_t *RPDO,
|
|||
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_TIMERS_ENABLE
|
||||
uint16_t eventTime = 0;
|
||||
odRet = OD_get_u16(OD_14xx_RPDOCommPar, 5, &eventTime, true);
|
||||
RPDO->timeoutTime_us = (uint32_t)eventTime * 1000;
|
||||
RPDO->timeoutTime_us = (uint32_t)eventTime * 1000U;
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -885,7 +885,7 @@ void CO_RPDO_process(CO_RPDO_t *RPDO,
|
|||
/* verify RPDO timeout */
|
||||
(void) rpdoReceived;
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_TIMERS_ENABLE
|
||||
if (RPDO->timeoutTime_us > 0) {
|
||||
if (RPDO->timeoutTime_us > 0U) {
|
||||
if (rpdoReceived) {
|
||||
if (RPDO->timeoutTimer > RPDO->timeoutTime_us) {
|
||||
CO_errorReset(PDO->em, CO_EM_RPDO_TIME_OUT,
|
||||
|
|
@ -894,7 +894,7 @@ void CO_RPDO_process(CO_RPDO_t *RPDO,
|
|||
/* enable monitoring */
|
||||
RPDO->timeoutTimer = 1;
|
||||
}
|
||||
else if ((RPDO->timeoutTimer > 0)
|
||||
else if ((RPDO->timeoutTimer > 0U)
|
||||
&& (RPDO->timeoutTimer < RPDO->timeoutTime_us)
|
||||
) {
|
||||
RPDO->timeoutTimer += timeDifference_us;
|
||||
|
|
@ -953,7 +953,7 @@ static ODR_t OD_write_18xx(OD_stream_t *stream, const void *buf,
|
|||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
/* "count" is also verified in *_init() function */
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4)) {
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4U)) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
||||
|
|
@ -965,16 +965,16 @@ static ODR_t OD_write_18xx(OD_stream_t *stream, const void *buf,
|
|||
switch (stream->subIndex) {
|
||||
case 1: { /* COB-ID used by PDO */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* bits 11...29 must be zero, PDO must be disabled on change,
|
||||
* CAN_ID == 0 is not allowed, mapping must be configured before
|
||||
* enabling the PDO */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| (valid && (PDO->valid && (CAN_ID != PDO->configuredCanId)))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
|| (valid && (PDO->mappedObjectsCount == 0))
|
||||
|| (valid && (PDO->mappedObjectsCount == 0U))
|
||||
) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
|
|
@ -1039,14 +1039,14 @@ static ODR_t OD_write_18xx(OD_stream_t *stream, const void *buf,
|
|||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
uint32_t inhibitTime = CO_getUint16(buf);
|
||||
TPDO->inhibitTime_us = inhibitTime * 100;
|
||||
TPDO->inhibitTime_us = inhibitTime * 100U;
|
||||
TPDO->inhibitTimer = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: { /* event-timer */
|
||||
uint32_t eventTime = CO_getUint16(buf);
|
||||
TPDO->eventTime_us = eventTime * 1000;
|
||||
TPDO->eventTime_us = eventTime * 1000U;
|
||||
TPDO->eventTimer = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1056,7 +1056,7 @@ static ODR_t OD_write_18xx(OD_stream_t *stream, const void *buf,
|
|||
case 6: { /* SYNC start value */
|
||||
uint8_t syncStartValue = CO_getUint8(buf);
|
||||
|
||||
if (PDO->valid || (syncStartValue > 240)) {
|
||||
if (PDO->valid || (syncStartValue > 240U)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
TPDO->syncStartValue = syncStartValue;
|
||||
|
|
@ -1142,29 +1142,29 @@ CO_ReturnError_t CO_TPDO_init(CO_TPDO_t *TPDO,
|
|||
odRet = OD_get_u32(OD_18xx_TPDOCommPar, 1, &COB_ID, true);
|
||||
if (odRet != ODR_OK) {
|
||||
if (errInfo != NULL) {
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_18xx_TPDOCommPar)) << 8) | 1;
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_18xx_TPDOCommPar)) << 8) | 1U;
|
||||
}
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
if (valid && ((PDO->mappedObjectsCount == 0) || (CAN_ID == 0))) {
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
if (valid && ((PDO->mappedObjectsCount == 0U) || (CAN_ID == 0U))) {
|
||||
valid = false;
|
||||
if (erroneousMap == 0) { erroneousMap = 1; }
|
||||
if (erroneousMap == 0U) { erroneousMap = 1; }
|
||||
}
|
||||
|
||||
if (erroneousMap != 0) {
|
||||
if (erroneousMap != 0U) {
|
||||
CO_errorReport(PDO->em,
|
||||
CO_EM_PDO_WRONG_MAPPING, CO_EMC_PROTOCOL_ERROR,
|
||||
(erroneousMap != 1) ? erroneousMap : COB_ID);
|
||||
(erroneousMap != 1U) ? erroneousMap : COB_ID);
|
||||
}
|
||||
if (!valid) {
|
||||
CAN_ID = 0;
|
||||
}
|
||||
|
||||
/* If default CAN-ID is stored in OD (without Node-ID), add Node-ID */
|
||||
if ((CAN_ID != 0) && (CAN_ID == (preDefinedCanId & 0xFF80))) {
|
||||
if ((CAN_ID != 0U) && (CAN_ID == (preDefinedCanId & 0xFF80U))) {
|
||||
CAN_ID = preDefinedCanId;
|
||||
}
|
||||
|
||||
|
|
@ -1189,8 +1189,8 @@ CO_ReturnError_t CO_TPDO_init(CO_TPDO_t *TPDO,
|
|||
uint16_t eventTime = 0;
|
||||
odRet = OD_get_u16(OD_18xx_TPDOCommPar, 3, &inhibitTime, true);
|
||||
odRet = OD_get_u16(OD_18xx_TPDOCommPar, 5, &eventTime, true);
|
||||
TPDO->inhibitTime_us = (uint32_t)inhibitTime * 100;
|
||||
TPDO->eventTime_us = (uint32_t)eventTime * 1000;
|
||||
TPDO->inhibitTime_us = (uint32_t)inhibitTime * 100U;
|
||||
TPDO->eventTime_us = (uint32_t)eventTime * 1000U;
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -1349,10 +1349,10 @@ void CO_TPDO_process(CO_TPDO_t *TPDO,
|
|||
) {
|
||||
/* event timer */
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_TIMERS_ENABLE
|
||||
if (TPDO->eventTime_us != 0) {
|
||||
if (TPDO->eventTime_us != 0U) {
|
||||
TPDO->eventTimer = (TPDO->eventTimer > timeDifference_us)
|
||||
? (TPDO->eventTimer - timeDifference_us) : 0;
|
||||
if (TPDO->eventTimer == 0) {
|
||||
? (TPDO->eventTimer - timeDifference_us) : 0U;
|
||||
if (TPDO->eventTimer == 0U) {
|
||||
TPDO->sendRequest = true;
|
||||
}
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_FLAG_TIMERNEXT
|
||||
|
|
@ -1369,7 +1369,7 @@ void CO_TPDO_process(CO_TPDO_t *TPDO,
|
|||
for (uint8_t i = 0; i < PDO->mappedObjectsCount; i++) {
|
||||
uint8_t *flagPDObyte = PDO->flagPDObyte[i];
|
||||
if (flagPDObyte != NULL) {
|
||||
if ((*flagPDObyte & PDO->flagPDObitmask[i]) == 0) {
|
||||
if ((*flagPDObyte & PDO->flagPDObitmask[i]) == 0U) {
|
||||
TPDO->sendRequest = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1385,10 +1385,10 @@ void CO_TPDO_process(CO_TPDO_t *TPDO,
|
|||
if (TPDO->transmissionType >= CO_PDO_TRANSM_TYPE_SYNC_EVENT_LO) {
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_TIMERS_ENABLE
|
||||
TPDO->inhibitTimer = (TPDO->inhibitTimer > timeDifference_us)
|
||||
? (TPDO->inhibitTimer - timeDifference_us) : 0;
|
||||
? (TPDO->inhibitTimer - timeDifference_us) : 0U;
|
||||
|
||||
/* send TPDO */
|
||||
if (TPDO->sendRequest && (TPDO->inhibitTimer == 0)) {
|
||||
if (TPDO->sendRequest && (TPDO->inhibitTimer == 0U)) {
|
||||
CO_TPDOsend(TPDO);
|
||||
}
|
||||
|
||||
|
|
@ -1417,28 +1417,28 @@ void CO_TPDO_process(CO_TPDO_t *TPDO,
|
|||
/* send synchronous cyclic TPDO */
|
||||
else {
|
||||
/* is the start of synchronous TPDO transmission */
|
||||
if (TPDO->syncCounter == 255) {
|
||||
if ((TPDO->SYNC->counterOverflowValue != 0)
|
||||
&& (TPDO->syncStartValue != 0)
|
||||
if (TPDO->syncCounter == 255U) {
|
||||
if ((TPDO->SYNC->counterOverflowValue != 0U)
|
||||
&& (TPDO->syncStartValue != 0U)
|
||||
) {
|
||||
/* syncStartValue is in use */
|
||||
TPDO->syncCounter = 254;
|
||||
}
|
||||
else {
|
||||
/* Send first TPDO somewhere in the middle */
|
||||
TPDO->syncCounter = (TPDO->transmissionType / 2) + 1;
|
||||
TPDO->syncCounter = (TPDO->transmissionType / 2U) + 1U;
|
||||
}
|
||||
}
|
||||
/* If the syncStartValue is in use, start first TPDO after SYNC
|
||||
* with matched syncStartValue. */
|
||||
if (TPDO->syncCounter == 254) {
|
||||
if (TPDO->syncCounter == 254U) {
|
||||
if (TPDO->SYNC->counter == TPDO->syncStartValue) {
|
||||
TPDO->syncCounter = TPDO->transmissionType;
|
||||
CO_TPDOsend(TPDO);
|
||||
}
|
||||
}
|
||||
/* Send TPDO after every N-th Sync */
|
||||
else if (--TPDO->syncCounter == 0) {
|
||||
else if (--TPDO->syncCounter == 0U) {
|
||||
TPDO->syncCounter = TPDO->transmissionType;
|
||||
CO_TPDOsend(TPDO);
|
||||
}
|
||||
|
|
|
|||
18
301/CO_PDO.h
18
301/CO_PDO.h
|
|
@ -135,13 +135,13 @@ extern "C" {
|
|||
|
||||
/** Maximum size of PDO message, 8 for standard CAN */
|
||||
#ifndef CO_PDO_MAX_SIZE
|
||||
#define CO_PDO_MAX_SIZE 8
|
||||
#define CO_PDO_MAX_SIZE 8U
|
||||
#endif
|
||||
|
||||
/** Maximum number of entries, which can be mapped to PDO, 8 for standard CAN,
|
||||
* may be less to preserve RAM usage */
|
||||
#ifndef CO_PDO_MAX_MAPPED_ENTRIES
|
||||
#define CO_PDO_MAX_MAPPED_ENTRIES 8
|
||||
#define CO_PDO_MAX_MAPPED_ENTRIES 8U
|
||||
#endif
|
||||
|
||||
/** Number of CANopen RPDO objects, which uses default CAN indentifiers.
|
||||
|
|
@ -152,7 +152,7 @@ extern "C" {
|
|||
* identifiers. In that case RPDO5 has CAN_ID=0x200+NodeId+1, RPDO6 has
|
||||
* CAN_ID=0x300+NodeId+1, RPDO9 has CAN_ID=0x200+NodeId+2 and so on. */
|
||||
#ifndef CO_RPDO_DEFAULT_CANID_COUNT
|
||||
#define CO_RPDO_DEFAULT_CANID_COUNT 4
|
||||
#define CO_RPDO_DEFAULT_CANID_COUNT 4U
|
||||
#endif
|
||||
|
||||
/** Number of CANopen TPDO objects, which uses default CAN indentifiers.
|
||||
|
|
@ -161,7 +161,7 @@ extern "C" {
|
|||
* TPDO9 has CAN_ID=0x180+NodeId+2 and so on.
|
||||
* For description see @ref CO_RPDO_DEFAULT_CANID_COUNT. */
|
||||
#ifndef CO_TPDO_DEFAULT_CANID_COUNT
|
||||
#define CO_TPDO_DEFAULT_CANID_COUNT 4
|
||||
#define CO_TPDO_DEFAULT_CANID_COUNT 4U
|
||||
#endif
|
||||
|
||||
#ifndef CO_PDO_OWN_TYPES
|
||||
|
|
@ -173,13 +173,13 @@ typedef uint8_t CO_PDO_size_t;
|
|||
* PDO transmission Types
|
||||
*/
|
||||
typedef enum {
|
||||
CO_PDO_TRANSM_TYPE_SYNC_ACYCLIC = 0, /**< synchronous (acyclic) */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_1 = 1, /**< synchronous (cyclic every sync) */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_240 = 0xF0, /**< synchronous (cyclic every 240-th
|
||||
CO_PDO_TRANSM_TYPE_SYNC_ACYCLIC = 0U, /**< synchronous (acyclic) */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_1 = 1U, /**< synchronous (cyclic every sync) */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_240 = 0xF0U, /**< synchronous (cyclic every 240-th
|
||||
sync) */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_EVENT_LO = 0xFE, /**< event-driven, lower value
|
||||
CO_PDO_TRANSM_TYPE_SYNC_EVENT_LO = 0xFEU, /**< event-driven, lower value
|
||||
(manufacturer specific), */
|
||||
CO_PDO_TRANSM_TYPE_SYNC_EVENT_HI = 0xFF /**< event-driven, higher value
|
||||
CO_PDO_TRANSM_TYPE_SYNC_EVENT_HI = 0xFFU /**< event-driven, higher value
|
||||
(device profile and application profile specific) */
|
||||
} CO_PDO_transmissionTypes_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ static void CO_SDOclient_receive(void *object, void *msg) {
|
|||
/* Ignore messages in idle state and messages with wrong length. Ignore
|
||||
* message also if previous message was not processed yet and not abort */
|
||||
if ((SDO_C->state != CO_SDO_ST_IDLE) && (DLC == 8U)
|
||||
&& (!CO_FLAG_READ(SDO_C->CANrxNew) || (data[0] == 0x80))
|
||||
&& (!CO_FLAG_READ(SDO_C->CANrxNew) || (data[0] == 0x80U))
|
||||
) {
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
if ((data[0] == 0x80) /* abort from server */
|
||||
if ((data[0] == 0x80U) /* abort from server */
|
||||
|| ((SDO_C->state != CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_SREQ)
|
||||
&& (SDO_C->state != CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_CRSP))
|
||||
) {
|
||||
|
|
@ -92,18 +92,18 @@ static void CO_SDOclient_receive(void *object, void *msg) {
|
|||
else if (SDO_C->state == CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_SREQ) {
|
||||
/* block upload, copy data directly */
|
||||
CO_SDO_state_t state = CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_SREQ;
|
||||
uint8_t seqno = data[0] & 0x7F;
|
||||
uint8_t seqno = data[0] & 0x7FU;
|
||||
SDO_C->timeoutTimer = 0;
|
||||
SDO_C->block_timeoutTimer = 0;
|
||||
|
||||
/* verify if sequence number is correct */
|
||||
if ((seqno <= SDO_C->block_blksize)
|
||||
&& (seqno == (SDO_C->block_seqno + 1))
|
||||
&& (seqno == (SDO_C->block_seqno + 1U))
|
||||
) {
|
||||
SDO_C->block_seqno = seqno;
|
||||
|
||||
/* is this the last segment? */
|
||||
if ((data[0] & 0x80) != 0) {
|
||||
if ((data[0] & 0x80U) != 0U) {
|
||||
/* copy data to temporary buffer, because we don't know the
|
||||
* number of bytes not containing data */
|
||||
(void)memcpy((void *)&SDO_C->block_dataUploadLast[0],
|
||||
|
|
@ -117,7 +117,7 @@ static void CO_SDOclient_receive(void *object, void *msg) {
|
|||
CO_fifo_write(&SDO_C->bufFifo,
|
||||
&data[1],
|
||||
7, &SDO_C->block_crc);
|
||||
SDO_C->sizeTran += 7;
|
||||
SDO_C->sizeTran += 7U;
|
||||
/* all segments in sub-block has been transferred */
|
||||
if (seqno == SDO_C->block_blksize) {
|
||||
state = CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_CRSP;
|
||||
|
|
@ -189,12 +189,12 @@ static ODR_t OD_write_1280(OD_stream_t *stream, const void *buf,
|
|||
|
||||
case 1: { /* COB-ID client -> server */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDClientToServer&0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDClientToServer & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* SDO client must not be valid when changing COB_ID */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| (valid && SDO_C->valid && (CAN_ID != CAN_ID_cur))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
) {
|
||||
|
|
@ -209,12 +209,12 @@ static ODR_t OD_write_1280(OD_stream_t *stream, const void *buf,
|
|||
|
||||
case 2: { /* COB-ID server -> client */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDServerToClient&0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDServerToClient & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* SDO client must not be valid when changing COB_ID */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| (valid && SDO_C->valid && (CAN_ID != CAN_ID_cur))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
) {
|
||||
|
|
@ -229,7 +229,7 @@ static ODR_t OD_write_1280(OD_stream_t *stream, const void *buf,
|
|||
|
||||
case 3: { /* Node-ID of the SDO server */
|
||||
uint8_t nodeId = CO_getUint8(buf);
|
||||
if (nodeId > 127) {
|
||||
if (nodeId > 127U) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
SDO_C->nodeIDOfTheSDOServer = nodeId;
|
||||
|
|
@ -260,7 +260,7 @@ CO_ReturnError_t CO_SDOclient_init(CO_SDOclient_t *SDO_C,
|
|||
/* verify arguments */
|
||||
if ((SDO_C == NULL) || (OD_1280_SDOcliPar == NULL)
|
||||
|| (OD_getIndex(OD_1280_SDOcliPar) < OD_H1280_SDO_CLIENT_1_PARAM)
|
||||
|| (OD_getIndex(OD_1280_SDOcliPar) > (OD_H1280_SDO_CLIENT_1_PARAM + 0x7F))
|
||||
|| (OD_getIndex(OD_1280_SDOcliPar) > (OD_H1280_SDO_CLIENT_1_PARAM + 0x7FU))
|
||||
|| (CANdevRx==NULL) || (CANdevTx==NULL)
|
||||
) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
|
|
@ -292,7 +292,7 @@ CO_ReturnError_t CO_SDOclient_init(CO_SDOclient_t *SDO_C,
|
|||
ODR_t odRet2 = OD_get_u32(OD_1280_SDOcliPar, 2, &COB_IDServerToClient, true);
|
||||
ODR_t odRet3 = OD_get_u8(OD_1280_SDOcliPar, 3, &nodeIDOfTheSDOServer, true);
|
||||
|
||||
if ((odRet0 != ODR_OK) || (maxSubIndex != 3)
|
||||
if ((odRet0 != ODR_OK) || (maxSubIndex != 3U)
|
||||
|| (odRet1 != ODR_OK) || (odRet2 != ODR_OK) || (odRet3 != ODR_OK)
|
||||
) {
|
||||
if (errInfo != NULL) *errInfo = OD_getIndex(OD_1280_SDOcliPar);
|
||||
|
|
@ -384,11 +384,11 @@ CO_SDO_return_t CO_SDOclient_setup(CO_SDOclient_t *SDO_C,
|
|||
#endif
|
||||
|
||||
/* verify valid bit */
|
||||
uint16_t CanIdC2S = ((COB_IDClientToServer & 0x80000000L) == 0) ?
|
||||
(uint16_t)(COB_IDClientToServer & 0x7FF) : 0;
|
||||
uint16_t CanIdS2C = ((COB_IDServerToClient & 0x80000000L) == 0) ?
|
||||
(uint16_t)(COB_IDServerToClient & 0x7FF) : 0;
|
||||
if ((CanIdC2S != 0) && (CanIdS2C != 0)) {
|
||||
uint16_t CanIdC2S = ((COB_IDClientToServer & 0x80000000UL) == 0U) ?
|
||||
(uint16_t)(COB_IDClientToServer & 0x7FFU) : 0U;
|
||||
uint16_t CanIdS2C = ((COB_IDServerToClient & 0x80000000UL) == 0U) ?
|
||||
(uint16_t)(COB_IDServerToClient & 0x7FFU) : 0U;
|
||||
if ((CanIdC2S != 0U) && (CanIdS2C != 0U)) {
|
||||
SDO_C->valid = true;
|
||||
}
|
||||
else {
|
||||
|
|
@ -447,14 +447,14 @@ CO_SDO_return_t CO_SDOclientDownloadInitiate(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->sizeInd = sizeIndicated;
|
||||
SDO_C->sizeTran = 0;
|
||||
SDO_C->finished = false;
|
||||
SDO_C->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000;
|
||||
SDO_C->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000U;
|
||||
SDO_C->timeoutTimer = 0;
|
||||
CO_fifo_reset(&SDO_C->bufFifo);
|
||||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_LOCAL
|
||||
/* if node-ID of the SDO server is the same as node-ID of this node, then
|
||||
* transfer data within this node */
|
||||
if ((SDO_C->OD != NULL) && (SDO_C->nodeId != 0)
|
||||
if ((SDO_C->OD != NULL) && (SDO_C->nodeId != 0U)
|
||||
&& (SDO_C->nodeIDOfTheSDOServer == SDO_C->nodeId)
|
||||
) {
|
||||
SDO_C->OD_IO.write = NULL;
|
||||
|
|
@ -463,7 +463,7 @@ CO_SDO_return_t CO_SDOclientDownloadInitiate(CO_SDOclient_t *SDO_C,
|
|||
else
|
||||
#endif
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
if (blockEnable && ((sizeIndicated == 0) ||
|
||||
if (blockEnable && ((sizeIndicated == 0U) ||
|
||||
(sizeIndicated > CO_CONFIG_SDO_CLI_PST))
|
||||
) {
|
||||
SDO_C->state = CO_SDO_ST_DOWNLOAD_BLK_INITIATE_REQ;
|
||||
|
|
@ -487,7 +487,7 @@ void CO_SDOclientDownloadInitiateSize(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->sizeInd = sizeIndicated;
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
if ((SDO_C->state == CO_SDO_ST_DOWNLOAD_BLK_INITIATE_REQ)
|
||||
&& (sizeIndicated > 0) && (sizeIndicated <= CO_CONFIG_SDO_CLI_PST)
|
||||
&& (sizeIndicated > 0U) && (sizeIndicated <= CO_CONFIG_SDO_CLI_PST)
|
||||
) {
|
||||
SDO_C->state = CO_SDO_ST_DOWNLOAD_INITIATE_REQ;
|
||||
}
|
||||
|
|
@ -566,19 +566,19 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->sizeTran += count;
|
||||
|
||||
/* error: no data */
|
||||
if (count == 0) {
|
||||
if (count == 0U) {
|
||||
abortCode = CO_SDO_AB_DEVICE_INCOMPAT;
|
||||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
}
|
||||
/* verify if sizeTran is too large */
|
||||
else if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
else if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
SDO_C->sizeTran -= count;
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
}
|
||||
/* Verify sizeTran is too small in last segment of data */
|
||||
else if (!bufferPartial
|
||||
&& (SDO_C->sizeInd > 0) && (SDO_C->sizeTran < SDO_C->sizeInd)
|
||||
&& (SDO_C->sizeInd > 0U) && (SDO_C->sizeTran < SDO_C->sizeInd)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_DATA_SHORT;
|
||||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
|
|
@ -598,18 +598,18 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
* bytes to terminate (unicode) string. Shorten also OD data
|
||||
* size, (temporary, send info about EOF into OD_IO.write) */
|
||||
if (((SDO_C->OD_IO.stream.attribute & ODA_STR) != 0)
|
||||
&& ((sizeInOd == 0) || (SDO_C->sizeTran < sizeInOd))
|
||||
&& ((sizeInOd == 0U) || (SDO_C->sizeTran < sizeInOd))
|
||||
) {
|
||||
buf[count++] = 0;
|
||||
SDO_C->sizeTran++;
|
||||
if ((sizeInOd == 0) || (sizeInOd > SDO_C->sizeTran)) {
|
||||
if ((sizeInOd == 0U) || (sizeInOd > SDO_C->sizeTran)) {
|
||||
buf[count++] = 0;
|
||||
SDO_C->sizeTran++;
|
||||
}
|
||||
SDO_C->OD_IO.stream.dataLength = (OD_size_t)SDO_C->sizeTran;
|
||||
}
|
||||
/* Indicate OD data size, if necessary. Used for EOF check. */
|
||||
else if (sizeInOd == 0) {
|
||||
else if (sizeInOd == 0U) {
|
||||
SDO_C->OD_IO.stream.dataLength = (OD_size_t)SDO_C->sizeTran;
|
||||
}
|
||||
/* Verify if size of data downloaded matches data size in OD. */
|
||||
|
|
@ -672,7 +672,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
/* CAN data received ******************************************************/
|
||||
else if (CO_FLAG_READ(SDO_C->CANrxNew)) {
|
||||
/* is SDO abort */
|
||||
if (SDO_C->CANrxData[0] == 0x80) {
|
||||
if (SDO_C->CANrxData[0] == 0x80U) {
|
||||
uint32_t code;
|
||||
(void)memcpy(&code, &SDO_C->CANrxData[4], sizeof(code));
|
||||
abortCode = (CO_SDO_abortCode_t)CO_SWAP_32(code);
|
||||
|
|
@ -686,7 +686,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
else switch (SDO_C->state) {
|
||||
case CO_SDO_ST_DOWNLOAD_INITIATE_RSP: {
|
||||
if (SDO_C->CANrxData[0] == 0x60) {
|
||||
if (SDO_C->CANrxData[0] == 0x60U) {
|
||||
/* verify index and subindex */
|
||||
uint16_t index;
|
||||
uint8_t subindex;
|
||||
|
|
@ -725,15 +725,15 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_SEGMENTED
|
||||
case CO_SDO_ST_DOWNLOAD_SEGMENT_RSP: {
|
||||
if ((SDO_C->CANrxData[0] & 0xEF) == 0x20) {
|
||||
if ((SDO_C->CANrxData[0] & 0xEFU) == 0x20U) {
|
||||
/* verify and alternate toggle bit */
|
||||
uint8_t toggle = SDO_C->CANrxData[0] & 0x10;
|
||||
uint8_t toggle = SDO_C->CANrxData[0] & 0x10U;
|
||||
if (toggle != SDO_C->toggle) {
|
||||
abortCode = CO_SDO_AB_TOGGLE_BIT;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
}
|
||||
SDO_C->toggle = (toggle == 0x00) ? 0x10 : 0x00;
|
||||
SDO_C->toggle = (toggle == 0x00U) ? 0x10 : 0x00;
|
||||
|
||||
/* is end of transfer? */
|
||||
if (SDO_C->finished) {
|
||||
|
|
@ -754,7 +754,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_INITIATE_RSP: {
|
||||
if ((SDO_C->CANrxData[0] & 0xFB) == 0xA0) {
|
||||
if ((SDO_C->CANrxData[0] & 0xFBU) == 0xA0U) {
|
||||
/* verify index and subindex */
|
||||
uint16_t index;
|
||||
uint8_t subindex;
|
||||
|
|
@ -769,7 +769,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
SDO_C->block_crc = 0;
|
||||
SDO_C->block_blksize = SDO_C->CANrxData[4];
|
||||
if ((SDO_C->block_blksize < 1) || (SDO_C->block_blksize > 127))
|
||||
if ((SDO_C->block_blksize < 1U) || (SDO_C->block_blksize > 127U))
|
||||
SDO_C->block_blksize = 127;
|
||||
SDO_C->block_seqno = 0;
|
||||
CO_fifo_altBegin(&SDO_C->bufFifo, 0);
|
||||
|
|
@ -784,17 +784,17 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_REQ:
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_RSP: {
|
||||
if (SDO_C->CANrxData[0] == 0xA2) {
|
||||
if (SDO_C->CANrxData[0] == 0xA2U) {
|
||||
/* check number of segments */
|
||||
if (SDO_C->CANrxData[1] < SDO_C->block_seqno) {
|
||||
/* NOT all segments transferred successfully.
|
||||
* Re-transmit data after erroneous segment. */
|
||||
size_t cntFailed = SDO_C->block_seqno
|
||||
- SDO_C->CANrxData[1];
|
||||
cntFailed = (cntFailed * 7) - SDO_C->block_noData;
|
||||
cntFailed = (cntFailed * 7U) - SDO_C->block_noData;
|
||||
SDO_C->sizeTran -= cntFailed;
|
||||
CO_fifo_altBegin(&SDO_C->bufFifo,
|
||||
(size_t)SDO_C->CANrxData[1] * 7);
|
||||
(size_t)SDO_C->CANrxData[1] * 7U);
|
||||
SDO_C->finished = false;
|
||||
}
|
||||
else if (SDO_C->CANrxData[1] > SDO_C->block_seqno) {
|
||||
|
|
@ -824,7 +824,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_END_RSP: {
|
||||
if (SDO_C->CANrxData[0] == 0xA1) {
|
||||
if (SDO_C->CANrxData[0] == 0xA1U) {
|
||||
/* SDO block download successfully transferred */
|
||||
SDO_C->state = CO_SDO_ST_IDLE;
|
||||
ret = CO_SDO_RT_ok_communicationEnd;
|
||||
|
|
@ -892,13 +892,13 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
count = CO_fifo_getOccupied(&SDO_C->bufFifo);
|
||||
|
||||
/* is expedited transfer, <= 4bytes of data */
|
||||
if (((SDO_C->sizeInd == 0) && (count <= 4))
|
||||
|| ((SDO_C->sizeInd > 0) && (SDO_C->sizeInd <= 4))
|
||||
if (((SDO_C->sizeInd == 0U) && (count <= 4U))
|
||||
|| ((SDO_C->sizeInd > 0U) && (SDO_C->sizeInd <= 4U))
|
||||
) {
|
||||
SDO_C->CANtxBuff->data[0] |= 0x02;
|
||||
SDO_C->CANtxBuff->data[0] |= 0x02U;
|
||||
|
||||
/* verify length, indicate data size */
|
||||
if ((count == 0) || ((SDO_C->sizeInd > 0) &&
|
||||
if ((count == 0U) || ((SDO_C->sizeInd > 0U) &&
|
||||
(SDO_C->sizeInd != count))
|
||||
) {
|
||||
SDO_C->state = CO_SDO_ST_IDLE;
|
||||
|
|
@ -906,8 +906,8 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
break;
|
||||
}
|
||||
if (SDO_C->sizeInd > 0) {
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01 | ((4 - count) << 2);
|
||||
if (SDO_C->sizeInd > 0U) {
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01U | ((4U - count) << 2);
|
||||
}
|
||||
|
||||
/* copy data */
|
||||
|
|
@ -919,9 +919,9 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
else {
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_SEGMENTED
|
||||
/* segmented transfer, indicate data size */
|
||||
if (SDO_C->sizeInd > 0) {
|
||||
if (SDO_C->sizeInd > 0U) {
|
||||
uint32_t size = CO_SWAP_32((uint32_t)SDO_C->sizeInd);
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01;
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01U;
|
||||
(void)memcpy(&SDO_C->CANtxBuff->data[4], &size, sizeof(size));
|
||||
}
|
||||
#else
|
||||
|
|
@ -948,7 +948,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
/* verify if sizeTran is too large */
|
||||
SDO_C->sizeTran += count;
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
SDO_C->sizeTran -= count;
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -956,16 +956,16 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
/* SDO command specifier */
|
||||
SDO_C->CANtxBuff->data[0] = (uint8_t)(SDO_C->toggle | ((7 - count) << 1));
|
||||
SDO_C->CANtxBuff->data[0] = (uint8_t)(SDO_C->toggle | ((7U - count) << 1));
|
||||
|
||||
/* is end of transfer? Verify also sizeTran */
|
||||
if ((CO_fifo_getOccupied(&SDO_C->bufFifo) == 0) && !bufferPartial) {
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran < SDO_C->sizeInd)) {
|
||||
if ((CO_fifo_getOccupied(&SDO_C->bufFifo) == 0U) && !bufferPartial) {
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran < SDO_C->sizeInd)) {
|
||||
abortCode = CO_SDO_AB_DATA_SHORT;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
}
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01;
|
||||
SDO_C->CANtxBuff->data[0] |= 0x01U;
|
||||
SDO_C->finished = true;
|
||||
}
|
||||
|
||||
|
|
@ -985,9 +985,9 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->CANtxBuff->data[3] = SDO_C->subIndex;
|
||||
|
||||
/* indicate data size */
|
||||
if (SDO_C->sizeInd > 0) {
|
||||
if (SDO_C->sizeInd > 0U) {
|
||||
uint32_t size = CO_SWAP_32((uint32_t)SDO_C->sizeInd);
|
||||
SDO_C->CANtxBuff->data[0] |= 0x02;
|
||||
SDO_C->CANtxBuff->data[0] |= 0x02U;
|
||||
(void)memcpy(&SDO_C->CANtxBuff->data[4], &size, sizeof(size));
|
||||
}
|
||||
|
||||
|
|
@ -999,7 +999,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_REQ: {
|
||||
if ((CO_fifo_altGetOccupied(&SDO_C->bufFifo) < 7) && bufferPartial) {
|
||||
if ((CO_fifo_altGetOccupied(&SDO_C->bufFifo) < 7U) && bufferPartial) {
|
||||
/* wait until data are refilled */
|
||||
break;
|
||||
}
|
||||
|
|
@ -1008,11 +1008,11 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
/* get up to 7 data bytes */
|
||||
count = CO_fifo_altRead(&SDO_C->bufFifo,
|
||||
&SDO_C->CANtxBuff->data[1], 7);
|
||||
SDO_C->block_noData = (uint8_t)(7 - count);
|
||||
SDO_C->block_noData = (uint8_t)(7U - count);
|
||||
|
||||
/* verify if sizeTran is too large */
|
||||
SDO_C->sizeTran += count;
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
SDO_C->sizeTran -= count;
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -1020,13 +1020,13 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
/* is end of transfer? Verify also sizeTran */
|
||||
if ((CO_fifo_altGetOccupied(&SDO_C->bufFifo) == 0) && !bufferPartial){
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran < SDO_C->sizeInd)) {
|
||||
if ((CO_fifo_altGetOccupied(&SDO_C->bufFifo) == 0U) && !bufferPartial){
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran < SDO_C->sizeInd)) {
|
||||
abortCode = CO_SDO_AB_DATA_SHORT;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
}
|
||||
SDO_C->CANtxBuff->data[0] |= 0x80;
|
||||
SDO_C->CANtxBuff->data[0] |= 0x80U;
|
||||
SDO_C->finished = true;
|
||||
SDO_C->state = CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_RSP;
|
||||
}
|
||||
|
|
@ -1049,7 +1049,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
case CO_SDO_ST_DOWNLOAD_BLK_END_REQ: {
|
||||
SDO_C->CANtxBuff->data[0] = 0xC1 | (SDO_C->block_noData << 2);
|
||||
SDO_C->CANtxBuff->data[0] = 0xC1U | (SDO_C->block_noData << 2);
|
||||
SDO_C->CANtxBuff->data[1] = (uint8_t) SDO_C->block_crc;
|
||||
SDO_C->CANtxBuff->data[2] = (uint8_t) (SDO_C->block_crc >> 8);
|
||||
|
||||
|
|
@ -1120,16 +1120,16 @@ CO_SDO_return_t CO_SDOclientUploadInitiate(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->sizeTran = 0;
|
||||
SDO_C->finished = false;
|
||||
CO_fifo_reset(&SDO_C->bufFifo);
|
||||
SDO_C->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000;
|
||||
SDO_C->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000U;
|
||||
SDO_C->timeoutTimer = 0;
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
SDO_C->block_SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 700;
|
||||
SDO_C->block_SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 700U;
|
||||
#endif
|
||||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_LOCAL
|
||||
/* if node-ID of the SDO server is the same as node-ID of this node, then
|
||||
* transfer data within this node */
|
||||
if (((SDO_C->OD != NULL) && (SDO_C->nodeId != 0))
|
||||
if (((SDO_C->OD != NULL) && (SDO_C->nodeId != 0U))
|
||||
&& (SDO_C->nodeIDOfTheSDOServer == SDO_C->nodeId)
|
||||
) {
|
||||
SDO_C->OD_IO.read = NULL;
|
||||
|
|
@ -1205,7 +1205,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
size_t countFifo = CO_fifo_getSpace(&SDO_C->bufFifo);
|
||||
|
||||
/* skip copying if buffer full */
|
||||
if (countFifo == 0) {
|
||||
if (countFifo == 0U) {
|
||||
ret = CO_SDO_RT_uploadDataBufferFull;
|
||||
}
|
||||
/* read data, in several passes if necessary */
|
||||
|
|
@ -1213,7 +1213,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
/* Get size of data in Object Dictionary. If size is not indicated
|
||||
* use maximum SDO client buffer size. Prepare temp buffer. */
|
||||
OD_size_t countData = SDO_C->OD_IO.stream.dataLength;
|
||||
OD_size_t countBuf = ((countData > 0) && (countData <= countFifo))
|
||||
OD_size_t countBuf = ((countData > 0U) && (countData <= countFifo))
|
||||
? countData : (OD_size_t)countFifo;
|
||||
OD_size_t countRd = 0;
|
||||
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1];
|
||||
|
|
@ -1230,12 +1230,12 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
else {
|
||||
/* if data is string, send only data up to null termination */
|
||||
if ((countRd > 0)
|
||||
if ((countRd > 0U)
|
||||
&& ((SDO_C->OD_IO.stream.attribute & ODA_STR) != 0)
|
||||
) {
|
||||
buf[countRd] = 0; /* (buf is one byte larger) */
|
||||
OD_size_t countStr = (OD_size_t)strlen((char *)buf);
|
||||
if (countStr == 0) countStr = 1; /* no zero length */
|
||||
if (countStr == 0U) countStr = 1; /* no zero length */
|
||||
if (countStr < countRd) {
|
||||
/* string terminator found, finish read, shorten data */
|
||||
countRd = countStr;
|
||||
|
|
@ -1250,14 +1250,14 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
/* verify if size of data uploaded is too large */
|
||||
SDO_C->sizeInd = SDO_C->OD_IO.stream.dataLength;
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
}
|
||||
/* If no more segments to be upload, finish */
|
||||
else if (odRet == ODR_OK) {
|
||||
/* verify size of data uploaded */
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran < SDO_C->sizeInd)){
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran < SDO_C->sizeInd)){
|
||||
abortCode = CO_SDO_AB_DATA_SHORT;
|
||||
ret = CO_SDO_RT_endedWithClientAbort;
|
||||
}
|
||||
|
|
@ -1287,7 +1287,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
/* CAN data received ******************************************************/
|
||||
else if (CO_FLAG_READ(SDO_C->CANrxNew)) {
|
||||
/* is SDO abort */
|
||||
if (SDO_C->CANrxData[0] == 0x80) {
|
||||
if (SDO_C->CANrxData[0] == 0x80U) {
|
||||
uint32_t code;
|
||||
(void)memcpy(&code, &SDO_C->CANrxData[4], sizeof(code));
|
||||
abortCode = (CO_SDO_abortCode_t)CO_SWAP_32(code);
|
||||
|
|
@ -1301,7 +1301,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
else switch (SDO_C->state) {
|
||||
case CO_SDO_ST_UPLOAD_INITIATE_RSP: {
|
||||
if ((SDO_C->CANrxData[0] & 0xF0) == 0x40) {
|
||||
if ((SDO_C->CANrxData[0] & 0xF0U) == 0x40U) {
|
||||
/* verify index and subindex */
|
||||
uint16_t index;
|
||||
uint8_t subindex;
|
||||
|
|
@ -1314,12 +1314,12 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
break;
|
||||
}
|
||||
|
||||
if (SDO_C->CANrxData[0] & 0x02) {
|
||||
if (SDO_C->CANrxData[0] & 0x02U) {
|
||||
/* Expedited transfer */
|
||||
size_t count = 4;
|
||||
/* is size indicated? */
|
||||
if (SDO_C->CANrxData[0] & 0x01) {
|
||||
count -= (SDO_C->CANrxData[0] >> 2) & 0x03;
|
||||
if (SDO_C->CANrxData[0] & 0x01U) {
|
||||
count -= (SDO_C->CANrxData[0] >> 2) & 0x03U;
|
||||
}
|
||||
/* copy data, indicate size and finish */
|
||||
CO_fifo_write(&SDO_C->bufFifo,
|
||||
|
|
@ -1332,7 +1332,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
else {
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_SEGMENTED
|
||||
/* segmented transfer, is size indicated? */
|
||||
if (SDO_C->CANrxData[0] & 0x01) {
|
||||
if (SDO_C->CANrxData[0] & 0x01U) {
|
||||
uint32_t size;
|
||||
(void)memcpy(&size, &SDO_C->CANrxData[4], sizeof(size));
|
||||
SDO_C->sizeInd = CO_SWAP_32(size);
|
||||
|
|
@ -1354,20 +1354,20 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_SEGMENTED
|
||||
case CO_SDO_ST_UPLOAD_SEGMENT_RSP: {
|
||||
if ((SDO_C->CANrxData[0] & 0xE0) == 0x00) {
|
||||
if ((SDO_C->CANrxData[0] & 0xE0U) == 0x00U) {
|
||||
size_t count, countWr;
|
||||
|
||||
/* verify and alternate toggle bit */
|
||||
uint8_t toggle = SDO_C->CANrxData[0] & 0x10;
|
||||
uint8_t toggle = SDO_C->CANrxData[0] & 0x10U;
|
||||
if (toggle != SDO_C->toggle) {
|
||||
abortCode = CO_SDO_AB_TOGGLE_BIT;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
}
|
||||
SDO_C->toggle = (toggle == 0x00) ? 0x10 : 0x00;
|
||||
SDO_C->toggle = (toggle == 0x00U) ? 0x10 : 0x00;
|
||||
|
||||
/* get data size and write data to the buffer */
|
||||
count = 7 - ((SDO_C->CANrxData[0] >> 1) & 0x07);
|
||||
count = 7U - ((SDO_C->CANrxData[0] >> 1) & 0x07U);
|
||||
countWr = CO_fifo_write(&SDO_C->bufFifo,
|
||||
&SDO_C->CANrxData[1],
|
||||
count, NULL);
|
||||
|
|
@ -1381,7 +1381,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
/* verify if size of data uploaded is too large */
|
||||
if ((SDO_C->sizeInd > 0)
|
||||
if ((SDO_C->sizeInd > 0U)
|
||||
&& (SDO_C->sizeTran > SDO_C->sizeInd)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
|
|
@ -1390,9 +1390,9 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
/* If no more segments to be upload, finish */
|
||||
if (SDO_C->CANrxData[0] & 0x01) {
|
||||
if (SDO_C->CANrxData[0] & 0x01U) {
|
||||
/* verify size of data uploaded */
|
||||
if ((SDO_C->sizeInd > 0)
|
||||
if ((SDO_C->sizeInd > 0U)
|
||||
&& (SDO_C->sizeTran < SDO_C->sizeInd)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_DATA_SHORT;
|
||||
|
|
@ -1416,17 +1416,17 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK
|
||||
case CO_SDO_ST_UPLOAD_BLK_INITIATE_RSP: {
|
||||
if ((SDO_C->CANrxData[0] & 0xF9) == 0xC0) {
|
||||
if ((SDO_C->CANrxData[0] & 0xF9U) == 0xC0U) {
|
||||
uint16_t index;
|
||||
uint8_t subindex;
|
||||
|
||||
/* get server CRC support info and data size */
|
||||
if ((SDO_C->CANrxData[0] & 0x04) != 0) {
|
||||
if ((SDO_C->CANrxData[0] & 0x04U) != 0U) {
|
||||
SDO_C->block_crcEnabled = true;
|
||||
} else {
|
||||
SDO_C->block_crcEnabled = false;
|
||||
}
|
||||
if (SDO_C->CANrxData[0] & 0x02) {
|
||||
if (SDO_C->CANrxData[0] & 0x02U) {
|
||||
uint32_t size;
|
||||
(void)memcpy(&size, &SDO_C->CANrxData[4], sizeof(size));
|
||||
SDO_C->sizeInd = CO_SWAP_32(size);
|
||||
|
|
@ -1445,7 +1445,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
}
|
||||
/* switch to regular transfer, CO_SDO_ST_UPLOAD_INITIATE_RSP */
|
||||
else if ((SDO_C->CANrxData[0] & 0xF0) == 0x40) {
|
||||
else if ((SDO_C->CANrxData[0] & 0xF0U) == 0x40U) {
|
||||
/* verify index and subindex */
|
||||
uint16_t index;
|
||||
uint8_t subindex;
|
||||
|
|
@ -1458,12 +1458,12 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
break;
|
||||
}
|
||||
|
||||
if (SDO_C->CANrxData[0] & 0x02) {
|
||||
if (SDO_C->CANrxData[0] & 0x02U) {
|
||||
/* Expedited transfer */
|
||||
size_t count = 4;
|
||||
/* is size indicated? */
|
||||
if (SDO_C->CANrxData[0] & 0x01) {
|
||||
count -= (SDO_C->CANrxData[0] >> 2) & 0x03;
|
||||
if (SDO_C->CANrxData[0] & 0x01U) {
|
||||
count -= (SDO_C->CANrxData[0] >> 2) & 0x03U;
|
||||
}
|
||||
/* copy data, indicate size and finish */
|
||||
CO_fifo_write(&SDO_C->bufFifo,
|
||||
|
|
@ -1475,7 +1475,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
else {
|
||||
/* segmented transfer, is size indicated? */
|
||||
if (SDO_C->CANrxData[0] & 0x01) {
|
||||
if (SDO_C->CANrxData[0] & 0x01U) {
|
||||
uint32_t size;
|
||||
(void)memcpy(&size, &SDO_C->CANrxData[4], sizeof(size));
|
||||
SDO_C->sizeInd = CO_SWAP_32(size);
|
||||
|
|
@ -1497,18 +1497,18 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
|
||||
case CO_SDO_ST_UPLOAD_BLK_END_SREQ: {
|
||||
if ((SDO_C->CANrxData[0] & 0xE3) == 0xC1) {
|
||||
if ((SDO_C->CANrxData[0] & 0xE3U) == 0xC1U) {
|
||||
/* Get number of data bytes in last segment, that do not
|
||||
* contain data. Then copy remaining data into fifo */
|
||||
uint8_t noData = ((SDO_C->CANrxData[0] >> 2) & 0x07);
|
||||
uint8_t noData = ((SDO_C->CANrxData[0] >> 2) & 0x07U);
|
||||
CO_fifo_write(&SDO_C->bufFifo,
|
||||
&SDO_C->block_dataUploadLast[0],
|
||||
7 - noData,
|
||||
7U - noData,
|
||||
&SDO_C->block_crc);
|
||||
SDO_C->sizeTran += 7 - noData;
|
||||
SDO_C->sizeTran += 7U - noData;
|
||||
|
||||
/* verify length */
|
||||
if ((SDO_C->sizeInd > 0)
|
||||
if ((SDO_C->sizeInd > 0U)
|
||||
&& (SDO_C->sizeTran != SDO_C->sizeInd)
|
||||
) {
|
||||
abortCode = (SDO_C->sizeTran > SDO_C->sizeInd) ?
|
||||
|
|
@ -1634,11 +1634,11 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_SEGMENTED
|
||||
case CO_SDO_ST_UPLOAD_SEGMENT_REQ: {
|
||||
/* verify, if there is enough space in data buffer */
|
||||
if (CO_fifo_getSpace(&SDO_C->bufFifo) < 7) {
|
||||
if (CO_fifo_getSpace(&SDO_C->bufFifo) < 7U) {
|
||||
ret = CO_SDO_RT_uploadDataBufferFull;
|
||||
break;
|
||||
}
|
||||
SDO_C->CANtxBuff->data[0] = 0x60 | SDO_C->toggle;
|
||||
SDO_C->CANtxBuff->data[0] = 0x60U | SDO_C->toggle;
|
||||
|
||||
/* reset timeout timer and send message */
|
||||
SDO_C->timeoutTimer = 0;
|
||||
|
|
@ -1656,11 +1656,11 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
SDO_C->CANtxBuff->data[3] = SDO_C->subIndex;
|
||||
|
||||
/* calculate number of block segments from free buffer space */
|
||||
count = CO_fifo_getSpace(&SDO_C->bufFifo) / 7;
|
||||
if (count > 127) {
|
||||
count = CO_fifo_getSpace(&SDO_C->bufFifo) / 7U;
|
||||
if (count > 127U) {
|
||||
count = 127;
|
||||
}
|
||||
else if (count == 0) {
|
||||
else if (count == 0U) {
|
||||
abortCode = CO_SDO_AB_OUT_OF_MEM;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
|
|
@ -1706,18 +1706,18 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
|||
}
|
||||
else {
|
||||
/* verify if size of data uploaded is too large */
|
||||
if ((SDO_C->sizeInd > 0) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
if ((SDO_C->sizeInd > 0U) && (SDO_C->sizeTran > SDO_C->sizeInd)) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO_C->state = CO_SDO_ST_ABORT;
|
||||
break;
|
||||
}
|
||||
|
||||
/* calculate number of block segments from free buffer space */
|
||||
count = CO_fifo_getSpace(&SDO_C->bufFifo) / 7;
|
||||
if (count >= 127) {
|
||||
count = CO_fifo_getSpace(&SDO_C->bufFifo) / 7U;
|
||||
if (count >= 127U) {
|
||||
count = 127;
|
||||
}
|
||||
else if (CO_fifo_getOccupied(&SDO_C->bufFifo) > 0) {
|
||||
else if (CO_fifo_getOccupied(&SDO_C->bufFifo) > 0U) {
|
||||
/* application must empty data buffer first */
|
||||
ret = CO_SDO_RT_uploadDataBufferFull;
|
||||
#ifdef CO_DEBUG_SDO_CLIENT
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ static void CO_SDO_receive(void *object, void *msg) {
|
|||
uint8_t *data = CO_CANrxMsg_readData(msg);
|
||||
|
||||
/* ignore messages with wrong length */
|
||||
if (DLC == 8) {
|
||||
if (data[0] == 0x80) {
|
||||
if (DLC == 8U) {
|
||||
if (data[0] == 0x80U) {
|
||||
/* abort from client, just make idle */
|
||||
SDO->state = CO_SDO_ST_IDLE;
|
||||
}
|
||||
|
|
@ -184,11 +184,11 @@ static CO_ReturnError_t CO_SDOserver_init_canRxTx(CO_SDOserver_t *SDO,
|
|||
#endif
|
||||
|
||||
/* verify valid bit */
|
||||
uint16_t idC2S = ((COB_IDClientToServer & 0x80000000L) == 0) ?
|
||||
(uint16_t)COB_IDClientToServer : 0;
|
||||
uint16_t idS2C = ((COB_IDServerToClient & 0x80000000L) == 0) ?
|
||||
(uint16_t)COB_IDServerToClient : 0;
|
||||
if ((idC2S != 0) && (idS2C != 0)) {
|
||||
uint16_t idC2S = ((COB_IDClientToServer & 0x80000000UL) == 0U) ?
|
||||
(uint16_t)COB_IDClientToServer : 0U;
|
||||
uint16_t idS2C = ((COB_IDServerToClient & 0x80000000UL) == 0U) ?
|
||||
(uint16_t)COB_IDServerToClient : 0U;
|
||||
if ((idC2S != 0U) && (idS2C != 0U)) {
|
||||
SDO->valid = true;
|
||||
}
|
||||
else {
|
||||
|
|
@ -249,12 +249,12 @@ static ODR_t OD_write_1201_additional(OD_stream_t *stream, const void *buf,
|
|||
|
||||
case 1: { /* COB-ID client -> server */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO->COB_IDClientToServer & 0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO->COB_IDClientToServer & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* SDO client must not be valid when changing COB_ID */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| ((valid && SDO->valid) && (CAN_ID != CAN_ID_cur))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
) {
|
||||
|
|
@ -271,12 +271,12 @@ static ODR_t OD_write_1201_additional(OD_stream_t *stream, const void *buf,
|
|||
|
||||
case 2: { /* COB-ID server -> client */
|
||||
uint32_t COB_ID = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FF);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO->COB_IDServerToClient & 0x7FF);
|
||||
bool_t valid = (COB_ID & 0x80000000) == 0;
|
||||
uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
|
||||
uint16_t CAN_ID_cur = (uint16_t)(SDO->COB_IDServerToClient & 0x7FFU);
|
||||
bool_t valid = (COB_ID & 0x80000000U) == 0U;
|
||||
|
||||
/* SDO client must not be valid when changing COB_ID */
|
||||
if (((COB_ID & 0x3FFFF800) != 0)
|
||||
if (((COB_ID & 0x3FFFF800U) != 0U)
|
||||
|| (valid && (SDO->valid && (CAN_ID != CAN_ID_cur)))
|
||||
|| (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))
|
||||
) {
|
||||
|
|
@ -292,11 +292,11 @@ static ODR_t OD_write_1201_additional(OD_stream_t *stream, const void *buf,
|
|||
}
|
||||
|
||||
case 3: { /* Node-ID of the SDO server */
|
||||
if (count != 1) {
|
||||
if (count != 1U) {
|
||||
return ODR_TYPE_MISMATCH;
|
||||
}
|
||||
uint8_t nodeId = CO_getUint8(buf);
|
||||
if ((nodeId < 1) || (nodeId > 127)) {
|
||||
if ((nodeId < 1U) || (nodeId > 127U)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
break;
|
||||
|
|
@ -333,7 +333,7 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
SDO->OD = OD;
|
||||
SDO->nodeId = nodeId;
|
||||
#if ((CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED)
|
||||
SDO->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000;
|
||||
SDO->SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 1000U;
|
||||
#endif
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_BLOCK
|
||||
SDO->block_SDOtimeoutTime_us = (uint32_t)SDOtimeoutTime_ms * 700;
|
||||
|
|
@ -350,18 +350,18 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
|
||||
if (OD_1200_SDOsrvPar == NULL) {
|
||||
/* configure default SDO channel */
|
||||
if ((nodeId < 1) || (nodeId > 127)) { return CO_ERROR_ILLEGAL_ARGUMENT; }
|
||||
if ((nodeId < 1U) || (nodeId > 127U)) { return CO_ERROR_ILLEGAL_ARGUMENT; }
|
||||
|
||||
CanId_ClientToServer = CO_CAN_ID_SDO_CLI + nodeId;
|
||||
CanId_ServerToClient = CO_CAN_ID_SDO_SRV + nodeId;
|
||||
CanId_ClientToServer = (uint16_t)CO_CAN_ID_SDO_CLI + nodeId;
|
||||
CanId_ServerToClient = (uint16_t)CO_CAN_ID_SDO_SRV + nodeId;
|
||||
SDO->valid = true;
|
||||
}
|
||||
else {
|
||||
uint16_t OD_SDOsrvParIdx = OD_getIndex(OD_1200_SDOsrvPar);
|
||||
|
||||
if (OD_SDOsrvParIdx == OD_H1200_SDO_SERVER_1_PARAM) {
|
||||
if (OD_SDOsrvParIdx == (uint16_t)OD_H1200_SDO_SERVER_1_PARAM) {
|
||||
/* configure default SDO channel and SDO server parameters for it */
|
||||
if ((nodeId < 1) || (nodeId > 127)) {
|
||||
if ((nodeId < 1U) || (nodeId > 127U)) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
ODR_t odRet2 = OD_get_u32(OD_1200_SDOsrvPar, 2,
|
||||
&COB_IDServerToClient32, true);
|
||||
|
||||
if ((odRet0 != ODR_OK) || ((maxSubIndex != 2) && (maxSubIndex != 3))
|
||||
if ((odRet0 != ODR_OK) || ((maxSubIndex != 2U) && (maxSubIndex != 3U))
|
||||
|| (odRet1 != ODR_OK) || (odRet2 != ODR_OK)
|
||||
) {
|
||||
if (errInfo != NULL) { *errInfo = OD_SDOsrvParIdx; }
|
||||
|
|
@ -394,10 +394,10 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
}
|
||||
|
||||
|
||||
CanId_ClientToServer = ((COB_IDClientToServer32 & 0x80000000) == 0)
|
||||
? (uint16_t)(COB_IDClientToServer32 & 0x7FF) : 0;
|
||||
CanId_ServerToClient = ((COB_IDServerToClient32 & 0x80000000) == 0)
|
||||
? (uint16_t)(COB_IDServerToClient32 & 0x7FF) : 0;
|
||||
CanId_ClientToServer = ((COB_IDClientToServer32 & 0x80000000U) == 0U)
|
||||
? (uint16_t)(COB_IDClientToServer32 & 0x7FFU) : 0U;
|
||||
CanId_ServerToClient = ((COB_IDServerToClient32 & 0x80000000U) == 0U)
|
||||
? (uint16_t)(COB_IDServerToClient32 & 0x7FFU) : 0U;
|
||||
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_FLAG_OD_DYNAMIC
|
||||
SDO->OD_1200_extension.object = SDO;
|
||||
|
|
@ -485,7 +485,7 @@ static bool_t validateAndWriteToOD(CO_SDOserver_t *SDO,
|
|||
|
||||
if (SDO->finished) {
|
||||
/* Verify if size of data downloaded matches size indicated. */
|
||||
if ((SDO->sizeInd > 0) && (SDO->sizeTran != SDO->sizeInd)) {
|
||||
if ((SDO->sizeInd > 0U) && (SDO->sizeTran != SDO->sizeInd)) {
|
||||
*abortCode = (SDO->sizeTran > SDO->sizeInd) ?
|
||||
CO_SDO_AB_DATA_LONG : CO_SDO_AB_DATA_SHORT;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -505,20 +505,20 @@ static bool_t validateAndWriteToOD(CO_SDOserver_t *SDO,
|
|||
* shorter than size of OD data buffer. If so, add two zero bytes
|
||||
* to terminate (unicode) string. Shorten also OD data size,
|
||||
* (temporary, send information about EOF into OD_IO.write) */
|
||||
if (((SDO->OD_IO.stream.attribute & ODA_STR) != 0)
|
||||
&& ((sizeInOd == 0) || (SDO->sizeTran < sizeInOd))
|
||||
&& ((SDO->bufOffsetWr + 2) <= CO_CONFIG_SDO_SRV_BUFFER_SIZE)
|
||||
if (((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_STR) != 0U)
|
||||
&& ((sizeInOd == 0U) || (SDO->sizeTran < sizeInOd))
|
||||
&& ((SDO->bufOffsetWr + 2U) <= CO_CONFIG_SDO_SRV_BUFFER_SIZE)
|
||||
) {
|
||||
SDO->buf[SDO->bufOffsetWr++] = 0;
|
||||
SDO->sizeTran++;
|
||||
if ((sizeInOd == 0) || (SDO->sizeTran < sizeInOd)) {
|
||||
if ((sizeInOd == 0U) || (SDO->sizeTran < sizeInOd)) {
|
||||
SDO->buf[SDO->bufOffsetWr++] = 0;
|
||||
SDO->sizeTran++;
|
||||
}
|
||||
SDO->OD_IO.stream.dataLength = SDO->sizeTran;
|
||||
}
|
||||
/* Indicate OD data size, if not indicated. Can be used for EOF check.*/
|
||||
else if (sizeInOd == 0) {
|
||||
else if (sizeInOd == 0U) {
|
||||
SDO->OD_IO.stream.dataLength = SDO->sizeTran;
|
||||
}
|
||||
/* Verify if size of data downloaded matches data size in OD. */
|
||||
|
|
@ -532,7 +532,7 @@ static bool_t validateAndWriteToOD(CO_SDOserver_t *SDO,
|
|||
}
|
||||
else {
|
||||
/* Verify if size of data downloaded is not too large. */
|
||||
if ((SDO->sizeInd > 0) && (SDO->sizeTran > SDO->sizeInd)) {
|
||||
if ((SDO->sizeInd > 0U) && (SDO->sizeTran > SDO->sizeInd)) {
|
||||
*abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
return false;
|
||||
|
|
@ -630,10 +630,10 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
|||
}
|
||||
|
||||
/* if data is string, send only data up to null termination */
|
||||
if ((countRd > 0) && ((SDO->OD_IO.stream.attribute & ODA_STR) != 0)) {
|
||||
if ((countRd > 0U) && ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_STR) != 0U)) {
|
||||
bufShifted[countRd] = 0; /* (SDO->buf is one byte larger) */
|
||||
OD_size_t countStr = (OD_size_t)strlen((char *)bufShifted);
|
||||
if (countStr == 0) { countStr = 1; }/* zero length is not allowed */
|
||||
if (countStr == 0U) { countStr = 1; }/* zero length is not allowed */
|
||||
if (countStr < countRd) {
|
||||
/* string terminator found, read is finished, shorten data */
|
||||
countRd = countStr;
|
||||
|
|
@ -644,7 +644,7 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
|||
|
||||
/* partial or finished read */
|
||||
SDO->bufOffsetWr = countRemain + countRd;
|
||||
if ((SDO->bufOffsetWr == 0) || (odRet == ODR_PARTIAL)) {
|
||||
if ((SDO->bufOffsetWr == 0U) || (odRet == ODR_PARTIAL)) {
|
||||
SDO->finished = false;
|
||||
if (SDO->bufOffsetWr < countMinimum) {
|
||||
*abortCode = CO_SDO_AB_DEVICE_INCOMPAT;
|
||||
|
|
@ -717,10 +717,10 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
if (SDO->state == CO_SDO_ST_IDLE) { /* new SDO communication? */
|
||||
bool_t upload = false;
|
||||
|
||||
if ((SDO->CANrxData[0] & 0xF0) == 0x20) {
|
||||
if ((SDO->CANrxData[0] & 0xF0U) == 0x20U) {
|
||||
SDO->state = CO_SDO_ST_DOWNLOAD_INITIATE_REQ;
|
||||
}
|
||||
else if (SDO->CANrxData[0] == 0x40) {
|
||||
else if (SDO->CANrxData[0] == 0x40U) {
|
||||
upload = true;
|
||||
SDO->state = CO_SDO_ST_UPLOAD_INITIATE_REQ;
|
||||
}
|
||||
|
|
@ -752,18 +752,18 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
}
|
||||
else {
|
||||
/* verify read/write attributes */
|
||||
if ((SDO->OD_IO.stream.attribute & ODA_SDO_RW) == 0) {
|
||||
if ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_SDO_RW) == 0U) {
|
||||
abortCode = CO_SDO_AB_UNSUPPORTED_ACCESS;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
}
|
||||
else if (upload
|
||||
&& ((SDO->OD_IO.stream.attribute & ODA_SDO_R) == 0)
|
||||
&& ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_SDO_R) == 0U)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_WRITEONLY;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
}
|
||||
else if (!upload
|
||||
&& ((SDO->OD_IO.stream.attribute & ODA_SDO_W) == 0)
|
||||
&& ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_SDO_W) == 0U)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_READONLY;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -786,7 +786,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
SDO->sizeInd = SDO->OD_IO.stream.dataLength;
|
||||
|
||||
if (SDO->sizeInd == 0) {
|
||||
if (SDO->sizeInd == 0U) {
|
||||
SDO->sizeInd = SDO->bufOffsetWr;
|
||||
}
|
||||
else if (SDO->sizeInd != SDO->bufOffsetWr) {
|
||||
|
|
@ -797,9 +797,9 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
}
|
||||
else {
|
||||
/* If data type is string, size is not known */
|
||||
SDO->sizeInd = ((SDO->OD_IO.stream.attribute&ODA_STR)==0)
|
||||
SDO->sizeInd = ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_STR)==0U)
|
||||
? SDO->OD_IO.stream.dataLength
|
||||
: 0;
|
||||
: 0U;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -809,7 +809,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
if ((SDO->state != CO_SDO_ST_IDLE) && (SDO->state != CO_SDO_ST_ABORT)) {
|
||||
switch (SDO->state) {
|
||||
case CO_SDO_ST_DOWNLOAD_INITIATE_REQ: {
|
||||
if (SDO->CANrxData[0] & 0x02) {
|
||||
if (SDO->CANrxData[0] & 0x02U) {
|
||||
/* Expedited transfer, max 4 bytes of data */
|
||||
|
||||
/* Size of OD variable (>0 if indicated) */
|
||||
|
|
@ -817,10 +817,10 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
/* Get SDO data size (indicated by SDO client or get from OD) */
|
||||
OD_size_t dataSizeToWrite = 4;
|
||||
if (SDO->CANrxData[0] & 0x01) {
|
||||
dataSizeToWrite -= (SDO->CANrxData[0] >> 2) & 0x03;
|
||||
if (SDO->CANrxData[0] & 0x01U) {
|
||||
dataSizeToWrite -= (SDO->CANrxData[0] >> 2) & 0x03U;
|
||||
}
|
||||
else if ((sizeInOd > 0) && (sizeInOd < 4)) {
|
||||
else if ((sizeInOd > 0U) && (sizeInOd < 4U)) {
|
||||
dataSizeToWrite = sizeInOd;
|
||||
}
|
||||
else { /* MISRA C 2004 14.10 */ }
|
||||
|
|
@ -838,14 +838,14 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
* shorter as size of OD data buffer. If so, add two zero bytes
|
||||
* to terminate (unicode) string. Shorten also OD data size,
|
||||
* (temporary, send information about EOF into OD_IO.write) */
|
||||
if (((SDO->OD_IO.stream.attribute & ODA_STR) != 0)
|
||||
&& ((sizeInOd == 0) || (dataSizeToWrite < sizeInOd))
|
||||
if (((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_STR) != 0U)
|
||||
&& ((sizeInOd == 0U) || (dataSizeToWrite < sizeInOd))
|
||||
) {
|
||||
OD_size_t delta = sizeInOd - dataSizeToWrite;
|
||||
dataSizeToWrite += (delta == 1) ? 1 : 2;
|
||||
dataSizeToWrite += (delta == 1U) ? 1U : 2U;
|
||||
SDO->OD_IO.stream.dataLength = dataSizeToWrite;
|
||||
}
|
||||
else if (sizeInOd == 0) {
|
||||
else if (sizeInOd == 0U) {
|
||||
SDO->OD_IO.stream.dataLength = dataSizeToWrite;
|
||||
}
|
||||
/* Verify if size of data downloaded matches data size in OD. */
|
||||
|
|
@ -880,7 +880,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
else {
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED
|
||||
/* segmented transfer, is size indicated? */
|
||||
if (SDO->CANrxData[0] & 0x01) {
|
||||
if (SDO->CANrxData[0] & 0x01U) {
|
||||
uint32_t size;
|
||||
OD_size_t sizeInOd = SDO->OD_IO.stream.dataLength;
|
||||
|
||||
|
|
@ -888,7 +888,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
SDO->sizeInd = CO_SWAP_32(size);
|
||||
|
||||
/* Indicated size of SDO matches sizeof OD variable? */
|
||||
if (sizeInOd > 0) {
|
||||
if (sizeInOd > 0U) {
|
||||
if (SDO->sizeInd > sizeInOd) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -920,11 +920,11 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED
|
||||
case CO_SDO_ST_DOWNLOAD_SEGMENT_REQ: {
|
||||
if ((SDO->CANrxData[0] & 0xE0) == 0x00) {
|
||||
SDO->finished = (SDO->CANrxData[0] & 0x01) != 0;
|
||||
if ((SDO->CANrxData[0] & 0xE0U) == 0x00U) {
|
||||
SDO->finished = (SDO->CANrxData[0] & 0x01U) != 0U;
|
||||
|
||||
/* verify and alternate toggle bit */
|
||||
uint8_t toggle = SDO->CANrxData[0] & 0x10;
|
||||
uint8_t toggle = SDO->CANrxData[0] & 0x10U;
|
||||
if (toggle != SDO->toggle) {
|
||||
abortCode = CO_SDO_AB_TOGGLE_BIT;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -932,13 +932,13 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
}
|
||||
|
||||
/* get data size and write data to the buffer */
|
||||
OD_size_t count = 7 - ((SDO->CANrxData[0] >> 1) & 0x07);
|
||||
OD_size_t count = 7U - ((SDO->CANrxData[0] >> 1) & 0x07U);
|
||||
(void)memcpy(SDO->buf + SDO->bufOffsetWr, &SDO->CANrxData[1], count);
|
||||
SDO->bufOffsetWr += count;
|
||||
SDO->sizeTran += count;
|
||||
|
||||
/* if data size exceeds variable size, abort */
|
||||
if ((SDO->OD_IO.stream.dataLength > 0)
|
||||
if ((SDO->OD_IO.stream.dataLength > 0U)
|
||||
&& (SDO->sizeTran > SDO->OD_IO.stream.dataLength)
|
||||
) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
|
|
@ -948,7 +948,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
/* if necessary, empty the buffer */
|
||||
if (SDO->finished
|
||||
|| ((CO_CONFIG_SDO_SRV_BUFFER_SIZE - SDO->bufOffsetWr)<(7+2))
|
||||
|| ((CO_CONFIG_SDO_SRV_BUFFER_SIZE - SDO->bufOffsetWr)<(7U+2U))
|
||||
) {
|
||||
if (!validateAndWriteToOD(SDO, &abortCode, 0, 0)) {
|
||||
break;
|
||||
|
|
@ -972,9 +972,9 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED
|
||||
case CO_SDO_ST_UPLOAD_SEGMENT_REQ: {
|
||||
if ((SDO->CANrxData[0] & 0xEF) == 0x60) {
|
||||
if ((SDO->CANrxData[0] & 0xEFU) == 0x60U) {
|
||||
/* verify and alternate toggle bit */
|
||||
uint8_t toggle = SDO->CANrxData[0] & 0x10;
|
||||
uint8_t toggle = SDO->CANrxData[0] & 0x10U;
|
||||
if (toggle != SDO->toggle) {
|
||||
abortCode = CO_SDO_AB_TOGGLE_BIT;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
@ -1265,8 +1265,8 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED
|
||||
case CO_SDO_ST_DOWNLOAD_SEGMENT_RSP: {
|
||||
SDO->CANtxBuff->data[0] = 0x20 | SDO->toggle;
|
||||
SDO->toggle = (SDO->toggle == 0x00) ? 0x10 : 0x00;
|
||||
SDO->CANtxBuff->data[0] = 0x20U | SDO->toggle;
|
||||
SDO->toggle = (SDO->toggle == 0x00U) ? 0x10U : 0x00U;
|
||||
|
||||
/* reset timeout timer and send message */
|
||||
SDO->timeoutTimer = 0;
|
||||
|
|
@ -1285,16 +1285,16 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
case CO_SDO_ST_UPLOAD_INITIATE_RSP: {
|
||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_SEGMENTED
|
||||
/* data were already loaded from OD variable */
|
||||
if ((SDO->sizeInd > 0) && (SDO->sizeInd <= 4)) {
|
||||
if ((SDO->sizeInd > 0U) && (SDO->sizeInd <= 4U)) {
|
||||
/* expedited transfer */
|
||||
SDO->CANtxBuff->data[0] = (uint8_t)(0x43|((4-SDO->sizeInd)<<2));
|
||||
SDO->CANtxBuff->data[0] = (uint8_t)(0x43U|((4U-SDO->sizeInd)<<2U));
|
||||
(void)memcpy(&SDO->CANtxBuff->data[4], &SDO->buf, SDO->sizeInd);
|
||||
SDO->state = CO_SDO_ST_IDLE;
|
||||
ret = CO_SDO_RT_ok_communicationEnd;
|
||||
}
|
||||
else {
|
||||
/* data will be transferred with segmented transfer */
|
||||
if (SDO->sizeInd > 0) {
|
||||
if (SDO->sizeInd > 0U) {
|
||||
/* indicate data size, if known */
|
||||
uint32_t sizeInd = SDO->sizeInd;
|
||||
uint32_t sizeIndSw = CO_SWAP_32(sizeInd);
|
||||
|
|
@ -1360,13 +1360,13 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
|
||||
/* SDO command specifier with toggle bit */
|
||||
SDO->CANtxBuff->data[0] = SDO->toggle;
|
||||
SDO->toggle = (SDO->toggle == 0x00) ? 0x10 : 0x00;
|
||||
SDO->toggle = (SDO->toggle == 0x00U) ? 0x10U : 0x00U;
|
||||
|
||||
OD_size_t count = SDO->bufOffsetWr - SDO->bufOffsetRd;
|
||||
/* verify, if this is the last segment */
|
||||
if ((count < 7) || (SDO->finished && (count == 7))) {
|
||||
if ((count < 7U) || (SDO->finished && (count == 7U))) {
|
||||
/* indicate last segment and nnn */
|
||||
SDO->CANtxBuff->data[0] |= ((7 - count) << 1) | 0x01;
|
||||
SDO->CANtxBuff->data[0] |= ((7U - count) << 1U) | 0x01U;
|
||||
SDO->state = CO_SDO_ST_IDLE;
|
||||
ret = CO_SDO_RT_ok_communicationEnd;
|
||||
}
|
||||
|
|
@ -1383,7 +1383,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
SDO->sizeTran += count;
|
||||
|
||||
/* verify if sizeTran is too large or too short if last segment */
|
||||
if (SDO->sizeInd > 0) {
|
||||
if (SDO->sizeInd > 0U) {
|
||||
if (SDO->sizeTran > SDO->sizeInd) {
|
||||
abortCode = CO_SDO_AB_DATA_LONG;
|
||||
SDO->state = CO_SDO_ST_ABORT;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
|
||||
#endif
|
||||
#ifndef CO_CONFIG_SDO_SRV_BUFFER_SIZE
|
||||
#define CO_CONFIG_SDO_SRV_BUFFER_SIZE 32
|
||||
#define CO_CONFIG_SDO_SRV_BUFFER_SIZE 32U
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -496,7 +496,7 @@ typedef struct {
|
|||
/** Timeout timer for SDO communication */
|
||||
uint32_t timeoutTimer;
|
||||
/** Interim data buffer for segmented or block transfer + byte for '\0' */
|
||||
uint8_t buf[CO_CONFIG_SDO_SRV_BUFFER_SIZE + 1];
|
||||
uint8_t buf[CO_CONFIG_SDO_SRV_BUFFER_SIZE + 1U];
|
||||
/** Offset of next free data byte available for write in the buffer. */
|
||||
OD_size_t bufOffsetWr;
|
||||
/** Offset of first data available for read in the buffer */
|
||||
|
|
|
|||
|
|
@ -39,22 +39,22 @@ static void CO_SYNC_receive(void *object, void *msg) {
|
|||
uint8_t DLC = CO_CANrxMsg_readDLC(msg);
|
||||
bool_t syncReceived = false;
|
||||
|
||||
if (SYNC->counterOverflowValue == 0) {
|
||||
if (DLC == 0) {
|
||||
if (SYNC->counterOverflowValue == 0U) {
|
||||
if (DLC == 0U) {
|
||||
syncReceived = true;
|
||||
}
|
||||
else {
|
||||
SYNC->receiveError = DLC | 0x40;
|
||||
SYNC->receiveError = DLC | 0x40U;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (DLC == 1) {
|
||||
if (DLC == 1U) {
|
||||
uint8_t *data = CO_CANrxMsg_readData(msg);
|
||||
SYNC->counter = data[0];
|
||||
syncReceived = true;
|
||||
}
|
||||
else {
|
||||
SYNC->receiveError = DLC | 0x80;
|
||||
SYNC->receiveError = DLC | 0x80U;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ static void CO_SYNC_receive(void *object, void *msg) {
|
|||
static ODR_t OD_write_1005(OD_stream_t *stream, const void *buf,
|
||||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count != sizeof(uint32_t)) || (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -91,7 +91,7 @@ static ODR_t OD_write_1005(OD_stream_t *stream, const void *buf,
|
|||
|
||||
CO_SYNC_t *SYNC = stream->object;
|
||||
uint32_t cobIdSync = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = (uint16_t)(cobIdSync & 0x7FF);
|
||||
uint16_t CAN_ID = (uint16_t)(cobIdSync & 0x7FFU);
|
||||
|
||||
/* verify written value */
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
|
||||
|
|
@ -102,7 +102,7 @@ static ODR_t OD_write_1005(OD_stream_t *stream, const void *buf,
|
|||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
#else
|
||||
if (((cobIdSync & 0xFFFFF800) != 0) || CO_IS_RESTRICTED_CAN_ID(CAN_ID)) {
|
||||
if (((cobIdSync & 0xFFFFF800U) != 0U) || CO_IS_RESTRICTED_CAN_ID(CAN_ID)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -287,8 +287,8 @@ CO_ReturnError_t CO_SYNC_init(CO_SYNC_t *SYNC,
|
|||
}
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
if (syncCounterOvf == 1) { syncCounterOvf = 2; }
|
||||
else if (syncCounterOvf > 240) { syncCounterOvf = 240; }
|
||||
if (syncCounterOvf == 1U) { syncCounterOvf = 2; }
|
||||
else if (syncCounterOvf > 240U) { syncCounterOvf = 240; }
|
||||
else { /* MISRA C 2004 14.10 */ }
|
||||
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_FLAG_OD_DYNAMIC
|
||||
|
|
@ -305,10 +305,10 @@ CO_ReturnError_t CO_SYNC_init(CO_SYNC_t *SYNC,
|
|||
/* Configure object variables */
|
||||
SYNC->em = em;
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
|
||||
SYNC->isProducer = (cobIdSync & 0x40000000) != 0;
|
||||
SYNC->isProducer = (cobIdSync & 0x40000000U) != 0U;
|
||||
#endif
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_FLAG_OD_DYNAMIC
|
||||
SYNC->CAN_ID = cobIdSync & 0x7FF;
|
||||
SYNC->CAN_ID = cobIdSync & 0x7FFU;
|
||||
SYNC->CANdevRx = CANdevRx;
|
||||
SYNC->CANdevRxIdx = CANdevRxIdx;
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
|
||||
|
|
@ -321,7 +321,7 @@ CO_ReturnError_t CO_SYNC_init(CO_SYNC_t *SYNC,
|
|||
CO_ReturnError_t ret = CO_CANrxBufferInit(
|
||||
CANdevRx, /* CAN device */
|
||||
CANdevRxIdx, /* rx buffer index */
|
||||
cobIdSync & 0x7FF, /* CAN identifier */
|
||||
cobIdSync & 0x7FFU, /* CAN identifier */
|
||||
0x7FF, /* mask */
|
||||
0, /* rtr */
|
||||
(void*)SYNC, /* object passed to receive function */
|
||||
|
|
@ -386,9 +386,9 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
}
|
||||
|
||||
uint32_t OD_1006_period = (SYNC->OD_1006_period != NULL)
|
||||
? *SYNC->OD_1006_period : 0;
|
||||
? *SYNC->OD_1006_period : 0U;
|
||||
|
||||
if (OD_1006_period > 0) {
|
||||
if (OD_1006_period > 0U) {
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
|
||||
if (SYNC->isProducer) {
|
||||
if (SYNC->timer >= OD_1006_period) {
|
||||
|
|
@ -409,7 +409,7 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
#endif /* (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER */
|
||||
|
||||
/* Verify timeout of SYNC */
|
||||
if (SYNC->timeoutError == 1) {
|
||||
if (SYNC->timeoutError == 1U) {
|
||||
/* periodTimeout is 1,5 * OD_1006_period, no overflow */
|
||||
uint32_t periodTimeout = OD_1006_period + (OD_1006_period >> 1);
|
||||
if (periodTimeout < OD_1006_period) {
|
||||
|
|
@ -417,7 +417,7 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
}
|
||||
|
||||
if (SYNC->timer > periodTimeout) {
|
||||
CO_errorReport(SYNC->em, CO_EM_SYNC_TIME_OUT,
|
||||
CO_errorReport(SYNC->em, (uint8_t)CO_EM_SYNC_TIME_OUT,
|
||||
CO_EMC_COMMUNICATION, SYNC->timer);
|
||||
SYNC->timeoutError = 2;
|
||||
}
|
||||
|
|
@ -434,7 +434,7 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
} /* if (OD_1006_period > 0) */
|
||||
|
||||
/* Synchronous PDOs are allowed only inside time window */
|
||||
if ((SYNC->OD_1007_window != NULL) && (*SYNC->OD_1007_window > 0)
|
||||
if ((SYNC->OD_1007_window != NULL) && (*SYNC->OD_1007_window > 0U)
|
||||
&& (SYNC->timer > *SYNC->OD_1007_window)
|
||||
) {
|
||||
if (!SYNC->syncIsOutsideWindow) {
|
||||
|
|
@ -447,8 +447,8 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
}
|
||||
|
||||
/* verify error from receive function */
|
||||
if (SYNC->receiveError != 0) {
|
||||
CO_errorReport(SYNC->em, CO_EM_SYNC_LENGTH,
|
||||
if (SYNC->receiveError != 0U) {
|
||||
CO_EMC_SYNC_DATA_LENGTH, SYNC->receiveError);
|
||||
SYNC->receiveError = 0;
|
||||
}
|
||||
|
|
@ -461,8 +461,8 @@ CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC,
|
|||
}
|
||||
|
||||
if (syncStatus == CO_SYNC_RX_TX) {
|
||||
if (SYNC->timeoutError == 2) {
|
||||
CO_errorReset(SYNC->em, CO_EM_SYNC_TIME_OUT, 0);
|
||||
if (SYNC->timeoutError == 2U) {
|
||||
}
|
||||
SYNC->timeoutError = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ static void CO_TIME_receive(void *object, void *msg) {
|
|||
static ODR_t OD_write_1012(OD_stream_t *stream, const void *buf,
|
||||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
if ((stream == NULL) || (stream->subIndex != 0) || (buf == NULL)
|
||||
if ((stream == NULL) || (stream->subIndex != 0U) || (buf == NULL)
|
||||
|| (count != sizeof(uint32_t)) || (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -74,14 +74,14 @@ static ODR_t OD_write_1012(OD_stream_t *stream, const void *buf,
|
|||
|
||||
/* verify written value */
|
||||
uint32_t cobIdTimeStamp = CO_getUint32(buf);
|
||||
uint16_t CAN_ID = cobIdTimeStamp & 0x7FF;
|
||||
if (((cobIdTimeStamp & 0x3FFFF800) != 0) || CO_IS_RESTRICTED_CAN_ID(CAN_ID)) {
|
||||
uint16_t CAN_ID = cobIdTimeStamp & 0x7FFU;
|
||||
if (((cobIdTimeStamp & 0x3FFFF800U) != 0U) || CO_IS_RESTRICTED_CAN_ID(CAN_ID)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
/* update object */
|
||||
TIME->isConsumer = (cobIdTimeStamp & 0x80000000L) != 0;
|
||||
TIME->isProducer = (cobIdTimeStamp & 0x40000000L) != 0;
|
||||
TIME->isConsumer = (cobIdTimeStamp & 0x80000000UL) != 0U;
|
||||
TIME->isProducer = (cobIdTimeStamp & 0x40000000UL) != 0U;
|
||||
|
||||
/* write value to the original location in the Object Dictionary */
|
||||
return OD_writeOriginal(stream, buf, count, countWritten);
|
||||
|
|
@ -125,9 +125,9 @@ CO_ReturnError_t CO_TIME_init(CO_TIME_t *TIME,
|
|||
#endif
|
||||
|
||||
/* Configure object variables */
|
||||
uint16_t cobId = cobIdTimeStamp & 0x7FF;
|
||||
TIME->isConsumer = (cobIdTimeStamp & 0x80000000L) != 0;
|
||||
TIME->isProducer = (cobIdTimeStamp & 0x40000000L) != 0;
|
||||
uint16_t cobId = cobIdTimeStamp & 0x7FFU;
|
||||
TIME->isConsumer = (cobIdTimeStamp & 0x80000000UL) != 0U;
|
||||
TIME->isProducer = (cobIdTimeStamp & 0x40000000UL) != 0U;
|
||||
CO_FLAG_CLEAR(TIME->CANrxNew);
|
||||
|
||||
/* configure TIME consumer message reception */
|
||||
|
|
@ -189,7 +189,7 @@ bool_t CO_TIME_process(CO_TIME_t *TIME,
|
|||
if(CO_FLAG_READ(TIME->CANrxNew)) {
|
||||
uint32_t ms_swapped = CO_getUint32(&TIME->timeStamp[0]);
|
||||
uint16_t days_swapped = CO_getUint16(&TIME->timeStamp[4]);
|
||||
TIME->ms = CO_SWAP_32(ms_swapped) & 0x0FFFFFFF;
|
||||
TIME->ms = CO_SWAP_32(ms_swapped) & 0x0FFFFFFFU;
|
||||
TIME->days = CO_SWAP_16(days_swapped);
|
||||
TIME->residual_us = 0;
|
||||
timestampReceived = true;
|
||||
|
|
@ -203,14 +203,14 @@ bool_t CO_TIME_process(CO_TIME_t *TIME,
|
|||
|
||||
/* Update time */
|
||||
uint32_t ms = 0;
|
||||
if (!timestampReceived && (timeDifference_us > 0)) {
|
||||
if (!timestampReceived && (timeDifference_us > 0U)) {
|
||||
uint32_t us = timeDifference_us + TIME->residual_us;
|
||||
ms = us / 1000;
|
||||
TIME->residual_us = us % 1000;
|
||||
ms = us / 1000U;
|
||||
TIME->residual_us = us % 1000U;
|
||||
TIME->ms += ms;
|
||||
if (TIME->ms >= ((uint32_t)1000*60*60*24)) {
|
||||
TIME->ms -= ((uint32_t)1000*60*60*24);
|
||||
TIME->days += 1;
|
||||
if (TIME->ms >= ((uint32_t)1000U*60U*60U*24U)) {
|
||||
TIME->ms -= ((uint32_t)1000U*60U*60U*24U);
|
||||
TIME->days += 1U;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ extern "C" {
|
|||
|
||||
|
||||
/** Length of the TIME message */
|
||||
#define CO_TIME_MSG_LENGTH 6
|
||||
#define CO_TIME_MSG_LENGTH 6U
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -477,25 +477,25 @@ typedef struct {
|
|||
* in PDO linking phase of the CANopen network configuration.
|
||||
*/
|
||||
typedef enum {
|
||||
CO_CAN_ID_NMT_SERVICE = 0x000, /**< 0x000, Network management */
|
||||
CO_CAN_ID_GFC = 0x001, /**< 0x001, Global fail-safe command */
|
||||
CO_CAN_ID_SYNC = 0x080, /**< 0x080, Synchronous message */
|
||||
CO_CAN_ID_EMERGENCY = 0x080, /**< 0x080, Emergency messages (+nodeID) */
|
||||
CO_CAN_ID_TIME = 0x100, /**< 0x100, Time message */
|
||||
CO_CAN_ID_SRDO_1 = 0x0FF, /**< 0x0FF, Default SRDO1 (+2*nodeID) */
|
||||
CO_CAN_ID_TPDO_1 = 0x180, /**< 0x180, Default TPDO1 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_1 = 0x200, /**< 0x200, Default RPDO1 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_2 = 0x280, /**< 0x280, Default TPDO2 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_2 = 0x300, /**< 0x300, Default RPDO2 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_3 = 0x380, /**< 0x380, Default TPDO3 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_3 = 0x400, /**< 0x400, Default RPDO3 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_4 = 0x480, /**< 0x480, Default TPDO4 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_4 = 0x500, /**< 0x500, Default RPDO5 (+nodeID) */
|
||||
CO_CAN_ID_SDO_SRV = 0x580, /**< 0x580, SDO response from server (+nodeID) */
|
||||
CO_CAN_ID_SDO_CLI = 0x600, /**< 0x600, SDO request from client (+nodeID) */
|
||||
CO_CAN_ID_HEARTBEAT = 0x700, /**< 0x700, Heartbeat message */
|
||||
CO_CAN_ID_LSS_SLV = 0x7E4, /**< 0x7E4, LSS response from slave */
|
||||
CO_CAN_ID_LSS_MST = 0x7E5 /**< 0x7E5, LSS request from master */
|
||||
CO_CAN_ID_NMT_SERVICE = 0x000U, /**< 0x000, Network management */
|
||||
CO_CAN_ID_GFC = 0x001U, /**< 0x001, Global fail-safe command */
|
||||
CO_CAN_ID_SYNC = 0x080U, /**< 0x080, Synchronous message */
|
||||
CO_CAN_ID_EMERGENCY = 0x080U, /**< 0x080, Emergency messages (+nodeID) */
|
||||
CO_CAN_ID_TIME = 0x100U, /**< 0x100, Time message */
|
||||
CO_CAN_ID_SRDO_1 = 0x0FFU, /**< 0x0FF, Default SRDO1 (+2*nodeID) */
|
||||
CO_CAN_ID_TPDO_1 = 0x180U, /**< 0x180, Default TPDO1 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_1 = 0x200U, /**< 0x200, Default RPDO1 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_2 = 0x280U, /**< 0x280, Default TPDO2 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_2 = 0x300U, /**< 0x300, Default RPDO2 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_3 = 0x380U, /**< 0x380, Default TPDO3 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_3 = 0x400U, /**< 0x400, Default RPDO3 (+nodeID) */
|
||||
CO_CAN_ID_TPDO_4 = 0x480U, /**< 0x480, Default TPDO4 (+nodeID) */
|
||||
CO_CAN_ID_RPDO_4 = 0x500U, /**< 0x500, Default RPDO5 (+nodeID) */
|
||||
CO_CAN_ID_SDO_SRV = 0x580U, /**< 0x580, SDO response from server (+nodeID) */
|
||||
CO_CAN_ID_SDO_CLI = 0x600U, /**< 0x600, SDO request from client (+nodeID) */
|
||||
CO_CAN_ID_HEARTBEAT = 0x700U, /**< 0x700, Heartbeat message */
|
||||
CO_CAN_ID_LSS_SLV = 0x7E4U, /**< 0x7E4, LSS response from slave */
|
||||
CO_CAN_ID_LSS_MST = 0x7E5U /**< 0x7E5, LSS request from master */
|
||||
} CO_Default_CAN_ID_t;
|
||||
|
||||
|
||||
|
|
@ -506,12 +506,12 @@ typedef enum {
|
|||
* They shall not be used for SYNC, TIME, EMCY, PDO and SDO.
|
||||
*/
|
||||
#ifndef CO_IS_RESTRICTED_CAN_ID
|
||||
#define CO_IS_RESTRICTED_CAN_ID(CAN_ID) (((CAN_ID) <= 0x7F) \
|
||||
|| (((CAN_ID) >= 0x101) && ((CAN_ID) <= 0x180)) \
|
||||
|| (((CAN_ID) >= 0x581) && ((CAN_ID) <= 0x5FF)) \
|
||||
|| (((CAN_ID) >= 0x601) && ((CAN_ID) <= 0x67F)) \
|
||||
|| (((CAN_ID) >= 0x6E0) && ((CAN_ID) <= 0x6FF)) \
|
||||
|| ((CAN_ID) >= 0x701))
|
||||
#define CO_IS_RESTRICTED_CAN_ID(CAN_ID) (((CAN_ID) <= 0x7FU) \
|
||||
|| (((CAN_ID) >= 0x101U) && ((CAN_ID) <= 0x180U)) \
|
||||
|| (((CAN_ID) >= 0x581U) && ((CAN_ID) <= 0x5FFU)) \
|
||||
|| (((CAN_ID) >= 0x601U) && ((CAN_ID) <= 0x67FU)) \
|
||||
|| (((CAN_ID) >= 0x6E0U) && ((CAN_ID) <= 0x6FFU)) \
|
||||
|| ((CAN_ID) >= 0x701U))
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -524,18 +524,18 @@ typedef enum {
|
|||
* counter is more or equal to 256.
|
||||
*/
|
||||
typedef enum {
|
||||
CO_CAN_ERRTX_WARNING = 0x0001, /**< 0x0001, CAN transmitter warning */
|
||||
CO_CAN_ERRTX_PASSIVE = 0x0002, /**< 0x0002, CAN transmitter passive */
|
||||
CO_CAN_ERRTX_BUS_OFF = 0x0004, /**< 0x0004, CAN transmitter bus off */
|
||||
CO_CAN_ERRTX_OVERFLOW = 0x0008, /**< 0x0008, CAN transmitter overflow */
|
||||
CO_CAN_ERRTX_WARNING = 0x0001U, /**< 0x0001, CAN transmitter warning */
|
||||
CO_CAN_ERRTX_PASSIVE = 0x0002U, /**< 0x0002, CAN transmitter passive */
|
||||
CO_CAN_ERRTX_BUS_OFF = 0x0004U, /**< 0x0004, CAN transmitter bus off */
|
||||
CO_CAN_ERRTX_OVERFLOW = 0x0008U, /**< 0x0008, CAN transmitter overflow */
|
||||
|
||||
CO_CAN_ERRTX_PDO_LATE = 0x0080, /**< 0x0080, TPDO is outside sync window */
|
||||
CO_CAN_ERRTX_PDO_LATE = 0x0080U, /**< 0x0080, TPDO is outside sync window */
|
||||
|
||||
CO_CAN_ERRRX_WARNING = 0x0100, /**< 0x0100, CAN receiver warning */
|
||||
CO_CAN_ERRRX_PASSIVE = 0x0200, /**< 0x0200, CAN receiver passive */
|
||||
CO_CAN_ERRRX_OVERFLOW = 0x0800, /**< 0x0800, CAN receiver overflow */
|
||||
CO_CAN_ERRRX_WARNING = 0x0100U, /**< 0x0100, CAN receiver warning */
|
||||
CO_CAN_ERRRX_PASSIVE = 0x0200U, /**< 0x0200, CAN receiver passive */
|
||||
CO_CAN_ERRRX_OVERFLOW = 0x0800U, /**< 0x0800, CAN receiver overflow */
|
||||
|
||||
CO_CAN_ERR_WARN_PASSIVE = 0x0303/**< 0x0303, combination */
|
||||
CO_CAN_ERR_WARN_PASSIVE = 0x0303U/**< 0x0303, combination */
|
||||
} CO_CAN_ERR_status_t;
|
||||
|
||||
|
||||
|
|
|
|||
150
301/CO_fifo.c
150
301/CO_fifo.c
|
|
@ -54,7 +54,7 @@
|
|||
/******************************************************************************/
|
||||
void CO_fifo_init(CO_fifo_t *fifo, uint8_t *buf, size_t bufSize) {
|
||||
|
||||
if ((fifo == NULL) || (buf == NULL) || (bufSize < 2)) {
|
||||
if ((fifo == NULL) || (buf == NULL) || (bufSize < 2U)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +93,12 @@ size_t CO_fifo_write(CO_fifo_t *fifo,
|
|||
}
|
||||
|
||||
bufDest = &fifo->buf[fifo->writePtr];
|
||||
for (i = count; i > 0; i--) {
|
||||
size_t writePtrNext = fifo->writePtr + 1;
|
||||
for (i = count; i > 0U; i--) {
|
||||
size_t writePtrNext = fifo->writePtr + 1U;
|
||||
|
||||
/* is circular buffer full */
|
||||
if ((writePtrNext == fifo->readPtr) ||
|
||||
((writePtrNext == fifo->bufSize) && (fifo->readPtr == 0))) {
|
||||
((writePtrNext == fifo->bufSize) && (fifo->readPtr == 0U))) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ size_t CO_fifo_read(CO_fifo_t *fifo, uint8_t *buf, size_t count, bool_t *eof) {
|
|||
}
|
||||
|
||||
bufSrc = &fifo->buf[fifo->readPtr];
|
||||
for (i = count; i > 0; ) {
|
||||
for (i = count; i > 0U; ) {
|
||||
const uint8_t c = *bufSrc;
|
||||
|
||||
/* is circular buffer empty */
|
||||
|
|
@ -182,7 +182,7 @@ size_t CO_fifo_altBegin(CO_fifo_t *fifo, size_t offset) {
|
|||
}
|
||||
|
||||
fifo->altReadPtr = fifo->readPtr;
|
||||
for (i = offset; i > 0; i--) {
|
||||
for (i = offset; i > 0U; i--) {
|
||||
/* is circular buffer empty */
|
||||
if (fifo->altReadPtr == fifo->writePtr) {
|
||||
break;
|
||||
|
|
@ -229,7 +229,7 @@ size_t CO_fifo_altRead(CO_fifo_t *fifo, uint8_t *buf, size_t count) {
|
|||
const uint8_t *bufSrc;
|
||||
|
||||
bufSrc = &fifo->buf[fifo->altReadPtr];
|
||||
for (i = count; i > 0; i--) {
|
||||
for (i = count; i > 0U; i--) {
|
||||
const uint8_t c = *bufSrc;
|
||||
|
||||
/* is there no more data */
|
||||
|
|
@ -282,12 +282,12 @@ bool_t CO_fifo_CommSearch(CO_fifo_t *fifo, bool_t clear) {
|
|||
commandEnd = (uint8_t *)memchr((const void *)&fifo->buf[0],
|
||||
(int)DELIM_COMMAND,
|
||||
fifo->writePtr);
|
||||
if ((commandEnd != NULL) || (fifo->readPtr == (fifo->writePtr + 1))) {
|
||||
if ((commandEnd != NULL) || (fifo->readPtr == (fifo->writePtr + 1U))) {
|
||||
/* command delimiter found or buffer full */
|
||||
newCommand = true;
|
||||
}
|
||||
}
|
||||
else if ((fifo->readPtr == 0) && (fifo->writePtr == (fifo->bufSize - 1))) {
|
||||
else if ((fifo->readPtr == 0U) && (fifo->writePtr == (fifo->bufSize - 1U))) {
|
||||
/* buffer full */
|
||||
newCommand = true;
|
||||
}
|
||||
|
|
@ -295,7 +295,7 @@ bool_t CO_fifo_CommSearch(CO_fifo_t *fifo, bool_t clear) {
|
|||
/* Clear buffer if set so */
|
||||
if (clear) {
|
||||
if (commandEnd != NULL) {
|
||||
fifo->readPtr = (size_t)(commandEnd - fifo->buf) + 1;
|
||||
fifo->readPtr = (size_t)(commandEnd - fifo->buf) + 1U;
|
||||
if (fifo->readPtr == fifo->bufSize) {
|
||||
fifo->readPtr = 0;
|
||||
}
|
||||
|
|
@ -348,7 +348,7 @@ size_t CO_fifo_readToken(CO_fifo_t *fifo,
|
|||
bool_t delimCommentFound = false;
|
||||
size_t tokenSize = 0;
|
||||
|
||||
if ((fifo != NULL) && (buf != NULL) && (count > 1) && ((err == NULL) || (*err == 0))
|
||||
if ((fifo != NULL) && (buf != NULL) && (count > 1U) && ((err == NULL) || (*err == false))
|
||||
&& (fifo->readPtr != fifo->writePtr)
|
||||
) {
|
||||
bool_t finished = false;
|
||||
|
|
@ -425,7 +425,7 @@ size_t CO_fifo_readToken(CO_fifo_t *fifo,
|
|||
}
|
||||
/* end, if buffer is now empty */
|
||||
if (ptr == fifo->writePtr) {
|
||||
if (step == 2) {
|
||||
if (step == 2U) {
|
||||
fifo->readPtr = ptr;
|
||||
}
|
||||
else {
|
||||
|
|
@ -440,8 +440,8 @@ size_t CO_fifo_readToken(CO_fifo_t *fifo,
|
|||
/* set 'err' return value */
|
||||
if ((err != NULL) && (*err == false)) {
|
||||
if ((tokenSize == count) || ((closed != NULL) &&
|
||||
(((*closed == 1) && (!delimCommandFound || (tokenSize == 0))) ||
|
||||
((*closed == 0) && (delimCommandFound || (tokenSize == 0))))
|
||||
(((*closed == 1) && (!delimCommandFound || (tokenSize == 0U))) ||
|
||||
((*closed == 0) && (delimCommandFound || (tokenSize == 0U))))
|
||||
)) {
|
||||
*err = true;
|
||||
}
|
||||
|
|
@ -488,7 +488,7 @@ static const uint8_t base64DecTable[] = {
|
|||
size_t CO_fifo_readU82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint8_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 6) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 6U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, &n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRIu8, n);
|
||||
}
|
||||
|
|
@ -500,7 +500,7 @@ size_t CO_fifo_readU82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readU162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint16_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 8) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 8U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRIu16, CO_SWAP_16(n));
|
||||
}
|
||||
|
|
@ -512,7 +512,7 @@ size_t CO_fifo_readU162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readU322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint32_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 12) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 12U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRIu32, CO_SWAP_32(n));
|
||||
}
|
||||
|
|
@ -524,7 +524,7 @@ size_t CO_fifo_readU322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readU642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint64_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 20) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 20U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRIu64, CO_SWAP_64(n));
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ size_t CO_fifo_readU642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readX82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint8_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 6) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 6U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "0x%02"PRIX8, n);
|
||||
}
|
||||
|
|
@ -548,7 +548,7 @@ size_t CO_fifo_readX82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readX162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint16_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 8) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 8U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "0x%04"PRIX16, CO_SWAP_16(n));
|
||||
}
|
||||
|
|
@ -560,7 +560,7 @@ size_t CO_fifo_readX162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readX322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint32_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 12) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 12U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "0x%08"PRIX32, CO_SWAP_32(n));
|
||||
}
|
||||
|
|
@ -572,7 +572,7 @@ size_t CO_fifo_readX322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readX642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
uint64_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 20) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 20U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "0x%016"PRIX64, CO_SWAP_64(n));
|
||||
}
|
||||
|
|
@ -584,7 +584,7 @@ size_t CO_fifo_readX642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readI82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
int8_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 6) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 6U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRId8, n);
|
||||
}
|
||||
|
|
@ -596,7 +596,7 @@ size_t CO_fifo_readI82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readI162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
int16_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 8) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 8U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRId16, CO_SWAP_16(n));
|
||||
}
|
||||
|
|
@ -608,7 +608,7 @@ size_t CO_fifo_readI162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readI322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
int32_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 13) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 13U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRId32, CO_SWAP_32(n));
|
||||
}
|
||||
|
|
@ -620,7 +620,7 @@ size_t CO_fifo_readI322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readI642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
int64_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 23) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 23U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%"PRId64, CO_SWAP_64(n));
|
||||
}
|
||||
|
|
@ -632,7 +632,7 @@ size_t CO_fifo_readI642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readR322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
float32_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 20) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 20U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%g", (double)CO_SWAP_32(n));
|
||||
}
|
||||
|
|
@ -644,7 +644,7 @@ size_t CO_fifo_readR322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readR642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
float64_t n=0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 30) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
if ((fifo != NULL) && (count >= 30U) && (CO_fifo_getOccupied(fifo) == sizeof(n))) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%g", (double)CO_SWAP_64(n));
|
||||
}
|
||||
|
|
@ -658,7 +658,7 @@ size_t CO_fifo_readHex2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
|
||||
size_t len = 0;
|
||||
|
||||
if ((fifo != NULL) && (count > 3)) {
|
||||
if ((fifo != NULL) && (count > 3U)) {
|
||||
/* Very first write is without leading space */
|
||||
if (!fifo->started) {
|
||||
uint8_t c;
|
||||
|
|
@ -668,7 +668,7 @@ size_t CO_fifo_readHex2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
}
|
||||
}
|
||||
|
||||
while ((len + 3) < count) {
|
||||
while ((len + 3U) < count) {
|
||||
uint8_t c;
|
||||
if(!CO_fifo_getc(fifo, &c)) {
|
||||
break;
|
||||
|
|
@ -683,14 +683,14 @@ size_t CO_fifo_readHex2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
size_t CO_fifo_readVs2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
||||
size_t len = 0;
|
||||
|
||||
if ((fifo != NULL) && (count > 3)) {
|
||||
if ((fifo != NULL) && (count > 3U)) {
|
||||
/* Start with '"' */
|
||||
if (!fifo->started) {
|
||||
buf[len++] = '"';
|
||||
fifo->started = true;
|
||||
}
|
||||
|
||||
while ((len + 2) < count) {
|
||||
while ((len + 2U) < count) {
|
||||
uint8_t c;
|
||||
if(!CO_fifo_getc(fifo, &c)) {
|
||||
if (end) {
|
||||
|
|
@ -698,7 +698,7 @@ size_t CO_fifo_readVs2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
else if ((c != 0) && (c != (uint8_t)'\r')) {
|
||||
else if ((c != 0U) && (c != (uint8_t)'\r')) {
|
||||
/* skip null and CR inside string */
|
||||
buf[len++] = (char)c;
|
||||
if (c == DELIM_DQUOTE) {
|
||||
|
|
@ -716,7 +716,7 @@ size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
|
||||
size_t len = 0;
|
||||
|
||||
if ((fifo != NULL) && (count >= 4)) {
|
||||
if ((fifo != NULL) && (count >= 4U)) {
|
||||
uint8_t step;
|
||||
uint16_t word;
|
||||
|
||||
|
|
@ -731,7 +731,7 @@ size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
word = (uint16_t)fifo->aux;
|
||||
}
|
||||
|
||||
while ((len + 3) <= count) {
|
||||
while ((len + 3U) <= count) {
|
||||
uint8_t c;
|
||||
|
||||
if(!CO_fifo_getc(fifo, &c)) {
|
||||
|
|
@ -740,12 +740,12 @@ size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
/* add padding if necessary */
|
||||
switch (step) {
|
||||
case 1:
|
||||
buf[len++] = base64EncTable[(word >> 4) & 0x3F];
|
||||
buf[len++] = base64EncTable[(word >> 4) & 0x3FU];
|
||||
buf[len++] = '=';
|
||||
buf[len++] = '=';
|
||||
break;
|
||||
case 2:
|
||||
buf[len++] = base64EncTable[(word >> 6) & 0x3F];
|
||||
buf[len++] = base64EncTable[(word >> 6) & 0x3FU];
|
||||
buf[len++] = '=';
|
||||
break;
|
||||
default:
|
||||
|
|
@ -760,14 +760,14 @@ size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
|
||||
switch (step++) {
|
||||
case 0:
|
||||
buf[len++] = base64EncTable[(word >> 2) & 0x3F];
|
||||
buf[len++] = base64EncTable[(word >> 2) & 0x3FU];
|
||||
break;
|
||||
case 1:
|
||||
buf[len++] = base64EncTable[(word >> 4) & 0x3F];
|
||||
buf[len++] = base64EncTable[(word >> 4) & 0x3FU];
|
||||
break;
|
||||
default:
|
||||
buf[len++] = base64EncTable[(word >> 6) & 0x3F];
|
||||
buf[len++] = base64EncTable[word & 0x3F];
|
||||
buf[len++] = base64EncTable[(word >> 6) & 0x3FU];
|
||||
buf[len++] = base64EncTable[word & 0x3FU];
|
||||
step = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -790,7 +790,7 @@ size_t CO_fifo_cpyTok2U8(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
uint32_t u32 = strtoul(buf, &sRet, 0);
|
||||
|
|
@ -812,7 +812,7 @@ size_t CO_fifo_cpyTok2U16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
uint32_t u32 = strtoul(buf, &sRet, 0);
|
||||
|
|
@ -834,7 +834,7 @@ size_t CO_fifo_cpyTok2U32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
uint32_t u32 = strtoul(buf, &sRet, 0);
|
||||
|
|
@ -856,7 +856,7 @@ size_t CO_fifo_cpyTok2U64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
uint64_t u64 = strtoull(buf, &sRet, 0);
|
||||
|
|
@ -878,7 +878,7 @@ size_t CO_fifo_cpyTok2I8(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
int32_t i32 = strtol(buf, &sRet, 0);
|
||||
|
|
@ -901,7 +901,7 @@ size_t CO_fifo_cpyTok2I16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
int32_t i32 = strtol(buf, &sRet, 0);
|
||||
|
|
@ -924,7 +924,7 @@ size_t CO_fifo_cpyTok2I32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
int32_t i32 = strtol(buf, &sRet, 0);
|
||||
|
|
@ -946,7 +946,7 @@ size_t CO_fifo_cpyTok2I64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
int64_t i64 = strtoll(buf, &sRet, 0);
|
||||
|
|
@ -968,7 +968,7 @@ size_t CO_fifo_cpyTok2R32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
float32_t f32 = strtof(buf, &sRet);
|
||||
|
|
@ -990,7 +990,7 @@ size_t CO_fifo_cpyTok2R64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
size_t nWr = 0;
|
||||
size_t nRd = CO_fifo_readToken(src, buf, sizeof(buf), &closed, &err);
|
||||
CO_fifo_st st = (uint8_t)closed;
|
||||
if ((nRd == 0) || err) st |= CO_fifo_st_errTok;
|
||||
if ((nRd == 0U) || err) st |= CO_fifo_st_errTok;
|
||||
else {
|
||||
char *sRet;
|
||||
float64_t f64 = strtof(buf, &sRet);
|
||||
|
|
@ -1033,18 +1033,18 @@ size_t CO_fifo_cpyTok2Hex(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
else {
|
||||
/* get memorized variables from previous function calls */
|
||||
step = (uint8_t)(dest->aux >> 8);
|
||||
firstChar = (uint8_t)(dest->aux & 0xFF);
|
||||
firstChar = (uint8_t)(dest->aux & 0xFFU);
|
||||
}
|
||||
|
||||
/* repeat until destination space available and no error and not finished
|
||||
* and source characters available */
|
||||
while ((destSpace > 0) && ((st & CO_fifo_st_errMask) == 0) && !finished) {
|
||||
while ((destSpace > 0U) && ((st & CO_fifo_st_errMask) == 0U) && !finished) {
|
||||
uint8_t c;
|
||||
if (!CO_fifo_getc(src, &c)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (step == 6) {
|
||||
if (step == 6U) {
|
||||
/* command is inside comment, waiting for command delimiter */
|
||||
bool_t insideComment = true;
|
||||
if ((c == DELIM_COMMAND) || CO_fifo_trimSpaces(src, &insideComment)) {
|
||||
|
|
@ -1056,7 +1056,7 @@ size_t CO_fifo_cpyTok2Hex(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
|
||||
if (isxdigit((int)c) != 0) {
|
||||
/* first or second hex digit */
|
||||
if (step == 0) {
|
||||
if (step == 0U) {
|
||||
firstChar = c;
|
||||
step = 1;
|
||||
}
|
||||
|
|
@ -1080,7 +1080,7 @@ size_t CO_fifo_cpyTok2Hex(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
}
|
||||
else {
|
||||
/* this is space or delimiter */
|
||||
if (step == 1) {
|
||||
if (step == 1U) {
|
||||
/* write the byte */
|
||||
uint8_t s[2];
|
||||
int32_t num;
|
||||
|
|
@ -1143,7 +1143,7 @@ size_t CO_fifo_cpyTok2Vs(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
|
||||
/* repeat until destination space available and no error and not finished
|
||||
* and source characters available */
|
||||
while ((destSpace > 0) && ((st & CO_fifo_st_errMask) == 0) && !finished) {
|
||||
while ((destSpace > 0U) && ((st & CO_fifo_st_errMask) == 0U) && !finished) {
|
||||
uint8_t c;
|
||||
if (!CO_fifo_getc(src, &c)) {
|
||||
break;
|
||||
|
|
@ -1169,9 +1169,9 @@ size_t CO_fifo_cpyTok2Vs(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
if (c == DELIM_DQUOTE) {
|
||||
/* double quote found, this may be end of the string or escaped
|
||||
* double quote (with two double quotes) */
|
||||
step += 2;
|
||||
step += 2U;
|
||||
}
|
||||
else if ((isgraph((int)c) == 0) && (step == 2)) {
|
||||
else if ((isgraph((int)c) == 0) && (step == 2U)) {
|
||||
/* end of single word string */
|
||||
bool_t insideComment = false;
|
||||
if ((c == DELIM_COMMAND)
|
||||
|
|
@ -1201,11 +1201,11 @@ size_t CO_fifo_cpyTok2Vs(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
/* escaped double quote, copy the character and continue */
|
||||
CO_fifo_putc(dest, c);
|
||||
destSpace--;
|
||||
step -= 2;
|
||||
step -= 2U;
|
||||
}
|
||||
else {
|
||||
/* previous character was closing double quote */
|
||||
if (step == 4) {
|
||||
if (step == 4U) {
|
||||
/* no opening double quote, syntax error */
|
||||
st |= CO_fifo_st_errTok;
|
||||
}
|
||||
|
|
@ -1303,20 +1303,20 @@ size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
else {
|
||||
/* get memorized variables from previous function calls */
|
||||
step = (uint8_t)(dest->aux >> 24);
|
||||
dword = dest->aux & 0xFFFFFF;
|
||||
dword = dest->aux & 0xFFFFFFU;
|
||||
}
|
||||
|
||||
/* repeat until destination space available and no error and not finished
|
||||
* and source characters available */
|
||||
while ((destSpace >= 3) && ((st & CO_fifo_st_errMask) == 0) && !finished) {
|
||||
while ((destSpace >= 3U) && ((st & CO_fifo_st_errMask) == 0U) && !finished) {
|
||||
uint8_t c;
|
||||
if (!CO_fifo_getc(src, &c)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (step >= 5) {
|
||||
if (step >= 5U) {
|
||||
/* String token is finished, waiting for command delimiter */
|
||||
bool_t insideComment = step > 5;
|
||||
bool_t insideComment = step > 5U;
|
||||
if ((c == DELIM_COMMAND) || CO_fifo_trimSpaces(src, &insideComment)) {
|
||||
st |= CO_fifo_st_closed;
|
||||
finished = true;
|
||||
|
|
@ -1333,12 +1333,12 @@ size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
continue;
|
||||
}
|
||||
|
||||
uint8_t code = base64DecTable[c & 0x7F];
|
||||
uint8_t code = base64DecTable[c & 0x7FU];
|
||||
|
||||
if (((c & 0x80) != 0) || ((code & 0x80) != 0)) {
|
||||
if (((c & 0x80U) != 0U) || ((code & 0x80U) != 0U)) {
|
||||
st |= CO_fifo_st_errTok;
|
||||
}
|
||||
else if (code >= 64 /* '=' (pad) or DELIM_COMMAND or space */) {
|
||||
else if (code >= 64U /* '=' (pad) or DELIM_COMMAND or space */) {
|
||||
/* base64 string finished, write remaining bytes */
|
||||
switch (step) {
|
||||
case 2:
|
||||
|
|
@ -1348,7 +1348,7 @@ size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
case 3:
|
||||
CO_fifo_putc(dest, (uint8_t)(dword >> 10));
|
||||
CO_fifo_putc(dest, (uint8_t)(dword >> 2));
|
||||
destSpace -= 2;
|
||||
destSpace -= 2U;
|
||||
break;
|
||||
default:
|
||||
/* MISRA C 2004 15.3 */
|
||||
|
|
@ -1366,11 +1366,11 @@ size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
}
|
||||
else {
|
||||
dword = (dword << 6) | code;
|
||||
if (step++ == 3) {
|
||||
CO_fifo_putc(dest, (uint8_t)((dword >> 16) & 0xFF));
|
||||
CO_fifo_putc(dest, (uint8_t)((dword >> 8) & 0xFF));
|
||||
CO_fifo_putc(dest, (uint8_t)(dword & 0xFF));
|
||||
destSpace -= 3;
|
||||
if (step++ == 3U) {
|
||||
CO_fifo_putc(dest, (uint8_t)((dword >> 16) & 0xFFU));
|
||||
CO_fifo_putc(dest, (uint8_t)((dword >> 8) & 0xFFU));
|
||||
CO_fifo_putc(dest, (uint8_t)(dword & 0xFFU));
|
||||
destSpace -= 3U;
|
||||
dword = 0;
|
||||
step = 0;
|
||||
}
|
||||
|
|
@ -1380,7 +1380,7 @@ size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status) {
|
|||
if (!finished) {
|
||||
st |= CO_fifo_st_partial;
|
||||
/* memorize variables for next iteration */
|
||||
dest->aux = ((uint32_t)step << 24) | (dword & 0xFFFFFF);
|
||||
dest->aux = ((uint32_t)step << 24) | (dword & 0xFFFFFFU);
|
||||
}
|
||||
|
||||
if (status != NULL) *status = st;
|
||||
|
|
|
|||
|
|
@ -64,13 +64,13 @@ void CO_LEDs_process(CO_LEDs_t *LEDs,
|
|||
bool_t tick = false;
|
||||
|
||||
LEDs->LEDtmr50ms += timeDifference_us;
|
||||
while (LEDs->LEDtmr50ms >= 50000) {
|
||||
bool_t rdFlickerNext = (LEDs->LEDred & CO_LED_flicker) == 0;
|
||||
while (LEDs->LEDtmr50ms >= 50000U) {
|
||||
|
||||
tick = true;
|
||||
LEDs->LEDtmr50ms -= 50000;
|
||||
LEDs->LEDtmr50ms -= 50000U;
|
||||
|
||||
if (++LEDs->LEDtmr200ms > 3) {
|
||||
if (++LEDs->LEDtmr200ms > 3U) {
|
||||
/* calculate 2,5Hz blinking and flashing */
|
||||
LEDs->LEDtmr200ms = 0;
|
||||
rd = gr = 0;
|
||||
|
|
|
|||
|
|
@ -75,19 +75,19 @@ extern "C" {
|
|||
|
||||
/** Bitfield for combining with red or green led */
|
||||
typedef enum {
|
||||
CO_LED_flicker = 0x01, /**< LED flickering 10Hz */
|
||||
CO_LED_blink = 0x02, /**< LED blinking 2,5Hz */
|
||||
CO_LED_flash_1 = 0x04, /**< LED single flash */
|
||||
CO_LED_flash_2 = 0x08, /**< LED double flash */
|
||||
CO_LED_flash_3 = 0x10, /**< LED triple flash */
|
||||
CO_LED_flash_4 = 0x20, /**< LED quadruple flash */
|
||||
CO_LED_CANopen = 0x80 /**< LED CANopen according to CiA 303-3 */
|
||||
CO_LED_flicker = 0x01U, /**< LED flickering 10Hz */
|
||||
CO_LED_blink = 0x02U, /**< LED blinking 2,5Hz */
|
||||
CO_LED_flash_1 = 0x04U, /**< LED single flash */
|
||||
CO_LED_flash_2 = 0x08U, /**< LED double flash */
|
||||
CO_LED_flash_3 = 0x10U, /**< LED triple flash */
|
||||
CO_LED_flash_4 = 0x20U, /**< LED quadruple flash */
|
||||
CO_LED_CANopen = 0x80U /**< LED CANopen according to CiA 303-3 */
|
||||
} CO_LED_BITFIELD_t;
|
||||
|
||||
/** Get on/off state for green led for specified bitfield */
|
||||
#define CO_LED_RED(LEDs, BITFIELD) (((LEDs)->LEDred & BITFIELD) ? 1 : 0)
|
||||
#define CO_LED_RED(LEDs, BITFIELD) ((((LEDs)->LEDred & BITFIELD) != 0U) ? 1U : 0U)
|
||||
/** Get on/off state for green led for specified bitfield */
|
||||
#define CO_LED_GREEN(LEDs, BITFIELD) (((LEDs)->LEDgreen & BITFIELD) ? 1 : 0)
|
||||
#define CO_LED_GREEN(LEDs, BITFIELD) ((((LEDs)->LEDgreen & BITFIELD) != 0U) ? 1U : 0U)
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
152
304/CO_SRDO.c
152
304/CO_SRDO.c
|
|
@ -44,7 +44,7 @@
|
|||
#define CO_SRDO_INVALID (0U)
|
||||
#define CO_SRDO_TX (1U)
|
||||
#define CO_SRDO_RX (2U)
|
||||
#define CO_SRDO_VALID_MAGIC (0xA5)
|
||||
#define CO_SRDO_VALID_MAGIC (0xA5U)
|
||||
|
||||
/* macro for information about SRDO configuration error */
|
||||
#define ERR_INFO(index, subindex, info) (((uint32_t)(index) << 16) | ((uint32_t)(subindex) << 8) | ((uint32_t)(info)))
|
||||
|
|
@ -147,7 +147,7 @@ OD_not_write_same_value(OD_stream_t *stream, const void *buf, OD_size_t count) {
|
|||
// The conformance test tool does not recognize CANopen Safety and on all object dictionaty tries to read and write the same value
|
||||
OD_size_t countRead = 0;
|
||||
uint8_t bufRead[6] = { 0 };
|
||||
if( count > 6 ) {
|
||||
if( count > 6U ) {
|
||||
return false;
|
||||
}
|
||||
ODR_t returnCode = OD_readOriginal(stream, bufRead, count, &countRead);
|
||||
|
|
@ -166,7 +166,7 @@ OD_read_SRDO_communicationParam(OD_stream_t* stream, void* buf, OD_size_t count,
|
|||
ODR_t returnCode = OD_readOriginal(stream, buf, count, countRead);
|
||||
|
||||
/* When reading COB_ID, add Node-Id to the read value, if necessary */
|
||||
if ((returnCode == ODR_OK) && ((stream->subIndex == 5U) || (stream->subIndex == 6U)) && (*countRead == 4)) {
|
||||
if ((returnCode == ODR_OK) && ((stream->subIndex == 5U) || (stream->subIndex == 6U)) && (*countRead == 4U)) {
|
||||
CO_SRDO_t* SRDO = stream->object;
|
||||
|
||||
uint32_t value = CO_getUint32(buf);
|
||||
|
|
@ -174,7 +174,7 @@ OD_read_SRDO_communicationParam(OD_stream_t* stream, void* buf, OD_size_t count,
|
|||
|
||||
/* If default COB ID is used, then OD entry does not contain $NodeId. Add it here. */
|
||||
if ((value == defaultCOB_ID) && (SRDO->nodeId <= 64U)) {
|
||||
value += (uint32_t)SRDO->nodeId * 2;
|
||||
value += (uint32_t)SRDO->nodeId * 2U;
|
||||
}
|
||||
|
||||
(void)CO_setUint32(buf, value);
|
||||
|
|
@ -185,7 +185,7 @@ OD_read_SRDO_communicationParam(OD_stream_t* stream, void* buf, OD_size_t count,
|
|||
|
||||
static ODR_t
|
||||
OD_write_SRDO_communicationParam(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) {
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4)) {
|
||||
if ((stream == NULL) || (buf == NULL) || (countWritten == NULL) || (count > 4U)) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
||||
|
|
@ -212,19 +212,19 @@ OD_write_SRDO_communicationParam(OD_stream_t* stream, const void* buf, OD_size_t
|
|||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
SRDO->informationDirection = value;
|
||||
} else if (stream->subIndex == 2) { /* SCT */
|
||||
} else if (stream->subIndex == 2U) { /* SCT */
|
||||
uint16_t value = CO_getUint16(buf);
|
||||
if (value < ((CO_CONFIG_SRDO_MINIMUM_DELAY / 1000) + 1)) {
|
||||
if (value < ((CO_CONFIG_SRDO_MINIMUM_DELAY / 1000U) + 1U)) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
} else if (stream->subIndex == 3) { /* SRVT */
|
||||
} else if (stream->subIndex == 3U) { /* SRVT */
|
||||
uint8_t value = CO_getUint8(buf);
|
||||
if (value == 0) {
|
||||
if (value == 0U) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
} else if (stream->subIndex == 4) { /* Transmission_type */
|
||||
} else if (stream->subIndex == 4U) { /* Transmission_type */
|
||||
uint8_t value = CO_getUint8(buf);
|
||||
if (value != 254) {
|
||||
if (value != 254U) {
|
||||
return ODR_INVALID_VALUE;
|
||||
}
|
||||
} else if ((stream->subIndex == 5U) || (stream->subIndex == 6U)) { /* COB_ID */
|
||||
|
|
@ -233,12 +233,12 @@ OD_write_SRDO_communicationParam(OD_stream_t* stream, const void* buf, OD_size_t
|
|||
uint16_t defaultCOB_ID = SRDO->defaultCOB_ID + index;
|
||||
|
||||
/* check value range, the spec does not specify if COB-ID flags are allowed */
|
||||
if ((value < 0x101) || (value > 0x180U) || ((value & 1) == index)) {
|
||||
if ((value < 0x101U) || (value > 0x180U) || ((value & 1U) == index)) {
|
||||
return ODR_INVALID_VALUE; /* Invalid value for parameter (download only). */
|
||||
}
|
||||
|
||||
/* if default COB-ID is being written, write defaultCOB_ID without nodeId */
|
||||
if ((SRDO->nodeId <= 64U) && (value == (defaultCOB_ID + ((uint32_t)SRDO->nodeId * 2)))) {
|
||||
if ((SRDO->nodeId <= 64U) && (value == (defaultCOB_ID + ((uint32_t)SRDO->nodeId * 2U)))) {
|
||||
value = defaultCOB_ID;
|
||||
(void)CO_setUint32(bufCopy, value);
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ OD_write_SRDO_mappingParam(OD_stream_t* stream, const void* buf, OD_size_t count
|
|||
}
|
||||
|
||||
/* SRDO must be disabled */
|
||||
if (SRDO->informationDirection != 0) {
|
||||
if (SRDO->informationDirection != 0U) {
|
||||
return ODR_UNSUPP_ACCESS; /* Unsupported access to an object. */
|
||||
}
|
||||
|
||||
|
|
@ -283,7 +283,7 @@ OD_write_SRDO_mappingParam(OD_stream_t* stream, const void* buf, OD_size_t count
|
|||
if (stream->subIndex == 0U) {
|
||||
uint8_t value = CO_getUint8(buf);
|
||||
/* only odd numbers are allowed */
|
||||
if ((value > CO_SRDO_MAX_MAPPED_ENTRIES) || (value & 1)) {
|
||||
if ((value > CO_SRDO_MAX_MAPPED_ENTRIES) || ((value & 1U) != 0U)) {
|
||||
return ODR_MAP_LEN; /* Number and length of object to be mapped exceeds SRDO length. */
|
||||
}
|
||||
SRDO->mappedObjectsCount = value;
|
||||
|
|
@ -378,7 +378,7 @@ CO_SRDO_init_start(CO_SRDOGuard_t* SRDOGuard, OD_entry_t* OD_13FE_configurationV
|
|||
/* Configure SRDOGuard->OD_IO_configurationValid variable.
|
||||
* It will be used for writing 0 to OD variable 13FE,00 */
|
||||
odRet = OD_getSub(OD_13FE_configurationValid, 0, &SRDOGuard->OD_IO_configurationValid, false);
|
||||
if ((odRet != ODR_OK) || (SRDOGuard->OD_IO_configurationValid.stream.dataLength != 1)) {
|
||||
if ((odRet != ODR_OK) || (SRDOGuard->OD_IO_configurationValid.stream.dataLength != 1U)) {
|
||||
if (errInfo != NULL) {
|
||||
*errInfo = (((uint32_t)OD_getIndex(OD_13FE_configurationValid)) << 8) | 1U;
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
}
|
||||
|
||||
/* clear object and configure some object variables */
|
||||
if (err == 0) {
|
||||
if (err == 0U) {
|
||||
(void)memset(SRDO, 0, sizeof(CO_SRDO_t));
|
||||
|
||||
SRDO->SRDOGuard = SRDOGuard;
|
||||
|
|
@ -456,89 +456,89 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
}
|
||||
|
||||
/* Get variables from object Dictionary and verify it's structure. */
|
||||
if (err == 0) {
|
||||
if (err == 0U) {
|
||||
if (OD_get_u8(OD_130x_SRDOCommPar, 0, &cp_highestSubindexSupported, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 0, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 0, 1);
|
||||
}
|
||||
else if (OD_get_u8(OD_130x_SRDOCommPar, 1, &informationDirection, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 1, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 1, 1);
|
||||
}
|
||||
else if (OD_get_u16(OD_130x_SRDOCommPar, 2, &safetyCycleTime, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 2, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 2, 1);
|
||||
}
|
||||
else if (OD_get_u8(OD_130x_SRDOCommPar, 3, &safetyRelatedValidationTime, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 3, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 3, 1);
|
||||
}
|
||||
else if (OD_get_u8(OD_130x_SRDOCommPar, 4, &transmissionType, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 4, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 4, 1);
|
||||
}
|
||||
else if (OD_get_u32(OD_130x_SRDOCommPar, 5, &COB_ID1_normal, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 5, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 5, 1);
|
||||
}
|
||||
else if (OD_get_u32(OD_130x_SRDOCommPar, 6, &COB_ID2_inverted, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 6, 1);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 6, 1);
|
||||
}
|
||||
else if (OD_get_u8(OD_13FE_configurationValid, 0, &configurationValid, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x13FE, 0, 1);
|
||||
err = ERR_INFO(0x13FEU, 0, 1);
|
||||
}
|
||||
else if (OD_get_u16(OD_13FF_safetyConfigurationSignature, SRDO_Index + 1, &crcSignatureFromOD, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x13FF, SRDO_Index + 1, 1);
|
||||
else if (OD_get_u16(OD_13FF_safetyConfigurationSignature, SRDO_Index + 1U, &crcSignatureFromOD, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x13FFU, SRDO_Index + 1U, 1);
|
||||
}
|
||||
else if (OD_get_u8(OD_138x_SRDOMapPar, 0, &mappedObjectsCount, true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, 0, 1);
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, 0, 1);
|
||||
}
|
||||
else {
|
||||
for (uint8_t i = 0; i < mappedObjectsCount; i++) {
|
||||
if (OD_get_u32(OD_138x_SRDOMapPar, i+1, &mapping[i], true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, i+1, 1);
|
||||
if (OD_get_u32(OD_138x_SRDOMapPar, i+1U, &mapping[i], true) != ODR_OK) {
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, i+1U, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if OD contains default COB_IDs, add node-id */
|
||||
if ((COB_ID1_normal == defaultCOB_ID) && (COB_ID2_inverted == (defaultCOB_ID + 1)) && (nodeId <= 64U)) {
|
||||
uint32_t add = (uint32_t)SRDO->nodeId * 2;
|
||||
if ((COB_ID1_normal == defaultCOB_ID) && (COB_ID2_inverted == (defaultCOB_ID + 1U)) && (nodeId <= 64U)) {
|
||||
uint32_t add = (uint32_t)SRDO->nodeId * 2U;
|
||||
COB_ID1_normal += add;
|
||||
COB_ID2_inverted += add;
|
||||
}
|
||||
|
||||
/* If this fails, something is wrong with the Object Dictionary. Device have to be reprogrammed. */
|
||||
if (err != 0) {
|
||||
if (err != 0U) {
|
||||
ret = CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
}
|
||||
|
||||
/* If configurationValid is set and SRDO is valid, continue with further configuration */
|
||||
if ((err == 0) && (configurationValid == CO_SRDO_VALID_MAGIC) && (informationDirection != CO_SRDO_INVALID)) {
|
||||
if ((err == 0U) && (configurationValid == CO_SRDO_VALID_MAGIC) && (informationDirection != CO_SRDO_INVALID)) {
|
||||
configurationInProgress = true;
|
||||
}
|
||||
|
||||
/* Verify parameters from OD */
|
||||
if ((err == 0) && configurationInProgress) {
|
||||
if (cp_highestSubindexSupported != 6) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 0, 2);
|
||||
if ((err == 0U) && configurationInProgress) {
|
||||
if (cp_highestSubindexSupported != 6U) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 0, 2);
|
||||
}
|
||||
else if (informationDirection > 3) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 1, 2);
|
||||
else if (informationDirection > 3U) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 1, 2);
|
||||
}
|
||||
else if (safetyCycleTime < ((CO_CONFIG_SRDO_MINIMUM_DELAY / 1000) + 1)) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 2, 2);
|
||||
else if (safetyCycleTime < ((CO_CONFIG_SRDO_MINIMUM_DELAY / 1000U) + 1U)) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 2, 2);
|
||||
}
|
||||
else if (safetyRelatedValidationTime < 1) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 3, 2);
|
||||
else if (safetyRelatedValidationTime < 1U) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 3, 2);
|
||||
}
|
||||
else if (transmissionType != 254) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 4, 2);
|
||||
else if (transmissionType != 254U) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 4, 2);
|
||||
}
|
||||
else if ((COB_ID1_normal < 0x101) || ((COB_ID1_normal & 1) == 0)) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 5, 2);
|
||||
else if ((COB_ID1_normal < 0x101U) || ((COB_ID1_normal & 1U) == 0U)) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 5, 2);
|
||||
}
|
||||
else if (((COB_ID1_normal + 1) != COB_ID2_inverted) || (COB_ID2_inverted > 0x180)) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 6, 2);
|
||||
else if (((COB_ID1_normal + 1U) != COB_ID2_inverted) || (COB_ID2_inverted > 0x180U)) {
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 6, 2);
|
||||
}
|
||||
else if ((mappedObjectsCount > CO_SRDO_MAX_MAPPED_ENTRIES) || ((mappedObjectsCount & 1) != 0)) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, 0, 2);
|
||||
else if ((mappedObjectsCount > CO_SRDO_MAX_MAPPED_ENTRIES) || ((mappedObjectsCount & 1U) != 0U)) {
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, 0, 2);
|
||||
}
|
||||
else {
|
||||
/* MISRA C 2004 14.10 */
|
||||
|
|
@ -546,7 +546,7 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
}
|
||||
|
||||
/* Verify CRC */
|
||||
if ((err == 0) && configurationInProgress) {
|
||||
if ((err == 0U) && configurationInProgress) {
|
||||
uint16_t crcResult = 0x0000;
|
||||
uint16_t tmp_u16;
|
||||
uint32_t tmp_u32;
|
||||
|
|
@ -568,16 +568,16 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
}
|
||||
|
||||
if (crcResult != crcSignatureFromOD) {
|
||||
err = ERR_INFO(0x13FF, SRDO_Index + 1, 3);
|
||||
err = ERR_INFO(0x13FFU, SRDO_Index + 1U, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure mappings */
|
||||
if ((err == 0) && configurationInProgress) {
|
||||
if ((err == 0U) && configurationInProgress) {
|
||||
size_t srdoDataLength[2] = {0, 0};
|
||||
|
||||
for (uint8_t i = 0; i < mappedObjectsCount; i++) {
|
||||
uint8_t plain_inverted = i % 2;
|
||||
uint8_t plain_inverted = i % 2U;
|
||||
uint32_t map = mapping[i];
|
||||
uint16_t index = (uint16_t) (map >> 16);
|
||||
uint8_t subIndex = (uint8_t) (map >> 8);
|
||||
|
|
@ -587,10 +587,10 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
|
||||
/* total SRDO length can not be more than CO_SRDO_MAX_SIZE bytes */
|
||||
if (mappedLength > CO_SRDO_MAX_SIZE) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, i + 1, 4);
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, i + 1U, 4);
|
||||
}
|
||||
/* is there a reference to the dummy entry */
|
||||
else if ((index < 0x20) && (subIndex == 0)) {
|
||||
else if ((index < 0x20U) && (subIndex == 0U)) {
|
||||
OD_stream_t *stream = &OD_IO->stream;
|
||||
(void)memset(stream, 0, sizeof(OD_stream_t));
|
||||
stream->dataLength = stream->dataOffset = mappedLength;
|
||||
|
|
@ -603,16 +603,16 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
OD_entry_t *entry = OD_find(OD, index);
|
||||
ODR_t odRet = OD_getSub(entry, subIndex, &OD_IOcopy, false);
|
||||
if (odRet != ODR_OK) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, i + 1, 5);
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, i + 1U, 5);
|
||||
}
|
||||
else {
|
||||
/* verify access attributes, byte alignment and length */
|
||||
OD_attr_t testAttribute = (informationDirection == CO_SRDO_RX) ? ODA_RSRDO : ODA_TSRDO;
|
||||
if (((OD_IOcopy.stream.attribute & testAttribute) == 0)
|
||||
|| ((mappedLengthBits & 0x07) != 0)
|
||||
if (((OD_IOcopy.stream.attribute & testAttribute) == 0U)
|
||||
|| ((mappedLengthBits & 0x07U) != 0U)
|
||||
|| (OD_IOcopy.stream.dataLength < mappedLength)
|
||||
) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, i + 1, 6);
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, i + 1U, 6);
|
||||
}
|
||||
|
||||
/* Copy values and store mappedLength temporary. */
|
||||
|
|
@ -621,17 +621,17 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
srdoDataLength[plain_inverted] += mappedLength;
|
||||
}
|
||||
}
|
||||
if (err != 0) {
|
||||
if (err != 0U) {
|
||||
break;
|
||||
}
|
||||
} /* for (uint8_t i = 0; i < mappedObjectsCount; i++) */
|
||||
|
||||
if (err == 0) {
|
||||
if (err == 0U) {
|
||||
if (srdoDataLength[0] != srdoDataLength[1]) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, 0, 7);
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, 0, 7);
|
||||
}
|
||||
else if ((srdoDataLength[0] == 0) || (srdoDataLength[0] > CO_SRDO_MAX_SIZE)) {
|
||||
err = ERR_INFO(0x1381 + SRDO_Index, 0, 8);
|
||||
else if ((srdoDataLength[0] == 0U) || (srdoDataLength[0] > CO_SRDO_MAX_SIZE)) {
|
||||
err = ERR_INFO(0x1381U + SRDO_Index, 0, 8);
|
||||
}
|
||||
else {
|
||||
SRDO->dataLength = srdoDataLength[0];
|
||||
|
|
@ -641,7 +641,7 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
}
|
||||
|
||||
/* Configure CAN tx buffers */
|
||||
if ((err == 0) && configurationInProgress && (informationDirection == CO_SRDO_TX)) {
|
||||
if ((err == 0U) && configurationInProgress && (informationDirection == CO_SRDO_TX)) {
|
||||
|
||||
SRDO->CANtxBuff[0] = CO_CANtxBufferInit(CANdevTxNormal, /* CAN device */
|
||||
CANdevTxIdxNormal, /* index of specific buffer inside CAN module */
|
||||
|
|
@ -651,7 +651,7 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
0); /* synchronous message flag bit */
|
||||
|
||||
if (SRDO->CANtxBuff[0] == NULL) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 5, 10);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 5, 10);
|
||||
}
|
||||
|
||||
SRDO->CANtxBuff[1] = CO_CANtxBufferInit(CANdevTxInverted, /* CAN device */
|
||||
|
|
@ -662,12 +662,12 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
0); /* synchronous message flag bit */
|
||||
|
||||
if (SRDO->CANtxBuff[1] == NULL) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 6, 10);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 6, 10);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure CAN rx buffers */
|
||||
if ((err == 0) && configurationInProgress && (informationDirection == CO_SRDO_RX)) {
|
||||
if ((err == 0U) && configurationInProgress && (informationDirection == CO_SRDO_RX)) {
|
||||
CO_ReturnError_t ret;
|
||||
|
||||
ret = CO_CANrxBufferInit(CANdevRxNormal, /* CAN device */
|
||||
|
|
@ -679,7 +679,7 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
CO_SRDO_receive_normal); /* this function will process received message */
|
||||
|
||||
if (ret != CO_ERROR_NO) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 5, 11);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 5, 11);
|
||||
}
|
||||
|
||||
ret = CO_CANrxBufferInit(CANdevRxInverted, /* CAN device */
|
||||
|
|
@ -691,12 +691,12 @@ CO_SRDO_init(CO_SRDO_t* SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t* SRDOGuard, OD_
|
|||
CO_SRDO_receive_inverted); /* this function will process received message */
|
||||
|
||||
if (ret != CO_ERROR_NO) {
|
||||
err = ERR_INFO(0x1301 + SRDO_Index, 6, 11);
|
||||
err = ERR_INFO(0x1301U + SRDO_Index, 6, 11);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure remaining variables */
|
||||
if (err == 0) {
|
||||
if (err == 0U) {
|
||||
SRDO->informationDirection = informationDirection;
|
||||
SRDO->cycleTime_us = (uint32_t)safetyCycleTime * 1000U;
|
||||
SRDO->validationTime_us = (uint32_t)safetyRelatedValidationTime * 1000U;
|
||||
|
|
@ -765,7 +765,7 @@ CO_SRDO_process(CO_SRDO_t* SRDO, uint32_t timeDifference_us, uint32_t* timerNext
|
|||
|
||||
/* copy mapped data from Object Dictionary into CAN buffers */
|
||||
for (uint8_t i = 0; i < SRDO->mappedObjectsCount; i++) {
|
||||
uint8_t plain_inverted = i % 2;
|
||||
uint8_t plain_inverted = i % 2U;
|
||||
OD_IO_t *OD_IO = &SRDO->OD_IO[i];
|
||||
OD_stream_t *stream = &OD_IO->stream;
|
||||
|
||||
|
|
@ -898,7 +898,7 @@ CO_SRDO_process(CO_SRDO_t* SRDO, uint32_t timeDifference_us, uint32_t* timerNext
|
|||
if (data_ok) {
|
||||
size_t verifyLength[2] = { 0, 0 };
|
||||
for (uint8_t i = 0; i < SRDO->mappedObjectsCount; i++) {
|
||||
uint8_t plain_inverted = i % 2;
|
||||
uint8_t plain_inverted = i % 2U;
|
||||
OD_IO_t *OD_IO = &SRDO->OD_IO[i];
|
||||
OD_stream_t *stream = &OD_IO->stream;
|
||||
|
||||
|
|
|
|||
22
305/CO_LSS.h
22
305/CO_LSS.h
|
|
@ -183,16 +183,16 @@ typedef enum {
|
|||
* Definition of table_index for /CiA301/ bit timing table
|
||||
*/
|
||||
typedef enum {
|
||||
CO_LSS_BIT_TIMING_1000 = 0, /**< 1000kbit/s */
|
||||
CO_LSS_BIT_TIMING_800 = 1, /**< 800kbit/s */
|
||||
CO_LSS_BIT_TIMING_500 = 2, /**< 500kbit/s */
|
||||
CO_LSS_BIT_TIMING_250 = 3, /**< 250kbit/s */
|
||||
CO_LSS_BIT_TIMING_125 = 4, /**< 125kbit/s */
|
||||
/* reserved = 5 */
|
||||
CO_LSS_BIT_TIMING_50 = 6, /**< 50kbit/s */
|
||||
CO_LSS_BIT_TIMING_20 = 7, /**< 20kbit/s */
|
||||
CO_LSS_BIT_TIMING_10 = 8, /**< 10kbit/s */
|
||||
CO_LSS_BIT_TIMING_AUTO = 9, /**< Automatic bit rate detection */
|
||||
CO_LSS_BIT_TIMING_1000 = 0U, /**< 1000kbit/s */
|
||||
CO_LSS_BIT_TIMING_800 = 1U, /**< 800kbit/s */
|
||||
CO_LSS_BIT_TIMING_500 = 2U, /**< 500kbit/s */
|
||||
CO_LSS_BIT_TIMING_250 = 3U, /**< 250kbit/s */
|
||||
CO_LSS_BIT_TIMING_125 = 4U, /**< 125kbit/s */
|
||||
/* reserved = 5U */
|
||||
CO_LSS_BIT_TIMING_50 = 6U, /**< 50kbit/s */
|
||||
CO_LSS_BIT_TIMING_20 = 7U, /**< 20kbit/s */
|
||||
CO_LSS_BIT_TIMING_10 = 8U, /**< 10kbit/s */
|
||||
CO_LSS_BIT_TIMING_AUTO = 9U, /**< Automatic bit rate detection */
|
||||
} CO_LSS_bitTimingTable_t;
|
||||
|
||||
/**
|
||||
|
|
@ -220,7 +220,7 @@ static const uint16_t CO_LSS_bitTimingTableLookup[] = {
|
|||
/**
|
||||
* Macro to check if node id is valid
|
||||
*/
|
||||
#define CO_LSS_NODE_ID_VALID(nid) (((nid >= 1) && (nid <= 0x7F)) || (nid == CO_LSS_NODE_ID_ASSIGNMENT))
|
||||
#define CO_LSS_NODE_ID_VALID(nid) (((nid >= 1U) && (nid <= 0x7FU)) || (nid == CO_LSS_NODE_ID_ASSIGNMENT))
|
||||
|
||||
/**
|
||||
* Macro to check if two LSS addresses are equal
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ static void CO_LSSslave_receive(void *object, void *msg)
|
|||
ack = true;
|
||||
LSSslave->fastscanPos = lssNext;
|
||||
|
||||
if ((bitCheck == 0) && (lssNext < lssSub)) {
|
||||
if ((bitCheck == 0U) && (lssNext < lssSub)) {
|
||||
/* complete match, enter configuration state */
|
||||
LSSslave->lssState = CO_LSS_STATE_CONFIGURATION;
|
||||
}
|
||||
|
|
@ -375,7 +375,7 @@ bool_t CO_LSSslave_process(CO_LSSslave_t *LSSslave) {
|
|||
errorCode = CO_LSS_CFG_BIT_TIMING_OK;
|
||||
errorCodeManuf = CO_LSS_CFG_BIT_TIMING_OK;
|
||||
|
||||
if ((tableSelector == 0) && CO_LSS_BIT_TIMING_VALID(tableIndex)) {
|
||||
if ((tableSelector == 0U) && CO_LSS_BIT_TIMING_VALID(tableIndex)) {
|
||||
uint16_t bit = CO_LSS_bitTimingTableLookup[tableIndex];
|
||||
bool_t bit_rate_supported = LSSslave->pFunctLSScheckBitRate(
|
||||
LSSslave->functLSScheckBitRateObject, bit);
|
||||
|
|
|
|||
70
CANopen.c
70
CANopen.c
|
|
@ -766,7 +766,7 @@ void CO_delete(CO_t *co) {
|
|||
#endif
|
||||
static CO_EM_t COO_EM;
|
||||
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
|
||||
static CO_EM_fifo_t COO_EM_FIFO[CO_GET_CNT(ARR_1003) + 1];
|
||||
static CO_EM_fifo_t COO_EM_FIFO[CO_GET_CNT(ARR_1003) + 1U];
|
||||
#endif
|
||||
static CO_SDOserver_t COO_SDOserver[OD_CNT_SDO_SRV];
|
||||
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
|
||||
|
|
@ -895,7 +895,7 @@ bool_t CO_isLSSslaveEnabled(CO_t *co) {
|
|||
(void) co; /* may be unused */
|
||||
bool_t en = false;
|
||||
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
|
||||
if (CO_GET_CNT(LSS_SLV) == 1) { en = true; }
|
||||
if (CO_GET_CNT(LSS_SLV) == 1U) { en = true; }
|
||||
#endif
|
||||
return en;
|
||||
}
|
||||
|
|
@ -931,7 +931,7 @@ CO_ReturnError_t CO_LSSinit(CO_t *co,
|
|||
{
|
||||
CO_ReturnError_t err;
|
||||
|
||||
if (co == NULL || CO_GET_CNT(LSS_SLV) != 1) {
|
||||
if ((co == NULL) || (CO_GET_CNT(LSS_SLV) != 1U)) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
|
|
@ -969,15 +969,15 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
(void)SDOclientTimeoutTime_ms; (void)SDOclientBlockTransfer;
|
||||
CO_ReturnError_t err;
|
||||
|
||||
if (co == NULL
|
||||
|| (CO_GET_CNT(NMT) == 0 && NMT == NULL)
|
||||
|| (CO_GET_CNT(EM) == 0 && em == NULL)
|
||||
if ((co == NULL)
|
||||
|| ((CO_GET_CNT(NMT) == 0U) && (NMT == NULL))
|
||||
|| ((CO_GET_CNT(EM) == 0U) && (em == NULL))
|
||||
) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
/* alternatives */
|
||||
if (CO_GET_CNT(NMT) == 0) {
|
||||
if (CO_GET_CNT(NMT) == 0U) {
|
||||
co->NMT = NMT;
|
||||
}
|
||||
if (em == NULL) {
|
||||
|
|
@ -987,18 +987,18 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
/* Verify CANopen Node-ID */
|
||||
co->nodeIdUnconfigured = false;
|
||||
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
|
||||
if (CO_GET_CNT(LSS_SLV) == 1 && nodeId == CO_LSS_NODE_ID_ASSIGNMENT) {
|
||||
if ((CO_GET_CNT(LSS_SLV) == 1U) && (nodeId == CO_LSS_NODE_ID_ASSIGNMENT)) {
|
||||
co->nodeIdUnconfigured = true;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (nodeId < 1 || nodeId > 127) {
|
||||
if ((nodeId < 1U) || (nodeId > 127U)) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
else { /* MISRA C 2004 14.10 */ }
|
||||
|
||||
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
|
||||
if (CO_GET_CNT(LEDS) == 1) {
|
||||
if (CO_GET_CNT(LEDS) == 1U) {
|
||||
err = CO_LEDs_init(co->LEDs);
|
||||
if (err) { return err; }
|
||||
}
|
||||
|
|
@ -1010,13 +1010,13 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
}
|
||||
|
||||
/* Emergency */
|
||||
if (CO_GET_CNT(EM) == 1) {
|
||||
if (CO_GET_CNT(EM) == 1U) {
|
||||
err = CO_EM_init(co->em,
|
||||
co->CANmodule,
|
||||
OD_GET(H1001, OD_H1001_ERR_REG),
|
||||
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
|
||||
co->em_fifo,
|
||||
(CO_GET_CNT(ARR_1003) + 1),
|
||||
(CO_GET_CNT(ARR_1003) + 1U),
|
||||
#endif
|
||||
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
|
||||
OD_GET(H1014, OD_H1014_COBID_EMERGENCY),
|
||||
|
|
@ -1041,7 +1041,7 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
}
|
||||
|
||||
/* NMT_Heartbeat */
|
||||
if (CO_GET_CNT(NMT) == 1) {
|
||||
if (CO_GET_CNT(NMT) == 1U) {
|
||||
err = CO_NMT_init(co->NMT,
|
||||
OD_GET(H1017, OD_H1017_PRODUCER_HB_TIME),
|
||||
em,
|
||||
|
|
@ -1064,7 +1064,7 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
}
|
||||
|
||||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
if (CO_GET_CNT(HB_CONS) == 1) {
|
||||
if (CO_GET_CNT(HB_CONS) == 1U) {
|
||||
err = CO_HBconsumer_init(co->HBcons,
|
||||
em,
|
||||
co->HBconsMonitoredNodes,
|
||||
|
|
@ -1101,7 +1101,7 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
#endif
|
||||
|
||||
/* SDOserver */
|
||||
if (CO_GET_CNT(SDO_SRV) > 0) {
|
||||
if (CO_GET_CNT(SDO_SRV) > 0U) {
|
||||
OD_entry_t *SDOsrvPar = OD_GET(H1200, OD_H1200_SDO_SERVER_1_PARAM);
|
||||
for (int16_t i = 0; i < CO_GET_CNT(SDO_SRV); i++) {
|
||||
err = CO_SDOserver_init(&co->SDOserver[i],
|
||||
|
|
@ -1137,7 +1137,7 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
#endif
|
||||
|
||||
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
|
||||
if (CO_GET_CNT(TIME) == 1) {
|
||||
if (CO_GET_CNT(TIME) == 1U) {
|
||||
err = CO_TIME_init(co->TIME,
|
||||
OD_GET(H1012, OD_H1012_COBID_TIME),
|
||||
co->CANmodule,
|
||||
|
|
@ -1152,7 +1152,7 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
#endif
|
||||
|
||||
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
|
||||
if (CO_GET_CNT(SYNC) == 1) {
|
||||
if (CO_GET_CNT(SYNC) == 1U) {
|
||||
err = CO_SYNC_init(co->SYNC,
|
||||
em,
|
||||
OD_GET(H1005, OD_H1005_COBID_SYNC),
|
||||
|
|
@ -1244,13 +1244,13 @@ CO_ReturnError_t CO_CANopenInitPDO(CO_t *co,
|
|||
if (co == NULL) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
if (nodeId < 1 || nodeId > 127 || co->nodeIdUnconfigured) {
|
||||
if ((nodeId < 1U) || (nodeId > 127U) || co->nodeIdUnconfigured) {
|
||||
return (co->nodeIdUnconfigured)
|
||||
? CO_ERROR_NODE_ID_UNCONFIGURED_LSS : CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
|
||||
if (CO_GET_CNT(RPDO) > 0) {
|
||||
if (CO_GET_CNT(RPDO) > 0U) {
|
||||
OD_entry_t *RPDOcomm = OD_GET(H1400, OD_H1400_RXPDO_1_PARAM);
|
||||
OD_entry_t *RPDOmap = OD_GET(H1600, OD_H1600_RXPDO_1_MAPPING);
|
||||
for (int16_t i = 0; i < CO_GET_CNT(RPDO); i++) {
|
||||
|
|
@ -1284,7 +1284,7 @@ CO_ReturnError_t CO_CANopenInitPDO(CO_t *co,
|
|||
#endif
|
||||
|
||||
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
|
||||
if (CO_GET_CNT(TPDO) > 0) {
|
||||
if (CO_GET_CNT(TPDO) > 0U) {
|
||||
OD_entry_t *TPDOcomm = OD_GET(H1800, OD_H1800_TXPDO_1_PARAM);
|
||||
OD_entry_t *TPDOmap = OD_GET(H1A00, OD_H1A00_TXPDO_1_MAPPING);
|
||||
for (int16_t i = 0; i < CO_GET_CNT(TPDO); i++) {
|
||||
|
|
@ -1332,7 +1332,7 @@ CO_ReturnError_t CO_CANopenInitSRDO(CO_t *co,
|
|||
if (co == NULL) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
if (nodeId < 1 || nodeId > 127 || co->nodeIdUnconfigured) {
|
||||
if ((nodeId < 1U) || (nodeId > 127U) || co->nodeIdUnconfigured) {
|
||||
return (co->nodeIdUnconfigured)
|
||||
? CO_ERROR_NODE_ID_UNCONFIGURED_LSS : CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
|
@ -1354,7 +1354,7 @@ CO_ReturnError_t CO_CANopenInitSRDO(CO_t *co,
|
|||
#endif
|
||||
|
||||
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
|
||||
if (CO_GET_CNT(SRDO) > 0) {
|
||||
if (CO_GET_CNT(SRDO) > 0U) {
|
||||
CO_ReturnError_t err;
|
||||
err = CO_SRDO_init_start(co->SRDOGuard,
|
||||
OD_GET(H13FE, OD_H13FE_SRDO_VALID),
|
||||
|
|
@ -1382,11 +1382,11 @@ CO_ReturnError_t CO_CANopenInitSRDO(CO_t *co,
|
|||
co->CANmodule,
|
||||
co->CANmodule,
|
||||
CANdevRxIdx,
|
||||
CANdevRxIdx + 1,
|
||||
CANdevRxIdx + 1U,
|
||||
co->CANmodule,
|
||||
co->CANmodule,
|
||||
CANdevTxIdx,
|
||||
CANdevTxIdx + 1,
|
||||
CANdevTxIdx + 1U,
|
||||
errInfo);
|
||||
if (err) { return err; }
|
||||
}
|
||||
|
|
@ -1415,7 +1415,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
CO_CANmodule_process(co->CANmodule);
|
||||
|
||||
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
|
||||
if (CO_GET_CNT(LSS_SLV) == 1) {
|
||||
if (CO_GET_CNT(LSS_SLV) == 1U) {
|
||||
if (CO_LSSslave_process(co->LSSslave)) {
|
||||
reset = CO_RESET_COMM;
|
||||
}
|
||||
|
|
@ -1438,7 +1438,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
#define CO_STATUS_FIRMWARE_DOWNLOAD_IN_PROGRESS 0
|
||||
#endif
|
||||
|
||||
if (CO_GET_CNT(LEDS) == 1) {
|
||||
if (CO_GET_CNT(LEDS) == 1U) {
|
||||
CO_LEDs_process(co->LEDs,
|
||||
timeDifference_us,
|
||||
unc ? CO_NMT_INITIALIZING : NMTstate,
|
||||
|
|
@ -1449,7 +1449,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
unc ? false : CO_isError(co->em, CO_EM_SYNC_TIME_OUT),
|
||||
unc ? false : (CO_isError(co->em, CO_EM_HEARTBEAT_CONSUMER)
|
||||
|| CO_isError(co->em, CO_EM_HB_CONSUMER_REMOTE_RESET)),
|
||||
CO_getErrorRegister(co->em) != 0,
|
||||
CO_getErrorRegister(co->em) != 0U,
|
||||
CO_STATUS_FIRMWARE_DOWNLOAD_IN_PROGRESS,
|
||||
timerNext_us);
|
||||
}
|
||||
|
|
@ -1461,7 +1461,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
}
|
||||
|
||||
/* Emergency */
|
||||
if (CO_GET_CNT(EM) == 1) {
|
||||
if (CO_GET_CNT(EM) == 1U) {
|
||||
CO_EM_process(co->em,
|
||||
NMTisPreOrOperational,
|
||||
timeDifference_us,
|
||||
|
|
@ -1469,7 +1469,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
}
|
||||
|
||||
/* NMT_Heartbeat */
|
||||
if (CO_GET_CNT(NMT) == 1) {
|
||||
if (CO_GET_CNT(NMT) == 1U) {
|
||||
reset = CO_NMT_process(co->NMT,
|
||||
&NMTstate,
|
||||
timeDifference_us,
|
||||
|
|
@ -1487,7 +1487,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
}
|
||||
|
||||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
if (CO_GET_CNT(HB_CONS) == 1) {
|
||||
if (CO_GET_CNT(HB_CONS) == 1U) {
|
||||
CO_HBconsumer_process(co->HBcons,
|
||||
NMTisPreOrOperational,
|
||||
timeDifference_us,
|
||||
|
|
@ -1498,7 +1498,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
#if (CO_CONFIG_NODE_GUARDING) & CO_CONFIG_NODE_GUARDING_SLAVE_ENABLE
|
||||
CO_nodeGuardingSlave_process(co->NGslave,
|
||||
NMTstate,
|
||||
(co->NMT->HBproducerTime_us > 0),
|
||||
(co->NMT->HBproducerTime_us > 0U),
|
||||
timeDifference_us,
|
||||
timerNext_us);
|
||||
#endif
|
||||
|
|
@ -1509,7 +1509,7 @@ CO_NMT_reset_cmd_t CO_process(CO_t *co,
|
|||
#endif
|
||||
|
||||
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
|
||||
if (CO_GET_CNT(TIME) == 1) {
|
||||
if (CO_GET_CNT(TIME) == 1U) {
|
||||
CO_TIME_process(co->TIME, NMTisPreOrOperational, timeDifference_us);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1535,10 +1535,10 @@ bool_t CO_process_SYNC(CO_t *co,
|
|||
{
|
||||
bool_t syncWas = false;
|
||||
|
||||
if (!co->nodeIdUnconfigured && CO_GET_CNT(SYNC) == 1) {
|
||||
if ((!co->nodeIdUnconfigured) && (CO_GET_CNT(SYNC) == 1U)) {
|
||||
CO_NMT_internalState_t NMTstate = CO_NMT_getInternalState(co->NMT);
|
||||
bool_t NMTisPreOrOperational = (NMTstate == CO_NMT_PRE_OPERATIONAL
|
||||
|| NMTstate == CO_NMT_OPERATIONAL);
|
||||
bool_t NMTisPreOrOperational = ((NMTstate == CO_NMT_PRE_OPERATIONAL)
|
||||
|| (NMTstate == CO_NMT_OPERATIONAL));
|
||||
|
||||
CO_SYNC_status_t sync_process = CO_SYNC_process(co->SYNC,
|
||||
NMTisPreOrOperational,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ static ODR_t OD_write_1010(OD_stream_t *stream, const void *buf,
|
|||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
/* verify arguments */
|
||||
if ((stream == NULL) || (stream->subIndex == 0) || (buf == NULL) || (count != 4)
|
||||
if ((stream == NULL) || (stream->subIndex == 0U) || (buf == NULL) || (count != 4U)
|
||||
|| (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -43,12 +43,12 @@ static ODR_t OD_write_1010(OD_stream_t *stream, const void *buf,
|
|||
|
||||
CO_storage_t *storage = stream->object;
|
||||
|
||||
if ((stream->subIndex == 0) || (storage->store == NULL) || !storage->enabled) {
|
||||
if ((stream->subIndex == 0U) || (storage->store == NULL) || !storage->enabled) {
|
||||
return ODR_READONLY;
|
||||
}
|
||||
|
||||
uint32_t val = CO_getUint32(buf);
|
||||
if (val != 0x65766173) {
|
||||
if (val != 0x65766173U) {
|
||||
return ODR_DATA_TRANSF;
|
||||
}
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ static ODR_t OD_write_1010(OD_stream_t *stream, const void *buf,
|
|||
for (uint8_t i = 0; i < storage->entriesCount; i++) {
|
||||
CO_storage_entry_t *entry = &storage->entries[i];
|
||||
|
||||
if ((stream->subIndex == 1) || (entry->subIndexOD == stream->subIndex)) {
|
||||
if (found == 0) found = 1;
|
||||
if ((entry->attr & CO_storage_cmd) != 0) {
|
||||
if ((stream->subIndex == 1U) || (entry->subIndexOD == stream->subIndex)) {
|
||||
if (found == 0U) found = 1;
|
||||
if ((entry->attr & (uint8_t)CO_storage_cmd) != 0U) {
|
||||
ODR_t code = storage->store(entry, storage->CANmodule);
|
||||
if (code != ODR_OK) returnCode = code;
|
||||
found = 2;
|
||||
|
|
@ -69,8 +69,8 @@ static ODR_t OD_write_1010(OD_stream_t *stream, const void *buf,
|
|||
}
|
||||
}
|
||||
|
||||
if (found != 2)
|
||||
returnCode = (found == 0) ? ODR_SUB_NOT_EXIST : ODR_READONLY;
|
||||
if (found != 2U)
|
||||
returnCode = (found == 0U) ? ODR_SUB_NOT_EXIST : ODR_READONLY;
|
||||
|
||||
if (returnCode == ODR_OK) *countWritten = sizeof(uint32_t);
|
||||
return returnCode;
|
||||
|
|
@ -86,7 +86,7 @@ static ODR_t OD_write_1011(OD_stream_t *stream, const void *buf,
|
|||
OD_size_t count, OD_size_t *countWritten)
|
||||
{
|
||||
/* verify arguments */
|
||||
if ((stream == NULL) || (stream->subIndex == 0) || (buf == NULL) || (count != 4)
|
||||
if ((stream == NULL) || (stream->subIndex == 0U) || (buf == NULL) || (count != 4U)
|
||||
|| (countWritten == NULL)
|
||||
) {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
|
|
@ -94,12 +94,12 @@ static ODR_t OD_write_1011(OD_stream_t *stream, const void *buf,
|
|||
|
||||
CO_storage_t *storage = stream->object;
|
||||
|
||||
if ((stream->subIndex == 0) || (storage->restore == NULL) || !storage->enabled){
|
||||
if ((stream->subIndex == 0U) || (storage->restore == NULL) || !storage->enabled){
|
||||
return ODR_READONLY;
|
||||
}
|
||||
|
||||
uint32_t val = CO_getUint32(buf);
|
||||
if (val != 0x64616F6C) {
|
||||
if (val != 0x64616F6CU) {
|
||||
return ODR_DATA_TRANSF;
|
||||
}
|
||||
|
||||
|
|
@ -110,9 +110,9 @@ static ODR_t OD_write_1011(OD_stream_t *stream, const void *buf,
|
|||
for (uint8_t i = 0; i < storage->entriesCount; i++) {
|
||||
CO_storage_entry_t *entry = &storage->entries[i];
|
||||
|
||||
if ((stream->subIndex == 1) || (entry->subIndexOD == stream->subIndex)) {
|
||||
if (found == 0) found = 1;
|
||||
if ((entry->attr & CO_storage_restore) != 0) {
|
||||
if ((stream->subIndex == 1U) || (entry->subIndexOD == stream->subIndex)) {
|
||||
if (found == 0U) found = 1;
|
||||
if ((entry->attr & (uint8_t)CO_storage_restore) != 0U) {
|
||||
ODR_t code = storage->restore(entry, storage->CANmodule);
|
||||
if (code != ODR_OK) returnCode = code;
|
||||
found = 2;
|
||||
|
|
@ -120,8 +120,8 @@ static ODR_t OD_write_1011(OD_stream_t *stream, const void *buf,
|
|||
}
|
||||
}
|
||||
|
||||
if (found != 2)
|
||||
returnCode = (found == 0) ? ODR_SUB_NOT_EXIST : ODR_READONLY;
|
||||
if (found != 2U)
|
||||
returnCode = (found == 0U) ? ODR_SUB_NOT_EXIST : ODR_READONLY;
|
||||
|
||||
if (returnCode == ODR_OK) *countWritten = sizeof(uint32_t);
|
||||
return returnCode;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ CO_ReturnError_t CO_storageEeprom_init(CO_storage_t *storage,
|
|||
bool_t eepromOvf = false;
|
||||
|
||||
/* verify arguments */
|
||||
if ((storage == NULL) || (entries == NULL) || (entriesCount == 0)
|
||||
if ((storage == NULL) || (entries == NULL) || (entriesCount == 0U)
|
||||
|| (storageInitError == NULL)
|
||||
) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
|
|
@ -159,10 +159,10 @@ CO_ReturnError_t CO_storageEeprom_init(CO_storage_t *storage,
|
|||
*storageInitError = 0;
|
||||
for (uint8_t i = 0; i < entriesCount; i++) {
|
||||
CO_storage_entry_t *entry = &entries[i];
|
||||
bool_t isAuto = (entry->attr & CO_storage_auto) != 0;
|
||||
bool_t isAuto = (entry->attr & (uint8_t)CO_storage_auto) != 0U;
|
||||
|
||||
/* verify arguments */
|
||||
if ((entry->addr == NULL) || (entry->len == 0) || (entry->subIndexOD < 2)) {
|
||||
if ((entry->addr == NULL) || (entry->len == 0U) || (entry->subIndexOD < 2U)) {
|
||||
*storageInitError = i;
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ CO_ReturnError_t CO_storageEeprom_init(CO_storage_t *storage,
|
|||
/* additional info in case of error */
|
||||
if (dataCorrupt) {
|
||||
uint32_t errorBit = entry->subIndexOD;
|
||||
if (errorBit > 31) errorBit = 31;
|
||||
if (errorBit > 31U) errorBit = 31;
|
||||
*storageInitError |= ((uint32_t) 1) << errorBit;
|
||||
ret = CO_ERROR_DATA_CORRUPT;
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ void CO_storageEeprom_auto_process(CO_storage_t *storage, bool_t saveAll) {
|
|||
for (uint8_t i = 0; i < storage->entriesCount; i++) {
|
||||
CO_storage_entry_t *entry = &storage->entries[i];
|
||||
|
||||
if ((entry->attr & CO_storage_auto) == 0)
|
||||
if ((entry->attr & (uint8_t)CO_storage_auto) == 0U)
|
||||
continue;
|
||||
|
||||
if (saveAll) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue