mss_uart.h 101 KB

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