1 /* 2 * Timer/counter unit support for the JZ4780. 3 * 4 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "tcu-jz4780.h" 23 24 25 26 // Channel abstraction. 27 28 Tcu_jz4780_channel::Tcu_jz4780_channel(l4_addr_t addr, uint8_t channel) 29 : Tcu_channel(addr, channel) 30 { 31 } 32 33 34 35 // Peripheral abstraction. 36 37 Tcu_jz4780_chip::Tcu_jz4780_chip(l4_addr_t start, l4_addr_t end) 38 : Tcu_chip(start, end) 39 { 40 } 41 42 Tcu_channel *Tcu_jz4780_chip::_get_channel(l4_addr_t addr, uint8_t channel) 43 { 44 return new Tcu_jz4780_channel(addr, channel); 45 } 46 47 48 49 // C language interface functions. 50 51 void *jz4780_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end) 52 { 53 return (void *) new Tcu_jz4780_chip(tcu_base, tcu_base_end); 54 } 55 56 void *jz4780_tcu_get_channel(void *tcu, uint8_t channel) 57 { 58 return static_cast<Tcu_jz4780_chip *>(tcu)->get_channel(channel); 59 } 60 61 void jz4780_tcu_disable(void *tcu_channel) 62 { 63 static_cast<Tcu_jz4780_channel *>(tcu_channel)->disable(); 64 } 65 66 void jz4780_tcu_enable(void *tcu_channel) 67 { 68 static_cast<Tcu_jz4780_channel *>(tcu_channel)->enable(); 69 } 70 71 int jz4780_tcu_is_enabled(void *tcu_channel) 72 { 73 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->is_enabled(); 74 } 75 76 uint8_t jz4780_tcu_get_clock(void *tcu_channel) 77 { 78 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_clock(); 79 } 80 81 void jz4780_tcu_set_clock(void *tcu_channel, uint8_t clock) 82 { 83 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_clock(clock); 84 } 85 86 uint32_t jz4780_tcu_get_prescale(void *tcu_channel) 87 { 88 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_prescale(); 89 } 90 91 void jz4780_tcu_set_prescale(void *tcu_channel, uint32_t prescale) 92 { 93 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_prescale(prescale); 94 } 95 96 uint32_t jz4780_tcu_get_counter(void *tcu_channel) 97 { 98 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_counter(); 99 } 100 101 void jz4780_tcu_set_counter(void *tcu_channel, uint32_t value) 102 { 103 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_counter(value); 104 } 105 106 uint8_t jz4780_tcu_get_count_mode(void *tcu_channel) 107 { 108 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_count_mode(); 109 } 110 111 void jz4780_tcu_set_count_mode(void *tcu_channel, uint8_t mode) 112 { 113 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_count_mode(mode); 114 } 115 116 uint32_t jz4780_tcu_get_full_data_value(void *tcu_channel) 117 { 118 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_full_data_value(); 119 } 120 121 void jz4780_tcu_set_full_data_value(void *tcu_channel, uint32_t value) 122 { 123 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value); 124 } 125 126 uint32_t jz4780_tcu_get_half_data_value(void *tcu_channel) 127 { 128 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_half_data_value(); 129 } 130 131 void jz4780_tcu_set_half_data_value(void *tcu_channel, uint32_t value) 132 { 133 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value); 134 }