| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: breg_spi.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/10 $ |
|---|
| 12 | * $brcm_Date: 1/11/11 7:01p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/basemodules/reg/breg_spi.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/10 1/11/11 7:01p mbatchel |
|---|
| 21 | * SW35230-2053, SW35230-2702: Integrate SPI isr support for DTV. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/SW35230-2053/1 11/11/10 1:55p mbatchel |
|---|
| 24 | * SW35230-2053: Integrate SPI isr support for DTV. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/9 1/13/04 5:02p brianlee |
|---|
| 27 | * PR9268: Make write structures constant. |
|---|
| 28 | * |
|---|
| 29 | * Hydra_Software_Devel/8 9/11/03 5:06p brianlee |
|---|
| 30 | * Fixed SPI register interface function definitions. |
|---|
| 31 | * |
|---|
| 32 | * Hydra_Software_Devel/7 9/11/03 10:51a brianlee |
|---|
| 33 | * Fixed BREG_SPI_Read definition. |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/6 8/29/03 10:30a marcusk |
|---|
| 36 | * Fixed BREG_SPI_Read definition. |
|---|
| 37 | * |
|---|
| 38 | * Hydra_Software_Devel/5 8/22/03 2:52p marcusk |
|---|
| 39 | * Updated with latest changes discussed in the UPG design review. |
|---|
| 40 | * |
|---|
| 41 | * Hydra_Software_Devel/4 3/31/03 1:20p marcusk |
|---|
| 42 | * Updated with comments on threadsafety |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/3 3/31/03 10:32a marcusk |
|---|
| 45 | * Updated comments. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/2 3/10/03 2:39p marcusk |
|---|
| 48 | * Removed const keyword from read routines (copy paste error). |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/1 3/5/03 5:13p marcusk |
|---|
| 51 | * Initial version. |
|---|
| 52 | * |
|---|
| 53 | ***************************************************************************/ |
|---|
| 54 | |
|---|
| 55 | /*= Module Overview ******************************************************** |
|---|
| 56 | This module provides a standard abstraction API for accessing SPI registers. |
|---|
| 57 | Several SPI busses may exist on a single platform. Some may be hardware based, |
|---|
| 58 | while others software based (using GPIO pins). In order to hide the |
|---|
| 59 | specific implementation of the SPI bus from a PortingInterface this SPI |
|---|
| 60 | register access abstraction is used. |
|---|
| 61 | |
|---|
| 62 | ---++++ SPI Register Handles |
|---|
| 63 | Hardware and software SPI implementations must follow the defined function |
|---|
| 64 | prototype definitions. All SPI PortingInterfaces supply the a function |
|---|
| 65 | that initializes a standard BREG_SPI_Handle (and fills it with function |
|---|
| 66 | pointers provided by the specific SPI PortingInterfaces implementation). |
|---|
| 67 | Please refer to the specific SPI PortingInterface implementations for more |
|---|
| 68 | details. |
|---|
| 69 | |
|---|
| 70 | An example of this type of function would be: |
|---|
| 71 | |
|---|
| 72 | <verbatim> |
|---|
| 73 | BERR_Code BSPI_CreateSpiRegHandle( BSPI_Handle SpiHandle, BREG_SPI_Handle *pSpiRegHandle ); |
|---|
| 74 | </verbatim> |
|---|
| 75 | |
|---|
| 76 | This handle should be created during initialization and passed to the |
|---|
| 77 | appropriate porting interfaces. The porting interfaces in turn pass |
|---|
| 78 | this handle to the abstract SPI functions when then call the appropriate |
|---|
| 79 | SPI implementation though function pointers contained in the BREG_SPI_Handle. |
|---|
| 80 | |
|---|
| 81 | ---++++ Handling ThreadSafe with SPI |
|---|
| 82 | Since multiple modules (PortingInterface and otherwise) may be sharing the |
|---|
| 83 | same SPI bus, any function calls to the modules in question must be serialized |
|---|
| 84 | to prevent thread collisions. |
|---|
| 85 | |
|---|
| 86 | 1 All calls to the modules sharing the same SPI handle must be protected |
|---|
| 87 | through the use of a mutex. This protection must be handled by the |
|---|
| 88 | upper level software (driver, middleware, etc). |
|---|
| 89 | 2 Upper level software can create an additional layer between the SPI |
|---|
| 90 | RegisterInterface and the corresponding SPI PortingInterface instance |
|---|
| 91 | that implements the SPI register access. In this layer a mutex is |
|---|
| 92 | used to protect all SPI accesses. This could easily be done |
|---|
| 93 | using the BREG_SPI_Impl structure. |
|---|
| 94 | ***************************************************************************/ |
|---|
| 95 | |
|---|
| 96 | #ifndef BREG_SPI_H |
|---|
| 97 | #define BREG_SPI_H |
|---|
| 98 | |
|---|
| 99 | #ifdef __cplusplus |
|---|
| 100 | extern "C" { |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | Summary: |
|---|
| 105 | This is an opaque handle that is used for SPI read and write functions. |
|---|
| 106 | */ |
|---|
| 107 | typedef struct BREG_SPI_Impl *BREG_SPI_Handle; |
|---|
| 108 | |
|---|
| 109 | /* |
|---|
| 110 | Summary: |
|---|
| 111 | This function writes a programmable number of SPI registers. |
|---|
| 112 | */ |
|---|
| 113 | BERR_Code BREG_SPI_Write( |
|---|
| 114 | BREG_SPI_Handle spiHandle, /* Device channel handle */ |
|---|
| 115 | const uint8_t *pWriteData, /* pointer to write memory location */ |
|---|
| 116 | size_t length /* size of *pWriteData buffers (number of bytes to write ) */ |
|---|
| 117 | ); |
|---|
| 118 | |
|---|
| 119 | /* |
|---|
| 120 | Summary: |
|---|
| 121 | This function reads a programmable number of SPI registers. |
|---|
| 122 | |
|---|
| 123 | The SPI protocol always writes data out as it is reading data in. |
|---|
| 124 | The incoming data is stored in pReadData while the data |
|---|
| 125 | going out is sourced from pWriteData. |
|---|
| 126 | */ |
|---|
| 127 | BERR_Code BREG_SPI_Read( |
|---|
| 128 | BREG_SPI_Handle spiHandle, /* Device channel handle */ |
|---|
| 129 | const uint8_t *pWriteData, /* pointer to memory location where data is to sent */ |
|---|
| 130 | uint8_t *pReadData, /* pointer to memory location to store read data */ |
|---|
| 131 | size_t length /* size of *pWriteData and *pReadData buffers (number of bytes to read + number of bytes to write) */ |
|---|
| 132 | ); |
|---|
| 133 | |
|---|
| 134 | /* |
|---|
| 135 | Summary: |
|---|
| 136 | This function writes a programmable number of SPI registers in isr. |
|---|
| 137 | */ |
|---|
| 138 | BERR_Code BREG_SPI_Write_isr( |
|---|
| 139 | BREG_SPI_Handle spiHandle, /* Device channel handle */ |
|---|
| 140 | const uint8_t *pWriteData, /* pointer to write memory location */ |
|---|
| 141 | size_t length /* size of *pWriteData buffers (number of bytes to write ) */ |
|---|
| 142 | ); |
|---|
| 143 | |
|---|
| 144 | /* |
|---|
| 145 | Summary: |
|---|
| 146 | This function reads a programmable number of SPI registers in isr. |
|---|
| 147 | |
|---|
| 148 | The SPI protocol always writes data out as it is reading data in. |
|---|
| 149 | The incoming data is stored in pReadData while the data |
|---|
| 150 | going out is sourced from pWriteData. |
|---|
| 151 | */ |
|---|
| 152 | BERR_Code BREG_SPI_Read_isr( |
|---|
| 153 | BREG_SPI_Handle spiHandle, /* Device channel handle */ |
|---|
| 154 | const uint8_t *pWriteData, /* pointer to memory location where data is to sent */ |
|---|
| 155 | uint8_t *pReadData, /* pointer to memory location to store read data */ |
|---|
| 156 | size_t length /* size of *pWriteData and *pReadData buffers (number of bytes to read + number of bytes to write) */ |
|---|
| 157 | ); |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | #ifdef __cplusplus |
|---|
| 161 | } |
|---|
| 162 | #endif |
|---|
| 163 | |
|---|
| 164 | #endif |
|---|
| 165 | /* End of File */ |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|