Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:43

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * SPI driver for spi memory devices
0005  */
0006 
0007 /*
0008  * Copyright (c) 2008 embedded brains GmbH & Co. KG
0009  *
0010  * Redistribution and use in source and binary forms, with or without
0011  * modification, are permitted provided that the following conditions
0012  * are met:
0013  * 1. Redistributions of source code must retain the above copyright
0014  *    notice, this list of conditions and the following disclaimer.
0015  * 2. Redistributions in binary form must reproduce the above copyright
0016  *    notice, this list of conditions and the following disclaimer in the
0017  *    documentation and/or other materials provided with the distribution.
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0029  * POSSIBILITY OF SUCH DAMAGE.
0030  */
0031 
0032 #ifndef _LIBCHIP_SPI_MEMDRV_H
0033 #define _LIBCHIP_SPI_MEMDRV_H
0034 
0035 #include <rtems/libi2c.h>
0036 
0037 #ifdef __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*=========================================================================*\
0042 | Function:                                                                 |
0043 \*-------------------------------------------------------------------------*/
0044 rtems_status_code spi_memdrv_write
0045 (
0046 /*-------------------------------------------------------------------------*\
0047 | Purpose:                                                                  |
0048 |   write a block of data to memory                                         |
0049 +---------------------------------------------------------------------------+
0050 | Input Parameters:                                                         |
0051 \*-------------------------------------------------------------------------*/
0052  rtems_device_major_number major,        /* major device number            */
0053  rtems_device_major_number minor,        /* minor device number            */
0054  void                      *arg          /* ptr to write argument struct   */
0055  );
0056 /*-------------------------------------------------------------------------*\
0057 | Return Value:                                                             |
0058 |    o = ok or error code                                                   |
0059 \*=========================================================================*/
0060 
0061 /*=========================================================================*\
0062 | Function:                                                                 |
0063 \*-------------------------------------------------------------------------*/
0064 rtems_status_code spi_memdrv_read
0065 (
0066 /*-------------------------------------------------------------------------*\
0067 | Purpose:                                                                  |
0068 |   read a block of data from memory                                        |
0069 +---------------------------------------------------------------------------+
0070 | Input Parameters:                                                         |
0071 \*-------------------------------------------------------------------------*/
0072  rtems_device_major_number major,        /* major device number            */
0073  rtems_device_major_number minor,        /* minor device number            */
0074  void                      *arg          /* ptr to read argument struct    */
0075  );
0076 /*-------------------------------------------------------------------------*\
0077 | Return Value:                                                             |
0078 |    o = ok or error code                                                   |
0079 \*=========================================================================*/
0080 
0081   typedef struct {
0082     uint32_t baudrate;           /* tfr rate, bits per second     */
0083     bool     erase_before_program;
0084     uint32_t empty_state;        /* value of erased cells         */
0085     uint32_t page_size;          /* programming page size in byte */
0086     uint32_t sector_size;        /* erase sector size in byte     */
0087     uint32_t mem_size;           /* total capacity in byte        */
0088   } spi_memdrv_param_t;
0089 
0090   typedef struct {
0091     rtems_libi2c_drv_t  libi2c_drv_entry;  /* general i2c/spi params */
0092     spi_memdrv_param_t  spi_memdrv_param;  /* private parameters     */
0093   } spi_memdrv_t;
0094 
0095   extern rtems_driver_address_table spi_memdrv_rw_ops;
0096   extern rtems_driver_address_table spi_memdrv_ro_ops;
0097 
0098 #ifdef __cplusplus
0099 }
0100 #endif
0101 
0102 #endif /* _LIBCHIP_SPI_MEMDRV_H */