Commit e2d191eb authored by Daniel Friesel's avatar Daniel Friesel
Browse files

tc1796: it's working!

parent 68f92431
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -6,23 +6,33 @@
#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 &copy);
		unsigned long long startvalue, stopvalue;

	public:
		counter_value_t value;
		volatile counter_overflow_t overflow;
		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;
		}
};

+4 −0
Original line number Diff line number Diff line
# Copyright 2022 Daniel Friesel
#
# SPDX-License-Identifier: CC0-1.0

config arch_infineon_tc1796_mock_driver_counter
bool "Cycle Counter"
select meta_driver_counter
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@
CPU = tc1796

cpu_freq ?= 150000000
counter_freq ?= 75000000
uart_freq ?= 115200
SERIAL_PORT ?= ttyUSB0
QEMU_PORT ?= 12345

@@ -81,6 +83,7 @@ arch_help:

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
+8 −14
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ extern "C" {
#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)
{
	/*
@@ -30,17 +33,13 @@ void Arch::setup(void)
	 */
	unlock_wdtcon();
	(*(unsigned int*)0xf0000040) = (29 << OF_NDIV) | (0 << OF_PDIV) | (3 << OF_KDIV) | (2 << OF_VCOSEL);
	//PMI_CON0.bits.CCBYP = 0;
	STM_CLC = 0x00000100;
	lock_wdtcon();
}

#ifdef CONFIG_wakeup
extern void wakeup();
#endif

#if defined(CONFIG_loop)
extern void loop();
volatile char run_loop = 0;
unsigned int old_tim5 = 0;
#endif

volatile bool sleep_done = false;
@@ -71,22 +70,17 @@ void Arch::idle_loop(void)
{
	while (1) {
#if defined(CONFIG_loop)
		if (run_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();
			run_loop = 0;
		}
#endif
#ifdef CONFIG_wakeup
		wakeup();
#endif
	}
}

void Arch::idle(void)
{
#ifdef CONFIG_wakeup
	wakeup();
#endif
}

Arch arch;
+0 −1
Original line number Diff line number Diff line
@@ -5,6 +5,5 @@
 */
#include "arch.h"
#include "driver/counter.h"
#include "driver/gpio.h"

Counter counter;
Loading