This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ce641638226223faff5b0b6843feca1a6bc06616 Author: Saravanan Sekar <[email protected]> AuthorDate: Fri Nov 6 21:52:01 2026 +0530 arch/tricore: Drive the UART without the iLLD. The TC3xx and TC4xx serial drivers are the same code but for the chip, and set up the ASCLIN and the UART pins through IfxAsclin and IfxPort, with the pins named by the iLLD pin map. Replace both with one driver, src/common/aurix/tricore_serial.c, which programs the ASCLIN registers directly: 8N1, 16 times oversampling with three samples, FIFO interrupts at one byte. The fractional baud rate divider is the continued fraction of the wanted ratio that fits the 12-bit BRG fields, in place of the IfxAsclin search. The P14.1 RX and P14.0 TX pins are set up with the port registers, which are IOCR and PDR on TC3xx, under the CPU ENDINIT, and PADCFG on TC4xx. src/common/aurix holds the peripheral drivers that both families share; the Make.defs and CMakeLists.txt of tc3xx and tc4xx pull it in, as the stm32 chips do with common/stm32. Signed-off-by: Saravanan Sekar <[email protected]> --- arch/tricore/src/common/aurix/CMakeLists.txt | 26 + arch/tricore/src/common/aurix/Make.defs | 28 + .../aurix/tricore_serial.c} | 396 ++++++----- arch/tricore/src/tc3xx/CMakeLists.txt | 4 +- arch/tricore/src/tc3xx/Make.defs | 3 +- arch/tricore/src/tc3xx/chip.h | 7 +- arch/tricore/src/tc3xx/tc3xx_serial.c | 732 --------------------- arch/tricore/src/tc3xx/tc3xx_wdt.c | 24 + arch/tricore/src/tc3xx/tc3xx_wdt.h | 1 + arch/tricore/src/tc4xx/CMakeLists.txt | 5 +- arch/tricore/src/tc4xx/Make.defs | 3 +- arch/tricore/src/tc4xx/chip.h | 7 +- 12 files changed, 319 insertions(+), 917 deletions(-) diff --git a/arch/tricore/src/common/aurix/CMakeLists.txt b/arch/tricore/src/common/aurix/CMakeLists.txt new file mode 100644 index 00000000000..ff2535d8ba1 --- /dev/null +++ b/arch/tricore/src/common/aurix/CMakeLists.txt @@ -0,0 +1,26 @@ +# ############################################################################## +# arch/tricore/src/common/aurix/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you 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. +# +# ############################################################################## + +# Peripheral drivers shared by the AURIX families, added by the CMakeLists.txt +# of each family + +target_sources(arch PRIVATE tricore_serial.c) diff --git a/arch/tricore/src/common/aurix/Make.defs b/arch/tricore/src/common/aurix/Make.defs new file mode 100644 index 00000000000..cb45158ae6e --- /dev/null +++ b/arch/tricore/src/common/aurix/Make.defs @@ -0,0 +1,28 @@ +############################################################################ +# arch/tricore/src/common/aurix/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +# Peripheral drivers shared by the AURIX families, included by the Make.defs +# of each family + +CHIP_CSRCS += tricore_serial.c + +VPATH += common$(DELIM)aurix diff --git a/arch/tricore/src/tc4xx/tc4xx_serial.c b/arch/tricore/src/common/aurix/tricore_serial.c similarity index 63% rename from arch/tricore/src/tc4xx/tc4xx_serial.c rename to arch/tricore/src/common/aurix/tricore_serial.c index 8f635caeab9..675f4dafdf8 100644 --- a/arch/tricore/src/tc4xx/tc4xx_serial.c +++ b/arch/tricore/src/common/aurix/tricore_serial.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/tricore/src/tc4xx/tc4xx_serial.c + * arch/tricore/src/common/aurix/tricore_serial.c * * SPDX-License-Identifier: Apache-2.0 * @@ -41,16 +41,42 @@ #include <arch/board/board.h> +#include <arch/chip/chip.h> + #include "tricore_internal.h" +#include "tricore_asclin.h" + +#if defined(CONFIG_ARCH_CHIP_TC3XX) +# include "hardware/tc3xx_port.h" +# include "tc3xx_wdt.h" +#elif defined(CONFIG_ARCH_CHIP_TC4XX) +# include "hardware/tc4xx_port.h" +#endif -#include "Asclin/Asc/IfxAsclin_Asc.h" -#include "IfxAsclin_PinMap.h" #include <chip.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#if defined(CONFIG_TC3XX_UART0) || defined(CONFIG_TC4XX_UART0) +# define HAVE_UART0 1 +#endif + +/* Bit timing: fPD is fASCLINF, 16 times oversampling, sample point 8 */ + +#define ASCLIN_PRESCALER 1 +#define ASCLIN_OVERSAMPLING 16 +#define ASCLIN_SAMPLEPOINT 8 + +/* Largest BRG numerator and denominator */ + +#define ASCLIN_BRG_MAX 0xfff + +/* ASCLIN register of a UART */ + +#define ASCLIN_REG(priv, reg) ((priv)->uartbase + ASCLIN_##reg##_OFFSET) + /* If we are not using the serial driver for the console, then we still must * provide some minimal implementation of up_putc. */ @@ -61,7 +87,7 @@ * be ttyS0. If there is no console then will use the lowest numbered UART. */ -#if defined(CONFIG_UART0_SERIAL_CONSOLE) && defined(CONFIG_TC4XX_UART0) +#if defined(CONFIG_UART0_SERIAL_CONSOLE) && defined(HAVE_UART0) # define HAVE_SERIAL_CONSOLE 1 #else # undef CONFIG_UART0_SERIAL_CONSOLE @@ -79,7 +105,7 @@ #else # undef CONSOLE_DEV /* No console */ # undef CONFIG_UART0_SERIAL_CONSOLE -# if defined(CONFIG_TC4XX_UART0) +# if defined(HAVE_UART0) # define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */ # define SERIAL_CONSOLE 1 # else @@ -88,7 +114,7 @@ #endif #undef HAVE_UART_DEVICE -#if defined(CONFIG_TC4XX_UART0) +#if defined(HAVE_UART0) # define HAVE_UART_DEVICE 1 #endif @@ -104,8 +130,7 @@ struct up_dev_s { - volatile void *uartbase; /* Base address of UART registers */ - const void *pins; /* Pin configuration */ + uintptr_t uartbase; /* Base address of UART registers */ uint32_t baud; /* Configured baud */ uint8_t irq; /* IRQ associated with this UART */ }; @@ -155,28 +180,16 @@ static const struct uart_ops_s g_uart_ops = /* I/O buffers */ -#ifdef CONFIG_TC4XX_UART0 +#ifdef HAVE_UART0 static char g_uart0rxbuffer[CONFIG_UART0_RXBUFSIZE]; static char g_uart0txbuffer[CONFIG_UART0_TXBUFSIZE]; #endif -#ifdef CONFIG_TC4XX_UART0 - -/* Pin configuration */ - -static const IfxAsclin_Asc_Pins g_uart0_pins = -{ - NULL, IfxPort_InputMode_pullUp, /* CTS pin not used */ - &UART_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin */ - NULL, IfxPort_OutputMode_pushPull, /* RTS pin not used */ - &UART_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */ - IfxPort_PadDriver_cmosAutomotiveSpeed1 -}; +#ifdef HAVE_UART0 static struct up_dev_s g_uart0priv = { - .uartbase = &MODULE_ASCLIN0, - .pins = &g_uart0_pins, + .uartbase = TRICORE_ASCLIN0_BASE, .baud = CONFIG_UART0_BAUD, .irq = TRICORE_UART_RX_IRQ, }; @@ -206,175 +219,200 @@ static uart_dev_t g_uart0port = ****************************************************************************/ /**************************************************************************** - * Name: asclin_init + * Name: asclin_modify + ****************************************************************************/ + +static void asclin_modify(uintptr_t reg, uint32_t clear, uint32_t set) +{ + putreg32((getreg32(reg) & ~clear) | set, reg); +} + +/**************************************************************************** + * Name: asclin_pin_config * * Description: - * Configure the UART baud, bits, parity, etc. This method is called the - * first time that the serial port is opened. + * Set up a UART pin: RX as input with pull-up, TX as push-pull alternate + * output 2, both with the speed 1 pad driver. On TC3xx the mode is in + * IOCR and the pad driver in PDR, under the CPU ENDINIT; on TC4xx both + * are in the PADCFG DRVCFG register of the pin. * ****************************************************************************/ -static void asclin_init(struct up_dev_s *priv) +static void asclin_pin_config(uintptr_t port, int pin, bool tx) { - Ifx_ASCLIN *asclin = priv->uartbase; - const IfxAsclin_Asc_Pins *pins = priv->pins; - - /* enabling the module */ - - IfxAsclin_enableModule(asclin); - - /* disabling the clock */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_noClock); - - /* setting the module in Initialise mode */ - - IfxAsclin_setFrameMode(asclin, IfxAsclin_FrameMode_initialise); - - /* sets the prescaler */ - - IfxAsclin_setPrescaler(asclin, 1); - - /* temporary set the clock source for baudrate configuration */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_ascFastClock); - - /* setting the baudrate bit fields to generate the required baudrate */ - - IfxAsclin_setBitTiming(asclin, priv->baud, - IfxAsclin_OversamplingFactor_16, - IfxAsclin_SamplePointPosition_8, - IfxAsclin_SamplesPerBit_three); - - /* disabling the clock again */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_noClock); - - /* selecting the loopback mode */ - - IfxAsclin_enableLoopBackMode(asclin, false); - - /* setting parity enable */ - - IfxAsclin_enableParity(asclin, false); - - /* setting parity type (odd/even) */ - - IfxAsclin_setParityType(asclin, IfxAsclin_ParityType_even); - - /* setting the stop bit */ - - IfxAsclin_setStopBit(asclin, IfxAsclin_StopBit_1); - - /* setting the shift direction */ - - IfxAsclin_setShiftDirection(asclin, - IfxAsclin_ShiftDirection_lsbFirst); - - /* setting the data length */ - - IfxAsclin_setDataLength(asclin, IfxAsclin_DataLength_8); - - /* setting Tx FIFO inlet width */ - - IfxAsclin_setTxFifoInletWidth(asclin, - IfxAsclin_TxFifoInletWidth_1); - - /* setting Rx FIFO outlet width */ - - IfxAsclin_setRxFifoOutletWidth(asclin, - IfxAsclin_RxFifoOutletWidth_1); - - /* setting idle delay */ - - IfxAsclin_setIdleDelay(asclin, IfxAsclin_IdleDelay_0); - - /* setting Tx FIFO level at which a Tx interrupt will be triggered */ - - IfxAsclin_setTxFifoInterruptLevel(asclin, - IfxAsclin_TxFifoInterruptLevel_0); - - /* setting Rx FIFO interrupt level at which a Rx - * interrupt will be triggered - */ - - IfxAsclin_setRxFifoInterruptLevel(asclin, - IfxAsclin_RxFifoInterruptLevel_1); - - /* setting Tx FIFO interrupt generation mode */ +#if defined(CONFIG_ARCH_CHIP_TC3XX) + int shift = TC3XX_PORT_IOCR_SHIFT(pin); + + asclin_modify(TC3XX_PORT_IOCR(port, pin), TC3XX_PORT_IOCR_MASK << shift, + (tx ? TC3XX_PORT_OUT_ALT2 : TC3XX_PORT_IN_PULLUP) << shift); + + shift = TC3XX_PORT_PDR_SHIFT(pin); + tc3xx_wdt_cpu_endinit(false); + asclin_modify(TC3XX_PORT_PDR(port, pin), TC3XX_PORT_PDR_MASK << shift, + TC3XX_PORT_PAD_SPEED1 << shift); + tc3xx_wdt_cpu_endinit(true); +#elif defined(CONFIG_ARCH_CHIP_TC4XX) + uintptr_t drvcfg = TC4XX_PORT_DRVCFG(port, pin); + + asclin_modify(drvcfg, TC4XX_PORT_DRVCFG_MODE_MASK, + tx ? TC4XX_PORT_OUT_ALT2 : TC4XX_PORT_IN_PULLUP); + asclin_modify(drvcfg, TC4XX_PORT_DRVCFG_PAD_MASK, TC4XX_PORT_PAD_SPEED1); +#endif +} - IfxAsclin_setTxFifoInterruptMode(asclin, - IfxAsclin_FifoInterruptMode_combined); +/**************************************************************************** + * Name: asclin_set_clock + * + * Description: + * Select the ASCLIN clock and wait until it is on or off. + * + ****************************************************************************/ - /* setting Rx FIFO interrupt generation mode */ +static void asclin_set_clock(struct up_dev_s *priv, uint32_t clksel) +{ + uint32_t on = clksel == ASCLIN_CSR_CLKSEL_NONE ? 0 : ASCLIN_CSR_CON; - IfxAsclin_setRxFifoInterruptMode(asclin, - IfxAsclin_FifoInterruptMode_combined); + asclin_modify(ASCLIN_REG(priv, CSR), ASCLIN_CSR_CLKSEL_MASK, clksel); + while ((getreg32(ASCLIN_REG(priv, CSR)) & ASCLIN_CSR_CON) != on); +} - /* selecting the frame mode */ +/**************************************************************************** + * Name: asclin_set_bittime + * + * Description: + * Set the prescaler, the oversampling and the sample point, with three + * samples per bit. + * + ****************************************************************************/ - IfxAsclin_setFrameMode(asclin, IfxAsclin_FrameMode_asc); +static void asclin_set_bittime(struct up_dev_s *priv) +{ + asclin_modify(ASCLIN_REG(priv, BITCON), + ASCLIN_BITCON_PRESCALER_MASK | ASCLIN_BITCON_OVS_MASK | + ASCLIN_BITCON_SP_MASK | ASCLIN_BITCON_SM, + (ASCLIN_PRESCALER - 1) | + ((ASCLIN_OVERSAMPLING - 1) << ASCLIN_BITCON_OVS_SHIFT) | + (ASCLIN_SAMPLEPOINT << ASCLIN_BITCON_SP_SHIFT) | + ASCLIN_BITCON_SM); +} - /* Pin mapping */ +/**************************************************************************** + * Name: asclin_set_baudrate + * + * Description: + * Set the fractional divider, which makes the oversampling clock + * fPD * NUMERATOR / DENOMINATOR. The fraction is the last continued + * fraction convergent of (baud * oversampling) / fPD whose terms fit in + * the 12-bit BRG fields. + * + ****************************************************************************/ - if (pins != NULL) +static void asclin_set_baudrate(struct up_dev_s *priv) +{ + uint32_t n = priv->baud * ASCLIN_OVERSAMPLING; + uint32_t d = tricore_clock_asclinf() / ASCLIN_PRESCALER; + uint32_t num0 = 0; + uint32_t num1 = 1; + uint32_t den0 = 1; + uint32_t den1 = 0; + + while (d != 0) { - IfxAsclin_Cts_In *cts = pins->cts; - - if (cts != NULL) - { - IfxAsclin_initCtsPin(cts, pins->ctsMode, pins->pinDriver); - } - - IfxAsclin_Rx_In *rx = pins->rx; - - if (rx != NULL) - { - IfxAsclin_initRxPin(rx, pins->rxMode, pins->pinDriver); - } - - IfxAsclin_Rts_Out *rts = pins->rts; + uint32_t a = n / d; + uint32_t r = n % d; + uint32_t num2; + uint32_t den2; - if (rts != NULL) + if (a > (ASCLIN_BRG_MAX - num0) / num1 || + (den1 != 0 && a > (ASCLIN_BRG_MAX - den0) / den1)) { - IfxAsclin_initRtsPin(rts, pins->rtsMode, pins->pinDriver); + break; } - IfxAsclin_Tx_Out *tx = pins->tx; - - if (tx != NULL) - { - IfxAsclin_initTxPin(tx, pins->txMode, pins->pinDriver); - } + num2 = a * num1 + num0; + den2 = a * den1 + den0; + num0 = num1; + num1 = num2; + den0 = den1; + den1 = den2; + n = d; + d = r; } - /* select the clock source */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_ascFastClock); - - /* disable all flags */ - - IfxAsclin_disableAllFlags(asclin); + asclin_modify(ASCLIN_REG(priv, BRG), + ASCLIN_BRG_DENOMINATOR_MASK | ASCLIN_BRG_NUMERATOR_MASK, + ((num1 != 0 ? num1 : 1) << ASCLIN_BRG_NUMERATOR_SHIFT) | + (den1 != 0 ? den1 : 1)); +} - /* clear all flags */ +/**************************************************************************** + * Name: asclin_init + * + * Description: + * Configure the UART baud, bits, parity, etc. This method is called the + * first time that the serial port is opened. 8N1, FIFO interrupts at + * one byte. + * + ****************************************************************************/ - IfxAsclin_clearAllFlags(asclin); +static void asclin_init(struct up_dev_s *priv) +{ + /* Enable the module, under the CPU ENDINIT on TC3xx */ - /* HW error flags */ +#ifdef CONFIG_ARCH_CHIP_TC3XX + tc3xx_wdt_cpu_endinit(false); +#endif + asclin_modify(ASCLIN_REG(priv, CLC), ASCLIN_CLC_DISR, 0); +#ifdef CONFIG_ARCH_CHIP_TC3XX + tc3xx_wdt_cpu_endinit(true); +#endif - IfxAsclin_enableParityErrorFlag(asclin, true); - IfxAsclin_enableFrameErrorFlag(asclin, true); - IfxAsclin_enableRxFifoOverflowFlag(asclin, true); - IfxAsclin_enableRxFifoUnderflowFlag(asclin, true); - IfxAsclin_enableTxFifoOverflowFlag(asclin, true); + /* Clock off, initialise mode, bit timing and baud rate */ - /* enable transfers */ + asclin_set_clock(priv, ASCLIN_CSR_CLKSEL_NONE); + asclin_modify(ASCLIN_REG(priv, FRAMECON), ASCLIN_FRAMECON_MODE_MASK, + ASCLIN_FRAMECON_MODE_INIT); + asclin_set_bittime(priv); + asclin_set_baudrate(priv); - IfxAsclin_enableRxFifoInlet(asclin, true); - IfxAsclin_enableTxFifoOutlet(asclin, true); + /* No loop back, 8 data bits, no parity, 1 stop bit, LSB first, one byte + * wide FIFO accesses, interrupts at the FIFO level, ASC mode + */ - IfxAsclin_flushRxFifo(asclin); - IfxAsclin_flushTxFifo(asclin); + asclin_modify(ASCLIN_REG(priv, IOCR), ASCLIN_IOCR_LB, 0); + asclin_modify(ASCLIN_REG(priv, FRAMECON), + ASCLIN_FRAMECON_PEN | ASCLIN_FRAMECON_ODD | + ASCLIN_FRAMECON_STOP_MASK | ASCLIN_FRAMECON_MSB | + ASCLIN_FRAMECON_IDLE_MASK, + 1 << ASCLIN_FRAMECON_STOP_SHIFT); + asclin_modify(ASCLIN_REG(priv, DATCON), ASCLIN_DATCON_DATLEN_MASK, 8 - 1); + asclin_modify(ASCLIN_REG(priv, TXFIFOCON), + ASCLIN_FIFOCON_W_MASK | ASCLIN_FIFOCON_INTLEVEL_MASK | + ASCLIN_FIFOCON_FM_MASK, 1 << ASCLIN_FIFOCON_W_SHIFT); + asclin_modify(ASCLIN_REG(priv, RXFIFOCON), + ASCLIN_FIFOCON_W_MASK | ASCLIN_FIFOCON_INTLEVEL_MASK | + ASCLIN_FIFOCON_FM_MASK, 1 << ASCLIN_FIFOCON_W_SHIFT); + asclin_modify(ASCLIN_REG(priv, FRAMECON), ASCLIN_FRAMECON_MODE_MASK, + ASCLIN_FRAMECON_MODE_ASC); + + /* Pins, RX on input A */ + + asclin_pin_config(UART_PIN_PORT, UART_PIN_RX, false); + asclin_modify(ASCLIN_REG(priv, IOCR), ASCLIN_IOCR_ALTI_MASK, 0); + asclin_pin_config(UART_PIN_PORT, UART_PIN_TX, true); + + /* Clock on, error flags enabled, FIFOs enabled and flushed */ + + asclin_set_clock(priv, ASCLIN_CSR_CLKSEL_FAST); + putreg32(0, ASCLIN_REG(priv, FLAGSENABLE)); + putreg32(0xffffffff, ASCLIN_REG(priv, FLAGSCLEAR)); + asclin_modify(ASCLIN_REG(priv, FLAGSENABLE), 0, + ASCLIN_FLAGS_PE | ASCLIN_FLAGS_FE | ASCLIN_FLAGS_RFO | + ASCLIN_FLAGS_RFU | ASCLIN_FLAGS_TFO); + asclin_modify(ASCLIN_REG(priv, RXFIFOCON), 0, ASCLIN_FIFOCON_EN); + asclin_modify(ASCLIN_REG(priv, TXFIFOCON), 0, ASCLIN_FIFOCON_EN); + asclin_modify(ASCLIN_REG(priv, RXFIFOCON), 0, ASCLIN_FIFOCON_FLUSH); + asclin_modify(ASCLIN_REG(priv, TXFIFOCON), 0, ASCLIN_FIFOCON_FLUSH); } /**************************************************************************** @@ -525,7 +563,7 @@ static int up_receive(struct uart_dev_s *dev, unsigned int *status) { struct up_dev_s *priv = dev->priv; - return IfxAsclin_readRxData(priv->uartbase); + return getreg32(ASCLIN_REG(priv, RXDATA)); } /**************************************************************************** @@ -541,8 +579,10 @@ static void up_rxint(struct uart_dev_s *dev, bool enable) struct up_dev_s *priv = dev->priv; irqstate_t flags = enter_critical_section(); - IfxAsclin_enableRxFifoFillLevelFlag(priv->uartbase, enable); - IfxAsclin_enableRxFifoInlet(priv->uartbase, enable); + asclin_modify(ASCLIN_REG(priv, FLAGSENABLE), ASCLIN_FLAGS_RFL, + enable ? ASCLIN_FLAGS_RFL : 0); + asclin_modify(ASCLIN_REG(priv, RXFIFOCON), ASCLIN_FIFOCON_EN, + enable ? ASCLIN_FIFOCON_EN : 0); leave_critical_section(flags); } @@ -559,7 +599,8 @@ static bool up_rxavailable(struct uart_dev_s *dev) { struct up_dev_s *priv = dev->priv; - return IfxAsclin_getRxFifoFillLevel(priv->uartbase) > 0; + return (getreg32(ASCLIN_REG(priv, RXFIFOCON)) & + ASCLIN_FIFOCON_FILL_MASK) != 0; } /**************************************************************************** @@ -582,10 +623,11 @@ static void up_send(struct uart_dev_s *dev, int ch) return; } - while (IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0); + while ((getreg32(ASCLIN_REG(priv, TXFIFOCON)) & + ASCLIN_FIFOCON_FILL_MASK) != 0); - IfxAsclin_clearAllFlags(priv->uartbase); - IfxAsclin_writeTxData(priv->uartbase, ch); + putreg32(0xffffffff, ASCLIN_REG(priv, FLAGSCLEAR)); + putreg32(ch, ASCLIN_REG(priv, TXDATA)); } /**************************************************************************** @@ -639,7 +681,8 @@ static bool up_txempty(struct uart_dev_s *dev) /* Return true if the TX wartermak is pending */ - return IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0; + return (getreg32(ASCLIN_REG(priv, TXFIFOCON)) & + ASCLIN_FIFOCON_FILL_MASK) != 0; } /**************************************************************************** @@ -657,10 +700,11 @@ void tricore_lowputc(char ch) /* Wait for FIFO */ - while (IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0); + while ((getreg32(ASCLIN_REG(priv, TXFIFOCON)) & + ASCLIN_FIFOCON_FILL_MASK) != 0); - IfxAsclin_clearAllFlags(priv->uartbase); - IfxAsclin_writeTxData(priv->uartbase, ch); + putreg32(0xffffffff, ASCLIN_REG(priv, FLAGSCLEAR)); + putreg32(ch, ASCLIN_REG(priv, TXDATA)); #endif /* HAVE_CONSOLE */ } diff --git a/arch/tricore/src/tc3xx/CMakeLists.txt b/arch/tricore/src/tc3xx/CMakeLists.txt index 98131b56dc6..0ec5917a83a 100644 --- a/arch/tricore/src/tc3xx/CMakeLists.txt +++ b/arch/tricore/src/tc3xx/CMakeLists.txt @@ -20,10 +20,12 @@ # # ############################################################################## -set(SRCS tc3xx_timerisr.c tc3xx_serial.c tc3xx_wdt.c tc3xx_clockconfig.c) +set(SRCS tc3xx_timerisr.c tc3xx_wdt.c tc3xx_clockconfig.c) target_sources(arch PRIVATE ${SRCS}) +add_subdirectory(${NUTTX_DIR}/arch/tricore/src/common/aurix aurix) + set(ILLD_UNPACK "${CMAKE_CURRENT_SOURCE_DIR}/../illd/tc3xx") set(ILLD_TARBALL "${ILLD_UNPACK}/illd.tar.gz") set(ILLD_UNPACK_NAME "illd_release_tc3x-main") diff --git a/arch/tricore/src/tc3xx/Make.defs b/arch/tricore/src/tc3xx/Make.defs index 5f5a759a1af..855632adf68 100644 --- a/arch/tricore/src/tc3xx/Make.defs +++ b/arch/tricore/src/tc3xx/Make.defs @@ -21,10 +21,11 @@ ############################################################################ CHIP_CSRCS += tc3xx_timerisr.c -CHIP_CSRCS += tc3xx_serial.c CHIP_CSRCS += tc3xx_wdt.c CHIP_CSRCS += tc3xx_clockconfig.c +include common/aurix/Make.defs + ifeq ($(CONFIG_BUILD_PROTECTED),y) CHIP_UCSRCS += tc397_userspace.c VPATH += $(BOARD_DIR)/kernel diff --git a/arch/tricore/src/tc3xx/chip.h b/arch/tricore/src/tc3xx/chip.h index 4f3a8cb903e..d56c9c13c85 100644 --- a/arch/tricore/src/tc3xx/chip.h +++ b/arch/tricore/src/tc3xx/chip.h @@ -29,8 +29,11 @@ #include "hardware/tc3xx_cpu.h" -#define UART_PIN_RX IfxAsclin0_RXA_P14_1_IN /* UART receive port pin */ -#define UART_PIN_TX IfxAsclin0_TX_P14_0_OUT /* UART transmit port pin */ +/* UART0 pins: ASCLIN0 RXA on P14.1, TX on P14.0 (alternate output 2) */ + +#define UART_PIN_PORT 0xf003ae00 /* P14 */ +#define UART_PIN_RX 1 +#define UART_PIN_TX 0 /**************************************************************************** * Pre-processor Definitions diff --git a/arch/tricore/src/tc3xx/tc3xx_serial.c b/arch/tricore/src/tc3xx/tc3xx_serial.c deleted file mode 100644 index 808386e5ecc..00000000000 --- a/arch/tricore/src/tc3xx/tc3xx_serial.c +++ /dev/null @@ -1,732 +0,0 @@ -/**************************************************************************** - * arch/tricore/src/tc3xx/tc3xx_serial.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <stdint.h> -#include <stdbool.h> -#include <unistd.h> -#include <string.h> -#include <assert.h> -#include <errno.h> - -#include <nuttx/debug.h> -#include <nuttx/irq.h> -#include <nuttx/arch.h> -#include <nuttx/serial/serial.h> - -#include <arch/board/board.h> - -#include "tricore_internal.h" - -#include "Asclin/Asc/IfxAsclin_Asc.h" - -#include <chip.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* If we are not using the serial driver for the console, then we still must - * provide some minimal implementation of up_putc. - */ - -#ifdef USE_SERIALDRIVER - -/* Which UART with be tty0/console and which tty1? The console will always - * be ttyS0. If there is no console then will use the lowest numbered UART. - */ - -#if defined(CONFIG_UART0_SERIAL_CONSOLE) && defined(CONFIG_TC3XX_UART0) -# define HAVE_SERIAL_CONSOLE 1 -#else -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef HAVE_SERIAL_CONSOLE -#endif - -#ifdef HAVE_SERIAL_CONSOLE -# if defined(CONFIG_UART0_SERIAL_CONSOLE) -# define CONSOLE_DEV g_uart0port /* UART0 is console */ -# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */ -# define SERIAL_CONSOLE 1 -# else -# error "I'm confused... Do we have a serial console or not?" -# endif -#else -# undef CONSOLE_DEV /* No console */ -# undef CONFIG_UART0_SERIAL_CONSOLE -# if defined(CONFIG_TC3XX_UART0) -# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */ -# define SERIAL_CONSOLE 1 -# else -# undef TTYS0_DEV -# endif -#endif - -#undef HAVE_UART_DEVICE -#if defined(CONFIG_TC3XX_UART0) -# define HAVE_UART_DEVICE 1 -#endif - -/* Common initialization logic will not not know that the all of the UARTs - * have been disabled. So, as a result, we may still have to provide - * stub implementations of tricore_earlyserialinit(), - * tricore_serialinit(), and up_putc(). - */ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct up_dev_s -{ - volatile void *uartbase; /* Base address of UART registers */ - const void *pins; /* Pin configuration */ - uint32_t baud; /* Configured baud */ - uint8_t irq; /* IRQ associated with this UART */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* Serial driver methods */ - -static int up_setup(struct uart_dev_s *dev); -static void up_shutdown(struct uart_dev_s *dev); -static int up_attach(struct uart_dev_s *dev); -static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, void *arg); -static int up_ioctl(struct file *filep, int cmd, unsigned long arg); -static int up_receive(struct uart_dev_s *dev, unsigned int *status); -static void up_rxint(struct uart_dev_s *dev, bool enable); -static bool up_rxavailable(struct uart_dev_s *dev); -static void up_send(struct uart_dev_s *dev, int ch); -static void up_txint(struct uart_dev_s *dev, bool enable); -static bool up_txready(struct uart_dev_s *dev); -static bool up_txempty(struct uart_dev_s *dev); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct uart_ops_s g_uart_ops = -{ - .setup = up_setup, - .shutdown = up_shutdown, - .attach = up_attach, - .detach = up_detach, - .ioctl = up_ioctl, - .receive = up_receive, - .rxint = up_rxint, - .rxavailable = up_rxavailable, -#ifdef CONFIG_SERIAL_IFLOWCONTROL - .rxflowcontrol = NULL, -#endif - .send = up_send, - .txint = up_txint, - .txready = up_txready, - .txempty = up_txempty, -}; - -/* I/O buffers */ - -#ifdef CONFIG_TC3XX_UART0 -static char g_uart0rxbuffer[CONFIG_UART0_RXBUFSIZE]; -static char g_uart0txbuffer[CONFIG_UART0_TXBUFSIZE]; -#endif - -#ifdef CONFIG_TC3XX_UART0 - -/* Pin configuration */ - -static const IfxAsclin_Asc_Pins g_uart0_pins = -{ - NULL, IfxPort_InputMode_pullUp, /* CTS pin not used */ - &UART_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin */ - NULL, IfxPort_OutputMode_pushPull, /* RTS pin not used */ - &UART_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */ - IfxPort_PadDriver_cmosAutomotiveSpeed1 -}; - -static struct up_dev_s g_uart0priv = -{ - .uartbase = &MODULE_ASCLIN0, - .pins = &g_uart0_pins, - .baud = CONFIG_UART0_BAUD, - .irq = TRICORE_UART_RX_IRQ, -}; - -static uart_dev_t g_uart0port = -{ -#if SERIAL_CONSOLE == 1 - .isconsole = 1, -#endif - .recv = - { - .size = CONFIG_UART0_RXBUFSIZE, - .buffer = g_uart0rxbuffer, - }, - .xmit = - { - .size = CONFIG_UART0_TXBUFSIZE, - .buffer = g_uart0txbuffer, - }, - .ops = &g_uart_ops, - .priv = &g_uart0priv, -}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: asclin_init - * - * Description: - * Configure the UART baud, bits, parity, etc. This method is called the - * first time that the serial port is opened. - * - ****************************************************************************/ - -static void asclin_init(struct up_dev_s *priv) -{ - Ifx_ASCLIN *asclin = priv->uartbase; - const IfxAsclin_Asc_Pins *pins = priv->pins; - - /* enabling the module */ - - IfxAsclin_enableModule(asclin); - - /* disabling the clock */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_noClock); - - /* setting the module in Initialise mode */ - - IfxAsclin_setFrameMode(asclin, IfxAsclin_FrameMode_initialise); - - /* sets the prescaler */ - - IfxAsclin_setPrescaler(asclin, 1); - - /* temporary set the clock source for baudrate configuration */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_ascFastClock); - - /* setting the baudrate bit fields to generate the required baudrate */ - - IfxAsclin_setBitTiming(asclin, priv->baud, - IfxAsclin_OversamplingFactor_16, - IfxAsclin_SamplePointPosition_8, - IfxAsclin_SamplesPerBit_three); - - /* disabling the clock again */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_noClock); - - /* selecting the loopback mode */ - - IfxAsclin_enableLoopBackMode(asclin, false); - - /* setting parity enable */ - - IfxAsclin_enableParity(asclin, false); - - /* setting parity type (odd/even) */ - - IfxAsclin_setParityType(asclin, IfxAsclin_ParityType_even); - - /* setting the stop bit */ - - IfxAsclin_setStopBit(asclin, IfxAsclin_StopBit_1); - - /* setting the shift direction */ - - IfxAsclin_setShiftDirection(asclin, - IfxAsclin_ShiftDirection_lsbFirst); - - /* setting the data length */ - - IfxAsclin_setDataLength(asclin, IfxAsclin_DataLength_8); - - /* setting Tx FIFO inlet width */ - - IfxAsclin_setTxFifoInletWidth(asclin, - IfxAsclin_TxFifoInletWidth_1); - - /* setting Rx FIFO outlet width */ - - IfxAsclin_setRxFifoOutletWidth(asclin, - IfxAsclin_RxFifoOutletWidth_1); - - /* setting idle delay */ - - IfxAsclin_setIdleDelay(asclin, IfxAsclin_IdleDelay_0); - - /* setting Tx FIFO level at which a Tx interrupt will be triggered */ - - IfxAsclin_setTxFifoInterruptLevel(asclin, - IfxAsclin_TxFifoInterruptLevel_0); - - /* setting Rx FIFO interrupt level at which a Rx - * interrupt will be triggered - */ - - IfxAsclin_setRxFifoInterruptLevel(asclin, - IfxAsclin_RxFifoInterruptLevel_1); - - /* setting Tx FIFO interrupt generation mode */ - - IfxAsclin_setTxFifoInterruptMode(asclin, - IfxAsclin_FifoInterruptMode_combined); - - /* setting Rx FIFO interrupt generation mode */ - - IfxAsclin_setRxFifoInterruptMode(asclin, - IfxAsclin_FifoInterruptMode_combined); - - /* selecting the frame mode */ - - IfxAsclin_setFrameMode(asclin, IfxAsclin_FrameMode_asc); - - /* Pin mapping */ - - if (pins != NULL) - { - IfxAsclin_Cts_In *cts = pins->cts; - - if (cts != NULL) - { - IfxAsclin_initCtsPin(cts, pins->ctsMode, pins->pinDriver); - } - - IfxAsclin_Rx_In *rx = pins->rx; - - if (rx != NULL) - { - IfxAsclin_initRxPin(rx, pins->rxMode, pins->pinDriver); - } - - IfxAsclin_Rts_Out *rts = pins->rts; - - if (rts != NULL) - { - IfxAsclin_initRtsPin(rts, pins->rtsMode, pins->pinDriver); - } - - IfxAsclin_Tx_Out *tx = pins->tx; - - if (tx != NULL) - { - IfxAsclin_initTxPin(tx, pins->txMode, pins->pinDriver); - } - } - - /* select the clock source */ - - IfxAsclin_setClockSource(asclin, IfxAsclin_ClockSource_ascFastClock); - - /* disable all flags */ - - IfxAsclin_disableAllFlags(asclin); - - /* clear all flags */ - - IfxAsclin_clearAllFlags(asclin); - - /* HW error flags */ - - IfxAsclin_enableParityErrorFlag(asclin, true); - IfxAsclin_enableFrameErrorFlag(asclin, true); - IfxAsclin_enableRxFifoOverflowFlag(asclin, true); - IfxAsclin_enableRxFifoUnderflowFlag(asclin, true); - IfxAsclin_enableTxFifoOverflowFlag(asclin, true); - - /* enable transfers */ - - IfxAsclin_enableRxFifoInlet(asclin, true); - IfxAsclin_enableTxFifoOutlet(asclin, true); - - IfxAsclin_flushRxFifo(asclin); - IfxAsclin_flushTxFifo(asclin); -} - -/**************************************************************************** - * Name: up_setup - * - * Description: - * Configure the UART baud, bits, parity, etc. This method is called the - * first time that the serial port is opened. - * - ****************************************************************************/ - -static int up_setup(struct uart_dev_s *dev) -{ - asclin_init(dev->priv); - - return OK; -} - -/**************************************************************************** - * Name: up_shutdown - * - * Description: - * Disable the UART. This method is called when the serial - * port is closed - * - ****************************************************************************/ - -static void up_shutdown(struct uart_dev_s *dev) -{ - struct up_dev_s *priv = dev->priv; - - /* Disable interrupts */ - - up_disable_irq(priv->irq); -} - -/**************************************************************************** - * Name: up_attach - * - * Description: - * Configure the UART to operation in interrupt driven mode. This method is - * called when the serial port is opened. Normally, this is just after the - * the setup() method is called, however, the serial console may operate in - * a non-interrupt driven mode during the boot phase. - * - * RX and TX interrupts are not enabled by the attach method (unless the - * hardware supports multiple levels of interrupt enabling). The RX and TX - * interrupts are not enabled until the txint() and rxint() are called. - * - ****************************************************************************/ - -static int up_attach(struct uart_dev_s *dev) -{ - struct up_dev_s *priv = dev->priv; - int ret; - - /* Initialize interrupt generation on the peripheral */ - - ret = irq_attach(priv->irq, up_interrupt, dev); - if (ret == OK) - { - /* Enable the interrupt (RX and TX interrupts are still disabled - * in the UART - */ - - up_enable_irq(priv->irq); - } - - return ret; -} - -/**************************************************************************** - * Name: up_detach - * - * Description: - * Detach UART interrupts. This method is called when the serial port is - * closed normally just before the shutdown method is called. The exception - * is the serial console which is never shutdown. - * - ****************************************************************************/ - -static void up_detach(struct uart_dev_s *dev) -{ - struct up_dev_s *priv = dev->priv; - - /* Disable interrupts */ - - up_disable_irq(priv->irq); - - /* Detach from the interrupt */ - - irq_detach(priv->irq); -} - -/**************************************************************************** - * Name: up_interrupt - * - * Description: - * This is the UART interrupt handler. It will be invoked when an - * interrupt is received on the 'irq'. It should call uart_xmitchars or - * uart_recvchars to perform the appropriate data transfers. The - * interrupt handling logic must be able to map the 'arg' to the - * appropriate uart_dev_s structure in order to call these functions. - * - ****************************************************************************/ - -static int up_interrupt(int irq, void *context, void *arg) -{ - struct uart_dev_s *dev = arg; - - if (up_rxavailable(dev)) - { - uart_recvchars(dev); - } - - if (up_txready(dev)) - { - uart_xmitchars(dev); - } - - return OK; -} - -/**************************************************************************** - * Name: up_ioctl - * - * Description: - * All ioctl calls will be routed through this method - * - ****************************************************************************/ - -static int up_ioctl(struct file *filep, int cmd, unsigned long arg) -{ - return -ENOTTY; -} - -/**************************************************************************** - * Name: up_receive - * - * Description: - * Called (usually) from the interrupt level to receive one - * character from the UART. Error bits associated with the - * receipt are provided in the return 'status'. - * - ****************************************************************************/ - -static int up_receive(struct uart_dev_s *dev, unsigned int *status) -{ - struct up_dev_s *priv = dev->priv; - - return IfxAsclin_readRxData(priv->uartbase); -} - -/**************************************************************************** - * Name: up_rxint - * - * Description: - * Call to enable or disable RX interrupts - * - ****************************************************************************/ - -static void up_rxint(struct uart_dev_s *dev, bool enable) -{ - struct up_dev_s *priv = dev->priv; - irqstate_t flags = enter_critical_section(); - - IfxAsclin_enableRxFifoFillLevelFlag(priv->uartbase, enable); - IfxAsclin_enableRxFifoInlet(priv->uartbase, enable); - - leave_critical_section(flags); -} - -/**************************************************************************** - * Name: up_rxavailable - * - * Description: - * Return true if the receive register is not empty - * - ****************************************************************************/ - -static bool up_rxavailable(struct uart_dev_s *dev) -{ - struct up_dev_s *priv = dev->priv; - - return IfxAsclin_getRxFifoFillLevel(priv->uartbase) > 0; -} - -/**************************************************************************** - * Name: up_send - * - * Description: - * This method will send one byte on the UART. - * - ****************************************************************************/ - -static void up_send(struct uart_dev_s *dev, int ch) -{ - struct up_dev_s *priv = dev->priv; - - /* Wait for FIFO */ - - if (dev == &CONSOLE_DEV) - { - up_putc(ch); - return; - } - - while (IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0); - - IfxAsclin_clearAllFlags(priv->uartbase); - IfxAsclin_writeTxData(priv->uartbase, ch); -} - -/**************************************************************************** - * Name: up_txint - * - * Description: - * Call to enable or disable TX interrupts - * - ****************************************************************************/ - -static void up_txint(struct uart_dev_s *dev, bool enable) -{ - irqstate_t flags; - - flags = enter_critical_section(); - - if (enable) - { - /* Enable the TX interrupt */ - - uart_xmitchars(dev); - } - - leave_critical_section(flags); -} - -/**************************************************************************** - * Name: up_txready - * - * Description: - * Return true if the tranmsit data register is not full - * - ****************************************************************************/ - -static bool up_txready(struct uart_dev_s *dev) -{ - return true; -} - -/**************************************************************************** - * Name: up_txempty - * - * Description: - * Return true if the tranmsit data register is empty - * - ****************************************************************************/ - -static bool up_txempty(struct uart_dev_s *dev) -{ - struct up_dev_s *priv = dev->priv; - - /* Return true if the TX wartermak is pending */ - - return IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0; -} - -/**************************************************************************** - * Name: tricore_lowputc - * - * Description: - * Provide priority, low-level access to support OS debug writes - * - ****************************************************************************/ - -void tricore_lowputc(char ch) -{ -#ifdef HAVE_SERIAL_CONSOLE - struct up_dev_s *priv = CONSOLE_DEV.priv; - - /* Wait for FIFO */ - - while (IfxAsclin_getTxFifoFillLevel(priv->uartbase) != 0); - - IfxAsclin_clearAllFlags(priv->uartbase); - IfxAsclin_writeTxData(priv->uartbase, ch); -#endif /* HAVE_CONSOLE */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef USE_EARLYSERIALINIT - -/**************************************************************************** - * Name: tricore_earlyserialinit - * - * Description: - * Performs the low level UART initialization early in debug so that the - * serial console will be available during boot up. This must be called - * before tricore_serialinit. NOTE: This function depends on GPIO pin - * configuration performed in up_consoleinit() and main clock - * initialization performed in up_clkinitialize(). - * - ****************************************************************************/ - -void tricore_earlyserialinit(void) -{ - /* Configuration whichever one is the console */ - -#ifdef HAVE_SERIAL_CONSOLE - CONSOLE_DEV.isconsole = true; - up_setup(&CONSOLE_DEV); -#endif -} -#endif - -/**************************************************************************** - * Name: tricore_serialinit - * - * Description: - * Register serial console and serial ports. This assumes - * that tricore_earlyserialinit was called previously. - * - ****************************************************************************/ - -void tricore_serialinit(void) -{ - /* Register the console */ - -#ifdef HAVE_SERIAL_CONSOLE - uart_register("/dev/console", &CONSOLE_DEV); -#endif - - /* Register all UARTs */ - - uart_register("/dev/ttyS0", &TTYS0_DEV); -} - -/**************************************************************************** - * Name: up_putc - * - * Description: - * Provide priority, low-level access to support OS debug writes - * - ****************************************************************************/ - -void up_putc(int ch) -{ -#ifdef HAVE_SERIAL_CONSOLE - tricore_lowputc(ch); -#endif -} -#endif /* USE_SERIALDRIVER */ diff --git a/arch/tricore/src/tc3xx/tc3xx_wdt.c b/arch/tricore/src/tc3xx/tc3xx_wdt.c index d4ca8d27ef9..068ae48987f 100644 --- a/arch/tricore/src/tc3xx/tc3xx_wdt.c +++ b/arch/tricore/src/tc3xx/tc3xx_wdt.c @@ -103,6 +103,30 @@ void tc3xx_wdt_safety_endinit(bool set) tc3xx_wdt_endinit(TC3XX_SCU_WDTS_CON0, pw, set); } +/**************************************************************************** + * Name: tc3xx_wdt_cpu_endinit + * + * Description: + * Set or clear the ENDINIT of the calling CPU, which protects for example + * the module clock control and the pad driver registers. CPU5 has the + * core ID 6 on TC39x, hence the limit to 5. + * + ****************************************************************************/ + +void tc3xx_wdt_cpu_endinit(bool set) +{ + uint32_t cpu = tricore_mfcr(TRICORE_CPU_CORE_ID); + uintptr_t con0; + uint32_t pw; + + cpu = cpu > 5 ? 5 : cpu; + con0 = TC3XX_SCU_WDTCPU_CON0(cpu); + pw = ((getreg32(con0) & TC3XX_WDT_CON0_PW_MASK) >> + TC3XX_WDT_CON0_PW_SHIFT) ^ TC3XX_WDT_PW_INVERTED; + + tc3xx_wdt_endinit(con0, pw, set); +} + /**************************************************************************** * Name: tricore_wdt_disable * diff --git a/arch/tricore/src/tc3xx/tc3xx_wdt.h b/arch/tricore/src/tc3xx/tc3xx_wdt.h index 8f974e5b506..7af46c609d3 100644 --- a/arch/tricore/src/tc3xx/tc3xx_wdt.h +++ b/arch/tricore/src/tc3xx/tc3xx_wdt.h @@ -34,5 +34,6 @@ ****************************************************************************/ void tc3xx_wdt_safety_endinit(bool set); +void tc3xx_wdt_cpu_endinit(bool set); #endif /* __ARCH_TRICORE_SRC_TC3XX_TC3XX_WDT_H */ diff --git a/arch/tricore/src/tc4xx/CMakeLists.txt b/arch/tricore/src/tc4xx/CMakeLists.txt index 922cd2a6cc2..25160a2066c 100644 --- a/arch/tricore/src/tc4xx/CMakeLists.txt +++ b/arch/tricore/src/tc4xx/CMakeLists.txt @@ -20,11 +20,12 @@ # # ############################################################################## -set(SRCS tc4xx_timerisr.c tc4xx_serial.c tc4xx_wdt.c tc4xx_clockconfig.c - tc4xx_ram.c) +set(SRCS tc4xx_timerisr.c tc4xx_wdt.c tc4xx_clockconfig.c tc4xx_ram.c) target_sources(arch PRIVATE ${SRCS}) +add_subdirectory(${NUTTX_DIR}/arch/tricore/src/common/aurix aurix) + set(ILLD_UNPACK "${CMAKE_CURRENT_SOURCE_DIR}/../illd/tc4xx") set(ILLD_TARBALL "${ILLD_UNPACK}/illd.tar.gz") set(ILLD_UNPACK_NAME "illd_release_tc4x-main") diff --git a/arch/tricore/src/tc4xx/Make.defs b/arch/tricore/src/tc4xx/Make.defs index 3bc5a996d1d..3d5ccf613ca 100644 --- a/arch/tricore/src/tc4xx/Make.defs +++ b/arch/tricore/src/tc4xx/Make.defs @@ -21,11 +21,12 @@ ############################################################################ CHIP_CSRCS += tc4xx_timerisr.c -CHIP_CSRCS += tc4xx_serial.c CHIP_CSRCS += tc4xx_wdt.c CHIP_CSRCS += tc4xx_clockconfig.c CHIP_CSRCS += tc4xx_ram.c +include common/aurix/Make.defs + ifeq ($(CONFIG_BUILD_PROTECTED),y) CHIP_UCSRCS += tc4d9_userspace.c VPATH += $(BOARD_DIR)/kernel diff --git a/arch/tricore/src/tc4xx/chip.h b/arch/tricore/src/tc4xx/chip.h index f71fd86c544..22e708e4e7c 100644 --- a/arch/tricore/src/tc4xx/chip.h +++ b/arch/tricore/src/tc4xx/chip.h @@ -29,8 +29,11 @@ #include "hardware/tc4xx_cpu.h" -#define UART_PIN_RX IfxAsclin0_RXA_F_P14_1_IN /* UART receive port pin */ -#define UART_PIN_TX IfxAsclin0_TX_F_P14_0_OUT /* UART transmit port pin */ +/* UART0 pins: ASCLIN0 RXA on P14.1, TX on P14.0 (alternate output 2) */ + +#define UART_PIN_PORT 0xf003d800 /* P14 */ +#define UART_PIN_RX 1 +#define UART_PIN_TX 0 /**************************************************************************** * Pre-processor Definitions
