Replace type char with uint8_t, where appropriate.
Fix typos and clarify CO_ODinterface. Remove unnecessary types from CO_driver.h.
This commit is contained in:
parent
267a2dafb2
commit
7b5de9f383
8 changed files with 41 additions and 60 deletions
|
|
@ -39,7 +39,7 @@ OD_size_t OD_readOriginal(OD_stream_t *stream, uint8_t subIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */
|
OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */
|
||||||
const char *odData = (const char *)stream->dataObjectOriginal;
|
const uint8_t *odData = stream->dataObjectOriginal;
|
||||||
|
|
||||||
if (odData == NULL) {
|
if (odData == NULL) {
|
||||||
*returnCode = ODR_SUB_NOT_EXIST;
|
*returnCode = ODR_SUB_NOT_EXIST;
|
||||||
|
|
@ -49,18 +49,18 @@ OD_size_t OD_readOriginal(OD_stream_t *stream, uint8_t subIndex,
|
||||||
*returnCode = ODR_OK;
|
*returnCode = ODR_OK;
|
||||||
|
|
||||||
/* If previous read was partial or OD variable length is larger than
|
/* If previous read was partial or OD variable length is larger than
|
||||||
* current buffer len, then data was (will be) read in several segments */
|
* current buffer size, then data was (will be) read in several segments */
|
||||||
if (stream->dataOffset > 0 || dataLenToCopy > count) {
|
if (stream->dataOffset > 0 || dataLenToCopy > count) {
|
||||||
if (stream->dataOffset >= dataLenToCopy) {
|
if (stream->dataOffset >= dataLenToCopy) {
|
||||||
*returnCode = ODR_DEV_INCOMPAT;
|
*returnCode = ODR_DEV_INCOMPAT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* reduce for already copied data */
|
/* Reduce for already copied data */
|
||||||
dataLenToCopy -= stream->dataOffset;
|
dataLenToCopy -= stream->dataOffset;
|
||||||
odData += stream->dataOffset;
|
odData += stream->dataOffset;
|
||||||
|
|
||||||
if (dataLenToCopy > count) {
|
if (dataLenToCopy > count) {
|
||||||
/* not enough space in destionation buffer */
|
/* Not enough space in destination buffer */
|
||||||
dataLenToCopy = count;
|
dataLenToCopy = count;
|
||||||
stream->dataOffset += dataLenToCopy;
|
stream->dataOffset += dataLenToCopy;
|
||||||
*returnCode = ODR_PARTIAL;
|
*returnCode = ODR_PARTIAL;
|
||||||
|
|
@ -88,7 +88,7 @@ OD_size_t OD_writeOriginal(OD_stream_t *stream, uint8_t subIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */
|
OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */
|
||||||
char *odData = (char *)stream->dataObjectOriginal;
|
uint8_t *odData = stream->dataObjectOriginal;
|
||||||
|
|
||||||
if (odData == NULL) {
|
if (odData == NULL) {
|
||||||
*returnCode = ODR_SUB_NOT_EXIST;
|
*returnCode = ODR_SUB_NOT_EXIST;
|
||||||
|
|
@ -98,7 +98,8 @@ OD_size_t OD_writeOriginal(OD_stream_t *stream, uint8_t subIndex,
|
||||||
*returnCode = ODR_OK;
|
*returnCode = ODR_OK;
|
||||||
|
|
||||||
/* If previous write was partial or OD variable length is larger than
|
/* If previous write was partial or OD variable length is larger than
|
||||||
* current data len, then data was (will be) written in several segments */
|
* current buffer size, then data was (will be) written in several
|
||||||
|
* segments */
|
||||||
if (stream->dataOffset > 0 || dataLenToCopy > count) {
|
if (stream->dataOffset > 0 || dataLenToCopy > count) {
|
||||||
if (stream->dataOffset >= dataLenToCopy) {
|
if (stream->dataOffset >= dataLenToCopy) {
|
||||||
*returnCode = ODR_DEV_INCOMPAT;
|
*returnCode = ODR_DEV_INCOMPAT;
|
||||||
|
|
@ -125,12 +126,11 @@ OD_size_t OD_writeOriginal(OD_stream_t *stream, uint8_t subIndex,
|
||||||
*returnCode = ODR_DATA_LONG;
|
*returnCode = ODR_DATA_LONG;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
CO_LOCK_OD();
|
CO_LOCK_OD();
|
||||||
memcpy(odData, buf, dataLenToCopy);
|
memcpy(odData, buf, dataLenToCopy);
|
||||||
CO_UNLOCK_OD();
|
CO_UNLOCK_OD();
|
||||||
return dataLenToCopy;
|
return dataLenToCopy;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read value from variable from Object Dictionary disabled, see OD_IO_t*/
|
/* Read value from variable from Object Dictionary disabled, see OD_IO_t*/
|
||||||
|
|
@ -158,17 +158,17 @@ static OD_size_t OD_writeDisabled(OD_stream_t *stream, uint8_t subIndex,
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
const OD_entry_t *OD_find(const OD_t *od, uint16_t index) {
|
const OD_entry_t *OD_find(const OD_t *od, uint16_t index) {
|
||||||
unsigned int cur;
|
|
||||||
unsigned int min = 0;
|
|
||||||
unsigned int max = od->size - 1;
|
|
||||||
|
|
||||||
if (od == NULL || od->size == 0) {
|
if (od == NULL || od->size == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t cur;
|
||||||
|
uint16_t min = 0;
|
||||||
|
uint16_t max = od->size - 1;
|
||||||
|
|
||||||
/* Fast search in ordered Object Dictionary. If indexes are mixed,
|
/* Fast search in ordered Object Dictionary. If indexes are mixed,
|
||||||
* this won't work. If Object Dictionary has up to 2^N entries, then N is
|
* this won't work. If Object Dictionary has up to N entries, then the
|
||||||
* max number of loop passes. */
|
* max number of loop passes is log2(N) */
|
||||||
while (min < max) {
|
while (min < max) {
|
||||||
/* get entry between min and max */
|
/* get entry between min and max */
|
||||||
cur = (min + max) >> 1;
|
cur = (min + max) >> 1;
|
||||||
|
|
@ -177,9 +177,9 @@ const OD_entry_t *OD_find(const OD_t *od, uint16_t index) {
|
||||||
if (index == entry->index) {
|
if (index == entry->index) {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
else if (index < entry->index) {
|
|
||||||
max = cur;
|
if (index < entry->index) {
|
||||||
if(max > 0) max--;
|
max = (cur > 0) ? (cur - 1) : cur;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
min = cur + 1;
|
min = cur + 1;
|
||||||
|
|
@ -239,7 +239,7 @@ ODR_t OD_getSub(const OD_entry_t *entry, uint8_t subIndex,
|
||||||
io->stream.dataObjectOriginal = NULL;
|
io->stream.dataObjectOriginal = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *data = (char *)odo->data;
|
uint8_t *data = odo->data;
|
||||||
int i = subIndex - 1;
|
int i = subIndex - 1;
|
||||||
io->stream.dataObjectOriginal = data + odo->dataElementSizeof * i;
|
io->stream.dataObjectOriginal = data + odo->dataElementSizeof * i;
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +318,7 @@ uint32_t OD_getSDOabCode(ODR_t returnCode) {
|
||||||
0x060A0023UL, /* Resource not available: SDO connection */
|
0x060A0023UL, /* Resource not available: SDO connection */
|
||||||
0x08000000UL, /* General error */
|
0x08000000UL, /* General error */
|
||||||
0x08000020UL, /* Data cannot be transferred or stored to application */
|
0x08000020UL, /* Data cannot be transferred or stored to application */
|
||||||
0x08000021UL, /* Data cannot be transf. because of local control */
|
0x08000021UL, /* Data cannot be transferred because of local control */
|
||||||
0x08000022UL, /* Data cannot be tran. because of present device state */
|
0x08000022UL, /* Data cannot be tran. because of present device state */
|
||||||
0x08000023UL, /* Object dict. not present or dynamic generation fails */
|
0x08000023UL, /* Object dict. not present or dynamic generation fails */
|
||||||
0x08000024UL /* No data available */
|
0x08000024UL /* No data available */
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ typedef struct {
|
||||||
*
|
*
|
||||||
* Write can be restarted with @ref OD_rwRestart() function.
|
* Write can be restarted with @ref OD_rwRestart() function.
|
||||||
*
|
*
|
||||||
* At the moment, when Object Dictionary is initialised, every variable has
|
* At the moment, when Object Dictionary is initialized, every variable has
|
||||||
* assigned the same "write" function, which simply copies data to Object
|
* assigned the same "write" function, which simply copies data to Object
|
||||||
* Dictionary variable. Application can bind its own "write" function,
|
* Dictionary variable. Application can bind its own "write" function,
|
||||||
* similar as it can bind "read" function.
|
* similar as it can bind "read" function.
|
||||||
|
|
@ -426,9 +426,9 @@ static inline uint16_t OD_getIndex(const OD_entry_t *entry) {
|
||||||
/**
|
/**
|
||||||
* Restart read or write operation on OD variable
|
* Restart read or write operation on OD variable
|
||||||
*
|
*
|
||||||
* It is not necessary to call this function, if stream was initialised by
|
* It is not necessary to call this function, if stream was initialized by
|
||||||
* @ref OD_getSub(). It is also not necessary to call this function, if prevous
|
* @ref OD_getSub(). It is also not necessary to call this function, if
|
||||||
* read or write was successfully finished.
|
* previous read or write was successfully finished.
|
||||||
*
|
*
|
||||||
* @param stream Object Dictionary stream object.
|
* @param stream Object Dictionary stream object.
|
||||||
*/
|
*/
|
||||||
|
|
@ -448,7 +448,7 @@ uint32_t OD_getSDOabCode(ODR_t returnCode);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise extended OD object with own read/write functions
|
* Initialize extended OD object with own read/write functions
|
||||||
*
|
*
|
||||||
* This function works on OD object, which has IO extension enabled. It gives
|
* This function works on OD object, which has IO extension enabled. It gives
|
||||||
* application very powerful tool: definition of own IO access on own OD
|
* application very powerful tool: definition of own IO access on own OD
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
|
||||||
/* write data, in several passes if necessary */
|
/* write data, in several passes if necessary */
|
||||||
if (SDO_C->OD_IO.write != NULL) {
|
if (SDO_C->OD_IO.write != NULL) {
|
||||||
size_t count = CO_fifo_getOccupied(&SDO_C->bufFifo);
|
size_t count = CO_fifo_getOccupied(&SDO_C->bufFifo);
|
||||||
char buf[count + 2];
|
uint8_t buf[count + 2];
|
||||||
|
|
||||||
CO_fifo_read(&SDO_C->bufFifo, buf, count, NULL);
|
CO_fifo_read(&SDO_C->bufFifo, buf, count, NULL);
|
||||||
SDO_C->sizeTran += count;
|
SDO_C->sizeTran += count;
|
||||||
|
|
@ -1213,7 +1213,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
||||||
OD_size_t countData = SDO_C->OD_IO.stream.dataLength;
|
OD_size_t countData = SDO_C->OD_IO.stream.dataLength;
|
||||||
OD_size_t countBuf = (countData > 0 && countData <= countFifo)
|
OD_size_t countBuf = (countData > 0 && countData <= countFifo)
|
||||||
? countData : countFifo;
|
? countData : countFifo;
|
||||||
char buf[countBuf + 1];
|
uint8_t buf[countBuf + 1];
|
||||||
ODR_t odRet;
|
ODR_t odRet;
|
||||||
|
|
||||||
/* load data from OD variable into the buffer */
|
/* load data from OD variable into the buffer */
|
||||||
|
|
@ -1229,7 +1229,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
|
||||||
/* if data is string, send only data up to null termination */
|
/* if data is string, send only data up to null termination */
|
||||||
if (countRd > 0 && (SDO_C->attribute & ODA_STR) != 0) {
|
if (countRd > 0 && (SDO_C->attribute & ODA_STR) != 0) {
|
||||||
buf[countRd] = 0; /* (buf is one byte larger) */
|
buf[countRd] = 0; /* (buf is one byte larger) */
|
||||||
OD_size_t countStr = strlen(buf);
|
OD_size_t countStr = strlen((char *)buf);
|
||||||
if (countStr == 0) countStr = 1; /* ne zero length */
|
if (countStr == 0) countStr = 1; /* ne zero length */
|
||||||
if (countStr < countRd) {
|
if (countStr < countRd) {
|
||||||
/* string terminator found, finish read, shorten data */
|
/* string terminator found, finish read, shorten data */
|
||||||
|
|
|
||||||
|
|
@ -579,9 +579,7 @@ static bool_t validateAndWriteToOD(CO_SDOserver_t *SDO,
|
||||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_BLOCK
|
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_BLOCK
|
||||||
/* calculate crc on current data */
|
/* calculate crc on current data */
|
||||||
if (SDO->block_crcEnabled && crcOperation > 0) {
|
if (SDO->block_crcEnabled && crcOperation > 0) {
|
||||||
SDO->block_crc = crc16_ccitt((unsigned char *)SDO->buf,
|
SDO->block_crc = crc16_ccitt(SDO->buf, bufOffsetWrOrig, SDO->block_crc);
|
||||||
bufOffsetWrOrig,
|
|
||||||
SDO->block_crc);
|
|
||||||
if (crcOperation == 2 && crcClient != SDO->block_crc) {
|
if (crcOperation == 2 && crcClient != SDO->block_crc) {
|
||||||
*abortCode = CO_SDO_AB_CRC;
|
*abortCode = CO_SDO_AB_CRC;
|
||||||
SDO->state = CO_SDO_ST_ABORT;
|
SDO->state = CO_SDO_ST_ABORT;
|
||||||
|
|
@ -650,7 +648,7 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
||||||
|
|
||||||
/* load data from OD variable into the buffer */
|
/* load data from OD variable into the buffer */
|
||||||
ODR_t odRet;
|
ODR_t odRet;
|
||||||
char *bufShifted = SDO->buf + countRemain;
|
uint8_t *bufShifted = SDO->buf + countRemain;
|
||||||
OD_size_t countRd = SDO->OD_IO.read(&SDO->OD_IO.stream, SDO->subIndex,
|
OD_size_t countRd = SDO->OD_IO.read(&SDO->OD_IO.stream, SDO->subIndex,
|
||||||
bufShifted,
|
bufShifted,
|
||||||
countRdRequest,
|
countRdRequest,
|
||||||
|
|
@ -665,7 +663,7 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
||||||
/* if data is string, send only data up to null termination */
|
/* if data is string, send only data up to null termination */
|
||||||
if (countRd > 0 && (SDO->attribute & ODA_STR) != 0) {
|
if (countRd > 0 && (SDO->attribute & ODA_STR) != 0) {
|
||||||
bufShifted[countRd] = 0; /* (SDO->buf is one byte larger) */
|
bufShifted[countRd] = 0; /* (SDO->buf is one byte larger) */
|
||||||
OD_size_t countStr = strlen(bufShifted);
|
OD_size_t countStr = strlen((char *)bufShifted);
|
||||||
if (countStr == 0) countStr = 1; /* zero length is not allowed */
|
if (countStr == 0) countStr = 1; /* zero length is not allowed */
|
||||||
if (countStr < countRd) {
|
if (countStr < countRd) {
|
||||||
/* string terminator found, read is finished, shorten data */
|
/* string terminator found, read is finished, shorten data */
|
||||||
|
|
@ -707,9 +705,7 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
||||||
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_BLOCK
|
#if (CO_CONFIG_SDO_SRV) & CO_CONFIG_SDO_SRV_BLOCK
|
||||||
/* update the crc */
|
/* update the crc */
|
||||||
if (calculateCrc && SDO->block_crcEnabled) {
|
if (calculateCrc && SDO->block_crcEnabled) {
|
||||||
SDO->block_crc = crc16_ccitt((uint8_t *)bufShifted,
|
SDO->block_crc = crc16_ccitt(bufShifted, countRd, SDO->block_crc);
|
||||||
countRd,
|
|
||||||
SDO->block_crc);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1098,9 +1094,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
||||||
/* data were already loaded from OD variable, verify crc */
|
/* data were already loaded from OD variable, verify crc */
|
||||||
if ((SDO->CANrxData[0] & 0x04) != 0) {
|
if ((SDO->CANrxData[0] & 0x04) != 0) {
|
||||||
SDO->block_crcEnabled = true;
|
SDO->block_crcEnabled = true;
|
||||||
SDO->block_crc = crc16_ccitt((unsigned char *)SDO->buf,
|
SDO->block_crc = crc16_ccitt(SDO->buf, SDO->bufOffsetWr, 0);
|
||||||
SDO->bufOffsetWr,
|
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SDO->block_crcEnabled = false;
|
SDO->block_crcEnabled = false;
|
||||||
|
|
|
||||||
|
|
@ -493,7 +493,7 @@ typedef struct {
|
||||||
/** Timeout timer for SDO communication */
|
/** Timeout timer for SDO communication */
|
||||||
uint32_t timeoutTimer;
|
uint32_t timeoutTimer;
|
||||||
/** Interim data buffer for segmented or block transfer + byte for '\0' */
|
/** Interim data buffer for segmented or block transfer + byte for '\0' */
|
||||||
char buf[CO_CONFIG_SDO_SRV_BUFFER_SIZE + 1];
|
uint8_t buf[CO_CONFIG_SDO_SRV_BUFFER_SIZE + 1];
|
||||||
/** Offset of next free data byte available for write in the buffer. */
|
/** Offset of next free data byte available for write in the buffer. */
|
||||||
OD_size_t bufOffsetWr;
|
OD_size_t bufOffsetWr;
|
||||||
/** Offset of first data available for read in the buffer */
|
/** Offset of first data available for read in the buffer */
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,7 @@ extern "C" {
|
||||||
* @defgroup CO_dataTypes Basic definitions
|
* @defgroup CO_dataTypes Basic definitions
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* Target specific basic definitions and data types according to Misra C
|
* Target specific basic definitions and data types.
|
||||||
* specification.
|
|
||||||
*
|
*
|
||||||
* Must be defined in the **CO_driver_target.h** file.
|
* Must be defined in the **CO_driver_target.h** file.
|
||||||
*
|
*
|
||||||
|
|
@ -138,7 +137,7 @@ extern "C" {
|
||||||
/** Logical false, for general use */
|
/** Logical false, for general use */
|
||||||
#define false 0
|
#define false 0
|
||||||
/** Boolean data type for general use */
|
/** Boolean data type for general use */
|
||||||
typedef unsigned char bool_t;
|
typedef uint_fast8_t bool_t;
|
||||||
/** INTEGER8 in CANopen (0002h), 8-bit signed integer */
|
/** INTEGER8 in CANopen (0002h), 8-bit signed integer */
|
||||||
typedef signed char int8_t;
|
typedef signed char int8_t;
|
||||||
/** INTEGER16 in CANopen (0003h), 16-bit signed integer */
|
/** INTEGER16 in CANopen (0003h), 16-bit signed integer */
|
||||||
|
|
@ -159,12 +158,6 @@ typedef unsigned long long int uint64_t;
|
||||||
typedef float float32_t;
|
typedef float float32_t;
|
||||||
/** REAL64 in CANopen (0011h), double precision floating point value, 64-bit */
|
/** REAL64 in CANopen (0011h), double precision floating point value, 64-bit */
|
||||||
typedef double float64_t;
|
typedef double float64_t;
|
||||||
/** VISIBLE_STRING in CANopen (0009h), string of signed 8-bit values */
|
|
||||||
typedef char char_t;
|
|
||||||
/** OCTET_STRING in CANopen (000Ah), string of unsigned 8-bit values */
|
|
||||||
typedef unsigned char oChar_t;
|
|
||||||
/** DOMAIN in CANopen (000Fh), used to transfer a large block of data */
|
|
||||||
typedef unsigned char domain_t;
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,12 +185,9 @@ extern "C" {
|
||||||
/* NULL is defined in stddef.h */
|
/* NULL is defined in stddef.h */
|
||||||
/* true and false are defined in stdbool.h */
|
/* true and false are defined in stdbool.h */
|
||||||
/* int8_t to uint64_t are defined in stdint.h */
|
/* int8_t to uint64_t are defined in stdint.h */
|
||||||
typedef unsigned char bool_t;
|
typedef uint_fast8_t bool_t;
|
||||||
typedef float float32_t;
|
typedef float float32_t;
|
||||||
typedef double float64_t;
|
typedef double float64_t;
|
||||||
typedef char char_t;
|
|
||||||
typedef unsigned char oChar_t;
|
|
||||||
typedef unsigned char domain_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Access to received CAN message */
|
/* Access to received CAN message */
|
||||||
|
|
|
||||||
|
|
@ -265,12 +265,9 @@ extern "C" {
|
||||||
/* NULL is defined in stddef.h */
|
/* NULL is defined in stddef.h */
|
||||||
/* true and false are defined in stdbool.h */
|
/* true and false are defined in stdbool.h */
|
||||||
/* int8_t to uint64_t are defined in stdint.h */
|
/* int8_t to uint64_t are defined in stdint.h */
|
||||||
typedef unsigned char bool_t;
|
typedef uint_fast8_t bool_t;
|
||||||
typedef float float32_t;
|
typedef float float32_t;
|
||||||
typedef double float64_t;
|
typedef double float64_t;
|
||||||
typedef char char_t;
|
|
||||||
typedef unsigned char oChar_t;
|
|
||||||
typedef unsigned char domain_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* CAN receive message structure as aligned in socketCAN. */
|
/* CAN receive message structure as aligned in socketCAN. */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue