1 /* 2 * TCU (timer/counter unit) support for the X1600. 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 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/tcu-common.h> 32 33 34 class Tcu_x1600_channel : public Tcu_channel 35 { 36 public: 37 explicit Tcu_x1600_channel(l4_addr_t start, uint8_t channel, l4_cap_idx_t irq); 38 39 void enable(); 40 uint8_t get_count_mode(); 41 void set_count_mode(uint8_t mode); 42 }; 43 44 45 class Tcu_x1600_chip : public Tcu_chip 46 { 47 protected: 48 unsigned int num_channels() 49 { return 8; } 50 51 Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel, l4_cap_idx_t irq); 52 53 public: 54 explicit Tcu_x1600_chip(l4_addr_t start, l4_addr_t end); 55 }; 56 57 #endif /* __cplusplus */ 58 59 60 61 /* C language interface. */ 62 63 EXTERN_C_BEGIN 64 65 void *x1600_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end); 66 67 void *x1600_tcu_get_channel(void *tcu, uint8_t channel, l4_cap_idx_t irq); 68 69 void x1600_tcu_disable(void *tcu_channel); 70 71 void x1600_tcu_enable(void *tcu_channel); 72 73 int x1600_tcu_is_enabled(void *tcu_channel); 74 75 uint8_t x1600_tcu_get_clock(void *tcu_channel); 76 77 void x1600_tcu_set_clock(void *tcu_channel, uint8_t clock); 78 79 uint32_t x1600_tcu_get_prescale(void *tcu_channel); 80 81 void x1600_tcu_set_prescale(void *tcu_channel, uint32_t prescale); 82 83 uint32_t x1600_tcu_get_counter(void *tcu_channel); 84 85 void x1600_tcu_set_counter(void *tcu_channel, uint32_t value); 86 87 uint8_t x1600_tcu_get_count_mode(void *tcu_channel); 88 89 void x1600_tcu_set_count_mode(void *tcu_channel, uint8_t mode); 90 91 uint32_t x1600_tcu_get_full_data_value(void *tcu_channel); 92 93 void x1600_tcu_set_full_data_value(void *tcu_channel, uint32_t value); 94 95 uint32_t x1600_tcu_get_half_data_value(void *tcu_channel); 96 97 void x1600_tcu_set_half_data_value(void *tcu_channel, uint32_t value); 98 99 int x1600_tcu_get_full_data_mask(void *tcu_channel); 100 101 void x1600_tcu_set_full_data_mask(void *tcu_channel, int masked); 102 103 int x1600_tcu_get_half_data_mask(void *tcu_channel); 104 105 void x1600_tcu_set_half_data_mask(void *tcu_channel, int masked); 106 107 int x1600_tcu_have_interrupt(void *tcu_channel); 108 109 int x1600_tcu_wait_for_irq(void *tcu_channel, unsigned int timeout); 110 111 EXTERN_C_END