| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2004-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_uart.h $ |
|---|
| 39 | * $brcm_Revision: 5 $ |
|---|
| 40 | * $brcm_Date: 2/16/11 1:04p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: Uart |
|---|
| 44 | * Specific APIs related to UART Control. |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/modules/uart/7400/include/nexus_uart.h $ |
|---|
| 49 | * |
|---|
| 50 | * 5 2/16/11 1:04p erickson |
|---|
| 51 | * SW7420-1491: add nelem required with nelem_out |
|---|
| 52 | * |
|---|
| 53 | * 4 2/15/11 2:12p erickson |
|---|
| 54 | * SW7420-1491: change param attributes |
|---|
| 55 | * |
|---|
| 56 | * 3 3/9/09 9:27a erickson |
|---|
| 57 | * PR52362: rework to improve uart performance |
|---|
| 58 | * |
|---|
| 59 | * 2 2/6/08 4:29p vsilyaev |
|---|
| 60 | * PR 38682: Added attributes for the linux kernel/user proxy mode |
|---|
| 61 | * |
|---|
| 62 | * 1 1/18/08 2:21p jgarrett |
|---|
| 63 | * PR 38808: Merging to main branch |
|---|
| 64 | * |
|---|
| 65 | * Nexus_Devel/2 11/28/07 2:11p erickson |
|---|
| 66 | * PR35457: doc update |
|---|
| 67 | * |
|---|
| 68 | * Nexus_Devel/1 11/20/07 1:28p erickson |
|---|
| 69 | * PR37423: added uart, gpio, spi modules |
|---|
| 70 | * |
|---|
| 71 | * Nexus_Devel/2 9/12/07 5:38p jgarrett |
|---|
| 72 | * PR 34702: Adding UART interface |
|---|
| 73 | * |
|---|
| 74 | * Nexus_Devel/1 9/12/07 10:39a jgarrett |
|---|
| 75 | * PR 34702: Adding initial IO headers |
|---|
| 76 | * |
|---|
| 77 | ***************************************************************************/ |
|---|
| 78 | #ifndef NEXUS_UART_H__ |
|---|
| 79 | #define NEXUS_UART_H__ |
|---|
| 80 | |
|---|
| 81 | #ifdef __cplusplus |
|---|
| 82 | extern "C" { |
|---|
| 83 | #endif |
|---|
| 84 | |
|---|
| 85 | /*************************************************************************** |
|---|
| 86 | Summary: |
|---|
| 87 | Handle for the Uart Interface. |
|---|
| 88 | |
|---|
| 89 | Description: |
|---|
| 90 | |
|---|
| 91 | See Also: |
|---|
| 92 | NEXUS_Uart_Open |
|---|
| 93 | ***************************************************************************/ |
|---|
| 94 | typedef struct NEXUS_Uart *NEXUS_UartHandle; |
|---|
| 95 | |
|---|
| 96 | /*************************************************************************** |
|---|
| 97 | Summary: |
|---|
| 98 | UART parity |
|---|
| 99 | |
|---|
| 100 | Description: |
|---|
| 101 | |
|---|
| 102 | See Also: |
|---|
| 103 | NEXUS_UartSettings |
|---|
| 104 | ***************************************************************************/ |
|---|
| 105 | typedef enum NEXUS_UartParity |
|---|
| 106 | { |
|---|
| 107 | NEXUS_UartParity_eNone, |
|---|
| 108 | NEXUS_UartParity_eOdd, |
|---|
| 109 | NEXUS_UartParity_eEven, |
|---|
| 110 | NEXUS_UartParity_eMax |
|---|
| 111 | } NEXUS_UartParity; |
|---|
| 112 | |
|---|
| 113 | /*************************************************************************** |
|---|
| 114 | Summary: |
|---|
| 115 | UART data bits |
|---|
| 116 | |
|---|
| 117 | Description: |
|---|
| 118 | |
|---|
| 119 | See Also: |
|---|
| 120 | NEXUS_UartSettings |
|---|
| 121 | ***************************************************************************/ |
|---|
| 122 | typedef enum NEXUS_UartDataBits |
|---|
| 123 | { |
|---|
| 124 | NEXUS_UartDataBits_e7, |
|---|
| 125 | NEXUS_UartDataBits_e8, |
|---|
| 126 | NEXUS_UartDataBits_eMax |
|---|
| 127 | } NEXUS_UartDataBits; |
|---|
| 128 | |
|---|
| 129 | /*************************************************************************** |
|---|
| 130 | Summary: |
|---|
| 131 | UART data bits |
|---|
| 132 | |
|---|
| 133 | Description: |
|---|
| 134 | |
|---|
| 135 | See Also: |
|---|
| 136 | NEXUS_UartSettings |
|---|
| 137 | ***************************************************************************/ |
|---|
| 138 | typedef enum NEXUS_UartStopBits |
|---|
| 139 | { |
|---|
| 140 | NEXUS_UartStopBits_e0, |
|---|
| 141 | NEXUS_UartStopBits_e1, |
|---|
| 142 | NEXUS_UartStopBits_e2, |
|---|
| 143 | NEXUS_UartStopBits_eMax |
|---|
| 144 | } NEXUS_UartStopBits; |
|---|
| 145 | |
|---|
| 146 | /*************************************************************************** |
|---|
| 147 | Summary: |
|---|
| 148 | UART Settings |
|---|
| 149 | |
|---|
| 150 | Description: |
|---|
| 151 | |
|---|
| 152 | See Also: |
|---|
| 153 | NEXUS_Uart_Open |
|---|
| 154 | NEXUS_Uart_GetDefaultSettings |
|---|
| 155 | ***************************************************************************/ |
|---|
| 156 | typedef struct NEXUS_UartSettings |
|---|
| 157 | { |
|---|
| 158 | unsigned rxBufferSize; |
|---|
| 159 | unsigned txBufferSize; |
|---|
| 160 | |
|---|
| 161 | unsigned baudRate; |
|---|
| 162 | NEXUS_UartParity parity; |
|---|
| 163 | NEXUS_UartDataBits dataBits; |
|---|
| 164 | NEXUS_UartStopBits stopBits; |
|---|
| 165 | |
|---|
| 166 | NEXUS_CallbackDesc rxReady; |
|---|
| 167 | NEXUS_CallbackDesc txDone; |
|---|
| 168 | NEXUS_CallbackDesc error; |
|---|
| 169 | } NEXUS_UartSettings; |
|---|
| 170 | |
|---|
| 171 | /*************************************************************************** |
|---|
| 172 | Summary: |
|---|
| 173 | Get default settings for the structure. |
|---|
| 174 | |
|---|
| 175 | Description: |
|---|
| 176 | This is required in order to make application code resilient to the addition of new strucutre members in the future. |
|---|
| 177 | |
|---|
| 178 | See Also: |
|---|
| 179 | NEXUS_Uart_Open |
|---|
| 180 | ***************************************************************************/ |
|---|
| 181 | void NEXUS_Uart_GetDefaultSettings( |
|---|
| 182 | NEXUS_UartSettings *pSettings /* [out] */ |
|---|
| 183 | ); |
|---|
| 184 | |
|---|
| 185 | /*************************************************************************** |
|---|
| 186 | Summary: |
|---|
| 187 | Open a serial port handle. |
|---|
| 188 | |
|---|
| 189 | Description: |
|---|
| 190 | |
|---|
| 191 | See Also: |
|---|
| 192 | NEXUS_Uart_Close |
|---|
| 193 | ***************************************************************************/ |
|---|
| 194 | NEXUS_UartHandle NEXUS_Uart_Open( /* attr{destructor=NEXUS_Uart_Close} */ |
|---|
| 195 | unsigned index, |
|---|
| 196 | const NEXUS_UartSettings *pSettings |
|---|
| 197 | ); |
|---|
| 198 | |
|---|
| 199 | /*************************************************************************** |
|---|
| 200 | Summary: |
|---|
| 201 | Close a serial port handle. |
|---|
| 202 | |
|---|
| 203 | Description: |
|---|
| 204 | |
|---|
| 205 | See Also: |
|---|
| 206 | NEXUS_Uart_Open |
|---|
| 207 | ***************************************************************************/ |
|---|
| 208 | void NEXUS_Uart_Close( |
|---|
| 209 | NEXUS_UartHandle handle |
|---|
| 210 | ); |
|---|
| 211 | |
|---|
| 212 | /*************************************************************************** |
|---|
| 213 | Summary: |
|---|
| 214 | Get the settings for a UART |
|---|
| 215 | |
|---|
| 216 | Description: |
|---|
| 217 | |
|---|
| 218 | See Also: |
|---|
| 219 | NEXUS_Uart_SetSettings |
|---|
| 220 | ***************************************************************************/ |
|---|
| 221 | void NEXUS_Uart_GetSettings( |
|---|
| 222 | NEXUS_UartHandle handle, |
|---|
| 223 | NEXUS_UartSettings *pSettings /* [out] */ |
|---|
| 224 | ); |
|---|
| 225 | |
|---|
| 226 | /*************************************************************************** |
|---|
| 227 | Summary: |
|---|
| 228 | Set the settings for a UART |
|---|
| 229 | |
|---|
| 230 | Description: |
|---|
| 231 | |
|---|
| 232 | See Also: |
|---|
| 233 | NEXUS_Uart_GetSettings |
|---|
| 234 | ***************************************************************************/ |
|---|
| 235 | NEXUS_Error NEXUS_Uart_SetSettings( |
|---|
| 236 | NEXUS_UartHandle handle, |
|---|
| 237 | const NEXUS_UartSettings *pSettings |
|---|
| 238 | ); |
|---|
| 239 | |
|---|
| 240 | /*************************************************************************** |
|---|
| 241 | Summary: |
|---|
| 242 | Read data from a serial port. |
|---|
| 243 | |
|---|
| 244 | Description: |
|---|
| 245 | This function will read data from a serial port, up to the number of bytes |
|---|
| 246 | specified. The application should continue to call this function until it |
|---|
| 247 | returns 0 bytes read before waiting for another callback. |
|---|
| 248 | |
|---|
| 249 | See Also: |
|---|
| 250 | NEXUS_Uart_Write |
|---|
| 251 | ***************************************************************************/ |
|---|
| 252 | NEXUS_Error NEXUS_Uart_Read( |
|---|
| 253 | NEXUS_UartHandle handle, |
|---|
| 254 | void *pData, /* [out] attr{nelem=numBytes;nelem_out=pBytesRead;reserved=64} */ |
|---|
| 255 | size_t numBytes, |
|---|
| 256 | size_t *pBytesRead /* [out] */ |
|---|
| 257 | ); |
|---|
| 258 | |
|---|
| 259 | /*************************************************************************** |
|---|
| 260 | Summary: |
|---|
| 261 | Write data to a serial port. |
|---|
| 262 | |
|---|
| 263 | Description: |
|---|
| 264 | This function will write data to a serial port, up to the number of bytes |
|---|
| 265 | specified. If the bytes specified exceeds available buffer space, the |
|---|
| 266 | number of bytes written will be smaller than the number requested. In this |
|---|
| 267 | case, the application should wait for a TxCallback and then continue to write |
|---|
| 268 | the remaining bytes. |
|---|
| 269 | |
|---|
| 270 | See Also: |
|---|
| 271 | NEXUS_Uart_Read |
|---|
| 272 | ***************************************************************************/ |
|---|
| 273 | NEXUS_Error NEXUS_Uart_Write( |
|---|
| 274 | NEXUS_UartHandle handle, |
|---|
| 275 | const void *pData, /* [out] attr{nelem=bufferSize;reserved=64} */ |
|---|
| 276 | size_t bufferSize, |
|---|
| 277 | size_t *pBytesWritten /* [out] */ |
|---|
| 278 | ); |
|---|
| 279 | |
|---|
| 280 | /*************************************************************************** |
|---|
| 281 | Summary: |
|---|
| 282 | UART status |
|---|
| 283 | |
|---|
| 284 | Description: |
|---|
| 285 | |
|---|
| 286 | See Also: |
|---|
| 287 | NEXUS_Uart_GetStatus |
|---|
| 288 | ***************************************************************************/ |
|---|
| 289 | typedef struct NEXUS_UartStatus |
|---|
| 290 | { |
|---|
| 291 | bool rxOverrun; |
|---|
| 292 | bool rxFrameError; |
|---|
| 293 | bool rxParityError; |
|---|
| 294 | unsigned rxBytes; |
|---|
| 295 | unsigned txBytes; |
|---|
| 296 | } NEXUS_UartStatus; |
|---|
| 297 | |
|---|
| 298 | /*************************************************************************** |
|---|
| 299 | Summary: |
|---|
| 300 | Get the current status of a UART. |
|---|
| 301 | ***************************************************************************/ |
|---|
| 302 | NEXUS_Error NEXUS_Uart_GetStatus( |
|---|
| 303 | NEXUS_UartHandle handle, |
|---|
| 304 | NEXUS_UartStatus *pStatus /* [out] */ |
|---|
| 305 | ); |
|---|
| 306 | |
|---|
| 307 | #ifdef __cplusplus |
|---|
| 308 | } |
|---|
| 309 | #endif |
|---|
| 310 | |
|---|
| 311 | #endif /* #ifndef NEXUS_UART_H__ */ |
|---|
| 312 | |
|---|