From 61f4d2dc0e672f2c26bc964a27789cfd4fb81b88 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 21 Jul 2022 12:49:26 +0200 Subject: tc1796 is a proper arch now --- include/arch/infineon-tc1796-mock/driver/counter.h | 41 ---------- include/arch/infineon-tc1796-mock/driver/gpio.h | 53 ------------ include/arch/infineon-tc1796-mock/driver/stdout.h | 24 ------ include/arch/infineon-tc1796-mock/driver/uptime.h | 32 -------- include/arch/tc1796-triboard/driver/counter.h | 41 ++++++++++ include/arch/tc1796-triboard/driver/gpio.h | 53 ++++++++++++ include/arch/tc1796-triboard/driver/stdout.h | 24 ++++++ include/arch/tc1796-triboard/driver/uptime.h | 32 ++++++++ src/arch/infineon-tc1796-mock/Kconfig | 7 -- src/arch/infineon-tc1796-mock/Makefile.inc | 94 ---------------------- src/arch/infineon-tc1796-mock/arch.cc | 86 -------------------- src/arch/infineon-tc1796-mock/driver/counter.cc | 9 --- src/arch/infineon-tc1796-mock/driver/gpio.cc | 8 -- src/arch/infineon-tc1796-mock/driver/stdout.cc | 74 ----------------- src/arch/infineon-tc1796-mock/prompt | 1 - src/arch/tc1796-triboard/Kconfig | 7 ++ src/arch/tc1796-triboard/Makefile.inc | 94 ++++++++++++++++++++++ src/arch/tc1796-triboard/arch.cc | 86 ++++++++++++++++++++ src/arch/tc1796-triboard/driver/counter.cc | 9 +++ src/arch/tc1796-triboard/driver/gpio.cc | 8 ++ src/arch/tc1796-triboard/driver/stdout.cc | 74 +++++++++++++++++ src/arch/tc1796-triboard/prompt | 1 + 22 files changed, 429 insertions(+), 429 deletions(-) delete mode 100644 include/arch/infineon-tc1796-mock/driver/counter.h delete mode 100644 include/arch/infineon-tc1796-mock/driver/gpio.h delete mode 100644 include/arch/infineon-tc1796-mock/driver/stdout.h delete mode 100644 include/arch/infineon-tc1796-mock/driver/uptime.h create mode 100644 include/arch/tc1796-triboard/driver/counter.h create mode 100644 include/arch/tc1796-triboard/driver/gpio.h create mode 100644 include/arch/tc1796-triboard/driver/stdout.h create mode 100644 include/arch/tc1796-triboard/driver/uptime.h delete mode 100644 src/arch/infineon-tc1796-mock/Kconfig delete mode 100644 src/arch/infineon-tc1796-mock/Makefile.inc delete mode 100644 src/arch/infineon-tc1796-mock/arch.cc delete mode 100644 src/arch/infineon-tc1796-mock/driver/counter.cc delete mode 100644 src/arch/infineon-tc1796-mock/driver/gpio.cc delete mode 100644 src/arch/infineon-tc1796-mock/driver/stdout.cc delete mode 100644 src/arch/infineon-tc1796-mock/prompt create mode 100644 src/arch/tc1796-triboard/Kconfig create mode 100644 src/arch/tc1796-triboard/Makefile.inc create mode 100644 src/arch/tc1796-triboard/arch.cc create mode 100644 src/arch/tc1796-triboard/driver/counter.cc create mode 100644 src/arch/tc1796-triboard/driver/gpio.cc create mode 100644 src/arch/tc1796-triboard/driver/stdout.cc create mode 100644 src/arch/tc1796-triboard/prompt diff --git a/include/arch/infineon-tc1796-mock/driver/counter.h b/include/arch/infineon-tc1796-mock/driver/counter.h deleted file mode 100644 index 38d039e..0000000 --- a/include/arch/infineon-tc1796-mock/driver/counter.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#ifndef COUNTER_H -#define COUNTER_H - -#define STM_TIM0 (*(volatile unsigned int*)0xf0000210) -#define STM_CAP (*(volatile unsigned int*)0xf000022c) - -typedef unsigned int counter_value_t; -typedef unsigned int counter_overflow_t; - -class Counter { - private: - Counter(const Counter ©); - unsigned long long startvalue, stopvalue; - - public: - counter_value_t value; - counter_overflow_t overflow; - - Counter() : overflow(0) {} - - inline void start() { - startvalue = STM_TIM0; - startvalue += (unsigned long long)STM_CAP << 32; - } - - inline void stop() { - stopvalue = STM_TIM0; - stopvalue += (unsigned long long)STM_CAP << 32; - value = (stopvalue - startvalue) & 0xffffffff; - overflow = (unsigned long long)(stopvalue - startvalue) >> 32; - } -}; - -extern Counter counter; - -#endif diff --git a/include/arch/infineon-tc1796-mock/driver/gpio.h b/include/arch/infineon-tc1796-mock/driver/gpio.h deleted file mode 100644 index 9ac43dd..0000000 --- a/include/arch/infineon-tc1796-mock/driver/gpio.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#ifndef GPIO_H -#define GPIO_H - -class GPIO { - private: - GPIO(const GPIO ©); - - public: - GPIO () {} - - enum Pin : unsigned char { - PIN_INVALID - }; - - inline void setup() { - *((int*)0xf0000f10) = 0x80808080; - *((int*)0xf0000f14) = 0x80808080; - *((int*)0xf0000f00) = 0x000000ff; - } - inline void led_on(unsigned char id = 0) { - *((int*)0xf0000f00) &= ~(1 << id); - } - inline void led_off(unsigned char id = 0) { - *((int*)0xf0000f00) |= (1 << id); - } - inline void led_toggle(unsigned char id = 0) { - *((int*)0xf0000f00) ^= (1 << id); - } - inline void input(unsigned char const pin) { - } - inline void input(unsigned char const pin, unsigned char const pull) { - } - inline void output(unsigned char const pin) { - } - inline void output(unsigned char const pin, unsigned char const value) { - } - inline unsigned char read(unsigned char const pin) { - return 0; - } - inline void write(unsigned char const pin, unsigned char value) { - } - inline void write_mask(unsigned char const pin_base, unsigned char set_mask, unsigned char clear_mask) { - } -}; - -extern GPIO gpio; - -#endif diff --git a/include/arch/infineon-tc1796-mock/driver/stdout.h b/include/arch/infineon-tc1796-mock/driver/stdout.h deleted file mode 100644 index b701dc1..0000000 --- a/include/arch/infineon-tc1796-mock/driver/stdout.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#ifndef STANDARDOUTPUT_H -#define STANDARDOUTPUT_H - -#include "object/outputstream.h" - -class StandardOutput : public OutputStream { - private: - StandardOutput(const StandardOutput ©); - - public: - StandardOutput () {} - void setup(); - - virtual void put(char c) override; -}; - -extern StandardOutput kout; - -#endif diff --git a/include/arch/infineon-tc1796-mock/driver/uptime.h b/include/arch/infineon-tc1796-mock/driver/uptime.h deleted file mode 100644 index 6f52f8f..0000000 --- a/include/arch/infineon-tc1796-mock/driver/uptime.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#ifndef UPTIME_H -#define UPTIME_H - -class Uptime { - private: - Uptime(const Uptime ©); -#ifdef TIMER_S - uint16_t seconds; -#endif - - public: -#ifdef TIMER_S - Uptime () : seconds(0) {} -#else - Uptime () {} -#endif - inline uint16_t get_us() { return 0; } - inline uint16_t get_cycles() { return 0; } -#ifdef TIMER_S - inline uint16_t get_s() { return seconds; } - inline void tick_s() { seconds++; } -#endif -}; - -extern Uptime uptime; - -#endif diff --git a/include/arch/tc1796-triboard/driver/counter.h b/include/arch/tc1796-triboard/driver/counter.h new file mode 100644 index 0000000..38d039e --- /dev/null +++ b/include/arch/tc1796-triboard/driver/counter.h @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef COUNTER_H +#define COUNTER_H + +#define STM_TIM0 (*(volatile unsigned int*)0xf0000210) +#define STM_CAP (*(volatile unsigned int*)0xf000022c) + +typedef unsigned int counter_value_t; +typedef unsigned int counter_overflow_t; + +class Counter { + private: + Counter(const Counter ©); + unsigned long long startvalue, stopvalue; + + public: + counter_value_t value; + counter_overflow_t overflow; + + Counter() : overflow(0) {} + + inline void start() { + startvalue = STM_TIM0; + startvalue += (unsigned long long)STM_CAP << 32; + } + + inline void stop() { + stopvalue = STM_TIM0; + stopvalue += (unsigned long long)STM_CAP << 32; + value = (stopvalue - startvalue) & 0xffffffff; + overflow = (unsigned long long)(stopvalue - startvalue) >> 32; + } +}; + +extern Counter counter; + +#endif diff --git a/include/arch/tc1796-triboard/driver/gpio.h b/include/arch/tc1796-triboard/driver/gpio.h new file mode 100644 index 0000000..9ac43dd --- /dev/null +++ b/include/arch/tc1796-triboard/driver/gpio.h @@ -0,0 +1,53 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef GPIO_H +#define GPIO_H + +class GPIO { + private: + GPIO(const GPIO ©); + + public: + GPIO () {} + + enum Pin : unsigned char { + PIN_INVALID + }; + + inline void setup() { + *((int*)0xf0000f10) = 0x80808080; + *((int*)0xf0000f14) = 0x80808080; + *((int*)0xf0000f00) = 0x000000ff; + } + inline void led_on(unsigned char id = 0) { + *((int*)0xf0000f00) &= ~(1 << id); + } + inline void led_off(unsigned char id = 0) { + *((int*)0xf0000f00) |= (1 << id); + } + inline void led_toggle(unsigned char id = 0) { + *((int*)0xf0000f00) ^= (1 << id); + } + inline void input(unsigned char const pin) { + } + inline void input(unsigned char const pin, unsigned char const pull) { + } + inline void output(unsigned char const pin) { + } + inline void output(unsigned char const pin, unsigned char const value) { + } + inline unsigned char read(unsigned char const pin) { + return 0; + } + inline void write(unsigned char const pin, unsigned char value) { + } + inline void write_mask(unsigned char const pin_base, unsigned char set_mask, unsigned char clear_mask) { + } +}; + +extern GPIO gpio; + +#endif diff --git a/include/arch/tc1796-triboard/driver/stdout.h b/include/arch/tc1796-triboard/driver/stdout.h new file mode 100644 index 0000000..b701dc1 --- /dev/null +++ b/include/arch/tc1796-triboard/driver/stdout.h @@ -0,0 +1,24 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDOUTPUT_H +#define STANDARDOUTPUT_H + +#include "object/outputstream.h" + +class StandardOutput : public OutputStream { + private: + StandardOutput(const StandardOutput ©); + + public: + StandardOutput () {} + void setup(); + + virtual void put(char c) override; +}; + +extern StandardOutput kout; + +#endif diff --git a/include/arch/tc1796-triboard/driver/uptime.h b/include/arch/tc1796-triboard/driver/uptime.h new file mode 100644 index 0000000..6f52f8f --- /dev/null +++ b/include/arch/tc1796-triboard/driver/uptime.h @@ -0,0 +1,32 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef UPTIME_H +#define UPTIME_H + +class Uptime { + private: + Uptime(const Uptime ©); +#ifdef TIMER_S + uint16_t seconds; +#endif + + public: +#ifdef TIMER_S + Uptime () : seconds(0) {} +#else + Uptime () {} +#endif + inline uint16_t get_us() { return 0; } + inline uint16_t get_cycles() { return 0; } +#ifdef TIMER_S + inline uint16_t get_s() { return seconds; } + inline void tick_s() { seconds++; } +#endif +}; + +extern Uptime uptime; + +#endif diff --git a/src/arch/infineon-tc1796-mock/Kconfig b/src/arch/infineon-tc1796-mock/Kconfig deleted file mode 100644 index 5efcbdc..0000000 --- a/src/arch/infineon-tc1796-mock/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2022 Daniel Friesel -# -# SPDX-License-Identifier: CC0-1.0 - -config arch_infineon_tc1796_mock_driver_counter -bool "Cycle Counter" -select meta_driver_counter diff --git a/src/arch/infineon-tc1796-mock/Makefile.inc b/src/arch/infineon-tc1796-mock/Makefile.inc deleted file mode 100644 index 7fcdd69..0000000 --- a/src/arch/infineon-tc1796-mock/Makefile.inc +++ /dev/null @@ -1,94 +0,0 @@ -# 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/infineon-tc1796-mock/arch.cc -CXX_TARGETS += src/arch/infineon-tc1796-mock/driver/gpio.cc -CXX_TARGETS += src/arch/infineon-tc1796-mock/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_infineon_tc1796_mock_driver_counter = y -endif - -ifdef CONFIG_arch_infineon_tc1796_mock_driver_counter - CXX_TARGETS += src/arch/infineon-tc1796-mock/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/infineon-tc1796-mock/arch.cc b/src/arch/infineon-tc1796-mock/arch.cc deleted file mode 100644 index 73ebd2d..0000000 --- a/src/arch/infineon-tc1796-mock/arch.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#include "arch.h" - -extern "C" { -#include -#include -#include -} - -#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/infineon-tc1796-mock/driver/counter.cc b/src/arch/infineon-tc1796-mock/driver/counter.cc deleted file mode 100644 index 0277d07..0000000 --- a/src/arch/infineon-tc1796-mock/driver/counter.cc +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#include "arch.h" -#include "driver/counter.h" - -Counter counter; diff --git a/src/arch/infineon-tc1796-mock/driver/gpio.cc b/src/arch/infineon-tc1796-mock/driver/gpio.cc deleted file mode 100644 index b66add2..0000000 --- a/src/arch/infineon-tc1796-mock/driver/gpio.cc +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#include "driver/gpio.h" - -GPIO gpio; diff --git a/src/arch/infineon-tc1796-mock/driver/stdout.cc b/src/arch/infineon-tc1796-mock/driver/stdout.cc deleted file mode 100644 index 499b2ab..0000000 --- a/src/arch/infineon-tc1796-mock/driver/stdout.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2022 Daniel Friesel - * - * SPDX-License-Identifier: BSD-2-Clause - */ -#include "driver/stdout.h" -#include -#include -#include - -#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/infineon-tc1796-mock/prompt b/src/arch/infineon-tc1796-mock/prompt deleted file mode 100644 index 19d4ab6..0000000 --- a/src/arch/infineon-tc1796-mock/prompt +++ /dev/null @@ -1 +0,0 @@ -Infineon TC1796 Mock (for Starter Kit) 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 +#include +#include +} + +#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 +#include +#include + +#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 -- cgit v1.2.3