diff options
Diffstat (limited to 'include/arch/tc1796-triboard/driver')
-rw-r--r-- | include/arch/tc1796-triboard/driver/counter.h | 41 | ||||
-rw-r--r-- | include/arch/tc1796-triboard/driver/gpio.h | 53 | ||||
-rw-r--r-- | include/arch/tc1796-triboard/driver/stdout.h | 24 | ||||
-rw-r--r-- | include/arch/tc1796-triboard/driver/uptime.h | 32 |
4 files changed, 150 insertions, 0 deletions
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 |