This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 06ce9749ea04404b4d6e49cd4681fb2fb0ca0a96 Author: Andrew Yong <[email protected]> AuthorDate: Tue Nov 24 15:49:56 2026 +0800 arch/arm: Add the PortalPlayer PP502x chip. Add ARCH_CHIP_PP502X, an ARM7TDMI chip that runs the main core and keeps the second core asleep. The chip has the interrupt controller with its high bank, the system timer on Timer 1 and up_udelay() on the microsecond counter, the glue for the 16550 UART driver on UART 0, the 80 MHz PLL (CONFIG_PP502X_PLL_BOOST), the CPU cache start-up, idle by stopping the core, a start-up file with its own vector table, and the register definitions of these blocks. No other block of the chip has code. The start-up file probes the SDRAM size by an alias test, programs the remap window for 32 MiB or 64 MiB, and up_allocate_heap() runs the heap to the end of the size found, so one image serves both parts. The CMakeLists.txt of the chip takes the common head and vector table out of the build in favour of the start-up file, as Make.defs does. Assisted-by: Claude Code:claude-sonnet-5-5 Assisted-by: Claude Code:claude-fable-5-2 Signed-off-by: Andrew Yong <[email protected]> --- arch/arm/Kconfig | 13 ++ arch/arm/include/pp502x/irq.h | 61 ++++++ arch/arm/src/pp502x/CMakeLists.txt | 47 +++++ arch/arm/src/pp502x/Kconfig | 32 +++ arch/arm/src/pp502x/Make.defs | 42 ++++ arch/arm/src/pp502x/chip.h | 103 +++++++++ arch/arm/src/pp502x/hardware/pp502x_cache.h | 86 ++++++++ arch/arm/src/pp502x/hardware/pp502x_intc.h | 95 +++++++++ arch/arm/src/pp502x/hardware/pp502x_memorymap.h | 56 +++++ arch/arm/src/pp502x/hardware/pp502x_remap.h | 71 +++++++ arch/arm/src/pp502x/hardware/pp502x_sysctl.h | 129 ++++++++++++ arch/arm/src/pp502x/hardware/pp502x_timer.h | 62 ++++++ arch/arm/src/pp502x/hardware/pp502x_uart.h | 53 +++++ arch/arm/src/pp502x/pp502x_allocateheap.c | 60 ++++++ arch/arm/src/pp502x/pp502x_cache.c | 77 +++++++ arch/arm/src/pp502x/pp502x_decodeirq.c | 109 ++++++++++ arch/arm/src/pp502x/pp502x_head.S | 266 ++++++++++++++++++++++++ arch/arm/src/pp502x/pp502x_idle.c | 55 +++++ arch/arm/src/pp502x/pp502x_irq.c | 149 +++++++++++++ arch/arm/src/pp502x/pp502x_lowsetup.c | 178 ++++++++++++++++ arch/arm/src/pp502x/pp502x_serial.c | 90 ++++++++ arch/arm/src/pp502x/pp502x_timerisr.c | 113 ++++++++++ 22 files changed, 1947 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index c98daf7edce..e6d67f96139 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -427,6 +427,15 @@ config ARCH_CHIP_MCX_NXXX ---help--- NXXx architectures (Cortex-M33) +config ARCH_CHIP_PP502X + bool "PortalPlayer PP502x" + select ARCH_ARM7TDMI + select ARCH_HAVE_UDELAY + select ARCH_HAVE_DYNAMIC_UDELAY + ---help--- + PortalPlayer PP502x architectures (ARM7TDMI). Only the main core + runs; the coprocessor stays asleep. + config ARCH_CHIP_RA4 bool "Renesas RA4" ---help--- @@ -1492,6 +1501,7 @@ config ARCH_CHIP default "nrf54l" if ARCH_CHIP_NRF54L default "nrf91" if ARCH_CHIP_NRF91 default "nuc1xx" if ARCH_CHIP_NUC1XX + default "pp502x" if ARCH_CHIP_PP502X default "ra4" if ARCH_CHIP_RA4 default "ra8m1" if ARCH_CHIP_RA8M1 default "rp2040" if ARCH_CHIP_RP2040 @@ -2040,6 +2050,9 @@ endif if ARCH_CHIP_NUC1XX source "arch/arm/src/nuc1xx/Kconfig" endif +if ARCH_CHIP_PP502X +source "arch/arm/src/pp502x/Kconfig" +endif if ARCH_CHIP_RA4 source "arch/arm/src/ra4/Kconfig" endif diff --git a/arch/arm/include/pp502x/irq.h b/arch/arm/include/pp502x/irq.h new file mode 100644 index 00000000000..cfd3568e8b7 --- /dev/null +++ b/arch/arm/include/pp502x/irq.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * arch/arm/include/pp502x/irq.h + * + * 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. + * + ****************************************************************************/ + +/* This file should never be included directly but, rather, only indirectly + * through nuttx/irq.h + */ + +#ifndef __ARCH_ARM_INCLUDE_PP502X_IRQ_H +#define __ARCH_ARM_INCLUDE_PP502X_IRQ_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* IRQ numbers 0-31 are the bits of the normal interrupt bank and 32-63 are + * the bits of the high bank. Bit 30 of the normal bank is the cascade of + * the high bank and is not dispatched as an IRQ of its own. + */ + +#define PP502X_IRQ_TIMER1 0 /* Timer 1 */ +#define PP502X_IRQ_TIMER2 1 /* Timer 2 */ +#define PP502X_IRQ_MAILBOX 4 /* Inter-core mailbox */ +#define PP502X_IRQ_I2S 10 /* I2S FIFO */ +#define PP502X_IRQ_USB 20 /* USB device controller */ +#define PP502X_IRQ_IDE 23 /* IDE controller */ +#define PP502X_IRQ_FIREWIRE 25 /* FireWire link */ +#define PP502X_IRQ_DMA 26 /* DMA controller */ +#define PP502X_IRQ_HI 30 /* High bank cascade */ + +#define PP502X_IRQ_HIBASE 32 +#define PP502X_IRQ_GPIO0 (PP502X_IRQ_HIBASE + 0) /* GPIO ports A-D */ +#define PP502X_IRQ_GPIO1 (PP502X_IRQ_HIBASE + 1) /* GPIO ports E-H */ +#define PP502X_IRQ_GPIO2 (PP502X_IRQ_HIBASE + 2) /* GPIO ports I-L */ +#define PP502X_IRQ_SER0 (PP502X_IRQ_HIBASE + 4) /* UART 0 */ +#define PP502X_IRQ_SER1 (PP502X_IRQ_HIBASE + 5) /* UART 1 */ +#define PP502X_IRQ_I2C (PP502X_IRQ_HIBASE + 8) /* I2C */ + +#define PP502X_IRQ_SYSTIMER PP502X_IRQ_TIMER1 + +#define NR_IRQS 64 + +#endif /* __ARCH_ARM_INCLUDE_PP502X_IRQ_H */ diff --git a/arch/arm/src/pp502x/CMakeLists.txt b/arch/arm/src/pp502x/CMakeLists.txt new file mode 100644 index 00000000000..019a6facfad --- /dev/null +++ b/arch/arm/src/pp502x/CMakeLists.txt @@ -0,0 +1,47 @@ +# ############################################################################## +# arch/arm/src/pp502x/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. +# +# ############################################################################## + +# The start-up file has the vector table (its reset slot must be a relative +# branch), so it replaces the common head and vector table. + +get_target_property(NUTTX_SRCS nuttx SOURCES) +list(FILTER NUTTX_SRCS EXCLUDE REGEX "arm_head\\.S$") +set_property(TARGET nuttx PROPERTY SOURCES ${NUTTX_SRCS}) + +get_target_property(ARCH_SRCS arch SOURCES) +list(FILTER ARCH_SRCS EXCLUDE REGEX "arm_vectortab\\.S$") +set_property(TARGET arch PROPERTY SOURCES ${ARCH_SRCS}) + +target_sources(nuttx PRIVATE pp502x_head.S) + +set(SRCS pp502x_allocateheap.c pp502x_cache.c pp502x_decodeirq.c pp502x_irq.c + pp502x_lowsetup.c pp502x_serial.c) + +if(NOT CONFIG_SCHED_TICKLESS) + list(APPEND SRCS pp502x_timerisr.c) +endif() + +if(NOT CONFIG_ARCH_IDLE_CUSTOM) + list(APPEND SRCS pp502x_idle.c) +endif() + +target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm/src/pp502x/Kconfig b/arch/arm/src/pp502x/Kconfig new file mode 100644 index 00000000000..2b2842d5564 --- /dev/null +++ b/arch/arm/src/pp502x/Kconfig @@ -0,0 +1,32 @@ +############################################################################ +# arch/arm/src/pp502x/Kconfig +# +# 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. +# +############################################################################ + +comment "PortalPlayer PP502x Configuration Options" + +config PP502X_PLL_BOOST + bool "Run the core from the 80 MHz PLL" + default y + ---help--- + Start the PLL and switch the core clock from the 24 MHz crystal + to 80 MHz at boot. If the PLL does not lock in time the core + stays on the crystal. When disabled the clock stays as the + boot loader left it. diff --git a/arch/arm/src/pp502x/Make.defs b/arch/arm/src/pp502x/Make.defs new file mode 100644 index 00000000000..b74d7e2997f --- /dev/null +++ b/arch/arm/src/pp502x/Make.defs @@ -0,0 +1,42 @@ +############################################################################ +# arch/arm/src/pp502x/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. +# +############################################################################ + +include arm/Make.defs + +# The vector table lives in the start-up file (its reset slot must be a +# relative branch) and the idle loop sleeps the core. + +HEAD_ASRC = pp502x_head.S + +CMN_ASRCS := $(filter-out arm_vectortab.S,$(CMN_ASRCS)) +CMN_CSRCS := $(filter-out arm_idle.c,$(CMN_CSRCS)) + +CHIP_CSRCS = pp502x_allocateheap.c pp502x_cache.c pp502x_decodeirq.c pp502x_irq.c +CHIP_CSRCS += pp502x_lowsetup.c pp502x_serial.c + +ifneq ($(CONFIG_SCHED_TICKLESS),y) +CHIP_CSRCS += pp502x_timerisr.c +endif + +ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) +CHIP_CSRCS += pp502x_idle.c +endif diff --git a/arch/arm/src/pp502x/chip.h b/arch/arm/src/pp502x/chip.h new file mode 100644 index 00000000000..74d1f1a612f --- /dev/null +++ b/arch/arm/src/pp502x/chip.h @@ -0,0 +1,103 @@ +/**************************************************************************** + * arch/arm/src/pp502x/chip.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_CHIP_H +#define __ARCH_ARM_SRC_PP502X_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifndef __ASSEMBLY__ +# include <stdint.h> +#endif + +#include "hardware/pp502x_memorymap.h" +#include "hardware/pp502x_cache.h" +#include "hardware/pp502x_intc.h" +#include "hardware/pp502x_remap.h" +#include "hardware/pp502x_sysctl.h" +#include "hardware/pp502x_timer.h" +#include "hardware/pp502x_uart.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Iterations of the wait for the COP sleep bit in pp502x_head.S, about + * 0.25 s at the 24 MHz entry clock for 23 cycles per iteration. + */ + +#define PP502X_COP_WAIT_COUNT 0x40000 + +/* SDRAM size probe: two words, 32 MiB apart, in the top 64 KiB of the first + * 32 MiB, which the image does not reach. PP502X_SDRAM_PROBE_HIGH is read + * back from the low word on a 32 MiB part. + */ + +#define PP502X_SDRAM_PROBE_OFFSET 0x01fff000 +#define PP502X_SDRAM_PROBE_LOW 0xa5a5a5a5 +#define PP502X_SDRAM_PROBE_HIGH 0x5a5a5a5a + +/* Bound on the wait for the PLL lock. The time limit is the normal exit; + * the poll count only covers a stuck USEC_TIMER. + */ + +#define PP502X_PLL_LOCK_TIMEOUT_US 10000 +#define PP502X_PLL_LOCK_MAX_POLLS 0x10000 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/* SDRAM size in bytes, set from the probe by pp502x_head.S */ + +extern uint32_t g_pp502x_ramsize; + +/**************************************************************************** + * Name: pp502x_cache_init + * + * Description: + * Turn the CPU cache on. Called from pp502x_head.S before BSS is + * cleared, so it uses no static data. + * + ****************************************************************************/ + +void pp502x_cache_init(void); + +/**************************************************************************** + * Name: pp502x_lowsetup + * + * Description: + * Called from pp502x_head.S before the OS starts, on the CPU only. + * Sets up the core clock and the console UART. + * + ****************************************************************************/ + +void pp502x_lowsetup(void); + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_PP502X_CHIP_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_cache.h b/arch/arm/src/pp502x/hardware/pp502x_cache.h new file mode 100644 index 00000000000..ce5f96b08e9 --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_cache.h @@ -0,0 +1,86 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_cache.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_CACHE_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_CACHE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Cache geometry: 8 KiB with 16 byte lines */ + +#define PP502X_CACHE_SIZE 8192 +#define PP502X_CACHE_LINESIZE 16 + +/* Register Offsets *********************************************************/ + +/* PP502X_CACHE_CTL is in the cache control block, PP502X_CACHE_PRIORITY in + * the device control block, and the other two in the remap block. + */ + +#define PP502X_CACHE_CTL_OFFSET 0x0000 +#define PP502X_CACHE_PRIORITY_OFFSET 0x0044 +#define PP502X_CACHE_MASK_OFFSET 0x0040 +#define PP502X_CACHE_OPERATION_OFFSET 0x0044 + +/* Register Addresses *******************************************************/ + +#define PP502X_CACHE_CTL (PP502X_CACHECTL_BASE + \ + PP502X_CACHE_CTL_OFFSET) +#define PP502X_CACHE_PRIORITY (PP502X_DEVCTL_BASE + \ + PP502X_CACHE_PRIORITY_OFFSET) +#define PP502X_CACHE_MASK (PP502X_REMAP_BASE + PP502X_CACHE_MASK_OFFSET) +#define PP502X_CACHE_OPERATION (PP502X_REMAP_BASE + \ + PP502X_CACHE_OPERATION_OFFSET) + +/* One status word per line, on the CPU side */ + +#define PP502X_CACHE_STATUS_CPU 0xf0004000 + +/* Register Bitfield Definitions ********************************************/ + +/* CACHE_CTL */ + +#define PP502X_CACHE_CTL_ENABLE (1 << 0) +#define PP502X_CACHE_CTL_RUN (1 << 1) +#define PP502X_CACHE_CTL_INIT (1 << 2) + +/* CACHE_PRIORITY */ + +#define PP502X_CACHE_PRIORITY_CPU (1 << 4) + +/* CACHE_MASK: the windows at 0x0 and 0x20000000 are cached */ + +#define PP502X_CACHE_MASK_CACHED 0x00001c00 + +/* CACHE_OPERATION */ + +#define PP502X_CACHE_OP_INIT 0x00000fc0 + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_CACHE_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_intc.h b/arch/arm/src/pp502x/hardware/pp502x_intc.h new file mode 100644 index 00000000000..b6fa6bba83b --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_intc.h @@ -0,0 +1,95 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_intc.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_INTC_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_INTC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +/* The high bank has the same layout at PP502X_INTC_HI_OFFSET */ + +#define PP502X_INTC_CPU_STAT_OFFSET 0x0000 /* Active CPU IRQ sources */ +#define PP502X_INTC_FORCEDCLR_OFFSET 0x001c /* Write 1 to unforce */ +#define PP502X_INTC_CPU_ENSTAT_OFFSET 0x0020 /* CPU enabled sources */ +#define PP502X_INTC_CPU_EN_OFFSET 0x0024 /* Write 1 to enable */ +#define PP502X_INTC_CPU_DIS_OFFSET 0x0028 /* Write 1 to disable */ +#define PP502X_INTC_CPU_PRIO_OFFSET 0x002c /* 1 routes to FIQ */ +#define PP502X_INTC_COP_DIS_OFFSET 0x0038 /* Write 1 to disable */ + +#define PP502X_INTC_HI_OFFSET 0x0100 /* High bank */ + +/* Register Addresses *******************************************************/ + +/* Normal bank */ + +#define PP502X_INTC_CPU_STAT (PP502X_INTC_BASE + \ + PP502X_INTC_CPU_STAT_OFFSET) +#define PP502X_INTC_FORCEDCLR (PP502X_INTC_BASE + \ + PP502X_INTC_FORCEDCLR_OFFSET) +#define PP502X_INTC_CPU_ENSTAT (PP502X_INTC_BASE + \ + PP502X_INTC_CPU_ENSTAT_OFFSET) +#define PP502X_INTC_CPU_EN (PP502X_INTC_BASE + PP502X_INTC_CPU_EN_OFFSET) +#define PP502X_INTC_CPU_DIS (PP502X_INTC_BASE + PP502X_INTC_CPU_DIS_OFFSET) +#define PP502X_INTC_CPU_PRIO (PP502X_INTC_BASE + \ + PP502X_INTC_CPU_PRIO_OFFSET) +#define PP502X_INTC_COP_DIS (PP502X_INTC_BASE + PP502X_INTC_COP_DIS_OFFSET) + +/* High bank */ + +#define PP502X_INTC_HI_CPU_STAT (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_CPU_STAT_OFFSET) +#define PP502X_INTC_HI_FORCEDCLR (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_FORCEDCLR_OFFSET) +#define PP502X_INTC_HI_CPU_ENSTAT (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_CPU_ENSTAT_OFFSET) +#define PP502X_INTC_HI_CPU_EN (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_CPU_EN_OFFSET) +#define PP502X_INTC_HI_CPU_DIS (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_CPU_DIS_OFFSET) +#define PP502X_INTC_HI_CPU_PRIO (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_CPU_PRIO_OFFSET) +#define PP502X_INTC_HI_COP_DIS (PP502X_INTC_BASE + PP502X_INTC_HI_OFFSET + \ + PP502X_INTC_COP_DIS_OFFSET) + +/* Register Bitfield Definitions ********************************************/ + +/* Bit of the normal bank that reports and enables the whole high bank */ + +#define PP502X_INTC_HI_CASCADE (1 << 30) + +/* CPU_PRIO: sources 31 and 27 are routed to FIQ. FIQ stays masked, so + * neither is delivered. + */ + +#define PP502X_INTC_CPU_PRIO_FIQ ((1u << 31) | (1u << 27)) + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_INTC_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_memorymap.h b/arch/arm/src/pp502x/hardware/pp502x_memorymap.h new file mode 100644 index 00000000000..4fbc28286c3 --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_memorymap.h @@ -0,0 +1,56 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_memorymap.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_MEMORYMAP_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_MEMORYMAP_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Address space. SDRAM is physically at 0x10000000; window 0 of the remap + * unit makes it appear at logical 0 as well, which is where the image is + * linked. + */ + +#define PP502X_SDRAM_LOGICAL 0x00000000 /* SDRAM through window 0 */ +#define PP502X_SDRAM_PHYS 0x10000000 /* SDRAM physical address */ +#define PP502X_SDRAM_SIZE_32M 0x02000000 /* Smaller SDRAM part */ +#define PP502X_SDRAM_SIZE_64M 0x04000000 /* Larger SDRAM part */ +#define PP502X_IRAM_BASE 0x40000000 /* Internal SRAM */ +#define PP502X_IRAM_SIZE 0x00020000 /* 128 KiB */ + +/* On-chip peripheral blocks */ + +#define PP502X_PROCID_BASE 0x60000000 /* Processor id */ +#define PP502X_INTC_BASE 0x60004000 /* Interrupt controller */ +#define PP502X_TIMER_BASE 0x60005000 /* Timers and USEC_TIMER */ +#define PP502X_DEVCTL_BASE 0x60006000 /* Device reset/enable, clocks */ +#define PP502X_PROCCTL_BASE 0x60007000 /* Core sleep/wake control */ +#define PP502X_CACHECTL_BASE 0x6000c000 /* Cache control */ +#define PP502X_GPIO_BASE 0x6000d000 /* GPIO ports A-L */ +#define PP502X_SYSCFG_BASE 0x70000000 /* System configuration, GPO32 */ +#define PP502X_UART0_BASE 0x70006000 /* UART 0 (dock connector) */ +#define PP502X_UART1_BASE 0x70006040 /* UART 1 */ +#define PP502X_REMAP_BASE 0xf000f000 /* Remap windows, cache mask */ + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_MEMORYMAP_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_remap.h b/arch/arm/src/pp502x/hardware/pp502x_remap.h new file mode 100644 index 00000000000..cdbe367b716 --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_remap.h @@ -0,0 +1,71 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_remap.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_REMAP_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_REMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +/* Eight windows with a logical and a physical register each */ + +#define PP502X_REMAP_LOGICAL_OFFSET(n) (8 * (n)) +#define PP502X_REMAP_PHYSICAL_OFFSET(n) (8 * (n) + 4) + +/* Register Addresses *******************************************************/ + +#define PP502X_REMAP_LOGICAL(n) (PP502X_REMAP_BASE + \ + PP502X_REMAP_LOGICAL_OFFSET(n)) +#define PP502X_REMAP_PHYSICAL(n) (PP502X_REMAP_BASE + \ + PP502X_REMAP_PHYSICAL_OFFSET(n)) + +/* Register Bitfield Definitions ********************************************/ + +/* REMAP_LOGICAL: compare address bits 29:25 (32 MiB) or 29:26 (64 MiB) */ + +#define PP502X_REMAP_MASK_32MB 0x3e00 +#define PP502X_REMAP_MASK_64MB 0x3c00 + +/* REMAP_PHYSICAL: access permissions, and the low bits that are always set + * for SDRAM + */ + +#define PP502X_REMAP_PHYS_READ (1 << 8) +#define PP502X_REMAP_PHYS_WRITE (1 << 9) +#define PP502X_REMAP_PHYS_DATA (1 << 10) +#define PP502X_REMAP_PHYS_CODE (1 << 11) +#define PP502X_REMAP_PHYS_SDRAM 0x84 + +#define PP502X_REMAP_PHYS_SDRAM_FLAGS \ + (PP502X_REMAP_PHYS_READ | PP502X_REMAP_PHYS_WRITE | \ + PP502X_REMAP_PHYS_DATA | PP502X_REMAP_PHYS_CODE | PP502X_REMAP_PHYS_SDRAM) + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_REMAP_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_sysctl.h b/arch/arm/src/pp502x/hardware/pp502x_sysctl.h new file mode 100644 index 00000000000..bd3b50cbdfa --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_sysctl.h @@ -0,0 +1,129 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_sysctl.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_SYSCTL_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_SYSCTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +#define PP502X_PROCID_OFFSET 0x0000 /* Processor id */ + +#define PP502X_CPU_CTL_OFFSET 0x0000 /* CPU control */ +#define PP502X_COP_CTL_OFFSET 0x0004 /* COP control */ + +#define PP502X_DEV_RS_OFFSET 0x0004 /* Device reset */ +#define PP502X_DEV_EN_OFFSET 0x000c /* Device clock enable */ +#define PP502X_CLOCK_SOURCE_OFFSET 0x0020 /* Clock source select */ +#define PP502X_PLL_CONTROL_OFFSET 0x0034 /* PLL control */ +#define PP502X_PLL_STATUS_OFFSET 0x003c /* PLL status */ + +#define PP502X_DEV_INIT2_OFFSET 0x0020 /* Device init 2 */ +#define PP502X_DEV_TIMING1_OFFSET 0x0034 /* Bus timing */ +#define PP502X_GPO32_ENABLE_OFFSET 0x0084 /* GPO32 output enable */ +#define PP502X_SER_PINMUX_OFFSET 0x008c /* UART pin routing */ + +/* Register Addresses *******************************************************/ + +#define PP502X_PROC_ID (PP502X_PROCID_BASE + PP502X_PROCID_OFFSET) + +#define PP502X_CPU_CTL (PP502X_PROCCTL_BASE + PP502X_CPU_CTL_OFFSET) +#define PP502X_COP_CTL (PP502X_PROCCTL_BASE + PP502X_COP_CTL_OFFSET) + +#define PP502X_DEV_RS (PP502X_DEVCTL_BASE + PP502X_DEV_RS_OFFSET) +#define PP502X_DEV_EN (PP502X_DEVCTL_BASE + PP502X_DEV_EN_OFFSET) +#define PP502X_CLOCK_SOURCE (PP502X_DEVCTL_BASE + \ + PP502X_CLOCK_SOURCE_OFFSET) +#define PP502X_PLL_CONTROL (PP502X_DEVCTL_BASE + \ + PP502X_PLL_CONTROL_OFFSET) +#define PP502X_PLL_STATUS (PP502X_DEVCTL_BASE + PP502X_PLL_STATUS_OFFSET) + +#define PP502X_DEV_INIT2 (PP502X_SYSCFG_BASE + PP502X_DEV_INIT2_OFFSET) +#define PP502X_DEV_TIMING1 (PP502X_SYSCFG_BASE + \ + PP502X_DEV_TIMING1_OFFSET) +#define PP502X_GPO32_ENABLE (PP502X_SYSCFG_BASE + \ + PP502X_GPO32_ENABLE_OFFSET) +#define PP502X_SER_PINMUX (PP502X_SYSCFG_BASE + \ + PP502X_SER_PINMUX_OFFSET) + +/* Register Bitfield Definitions ********************************************/ + +/* Processor id: the low byte reads differently on each core */ + +#define PP502X_PROCID_CPU 0x55 +#define PP502X_PROCID_COP 0xaa + +/* CPU_CTL and COP_CTL */ + +#define PP502X_PROCCTL_SLEEP (1 << 31) /* Stop until an interrupt */ +#define PP502X_PROCCTL_WAIT_CNT (1 << 30) /* Stop until COUNT expires */ +#define PP502X_PROCCTL_CNT_CLKS (1 << 27) /* COUNT is in clock cycles */ + +/* Stall the core for n clock cycles */ + +#define PP502X_PROCCTL_STALL(n) (PP502X_PROCCTL_WAIT_CNT | \ + PP502X_PROCCTL_CNT_CLKS | (n)) + +/* DEV_RS and DEV_EN */ + +#define PP502X_DEV_SER0 (1 << 6) /* UART 0 */ + +/* DEV_INIT2 */ + +#define PP502X_DEV_INIT2_PLL_POWER (1 << 30) /* PLL power */ + +/* PLL_CONTROL: enable bits, and 80 MHz (24 MHz x 20 / 3 / 2) */ + +#define PP502X_PLL_CONTROL_ENABLE 0x88000000 +#define PP502X_PLL_CONTROL_RUN 0x80000000 +#define PP502X_PLL_CONTROL_80MHZ 0x8a121403 + +/* PLL_STATUS */ + +#define PP502X_PLL_STATUS_LOCKED (1 << 31) + +/* CLOCK_SOURCE: all four slots on the crystal or on the PLL, slot 2 active */ + +#define PP502X_CLOCK_SOURCE_CRYSTAL 0x20002222 +#define PP502X_CLOCK_SOURCE_PLL 0x20007777 + +/* DEV_TIMING1 for the crystal and for an 80 MHz core clock */ + +#define PP502X_DEV_TIMING1_CRYSTAL 0x303 +#define PP502X_DEV_TIMING1_80MHZ 0x808 + +/* SER_PINMUX and GPO32_ENABLE: pins of UART 0, clear to route it to the + * dock connector + */ + +#define PP502X_SER0_PINS_MASK (3 << 2) + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_SYSCTL_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_timer.h b/arch/arm/src/pp502x/hardware/pp502x_timer.h new file mode 100644 index 00000000000..6d9e7556aff --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_timer.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_timer.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_TIMER_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_TIMER_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +/* Both timers and USEC_TIMER count at 1 MHz */ + +#define PP502X_TIMER1_CFG_OFFSET 0x0000 /* Timer 1 configuration */ +#define PP502X_TIMER1_VAL_OFFSET 0x0004 /* Timer 1 value, read acks */ +#define PP502X_TIMER2_CFG_OFFSET 0x0008 /* Timer 2 configuration */ +#define PP502X_TIMER2_VAL_OFFSET 0x000c /* Timer 2 value, read acks */ +#define PP502X_USEC_TIMER_OFFSET 0x0010 /* Free-running microseconds */ + +/* Register Addresses *******************************************************/ + +#define PP502X_TIMER1_CFG (PP502X_TIMER_BASE + PP502X_TIMER1_CFG_OFFSET) +#define PP502X_TIMER1_VAL (PP502X_TIMER_BASE + PP502X_TIMER1_VAL_OFFSET) +#define PP502X_TIMER2_CFG (PP502X_TIMER_BASE + PP502X_TIMER2_CFG_OFFSET) +#define PP502X_TIMER2_VAL (PP502X_TIMER_BASE + PP502X_TIMER2_VAL_OFFSET) +#define PP502X_USEC_TIMER (PP502X_TIMER_BASE + PP502X_USEC_TIMER_OFFSET) + +/* Register Bitfield Definitions ********************************************/ + +/* TIMERn_CFG */ + +#define PP502X_TIMER_CFG_ENABLE (1 << 31) /* Count and interrupt */ +#define PP502X_TIMER_CFG_REPEAT (1 << 30) /* Reload at zero */ +#define PP502X_TIMER_CFG_PERIOD_MASK 0x1fffffff /* Period less one, in us */ + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_TIMER_H */ diff --git a/arch/arm/src/pp502x/hardware/pp502x_uart.h b/arch/arm/src/pp502x/hardware/pp502x_uart.h new file mode 100644 index 00000000000..f837fbf3711 --- /dev/null +++ b/arch/arm/src/pp502x/hardware/pp502x_uart.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/src/pp502x/hardware/pp502x_uart.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_UART_H +#define __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_UART_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "hardware/pp502x_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +/* 16550 compatible registers, one per 32-bit word */ + +#define PP502X_UART_THR_OFFSET 0x0000 /* Transmit holding (DLL if DLAB) */ +#define PP502X_UART_IER_OFFSET 0x0004 /* Interrupt enable (DLM if DLAB) */ +#define PP502X_UART_FCR_OFFSET 0x0008 /* FIFO control, interrupt id */ +#define PP502X_UART_LCR_OFFSET 0x000c /* Line control */ +#define PP502X_UART_MCR_OFFSET 0x0010 /* Modem control */ +#define PP502X_UART_LSR_OFFSET 0x0014 /* Line status */ + +/* Register Bitfield Definitions ********************************************/ + +/* LSR */ + +#define PP502X_UART_LSR_THRE (1 << 5) /* Transmit holding empty */ + +#endif /* __ARCH_ARM_SRC_PP502X_HARDWARE_PP502X_UART_H */ diff --git a/arch/arm/src/pp502x/pp502x_allocateheap.c b/arch/arm/src/pp502x/pp502x_allocateheap.c new file mode 100644 index 00000000000..15b4b9badf9 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_allocateheap.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_allocateheap.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 <nuttx/arch.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +uint32_t g_pp502x_ramsize = CONFIG_RAM_SIZE; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_allocate_heap + * + * Description: + * Set the heap from the end of the idle stack to the end of the SDRAM, + * whose size the start-up code probed. + * + ****************************************************************************/ + +void up_allocate_heap(void **heap_start, size_t *heap_size) +{ + *heap_start = (void *)g_idle_topstack; + *heap_size = CONFIG_RAM_START + g_pp502x_ramsize - g_idle_topstack; +} diff --git a/arch/arm/src/pp502x/pp502x_cache.c b/arch/arm/src/pp502x/pp502x_cache.c new file mode 100644 index 00000000000..a099f6bea91 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_cache.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_cache.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 <stdint.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pp502x_cache_init + * + * Description: + * Turn the CPU cache on: mask and operation word cleared, init mode, one + * status word per line cleared, CPU priority bit, the mask, the init + * operation, enable and run, and one read of every line of the first + * 8 KiB of logical SDRAM, which is cached; the physical alias is not. + * + ****************************************************************************/ + +void pp502x_cache_init(void) +{ + uintptr_t addr; + + putreg32(0, PP502X_CACHE_MASK); + putreg32(0, PP502X_CACHE_OPERATION); + putreg32(PP502X_CACHE_CTL_INIT, PP502X_CACHE_CTL); + + for (addr = PP502X_CACHE_STATUS_CPU; + addr < PP502X_CACHE_STATUS_CPU + PP502X_CACHE_SIZE; + addr += PP502X_CACHE_LINESIZE) + { + putreg32(0, addr); + } + + putreg32(getreg32(PP502X_CACHE_PRIORITY) | PP502X_CACHE_PRIORITY_CPU, + PP502X_CACHE_PRIORITY); + putreg32(PP502X_CACHE_MASK_CACHED, PP502X_CACHE_MASK); + putreg32(PP502X_CACHE_OP_INIT, PP502X_CACHE_OPERATION); + putreg32(PP502X_CACHE_CTL_ENABLE | PP502X_CACHE_CTL_RUN | + PP502X_CACHE_CTL_INIT, PP502X_CACHE_CTL); + + for (addr = PP502X_SDRAM_LOGICAL; + addr < PP502X_SDRAM_LOGICAL + PP502X_CACHE_SIZE; + addr += PP502X_CACHE_LINESIZE) + { + (void)getreg8(addr); + } +} diff --git a/arch/arm/src/pp502x/pp502x_decodeirq.c b/arch/arm/src/pp502x/pp502x_decodeirq.c new file mode 100644 index 00000000000..dc27b8fd5f7 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_decodeirq.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_decodeirq.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 <stdint.h> +#include <assert.h> + +#include <nuttx/irq.h> +#include <nuttx/arch.h> +#include <nuttx/debug.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pp502x_lowestbit + ****************************************************************************/ + +#ifndef CONFIG_SUPPRESS_INTERRUPTS +static int pp502x_lowestbit(uint32_t status) +{ + int bit; + + for (bit = 0; bit < 32; bit++) + { + if ((status & (1u << bit)) != 0) + { + break; + } + } + + return bit; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arm_decodeirq + * + * Description: + * Deliver the lowest numbered pending and enabled source, normal bank + * first. The high bank cascade bit is not a source of its own. + * + ****************************************************************************/ + +uint32_t *arm_decodeirq(uint32_t *regs) +{ +#ifdef CONFIG_SUPPRESS_INTERRUPTS + err("ERROR: Unexpected IRQ\n"); + PANIC(); +#else + uint32_t status; + int irq; + + status = getreg32(PP502X_INTC_CPU_STAT) & + getreg32(PP502X_INTC_CPU_ENSTAT) & ~PP502X_INTC_HI_CASCADE; + + if (status != 0) + { + irq = pp502x_lowestbit(status); + } + else + { + status = getreg32(PP502X_INTC_HI_CPU_STAT) & + getreg32(PP502X_INTC_HI_CPU_ENSTAT); + if (status == 0) + { + return regs; + } + + irq = PP502X_IRQ_HIBASE + pp502x_lowestbit(status); + } + + regs = arm_doirq(irq, regs); +#endif + + return regs; +} diff --git a/arch/arm/src/pp502x/pp502x_head.S b/arch/arm/src/pp502x/pp502x_head.S new file mode 100644 index 00000000000..206a8ad4587 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_head.S @@ -0,0 +1,266 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_head.S + * + * 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 "arm.h" +#include "chip.h" +#include "arm_internal.h" + + .file "pp502x_head.S" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define REMAP0_PHYSICAL (PP502X_SDRAM_PHYS | PP502X_REMAP_PHYS_SDRAM_FLAGS) + +/**************************************************************************** + * Text + ****************************************************************************/ + + .syntax unified + .arm + +/* The image is linked at logical address 0 with this section first, so the + * vector table below is also the one the core fetches once window 0 maps + * SDRAM at 0. Everything up to .Lrelocated runs at the load address, + * which can differ from the link address, and must be position + * independent. + */ + + .section .vectors, "ax" + + .globl _vector_start + .globl _vector_end + .globl __start + +/**************************************************************************** + * Name: _vector_start + * + * Description: + * Exception vectors. Every slot is a relative branch: the loader enters + * the first word of the image wherever it placed it, and loaders find + * the start of an image by its two leading branch instructions. + * + ****************************************************************************/ + +_vector_start: + b __start /* 0x00: Reset */ + b arm_vectorundefinsn /* 0x04: Undefined instruction */ + b arm_vectorsvc /* 0x08: Software interrupt */ + b arm_vectorprefetch /* 0x0c: Prefetch abort */ + b arm_vectordata /* 0x10: Data abort */ + b arm_vectoraddrexcptn /* 0x14: Address exception */ + b arm_vectorirq /* 0x18: IRQ */ + b arm_vectorfiq /* 0x1c: FIQ */ + +_vector_end: + +/**************************************************************************** + * Name: __start + * + * Description: + * Entry point for both cores. The COP masks its interrupts and sleeps + * for good. The CPU masks its interrupts, waits for the COP to sleep + * (for a bounded time), turns off the cache and the local vector table, + * sizes the SDRAM, maps SDRAM at logical 0, moves the image to the start + * of SDRAM if it was loaded elsewhere, and continues at its link address, + * where it turns the cache on again. + * + ****************************************************************************/ + + .type __start, %function + +__start: + mov r0, #(PSR_MODE_SVC | PSR_I_BIT | PSR_F_BIT) + msr cpsr_c, r0 + + ldr r0, =PP502X_PROC_ID + ldrb r0, [r0] + cmp r0, #PP502X_PROCID_CPU + beq .Lcpu + + mvn r2, #0 + ldr r1, =PP502X_INTC_COP_DIS + str r2, [r1] + ldr r1, =PP502X_INTC_HI_COP_DIS + str r2, [r1] + + ldr r1, =PP502X_COP_CTL + mov r2, #PP502X_PROCCTL_SLEEP +.Lcopsleep: + str r2, [r1] + nop + nop + nop + nop + b .Lcopsleep + +.Lcpu: + mvn r2, #0 + ldr r1, =PP502X_INTC_CPU_DIS + str r2, [r1] + ldr r1, =PP502X_INTC_HI_CPU_DIS + str r2, [r1] + + /* The wait is bounded: a COP that never sleeps must not hang the + * boot before any output. + */ + + ldr r1, =PP502X_COP_CTL + ldr r3, =PP502X_COP_WAIT_COUNT +.Lwaitcop: + ldr r2, [r1] + tst r2, #PP502X_PROCCTL_SLEEP + bne .Lcopwaited + subs r3, r3, #1 + bne .Lwaitcop +.Lcopwaited: + + ldr r1, =PP502X_CACHE_CTL + mov r2, #0 + str r2, [r1] + + /* Size the SDRAM. A 32 MiB part repeats in the upper half of the + * 64 MiB window, so a word written there reads back at the same offset + * in the lower half. Both words are restored. fp keeps the size + * until .Lremapped. + */ + + ldr r1, =(PP502X_SDRAM_PHYS + PP502X_SDRAM_PROBE_OFFSET) + ldr r3, =PP502X_SDRAM_SIZE_32M + ldr r4, [r1] + ldr r5, [r1, r3] + ldr r6, =PP502X_SDRAM_PROBE_LOW + ldr r7, =PP502X_SDRAM_PROBE_HIGH + str r6, [r1] + str r7, [r1, r3] + ldr r2, [r1] + cmp r2, r7 + str r5, [r1, r3] + str r4, [r1] + ldr fp, =PP502X_SDRAM_SIZE_64M + ldr r2, =PP502X_REMAP_MASK_64MB + ldreq fp, =PP502X_SDRAM_SIZE_32M + ldreq r2, =PP502X_REMAP_MASK_32MB + + /* Window 0 only translates logical addresses below the SDRAM size, + * so this code, which runs at its physical address, is not moved by + * it. + */ + + ldr r1, =PP502X_REMAP_LOGICAL(0) + str r2, [r1] + ldr r2, =REMAP0_PHYSICAL + str r2, [r1, #4] + + /* Copy downwards to the start of SDRAM. The copy is safe as long as + * the load address is at least the image size above the destination. + */ + + adr r0, _vector_start + ldr r1, =PP502X_SDRAM_PHYS + cmp r0, r1 + cmpne r0, #0 + beq .Lrelocated + + ldr r2, =_edata + add r2, r1, r2 +.Lcopy: + ldmia r0!, {r3-r10} + stmia r1!, {r3-r10} + cmp r1, r2 + blo .Lcopy + +.Lrelocated: + ldr pc, =.Lremapped + + .ltorg + .size __start, . - __start + +/**************************************************************************** + * Name: .Lremapped + * + * Description: + * Runs at the link address: set up the idle stack in SYS mode, turn the + * cache on (it uses no static data), clear BSS and start the OS. + * + ****************************************************************************/ + + .text + +.Lremapped: + mov r0, #(PSR_MODE_SYS | PSR_I_BIT | PSR_F_BIT) + msr cpsr_c, r0 + + adr r0, .Linitparms + ldmia r0, {r4, r5, sp} + + ldr r0, =g_pp502x_ramsize + str fp, [r0] + + bl pp502x_cache_init + + mov fp, #0 +1: cmp r4, r5 + strcc fp, [r4], #4 + bcc 1b + + bl pp502x_lowsetup + +#ifdef USE_EARLYSERIALINIT + bl arm_earlyserialinit +#endif + + mov lr, #0 + b nx_start + +.Linitparms: + .long _sbss + .long _ebss + .long _ebss + CONFIG_IDLETHREAD_STACKSIZE + + .ltorg + +/**************************************************************************** + * Name: g_idle_topstack + * + * Description: + * The idle task stack starts at the end of BSS. The heap continues from + * there until the end of RAM. + * + ****************************************************************************/ + + .data + .align 4 + .globl g_idle_topstack + .type g_idle_topstack, object + +g_idle_topstack: + .long _ebss + CONFIG_IDLETHREAD_STACKSIZE + .size g_idle_topstack, . - g_idle_topstack + .end diff --git a/arch/arm/src/pp502x/pp502x_idle.c b/arch/arm/src/pp502x/pp502x_idle.c new file mode 100644 index 00000000000..74d138134d9 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_idle.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_idle.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 <nuttx/arch.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_idle + * + * Description: + * Stop the CPU until an enabled interrupt arrives. The core takes a few + * cycles to stop after the write, hence the padding. + * + ****************************************************************************/ + +void up_idle(void) +{ +#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_TIMER_INTS) + nxsched_process_timer(); +#else + putreg32(PP502X_PROCCTL_SLEEP, PP502X_CPU_CTL); + __asm__ __volatile__("nop\n\tnop\n\tnop\n\tnop\n"); +#endif +} diff --git a/arch/arm/src/pp502x/pp502x_irq.c b/arch/arm/src/pp502x/pp502x_irq.c new file mode 100644 index 00000000000..a98303ed8fe --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_irq.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_irq.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 <stdint.h> + +#include <nuttx/irq.h> +#include <nuttx/arch.h> + +#include "arm.h" +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* GPIO interrupt enable registers: three modules of four ports */ + +#define PP502X_GPIO_NMODULES 3 +#define PP502X_GPIO_NPORTS 4 +#define PP502X_GPIO_MODULE_STRIDE 0x80 +#define PP502X_GPIO_INT_EN_OFFSET 0x50 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_irqinitialize + ****************************************************************************/ + +void up_irqinitialize(void) +{ + uintptr_t base; + int module; + int port; + + /* Mask every source on both cores and drop forced sources, so that + * nothing the boot loader left enabled is delivered. + */ + + putreg32(0xffffffff, PP502X_INTC_CPU_DIS); + putreg32(0xffffffff, PP502X_INTC_HI_CPU_DIS); + putreg32(0xffffffff, PP502X_INTC_COP_DIS); + putreg32(0xffffffff, PP502X_INTC_HI_COP_DIS); + putreg32(0xffffffff, PP502X_INTC_FORCEDCLR); + putreg32(0xffffffff, PP502X_INTC_HI_FORCEDCLR); + putreg32(PP502X_INTC_CPU_PRIO_FIQ, PP502X_INTC_CPU_PRIO); + putreg32(0, PP502X_INTC_HI_CPU_PRIO); + + for (module = 0; module < PP502X_GPIO_NMODULES; module++) + { + base = PP502X_GPIO_BASE + module * PP502X_GPIO_MODULE_STRIDE + + PP502X_GPIO_INT_EN_OFFSET; + + for (port = 0; port < PP502X_GPIO_NPORTS; port++) + { + putreg32(0, base + 4 * port); + } + } + +#ifndef CONFIG_SUPPRESS_INTERRUPTS + arm_color_intstack(); + up_irq_restore(PSR_MODE_SYS | PSR_F_BIT); +#endif +} + +/**************************************************************************** + * Name: up_disable_irq + * + * Description: + * Disable the IRQ specified by 'irq' for the CPU. The high bank cascade + * stays enabled for the other high bank sources. + * + ****************************************************************************/ + +void up_disable_irq(int irq) +{ + if ((unsigned)irq < PP502X_IRQ_HIBASE) + { + putreg32(1u << irq, PP502X_INTC_CPU_DIS); + } + else if ((unsigned)irq < NR_IRQS) + { + putreg32(1u << (irq - PP502X_IRQ_HIBASE), PP502X_INTC_HI_CPU_DIS); + } +} + +/**************************************************************************** + * Name: up_enable_irq + * + * Description: + * Enable the IRQ specified by 'irq' for the CPU. The enable registers + * are write-1-to-set, so no read-modify-write is needed. A high bank + * source also needs the cascade bit in the normal bank. + * + ****************************************************************************/ + +void up_enable_irq(int irq) +{ + if ((unsigned)irq < PP502X_IRQ_HIBASE) + { + putreg32(1u << irq, PP502X_INTC_CPU_EN); + } + else if ((unsigned)irq < NR_IRQS) + { + putreg32(1u << (irq - PP502X_IRQ_HIBASE), PP502X_INTC_HI_CPU_EN); + putreg32(PP502X_INTC_HI_CASCADE, PP502X_INTC_CPU_EN); + } +} + +/**************************************************************************** + * Name: arm_ack_irq + * + * Description: + * Acknowledge the interrupt. Sources are acknowledged at the peripheral + * (the timers by a read of their value register), so there is nothing to + * do at the controller. + * + ****************************************************************************/ + +void arm_ack_irq(int irq) +{ +} diff --git a/arch/arm/src/pp502x/pp502x_lowsetup.c b/arch/arm/src/pp502x/pp502x_lowsetup.c new file mode 100644 index 00000000000..d28931422aa --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_lowsetup.c @@ -0,0 +1,178 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_lowsetup.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 <stdbool.h> +#include <stdint.h> + +#include <nuttx/arch.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define PP502X_RESET_PULSE_US 1000 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_PP502X_PLL_BOOST + +/**************************************************************************** + * Name: pp502x_clockswitch + * + * Description: + * Write the bus timing and the clock source in the given order with the + * CPU stalled around the switch. Interrupts are masked and the COP is + * parked, so the CPU is the only master. + * + ****************************************************************************/ + +static void pp502x_clockswitch(uint32_t source, uint32_t timing, + bool timingfirst) +{ + putreg32(PP502X_PROCCTL_STALL(3), PP502X_CPU_CTL); + + if (timingfirst) + { + putreg32(timing, PP502X_DEV_TIMING1); + putreg32(source, PP502X_CLOCK_SOURCE); + } + else + { + putreg32(source, PP502X_CLOCK_SOURCE); + putreg32(timing, PP502X_DEV_TIMING1); + } + + putreg32(PP502X_PROCCTL_STALL(31), PP502X_CPU_CTL); +} + +/**************************************************************************** + * Name: pp502x_pllwait + * + * Description: + * Wait for the PLL lock bit, for at most PP502X_PLL_LOCK_TIMEOUT_US. + * + ****************************************************************************/ + +static bool pp502x_pllwait(void) +{ + uint32_t start = getreg32(PP502X_USEC_TIMER); + unsigned int polls; + + for (polls = 0; polls < PP502X_PLL_LOCK_MAX_POLLS; polls++) + { + if ((getreg32(PP502X_PLL_STATUS) & PP502X_PLL_STATUS_LOCKED) != 0) + { + return true; + } + + if (getreg32(PP502X_USEC_TIMER) - start >= + PP502X_PLL_LOCK_TIMEOUT_US) + { + break; + } + } + + return false; +} + +#endif /* CONFIG_PP502X_PLL_BOOST */ + +/**************************************************************************** + * Name: pp502x_clockconfig + * + * Description: + * Move the core from the 24 MHz crystal to the 80 MHz PLL. If the PLL + * does not lock in time, power it down and stay on the crystal; the bus + * is never routed onto an unlocked PLL. The timers and the UART count + * from the crystal and do not depend on this choice. Without + * CONFIG_PP502X_PLL_BOOST the clock stays as the boot loader left it. + * + ****************************************************************************/ + +static void pp502x_clockconfig(void) +{ +#ifdef CONFIG_PP502X_PLL_BOOST + modifyreg32(PP502X_DEV_INIT2, 0, PP502X_DEV_INIT2_PLL_POWER); + modifyreg32(PP502X_PLL_CONTROL, 0, PP502X_PLL_CONTROL_ENABLE); + + pp502x_clockswitch(PP502X_CLOCK_SOURCE_CRYSTAL, + PP502X_DEV_TIMING1_CRYSTAL, false); + + putreg32(PP502X_PLL_CONTROL_80MHZ, PP502X_PLL_CONTROL); + + if (pp502x_pllwait()) + { + pp502x_clockswitch(PP502X_CLOCK_SOURCE_PLL, + PP502X_DEV_TIMING1_80MHZ, true); + } + else + { + modifyreg32(PP502X_PLL_CONTROL, PP502X_PLL_CONTROL_RUN, 0); + modifyreg32(PP502X_DEV_INIT2, PP502X_DEV_INIT2_PLL_POWER, 0); + } +#endif +} + +/**************************************************************************** + * Name: pp502x_uart0setup + * + * Description: + * Route UART0 to the dock connector pins, clock it and pulse its reset. + * The line settings are left to the 16550 driver. + * + ****************************************************************************/ + +static void pp502x_uart0setup(void) +{ + modifyreg32(PP502X_SER_PINMUX, PP502X_SER0_PINS_MASK, 0); + modifyreg32(PP502X_GPO32_ENABLE, PP502X_SER0_PINS_MASK, 0); + modifyreg32(PP502X_DEV_EN, 0, PP502X_DEV_SER0); + + modifyreg32(PP502X_DEV_RS, 0, PP502X_DEV_SER0); + up_udelay(PP502X_RESET_PULSE_US); + modifyreg32(PP502X_DEV_RS, PP502X_DEV_SER0, 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pp502x_lowsetup + ****************************************************************************/ + +void pp502x_lowsetup(void) +{ + pp502x_clockconfig(); + pp502x_uart0setup(); +} diff --git a/arch/arm/src/pp502x/pp502x_serial.c b/arch/arm/src/pp502x/pp502x_serial.c new file mode 100644 index 00000000000..15fb8e38c71 --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_serial.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_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 <stdint.h> + +#include <nuttx/serial/uart_16550.h> + +#include "chip.h" +#include "arm_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arm_lowputc + * + * Description: + * Output one byte on UART0 without using the serial driver. + * + ****************************************************************************/ + +void arm_lowputc(char ch) +{ + while ((getreg32(PP502X_UART0_BASE + PP502X_UART_LSR_OFFSET) & + PP502X_UART_LSR_THRE) == 0) + { + } + + putreg32((uint32_t)ch, PP502X_UART0_BASE + PP502X_UART_THR_OFFSET); +} + +#ifdef CONFIG_16550_UART + +/**************************************************************************** + * Name: arm_earlyserialinit + * + * Description: + * Configure the console UART before the OS starts. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void arm_earlyserialinit(void) +{ + u16550_earlyserialinit(); +} +#endif + +/**************************************************************************** + * Name: arm_serialinit + * + * Description: + * Register the serial devices. + * + ****************************************************************************/ + +#ifdef USE_SERIALDRIVER +void arm_serialinit(void) +{ + u16550_serialinit(); +} +#endif + +#endif /* CONFIG_16550_UART */ diff --git a/arch/arm/src/pp502x/pp502x_timerisr.c b/arch/arm/src/pp502x/pp502x_timerisr.c new file mode 100644 index 00000000000..ecee8e41f7a --- /dev/null +++ b/arch/arm/src/pp502x/pp502x_timerisr.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * arch/arm/src/pp502x/pp502x_timerisr.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 <stdint.h> + +#include <nuttx/arch.h> +#include <nuttx/irq.h> + +#include "chip.h" +#include "clock/clock.h" +#include "arm_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Timer 1 counts microseconds, so the period field is the tick less one */ + +#define PP502X_TICK_PERIOD (CONFIG_USEC_PER_TICK - 1) +#define PP502X_TICK_CFG (PP502X_TIMER_CFG_ENABLE | \ + PP502X_TIMER_CFG_REPEAT | \ + (PP502X_TICK_PERIOD & \ + PP502X_TIMER_CFG_PERIOD_MASK)) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pp502x_timerisr + * + * Description: + * The system timer interrupt handler. Reading TIMER1_VAL acknowledges + * the interrupt. + * + ****************************************************************************/ + +static int pp502x_timerisr(int irq, uint32_t *regs, void *arg) +{ + getreg32(PP502X_TIMER1_VAL); + + nxsched_process_timer(); + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_timer_initialize + * + * Description: + * Start Timer 1 as a periodic interrupt at CONFIG_USEC_PER_TICK. + * + ****************************************************************************/ + +void up_timer_initialize(void) +{ + up_disable_irq(PP502X_IRQ_SYSTIMER); + + putreg32(0, PP502X_TIMER1_CFG); + getreg32(PP502X_TIMER1_VAL); + + irq_attach(PP502X_IRQ_SYSTIMER, (xcpt_t)pp502x_timerisr, NULL); + + putreg32(PP502X_TICK_CFG, PP502X_TIMER1_CFG); + + up_enable_irq(PP502X_IRQ_SYSTIMER); +} + +/**************************************************************************** + * Name: up_udelay + * + * Description: + * Busy-wait on the free-running microsecond counter. The unsigned + * difference stays correct across counter wrap. + * + ****************************************************************************/ + +void up_udelay(useconds_t microseconds) +{ + uint32_t start = getreg32(PP502X_USEC_TIMER); + + while (getreg32(PP502X_USEC_TIMER) - start < microseconds) + { + } +}
