1
0
Fork 0

Stack configuration added do CO_driver.h

Change macro CO_USE_LEDS -> CO_CONFIG_NMT_LEDS 1
Change macro CO_SDO_BUFFER_SIZE -> CO_CONFIG_SDO_BUFFER_SIZE
This commit is contained in:
Janez 2020-03-07 15:40:12 +01:00
parent 3fc79b807e
commit 02e2cc5860
9 changed files with 76 additions and 46 deletions

View file

@ -102,7 +102,7 @@ CO_ReturnError_t CO_NMT_init(
}
/* blinking bytes and LEDS */
#ifdef CO_USE_LEDS
#if CO_CONFIG_NMT_LEDS > 0
NMT->LEDtimer = 0;
NMT->LEDflickering = 0;
NMT->LEDblinking = 0;
@ -112,7 +112,7 @@ CO_ReturnError_t CO_NMT_init(
NMT->LEDquadrupleFlash = 0;
NMT->LEDgreenRun = -1;
NMT->LEDredError = 1;
#endif /* CO_USE_LEDS */
#endif /* CO_CONFIG_NMT_LEDS */
/* Configure object variables */
NMT->operatingState = CO_NMT_INITIALIZING;
@ -217,7 +217,7 @@ CO_NMT_reset_cmd_t CO_NMT_process(
CANpassive = 1;
#ifdef CO_USE_LEDS
#if CO_CONFIG_NMT_LEDS > 0
NMT->LEDtimer += timeDifference_us;
if (NMT->LEDtimer >= 50000) {
NMT->LEDtimer -= 50000;
@ -290,7 +290,7 @@ CO_NMT_reset_cmd_t CO_NMT_process(
else
NMT->LEDredError = -1;
#endif /* CO_USE_LEDS */
#endif /* CO_CONFIG_NMT_LEDS */
/* in case of error enter pre-operational state */

View file

@ -129,7 +129,7 @@ typedef enum{
* @ref CO_NMT_statusLEDdiodes. Object is initialized by CO_NMT_init().
*/
typedef struct{
#ifdef CO_USE_LEDS
#if CO_CONFIG_NMT_LEDS > 0
uint32_t LEDtimer; /**< 50ms led timer */
int8_t LEDflickering; /**< See @ref CO_NMT_statusLEDdiodes */
int8_t LEDblinking; /**< See @ref CO_NMT_statusLEDdiodes */
@ -139,7 +139,7 @@ typedef struct{
int8_t LEDquadrupleFlash; /**< See @ref CO_NMT_statusLEDdiodes */
int8_t LEDgreenRun; /**< See @ref CO_NMT_statusLEDdiodes */
int8_t LEDredError; /**< See @ref CO_NMT_statusLEDdiodes */
#endif /* CO_USE_LEDS */
#endif /* CO_CONFIG_NMT_LEDS */
uint8_t operatingState; /**< See @ref CO_NMT_internalState_t */
uint8_t resetCommand; /**< If different than zero, device will reset */

View file

@ -39,8 +39,8 @@
#define CCS_ABORT 0x80U
#if CO_SDO_BUFFER_SIZE < 7
#error CO_SDO_BUFFER_SIZE must be greater than 7
#if CO_CONFIG_SDO_BUFFER_SIZE < 7
#error CO_CONFIG_SDO_BUFFER_SIZE must be greater than 7
#endif
@ -214,7 +214,7 @@ static void CO_SDO_receive(void *object, void *msg){
/* copy data */
for(i=1; i<8; i++) {
SDO->ODF_arg.data[SDO->bufferOffset++] = data[i]; //SDO->ODF_arg.data is equal as SDO->databuffer
if(SDO->bufferOffset >= CO_SDO_BUFFER_SIZE) {
if(SDO->bufferOffset >= CO_CONFIG_SDO_BUFFER_SIZE) {
/* buffer full, break reception */
SDO->state = CO_SDO_ST_DOWNLOAD_BL_SUB_RESP;
CO_FLAG_SET(SDO->CANrxNew);
@ -450,7 +450,7 @@ uint16_t CO_OD_getLength(CO_SDO_t *SDO, uint16_t entryNo, uint8_t subIndex){
if(object->maxSubIndex == 0U){ /* Object type is Var */
if(object->pData == 0){ /* data type is domain */
return CO_SDO_BUFFER_SIZE;
return CO_CONFIG_SDO_BUFFER_SIZE;
}
else{
return object->length;
@ -462,7 +462,7 @@ uint16_t CO_OD_getLength(CO_SDO_t *SDO, uint16_t entryNo, uint8_t subIndex){
}
else if(object->pData == 0){
/* data type is domain */
return CO_SDO_BUFFER_SIZE;
return CO_CONFIG_SDO_BUFFER_SIZE;
}
else{
return object->length;
@ -471,7 +471,7 @@ uint16_t CO_OD_getLength(CO_SDO_t *SDO, uint16_t entryNo, uint8_t subIndex){
else{ /* Object type is Record */
if(((const CO_OD_entryRecord_t*)(object->pData))[subIndex].pData == 0){
/* data type is domain */
return CO_SDO_BUFFER_SIZE;
return CO_CONFIG_SDO_BUFFER_SIZE;
}
else{
return ((const CO_OD_entryRecord_t*)(object->pData))[subIndex].length;
@ -604,7 +604,7 @@ uint32_t CO_SDO_initTransfer(CO_SDO_t *SDO, uint16_t index, uint8_t subIndex){
SDO->ODF_arg.offset = 0U;
/* verify length */
if(SDO->ODF_arg.dataLength > CO_SDO_BUFFER_SIZE){
if(SDO->ODF_arg.dataLength > CO_CONFIG_SDO_BUFFER_SIZE){
return CO_SDO_AB_DEVICE_INCOMPAT; /* general internal incompatibility in the device */
}
@ -853,7 +853,7 @@ int8_t CO_SDO_process(
/* upload */
else{
abortCode = CO_SDO_readOD(SDO, CO_SDO_BUFFER_SIZE);
abortCode = CO_SDO_readOD(SDO, CO_CONFIG_SDO_BUFFER_SIZE);
if(abortCode != 0U){
CO_SDO_abort(SDO, abortCode);
return -1;
@ -985,7 +985,7 @@ int8_t CO_SDO_process(
return -1;
}
SDO->ODF_arg.dataLength = CO_SDO_BUFFER_SIZE;
SDO->ODF_arg.dataLength = CO_CONFIG_SDO_BUFFER_SIZE;
SDO->bufferOffset = 0;
}
}
@ -1028,7 +1028,7 @@ int8_t CO_SDO_process(
SDO->CANtxBuff->data[3] = SDO->CANrxData[3];
/* blksize */
SDO->blksize = (CO_SDO_BUFFER_SIZE > (7*127)) ? 127 : (CO_SDO_BUFFER_SIZE / 7);
SDO->blksize = (CO_CONFIG_SDO_BUFFER_SIZE > (7*127)) ? 127 : (CO_CONFIG_SDO_BUFFER_SIZE / 7);
SDO->CANtxBuff->data[4] = SDO->blksize;
/* is CRC enabled */
@ -1087,12 +1087,12 @@ int8_t CO_SDO_process(
return -1;
}
SDO->ODF_arg.dataLength = CO_SDO_BUFFER_SIZE;
SDO->ODF_arg.dataLength = CO_CONFIG_SDO_BUFFER_SIZE;
SDO->bufferOffset = 0;
}
/* blksize */
len = CO_SDO_BUFFER_SIZE - SDO->bufferOffset;
len = CO_CONFIG_SDO_BUFFER_SIZE - SDO->bufferOffset;
SDO->blksize = (len > (7*127)) ? 127 : (len / 7);
SDO->CANtxBuff->data[2] = SDO->blksize;
@ -1100,7 +1100,7 @@ int8_t CO_SDO_process(
if(lastSegmentInSubblock) {
SDO->state = CO_SDO_ST_DOWNLOAD_BL_END;
}
else if(SDO->bufferOffset >= CO_SDO_BUFFER_SIZE) {
else if(SDO->bufferOffset >= CO_CONFIG_SDO_BUFFER_SIZE) {
CO_SDO_abort(SDO, CO_SDO_AB_DEVICE_INCOMPAT);
return -1;
}
@ -1222,7 +1222,7 @@ int8_t CO_SDO_process(
SDO->ODF_arg.dataLength = CO_OD_getLength(SDO, SDO->entryNo, SDO->ODF_arg.subIndex) - len;
/* read next data from Object dictionary function */
abortCode = CO_SDO_readOD(SDO, CO_SDO_BUFFER_SIZE);
abortCode = CO_SDO_readOD(SDO, CO_CONFIG_SDO_BUFFER_SIZE);
if(abortCode != 0U){
CO_SDO_abort(SDO, abortCode);
return -1;
@ -1375,7 +1375,7 @@ int8_t CO_SDO_process(
SDO->ODF_arg.dataLength = CO_OD_getLength(SDO, SDO->entryNo, SDO->ODF_arg.subIndex) - len;
/* read next data from Object dictionary function */
abortCode = CO_SDO_readOD(SDO, CO_SDO_BUFFER_SIZE);
abortCode = CO_SDO_readOD(SDO, CO_CONFIG_SDO_BUFFER_SIZE);
if(abortCode != 0U){
CO_SDO_abort(SDO, abortCode);
return -1;

View file

@ -311,7 +311,7 @@ typedef enum{
* download it must store the data in own location. In case of upload it must
* write the data (maximum size is specified by length) into data buffer and
* specify actual length. With domain data type it is possible to transfer
* data, which are longer than #CO_SDO_BUFFER_SIZE. In that case
* data, which are longer than #CO_CONFIG_SDO_BUFFER_SIZE. In that case
* Object dictionary function is called multiple times between SDO transfer.
*
* ####Parameter to function:
@ -323,22 +323,6 @@ typedef enum{
*/
/**
* SDO buffer size.
*
* Size of the internal SDO buffer.
*
* Size must be at least equal to size of largest variable in @ref CO_SDO_objectDictionary.
* If data type is domain, data length is not limited to SDO buffer size. If
* block transfer is implemented, value should be set to 889.
*
* Value can be in range from 7 to 889 bytes.
*/
#ifndef CO_SDO_BUFFER_SIZE
#define CO_SDO_BUFFER_SIZE 32
#endif
/**
* Object Dictionary attributes. Bit masks for attribute in CO_OD_entry_t.
*/
@ -589,8 +573,8 @@ typedef struct{
typedef struct{
/** 8 data bytes of the received message. */
uint8_t CANrxData[8];
/** SDO data buffer of size #CO_SDO_BUFFER_SIZE. */
uint8_t databuffer[CO_SDO_BUFFER_SIZE];
/** SDO data buffer of size #CO_CONFIG_SDO_BUFFER_SIZE. */
uint8_t databuffer[CO_CONFIG_SDO_BUFFER_SIZE];
/** Internal flag indicates, that this object has own OD */
bool_t ownOD;
/** Pointer to the @ref CO_SDO_objectDictionary (array) */

View file

@ -87,6 +87,38 @@ extern "C" {
* (or interrupts), CAN module, etc.).
*/
/**
* @defgroup CO_STACK_CONFIG Stack configuration
*
* Definitions specify, which parts of the stack will be enabled. Values can be
* overridden by CO_driver_target.h file for example.
* @{
*/
/**
* Usage of CANopen LEDS.
*
* If >0, calculate CANopen blinking variables, which can be used for LEDs */
#ifndef CO_CONFIG_NMT_LEDS
#define CO_CONFIG_NMT_LEDS 0
#endif
/**
* Size of the internal SDO buffer.
*
* Size must be at least equal to size of largest variable in
* @ref CO_SDO_objectDictionary. If data type is domain, data length is not
* limited to SDO buffer size. If block transfer is implemented, value should be
* set to 889.
*
* Value can be in range from 7 to 889 bytes.
*/
#ifndef CO_CONFIG_SDO_BUFFER_SIZE
#define CO_CONFIG_SDO_BUFFER_SIZE 32
#endif
/** @} */
/* Macros and declarations in following part are only used for documentation. */
#ifdef CO_DOXYGEN
/**
@ -108,8 +140,6 @@ extern "C" {
*/
/** CO_LITTLE_ENDIAN or CO_BIG_ENDIAN must be defined */
#define CO_LITTLE_ENDIAN
/** Enable LED blinking calculation, optional */
#define CO_USE_LEDS
/** NULL, for general usage */
#define NULL (0)
/** Logical true, for general use */

View file

@ -129,7 +129,7 @@ extern "C" {
#ifdef CO_DOXYGEN
/**
* @defgroup CO_NO_OBJ Configuration
* @defgroup CO_NO_OBJ CANopen configuration
*
* Definitions specify, which and how many CANopenNode communication objects
* will be used in current configuration. Usage of some objects is mandatory and

View file

@ -28,6 +28,7 @@ Change Log
### Added
- Documentation added to `doc` directory: CHANGELOG.md, deviceSupport.md, gettingStarted.md, LSSusage.md and traceUsage.md.
- All CANopen objects calculates next timer info for OS. Useful for energy saving.
- Stack configuration added to CO_driver.h. Can be overridden by custom definitions.
[Unreleased master]
-------------------
@ -77,7 +78,7 @@ Change Log
------
Changelog written according to recomendations from https://keepachangelog.com/
Changelog written according to recommendations from https://keepachangelog.com/
[Unreleased split-driver]: https://github.com/CANopenNode/CANopenNode/tree/split-driver
[Unreleased master]: https://github.com/CANopenNode/CANopenNode

View file

@ -34,13 +34,22 @@
#include <stdbool.h>
#include <stdint.h>
#if __has_include("CO_driver_custom.h")
#include "CO_driver_custom.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Stack configuration override */
#ifndef CO_CONFIG_NMT_LEDS
#define CO_CONFIG_NMT_LEDS 1
#endif
/* Basic definitions */
#define CO_LITTLE_ENDIAN
#define CO_USE_LEDS
/* NULL is defined in stddef.h */
/* true and false are defined in stdbool.h */
/* int8_t to uint64_t are defined in stdint.h */

View file

@ -42,7 +42,7 @@
#include <net/if.h>
#if __has_include("CO_driver_custom.h")
#include "CO_driver_custom.h"
#include "CO_driver_custom.h"
#endif
#include "CO_notify_pipe.h"
#include "CO_error.h"
@ -51,6 +51,12 @@
extern "C" {
#endif
/* Stack configuration override */
#ifndef CO_CONFIG_SDO_BUFFER_SIZE
#define CO_CONFIG_SDO_BUFFER_SIZE 889
#endif
/**
* @defgroup CO_socketCAN_driver_target CO_driver_target.h
* @ingroup CO_socketCAN