1
0
Fork 0
This commit is contained in:
Janez 2023-03-17 18:49:29 +01:00
commit 32d6106047
3 changed files with 15 additions and 22 deletions

View file

@ -621,13 +621,12 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
}
if (abortCode == CO_SDO_AB_NONE) {
OD_size_t countWritten = 0;
bool_t lock = OD_mappable(&SDO_C->OD_IO.stream);
/* write data to Object Dictionary */
if (lock) { CO_LOCK_OD(SDO_C->CANdevTx); }
CO_LOCK_OD(SDO_C->CANdevTx);
ODR_t odRet = SDO_C->OD_IO.write(&SDO_C->OD_IO.stream, buf,
(OD_size_t)count, &countWritten);
if (lock) { CO_UNLOCK_OD(SDO_C->CANdevTx); }
CO_UNLOCK_OD(SDO_C->CANdevTx);
/* verify for errors in write */
if (odRet != ODR_OK && odRet != ODR_PARTIAL) {
@ -1214,13 +1213,12 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
? countData : (OD_size_t)countFifo;
OD_size_t countRd = 0;
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1];
bool_t lock = OD_mappable(&SDO_C->OD_IO.stream);
/* load data from OD variable into the buffer */
if (lock) { CO_LOCK_OD(SDO_C->CANdevTx); }
CO_LOCK_OD(SDO_C->CANdevTx);
ODR_t odRet = SDO_C->OD_IO.read(&SDO_C->OD_IO.stream,
buf, countBuf, &countRd);
if (lock) { CO_UNLOCK_OD(SDO_C->CANdevTx); }
CO_UNLOCK_OD(SDO_C->CANdevTx);
if (odRet != ODR_OK && odRet != ODR_PARTIAL) {
abortCode = (CO_SDO_abortCode_t)OD_getSDOabCode(odRet);

View file

@ -551,12 +551,11 @@ static bool_t validateAndWriteToOD(CO_SDOserver_t *SDO,
/* write data */
OD_size_t countWritten = 0;
bool_t lock = OD_mappable(&SDO->OD_IO.stream);
if (lock) { CO_LOCK_OD(SDO->CANdevTx); }
CO_LOCK_OD(SDO->CANdevTx);
ODR_t odRet = SDO->OD_IO.write(&SDO->OD_IO.stream, SDO->buf,
SDO->bufOffsetWr, &countWritten);
if (lock) { CO_UNLOCK_OD(SDO->CANdevTx); }
CO_UNLOCK_OD(SDO->CANdevTx);
SDO->bufOffsetWr = 0;
@ -613,12 +612,11 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
/* load data from OD variable into the buffer */
OD_size_t countRd = 0;
uint8_t *bufShifted = SDO->buf + countRemain;
bool_t lock = OD_mappable(&SDO->OD_IO.stream);
if (lock) { CO_LOCK_OD(SDO->CANdevTx); }
CO_LOCK_OD(SDO->CANdevTx);
ODR_t odRet = SDO->OD_IO.read(&SDO->OD_IO.stream, bufShifted,
countRdRequest, &countRd);
if (lock) { CO_UNLOCK_OD(SDO->CANdevTx); }
CO_UNLOCK_OD(SDO->CANdevTx);
if (odRet != ODR_OK && odRet != ODR_PARTIAL) {
*abortCode = (CO_SDO_abortCode_t)OD_getSDOabCode(odRet);
@ -850,12 +848,11 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
/* Copy data */
OD_size_t countWritten = 0;
bool_t lock = OD_mappable(&SDO->OD_IO.stream);
if (lock) { CO_LOCK_OD(SDO->CANdevTx); }
CO_LOCK_OD(SDO->CANdevTx);
ODR_t odRet = SDO->OD_IO.write(&SDO->OD_IO.stream, buf,
dataSizeToWrite, &countWritten);
if (lock) { CO_UNLOCK_OD(SDO->CANdevTx); }
CO_UNLOCK_OD(SDO->CANdevTx);
if (odRet != ODR_OK) {
abortCode = (CO_SDO_abortCode_t)OD_getSDOabCode(odRet);
@ -1299,12 +1296,11 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
#else /* Expedited transfer only */
/* load data from OD variable */
OD_size_t count = 0;
bool_t lock = OD_mappable(&SDO->OD_IO.stream);
if (lock) { CO_LOCK_OD(SDO->CANdevTx); }
CO_LOCK_OD(SDO->CANdevTx);
ODR_t odRet = SDO->OD_IO.read(&SDO->OD_IO.stream,
&SDO->CANtxBuff->data[4], 4, &count);
if (lock) { CO_UNLOCK_OD(SDO->CANdevTx); }
CO_UNLOCK_OD(SDO->CANdevTx);
/* strings are allowed to be shorter */
if (odRet == ODR_PARTIAL

View file

@ -418,16 +418,15 @@ typedef struct {
* variable. CO_LOCK_OD(CAN_MODULE) and CO_UNLOCK_OD(CAN_MODULE) macros
* are used to protect:
* - Whole real-time thread,
* - SDO server protects read/write access to OD variable, if specific OD
* variable has ODA_TRPDO or ODA_TRSRDO from @ref OD_attributes_t set. If
* those attributes are not set, OD variable is not locked by SDO server.
* - SDO server protects read/write access to OD variable.
* Locking of long OD variables, not accessible from real-time thread, may
* block RT thread.
* - Any mainline code, which accesses PDO-mappable OD variable, must protect
* read/write with locking macros. Use @ref OD_mappable() for check.
* - Other cases, where non-PDO-mappable OD variable is used inside real-time
* thread by some other part of the user application must be considered with
* special care.
* special care. Also when there are multiple threads accessing the OD (e.g.
* when using a RTOS), you should always lock the OD.
*
* #### Synchronization functions for CAN receive
* After CAN message is received, it is pre-processed in CANrx_callback(), which