diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2022-07-21 12:49:26 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2022-07-21 12:49:26 +0200 |
commit | 61f4d2dc0e672f2c26bc964a27789cfd4fb81b88 (patch) | |
tree | e6e688cc34cf69928039f58e2fd9c5796cf611d6 /src/arch/tc1796-triboard | |
parent | e2d191ebe69745fe658df8c56be2f8d3c4e7af47 (diff) |
tc1796 is a proper arch now
Diffstat (limited to 'src/arch/tc1796-triboard')
-rw-r--r-- | src/arch/tc1796-triboard/Kconfig | 7 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/Makefile.inc | 94 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/arch.cc | 86 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/driver/counter.cc | 9 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/driver/gpio.cc | 8 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/driver/stdout.cc | 74 | ||||
-rw-r--r-- | src/arch/tc1796-triboard/prompt | 1 |
7 files changed, 279 insertions, 0 deletions
diff --git a/src/arch/tc1796-triboard/Kconfig b/src/arch/tc1796-triboard/Kconfig new file mode 100644 index 0000000..b390ecc --- /dev/null +++ b/src/arch/tc1796-triboard/Kconfig @@ -0,0 +1,7 @@ +# Copyright 2022 Daniel Friesel +# +# SPDX-License-Identifier: CC0-1.0 + +config arch_tc1796_triboard_driver_counter +bool "Cycle Counter" +select meta_driver_counter diff --git a/src/arch/tc1796-triboard/Makefile.inc b/src/arch/tc1796-triboard/Makefile.inc new file mode 100644 index 0000000..97c76a8 --- /dev/null +++ b/src/arch/tc1796-triboard/Makefile.inc @@ -0,0 +1,94 @@ +# vim:ft=make +# +# Copyright 2022 Daniel Friesel +# +# SPDX-License-Identifier: BSD-2-Clause + +CPU = tc1796 + +cpu_freq ?= 150000000 +counter_freq ?= 75000000 +uart_freq ?= 115200 +SERIAL_PORT ?= ttyUSB0 +QEMU_PORT ?= 12345 + +COMMON_FLAGS += -mcpu=${CPU} -DMULTIPASS_ARCH_tc1796 + +ARCH_SHORTNAME = tc1796 + +LICENSE = -mlicense-dir=${HOME}/var/source/aurix-infineon-hightec-tricore +CC = wine ${HOME}/.wine/drive_c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/tricore-gcc.exe ${LICENSE} +CXX = wine ${HOME}/.wine/drive_c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/tricore-g++.exe ${LICENSE} +OBJCOPY = wine ${HOME}/.wine/drive_c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/tricore-objcopy.exe +OBJDUMP = wine ${HOME}/.wine/drive_c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/tricore-objdump.exe ${LICENSE} +SIZE = wine ${HOME}/.wine/drive_c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/tricore-size.exe + +CXX_TARGETS += src/arch/tc1796-triboard/arch.cc +CXX_TARGETS += src/arch/tc1796-triboard/driver/gpio.cc +CXX_TARGETS += src/arch/tc1796-triboard/driver/stdout.cc + +ifneq (${cpu_freq}, ) + COMMON_FLAGS += -DF_CPU=${cpu_freq}U +else + COMMON_FLAGS += -DF_CPU=150000000U +endif + +ifneq ($(findstring counter,${arch_drivers}), ) + CONFIG_arch_tc1796_triboard_driver_counter = y +endif + +ifdef CONFIG_arch_tc1796_triboard_driver_counter + CXX_TARGETS += src/arch/tc1796-triboard/driver/counter.cc +endif + +OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o} ${ASM_TARGETS:.S=.o} + +%.o : %.cc | include/config.h + ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} + +%.o : %.c | include/config.h + ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c} + +%.o : %.S | include/config.h + ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -Wa,-gstabs,-ggdb -x assembler-with-cpp -c -o $@ ${@:.o=.S} + +build/system.elf: ${OBJECTS} + ${QUIET}mkdir -p build + ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \ + -Wl,--gc-sections \ + -o $@ ${OBJECTS} + +build/system.bin: build/system.elf + ${QUIET}${OBJCOPY} -O binary $< $@ + +# Needs a Debian3.1 VM with ios:/ess/dortmund/proj/compiler/tricore-gcc-3.4.5 installed to /opt/trigcc345, +# http://archive.debian.org/debian-security/pool/updates/main/r/resmgr/libresmgr1_1.0-2sarge2_i386.deb http://archive.debian.org/debian-security/pool/updates/main/r/resmgr/resmgr_1.0-2sarge2_i386.deb installed, +# and SSH via localhost:2222. E.g.: +# > qemu-system-i386 -boot c -m 2048 -hda debian3-1.qcow2 -machine type=pc,accel=kvm:tcg --enable-kvm -net nic,model=ne2k_pci -net user,hostfwd=tcp::2022-:22 -smp cores=1,threads=2 -usb -monitor telnet::${QEMU_PORT},server,nowait +# Must already be running in the background before 'make program' can be used. +program: build/system.bin + ${QUIET}echo 'device_add usb-host,vendorid=0x058b,productid=0x0028,id=tricore' | nc -q 1 localhost ${QEMU_PORT} + ${QUIET}scp -oKexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -P 2022 build/system.bin root@localhost:/tmp/system.bin + ${QUIET}ssh -oKexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -p 2022 root@localhost "/opt/trigcc345/bin/tricore-jtag-usb-flash /opt/trigcc345/tricore/flash_driver/intern/tc1796/flashprg.elf /tmp/system.bin" + ${QUIET}echo 'device_del tricore' | nc -q 1 localhost ${QEMU_PORT} + +monitor: + ${QUIET}screen /dev/${SERIAL_PORT} ${uart_freq} + +arch_clean: + ${QUIET}rm -f ${OBJECTS} build/system.elf + +arch_help: + @true + +arch_info: + @echo "CPU Freq: ${cpu_freq} Hz" + @echo "Count Freq: ${counter_freq} Hz" + +attributes: build/system.elf + ${QUIET}script/size.py "${SIZE}" text,rodata bss + +nfpvalues: build/system.elf + ${QUIET}script/nfpvalues.py "${SIZE}" text,rodata bss + +.PHONY: arch_clean arch_help arch_info attributes monitor program diff --git a/src/arch/tc1796-triboard/arch.cc b/src/arch/tc1796-triboard/arch.cc new file mode 100644 index 0000000..73ebd2d --- /dev/null +++ b/src/arch/tc1796-triboard/arch.cc @@ -0,0 +1,86 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "arch.h" + +extern "C" { +#include <machine/wdtcon.h> +#include <tc1796b/scu.h> +#include <tc1796b/pmi.h> +} + +#ifdef __acweaving +#define __delay_cycles(x) +#endif + +#define OF_BYP 29 +#define OF_NDIV 16 +#define OF_PDIV 13 +#define OF_KDIV 8 +#define OF_VCOSEL 6 +#define OF_SYSFS 2 + +#define STM_CLC (*(volatile unsigned int*)0xf0000200) +#define STM_TIM5 (*(volatile unsigned int*)0xf0000224) + +void Arch::setup(void) +{ + /* + * 20 MHz Crystal -> 150 MHz clock + * PLL_CLC := (NDIV = 29; PDIV = 0; KDIV = 3; VCOSEL = 2) + */ + unlock_wdtcon(); + (*(unsigned int*)0xf0000040) = (29 << OF_NDIV) | (0 << OF_PDIV) | (3 << OF_KDIV) | (2 << OF_VCOSEL); + STM_CLC = 0x00000100; + lock_wdtcon(); +} + +#if defined(CONFIG_loop) +extern void loop(); +unsigned int old_tim5 = 0; +#endif + +volatile bool sleep_done = false; + +void Arch::sleep_ms(unsigned int const ms) +{ + delay_ms(ms); +} + +void Arch::delay_us(unsigned int const us) +{ + for (unsigned int i = 0; i < us; i++) { + for (unsigned int c = 0; c < F_CPU/1000000; c++) { + asm volatile("nop"); + } + } +} +void Arch::delay_ms(unsigned int const ms) +{ + for (unsigned int i = 0; i < ms; i++) { + for (unsigned int c = 0; c < F_CPU/1000; c++) { + asm volatile("nop"); + } + } +} + +void Arch::idle_loop(void) +{ + while (1) { +#if defined(CONFIG_loop) + // STM_TIM5 will overflow once every 1.9 years. + if ((STM_TIM5 - old_tim5 > 70) || (old_tim5 > STM_TIM5)) { + old_tim5 = STM_TIM5; + loop(); + } +#endif + } +} + +void Arch::idle(void) +{ +} + +Arch arch; diff --git a/src/arch/tc1796-triboard/driver/counter.cc b/src/arch/tc1796-triboard/driver/counter.cc new file mode 100644 index 0000000..0277d07 --- /dev/null +++ b/src/arch/tc1796-triboard/driver/counter.cc @@ -0,0 +1,9 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "arch.h" +#include "driver/counter.h" + +Counter counter; diff --git a/src/arch/tc1796-triboard/driver/gpio.cc b/src/arch/tc1796-triboard/driver/gpio.cc new file mode 100644 index 0000000..b66add2 --- /dev/null +++ b/src/arch/tc1796-triboard/driver/gpio.cc @@ -0,0 +1,8 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "driver/gpio.h" + +GPIO gpio; diff --git a/src/arch/tc1796-triboard/driver/stdout.cc b/src/arch/tc1796-triboard/driver/stdout.cc new file mode 100644 index 0000000..499b2ab --- /dev/null +++ b/src/arch/tc1796-triboard/driver/stdout.cc @@ -0,0 +1,74 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "driver/stdout.h" +#include <machine/wdtcon.h> +#include <tc1796b/port5-struct.h> +#include <tc1796b/asc0-struct.h> + +#define OF_BYP 29 +#define OF_NDIV 16 +#define OF_PDIV 13 +#define OF_KDIV 8 +#define OF_VCOSEL 6 +#define OF_SYSFS 2 + +#define OF_RMC 8 +#define ASC0_CLC (*(volatile unsigned int*)0xf0000a00) +#define ASC0_PISEL (*(volatile unsigned int*)0xf0000a04) +#define ASC0_CON (*(volatile unsigned int*)0xf0000a10) +#define ASC0_BG (*(volatile unsigned int*)0xf0000a14) +#define ASC0_FDV (*(volatile unsigned int*)0xf0000a18) +#define ASC0_TBUF (*(volatile unsigned int*)0xf0000a20) +#define ASC0_TBSRC (*(volatile unsigned int*)0xf0000afc) + +#define SRC_SRE (1 << 12) +#define SRC_SRR (1 << 13) +#define SRC_CLRR (1 << 14) +#define SRC_SETR (1 << 15) + +void StandardOutput::setup() +{ + // P5_IOCR0.PC1 = OUT_PPALT1 + (*(volatile unsigned int*)0xf0001110) = 0x9 << 12; + // P5_IOMR.PS1 = 1 + (*(volatile unsigned int*)0xf0001104) = 0x00000001; + + /* Configure for 115200 Baud @ 75 MHz fSYS, see table 19-4 */ + unsigned int const reload_value = 0x17; + unsigned int const fdv = 0x12e; + + unlock_wdtcon(); + // ASC0_CLC: enable (DISR := 0), RMC := 1 (clock divider == 1 -> clock == system clock "fsys"?) + ASC0_CLC = 1 << OF_RMC; + lock_wdtcon(); + // ASC0_CON = 0 + ASC0_CON = 0; + // ASC0_BG = reload_value + ASC0_BG = reload_value; + // ASC0_FDV = fdv + ASC0_FDV = fdv; + // ASC0_CON := (M := ASCM_8ASYNC == 1; FDE := 1; R := 1 + ASC0_CON = (1 << 0) | (1 << 11) | (1 << 15); + + /* After initialization, the transmit buffer is ready to accept writes. */ + ASC0_TBSRC = SRC_SETR; +} + +void StandardOutput::put(char c) +{ + while (!(ASC0_TBSRC & SRC_SRR)) ; + + /* Clear service request flag -- we're filling up TBUF */ + ASC0_TBSRC = SRC_CLRR; + + ASC0_TBUF = c; + + if (c == '\n') { + put('\r'); + } +} + +StandardOutput kout; diff --git a/src/arch/tc1796-triboard/prompt b/src/arch/tc1796-triboard/prompt new file mode 100644 index 0000000..0e6a368 --- /dev/null +++ b/src/arch/tc1796-triboard/prompt @@ -0,0 +1 @@ +TC1796 TriBoard |