第一版代码,为了在EEPROM保存参数的时候走STM32的CRC,让Codex修改了一下,现在的效果是无法存储,codex表示原因是CRC方法不同,修改到一半今天的额度使用完了,有待后续解决CRC的bug

This commit is contained in:
2026-02-28 17:36:05 +08:00
commit b2fedd58b2
212 changed files with 208290 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
/*
* CANopen Indicator specification (CiA 303-3 v1.4.0)
*
* @file CO_LEDs.h
* @ingroup CO_LEDs
* @author Janez Paternoster
* @copyright 2020 Janez Paternoster
*
* This file is part of <https://github.com/CANopenNode/CANopenNode>, a CANopen Stack.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
#include "303/CO_LEDs.h"
#if ((CO_CONFIG_LEDS)&CO_CONFIG_LEDS_ENABLE) != 0
CO_ReturnError_t
CO_LEDs_init(CO_LEDs_t* LEDs) {
CO_ReturnError_t ret = CO_ERROR_NO;
/* verify arguments */
if (LEDs == NULL) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* clear the object */
(void)memset(LEDs, 0, sizeof(CO_LEDs_t));
return ret;
}
void
CO_LEDs_process(CO_LEDs_t* LEDs, uint32_t timeDifference_us, CO_NMT_internalState_t NMTstate, bool_t LSSconfig,
bool_t ErrCANbusOff, bool_t ErrCANbusWarn, bool_t ErrRpdo, bool_t ErrSync, bool_t ErrHbCons,
bool_t ErrOther, bool_t firmwareDownload, uint32_t* timerNext_us) {
(void)timerNext_us; /* may be unused */
uint8_t rd = 0;
uint8_t gr = 0;
bool_t tick = false;
LEDs->LEDtmr50ms += timeDifference_us;
while (LEDs->LEDtmr50ms >= 50000U) {
bool_t rdFlickerNext = (LEDs->LEDred & (uint8_t)CO_LED_flicker) == 0U;
tick = true;
LEDs->LEDtmr50ms -= 50000U;
if (++LEDs->LEDtmr200ms > 3U) {
/* calculate 2,5Hz blinking and flashing */
LEDs->LEDtmr200ms = 0;
rd = 0;
gr = 0;
if ((LEDs->LEDred & CO_LED_blink) == 0U) {
rd |= CO_LED_blink;
} else {
gr |= CO_LED_blink;
}
switch (++LEDs->LEDtmrflash_1) {
case 1: rd |= CO_LED_flash_1; break;
case 2: gr |= CO_LED_flash_1; break;
case 6: LEDs->LEDtmrflash_1 = 0; break;
default: /* none */ break;
}
switch (++LEDs->LEDtmrflash_2) {
case 1:
case 3: rd |= CO_LED_flash_2; break;
case 2:
case 4: gr |= CO_LED_flash_2; break;
case 8: LEDs->LEDtmrflash_2 = 0; break;
default: /* none */ break;
}
switch (++LEDs->LEDtmrflash_3) {
case 1:
case 3:
case 5: rd |= CO_LED_flash_3; break;
case 2:
case 4:
case 6: gr |= CO_LED_flash_3; break;
case 10: LEDs->LEDtmrflash_3 = 0; break;
default: /* none */ break;
}
switch (++LEDs->LEDtmrflash_4) {
case 1:
case 3:
case 5:
case 7: rd |= CO_LED_flash_4; break;
case 2:
case 4:
case 6:
case 8: gr |= CO_LED_flash_4; break;
case 12: LEDs->LEDtmrflash_4 = 0; break;
default: /* none */ break;
}
} else {
/* clear flicker and CANopen bits, keep others */
rd = LEDs->LEDred & (0xFFU ^ (CO_LED_flicker | CO_LED_CANopen));
gr = LEDs->LEDgreen & (0xFFU ^ (CO_LED_flicker | CO_LED_CANopen));
}
/* calculate 10Hz flickering */
if (rdFlickerNext) {
rd |= CO_LED_flicker;
} else {
gr |= CO_LED_flicker;
}
} /* while (LEDs->LEDtmr50ms >= 50000) */
if (tick) {
uint8_t rd_co, gr_co;
/* CANopen red ERROR LED */
if (ErrCANbusOff) {
rd_co = 1;
} else if (NMTstate == CO_NMT_INITIALIZING) {
rd_co = rd & CO_LED_flicker;
} else if (ErrRpdo) {
rd_co = rd & CO_LED_flash_4;
} else if (ErrSync) {
rd_co = rd & CO_LED_flash_3;
} else if (ErrHbCons) {
rd_co = rd & CO_LED_flash_2;
} else if (ErrCANbusWarn) {
rd_co = rd & CO_LED_flash_1;
} else if (ErrOther) {
rd_co = rd & CO_LED_blink;
} else {
rd_co = 0;
}
/* CANopen green RUN LED */
if (LSSconfig) {
gr_co = gr & CO_LED_flicker;
} else if (firmwareDownload) {
gr_co = gr & CO_LED_flash_3;
} else if (NMTstate == CO_NMT_STOPPED) {
gr_co = gr & CO_LED_flash_1;
} else if (NMTstate == CO_NMT_PRE_OPERATIONAL) {
gr_co = gr & CO_LED_blink;
} else if (NMTstate == CO_NMT_OPERATIONAL) {
gr_co = 1;
} else {
gr_co = 0;
}
if (rd_co != 0U) {
rd |= CO_LED_CANopen;
}
if (gr_co != 0U) {
gr |= CO_LED_CANopen;
}
LEDs->LEDred = rd;
LEDs->LEDgreen = gr;
} /* if (tick) */
#if ((CO_CONFIG_LEDS)&CO_CONFIG_FLAG_TIMERNEXT) != 0
if (timerNext_us != NULL) {
uint32_t diff = 50000 - LEDs->LEDtmr50ms;
if (*timerNext_us > diff) {
*timerNext_us = diff;
}
}
#endif
}
#endif /* (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE */

View File

@@ -0,0 +1,142 @@
/**
* CANopen Indicator specification (CiA 303-3 v1.4.0)
*
* @file CO_LEDs.h
* @ingroup CO_LEDs
* @author Janez Paternoster
* @copyright 2020 Janez Paternoster
*
* This file is part of <https://github.com/CANopenNode/CANopenNode>, a CANopen Stack.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
#ifndef CO_LEDS_H
#define CO_LEDS_H
#include "301/CO_driver.h"
#include "301/CO_NMT_Heartbeat.h"
/* default configuration, see CO_config.h */
#ifndef CO_CONFIG_LEDS
#define CO_CONFIG_LEDS (CO_CONFIG_LEDS_ENABLE | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT)
#endif
#if (((CO_CONFIG_LEDS)&CO_CONFIG_LEDS_ENABLE) != 0) || defined CO_DOXYGEN
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup CO_LEDs LED indicators
* Specified in standard CiA 303-3.
*
* @ingroup CO_CANopen_303
* @{
* CIA 303-3 standard specifies indicator LED diodes, which reflects state of the CANopen device. Green and red leds or
* bi-color led can be used.
*
* CANopen green led - run led:
* - flickering: LSS configuration state is active
* - blinking: device is in NMT pre-operational state
* - single flash: device is in NMT stopped state
* - triple flash: a software download is running in the device
* - on: device is in NMT operational state
*
* CANopen red led - error led:
* - off: no error
* - flickering: LSS node id is not configured, CANopen is not initialized
* - blinking: invalid configuration, general error
* - single flash: CAN warning limit reached
* - double flash: heartbeat consumer - error in remote monitored node
* - triple flash: sync message reception timeout
* - quadruple flash: PDO has not been received before the event timer elapsed
* - on: CAN bus off
*
* To apply on/off state to the led diode, use #CO_LED_RED or #CO_LED_GREEN macros with one of the @ref CO_LED_bitmasks.
* For CANopen leds use #CO_LED_CANopen bitmask.
*/
/**
* @defgroup CO_LED_bitmasks CO_LED bitmasks
* @{
* Bitmasks for the LED indicators
*/
#define CO_LED_flicker 0x01U /**< LED flickering 10Hz */
#define CO_LED_blink 0x02U /**< LED blinking 2,5Hz */
#define CO_LED_flash_1 0x04U /**< LED single flash */
#define CO_LED_flash_2 0x08U /**< LED double flash */
#define CO_LED_flash_3 0x10U /**< LED triple flash */
#define CO_LED_flash_4 0x20U /**< LED quadruple flash */
#define CO_LED_CANopen 0x80U /**< LED CANopen according to CiA 303-3 */
/** @} */
/** Get on/off state for red led for one of the @ref CO_LED_bitmasks */
#define CO_LED_RED(LEDs, BITMASK) ((((LEDs)->LEDred & BITMASK) != 0U) ? 1U : 0U)
/** Get on/off state for green led for one of the @ref CO_LED_bitmasks */
#define CO_LED_GREEN(LEDs, BITMASK) ((((LEDs)->LEDgreen & BITMASK) != 0U) ? 1U : 0U)
/**
* LEDs object, initialized by CO_LEDs_init()
*/
typedef struct {
uint32_t LEDtmr50ms; /**< 50ms led timer */
uint8_t LEDtmr200ms; /**< 200ms led timer */
uint8_t LEDtmrflash_1; /**< single flash led timer */
uint8_t LEDtmrflash_2; /**< double flash led timer */
uint8_t LEDtmrflash_3; /**< triple flash led timer */
uint8_t LEDtmrflash_4; /**< quadruple flash led timer */
uint8_t LEDred; /**< red led bitfield, to be combined with @ref CO_LED_bitmasks */
uint8_t LEDgreen; /**< green led bitfield, to be combined with @ref CO_LED_bitmasks */
} CO_LEDs_t;
/**
* Initialize LEDs object.
*
* Function must be called in the communication reset section.
*
* @param LEDs This object will be initialized.
*
* @return #CO_ReturnError_t CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.
*/
CO_ReturnError_t CO_LEDs_init(CO_LEDs_t* LEDs);
/**
* Process indicator states
*
* Function must be called cyclically.
*
* @param LEDs This object.
* @param timeDifference_us Time difference from previous function call in [microseconds].
* @param NMTstate NMT operating state.
* @param LSSconfig Node is in LSS configuration state indication.
* @param ErrCANbusOff CAN bus off indication (highest priority).
* @param ErrCANbusWarn CAN error warning limit reached indication.
* @param ErrRpdo RPDO event timer timeout indication.
* @param ErrSync Sync receive timeout indication.
* @param ErrHbCons Heartbeat consumer error (remote node) indication.
* @param ErrOther Other error indication (lowest priority).
* @param firmwareDownload Firmware download is in progress indication.
* @param [out] timerNext_us info to OS - see CO_process().
*/
void CO_LEDs_process(CO_LEDs_t* LEDs, uint32_t timeDifference_us, CO_NMT_internalState_t NMTstate, bool_t LSSconfig,
bool_t ErrCANbusOff, bool_t ErrCANbusWarn, bool_t ErrRpdo, bool_t ErrSync, bool_t ErrHbCons,
bool_t ErrOther, bool_t firmwareDownload, uint32_t* timerNext_us);
/** @} */ /* CO_LEDs */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE */
#endif /* CO_LEDS_H */