Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:45

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2016 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifndef LIBBSP_ARM_ATSAM_SC16IS752_H
0029 #define LIBBSP_ARM_ATSAM_SC16IS752_H
0030 
0031 #include <rtems/irq-extension.h>
0032 #include <libchip/chip.h>
0033 
0034 #include <dev/serial/sc16is752.h>
0035 
0036 #ifdef __cplusplus
0037 extern "C" {
0038 #endif /* __cplusplus */
0039 
0040 /**
0041  * @brief The SC16IS752 device context.
0042  *
0043  * All members are private to the device driver.
0044  */
0045 typedef struct {
0046   sc16is752_spi_context base;
0047   Pin irq_pin;
0048   rtems_interrupt_server_entry irqs_entry;
0049   rtems_interrupt_server_action irqs_action;
0050   uint32_t irqs_index;
0051 } atsam_sc16is752_spi_context;
0052 
0053 /**
0054  * @brief The SC16IS752 device configuration.
0055  *
0056  * @see atsam_sc16is752_spi_create().
0057  */
0058 typedef struct {
0059   /**
0060    * @brief The device file path for the new device.
0061    */
0062   const char *device_path;
0063 
0064   /**
0065    * @brief The SC16IS752 mode.
0066    */
0067   sc16is752_mode mode;
0068 
0069   /**
0070    * @brief The input frequency in Hertz of the SC16IS752 chip.  See XTAL1 and
0071    * XTAL2 pins.
0072    */
0073   uint32_t input_frequency;
0074 
0075   /**
0076    * @brief The SPI bus device path.
0077    */
0078   const char *spi_path;
0079 
0080   /**
0081    * @brief The SPI chip select (starts with 0, the SPI driver uses
0082    * SPI_ChipSelect(1 << spi_chip_select)).
0083    */
0084   uint8_t spi_chip_select;
0085 
0086   /**
0087    * @brief The SPI bus speed in Hertz.
0088    */
0089   uint32_t spi_speed_hz;
0090 
0091   /**
0092    * @brief The interrupt pin, e.g. { PIO_PD28, PIOD, ID_PIOD, PIO_INPUT,
0093    * PIO_IT_LOW_LEVEL }.
0094    */
0095   const Pin irq_pin;
0096 
0097   /**
0098    * @brief The index to identify the interrupt server used for interrupt
0099    * processing.
0100    */
0101   uint32_t server_index;
0102 } atsam_sc16is752_spi_config;
0103 
0104 /**
0105  * @brief Creates an SPI connected SC16IS752 device.
0106  *
0107  * This devices uses the interrupt server, see rtems_interrupt_server_create().
0108  *
0109  * The device claims the interrupt of the PIO block.
0110  *
0111  * @param[out] ctx is the device context.  It may have an arbitrary content.
0112  * @param config is the device configuration.
0113  *
0114  * @return See sc16is752_spi_create().
0115  */
0116 int atsam_sc16is752_spi_create(
0117   atsam_sc16is752_spi_context      *ctx,
0118   const atsam_sc16is752_spi_config *config
0119 );
0120 
0121 #ifdef __cplusplus
0122 }
0123 #endif /* __cplusplus */
0124 
0125 #endif /* LIBBSP_ARM_ATSAM_SC16IS752_H */