1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/tcu/src/jz4780.cc Thu Feb 01 01:16:04 2024 +0100
1.3 @@ -0,0 +1,134 @@
1.4 +/*
1.5 + * Timer/counter unit support for the JZ4780.
1.6 + *
1.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include "tcu-jz4780.h"
1.26 +
1.27 +
1.28 +
1.29 +// Channel abstraction.
1.30 +
1.31 +Tcu_jz4780_channel::Tcu_jz4780_channel(l4_addr_t addr, uint8_t channel)
1.32 +: Tcu_channel(addr, channel)
1.33 +{
1.34 +}
1.35 +
1.36 +
1.37 +
1.38 +// Peripheral abstraction.
1.39 +
1.40 +Tcu_jz4780_chip::Tcu_jz4780_chip(l4_addr_t start, l4_addr_t end)
1.41 +: Tcu_chip(start, end)
1.42 +{
1.43 +}
1.44 +
1.45 +Tcu_channel *Tcu_jz4780_chip::_get_channel(l4_addr_t addr, uint8_t channel)
1.46 +{
1.47 + return new Tcu_jz4780_channel(addr, channel);
1.48 +}
1.49 +
1.50 +
1.51 +
1.52 +// C language interface functions.
1.53 +
1.54 +void *jz4780_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end)
1.55 +{
1.56 + return (void *) new Tcu_jz4780_chip(tcu_base, tcu_base_end);
1.57 +}
1.58 +
1.59 +void *jz4780_tcu_get_channel(void *tcu, uint8_t channel)
1.60 +{
1.61 + return static_cast<Tcu_jz4780_chip *>(tcu)->get_channel(channel);
1.62 +}
1.63 +
1.64 +void jz4780_tcu_disable(void *tcu_channel)
1.65 +{
1.66 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->disable();
1.67 +}
1.68 +
1.69 +void jz4780_tcu_enable(void *tcu_channel)
1.70 +{
1.71 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->enable();
1.72 +}
1.73 +
1.74 +int jz4780_tcu_is_enabled(void *tcu_channel)
1.75 +{
1.76 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->is_enabled();
1.77 +}
1.78 +
1.79 +uint8_t jz4780_tcu_get_clock(void *tcu_channel)
1.80 +{
1.81 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_clock();
1.82 +}
1.83 +
1.84 +void jz4780_tcu_set_clock(void *tcu_channel, uint8_t clock)
1.85 +{
1.86 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_clock(clock);
1.87 +}
1.88 +
1.89 +uint32_t jz4780_tcu_get_prescale(void *tcu_channel)
1.90 +{
1.91 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_prescale();
1.92 +}
1.93 +
1.94 +void jz4780_tcu_set_prescale(void *tcu_channel, uint32_t prescale)
1.95 +{
1.96 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_prescale(prescale);
1.97 +}
1.98 +
1.99 +uint32_t jz4780_tcu_get_counter(void *tcu_channel)
1.100 +{
1.101 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_counter();
1.102 +}
1.103 +
1.104 +void jz4780_tcu_set_counter(void *tcu_channel, uint32_t value)
1.105 +{
1.106 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_counter(value);
1.107 +}
1.108 +
1.109 +uint8_t jz4780_tcu_get_count_mode(void *tcu_channel)
1.110 +{
1.111 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_count_mode();
1.112 +}
1.113 +
1.114 +void jz4780_tcu_set_count_mode(void *tcu_channel, uint8_t mode)
1.115 +{
1.116 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_count_mode(mode);
1.117 +}
1.118 +
1.119 +uint32_t jz4780_tcu_get_full_data_value(void *tcu_channel)
1.120 +{
1.121 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_full_data_value();
1.122 +}
1.123 +
1.124 +void jz4780_tcu_set_full_data_value(void *tcu_channel, uint32_t value)
1.125 +{
1.126 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value);
1.127 +}
1.128 +
1.129 +uint32_t jz4780_tcu_get_half_data_value(void *tcu_channel)
1.130 +{
1.131 + return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_half_data_value();
1.132 +}
1.133 +
1.134 +void jz4780_tcu_set_half_data_value(void *tcu_channel, uint32_t value)
1.135 +{
1.136 + static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value);
1.137 +}