From ee834b787eefa7cd79595401fc62e9dc341924b7 Mon Sep 17 00:00:00 2001 From: zhanglinjing Date: Thu, 27 Jun 2024 13:27:42 +0200 Subject: [PATCH] fix can node problem --- cores/Arduino.h | 8 + libraries/CAN/src/CANXMC.cpp | 18 +- variants/XMC1400/XMC1000_RomFunctionTable.h | 186 ++++++++++++------ variants/XMC1400/XMC1400.h | 2 +- .../config/XMC1400_XMC2GO/pins_arduino.h | 34 ++-- .../config/XMC4200_Platform2GO/pins_arduino.h | 1 + .../config/XMC4400_Platform2GO/pins_arduino.h | 1 + .../config/XMC4700_Relax_Kit/pins_arduino.h | 1 + 8 files changed, 169 insertions(+), 82 deletions(-) diff --git a/cores/Arduino.h b/cores/Arduino.h index 79e7c4cc..d8bbf3d7 100644 --- a/cores/Arduino.h +++ b/cores/Arduino.h @@ -252,10 +252,18 @@ extern "C" { /* * XMC (Arduino) CAN type */ + + typedef enum + { + XMC_NODE_NUM_0, + XMC_NODE_NUM_1 + } + XMC_CAN_NODE_NUM_t; typedef struct { CAN_NODE_TypeDef *can_node; + XMC_CAN_NODE_NUM_t can_node_num; uint32_t can_frequency; XMC_PORT_PIN_t rx; XMC_GPIO_CONFIG_t rx_config; diff --git a/libraries/CAN/src/CANXMC.cpp b/libraries/CAN/src/CANXMC.cpp index 22f365de..ca51c9ca 100644 --- a/libraries/CAN/src/CANXMC.cpp +++ b/libraries/CAN/src/CANXMC.cpp @@ -70,9 +70,9 @@ CANXMC::~CANXMC() {} XMC_CAN_NODE_SetReceiveInput(_XMC_CAN_config->can_node, _XMC_CAN_config->node_input); XMC_CAN_MO_Config(&CAN_msg_rx); - XMC_CAN_AllocateMOtoNodeList(CAN_xmc, 1, 0); + XMC_CAN_AllocateMOtoNodeList(CAN_xmc, _XMC_CAN_config->can_node_num, 0); XMC_CAN_MO_Config(&CAN_msg_tx); - XMC_CAN_AllocateMOtoNodeList(CAN_xmc, 1, 1); + XMC_CAN_AllocateMOtoNodeList(CAN_xmc, _XMC_CAN_config->can_node_num, 1); /* Message object accepts the reception of both, standard and extended frames */ XMC_CAN_MO_AcceptStandardAndExtendedID(&CAN_msg_rx); @@ -119,9 +119,13 @@ CANXMC::~CANXMC() {} XMC_CAN_MO_UpdateData(&CAN_msg_tx); /* Send data in CAN_NODE_LMO_0 */ - XMC_CAN_MO_Transmit(&CAN_msg_tx); + XMC_CAN_STATUS_t send_status = XMC_CAN_MO_Transmit(&CAN_msg_tx); - return 1; + if (send_status == XMC_CAN_STATUS_SUCCESS) { + return 1; + } else { + return 0; + } }; int CANXMC::parsePacket() @@ -217,14 +221,16 @@ CANXMC::~CANXMC() {} /* Interrupt Handler*/ extern "C" { -#if defined(XMC4700_Relax_Kit) +#if(UC_FAMILY == XMC4) void CAN0_7_IRQHandler() { /* Set the frame received flag to true */ can_frame_received = true; CAN.onInterrupt(); } -#elif defined(XMC1400_XMC2GO) +#endif + +#if(UC_SERIES == XMC14) void CAN0_3_IRQHandler() { /* Set the frame received flag to true */ can_frame_received = true; diff --git a/variants/XMC1400/XMC1000_RomFunctionTable.h b/variants/XMC1400/XMC1000_RomFunctionTable.h index d4df47a3..aaf80ff3 100644 --- a/variants/XMC1400/XMC1000_RomFunctionTable.h +++ b/variants/XMC1400/XMC1000_RomFunctionTable.h @@ -1,41 +1,41 @@ /********************************************************************************************************************* * @file XMC1000_RomFunctionTable.h - * @brief ROM functions prototypes for the XMC1400-Series - * @version V1.0 - * @date 03 Sep 2015 + * @brief ROM functions prototypes for the XMC1000-Series * * @cond ********************************************************************************************************************* - * Copyright (c) 2015-2016, Infineon Technologies AG + * Copyright (c) 2013-2020, Infineon Technologies AG * All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the - * following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. + * Boost Software License - Version 1.0 - August 17th, 2003 * - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. + * Permission is hereby granted, free of charge, to any person or organization + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to use, reproduce, display, distribute, + * execute, and transmit the Software, and to prepare derivative works of the + * Software, and to permit third-parties to whom the Software is furnished to + * do so, all subject to the following: * - * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * The copyright notices in the Software and this entire statement, including + * the above license grant, this restriction and the following disclaimer, + * must be included in all copies of the Software, in whole or in part, and + * all derivative works of the Software, unless such copies or derivative + * works are solely in the form of machine-executable object code generated by + * a source language processor. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * - * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with - * Infineon Technologies AG dave@infineon.com). + * To improve the quality of the software, users are encouraged to share + * modifications, enhancements or bug fixes with Infineon Technologies AG + * at XMCSupport@infineon.com. ********************************************************************************************************************* * - **************************** Change history ********************************* - * V1.0, 03 Sep 2015, JFT : Initial version - ***************************************************************************** * @endcond */ @@ -61,6 +61,17 @@ extern "C" { /* Pointer to Request BMI installation routine */ #define _BmiInstallationReq (ROM_FUNCTION_TABLE_START + 0x08U) +/* Pointer to Calculate chip temperature routine */ +#define _CalcTemperature (ROM_FUNCTION_TABLE_START + 0x0CU) + +/* Pointer to Erase Flash Sector routine */ +#define _NvmEraseSector (ROM_FUNCTION_TABLE_START + 0x10U) + +/* Pointer to Program & Verify Flash Block routine */ +#define _NvmProgVerifyBlock (ROM_FUNCTION_TABLE_START + 0x14U) + +/* Pointer to Calculate target level for temperature comparison routine */ +#define _CalcTSEVAR (ROM_FUNCTION_TABLE_START + 0x20U) /* *************************************************************************** ******************************** Enumerations ******************************** @@ -95,79 +106,140 @@ typedef enum TagNVMStatus } NVM_STATUS; -/* *************************************************************************** +/**************************************************************************** *********************************** Macros *********************************** *************************************************************************** */ -/* *************************************************************************** +/**************************************************************************** Description: Erase granularity = 1 Page of 16 blocks of 16 Bytes = Equivalent to 256 Bytes using this routine. Input parameters: -– Logical address of the Flash Page to be erased which must be page aligned +- Logical address of the Flash Page to be erased which must be page aligned and in NVM address range Return status: -– OK (NVM_PASS) -– Invalid address (NVM_E_DST_ALIGNMENT or NVM_E_DST_AREA_EXCEED) -– Operation failed (Error during low level NVM programming driver): - NVM_E_FAIL - NVM_E_VERIFY - NVM_E_NVM_FAIL +- OK (NVM_PASS) +- Invalid address (NVM_E_DST_ALIGNMENT or NVM_E_DST_AREA_EXCEED) Prototype: - NVM_STATUS XMC1000_NvmErasePage(uint32_t *pageAddr) -*************************************************************************** */ -#define XMC1000_NvmErasePage (*((NVM_STATUS (**) (uint32_t * )) \ - _NvmErase)) + int32_t XMC1000_NvmErasePage(uint32_t *pageAddr) +****************************************************************************/ +#define XMC1000_NvmErasePage (*((int32_t (**) (uint32_t * )) _NvmErase)) -/* *************************************************************************** +/**************************************************************************** Description: This procedure performs erase (skipped if not necessary), program and verify of selected Flash page. Input parameter: -– Logical address of the target Flash Page, must be page aligned and in NVM +- Logical address of the target Flash Page, must be page aligned and in NVM address range -– Address in SRAM where the data starts, must be 4-byte aligned +- Address in SRAM where the data starts, must be 4-byte aligned Return status: -– OK (NVM_PASS) -– Invalid addresses +- OK (NVM_PASS) +- Invalid addresses NVM_E_DST_ALIGNMENT NVM_E_SRC_ALIGNMENT NVM_E_DST_AREA_EXCEED NVM_E_SRC_AREA_EXCCEED -– Operation failed (Error during low level NVM programming driver): - NVM_E_FAIL +- Operation failed (Error during low level NVM programming driver): NVM_E_VERIFY NVM_E_NVM_FAIL Prototype: - NVM_STATUS XMC1000_NvmProgVerify(const uint32_t *srcAddr, uint32_t *dstAddr) -*************************************************************************** */ -#define XMC1000_NvmProgVerify (*((NVM_STATUS (**) (const uint32_t * ,\ - uint32_t * ))\ - _NvmProgVerify)) + int32_t XMC1000_NvmProgVerify(const uint32_t *srcAddr, uint32_t *dstAddr) +****************************************************************************/ +#define XMC1000_NvmProgVerify (*((int32_t (**) (const uint32_t * ,uint32_t * )) _NvmProgVerify)) -/* *************************************************************************** +/**************************************************************************** Description: This procedure initiates installation of a new BMI value. In particular, it can be used as well as to restore the state upon delivery for a device already in User Productive mode. Input parameter: -– BMI value to be installed +- BMI value to be installed Return status: -– wrong input BMI value (0x01) - only upon error, if OK the procedure triggers +- wrong input BMI value (0x01) - only upon error, if OK the procedure triggers a reset respectively does not return to calling routine ! Prototype: unsigned long XMC1000_BmiInstallationReq(unsigned short requestedBmiValue) -**************************************************************************** */ -#define XMC1000_BmiInstallationReq (*((uint32_t (**) (uint16_t)) \ - _BmiInstallationReq)) +*****************************************************************************/ +#define XMC1000_BmiInstallationReq (*((uint32_t (**) (uint16_t)) _BmiInstallationReq)) + +/**************************************************************************** +Description: This procedure calculates the current chip temperature as +measured by the XMC1000 built-in sensor, based on data from Flash including +trimming values and pre-calculated constants and data from the actual +measurement (read from Temperature Sensor Counter2 Monitor Register ANATSEMON). + +Input parameter: +- None + +Return status: +- chip temperature in degree Kelvin + +Prototype: + uint32_t XMC1000_CalcTemperature(void) +*****************************************************************************/ +#define XMC1000_CalcTemperature (*((uint32_t (**) (void )) _CalcTemperature)) + +/**************************************************************************** +Description: XMC1000 Flash can be erased with granularity of one sector, i.e. + 16 pages of (16 blocks of 16 Bytes) = 4K Bytes using this routine. + +Input parameter: +– sectorAddr: logical address of the Flash Sector to be erased, must be in NVM address range + +Return status: +– OK (NVM_PASS) +– invalid address (NVM_E_DST_AREA_EXCEEDED, NVM_E_DST_ALIGNMENT) + +Prototype: + int32_t XMC1000_NvmEraseSector(uint32_t *sectorAddr) +*****************************************************************************/ +#define XMC1000_NvmEraseSector (*((int32_t (**) (uint32_t * )) _NvmEraseSector)) + +/**************************************************************************** +Description: XMC1100 Flash can be programmed and verified with granularity of +one block (4 words of 4 Bytes) = 16 Bytes using this routine. + +Input parameter: +– dstAddr: logical address of the Flash Sector to be erased, must be in NVM address range +- srcAddr: address in SRAM where the data starts + +Return status: +– OK (NVM_PASS) +– invalid addresses (NVM_E_SRC_AREA_EXCEEDED, NVM_E_SRC_ALIGNMENT, + NVM_E_DST_AREA_EXCEEDED, NVM_E_DST_ALIGNMENT) +– operation failed (NVM_E_NVM_FAIL, NVM_E_VERIFY) + +Prototype: + int32_t XMC1000_NvmProgVerifyBlock(const uint32_t *srcAddr, uint32_t *dstAddr) +*****************************************************************************/ +#define XMC1000_NvmProgVerifyBlock (*((int32_t (**) (const uint32_t * , uint32_t * )) _NvmProgVerifyBlock)) + +/**************************************************************************** +Description: This procedure, a kind of reverse of Calculate chip temperature, +calculates the value which must be installed in SCU_ANALOG->ANATSEIH.TSE_IH or +SCU_ANALOG->ANATSEIL.TSE_IL register to get indication in +SCU_INTERRUPT->SRRAW.TSE_LOW or SCU_INTERRUPT->SRRAW.TSE_HIGH +when the chip temperature is above/below some target/threshold. + +Input parameter: +– temperature: threshold temperature in degree Kelvin - allowed range 223...423 + +Return status: +– equivalent sensor threshold value for the temperature provided as input parameter + +Prototype: + uint32_t XMC1000_CalcTSEVAR(uint32_t temperature) +*****************************************************************************/ +#define XMC1000_CalcTSEVAR (*((uint32_t (**) (uint32_t * )) _CalcTSEVAR)) #ifdef __cplusplus } diff --git a/variants/XMC1400/XMC1400.h b/variants/XMC1400/XMC1400.h index c60d9493..dd40ad38 100644 --- a/variants/XMC1400/XMC1400.h +++ b/variants/XMC1400/XMC1400.h @@ -8831,7 +8831,7 @@ typedef struct { /*!< (@ 0x40040400) PORT4 St #define USIC1_CH0 ((USIC_CH_TypeDef *) USIC1_CH0_BASE) #define USIC1_CH1 ((USIC_CH_TypeDef *) USIC1_CH1_BASE) #if defined(UC_DEVICE) && ((UC_DEVICE == XMC1403) || (UC_DEVICE == XMC1404)) -#define CAN ((CAN_GLOBAL_TypeDef *) CAN_BASE) +#define CAN_xmc ((CAN_GLOBAL_TypeDef *) CAN_BASE) #define CAN_NODE0 ((CAN_NODE_TypeDef *) CAN_NODE0_BASE) #define CAN_NODE1 ((CAN_NODE_TypeDef *) CAN_NODE1_BASE) #define CAN_MO ((CAN_MO_CLUSTER_Type *) CAN_MO_BASE) diff --git a/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h b/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h index 55336053..f49c9538 100644 --- a/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h +++ b/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h @@ -127,6 +127,7 @@ extern const uint8_t NUM_ANALOG_INPUTS; #define USIC0_5_IRQHandler IRQ14_Handler // I2C #define USIC0_5_IRQn IRQ14_IRQn +/* I2S interrupt source B */ #define USIC1_2_IRQHandler IRQ11_Handler // I2S #define USIC1_2_IRQn IRQ11_IRQn @@ -136,6 +137,7 @@ extern const uint8_t NUM_ANALOG_INPUTS; #define ERU0_0_IRQHandler IRQ3_Handler // RESET #define ERU0_0_IRQn IRQ3_IRQn +/* CAN interrupt source B */ #define CAN0_3_IRQHandler IRQ7_Handler // CAN #define CAN0_3_IRQn IRQ7_IRQn @@ -373,30 +375,26 @@ XMC_I2S_t i2s_config = // XMC CAN instance #ifdef CAN_xmc -XMC_ARD_CAN_t XMC_CAN_0 = -{ +XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE0, + .can_node_num = 0, .can_frequency = (uint32_t)48000000, - .rx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE, - .pin = (uint8_t)1 + .rx = {.port = (XMC_GPIO_PORT_t *)PORT1_BASE, .pin = (uint8_t)1}, + .rx_config = + { + .mode = XMC_GPIO_MODE_INPUT_TRISTATE, + }, + .tx = {.port = (XMC_GPIO_PORT_t *)PORT1_BASE, .pin = (uint8_t)0}, + .tx_config = + { + .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9, }, - .rx_config = { - .mode = XMC_GPIO_MODE_INPUT_TRISTATE, - }, - .tx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE, - .pin = (uint8_t)0 - }, - .tx_config = { - .mode =XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9, - }, .node_input = CAN_NODE0_RXD_P1_1, - .irq_num = CAN0_3_IRQn, - .irq_service_request = 3u, - .irq_source = XMC_SCU_IRQCTRL_CAN0_SR3_IRQ7 -}; + .irq_num = CAN0_3_IRQn, + .irq_service_request = 3, + .irq_source = XMC_SCU_IRQCTRL_CAN0_SR3_IRQ7}; #endif - // Serial Interrupt and event handling #ifdef __cplusplus extern "C" { diff --git a/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h b/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h index d1eee824..be9fbb03 100644 --- a/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h +++ b/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h @@ -380,6 +380,7 @@ XMC_I2C_t XMC_I2C_0 = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE0, + .can_node_num = 0, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT14_BASE, .pin = (uint8_t)3 diff --git a/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h b/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h index 539a6d5f..439c442c 100644 --- a/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h +++ b/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h @@ -432,6 +432,7 @@ XMC_I2C_t XMC_I2C_0 = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE1, + .can_node_num = 1, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE, .pin = (uint8_t)13 diff --git a/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h b/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h index cfe24f4e..1e036390 100644 --- a/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h +++ b/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h @@ -713,6 +713,7 @@ XMC_I2S_t i2s_config = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE1, + .can_node_num = 1, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE, .pin = (uint8_t)13