this is testing

Committer:
pmallick
Date:
Thu Jan 14 18:54:16 2021 +0530
Revision:
0:3afcd581558d
this is testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmallick 0:3afcd581558d 1 /***************************************************************************//**
pmallick 0:3afcd581558d 2 * @file spi.h
pmallick 0:3afcd581558d 3 * @brief Header file of SPI Interface
pmallick 0:3afcd581558d 4 * @author DBogdan (dragos.bogdan@analog.com)
pmallick 0:3afcd581558d 5 ********************************************************************************
pmallick 0:3afcd581558d 6 * Copyright 2019(c) Analog Devices, Inc.
pmallick 0:3afcd581558d 7 *
pmallick 0:3afcd581558d 8 * All rights reserved.
pmallick 0:3afcd581558d 9 *
pmallick 0:3afcd581558d 10 * Redistribution and use in source and binary forms, with or without
pmallick 0:3afcd581558d 11 * modification, are permitted provided that the following conditions are met:
pmallick 0:3afcd581558d 12 * - Redistributions of source code must retain the above copyright
pmallick 0:3afcd581558d 13 * notice, this list of conditions and the following disclaimer.
pmallick 0:3afcd581558d 14 * - Redistributions in binary form must reproduce the above copyright
pmallick 0:3afcd581558d 15 * notice, this list of conditions and the following disclaimer in
pmallick 0:3afcd581558d 16 * the documentation and/or other materials provided with the
pmallick 0:3afcd581558d 17 * distribution.
pmallick 0:3afcd581558d 18 * - Neither the name of Analog Devices, Inc. nor the names of its
pmallick 0:3afcd581558d 19 * contributors may be used to endorse or promote products derived
pmallick 0:3afcd581558d 20 * from this software without specific prior written permission.
pmallick 0:3afcd581558d 21 * - The use of this software may or may not infringe the patent rights
pmallick 0:3afcd581558d 22 * of one or more patent holders. This license does not release you
pmallick 0:3afcd581558d 23 * from the requirement that you obtain separate licenses from these
pmallick 0:3afcd581558d 24 * patent holders to use this software.
pmallick 0:3afcd581558d 25 * - Use of the software either in source or binary form, must be run
pmallick 0:3afcd581558d 26 * on or directly connected to an Analog Devices Inc. component.
pmallick 0:3afcd581558d 27 *
pmallick 0:3afcd581558d 28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
pmallick 0:3afcd581558d 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
pmallick 0:3afcd581558d 30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
pmallick 0:3afcd581558d 31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
pmallick 0:3afcd581558d 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
pmallick 0:3afcd581558d 33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
pmallick 0:3afcd581558d 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
pmallick 0:3afcd581558d 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
pmallick 0:3afcd581558d 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
pmallick 0:3afcd581558d 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pmallick 0:3afcd581558d 38 *******************************************************************************/
pmallick 0:3afcd581558d 39
pmallick 0:3afcd581558d 40 #ifndef SPI_H_
pmallick 0:3afcd581558d 41 #define SPI_H_
pmallick 0:3afcd581558d 42
pmallick 0:3afcd581558d 43 /******************************************************************************/
pmallick 0:3afcd581558d 44 /***************************** Include Files **********************************/
pmallick 0:3afcd581558d 45 /******************************************************************************/
pmallick 0:3afcd581558d 46
pmallick 0:3afcd581558d 47 #include <stdint.h>
pmallick 0:3afcd581558d 48
pmallick 0:3afcd581558d 49 /******************************************************************************/
pmallick 0:3afcd581558d 50 /********************** Macros and Constants Definitions **********************/
pmallick 0:3afcd581558d 51 /******************************************************************************/
pmallick 0:3afcd581558d 52
pmallick 0:3afcd581558d 53 #define SPI_CPHA 0x01
pmallick 0:3afcd581558d 54 #define SPI_CPOL 0x02
pmallick 0:3afcd581558d 55
pmallick 0:3afcd581558d 56 /******************************************************************************/
pmallick 0:3afcd581558d 57 /*************************** Types Declarations *******************************/
pmallick 0:3afcd581558d 58 /******************************************************************************/
pmallick 0:3afcd581558d 59
pmallick 0:3afcd581558d 60 /**
pmallick 0:3afcd581558d 61 * @enum spi_mode
pmallick 0:3afcd581558d 62 * @brief SPI configuration for clock phase and polarity.
pmallick 0:3afcd581558d 63 */
pmallick 0:3afcd581558d 64 typedef enum spi_mode {
pmallick 0:3afcd581558d 65 /** Data on rising, shift out on falling */
pmallick 0:3afcd581558d 66 SPI_MODE_0 = (0 | 0),
pmallick 0:3afcd581558d 67 /** Data on falling, shift out on rising */
pmallick 0:3afcd581558d 68 SPI_MODE_1 = (0 | SPI_CPHA),
pmallick 0:3afcd581558d 69 /** Data on falling, shift out on rising */
pmallick 0:3afcd581558d 70 SPI_MODE_2 = (SPI_CPOL | 0),
pmallick 0:3afcd581558d 71 /** Data on rising, shift out on falling */
pmallick 0:3afcd581558d 72 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
pmallick 0:3afcd581558d 73 } spi_mode;
pmallick 0:3afcd581558d 74
pmallick 0:3afcd581558d 75 /**
pmallick 0:3afcd581558d 76 * @struct spi_platform_ops
pmallick 0:3afcd581558d 77 * @brief Structure holding SPI function pointers that point to the platform
pmallick 0:3afcd581558d 78 * specific function
pmallick 0:3afcd581558d 79 */
pmallick 0:3afcd581558d 80 struct spi_platform_ops ;
pmallick 0:3afcd581558d 81
pmallick 0:3afcd581558d 82 /**
pmallick 0:3afcd581558d 83 * @struct spi_init_param
pmallick 0:3afcd581558d 84 * @brief Structure holding the parameters for SPI initialization
pmallick 0:3afcd581558d 85 */
pmallick 0:3afcd581558d 86 typedef struct spi_init_param {
pmallick 0:3afcd581558d 87 /** maximum transfer speed */
pmallick 0:3afcd581558d 88 uint32_t max_speed_hz;
pmallick 0:3afcd581558d 89 /** SPI chip select */
pmallick 0:3afcd581558d 90 uint8_t chip_select;
pmallick 0:3afcd581558d 91 /** SPI mode */
pmallick 0:3afcd581558d 92 enum spi_mode mode;
pmallick 0:3afcd581558d 93 const struct spi_platform_ops *platform_ops;
pmallick 0:3afcd581558d 94 /** SPI extra parameters (device specific) */
pmallick 0:3afcd581558d 95 void *extra;
pmallick 0:3afcd581558d 96 } spi_init_param;
pmallick 0:3afcd581558d 97
pmallick 0:3afcd581558d 98 /**
pmallick 0:3afcd581558d 99 * @struct spi_desc
pmallick 0:3afcd581558d 100 * @brief Structure holding SPI descriptor.
pmallick 0:3afcd581558d 101 */
pmallick 0:3afcd581558d 102 typedef struct spi_desc {
pmallick 0:3afcd581558d 103 /** maximum transfer speed */
pmallick 0:3afcd581558d 104 uint32_t max_speed_hz;
pmallick 0:3afcd581558d 105 /** SPI chip select */
pmallick 0:3afcd581558d 106 uint8_t chip_select;
pmallick 0:3afcd581558d 107 /** SPI mode */
pmallick 0:3afcd581558d 108 enum spi_mode mode;
pmallick 0:3afcd581558d 109 const struct spi_platform_ops *platform_ops;
pmallick 0:3afcd581558d 110 /** SPI extra parameters (device specific) */
pmallick 0:3afcd581558d 111 void *extra;
pmallick 0:3afcd581558d 112 } spi_desc;
pmallick 0:3afcd581558d 113
pmallick 0:3afcd581558d 114 /**
pmallick 0:3afcd581558d 115 * @struct spi_platform_ops
pmallick 0:3afcd581558d 116 * @brief Structure holding SPI function pointers that point to the platform
pmallick 0:3afcd581558d 117 * specific function
pmallick 0:3afcd581558d 118 */
pmallick 0:3afcd581558d 119 struct spi_platform_ops {
pmallick 0:3afcd581558d 120 /** SPI initialization function pointer */
pmallick 0:3afcd581558d 121 int32_t (*spi_ops_init)(struct spi_desc **, const struct spi_init_param *);
pmallick 0:3afcd581558d 122 /** SPI write/read function pointer */
pmallick 0:3afcd581558d 123 int32_t (*spi_ops_write_and_read)(struct spi_desc *, uint8_t *, uint16_t);
pmallick 0:3afcd581558d 124 /** SPI remove function pointer */
pmallick 0:3afcd581558d 125 int32_t (*spi_ops_remove)(struct spi_desc *);
pmallick 0:3afcd581558d 126 };
pmallick 0:3afcd581558d 127
pmallick 0:3afcd581558d 128 /******************************************************************************/
pmallick 0:3afcd581558d 129 /************************ Functions Declarations ******************************/
pmallick 0:3afcd581558d 130 /******************************************************************************/
pmallick 0:3afcd581558d 131
pmallick 0:3afcd581558d 132 /* Initialize the SPI communication peripheral. */
pmallick 0:3afcd581558d 133 int32_t spi_init(struct spi_desc **desc,
pmallick 0:3afcd581558d 134 const struct spi_init_param *param);
pmallick 0:3afcd581558d 135
pmallick 0:3afcd581558d 136 /* Free the resources allocated by spi_init(). */
pmallick 0:3afcd581558d 137 int32_t spi_remove(struct spi_desc *desc);
pmallick 0:3afcd581558d 138
pmallick 0:3afcd581558d 139 /* Write and read data to/from SPI. */
pmallick 0:3afcd581558d 140 int32_t spi_write_and_read(struct spi_desc *desc,
pmallick 0:3afcd581558d 141 uint8_t *data,
pmallick 0:3afcd581558d 142 uint16_t bytes_number);
pmallick 0:3afcd581558d 143
pmallick 0:3afcd581558d 144 #endif // SPI_H_