paul@222 | 1 | /* |
paul@222 | 2 | * Common SPI abstractions. |
paul@222 | 3 | * |
paul@222 | 4 | * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> |
paul@222 | 5 | * |
paul@222 | 6 | * This program is free software; you can redistribute it and/or |
paul@222 | 7 | * modify it under the terms of the GNU General Public License as |
paul@222 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@222 | 9 | * the License, or (at your option) any later version. |
paul@222 | 10 | * |
paul@222 | 11 | * This program is distributed in the hope that it will be useful, |
paul@222 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@222 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@222 | 14 | * GNU General Public License for more details. |
paul@222 | 15 | * |
paul@222 | 16 | * You should have received a copy of the GNU General Public License |
paul@222 | 17 | * along with this program; if not, write to the Free Software |
paul@222 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@222 | 19 | * Boston, MA 02110-1301, USA |
paul@222 | 20 | */ |
paul@222 | 21 | |
paul@222 | 22 | #pragma once |
paul@222 | 23 | |
paul@236 | 24 | |
paul@236 | 25 | |
paul@222 | 26 | #ifdef __cplusplus |
paul@222 | 27 | |
paul@236 | 28 | #include <l4/re/c/dma_space.h> |
paul@222 | 29 | #include <stdint.h> |
paul@222 | 30 | |
paul@222 | 31 | /* SPI channel abstractions. */ |
paul@222 | 32 | |
paul@307 | 33 | class Spi_control_base |
paul@307 | 34 | { |
paul@307 | 35 | public: |
paul@307 | 36 | virtual void acquire_control(bool asserted) = 0; |
paul@307 | 37 | |
paul@307 | 38 | virtual void release_control() = 0; |
paul@307 | 39 | }; |
paul@307 | 40 | |
paul@222 | 41 | class Spi_channel_base |
paul@222 | 42 | { |
paul@307 | 43 | protected: |
paul@307 | 44 | Spi_control_base *_control = NULL; |
paul@307 | 45 | |
paul@222 | 46 | public: |
paul@307 | 47 | void set_control(Spi_control_base *control) |
paul@307 | 48 | { _control = control; } |
paul@307 | 49 | |
paul@222 | 50 | virtual uint32_t send(uint32_t bytes, const uint8_t data[]) = 0; |
paul@222 | 51 | |
paul@222 | 52 | virtual uint32_t send_dc(uint32_t bytes, const uint8_t data[], |
paul@236 | 53 | const int dc[], uint8_t char_size, |
paul@236 | 54 | bool big_endian) = 0; |
paul@222 | 55 | |
paul@222 | 56 | virtual uint32_t send_units(uint32_t bytes, const uint8_t data[], |
paul@236 | 57 | uint8_t unit_size, uint8_t char_size, |
paul@236 | 58 | bool big_endian) = 0; |
paul@236 | 59 | |
paul@236 | 60 | virtual uint32_t transfer(l4_addr_t vaddr, l4re_dma_space_dma_addr_t paddr, |
paul@236 | 61 | uint32_t count, uint8_t unit_size, uint8_t char_size, |
paul@236 | 62 | l4_addr_t desc_vaddr = 0, |
paul@236 | 63 | l4re_dma_space_dma_addr_t desc_paddr = 0) = 0; |
paul@222 | 64 | }; |
paul@222 | 65 | |
paul@222 | 66 | #endif /* __cplusplus */ |