paul@250 | 1 | /* |
paul@250 | 2 | * TCU (timer/counter unit) support for the X1600. |
paul@250 | 3 | * |
paul@250 | 4 | * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> |
paul@250 | 5 | * |
paul@250 | 6 | * This program is free software; you can redistribute it and/or |
paul@250 | 7 | * modify it under the terms of the GNU General Public License as |
paul@250 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@250 | 9 | * the License, or (at your option) any later version. |
paul@250 | 10 | * |
paul@250 | 11 | * This program is distributed in the hope that it will be useful, |
paul@250 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@250 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@250 | 14 | * GNU General Public License for more details. |
paul@250 | 15 | * |
paul@250 | 16 | * You should have received a copy of the GNU General Public License |
paul@250 | 17 | * along with this program; if not, write to the Free Software |
paul@250 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@250 | 19 | * Boston, MA 02110-1301, USA |
paul@250 | 20 | */ |
paul@250 | 21 | |
paul@250 | 22 | #pragma once |
paul@250 | 23 | |
paul@250 | 24 | #include <l4/sys/types.h> |
paul@250 | 25 | #include <stdint.h> |
paul@250 | 26 | |
paul@250 | 27 | |
paul@250 | 28 | |
paul@250 | 29 | #ifdef __cplusplus |
paul@250 | 30 | |
paul@250 | 31 | #include <l4/devices/tcu-common.h> |
paul@250 | 32 | |
paul@250 | 33 | |
paul@250 | 34 | class Tcu_x1600_channel : public Tcu_channel |
paul@250 | 35 | { |
paul@250 | 36 | public: |
paul@252 | 37 | explicit Tcu_x1600_channel(l4_addr_t start, uint8_t channel, l4_cap_idx_t irq); |
paul@250 | 38 | |
paul@250 | 39 | void enable(); |
paul@250 | 40 | uint8_t get_count_mode(); |
paul@250 | 41 | void set_count_mode(uint8_t mode); |
paul@250 | 42 | }; |
paul@250 | 43 | |
paul@250 | 44 | |
paul@250 | 45 | class Tcu_x1600_chip : public Tcu_chip |
paul@250 | 46 | { |
paul@250 | 47 | protected: |
paul@250 | 48 | unsigned int num_channels() |
paul@250 | 49 | { return 8; } |
paul@250 | 50 | |
paul@252 | 51 | Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel, l4_cap_idx_t irq); |
paul@250 | 52 | |
paul@250 | 53 | public: |
paul@250 | 54 | explicit Tcu_x1600_chip(l4_addr_t start, l4_addr_t end); |
paul@250 | 55 | }; |
paul@250 | 56 | |
paul@250 | 57 | #endif /* __cplusplus */ |
paul@250 | 58 | |
paul@250 | 59 | |
paul@250 | 60 | |
paul@250 | 61 | /* C language interface. */ |
paul@250 | 62 | |
paul@250 | 63 | EXTERN_C_BEGIN |
paul@250 | 64 | |
paul@250 | 65 | void *x1600_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end); |
paul@250 | 66 | |
paul@252 | 67 | void *x1600_tcu_get_channel(void *tcu, uint8_t channel, l4_cap_idx_t irq); |
paul@250 | 68 | |
paul@250 | 69 | void x1600_tcu_disable(void *tcu_channel); |
paul@250 | 70 | |
paul@250 | 71 | void x1600_tcu_enable(void *tcu_channel); |
paul@250 | 72 | |
paul@250 | 73 | int x1600_tcu_is_enabled(void *tcu_channel); |
paul@250 | 74 | |
paul@250 | 75 | uint8_t x1600_tcu_get_clock(void *tcu_channel); |
paul@250 | 76 | |
paul@250 | 77 | void x1600_tcu_set_clock(void *tcu_channel, uint8_t clock); |
paul@250 | 78 | |
paul@250 | 79 | uint32_t x1600_tcu_get_prescale(void *tcu_channel); |
paul@250 | 80 | |
paul@250 | 81 | void x1600_tcu_set_prescale(void *tcu_channel, uint32_t prescale); |
paul@250 | 82 | |
paul@250 | 83 | uint32_t x1600_tcu_get_counter(void *tcu_channel); |
paul@250 | 84 | |
paul@250 | 85 | void x1600_tcu_set_counter(void *tcu_channel, uint32_t value); |
paul@250 | 86 | |
paul@250 | 87 | uint8_t x1600_tcu_get_count_mode(void *tcu_channel); |
paul@250 | 88 | |
paul@250 | 89 | void x1600_tcu_set_count_mode(void *tcu_channel, uint8_t mode); |
paul@250 | 90 | |
paul@250 | 91 | uint32_t x1600_tcu_get_full_data_value(void *tcu_channel); |
paul@250 | 92 | |
paul@250 | 93 | void x1600_tcu_set_full_data_value(void *tcu_channel, uint32_t value); |
paul@250 | 94 | |
paul@250 | 95 | uint32_t x1600_tcu_get_half_data_value(void *tcu_channel); |
paul@250 | 96 | |
paul@250 | 97 | void x1600_tcu_set_half_data_value(void *tcu_channel, uint32_t value); |
paul@250 | 98 | |
paul@252 | 99 | int x1600_tcu_get_full_data_mask(void *tcu_channel); |
paul@252 | 100 | |
paul@252 | 101 | void x1600_tcu_set_full_data_mask(void *tcu_channel, int masked); |
paul@252 | 102 | |
paul@252 | 103 | int x1600_tcu_get_half_data_mask(void *tcu_channel); |
paul@252 | 104 | |
paul@252 | 105 | void x1600_tcu_set_half_data_mask(void *tcu_channel, int masked); |
paul@252 | 106 | |
paul@252 | 107 | int x1600_tcu_have_interrupt(void *tcu_channel); |
paul@252 | 108 | |
paul@252 | 109 | int x1600_tcu_wait_for_irq(void *tcu_channel, unsigned int timeout); |
paul@252 | 110 | |
paul@250 | 111 | EXTERN_C_END |