1 /******************************************************************************* 2 * (c) Copyright 2011-2013 Microsemi SoC Products Group. All rights reserved. 3 * 4 * SmartFusion2 Microcontroller Subsystem MMUART bare metal software driver 5 * public API. 6 * 7 * SVN $Revision: 5610 $ 8 * SVN $Date: 2013-04-05 18:49:30 +0530 (Fri, 05 Apr 2013) $ 9 */ 10 /*=========================================================================*//** 11 @mainpage SmartFusion2 MSS UART Bare Metal Driver. 12 ============================================================================== 13 @section intro_sec Introduction 14 ============================================================================== 15 The SmartFusion2 microcontroller subsystem (MSS) includes two multi-mode UART 16 (MMUART) peripherals for serial communication. This driver provides a set of 17 functions for controlling the MSS MMUARTs as part of a bare metal system 18 where no operating system is available. These drivers can be adapted for use 19 as part of an operating system, but the implementation of the adaptation layer 20 between this driver and the operating system's driver model is outside the 21 scope of this driver. 22 Note: MSS UART is synonymous with MSS MMUART in this document. 23 24 ============================================================================== 25 @section hw_dependencies Hardware Flow Dependencies 26 ============================================================================== 27 The configuration of all features of the MSS MMUART peripherals is covered by 28 this driver with the exception of the SmartFusion2 IOMUX configuration. 29 SmartFusion2 allows multiple non-concurrent uses of some external pins through 30 IOMUX configuration. This feature allows optimization of external pin usage by 31 assigning external pins for use by either the microcontroller subsystem or the 32 FPGA fabric. The MSS MMUART serial signals are routed through IOMUXs to the 33 SmartFusion2 device external pins. The MSS MMUART serial signals may also be 34 routed through IOMUXs to the SmartFusion2 FPGA fabric. For more information on 35 IOMUX, refer to the IOMUX section of the SmartFusion2 Microcontroller 36 Subsystem (MSS) User�s Guide. 37 The IOMUXs are configured using the SmartFusion2 MSS configurator tool. You 38 must ensure that the MSS MMUART peripherals are enabled and configured in the 39 SmartFusion2 MSS configurator if you wish to use them. For more information on 40 IOMUXs, refer to the IOMUX section of the SmartFusion2 Microcontroller 41 Subsystem (MSS) User�s Guide. 42 The base address, register addresses and interrupt number assignment for the 43 MSS MMUART peripherals are defined as constants in the SmartFusion2 CMSIS HAL. 44 You must ensure that the latest SmartFusion2 CMSIS HAL is included in the 45 project settings of the software tool chain used to build your project and 46 that it is generated into your project. 47 48 ============================================================================== 49 @section theory_op Theory of Operation 50 ============================================================================== 51 The MSS MMUART driver functions are grouped into the following categories: 52 - Initialization and configuration functions 53 - Polled transmit and receive functions 54 - Interrupt driven transmit and receive functions 55 56 -------------------------------- 57 Initialization and Configuration 58 -------------------------------- 59 The MSS MMUART supports the following four broad modes of operation: 60 - UART or USART mode 61 - LIN mode 62 - IrDA mode 63 - Smartcard or ISO 7816 mode 64 The MSS MMUART driver provides the MSS_UART_init(), MSS_UART_lin_init(), 65 MSS_UART_irda_init() and MSS_UART_smartcard_init() functions to initialize the 66 MSS MMUARTs for operation in one of these modes. One of these initialization 67 functions must be called before any other MSS MMUART driver functions can be 68 called. The MSS MMUART operating modes are mutually exclusive; therefore only 69 one of the initialization functions must be called. The first parameter of the 70 initialization functions is a pointer to one of two global data structures 71 used to store state information for each MSS MMUART. A pointer to these data 72 structures is also used as the first parameter to many of the driver functions 73 to identify which MSS MMUART will be used by the called function. The names of 74 these two data structures are g_mss_uart0 and g_mss_uart1. Therefore, any call 75 to an MSS MMUART function should be of the form 76 MSS_UART_function_name( &g_mss_uart0, ... ) or 77 MSS_UART_function_name( &g_mss_uart1, ... ). 78 79 UART or USART Mode 80 For the UART or USART modes of operation, the MSS MMUART driver is initialized 81 through a call to the MSS_UART_init() function. This function takes the UART�s 82 configuration as its parameters. The MSS_UART_init() function must be called 83 before any other MSS MMUART driver functions can be called. 84 The MSS_UART_init() function configures the baud rate based on the input baud 85 rate parameter and if possible uses a fractional baud rate for greater 86 precision. This function disables the LIN, IrDA and SmartCard modes. 87 88 LIN mode 89 For the LIN mode of operation, the MSS MMUART driver is initialized through a 90 call to the MSS_UART_lin_init() function. This function takes the LIN node�s 91 configuration as its parameters. The MSS_UART_lin_init() function must be 92 called before any other MSS MMUART driver functions can be called. The 93 MSS_UART_lin_init() function configures the baud rate based on the input baud 94 rate parameter and if possible uses a fractional baud rate for greater 95 precision. This function disables the IrDA and SmartCard modes. 96 The driver also provides the following LIN mode configuration functions: 97 - MSS_UART_set_break() 98 - MSS_UART_clear_break() 99 - MSS_UART_set_pidpei_handler() 100 - MSS_UART_set_linbreak_handler() 101 - MSS_UART_set_linsync_handler() 102 Note: These LIN mode configuration functions can only be called after the 103 MSS_UART_lin_init() function is called. 104 105 IrDA mode 106 For the IrDA mode of operation, the driver is initialized through a call to 107 the MSS_UART_irda_init() function. This function takes the IrDA node�s 108 configuration as its parameters. The MSS_UART_irda_init() function must be 109 called before any other MSS MMUART driver functions can be called. The 110 MSS_UART_irda_init() function configures the baud rate based on the input baud 111 rate parameter and if possible uses a fractional baud rate for greater 112 precision. This function disables the LIN and SmartCard modes. 113 114 Smartcard or ISO 7816 mode 115 For the Smartcard or ISO 7816 mode of operation, the driver is initialized 116 through a call to the MSS_UART_smartcard_init() function. This function takes 117 the smartcard configuration as its parameters. The MSS_UART_smartcard_init() 118 function must be called before any other MSS MMUART driver functions can be 119 called. The MSS_UART_smartcard_init() function configures the baud rate based 120 on the input baud rate parameter and if possible uses a fractional baud rate 121 for greater precision. This function disables the LIN and IrDA modes. 122 The driver also provides the following Smartcard mode configuration functions: 123 - MSS_UART_enable_halfduplex() 124 - MSS_UART_disable_halfduplex() 125 - MSS_UART_set_nack_handler() 126 Note: These Smartcard mode configuration functions can only be called after 127 the MSS_UART_smartcard_init() function is called. 128 129 Common Configuration Functions 130 The driver also provides the configuration functions that can be used with all 131 MSS MMUART operating modes. These common configuration functions are as 132 follows: 133 - MSS_UART_set_rx_endian() 134 - MSS_UART_set_tx_endian() 135 - MSS_UART_enable_afclear() 136 - MSS_UART_disable_afclear() 137 - MSS_UART_enable_rx_timeout() 138 - MSS_UART_disable_rx_timeout() 139 - MSS_UART_enable_tx_time_guard() 140 - MSS_UART_disable_tx_time_guard() 141 - MSS_UART_set_address() 142 - MSS_UART_set_ready_mode() 143 - MSS_UART_set_usart_mode() 144 - MSS_UART_set_filter_length() 145 - MSS_UART_enable_afm() 146 - MSS_UART_disable_afm() 147 Note: These configuration functions can only be called after one of the 148 MSS_UART_init(), MSS_UART_lin_init(), MSS_UART_irda_init() or 149 MSS_UART_smartcard_init() functions is called. 150 151 -------------------------------------- 152 Polled Transmit and Receive Operations 153 -------------------------------------- 154 The driver can be used to transmit and receive data once initialized. 155 Data is transmitted using the MSS_UART_polled_tx() function. This function is 156 blocking, meaning that it will only return once the data passed to the 157 function has been sent to the MSS MMUART hardware transmitter. Data received 158 by the MSS MMUART hardware receiver can be read by the MSS_UART_get_rx() 159 function. 160 The MSS_UART_polled_tx_string() function is provided to transmit a NULL (�\0�) 161 terminated string in polled mode. This function is blocking, meaning that it 162 will only return once the data passed to the function has been sent to the MSS 163 MMUART hardware transmitter. 164 The MSS_UART_fill_tx_fifo() function fills the MSS MMUART hardware transmit 165 FIFO with data from a buffer passed as a parameter and returns the number of 166 bytes transferred to the FIFO. If the transmit FIFO is not empty when the 167 MSS_UART_fill_tx_fifo() function is called it returns immediately without 168 transferring any data to the FIFO. 169 170 --------------------------- 171 Interrupt Driven Operations 172 --------------------------- 173 The driver can also transmit or receive data under interrupt control, freeing 174 your application to perform other tasks until an interrupt occurs indicating 175 that the driver�s attention is required. 176 177 Interrupt Handlers 178 The MSS MMUART driver supports all types of interrupt triggered by the MSS 179 MMUART. The driver�s internal top level interrupt handler identifies the 180 source of the MSS MMUART interrupt and calls the corresponding lower level 181 handler function that you previously registered with the driver through calls 182 to the MSS_UART_set_rx_handler(), MSS_UART_set_tx_handler(), 183 MSS_UART_set_rxstatus_handler(), and MSS_UART_set_modemstatus_handler() 184 functions. You are responsible for creating these lower level interrupt 185 handlers as part of your application program and registering them with the 186 driver. 187 Note: The SmartFusion2 CMSIS-PAL defines the UART0_IRQHandler() and 188 UART1_IRQHandler() functions (with weak linkage) and assigns them as the 189 interrupt service routines (ISR) for the MSS MMUART interrupt inputs to 190 the Cortex-M3 NVIC. The MSS MMUART driver provides the implementation 191 functions for both of these ISRs from which it calls its own internal 192 top level, interrupt handler function. 193 The MSS_UART_enable_irq() and MSS_UART_disable_irq() functions are used to 194 enable or disable the received line status, received data available/character 195 timeout, transmit holding register empty and modem status interrupts at the 196 MSS MMUART level. The MSS_UART_enable_irq() function also enables the MSS 197 MMUART instance interrupt at the Cortex-M3 level. 198 199 Transmitting Data 200 Interrupt-driven transmit is initiated by a call to MSS_UART_irq_tx(), 201 specifying the block of data to transmit. Your application is then free to 202 perform other tasks and inquire later whether transmit has completed by 203 calling the MSS_UART_tx_complete() function. The MSS_UART_irq_tx() function 204 enables the UART�s transmit holding register empty (THRE) interrupt and then, 205 when the interrupt goes active, the driver�s default THRE interrupt handler 206 transfers the data block to the UART until the entire block is transmitted. 207 Note: You can use the MSS_UART_set_tx_handler() function to assign an 208 alternative handler to the THRE interrupt. In this case, you must not 209 use the MSS_UART_irq_tx() function to initiate the transmit, as this 210 will re-assign the driver�s default THRE interrupt handler to the THRE 211 interrupt. Instead, your alternative THRE interrupt handler must include 212 a call to the MSS_UART_fill_tx_fifo() function to transfer the data to 213 the UART. 214 215 Receiving Data 216 Interrupt-driven receive is performed by first calling 217 MSS_UART_set_rx_handler() to register a receive handler function that will be 218 called by the driver whenever receive data is available. You must provide this 219 receive handler function which must include a call to the MSS_UART_get_rx() 220 function to actually read the received data. 221 222 ----------- 223 UART Status 224 ----------- 225 The function MSS_UART_get_rx_status() is used to read the receiver error 226 status. This function returns the overrun, parity, framing, break, and FIFO 227 error status of the receiver. 228 The function MSS_UART_get_tx_status() is used to read the transmitter status. 229 This function returns the transmit empty (TEMT) and transmit holding register 230 empty (THRE) status of the transmitter. 231 The function MSS_UART_get_modem_status() is used to read the modem status 232 flags. This function returns the current value of the modem status register. 233 234 -------- 235 Loopback 236 -------- 237 The MSS_UART_set_loopback() function can be used to locally loopback the Tx 238 and Rx lines of a UART. This is not to be confused with the loopback of UART0 239 to UART1, which can be achieved through the microcontroller subsystem�s system 240 registers. 241 242 *//*=========================================================================*/ 243 #ifndef __MSS_UART_H_ 244 #define __MSS_UART_H_ 1 245 246 #include "../../CMSIS/m2sxxx.h" 247 #include <stddef.h> 248 249 #ifdef __cplusplus 250 extern "C" { 251 #endif 252 253 /***************************************************************************//** 254 Baud rates 255 The following definitions are used to specify standard baud rates as a 256 parameter to the MSS_UART_init() function. 257 */ 258 #define MSS_UART_110_BAUD 110 259 #define MSS_UART_300_BAUD 300 260 #define MSS_UART_1200_BAUD 1200 261 #define MSS_UART_2400_BAUD 2400 262 #define MSS_UART_4800_BAUD 4800 263 #define MSS_UART_9600_BAUD 9600 264 #define MSS_UART_19200_BAUD 19200 265 #define MSS_UART_38400_BAUD 38400 266 #define MSS_UART_57600_BAUD 57600 267 #define MSS_UART_115200_BAUD 115200 268 #define MSS_UART_230400_BAUD 230400 269 #define MSS_UART_460800_BAUD 460800 270 #define MSS_UART_921600_BAUD 921600 271 272 /***************************************************************************//** 273 Data Bits Length 274 The following defines are used to build the value of the MSS_UART_init() 275 function line_config parameter. 276 */ 277 #define MSS_UART_DATA_5_BITS ( (uint8_t) 0x00 ) 278 #define MSS_UART_DATA_6_BITS ( (uint8_t) 0x01 ) 279 #define MSS_UART_DATA_7_BITS ( (uint8_t) 0x02 ) 280 #define MSS_UART_DATA_8_BITS ( (uint8_t) 0x03 ) 281 282 /***************************************************************************//** 283 Parity 284 The following defines are used to build the value of the MSS_UART_init() 285 function line_config parameter. 286 */ 287 #define MSS_UART_NO_PARITY ( (uint8_t) 0x00 ) 288 #define MSS_UART_ODD_PARITY ( (uint8_t) 0x08 ) 289 #define MSS_UART_EVEN_PARITY ( (uint8_t) 0x18 ) 290 #define MSS_UART_STICK_PARITY_0 ( (uint8_t) 0x38 ) 291 #define MSS_UART_STICK_PARITY_1 ( (uint8_t) 0x28 ) 292 293 /***************************************************************************//** 294 Number of Stop Bits 295 The following defines are used to build the value of the MSS_UART_init() 296 function line_config parameter. 297 */ 298 #define MSS_UART_ONE_STOP_BIT ( (uint8_t) 0x00 ) 299 #define MSS_UART_ONEHALF_STOP_BIT ( (uint8_t) 0x04 ) 300 #define MSS_UART_TWO_STOP_BITS ( (uint8_t) 0x04 ) 301 302 /***************************************************************************//** 303 Receiver Error Status 304 The following defines are used to determine the UART receiver error type. 305 These bit mask constants are used with the return value of the 306 MSS_UART_get_rx_status() function to find out if any errors occurred while 307 receiving data. 308 */ 309 #define MSS_UART_INVALID_PARAM ( (uint8_t)0xFF ) 310 #define MSS_UART_NO_ERROR ( (uint8_t)0x00 ) 311 #define MSS_UART_OVERUN_ERROR ( (uint8_t)0x02 ) 312 #define MSS_UART_PARITY_ERROR ( (uint8_t)0x04 ) 313 #define MSS_UART_FRAMING_ERROR ( (uint8_t)0x08 ) 314 #define MSS_UART_BREAK_ERROR ( (uint8_t)0x10 ) 315 #define MSS_UART_FIFO_ERROR ( (uint8_t)0x80 ) 316 317 /***************************************************************************//** 318 Transmitter Status 319 The following definitions are used to determine the UART transmitter status. 320 These bit mask constants are used with the return value of the 321 MSS_UART_get_tx_status() function to find out the status of the transmitter. 322 */ 323 #define MSS_UART_TX_BUSY ( (uint8_t) 0x00 ) 324 #define MSS_UART_THRE ( (uint8_t) 0x20 ) 325 #define MSS_UART_TEMT ( (uint8_t) 0x40 ) 326 327 /***************************************************************************//** 328 Modem Status 329 The following defines are used to determine the modem status. These bit 330 mask constants are used with the return value of the 331 MSS_UART_get_modem_status() function to find out the modem status of 332 the UART. 333 */ 334 #define MSS_UART_DCTS ( (uint8_t) 0x01 ) 335 #define MSS_UART_DDSR ( (uint8_t) 0x02 ) 336 #define MSS_UART_TERI ( (uint8_t) 0x04 ) 337 #define MSS_UART_DDCD ( (uint8_t) 0x08 ) 338 #define MSS_UART_CTS ( (uint8_t) 0x10 ) 339 #define MSS_UART_DSR ( (uint8_t) 0x20 ) 340 #define MSS_UART_RI ( (uint8_t) 0x40 ) 341 #define MSS_UART_DCD ( (uint8_t) 0x80 ) 342 343 /***************************************************************************//** 344 This typedef specifies the irq_mask parameter for the MSS_UART_enable_irq() 345 and MSS_UART_disable_irq() functions. The driver defines a set of bit masks 346 that are used to build the value of the irq_mask parameter. A bitwise OR of 347 these bit masks is used to enable or disable multiple MSS MMUART interrupts. 348 */ 349 typedef uint16_t mss_uart_irq_t; 350 351 /***************************************************************************//** 352 The following defines specify the interrupt masks to enable and disable MSS 353 MMUART interrupts. They are used to build the value of the irq_mask parameter 354 for the MSS_UART_enable_irq() and MSS_UART_disable_irq() functions. A bitwise 355 OR of these constants is used to enable or disable multiple interrupts. 356 */ 357 #define MSS_UART_RBF_IRQ 0x001 358 #define MSS_UART_TBE_IRQ 0x002 359 #define MSS_UART_LS_IRQ 0x004 360 #define MSS_UART_MS_IRQ 0x008 361 #define MSS_UART_RTO_IRQ 0x010 362 #define MSS_UART_NACK_IRQ 0x020 363 #define MSS_UART_PIDPE_IRQ 0x040 364 #define MSS_UART_LINB_IRQ 0x080 365 #define MSS_UART_LINS_IRQ 0x100 366 #define MSS_UART_INVALID_IRQ UINT16_MAX 367 368 /***************************************************************************//** 369 This enumeration specifies the receiver FIFO trigger level. This is the number 370 of bytes that must be received before the UART generates a receive data 371 available interrupt. It provides the allowed values for the 372 MSS_UART_set_rx_handler() function trigger_level parameter. 373 */ 374 typedef enum { 375 MSS_UART_FIFO_SINGLE_BYTE = 0x00, 376 MSS_UART_FIFO_FOUR_BYTES = 0x40, 377 MSS_UART_FIFO_EIGHT_BYTES = 0x80, 378 MSS_UART_FIFO_FOURTEEN_BYTES = 0xC0, 379 MSS_UART_FIFO_INVALID_TRIG_LEVEL 380 } mss_uart_rx_trig_level_t; 381 382 /***************************************************************************//** 383 This enumeration specifies the loopback configuration of the UART. It provides 384 the allowed values for the MSS_UART_set_loopback() function�s loopback 385 parameter. Use MSS_UART_LOCAL_LOOPBACK_ON to set up the UART to locally 386 loopback its Tx and Rx lines. Use MSS_UART_REMOTE_LOOPBACK_ON to set up the 387 UART in remote loopback mode. 388 */ 389 typedef enum { 390 MSS_UART_LOCAL_LOOPBACK_OFF, 391 MSS_UART_LOCAL_LOOPBACK_ON, 392 MSS_UART_REMOTE_LOOPBACK_OFF, 393 MSS_UART_REMOTE_LOOPBACK_ON, 394 MSS_UART_AUTO_ECHO_OFF, 395 MSS_UART_AUTO_ECHO_ON, 396 MSS_UART_INVALID_LOOPBACK 397 } mss_uart_loopback_t; 398 399 /***************************************************************************//** 400 IrDA input / output polarity. 401 This enumeration specifies the RZI modem polarity for input and output signals. 402 This is passed as parameters in MSS_UART_irda_init() function. 403 */ 404 typedef enum { 405 MSS_UART_ACTIVE_LOW = 0u, 406 MSS_UART_ACTIVE_HIGH = 1u, 407 MSS_UART_INVALID_POLARITY 408 } mss_uart_rzi_polarity_t; 409 410 /***************************************************************************//** 411 IrDA input / output pulse width. 412 This enumeration specifies the RZI modem pulse width for input and output signals. 413 This is passed as parameters in MSS_UART_irda_init() function. 414 */ 415 typedef enum { 416 MSS_UART_3_BY_16 = 0u, 417 MSS_UART_1_BY_4 = 1u, 418 MSS_UART_INVALID_PW 419 } mss_uart_rzi_pulsewidth_t; 420 421 /***************************************************************************//** 422 Tx / Rx endianess. 423 This enumeration specifies the MSB first or LSB first for MSS UART transmitter 424 and receiver. The parameter of this type shall be passed in 425 MSS_UART_set_rx_endian()and MSS_UART_set_tx_endian() functions. 426 */ 427 typedef enum { 428 MSS_UART_LITTLEEND, 429 MSS_UART_BIGEND, 430 MSS_UART_INVALID_ENDIAN 431 } mss_uart_endian_t; 432 433 /***************************************************************************//** 434 Glitch filter length. 435 This enumeration specifies the glitch filter length. The function 436 MSS_UART_set_filter_length() accepts the parameter of this type. 437 */ 438 typedef enum { 439 MSS_UART_LEN0 = 0, 440 MSS_UART_LEN1 = 1, 441 MSS_UART_LEN2 = 2, 442 MSS_UART_LEN3 = 3, 443 MSS_UART_LEN4 = 4, 444 MSS_UART_LEN5 = 5, 445 MSS_UART_LEN6 = 6, 446 MSS_UART_LEN7 = 7, 447 MSS_UART_INVALID_FILTER_LENGTH = 8 448 } mss_uart_filter_length_t; 449 450 /***************************************************************************//** 451 TXRDY and RXRDY mode. 452 This enumeration specifies the TXRDY and RXRDY signal modes. The function 453 MSS_UART_set_ready_mode() accepts the parameter of this type. 454 */ 455 typedef enum { 456 MSS_UART_READY_MODE0, 457 MSS_UART_READY_MODE1, 458 MSS_UART_INVALID_READY_MODE 459 } mss_uart_ready_mode_t; 460 461 /***************************************************************************//** 462 USART mode of operation. 463 This enumeration specifies the mode of operation of MSS UART when operating 464 as USART. The function MSS_UART_set_usart_mode() accepts the parameter of this type. 465 */ 466 typedef enum { 467 MSS_UART_ASYNC_MODE = 0, 468 MSS_UART_SYNC_SLAVE_POS_EDGE_CLK = 1, 469 MSS_UART_SYNC_SLAVE_NEG_EDGE_CLK = 2, 470 MSS_UART_SYNC_MASTER_POS_EDGE_CLK = 3, 471 MSS_UART_SYNC_MASTER_NEG_EDGE_CLK = 4, 472 MSS_UART_INVALID_SYNC_MODE = 5 473 } mss_uart_usart_mode_t; 474 475 476 /***************************************************************************//** 477 MSS UART instance type. 478 This is type definition for MSS UART instance. You need to create and 479 maintain a record of this type. This holds all data regarding the MSS UART 480 instance 481 */ 482 typedef struct mss_uart_instance mss_uart_instance_t; 483 484 /***************************************************************************//** 485 Interrupt handler prototype. 486 This typedef specifies the function prototype for MSS UART interrupt handlers. 487 All interrupt handlers registered with the MSS UART driver must be of this type. 488 The interrupt handlers are registered with the driver through the 489 MSS_UART_set_rx_handler(), MSS_UART_set_tx_handler(), 490 MSS_UART_set_rxstatus_handler(), and MSS_UART_set_modemstatus_handler() 491 functions. 492 The this_uart parameter is a pointer to either g_mss_uart0 or g_mss_uart1 to 493 identify the MSS UART to associate with the handler function. 494 */ 495 typedef void (*mss_uart_irq_handler_t)( mss_uart_instance_t * this_uart ); 496 497 /***************************************************************************//** 498 mss_uart_instance. 499 There is one instance of this structure for each instance of the 500 microcontroller subsystem�s UARTs. Instances of this structure are used to 501 identify a specific UART. A pointer to an initialized instance of the 502 mss_uart_instance_t structure is passed as the first parameter to 503 MSS UART driver functions to identify which UART should perform the 504 requested operation. 505 */ 506 struct mss_uart_instance{ 507 /* CMSIS related defines identifying the UART hardware. */ 508 UART_TypeDef * hw_reg; /*!< Pointer to UART registers. */ 509 IRQn_Type irqn; /*!< UART's Cortex-M3 NVIC interrupt number. */ 510 uint32_t baudrate; /*!< Operating baud rate. */ 511 uint8_t lineconfig; /*!< Line configuration parameters. */ 512 uint8_t status; /*!< Sticky line status. */ 513 514 /* transmit related info (used with interrupt driven transmit): */ 515 const uint8_t * tx_buffer; /*!< Pointer to transmit buffer. */ 516 uint32_t tx_buff_size; /*!< Transmit buffer size. */ 517 uint32_t tx_idx; /*!< Index within transmit buffer of next byte to transmit.*/ 518 519 /* line status interrupt handler:*/ 520 mss_uart_irq_handler_t linests_handler; /*!< Pointer to user registered line status handler. */ 521 /* receive interrupt handler:*/ 522 mss_uart_irq_handler_t rx_handler; /*!< Pointer to user registered receiver handler. */ 523 /* transmit interrupt handler:*/ 524 mss_uart_irq_handler_t tx_handler; /*!< Pointer to user registered transmit handler. */ 525 /* modem status interrupt handler:*/ 526 mss_uart_irq_handler_t modemsts_handler; /*!< Pointer to user registered modem status handler. */ 527 /* receiver timeout interrupt handler */ 528 mss_uart_irq_handler_t rto_handler; /*!< Pointer to user registered receiver timeout handler. */ 529 /* NACK interrupt handler */ 530 mss_uart_irq_handler_t nack_handler; /*!< Pointer to user registered NACK handler. */ 531 /* PID parity prror interrup handler */ 532 mss_uart_irq_handler_t pid_pei_handler; /*!< Pointer to user registered PID parity error handler. */ 533 /* LIN break interrupt handler */ 534 mss_uart_irq_handler_t break_handler; /*!< Pointer to user registered LIN break handler. */ 535 /* LIN sync detection interrupt handler */ 536 mss_uart_irq_handler_t sync_handler; /*!< Pointer to user registered LIN sync dectection handler. */ 537 }; 538 539 /***************************************************************************//** 540 This instance of mss_uart_instance_t holds all data related to the operations 541 performed by UART0. The function MSS_UART_init() initializes this structure. 542 A pointer to g_mss_uart0 is passed as the first parameter to MSS UART driver 543 functions to indicate that UART0 should perform the requested operation. 544 */ 545 extern mss_uart_instance_t g_mss_uart0; 546 547 /***************************************************************************//** 548 This instance of mss_uart_instance_t holds all data related to the operations 549 performed by UART1. The function MSS_UART_init() initializes this structure. 550 A pointer to g_mss_uart1 is passed as the first parameter to MSS UART driver 551 functions to indicate that UART1 should perform the requested operation. 552 */ 553 extern mss_uart_instance_t g_mss_uart1; 554 555 /***************************************************************************//** 556 The MSS_UART_init() function initializes and configures one of the SmartFusion2 557 MSS UARTs with the configuration passed as a parameter. The configuration 558 parameters are the baud_rate which is used to generate the baud value and the 559 line_config which is used to specify the line configuration (bit length, 560 stop bits and parity). 561 562 @param this_uart 563 The this_uart parameter is a pointer to an mss_uart_instance_t structure 564 identifying the MSS UART hardware block to be initialized. There are two 565 such data structures, g_mss_uart0 and g_mss_uart1, associated with MSS 566 UART0 and MSS UART1 respectively. This parameter must point to either 567 the g_mss_uart0 or g_mss_uart1 global data structure defined within 568 the UART driver.. 569 570 @param baud_rate 571 The baud_rate parameter specifies the baud rate. It can be specified for 572 common baud rates� using the following defines: 573 � MSS_UART_110_BAUD 574 � MSS_UART_300_BAUD 575 � MSS_UART_1200_BAUD 576 � MSS_UART_2400_BAUD 577 � MSS_UART_4800_BAUD 578 � MSS_UART_9600_BAUD 579 � MSS_UART_19200_BAUD 580 � MSS_UART_38400_BAUD 581 � MSS_UART_57600_BAUD 582 � MSS_UART_115200_BAUD 583 � MSS_UART_230400_BAUD 584 � MSS_UART_460800_BAUD 585 � MSS_UART_921600_BAUD 586 Alternatively, any nonstandard baud rate can be specified by simply passing 587 the actual required baud rate as the value for this parameter. 588 589 @param line_config 590 The line_config parameter is the line configuration specifying the bit length, 591 number of stop bits and parity settings. This is a bitwise OR of one value 592 from each of the following groups of allowed values: 593 � One of the following to specify the transmit/receive data bit length: 594 MSS_UART_DATA_5_BITS 595 MSS_UART_DATA_6_BITS, 596 MSS_UART_DATA_7_BITS 597 MSS_UART_DATA_8_BITS 598 � One of the following to specify the parity setting: 599 MSS_UART_NO_PARITY 600 MSS_UART_EVEN_PARITY 601 MSS_UART_ODD_PARITY 602 MSS_UART_STICK_PARITY_0 603 MSS_UART_STICK_PARITY_1 604 � One of the following to specify the number of stop bits: 605 MSS_UART_ONE_STOP_BIT 606 MSS_UART_ONEHALF_STOP_BIT 607 MSS_UART_TWO_STOP_BITS 608 609 @return 610 This function does not return a value. 611 612 Example: 613 @code 614 #include "mss_uart.h" 615 616 int main(void) 617 { 618 MSS_UART_init(&g_mss_uart0, 619 MSS_UART_57600_BAUD, 620 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 621 622 return(0); 623 } 624 @endcode 625 */ 626 void 627 MSS_UART_init 628 ( 629 mss_uart_instance_t* this_uart, 630 uint32_t baud_rate, 631 uint8_t line_config 632 ); 633 634 /***************************************************************************//** 635 The MSS_UART_lin_init() function is used to initialize the MSS UART for 636 LIN mode of operation. The configuration parameters are the baud_rate which is 637 used to generate the baud value and the line_config which is used to specify 638 the line configuration (bit length, stop bits and parity). 639 640 @param this_uart 641 The this_uart parameter is a pointer to an mss_uart_instance_t 642 structure identifying the MSS UART hardware block that will perform 643 the requested function. There are two such data structures, 644 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 645 This parameter must point to either the g_mss_uart0 or g_mss_uart1 646 global data structure defined within the UART driver. 647 648 @param baud_rate 649 The baud_rate parameter specifies the baud rate. It can be specified for 650 common baud rates� using the following defines: 651 � MSS_UART_110_BAUD 652 � MSS_UART_300_BAUD 653 � MSS_UART_1200_BAUD 654 � MSS_UART_2400_BAUD 655 � MSS_UART_4800_BAUD 656 � MSS_UART_9600_BAUD 657 � MSS_UART_19200_BAUD 658 � MSS_UART_38400_BAUD 659 � MSS_UART_57600_BAUD 660 � MSS_UART_115200_BAUD 661 � MSS_UART_230400_BAUD 662 � MSS_UART_460800_BAUD 663 � MSS_UART_921600_BAUD 664 Alternatively, any nonstandard baud rate can be specified by simply passing 665 the actual required baud rate as the value for this parameter. 666 667 @param line_config 668 The line_config parameter is the line configuration specifying the bit length, 669 number of stop bits and parity settings. This is a bitwise OR of one value 670 from each of the following groups of allowed values: 671 � One of the following to specify the transmit/receive data bit length: 672 MSS_UART_DATA_5_BITS 673 MSS_UART_DATA_6_BITS, 674 MSS_UART_DATA_7_BITS 675 MSS_UART_DATA_8_BITS 676 � One of the following to specify the parity setting: 677 MSS_UART_NO_PARITY 678 MSS_UART_EVEN_PARITY 679 MSS_UART_ODD_PARITY 680 MSS_UART_STICK_PARITY_0 681 MSS_UART_STICK_PARITY_1 682 � One of the following to specify the number of stop bits: 683 MSS_UART_ONE_STOP_BIT 684 MSS_UART_ONEHALF_STOP_BIT 685 MSS_UART_TWO_STOP_BITS 686 687 @return 688 This function does not return a value. 689 690 Example: 691 @code 692 #include "mss_uart.h" 693 694 int main(void) 695 { 696 MSS_UART_lin_init(&g_mss_uart0, 697 MSS_UART_57600_BAUD, 698 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 699 700 return(0); 701 } 702 @endcode 703 */ 704 void 705 MSS_UART_lin_init 706 ( 707 mss_uart_instance_t* this_uart, 708 uint32_t baud_rate, 709 uint8_t line_config 710 ); 711 712 /***************************************************************************//** 713 The MSS_UART_irda_init() function is used to initialize the MSS UART instance 714 referenced by the parameter this_uart for IrDA mode of operation. This 715 function must be called before calling any other IrDA functionality specific 716 functions. 717 718 @param this_uart 719 The this_uart parameter is a pointer to an mss_uart_instance_t 720 structure identifying the MSS UART hardware block that will perform 721 the requested function. There are two such data structures, 722 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 723 This parameter must point to either the g_mss_uart0 or g_mss_uart1 724 global data structure defined within the UART driver. 725 726 @param baud_rate 727 The baud_rate parameter specifies the baud rate. It can be specified for 728 common baud rates� using the following defines: 729 � MSS_UART_110_BAUD 730 � MSS_UART_300_BAUD 731 � MSS_UART_1200_BAUD 732 � MSS_UART_2400_BAUD 733 � MSS_UART_4800_BAUD 734 � MSS_UART_9600_BAUD 735 � MSS_UART_19200_BAUD 736 � MSS_UART_38400_BAUD 737 � MSS_UART_57600_BAUD 738 � MSS_UART_115200_BAUD 739 � MSS_UART_230400_BAUD 740 � MSS_UART_460800_BAUD 741 � MSS_UART_921600_BAUD 742 Alternatively, any nonstandard baud rate can be specified by simply passing 743 the actual required baud rate as the value for this parameter. 744 745 @param line_config 746 The line_config parameter is the line configuration specifying the bit length, 747 number of stop bits and parity settings. This is a bitwise OR of one value 748 from each of the following groups of allowed values: 749 � One of the following to specify the transmit/receive data bit length: 750 MSS_UART_DATA_5_BITS 751 MSS_UART_DATA_6_BITS, 752 MSS_UART_DATA_7_BITS 753 MSS_UART_DATA_8_BITS 754 � One of the following to specify the parity setting: 755 MSS_UART_NO_PARITY 756 MSS_UART_EVEN_PARITY 757 MSS_UART_ODD_PARITY 758 MSS_UART_STICK_PARITY_0 759 MSS_UART_STICK_PARITY_1 760 � One of the following to specify the number of stop bits: 761 MSS_UART_ONE_STOP_BIT 762 MSS_UART_ONEHALF_STOP_BIT 763 MSS_UART_TWO_STOP_BITS 764 765 @return 766 This function does not return a value. 767 768 Example: 769 @code 770 MSS_UART_irda_init(&g_mss_uart0, 771 MSS_UART_57600_BAUD, 772 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT, 773 MSS_UART_ACTIVE_LOW, 774 MSS_UART_ACTIVE_LOW, 775 MSS_UART_3_BY_16); 776 @endcode 777 */ 778 void 779 MSS_UART_irda_init 780 ( 781 mss_uart_instance_t* this_uart, 782 uint32_t baud_rate, 783 uint8_t line_config, 784 mss_uart_rzi_polarity_t rxpol, 785 mss_uart_rzi_polarity_t txpol, 786 mss_uart_rzi_pulsewidth_t pw 787 ); 788 789 /***************************************************************************//** 790 The MSS_UART_smartcard_init() function is used to initialize the MSS UART 791 for ISO 7816 (smartcard) mode of operation. The configuration parameters are 792 the baud_rate which is used to generate the baud value and the line_config 793 which is used to specify the line configuration (bit length, stop bits and parity). 794 This function disables all other modes of the MSS UART instance pointed by 795 the parameter this_uart. 796 797 @param this_uart 798 The this_uart parameter is a pointer to an mss_uart_instance_t 799 structure identifying the MSS UART hardware block that will perform 800 the requested function. There are two such data structures, 801 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 802 This parameter must point to either the g_mss_uart0 or g_mss_uart1 803 global data structure defined within the UART driver. 804 805 @param baud_rate 806 The baud_rate parameter specifies the baud rate. It can be specified for 807 common baud rates� using the following defines: 808 � MSS_UART_110_BAUD 809 � MSS_UART_300_BAUD 810 � MSS_UART_1200_BAUD 811 � MSS_UART_2400_BAUD 812 � MSS_UART_4800_BAUD 813 � MSS_UART_9600_BAUD 814 � MSS_UART_19200_BAUD 815 � MSS_UART_38400_BAUD 816 � MSS_UART_57600_BAUD 817 � MSS_UART_115200_BAUD 818 � MSS_UART_230400_BAUD 819 � MSS_UART_460800_BAUD 820 � MSS_UART_921600_BAUD 821 Alternatively, any nonstandard baud rate can be specified by simply passing 822 the actual required baud rate as the value for this parameter. 823 824 @param line_config 825 The line_config parameter is the line configuration specifying the bit length, 826 number of stop bits and parity settings. This is a bitwise OR of one value 827 from each of the following groups of allowed values: 828 � One of the following to specify the transmit/receive data bit length: 829 MSS_UART_DATA_5_BITS 830 MSS_UART_DATA_6_BITS, 831 MSS_UART_DATA_7_BITS 832 MSS_UART_DATA_8_BITS 833 � One of the following to specify the parity setting: 834 MSS_UART_NO_PARITY 835 MSS_UART_EVEN_PARITY 836 MSS_UART_ODD_PARITY 837 MSS_UART_STICK_PARITY_0 838 MSS_UART_STICK_PARITY_1 839 � One of the following to specify the number of stop bits: 840 MSS_UART_ONE_STOP_BIT 841 MSS_UART_ONEHALF_STOP_BIT 842 MSS_UART_TWO_STOP_BITS 843 844 @return 845 This function does not return a value. 846 847 Example: 848 @code 849 #include "mss_uart.h" 850 851 int main(void) 852 { 853 MSS_UART_smartcard_init(&g_mss_uart0, 854 MSS_UART_57600_BAUD, 855 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 856 857 return(0); 858 } 859 @endcode 860 */ 861 void 862 MSS_UART_smartcard_init 863 ( 864 mss_uart_instance_t* this_uart, 865 uint32_t baud_rate, 866 uint8_t line_config 867 ); 868 869 /***************************************************************************//** 870 The function MSS_UART_polled_tx() is used to transmit data. It transfers the 871 contents of the transmitter data buffer, passed as a function parameter, into 872 the UART�s hardware transmitter FIFO. It returns when the full content of the 873 transmit data buffer has been transferred to the UART�s transmit FIFO. It is 874 safe to release or reuse the memory used as the transmitter data buffer once 875 this function returns. 876 877 Note: This function reads the UART�s line status register (LSR) to poll 878 for the active state of the transmitter holding register empty (THRE) bit 879 before transferring data from the data buffer to the transmitter FIFO. It 880 transfers data to the transmitter FIFO in blocks of 16 bytes or less and 881 allows the FIFO to empty before transferring the next block of data. 882 883 Note: The actual transmission over the serial connection will still be 884 in progress when this function returns. Use the MSS_UART_get_tx_status() 885 function if you need to know when the transmitter is empty. 886 887 @param this_uart 888 The this_uart parameter is a pointer to an mss_uart_instance_t 889 structure identifying the MSS UART hardware block that will perform 890 the requested function. There are two such data structures, 891 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 892 This parameter must point to either the g_mss_uart0 or g_mss_uart1 893 global data structure defined within the UART driver. 894 895 @param pbuff 896 The pbuff parameter is a pointer to a buffer containing the data to 897 be transmitted. 898 899 @param tx_size 900 The tx_size parameter specifies the size, in bytes, of the data to 901 be transmitted. 902 903 @return 904 This function does not return a value. 905 906 Example: 907 @code 908 #include "mss_uart.h" 909 910 int main(void) 911 { 912 uint8_t message[12] = "Hello World"; 913 914 MSS_UART_init(&g_mss_uart0, 915 MSS_UART_57600_BAUD, 916 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 917 918 MSS_UART_polled_tx(&g_mss_uart0, message, sizeof(message)); 919 920 return(0); 921 } 922 @endcode 923 */ 924 void 925 MSS_UART_polled_tx 926 ( 927 mss_uart_instance_t * this_uart, 928 const uint8_t * pbuff, 929 uint32_t tx_size 930 ); 931 932 /***************************************************************************//** 933 The function MSS_UART_polled_tx_string() is used to transmit a NULL ('\0') 934 terminated string. It transfers the text string, from the buffer starting at 935 the address pointed to by p_sz_string into the UART�s hardware transmitter 936 FIFO. It returns when the complete string has been transferred to the UART's 937 transmit FIFO. It is safe to release or reuse the memory used as the string 938 buffer once this function returns. 939 940 Note: This function reads the UART�s line status register (LSR) to poll 941 for the active state of the transmitter holding register empty (THRE) bit 942 before transferring data from the data buffer to the transmitter FIFO. It 943 transfers data to the transmitter FIFO in blocks of 16 bytes or less and 944 allows the FIFO to empty before transferring the next block of data. 945 946 Note: The actual transmission over the serial connection will still be 947 in progress when this function returns. Use the MSS_UART_get_tx_status() 948 function if you need to know when the transmitter is empty. 949 950 @param this_uart 951 The this_uart parameter is a pointer to an mss_uart_instance_t 952 structure identifying the MSS UART hardware block that will perform 953 the requested function. There are two such data structures, 954 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 955 This parameter must point to either the g_mss_uart0 or g_mss_uart1 956 global data structure defined within the UART driver. 957 958 @param p_sz_string 959 The p_sz_string parameter is a pointer to a buffer containing the NULL 960 ('\0') terminated string to be transmitted. 961 962 @return 963 This function does not return a value. 964 965 Example: 966 @code 967 #include "mss_uart.h" 968 969 int main(void) 970 { 971 uint8_t message[12] = "Hello World"; 972 973 MSS_UART_init(&g_mss_uart0, 974 MSS_UART_57600_BAUD, 975 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 976 977 MSS_UART_polled_tx_string(&g_mss_uart0, message); 978 979 return(0); 980 } 981 @endcode 982 983 */ 984 void 985 MSS_UART_polled_tx_string 986 ( 987 mss_uart_instance_t * this_uart, 988 const uint8_t * p_sz_string 989 ); 990 991 992 /***************************************************************************//** 993 The function MSS_UART_irq_tx() is used to initiate an interrupt-driven 994 transmit. It returns immediately after making a note of the transmit buffer 995 location and enabling transmit interrupts both at the UART and Cortex-M3 NVIC 996 level. This function takes a pointer via the pbuff parameter to a memory 997 buffer containing the data to transmit. The memory buffer specified through 998 this pointer must remain allocated and contain the data to transmit until 999 the transmit completion has been detected through calls to function 1000 MSS_UART_tx_complete(). The actual transmission over the serial connection 1001 is still in progress until calls to the MSS_UART_tx_complete() function 1002 indicate transmit completion. 1003 1004 Note: The MSS_UART_irq_tx() function enables both the transmit holding 1005 register empty (THRE) interrupt in the UART and the MSS UART instance 1006 interrupt in the Cortex-M3 NVIC as part of its implementation. 1007 1008 Note: The MSS_UART_irq_tx() function assigns an internal default transmit 1009 interrupt handler function to the UART�s THRE interrupt. This interrupt 1010 handler overrides any custom interrupt handler that you may have previously 1011 registered using the MSS_UART_set_tx_handler() function. 1012 1013 Note: The MSS_UART_irq_tx() function�s default transmit interrupt 1014 handler disables the UART�s THRE interrupt when all of the data has 1015 been transferred to the UART's transmit FIFO. 1016 1017 1018 @param this_uart 1019 The this_uart parameter is a pointer to an mss_uart_instance_t 1020 structure identifying the MSS UART hardware block that will perform 1021 the requested function. There are two such data structures, 1022 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1023 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1024 global data structure defined within the UART driver. 1025 1026 @param pbuff 1027 The pbuff parameter is a pointer to a buffer containing the data 1028 to be transmitted. 1029 1030 @param tx_size 1031 The tx_size parameter specifies the size, in bytes, of the data 1032 to be transmitted. 1033 1034 @return 1035 This function does not return a value. 1036 1037 Example: 1038 @code 1039 #include "mss_uart.h" 1040 1041 int main(void) 1042 { 1043 uint8_t tx_buff[10] = "abcdefghi"; 1044 1045 MSS_UART_init(&g_mss_uart0, 1046 MSS_UART_57600_BAUD, 1047 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 1048 1049 MSS_UART_irq_tx(&g_mss_uart0, tx_buff, sizeof(tx_buff)); 1050 1051 while(0 == MSS_UART_tx_complete(&g_mss_uart0)) 1052 { 1053 ; 1054 } 1055 return(0); 1056 } 1057 @endcode 1058 */ 1059 void 1060 MSS_UART_irq_tx 1061 ( 1062 mss_uart_instance_t * this_uart, 1063 const uint8_t * pbuff, 1064 uint32_t tx_size 1065 ); 1066 1067 /***************************************************************************//** 1068 The MSS_UART_tx_complete() function is used to find out if the interrupt-driven 1069 transmit previously initiated through a call to MSS_UART_irq_tx() is complete. 1070 This is typically used to find out when it is safe to reuse or release the 1071 memory buffer holding transmit data. 1072 1073 Note: The transfer of all of the data from the memory buffer to the UART�s 1074 transmit FIFO and the actual transmission over the serial connection are both 1075 complete when a call to the MSS_UART_tx_complete() function indicates transmit 1076 completion. 1077 1078 @param this_uart 1079 The this_uart parameter is a pointer to an mss_uart_instance_t 1080 structure identifying the MSS UART hardware block that will perform 1081 the requested function. There are two such data structures, 1082 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1083 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1084 global data structure defined within the UART driver. 1085 1086 @return 1087 This function return a non-zero value if transmit has completed, otherwise 1088 it returns zero. 1089 1090 Example: 1091 See the MSS_UART_irq_tx() function for an example that uses the 1092 MSS_UART_tx_complete() function. 1093 */ 1094 int8_t 1095 MSS_UART_tx_complete 1096 ( 1097 mss_uart_instance_t * this_uart 1098 ); 1099 1100 /***************************************************************************//** 1101 The MSS_UART_get_rx() function reads the content of the UART receiver�s FIFO 1102 and stores it in the receive buffer that is passed via the rx_buff function 1103 parameter. It copies either the full contents of the FIFO into the receive 1104 buffer, or just enough data from the FIFO to fill the receive buffer, 1105 dependent upon the size of the receive buffer passed by the buff_size 1106 parameter. The MSS_UART_get_rx() function returns the number of bytes copied 1107 into the receive buffer .This function is non-blocking and will return 0 1108 immediately if no data has been received. 1109 1110 Note: The MSS_UART_get_rx() function reads and accumulates the receiver 1111 status of the MSS UART instance before reading each byte from the receiver's 1112 data register/FIFO. This allows the driver to maintain a sticky record of any 1113 receiver errors that occur as the UART receives each data byte; receiver 1114 errors would otherwise be lost after each read from the receiver's data register. 1115 A call to the MSS_UART_get_rx_status() function returns any receiver errors 1116 accumulated during the execution of the MSS_UART_get_rx() function. 1117 1118 Note: If you need to read the error status for each byte received, set 1119 the buff_size to 1 and read the receive line error status for each byte 1120 using the MSS_UART_get_rx_status() function. 1121 The MSS_UART_get_rx() function can be used in polled mode, where it is called 1122 at regular intervals to find out if any data has been received, or in interrupt 1123 driven-mode, where it is called as part of a receive handler that is called 1124 by the driver as a result of data being received. 1125 1126 Note: In interrupt driven mode you should call the MSS_UART_get_rx() 1127 function as part of the receive handler function that you register with 1128 the MSS UART driver through a call to MSS_UART_set_rx_handler(). 1129 1130 @param this_uart 1131 The this_uart parameter is a pointer to an mss_uart_instance_t 1132 structure identifying the MSS UART hardware block that will perform 1133 the requested function. There are two such data structures, 1134 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1135 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1136 global data structure defined within the UART driver. 1137 1138 @param rx_buff 1139 The rx_buff parameter is a pointer to a buffer where the received 1140 data is copied. 1141 1142 @param buff_size 1143 The buff_size parameter specifies the size of the receive buffer in bytes. 1144 1145 @return 1146 This function returns the number of bytes that were copied into the 1147 rx_buff buffer. It returns 0 if no data has been received. 1148 1149 Polled mode example: 1150 @code 1151 int main( void ) 1152 { 1153 uint8_t rx_buff[RX_BUFF_SIZE]; 1154 uint32_t rx_idx = 0; 1155 1156 MSS_UART_init(&g_mss_uart0, 1157 MSS_UART_57600_BAUD, 1158 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 1159 1160 while(1) 1161 { 1162 rx_size = MSS_UART_get_rx(&g_mss_uart0, rx_buff, sizeof(rx_buff)); 1163 if(rx_size > 0) 1164 { 1165 process_rx_data(rx_buff, rx_size); 1166 } 1167 task_a(); 1168 task_b(); 1169 } 1170 return 0; 1171 } 1172 @endcode 1173 1174 Interrupt driven example: 1175 @code 1176 int main( void ) 1177 { 1178 MSS_UART_init(&g_mss_uart1, 1179 MSS_UART_57600_BAUD, 1180 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 1181 1182 MSS_UART_set_rx_handler(&g_mss_uart1, 1183 uart1_rx_handler, 1184 MSS_UART_FIFO_SINGLE_BYTE); 1185 1186 while(1) 1187 { 1188 task_a(); 1189 task_b(); 1190 } 1191 return 0; 1192 } 1193 1194 void uart1_rx_handler(mss_uart_instance_t * this_uart) 1195 { 1196 uint8_t rx_buff[RX_BUFF_SIZE]; 1197 uint32_t rx_idx = 0; 1198 rx_size = MSS_UART_get_rx(this_uart, rx_buff, sizeof(rx_buff)); 1199 process_rx_data(rx_buff, rx_size); 1200 } 1201 @endcode 1202 */ 1203 size_t 1204 MSS_UART_get_rx 1205 ( 1206 mss_uart_instance_t * this_uart, 1207 uint8_t * rx_buff, 1208 size_t buff_size 1209 ); 1210 1211 /***************************************************************************//** 1212 The MSS_UART_set_rx_handler() function is used to register a receive handler 1213 function that is called by the driver when a UART receive data available (RDA) 1214 interrupt occurs. You must create and register the receive handler function 1215 to suit your application and it must include a call to the MSS_UART_get_rx() 1216 function to actually read the received data. 1217 1218 Note: The MSS_UART_set_rx_handler() function enables both the RDA 1219 interrupt in the UART and the MSS UART instance interrupt in the Cortex-M3 1220 NVIC as part 1221 of its implementation. 1222 1223 Note: You can disable the RDA interrupt once the data is received by 1224 calling the MSS_UART_disable_irq() function. This is your choice and is 1225 dependent upon your application. 1226 1227 1228 @param this_uart 1229 The this_uart parameter is a pointer to an mss_uart_instance_t 1230 structure identifying the MSS UART hardware block that will perform 1231 the requested function. There are two such data structures, 1232 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1233 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1234 global data structure defined within the UART driver. 1235 1236 @param handler 1237 The handler parameter is a pointer to a receive interrupt handler function 1238 provided by your application that will be called as a result of a UART RDA 1239 interrupt. This handler function must be of type mss_uart_irq_handler_t. 1240 1241 @param trigger_level 1242 The trigger_level parameter is the receive FIFO trigger level. This 1243 specifies the number of bytes that must be received before the UART 1244 triggers an RDA interrupt. 1245 1246 @return 1247 This function does not return a value. 1248 1249 Example: 1250 @code 1251 #include "mss_uart.h" 1252 1253 #define RX_BUFF_SIZE 64 1254 1255 uint8_t g_rx_buff[RX_BUFF_SIZE]; 1256 1257 void uart0_rx_handler(mss_uart_instance_t * this_uart) 1258 { 1259 MSS_UART_get_rx(this_uart, &g_rx_buff[g_rx_idx], sizeof(g_rx_buff)); 1260 } 1261 1262 int main(void) 1263 { 1264 MSS_UART_init(&g_mss_uart0, 1265 MSS_UART_57600_BAUD, 1266 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 1267 1268 MSS_UART_set_rx_handler(&g_mss_uart0, 1269 uart0_rx_handler, 1270 MSS_UART_FIFO_SINGLE_BYTE); 1271 1272 while(1) 1273 { 1274 ; 1275 } 1276 return(0); 1277 } 1278 @endcode 1279 */ 1280 void 1281 MSS_UART_set_rx_handler 1282 ( 1283 mss_uart_instance_t * this_uart, 1284 mss_uart_irq_handler_t handler, 1285 mss_uart_rx_trig_level_t trigger_level 1286 ); 1287 1288 /***************************************************************************//** 1289 The MSS_UART_set_loopback() function is used to locally loopback the Tx and 1290 Rx lines of a UART. This is not to be confused with the loopback of UART0 1291 to UART1, which can be achieved through the microcontroller subsystem�s 1292 system registers. 1293 1294 @param this_uart 1295 The this_uart parameter is a pointer to an mss_uart_instance_t 1296 structure identifying the MSS UART hardware block that will perform 1297 the requested function. There are two such data structures, 1298 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1299 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1300 global data structure defined within the UART driver. 1301 1302 @param loopback 1303 The loopback parameter indicates whether or not the UART�s transmit 1304 and receive lines should be looped back. Allowed values are as follows: 1305 - MSS_UART_LOCAL_LOOPBACK_ON 1306 - MSS_UART_LOCAL_LOOPBACK_OFF 1307 - MSS_UART_REMOTE_LOOPBACK_ON 1308 - MSS_UART_REMOTE_LOOPBACK_OFF 1309 - MSS_UART_AUTO_ECHO_ON 1310 - MSS_UART_AUTO_ECHO_OFF 1311 1312 @return 1313 This function does not return a value. 1314 1315 Example: 1316 @code 1317 MSS_UART_init(&g_mss_uart0, 1318 MSS_UART_57600_BAUD, 1319 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 1320 1321 MSS_UART_set_loopback(&g_mss_uart0, MSS_UART_LOCAL_LOOPBACK_OFF); 1322 @endcode 1323 */ 1324 void 1325 MSS_UART_set_loopback 1326 ( 1327 mss_uart_instance_t * this_uart, 1328 mss_uart_loopback_t loopback 1329 ); 1330 1331 /***************************************************************************//** 1332 The MSS_UART_enable_irq() function enables the MSS UART interrupts specified 1333 by the irq_mask parameter. The irq_mask parameter identifies the MSS UART 1334 interrupts by bit position, as defined in the interrupt enable register (IER) 1335 of MSS UART. The MSS UART interrupts and their identifying irq_mask bit 1336 positions are as follows: 1337 When an irq_mask bit position is set to 1, this function enables the 1338 corresponding MSS UART interrupt in the IER register. When an irq_mask bit 1339 position is set to 0, the corresponding interrupt�s state remains unchanged in 1340 the IER register. 1341 Note: The MSS_UART_enable_irq() function also enables the MSS UART instance 1342 interrupt in the Cortex-M3 NVIC. 1343 1344 @param this_uart 1345 The this_uart parameter is a pointer to an mss_uart_instance_t structure 1346 identifying the MSS UART hardware block that will perform the requested 1347 function. There are two such data structures, g_mss_uart0 and g_mss_uart1, 1348 associated with MSS UART0 and MSS UART1. This parameter must point to either 1349 the g_mss_uart0 or g_mss_uart1 global data structure defined within the UART 1350 driver. 1351 1352 @param irq_mask 1353 The irq_mask parameter is used to select which of the MSS UART�s interrupts 1354 you want to enable. The allowed value for the irq_mask parameter is one of 1355 the following constants or a bitwise OR of more than one: 1356 - MSS_UART_RBF_IRQ (bit mask = 0x001) 1357 - MSS_UART_TBE_IRQ (bit mask = 0x002) 1358 - MSS_UART_LS_IRQ (bit mask = 0x004) 1359 - MSS_UART_MS_IRQ (bit mask = 0x008) 1360 - MSS_UART_RTO_IRQ (bit mask = 0x010) 1361 - MSS_UART_NACK_IRQ (bit mask = 0x020) 1362 - MSS_UART_PIDPE_IRQ (bit mask = 0x040) 1363 - MSS_UART_LINB_IRQ (bit mask = 0x080) 1364 - MSS_UART_LINS_IRQ (bit mask = 0x100) 1365 1366 @return 1367 This function does not return a value. 1368 1369 Example: 1370 @code 1371 MSS_UART_enable_irq(&g_mss_uart0,(MSS_UART_RBF_IRQ | MSS_UART_TBE_IRQ)); 1372 @endcode 1373 */ 1374 void 1375 MSS_UART_enable_irq 1376 ( 1377 mss_uart_instance_t * this_uart, 1378 mss_uart_irq_t irq_mask 1379 ); 1380 1381 /***************************************************************************//** 1382 The MSS_UART_disable_irq() function disables the MSS UART interrupts specified 1383 by the irq_mask parameter. The irq_mask parameter identifies the MSS UART 1384 interrupts by bit position, as defined in the interrupt enable register (IER) 1385 of MSS UART. The MSS UART interrupts and their identifying bit positions are 1386 as follows: 1387 When an irq_mask bit position is set to 1, this function disables the 1388 corresponding MSS UART interrupt in the IER register. When an irq_mask bit 1389 position is set to 0, the corresponding interrupt�s state remains unchanged in 1390 the IER register. 1391 Note: If you disable all four of the UART�s interrupts, the 1392 MSS_UART_disable_irq() function also disables the MSS UART instance 1393 interrupt in the Cortex-M3 NVIC. 1394 1395 @param this_uart 1396 The this_uart parameter is a pointer to an mss_uart_instance_t 1397 structure identifying the MSS UART hardware block that will perform 1398 the requested function. There are two such data structures, 1399 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1400 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1401 global data structure defined within the UART driver. 1402 1403 @param irq_mask 1404 The irq_mask parameter is used to select which of the MSS UART�s interrupts 1405 you want to disable. The allowed value for the irq_mask parameter is one of 1406 the following constants or a bitwise OR of more than one: 1407 - MSS_UART_RBF_IRQ (bit mask = 0x001) 1408 - MSS_UART_TBE_IRQ (bit mask = 0x002) 1409 - MSS_UART_LS_IRQ (bit mask = 0x004) 1410 - MSS_UART_MS_IRQ (bit mask = 0x008) 1411 - MSS_UART_RTO_IRQ (bit mask = 0x010) 1412 - MSS_UART_NACK_IRQ (bit mask = 0x020) 1413 - MSS_UART_PIDPE_IRQ (bit mask = 0x040) 1414 - MSS_UART_LINB_IRQ (bit mask = 0x080) 1415 - MSS_UART_LINS_IRQ (bit mask = 0x100) 1416 1417 @return 1418 This function does not return a value. 1419 1420 Example: 1421 @code 1422 MSS_UART_disable_irq(&g_mss_uart0, (MSS_UART_RBF_IRQ | MSS_UART_TBE_IRQ)); 1423 @endcode 1424 */ 1425 void 1426 MSS_UART_disable_irq 1427 ( 1428 mss_uart_instance_t * this_uart, 1429 mss_uart_irq_t irq_mask 1430 ); 1431 1432 /***************************************************************************//** 1433 The MSS_UART_set_pidpei_handler() function is used assign a custom interrupt 1434 handler for the PIDPEI (PID parity error interrupt) when the MSS UART is 1435 operating in LIN mode. 1436 1437 @param this_uart 1438 The this_uart parameter is a pointer to an mss_uart_instance_t 1439 structure identifying the MSS UART hardware block that will perform 1440 the requested function. There are two such data structures, 1441 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1442 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1443 global data structure defined within the UART driver. 1444 1445 @param handler 1446 The handler parameter is the pointer to the custom handler function. 1447 This parameter is of type mss_uart_irq_handler_t. 1448 1449 @return 1450 This function does not return a value. 1451 1452 Example: 1453 @code 1454 MSS_UART_ set_pidpei_handler(&g_mss_uart0, my_pidpei_handler); 1455 @endcode 1456 */ 1457 void 1458 MSS_UART_set_pidpei_handler 1459 ( 1460 mss_uart_instance_t * this_uart, 1461 mss_uart_irq_handler_t handler 1462 ); 1463 1464 /***************************************************************************//** 1465 The MSS_UART_set_linbreak_handler () function is used assign a custom 1466 interrupt handler for the LIN Break detection interrupt when the MSS UART 1467 is operating in LIN mode. 1468 1469 @param this_uart 1470 The this_uart parameter is a pointer to an mss_uart_instance_t 1471 structure identifying the MSS UART hardware block that will perform 1472 the requested function. There are two such data structures, 1473 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1474 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1475 global data structure defined within the UART driver. 1476 1477 @param handler 1478 The handler parameter is the pointer to the custom handler function. 1479 This parameter is of type mss_uart_irq_handler_t. 1480 1481 @return 1482 This function does not return a value. 1483 Example: 1484 @code 1485 MSS_UART_set_linbreak_handler(&g_mss_uart0, my_break_handler); 1486 @endcode 1487 */ 1488 void 1489 MSS_UART_set_linbreak_handler 1490 ( 1491 mss_uart_instance_t * this_uart, 1492 mss_uart_irq_handler_t handler 1493 ); 1494 1495 /***************************************************************************//** 1496 The MSS_UART_set_linsync_handler() function is used assign a custom interrupt 1497 handler for the LIN Sync character detection interrupt when the MSS UART 1498 is operating in LIN mode. 1499 1500 @param this_uart 1501 The this_uart parameter is a pointer to an mss_uart_instance_t 1502 structure identifying the MSS UART hardware block that will perform 1503 the requested function. There are two such data structures, 1504 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1505 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1506 global data structure defined within the UART driver. 1507 1508 @param handler 1509 The handler parameter is the pointer to the custom handler function. 1510 This parameter is of type mss_uart_irq_handler_t. 1511 1512 @return 1513 This function does not return a value. 1514 Example: 1515 @code 1516 MSS_UART_set_linsync_handler(&g_mss_uart0, my_linsync_handler); 1517 @endcode 1518 */ 1519 void 1520 MSS_UART_set_linsync_handler 1521 ( 1522 mss_uart_instance_t * this_uart, 1523 mss_uart_irq_handler_t handler 1524 ); 1525 1526 /***************************************************************************//** 1527 The MSS_UART_set_nack_handler() function is used assign a custom interrupt 1528 handler for the NACK character detection interrupt when the MSS UART 1529 is operating in Smartcard mode. 1530 1531 @param this_uart 1532 The this_uart parameter is a pointer to an mss_uart_instance_t 1533 structure identifying the MSS UART hardware block that will perform 1534 the requested function. There are two such data structures, 1535 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1536 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1537 global data structure defined within the UART driver. 1538 1539 @param handler 1540 The handler parameter is the pointer to the custom handler function. 1541 This parameter is of type mss_uart_irq_handler_t. 1542 1543 @return 1544 This function does not return a value. 1545 Example: 1546 @code 1547 MSS_UART_set_nack_handler(&g_mss_uart0, my_nack_handler); 1548 @endcode 1549 */ 1550 void 1551 MSS_UART_set_nack_handler 1552 ( 1553 mss_uart_instance_t * this_uart, 1554 mss_uart_irq_handler_t handler 1555 ); 1556 1557 /***************************************************************************//** 1558 The MSS_UART_set_rx_timeout_handler() function is used assign a custom 1559 interrupt handler for the receiver timeout interrupt when the MSS UART is 1560 operating in mode. It finds application in IrDA mode of operation. 1561 1562 @param this_uart 1563 The this_uart parameter is a pointer to an mss_uart_instance_t 1564 structure identifying the MSS UART hardware block that will perform 1565 the requested function. There are two such data structures, 1566 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1567 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1568 global data structure defined within the UART driver. 1569 1570 @param handler 1571 The handler parameter is the pointer to the custom handler function. 1572 This parameter is of type mss_uart_irq_handler_t. 1573 1574 @return 1575 This function does not return a value. 1576 Example: 1577 @code 1578 MSS_UART_set_rx_timeout_handler(&g_mss_uart0, my_rxtimeout_handler); 1579 @endcode 1580 */ 1581 void 1582 MSS_UART_set_rx_timeout_handler 1583 ( 1584 mss_uart_instance_t * this_uart, 1585 mss_uart_irq_handler_t handler 1586 ); 1587 1588 /***************************************************************************//** 1589 The MSS_UART_set_rxstatus_handler() function is used to register a receiver 1590 status handler function that is called by the driver when a UART receiver 1591 line status (RLS) interrupt occurs. You must create and register the handler 1592 function to suit your application. 1593 1594 Note: The MSS_UART_set_rxstatus_handler() function enables both the RLS 1595 interrupt in the UART and the MSS UART instance interrupt in the Cortex-M3 1596 NVIC as part of its implementation. 1597 1598 Note: You can disable the RLS interrupt when required by calling the 1599 MSS_UART_disable_irq() function. This is your choice and is dependent upon 1600 your application. 1601 1602 @param this_uart 1603 The this_uart parameter is a pointer to an mss_uart_instance_t 1604 structure identifying the MSS UART hardware block that will perform 1605 the requested function. There are two such data structures, 1606 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1607 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1608 global data structure defined within the UART driver. 1609 1610 @param handler 1611 The handler parameter is a pointer to a receiver line status interrupt 1612 handler function provided by your application that will be called as a 1613 result of a UART RLS interrupt. This handler function must be of type 1614 mss_uart_irq_handler_t. 1615 1616 @return 1617 This function does not return a value. 1618 1619 Example: 1620 @code 1621 #include "mss_uart.h" 1622 1623 void uart_rxsts_handler(mss_uart_instance_t * this_uart) 1624 { 1625 uint8_t status; 1626 status = MSS_UART_get_rx_status(this_uart); 1627 if(status & MSS_UART_OVERUN_ERROR) 1628 { 1629 discard_rx_data(); 1630 } 1631 } 1632 1633 int main(void) 1634 { 1635 MSS_UART_init( &g_mss_uart0, 1636 MSS_UART_57600_BAUD, 1637 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | 1638 MSS_UART_ONE_STOP_BIT ); 1639 1640 MSS_UART_set_rxstatus_handler(&g_mss_uart0, uart_rxsts_handler); 1641 1642 while(1) 1643 { 1644 ; 1645 } 1646 return(0); 1647 } 1648 @endcode 1649 */ 1650 void 1651 MSS_UART_set_rxstatus_handler 1652 ( 1653 mss_uart_instance_t * this_uart, 1654 mss_uart_irq_handler_t handler 1655 ); 1656 1657 /***************************************************************************//** 1658 The MSS_UART_set_tx_handler() function is used to register a transmit handler 1659 function that is called by the driver when a UART transmit holding register 1660 empty (THRE) interrupt occurs. You must create and register the transmit 1661 handler function to suit your application. You can use the 1662 MSS_UART_fill_tx_fifo() function in your transmit handler function to 1663 write data to the transmitter. 1664 1665 Note: The MSS_UART_set_tx_handler() function enables both the THRE 1666 interrupt in the UART and the MSS UART instance interrupt in the Cortex-M3 1667 NVIC as part of its implementation. 1668 1669 Note: You can disable the THRE interrupt when required by calling the 1670 MSS_UART_disable_irq() function. This is your choice and is dependent upon 1671 your application. 1672 1673 Note: The MSS_UART_irq_tx() function does not use the transmit handler 1674 function that you register with the MSS_UART_set_tx_handler() function. 1675 It uses its own internal THRE interrupt handler function that overrides 1676 any custom interrupt handler that you register using the 1677 MSS_UART_set_tx_handler() function. 1678 1679 @param this_uart 1680 The this_uart parameter is a pointer to an mss_uart_instance_t 1681 structure identifying the MSS UART hardware block that will perform 1682 the requested function. There are two such data structures, 1683 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1684 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1685 global data structure defined within the UART driver. 1686 1687 @param handler 1688 The handler parameter is a pointer to a transmit interrupt handler 1689 function provided by your application that will be called as a result 1690 of a UART THRE interrupt. This handler function must be of type 1691 mss_uart_irq_handler_t. 1692 1693 @return 1694 This function does not return a value. 1695 1696 Example: 1697 @code 1698 #include "mss_uart.h" 1699 1700 uint8_t * g_tx_buffer; 1701 size_t g_tx_size = 0; 1702 1703 void uart_tx_handler(mss_uart_instance_t * this_uart) 1704 { 1705 size_t size_in_fifo; 1706 size_in_fifo = MSS_UART_fill_tx_fifo(this_uart, 1707 (const uint8_t *)g_tx_buffer, 1708 g_tx_size); 1709 1710 if(size_in_fifo == g_tx_size) 1711 { 1712 g_tx_size = 0; 1713 MSS_UART_disable_irq(this_uart, MSS_UART_TBE_IRQ); 1714 } 1715 else 1716 { 1717 g_tx_buffer = &g_tx_buffer[size_in_fifo]; 1718 g_tx_size = g_tx_size - size_in_fifo; 1719 } 1720 } 1721 1722 int main(void) 1723 { 1724 uint8_t message[12] = "Hello world"; 1725 1726 MSS_UART_init(&g_mss_uart0, 1727 MSS_UART_57600_BAUD, 1728 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | 1729 MSS_UART_ONE_STOP_BIT); 1730 1731 g_tx_buffer = message; 1732 g_tx_size = sizeof(message); 1733 1734 MSS_UART_set_tx_handler(&g_mss_uart0, uart_tx_handler); 1735 1736 while(1) 1737 { 1738 ; 1739 } 1740 return(0); 1741 } 1742 @endcode 1743 */ 1744 void 1745 MSS_UART_set_tx_handler 1746 ( 1747 mss_uart_instance_t * this_uart, 1748 mss_uart_irq_handler_t handler 1749 ); 1750 1751 /***************************************************************************//** 1752 The MSS_UART_set_modemstatus_handler() function is used to register a modem 1753 status handler function that is called by the driver when a UART modem status 1754 (MS) interrupt occurs. You must create and register the handler function to 1755 suit your application. 1756 1757 Note: The MSS_UART_set_modemstatus_handler() function enables both the MS 1758 interrupt in the UART and the MSS UART instance interrupt in the Cortex-M3 NVIC 1759 as part of its implementation. 1760 1761 Note: You can disable the MS interrupt when required by calling the 1762 MSS_UART_disable_irq() function. This is your choice and is dependent 1763 upon your application. 1764 1765 @param this_uart 1766 The this_uart parameter is a pointer to an mss_uart_instance_t 1767 structure identifying the MSS UART hardware block that will perform 1768 the requested function. There are two such data structures, 1769 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1770 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1771 global data structure defined within the UART driver. 1772 1773 @param handler 1774 The handler parameter is a pointer to a modem status interrupt handler 1775 function provided by your application that will be called as a result 1776 of a UART MS interrupt. This handler function must be of type 1777 mss_uart_irq_handler_t. 1778 1779 @return 1780 This function does not return a value. 1781 1782 Example: 1783 @code 1784 #include "mss_uart.h" 1785 1786 void uart_modem_handler(mss_uart_instance_t * this_uart) 1787 { 1788 uint8_t status; 1789 status = MSS_UART_get_modem_status(this_uart); 1790 if(status & MSS_UART_CTS) 1791 { 1792 uart_cts_handler(); 1793 } 1794 } 1795 1796 int main(void) 1797 { 1798 MSS_UART_init(&g_mss_uart0, 1799 MSS_UART_57600_BAUD, 1800 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | 1801 MSS_UART_ONE_STOP_BIT); 1802 MSS_UART_set_modemstatus_handler(&g_mss_uart0, uart_modem_handler); 1803 1804 while(1) 1805 { 1806 ; 1807 } 1808 return(0); 1809 } 1810 @endcode 1811 */ 1812 1813 void 1814 MSS_UART_set_modemstatus_handler 1815 ( 1816 mss_uart_instance_t * this_uart, 1817 mss_uart_irq_handler_t handler 1818 ); 1819 1820 /***************************************************************************//** 1821 The MSS_UART_fill_tx_fifo() function fills the UART's hardware transmitter 1822 FIFO with the data found in the transmitter buffer that is passed via the 1823 tx_buffer function parameter. If the transmitter FIFO is not empty when 1824 the function is called, the function returns immediately without transferring 1825 any data to the FIFO; otherwise, the function transfers data from the 1826 transmitter buffer to the FIFO until it is full or until the complete 1827 contents of the transmitter buffer have been copied into the FIFO. The 1828 function returns the number of bytes copied into the UART's transmitter FIFO. 1829 1830 Note: This function reads the UART�s line status register (LSR) to check 1831 for the active state of the transmitter holding register empty (THRE) bit 1832 before transferring data from the data buffer to the transmitter FIFO. If 1833 THRE is 0, the function returns immediately, without transferring any data 1834 to the FIFO. If THRE is 1, the function transfers up to 16 bytes of data 1835 to the FIFO and then returns. 1836 1837 Note: The actual transmission over the serial connection will still be 1838 in progress when this function returns. Use the MSS_UART_get_tx_status() 1839 function if you need to know when the transmitter is empty. 1840 1841 @param this_uart 1842 The this_uart parameter is a pointer to an mss_uart_instance_t 1843 structure identifying the MSS UART hardware block that will perform 1844 the requested function. There are two such data structures, 1845 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1846 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1847 global data structure defined within the UART driver. 1848 1849 @param tx_buffer 1850 The tx_buffer parameter is a pointer to a buffer containing the data 1851 to be transmitted. 1852 1853 @param tx_size 1854 The tx_size parameter is the size in bytes, of the data to be transmitted. 1855 1856 @return 1857 This function returns the number of bytes copied into the UART's 1858 transmitter FIFO. 1859 1860 Example: 1861 @code 1862 void send_using_interrupt(uint8_t * pbuff, size_t tx_size) 1863 { 1864 size_t size_in_fifo; 1865 size_in_fifo = MSS_UART_fill_tx_fifo(&g_mss_uart0, pbuff, tx_size); 1866 } 1867 @endcode 1868 */ 1869 size_t 1870 MSS_UART_fill_tx_fifo 1871 ( 1872 mss_uart_instance_t * this_uart, 1873 const uint8_t * tx_buffer, 1874 size_t tx_size 1875 ); 1876 1877 /***************************************************************************//** 1878 The MSS_UART_get_rx_status() function returns the receiver error status of the 1879 MSS UART instance. It reads both the current error status of the receiver from 1880 the UART�s line status register (LSR) and the accumulated error status from 1881 preceding calls to the MSS_UART_get_rx() function, and it combines them using 1882 a bitwise OR. It returns the cumulative overrun, parity, framing, break and 1883 FIFO error status of the receiver, since the previous call to 1884 MSS_UART_get_rx_status(), as an 8-bit encoded value. 1885 1886 Note: The MSS_UART_get_rx() function reads and accumulates the receiver 1887 status of the MSS UART instance before reading each byte from the receiver�s 1888 data register/FIFO. The driver maintains a sticky record of the cumulative 1889 receiver error status, which persists after the MSS_UART_get_rx() function 1890 returns. The MSS_UART_get_rx_status() function clears the driver�s sticky 1891 receiver error record before returning. 1892 1893 Note: The driver�s transmit functions also read the line status 1894 register (LSR) as part of their implementation. When the driver reads the 1895 LSR, the UART clears any active receiver error bits in the LSR. This could 1896 result in the driver losing receiver errors. To avoid any loss of receiver 1897 errors, the transmit functions also update the driver�s sticky record of the 1898 cumulative receiver error status whenever they read the LSR. 1899 1900 @param this_uart 1901 The this_uart parameter is a pointer to an mss_uart_instance_t 1902 structure identifying the MSS UART hardware block that will perform 1903 the requested function. There are two such data structures, 1904 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1905 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1906 global data structure defined within the UART driver. 1907 1908 @return 1909 This function returns the UART�s receiver error status as an 8-bit unsigned 1910 integer. The returned value is 0 if no receiver errors occurred. The driver 1911 provides a set of bit mask constants that should be compared with and/or 1912 used to mask the returned value to determine the receiver error status. 1913 When the return value is compared to the following bit masks, a non-zero 1914 result indicates that the corresponding error occurred: 1915 � MSS_UART_OVERRUN_ERROR (bit mask = 0x02) 1916 � MSS_UART_PARITY_ERROR (bit mask = 0x04) 1917 � MSS_UART_FRAMING_ERROR (bit mask = 0x08) 1918 � MSS_UART_BREAK_ERROR (bit mask = 0x10) 1919 � MSS_UART_FIFO_ERROR (bit mask = 0x80) 1920 When the return value is compared to the following bit mask, a non-zero 1921 result indicates that no error occurred: 1922 � MSS_UART_NO_ERROR (bit mask = 0x00) 1923 Upon unsuccessful execution, this function returns: 1924 � MSS_UART_INVALID_PARAM (bit mask = 0xFF) 1925 1926 Example: 1927 @code 1928 uint8_t rx_data[MAX_RX_DATA_SIZE]; 1929 uint8_t err_status; 1930 err_status = MSS_UART_get_rx_status(&g_mss_uart0); 1931 1932 if(MSS_UART_NO_ERROR == err_status) 1933 { 1934 rx_size = MSS_UART_get_rx(&g_mss_uart0, rx_data, MAX_RX_DATA_SIZE); 1935 } 1936 @endcode 1937 */ 1938 uint8_t 1939 MSS_UART_get_rx_status 1940 ( 1941 mss_uart_instance_t * this_uart 1942 ); 1943 1944 /***************************************************************************//** 1945 The MSS_UART_get_modem_status() function returns the modem status of the 1946 MSS UART instance. It reads the modem status register (MSR) and returns 1947 the 8 bit value. The bit encoding of the returned value is exactly the 1948 same as the definition of the bits in the MSR. 1949 1950 @param this_uart 1951 The this_uart parameter is a pointer to an mss_uart_instance_t 1952 structure identifying the MSS UART hardware block that will perform 1953 the requested function. There are two such data structures, 1954 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 1955 This parameter must point to either the g_mss_uart0 or g_mss_uart1 1956 global data structure defined within the UART driver. 1957 1958 @return 1959 This function returns current state of the UART's MSR as an 8 bit 1960 unsigned integer. The driver provides the following set of bit mask 1961 constants that should be compared with and/or used to mask the 1962 returned value to determine the modem status: 1963 � MSS_UART_DCTS (bit mask = 0x01) 1964 � MSS_UART_DDSR (bit mask = 0x02) 1965 � MSS_UART_TERI (bit mask = 0x04) 1966 � MSS_UART_DDCD (bit mask = 0x08) 1967 � MSS_UART_CTS (bit mask = 0x10) 1968 � MSS_UART_DSR (bit mask = 0x20) 1969 � MSS_UART_RI (bit mask = 0x40) 1970 � MSS_UART_DCD (bit mask = 0x80) 1971 1972 Example: 1973 @code 1974 void uart_modem_status_isr(mss_uart_instance_t * this_uart) 1975 { 1976 uint8_t status; 1977 status = MSS_UART_get_modem_status(this_uart); 1978 if( status & MSS_UART_DCTS ) 1979 { 1980 uart_dcts_handler(); 1981 } 1982 if( status & MSS_UART_CTS ) 1983 { 1984 uart_cts_handler(); 1985 } 1986 } 1987 @endcode 1988 */ 1989 uint8_t 1990 MSS_UART_get_modem_status 1991 ( 1992 mss_uart_instance_t * this_uart 1993 ); 1994 1995 /***************************************************************************//** 1996 The MSS_UART_get_tx_status() function returns the transmitter status of the 1997 MSS UART instance. It reads both the UART�s line status register (LSR) and 1998 returns the status of the transmit holding register empty (THRE) and 1999 transmitter empty (TEMT) bits.* 2000 2001 @param this_uart 2002 The this_uart parameter is a pointer to an mss_uart_instance_t 2003 structure identifying the MSS UART hardware block that will perform 2004 the requested function. There are two such data structures, 2005 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2006 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2007 global data structure defined within the UART driver. 2008 2009 @return 2010 This function returns the UART�s transmitter status as an 8-bit unsigned 2011 integer. The returned value is 0 if the transmitter status bits are not 2012 set or the function execution failed. The driver provides a set of bit 2013 mask constants that should be compared with and/or used to mask the 2014 returned value to determine the transmitter status. 2015 When the return value is compared to the following bit mask, a non-zero 2016 result indicates that the corresponding transmitter status bit is set: 2017 � MSS_UART_THRE (bit mask = 0x20) 2018 � MSS_UART_TEMT (bit mask = 0x40) 2019 When the return value is compared to the following bit mask, a non-zero 2020 result indicates that the transmitter is busy or the function execution 2021 failed. 2022 � MSS_UART_TX_BUSY (bit mask = 0x00) 2023 2024 Example: 2025 @code 2026 uint8_t tx_buff[10] = "abcdefghi"; 2027 MSS_UART_init(&g_mss_uart0, 2028 MSS_UART_57600_BAUD, 2029 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2030 2031 MSS_UART_polled_tx(&g_mss_uart0, tx_buff, sizeof(tx_buff)); 2032 2033 while(!(MSS_UART_TEMT & MSS_UART_get_tx_status(&g_mss_uart0))) 2034 { 2035 ; 2036 } 2037 @endcode 2038 */ 2039 uint8_t 2040 MSS_UART_get_tx_status 2041 ( 2042 mss_uart_instance_t * this_uart 2043 ); 2044 2045 /***************************************************************************//** 2046 The MSS_UART_set_break() function is used to send the break 2047 (9 zeros after stop bit) signal on the TX line. This function can be used 2048 only when the MSS UART is initialized in LIN mode by using MSS_UART_lin_init(). 2049 2050 @param this_uart 2051 The this_uart parameter is a pointer to an mss_uart_instance_t 2052 structure identifying the MSS UART hardware block that will perform 2053 the requested function. There are two such data structures, 2054 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2055 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2056 global data structure defined within the UART driver. 2057 2058 @return 2059 This function does not return a value. 2060 2061 Example: 2062 @code 2063 MSS_UART_init(&g_mss_uart0, 2064 MSS_UART_57600_BAUD, 2065 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2066 2067 MSS_UART_set_break(&g_mss_uart0); 2068 @endcode 2069 */ 2070 void 2071 MSS_UART_set_break 2072 ( 2073 mss_uart_instance_t * this_uart 2074 ); 2075 2076 /***************************************************************************//** 2077 The MSS_UART_clear_break() function is used to remove the break signal on the 2078 TX line. This function can be used only when the MSS UART is initialized in 2079 LIN mode by using MSS_UART_lin_init(). 2080 2081 @param this_uart 2082 The this_uart parameter is a pointer to an mss_uart_instance_t 2083 structure identifying the MSS UART hardware block that will perform 2084 the requested function. There are two such data structures, 2085 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2086 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2087 global data structure defined within the UART driver. 2088 2089 @return 2090 This function does not return a value. 2091 2092 Example: 2093 @code 2094 MSS_UART_init(&g_mss_uart0, 2095 MSS_UART_57600_BAUD, 2096 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2097 2098 MSS_UART_clear_break(&g_mss_uart0); 2099 @endcode 2100 */ 2101 void 2102 MSS_UART_clear_break 2103 ( 2104 mss_uart_instance_t * this_uart 2105 ); 2106 2107 /***************************************************************************//** 2108 The MSS_UART_enable_half_duplex() function is used to enable the half-duplex 2109 (single wire) mode for the MSS UART. Though it finds application in Smartcard 2110 mode, half-duplex mode can be used in other modes as well. 2111 2112 @param this_uart 2113 The this_uart parameter is a pointer to an mss_uart_instance_t 2114 structure identifying the MSS UART hardware block that will perform 2115 the requested function. There are two such data structures, 2116 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2117 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2118 global data structure defined within the UART driver. 2119 2120 @return 2121 This function does not return a value. 2122 2123 Example: 2124 @code 2125 MSS_UART_init(&g_mss_uart0, 2126 MSS_UART_57600_BAUD, 2127 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2128 2129 MSS_UART_enable_half_duplex(&g_mss_uart0); 2130 @endcode 2131 */ 2132 void 2133 MSS_UART_enable_half_duplex 2134 ( 2135 mss_uart_instance_t * this_uart 2136 ); 2137 2138 /***************************************************************************//** 2139 The MSS_UART_disable_half_duplex() function is used to disable the half-duplex 2140 (single wire) mode for the MSS UART. Though it finds application in Smartcard 2141 mode, half-duplex mode can be used in other modes as well. 2142 2143 @param this_uart 2144 The this_uart parameter is a pointer to an mss_uart_instance_t 2145 structure identifying the MSS UART hardware block that will perform 2146 the requested function. There are two such data structures, 2147 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2148 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2149 global data structure defined within the UART driver. 2150 2151 @return 2152 This function does not return a value. 2153 2154 Example: 2155 @code 2156 MSS_UART_init(&g_mss_uart0, 2157 MSS_UART_57600_BAUD, 2158 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2159 2160 MSS_UART_disable_half_duplex(&g_mss_uart0); 2161 @endcode 2162 */ 2163 void 2164 MSS_UART_disable_half_duplex 2165 ( 2166 mss_uart_instance_t * this_uart 2167 ); 2168 2169 /***************************************************************************//** 2170 The MSS_UART_set_rx_endian() function is used to configure the LSB first or 2171 MSB first setting for MSS UART receiver 2172 2173 @param this_uart 2174 The this_uart parameter is a pointer to an mss_uart_instance_t 2175 structure identifying the MSS UART hardware block that will perform 2176 the requested function. There are two such data structures, 2177 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2178 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2179 global data structure defined within the UART driver. 2180 2181 @param endian 2182 The endian parameter tells the LSB first or MSB first configuration. 2183 This parameter is of type mss_uart_endian_t. 2184 2185 @return 2186 This function does not return a value. 2187 2188 Example: 2189 @code 2190 MSS_UART_init(&g_mss_uart0, 2191 MSS_UART_57600_BAUD, 2192 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2193 2194 MSS_UART_set_rx_endian(&g_mss_uart0, MSS_UART_LITTLEEND); 2195 @endcode 2196 */ 2197 void 2198 MSS_UART_set_rx_endian 2199 ( 2200 mss_uart_instance_t * this_uart, 2201 mss_uart_endian_t endian 2202 ); 2203 2204 /***************************************************************************//** 2205 The MSS_UART_set_tx_endian() function is used to configure the LSB first or 2206 MSB first setting for MSS UART transmitter. 2207 2208 @param this_uart 2209 The this_uart parameter is a pointer to an mss_uart_instance_t 2210 structure identifying the MSS UART hardware block that will perform 2211 the requested function. There are two such data structures, 2212 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2213 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2214 global data structure defined within the UART driver. 2215 2216 @param endian 2217 The endian parameter tells the LSB first or MSB first configuration. 2218 This parameter is of type mss_uart_endian_t. 2219 2220 @return 2221 This function does not return a value. 2222 2223 Example: 2224 @code 2225 MSS_UART_init(&g_mss_uart0, 2226 MSS_UART_57600_BAUD, 2227 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2228 2229 MSS_UART_set_tx_endian(&g_mss_uart0, MSS_UART_LITTLEEND); 2230 @endcode 2231 */ 2232 void 2233 MSS_UART_set_tx_endian 2234 ( 2235 mss_uart_instance_t * this_uart, 2236 mss_uart_endian_t endian 2237 ); 2238 2239 /***************************************************************************//** 2240 The MSS_UART_set_filter_length () function is used to configure the glitch 2241 filter length of the MSS UART. This should be configured in accordance with 2242 the chosen baud rate. 2243 2244 @param this_uart 2245 The this_uart parameter is a pointer to an mss_uart_instance_t 2246 structure identifying the MSS UART hardware block that will perform 2247 the requested function. There are two such data structures, 2248 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2249 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2250 global data structure defined within the UART driver. 2251 2252 @param length 2253 The length parameter is of mss_uart_filter_length_t type that determines 2254 the length of the glitch filter. 2255 2256 @return 2257 This function does not return a value. 2258 2259 Example: 2260 @code 2261 MSS_UART_init(&g_mss_uart0, 2262 MSS_UART_57600_BAUD, 2263 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2264 2265 MSS_UART_set_filter_length(&g_mss_uart0, MSS_UART_LEN2); 2266 @endcode 2267 */ 2268 void 2269 MSS_UART_set_filter_length 2270 ( 2271 mss_uart_instance_t * this_uart, 2272 mss_uart_filter_length_t length 2273 ); 2274 2275 /***************************************************************************//** 2276 The MSS_UART_enable_afm() function is used to enable address flag detection 2277 mode of the MSS UART 2278 2279 @param this_uart 2280 The this_uart parameter is a pointer to an mss_uart_instance_t 2281 structure identifying the MSS UART hardware block that will perform 2282 the requested function. There are two such data structures, 2283 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2284 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2285 global data structure defined within the UART driver. 2286 2287 @return 2288 This function does not return a value. 2289 2290 Example: 2291 @code 2292 MSS_UART_init(&g_mss_uart0, 2293 MSS_UART_57600_BAUD, 2294 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2295 2296 MSS_UART_enable_afm(&g_mss_uart0); 2297 @endcode 2298 */ 2299 void 2300 MSS_UART_enable_afm 2301 ( 2302 mss_uart_instance_t * this_uart 2303 ); 2304 2305 /***************************************************************************//** 2306 The MSS_UART_disable_afm() function is used to disable address flag detection 2307 mode of the MSS UART. 2308 2309 @param this_uart 2310 The this_uart parameter is a pointer to an mss_uart_instance_t 2311 structure identifying the MSS UART hardware block that will perform 2312 the requested function. There are two such data structures, 2313 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2314 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2315 global data structure defined within the UART driver. 2316 2317 @return 2318 This function does not return a value. 2319 2320 Example: 2321 @code 2322 MSS_UART_init(&g_mss_uart0, 2323 MSS_UART_57600_BAUD, 2324 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2325 2326 MSS_UART_disable_afm(&g_mss_uart0); 2327 @endcode 2328 */ 2329 void 2330 MSS_UART_disable_afm 2331 ( 2332 mss_uart_instance_t * this_uart 2333 ); 2334 2335 /***************************************************************************//** 2336 The MSS_UART_enable_afclear () function is used to enable address flag clear 2337 of the MSS UART. This should be used in conjunction with address flag 2338 detection mode (AFM). 2339 2340 @param this_uart 2341 The this_uart parameter is a pointer to an mss_uart_instance_t 2342 structure identifying the MSS UART hardware block that will perform 2343 the requested function. There are two such data structures, 2344 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2345 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2346 global data structure defined within the UART driver. 2347 2348 @return 2349 This function does not return a value. 2350 2351 Example: 2352 @code 2353 MSS_UART_init(&g_mss_uart0, 2354 MSS_UART_57600_BAUD, 2355 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2356 2357 MSS_UART_enable_afclear(&g_mss_uart0); 2358 @endcode 2359 */ 2360 void 2361 MSS_UART_enable_afclear 2362 ( 2363 mss_uart_instance_t * this_uart 2364 ); 2365 2366 /***************************************************************************//** 2367 The MSS_UART_disable_afclear () function is used to disable address flag 2368 clear of the MSS UART. This should be used in conjunction with address flag 2369 detection mode (AFM). 2370 2371 @param this_uart 2372 The this_uart parameter is a pointer to an mss_uart_instance_t 2373 structure identifying the MSS UART hardware block that will perform 2374 the requested function. There are two such data structures, 2375 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2376 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2377 global data structure defined within the UART driver. 2378 2379 @return 2380 This function does not return a value. 2381 2382 Example: 2383 @code 2384 MSS_UART_init(&g_mss_uart0, 2385 MSS_UART_57600_BAUD, 2386 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2387 2388 MSS_UART_disable_afclear(&g_mss_uart0); 2389 @endcode 2390 */ 2391 void 2392 MSS_UART_disable_afclear 2393 ( 2394 mss_uart_instance_t * this_uart 2395 ); 2396 2397 /***************************************************************************//** 2398 The MSS_UART_enable_rx_timeout() function is used to enable and configure 2399 the receiver timeout functionality of MSS UART. This function accepts the 2400 timeout parameter and applies the timeout based up on the baud rate as per 2401 the formula 4 x timeout x bit time. 2402 2403 @param this_uart 2404 The this_uart parameter is a pointer to an mss_uart_instance_t 2405 structure identifying the MSS UART hardware block that will perform 2406 the requested function. There are two such data structures, 2407 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2408 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2409 global data structure defined within the UART driver. 2410 2411 @param timeout 2412 The timeout parameter specifies the receiver timeout multiple. 2413 It should be configured according to the baud rate in use. 2414 2415 @return 2416 This function does not return a value. 2417 2418 Example: 2419 @code 2420 MSS_UART_init(&g_mss_uart0, 2421 MSS_UART_57600_BAUD, 2422 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2423 2424 MSS_UART_enable_rx_timeout(&g_mss_uart0 , 24); 2425 @endcode 2426 */ 2427 void 2428 MSS_UART_enable_rx_timeout 2429 ( 2430 mss_uart_instance_t * this_uart, 2431 uint8_t timeout 2432 ); 2433 2434 /***************************************************************************//** 2435 The MSS_UART_disable_rx_timeout() function is used to disable the receiver 2436 timeout functionality of MSS UART. 2437 2438 @param this_uart 2439 The this_uart parameter is a pointer to an mss_uart_instance_t 2440 structure identifying the MSS UART hardware block that will perform 2441 the requested function. There are two such data structures, 2442 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2443 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2444 global data structure defined within the UART driver. 2445 2446 @return 2447 This function does not return a value. 2448 2449 Example: 2450 @code 2451 MSS_UART_init(&g_mss_uart0, 2452 MSS_UART_57600_BAUD, 2453 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2454 2455 MSS_UART_disable_rx_timeout(&g_mss_uart0); 2456 @endcode 2457 */ 2458 void 2459 MSS_UART_disable_rx_timeout 2460 ( 2461 mss_uart_instance_t * this_uart 2462 ); 2463 2464 /***************************************************************************//** 2465 The MSS_UART_enable_tx_time_guard() function is used to enable and configure 2466 the transmitter time guard functionality of MSS UART. This function accepts 2467 the timeguard parameter and applies the timeguard based up on the baud rate 2468 as per the formula timeguard x bit time. 2469 2470 @param this_uart 2471 The this_uart parameter is a pointer to an mss_uart_instance_t 2472 structure identifying the MSS UART hardware block that will perform 2473 the requested function. There are two such data structures, 2474 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2475 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2476 global data structure defined within the UART driver. 2477 2478 @return 2479 This function does not return a value. 2480 2481 Example: 2482 @code 2483 MSS_UART_init(&g_mss_uart0, 2484 MSS_UART_57600_BAUD, 2485 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2486 2487 MSS_UART_enable_tx_time_guard(&g_mss_uart0 , 24); 2488 @endcode 2489 */ 2490 void 2491 MSS_UART_enable_tx_time_guard 2492 ( 2493 mss_uart_instance_t * this_uart, 2494 uint8_t timeguard 2495 ); 2496 2497 /***************************************************************************//** 2498 The MSS_UART_disable_tx_time_guard() function is used to disable the 2499 transmitter time guard functionality of MSS UART. 2500 2501 @param this_uart 2502 The this_uart parameter is a pointer to an mss_uart_instance_t 2503 structure identifying the MSS UART hardware block that will perform 2504 the requested function. There are two such data structures, 2505 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2506 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2507 global data structure defined within the UART driver. 2508 2509 @return 2510 This function does not return a value. 2511 2512 Example: 2513 @code 2514 MSS_UART_init(&g_mss_uart0, 2515 MSS_UART_57600_BAUD, 2516 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2517 2518 MSS_UART_disable_tx_time_guard(&g_mss_uart0); 2519 @endcode 2520 */ 2521 void 2522 MSS_UART_disable_tx_time_guard 2523 ( 2524 mss_uart_instance_t * this_uart 2525 ); 2526 2527 /***************************************************************************//** 2528 The MSS_UART_set_address() function is used to set the 8-bit address for 2529 the MSS UART referenced by this_uart parameter. 2530 2531 @param this_uart 2532 The this_uart parameter is a pointer to an mss_uart_instance_t 2533 structure identifying the MSS UART hardware block that will perform 2534 the requested function. There are two such data structures, 2535 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2536 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2537 global data structure defined within the UART driver. 2538 2539 @param address 2540 The address parameter is the 8-bit address which is to be configured 2541 to the MSS UART referenced by this_uart parameter. 2542 2543 @return 2544 This function does not return a value. 2545 2546 Example: 2547 @code 2548 MSS_UART_init(&g_mss_uart0, 2549 MSS_UART_57600_BAUD, 2550 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2551 2552 MSS_UART_set_address(&g_mss_uart0, 0xAA); 2553 @endcode 2554 */ 2555 void 2556 MSS_UART_set_address 2557 ( 2558 mss_uart_instance_t * this_uart, 2559 uint8_t address 2560 ); 2561 2562 /***************************************************************************//** 2563 The MSS_UART_set_ready_mode() function is used to configure the MODE0 or MODE1 2564 to the TXRDY and RXRDY signals of the MSS UART referenced by this_uart 2565 parameter. The mode parameter is used to provide the mode to be configured. 2566 2567 @param this_uart 2568 The this_uart parameter is a pointer to an mss_uart_instance_t 2569 structure identifying the MSS UART hardware block that will perform 2570 the requested function. There are two such data structures, 2571 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2572 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2573 global data structure defined within the UART driver. 2574 2575 @param mode 2576 The mode parameter is the mss_uart_ready_mode_t type which is used to 2577 configure the TXRDY and RXRDY signal modes. 2578 2579 @return 2580 This function does not return a value. 2581 2582 Example: 2583 @code 2584 MSS_UART_init(&g_mss_uart0, 2585 MSS_UART_57600_BAUD, 2586 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2587 2588 MSS_UART_set_ready_mode(&g_mss_uart0, MSS_UART_READY_MODE0); 2589 @endcode 2590 */ 2591 void 2592 MSS_UART_set_ready_mode 2593 ( 2594 mss_uart_instance_t * this_uart, 2595 mss_uart_ready_mode_t mode 2596 ); 2597 2598 /***************************************************************************//** 2599 The MSS_UART_set_usart_mode() function is used to configure the MSS UART 2600 referenced by the parameter this_uart in USART mode. Various USART modes 2601 are supported which can be configured by the parameter mode of type 2602 mss_uart_usart_mode_t. 2603 2604 @param this_uart 2605 The this_uart parameter is a pointer to an mss_uart_instance_t 2606 structure identifying the MSS UART hardware block that will perform 2607 the requested function. There are two such data structures, 2608 g_mss_uart0 and g_mss_uart1, associated with MSS UART0 and MSS UART1. 2609 This parameter must point to either the g_mss_uart0 or g_mss_uart1 2610 global data structure defined within the UART driver. 2611 2612 @param mode 2613 The mode parameter is the USART mode to be configured. 2614 This parameter is of type mss_uart_usart_mode_t. 2615 2616 @return 2617 This function does not return a value. 2618 2619 Example: 2620 @code 2621 MSS_UART_init(&g_mss_uart0, 2622 MSS_UART_57600_BAUD, 2623 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); 2624 2625 MSS_UART_set_usart_mode(&g_mss_uart0, MSS_UART_SYNC_MASTER_POS_EDGE_CLK); 2626 @endcode 2627 */ 2628 void 2629 MSS_UART_set_usart_mode 2630 ( 2631 mss_uart_instance_t * this_uart, 2632 mss_uart_usart_mode_t mode 2633 ); 2634 2635 #ifdef __cplusplus 2636 } 2637 #endif 2638 2639 #endif /* __MSS_UART_H_ */ 2640