paul@250 | 1 | /* |
paul@250 | 2 | * TCU (timer/counter unit) support for the JZ4780. |
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_jz4780_channel : public Tcu_channel |
paul@250 | 35 | { |
paul@250 | 36 | public: |
paul@250 | 37 | explicit Tcu_jz4780_channel(l4_addr_t start, uint8_t channel); |
paul@250 | 38 | }; |
paul@250 | 39 | |
paul@250 | 40 | |
paul@250 | 41 | class Tcu_jz4780_chip : public Tcu_chip |
paul@250 | 42 | { |
paul@250 | 43 | protected: |
paul@250 | 44 | unsigned int num_channels() |
paul@250 | 45 | { return 8; } |
paul@250 | 46 | |
paul@250 | 47 | Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel); |
paul@250 | 48 | |
paul@250 | 49 | public: |
paul@250 | 50 | explicit Tcu_jz4780_chip(l4_addr_t start, l4_addr_t end); |
paul@250 | 51 | }; |
paul@250 | 52 | |
paul@250 | 53 | #endif /* __cplusplus */ |
paul@250 | 54 | |
paul@250 | 55 | |
paul@250 | 56 | |
paul@250 | 57 | /* C language interface. */ |
paul@250 | 58 | |
paul@250 | 59 | EXTERN_C_BEGIN |
paul@250 | 60 | |
paul@250 | 61 | void *jz4780_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end); |
paul@250 | 62 | |
paul@250 | 63 | void *jz4780_tcu_get_channel(void *tcu, uint8_t channel); |
paul@250 | 64 | |
paul@250 | 65 | void jz4780_tcu_disable(void *tcu_channel); |
paul@250 | 66 | |
paul@250 | 67 | void jz4780_tcu_enable(void *tcu_channel); |
paul@250 | 68 | |
paul@250 | 69 | int jz4780_tcu_is_enabled(void *tcu_channel); |
paul@250 | 70 | |
paul@250 | 71 | uint8_t jz4780_tcu_get_clock(void *tcu_channel); |
paul@250 | 72 | |
paul@250 | 73 | void jz4780_tcu_set_clock(void *tcu_channel, uint8_t clock); |
paul@250 | 74 | |
paul@250 | 75 | uint32_t jz4780_tcu_get_prescale(void *tcu_channel); |
paul@250 | 76 | |
paul@250 | 77 | void jz4780_tcu_set_prescale(void *tcu_channel, uint32_t prescale); |
paul@250 | 78 | |
paul@250 | 79 | uint32_t jz4780_tcu_get_counter(void *tcu_channel); |
paul@250 | 80 | |
paul@250 | 81 | void jz4780_tcu_set_counter(void *tcu_channel, uint32_t value); |
paul@250 | 82 | |
paul@250 | 83 | uint8_t jz4780_tcu_get_count_mode(void *tcu_channel); |
paul@250 | 84 | |
paul@250 | 85 | void jz4780_tcu_set_count_mode(void *tcu_channel, uint8_t mode); |
paul@250 | 86 | |
paul@250 | 87 | uint32_t jz4780_tcu_get_full_data_value(void *tcu_channel); |
paul@250 | 88 | |
paul@250 | 89 | void jz4780_tcu_set_full_data_value(void *tcu_channel, uint32_t value); |
paul@250 | 90 | |
paul@250 | 91 | uint32_t jz4780_tcu_get_half_data_value(void *tcu_channel); |
paul@250 | 92 | |
paul@250 | 93 | void jz4780_tcu_set_half_data_value(void *tcu_channel, uint32_t value); |
paul@250 | 94 | |
paul@250 | 95 | EXTERN_C_END |