Remove CO_CONFIG_HB_CONS_SIZE macro, size is fetched from Object Dictionary
It is necessary to re-generate OD.h file with the latest CANopenEditor from https://github.com/CANopenNode/CANopenEditor
This commit is contained in:
parent
01887f268d
commit
b8b9011f7f
5 changed files with 37 additions and 33 deletions
|
|
@ -33,10 +33,6 @@
|
|||
#error CO_CONFIG_HB_CONS_CALLBACK_CHANGE and CO_CONFIG_HB_CONS_CALLBACK_MULTI cannot be set simultaneously!
|
||||
#endif
|
||||
|
||||
#if CO_CONFIG_HB_CONS_SIZE < 1 || CO_CONFIG_HB_CONS_SIZE > 127
|
||||
#error CO_CONFIG_HB_CONS_SIZE is not correct
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read received message from CAN module.
|
||||
*
|
||||
|
|
@ -118,6 +114,8 @@ static ODR_t OD_write_1016(OD_stream_t *stream, const void *buf,
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_HBconsumer_init(CO_HBconsumer_t *HBcons,
|
||||
CO_EM_t *em,
|
||||
CO_HBconsNode_t *monitoredNodes,
|
||||
uint8_t monitoredNodesCount,
|
||||
OD_entry_t *OD_1016_HBcons,
|
||||
CO_CANmodule_t *CANdevRx,
|
||||
uint16_t CANdevRxIdxStart,
|
||||
|
|
@ -126,8 +124,8 @@ CO_ReturnError_t CO_HBconsumer_init(CO_HBconsumer_t *HBcons,
|
|||
ODR_t odRet;
|
||||
|
||||
/* verify arguments */
|
||||
if (HBcons == NULL || em == NULL || OD_1016_HBcons == NULL
|
||||
|| CANdevRx == NULL
|
||||
if (HBcons == NULL || em == NULL || monitoredNodes == NULL
|
||||
|| OD_1016_HBcons == NULL || CANdevRx == NULL
|
||||
) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
|
@ -135,13 +133,14 @@ CO_ReturnError_t CO_HBconsumer_init(CO_HBconsumer_t *HBcons,
|
|||
/* Configure object variables */
|
||||
memset(HBcons, 0, sizeof(CO_HBconsumer_t));
|
||||
HBcons->em = em;
|
||||
HBcons->monitoredNodes = monitoredNodes;
|
||||
HBcons->CANdevRx = CANdevRx;
|
||||
HBcons->CANdevRxIdxStart = CANdevRxIdxStart;
|
||||
|
||||
/* get actual number of monitored nodes */
|
||||
HBcons->numberOfMonitoredNodes =
|
||||
OD_1016_HBcons->subEntriesCount-1 < CO_CONFIG_HB_CONS_SIZE ?
|
||||
OD_1016_HBcons->subEntriesCount-1 : CO_CONFIG_HB_CONS_SIZE;
|
||||
OD_1016_HBcons->subEntriesCount-1 < monitoredNodesCount ?
|
||||
OD_1016_HBcons->subEntriesCount-1 : monitoredNodesCount;
|
||||
|
||||
for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) {
|
||||
uint32_t val;
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@
|
|||
CO_CONFIG_GLOBAL_FLAG_TIMERNEXT | \
|
||||
CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
|
||||
#endif
|
||||
#ifndef CO_CONFIG_HB_CONS_SIZE
|
||||
#define CO_CONFIG_HB_CONS_SIZE 8
|
||||
#endif
|
||||
|
||||
#if ((CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE) || defined CO_DOXYGEN
|
||||
|
||||
|
|
@ -142,10 +139,10 @@ typedef struct {
|
|||
typedef struct {
|
||||
/** From CO_HBconsumer_init() */
|
||||
CO_EM_t *em;
|
||||
/** Array of monitored nodes, maximum size CO_CONFIG_HB_CONS_SIZE */
|
||||
CO_HBconsNode_t monitoredNodes[CO_CONFIG_HB_CONS_SIZE];
|
||||
/** Actual number of monitored nodes,
|
||||
* MIN(CO_CONFIG_HB_CONS_SIZE or number-of-array-elements-in-OD-0x1016) */
|
||||
/** Array of monitored nodes, from CO_HBconsumer_init() */
|
||||
CO_HBconsNode_t *monitoredNodes;
|
||||
/** Actual number of monitored nodes, size-of-the-above-array or
|
||||
* number-of-array-elements-in-OD-0x1016, whichever is smaller. */
|
||||
uint8_t numberOfMonitoredNodes;
|
||||
/** True, if all monitored nodes are active or no node is monitored. Can be
|
||||
* read by the application */
|
||||
|
|
@ -182,17 +179,22 @@ typedef struct {
|
|||
*
|
||||
* @param HBcons This object will be initialized.
|
||||
* @param em Emergency object.
|
||||
* @param monitoredNodes Array of monitored nodes, must be defined externally.
|
||||
* @param monitoredNodesCount Size of the above array, usually equal to number
|
||||
* of array elements in OD 0x1016, valid values are 1 to 127
|
||||
* @param OD_1016_HBcons OD entry for 0x1016 - "Consumer heartbeat time", entry
|
||||
* is required, IO extension will be applied.
|
||||
* @param CANdevRx CAN device for Heartbeat reception.
|
||||
* @param CANdevRxIdxStart Starting index of receive buffer in the above CAN
|
||||
* device. Number of used indexes is equal to CO_CONFIG_HB_CONS_SIZE.
|
||||
* device. Number of used indexes is equal to monitoredNodesCount.
|
||||
* @param [out] errInfo Additional information in case of error, may be NULL.
|
||||
*
|
||||
* @return @ref CO_ReturnError_t CO_ERROR_NO in case of success.
|
||||
*/
|
||||
CO_ReturnError_t CO_HBconsumer_init(CO_HBconsumer_t *HBcons,
|
||||
CO_EM_t *em,
|
||||
CO_HBconsNode_t *monitoredNodes,
|
||||
uint8_t monitoredNodesCount,
|
||||
OD_entry_t *OD_1016_HBcons,
|
||||
CO_CANmodule_t *CANdevRx,
|
||||
uint16_t CANdevRxIdxStart,
|
||||
|
|
|
|||
|
|
@ -183,18 +183,6 @@ extern "C" {
|
|||
#define CO_CONFIG_HB_CONS_CALLBACK_CHANGE 0x02
|
||||
#define CO_CONFIG_HB_CONS_CALLBACK_MULTI 0x04
|
||||
#define CO_CONFIG_HB_CONS_QUERY_FUNCT 0x08
|
||||
|
||||
/**
|
||||
* Number of heartbeat consumer objects, where each object corresponds to one
|
||||
* sub-index in OD object 0x1016, "Consumer heartbeat time". Each heartbeat
|
||||
* consumer uses own CANrx object. Actual number of heartbeat consumer objects
|
||||
* may be lower, if OD variable 1016 has lower number of sub entries.
|
||||
*
|
||||
* If heartbeat consumer is enabled, then valid values are 1 to 127.
|
||||
*/
|
||||
#ifdef CO_DOXYGEN
|
||||
#define CO_CONFIG_HB_CONS_SIZE 8
|
||||
#endif
|
||||
/** @} */ /* CO_STACK_CONFIG_NMT_HB */
|
||||
|
||||
|
||||
|
|
|
|||
17
CANopen.c
17
CANopen.c
|
|
@ -64,7 +64,10 @@
|
|||
#error OD_CNT_HB_CONS from OD.h not correct!
|
||||
#endif
|
||||
#if ((CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE) && OD_CNT_HB_CONS == 1
|
||||
#define CO_RX_CNT_HB_CONS CO_CONFIG_HB_CONS_SIZE
|
||||
#if OD_CNT_ARR_1016 < 1 || OD_CNT_ARR_1016 > 127
|
||||
#error OD_CNT_ARR_1016 is not defined in Object Dictionary or value is wrong!
|
||||
#endif
|
||||
#define CO_RX_CNT_HB_CONS OD_CNT_ARR_1016
|
||||
#else
|
||||
#define CO_RX_CNT_HB_CONS 0
|
||||
#endif
|
||||
|
|
@ -353,11 +356,16 @@ CO_t *CO_new(CO_config_t *config, uint32_t *heapMemoryUsed) {
|
|||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
ON_MULTI_OD(uint8_t RX_CNT_HB_CONS = 0);
|
||||
if (CO_GET_CNT(HB_CONS) == 1) {
|
||||
uint8_t countOfMonitoredNodes = CO_GET_CNT(ARR_1016);
|
||||
p = calloc(1, sizeof(CO_HBconsumer_t));
|
||||
if (p == NULL) break;
|
||||
else co->HBcons = (CO_HBconsumer_t *)p;
|
||||
mem += sizeof(CO_HBconsumer_t);
|
||||
ON_MULTI_OD(RX_CNT_HB_CONS = CO_CONFIG_HB_CONS_SIZE);
|
||||
p = calloc(countOfMonitoredNodes, sizeof(CO_HBconsNode_t));
|
||||
if (p == NULL) break;
|
||||
else co->HBconsMonitoredNodes = (CO_HBconsNode_t *)p;
|
||||
mem += countOfMonitoredNodes * sizeof(CO_HBconsNode_t);
|
||||
ON_MULTI_OD(RX_CNT_HB_CONS = countOfMonitoredNodes);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -700,6 +708,7 @@ void CO_delete(CO_t *co) {
|
|||
free(co->em);
|
||||
|
||||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
free(co->HBconsMonitoredNodes);
|
||||
free(co->HBcons);
|
||||
#endif
|
||||
|
||||
|
|
@ -724,6 +733,7 @@ void CO_delete(CO_t *co) {
|
|||
static CO_NMT_t COO_NMT;
|
||||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
static CO_HBconsumer_t COO_HBcons;
|
||||
static CO_HBconsNode_t COO_HBconsMonitoredNodes[OD_CNT_ARR_1016];
|
||||
#endif
|
||||
static CO_EM_t COO_EM;
|
||||
static CO_SDOserver_t COO_SDOserver[OD_CNT_SDO_SRV];
|
||||
|
|
@ -782,6 +792,7 @@ CO_t *CO_new(CO_config_t *config, uint32_t *heapMemoryUsed) {
|
|||
co->NMT = &COO_NMT;
|
||||
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
|
||||
co->HBcons = &COO_HBcons;
|
||||
co->HBconsMonitoredNodes = &COO_HBconsMonitoredNodes[0];
|
||||
#endif
|
||||
co->em = &COO_EM;
|
||||
co->SDOserver = &COO_SDOserver[0];
|
||||
|
|
@ -1010,6 +1021,8 @@ CO_ReturnError_t CO_CANopenInit(CO_t *co,
|
|||
if (CO_GET_CNT(HB_CONS) == 1) {
|
||||
err = CO_HBconsumer_init(co->HBcons,
|
||||
em,
|
||||
co->HBconsMonitoredNodes,
|
||||
CO_GET_CNT(ARR_1016),
|
||||
OD_GET(H1016, OD_H1016_CONSUMER_HB_TIME),
|
||||
co->CANmodule,
|
||||
CO_GET_CO(RX_IDX_HB_CONS),
|
||||
|
|
|
|||
|
|
@ -201,10 +201,11 @@ typedef struct {
|
|||
* There must be one NMT object in the device. */
|
||||
uint8_t CNT_NMT;
|
||||
OD_entry_t *ENTRY_H1017; /**< OD entry for @ref CO_NMT_init() */
|
||||
/** Number of Heartbeat consumer objects, 0 or 1: object uses from 1 to 127
|
||||
* internal consumers (CANrx), as specified by @ref CO_CONFIG_HB_CONS_SIZE.
|
||||
*/
|
||||
/** Number of Heartbeat consumer objects, 0 or 1 */
|
||||
uint8_t CNT_HB_CONS;
|
||||
/** Number of internal consumers (CANrx), used inside Heartbeat consumer
|
||||
* object, 1 to 127. */
|
||||
uint8_t CNT_ARR_1016;
|
||||
OD_entry_t *ENTRY_H1016; /**< OD entry for @ref CO_HBconsumer_init()*/
|
||||
/** Number of Emergency objects, 0 or 1: optional producer (CANtx) +
|
||||
* optional consumer (CANrx), configurable by @ref CO_CONFIG_EM.
|
||||
|
|
@ -291,6 +292,7 @@ typedef struct {
|
|||
#if ((CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE) || defined CO_DOXYGEN
|
||||
/** Heartbeat consumer object, initialised by @ref CO_HBconsumer_init() */
|
||||
CO_HBconsumer_t *HBcons;
|
||||
CO_HBconsNode_t *HBconsMonitoredNodes;
|
||||
#if defined CO_MULTIPLE_OD || defined CO_DOXYGEN
|
||||
uint16_t RX_IDX_HB_CONS; /**< Start index in CANrx. */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue