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 l4_cap_idx_t irq) 30 : Tcu_channel(addr, channel, irq) 31 { 32 } 33 34 35 36 // Peripheral abstraction. 37 38 Tcu_jz4780_chip::Tcu_jz4780_chip(l4_addr_t start, l4_addr_t end) 39 : Tcu_chip(start, end) 40 { 41 } 42 43 Tcu_channel *Tcu_jz4780_chip::_get_channel(l4_addr_t addr, uint8_t channel, 44 l4_cap_idx_t irq) 45 { 46 return new Tcu_jz4780_channel(addr, channel, irq); 47 } 48 49 50 51 // C language interface functions. 52 53 void *jz4780_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end) 54 { 55 return (void *) new Tcu_jz4780_chip(tcu_base, tcu_base_end); 56 } 57 58 void *jz4780_tcu_get_channel(void *tcu, uint8_t channel, l4_cap_idx_t irq) 59 { 60 return static_cast<Tcu_jz4780_chip *>(tcu)->get_channel(channel, irq); 61 } 62 63 void jz4780_tcu_disable(void *tcu_channel) 64 { 65 static_cast<Tcu_jz4780_channel *>(tcu_channel)->disable(); 66 } 67 68 void jz4780_tcu_enable(void *tcu_channel) 69 { 70 static_cast<Tcu_jz4780_channel *>(tcu_channel)->enable(); 71 } 72 73 int jz4780_tcu_is_enabled(void *tcu_channel) 74 { 75 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->is_enabled(); 76 } 77 78 uint8_t jz4780_tcu_get_clock(void *tcu_channel) 79 { 80 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_clock(); 81 } 82 83 void jz4780_tcu_set_clock(void *tcu_channel, uint8_t clock) 84 { 85 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_clock(clock); 86 } 87 88 uint32_t jz4780_tcu_get_prescale(void *tcu_channel) 89 { 90 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_prescale(); 91 } 92 93 void jz4780_tcu_set_prescale(void *tcu_channel, uint32_t prescale) 94 { 95 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_prescale(prescale); 96 } 97 98 uint32_t jz4780_tcu_get_counter(void *tcu_channel) 99 { 100 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_counter(); 101 } 102 103 void jz4780_tcu_set_counter(void *tcu_channel, uint32_t value) 104 { 105 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_counter(value); 106 } 107 108 uint8_t jz4780_tcu_get_count_mode(void *tcu_channel) 109 { 110 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_count_mode(); 111 } 112 113 void jz4780_tcu_set_count_mode(void *tcu_channel, uint8_t mode) 114 { 115 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_count_mode(mode); 116 } 117 118 uint32_t jz4780_tcu_get_full_data_value(void *tcu_channel) 119 { 120 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_full_data_value(); 121 } 122 123 void jz4780_tcu_set_full_data_value(void *tcu_channel, uint32_t value) 124 { 125 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value); 126 } 127 128 uint32_t jz4780_tcu_get_half_data_value(void *tcu_channel) 129 { 130 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_half_data_value(); 131 } 132 133 void jz4780_tcu_set_half_data_value(void *tcu_channel, uint32_t value) 134 { 135 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_value(value); 136 } 137 138 int jz4780_tcu_get_full_data_mask(void *tcu_channel) 139 { 140 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_full_data_mask(); 141 } 142 143 void jz4780_tcu_set_full_data_mask(void *tcu_channel, int masked) 144 { 145 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_full_data_mask(masked); 146 } 147 148 int jz4780_tcu_get_half_data_mask(void *tcu_channel) 149 { 150 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->get_half_data_mask(); 151 } 152 153 void jz4780_tcu_set_half_data_mask(void *tcu_channel, int masked) 154 { 155 static_cast<Tcu_jz4780_channel *>(tcu_channel)->set_half_data_mask(masked); 156 } 157 158 int jz4780_tcu_have_interrupt(void *tcu_channel) 159 { 160 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->have_interrupt(); 161 } 162 163 int jz4780_tcu_wait_for_irq(void *tcu_channel, unsigned int timeout) 164 { 165 return static_cast<Tcu_jz4780_channel *>(tcu_channel)->wait_for_irq(timeout); 166 }