Lpuart_Uart_Ip.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : FLEXIO
  5. * Dependencies :
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file Lpuart_Uart_Ip.c
  26. * @defgroup lpuart_uart_ip Lpuart UART IPL
  27. * @addtogroup lpuart_uart_ip Lpuart UART IPL
  28. * @{
  29. */
  30. #include "Port.h"
  31. #include "Dio.h"
  32. #ifdef __cplusplus
  33. extern "C"{
  34. #endif
  35. /*==================================================================================================
  36. * INCLUDE FILES
  37. * 1) system and project includes
  38. * 2) needed interfaces from external units
  39. * 3) internal and external interfaces from this unit
  40. ==================================================================================================*/
  41. #include "Lpuart_Uart_Ip.h"
  42. #include "Lpuart_Uart_Ip_HwAccess.h"
  43. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  44. #include "Dma_Ip.h"
  45. #endif
  46. #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
  47. #if (LPUART_UART_IP_DEV_ERROR_DETECT == STD_ON)
  48. #include "Devassert.h"
  49. #endif /* (STD_ON == LPUART_UART_IP_DEV_ERROR_DETECT) */
  50. #endif /* idfef LPUART_UART_IP_DEV_ERROR_DETECT */
  51. /*==================================================================================================
  52. * SOURCE FILE VERSION INFORMATION
  53. ==================================================================================================*/
  54. #define LPUART_UART_IP_VENDOR_ID_C 43
  55. #define LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C 4
  56. #define LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C 4
  57. #define LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C 0
  58. #define LPUART_UART_IP_SW_MAJOR_VERSION_C 1
  59. #define LPUART_UART_IP_SW_MINOR_VERSION_C 0
  60. #define LPUART_UART_IP_SW_PATCH_VERSION_C 0
  61. /*==================================================================================================
  62. * FILE VERSION CHECKS
  63. ==================================================================================================*/
  64. /* Checks against Lpuart_Uart_Ip.h */
  65. #if (LPUART_UART_IP_VENDOR_ID_C != LPUART_UART_IP_VENDOR_ID)
  66. #error "Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h have different vendor ids"
  67. #endif
  68. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION) || \
  69. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MINOR_VERSION) || \
  70. (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C != LPUART_UART_IP_AR_RELEASE_REVISION_VERSION))
  71. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h are different"
  72. #endif
  73. #if ((LPUART_UART_IP_SW_MAJOR_VERSION_C != LPUART_UART_IP_SW_MAJOR_VERSION) || \
  74. (LPUART_UART_IP_SW_MINOR_VERSION_C != LPUART_UART_IP_SW_MINOR_VERSION) || \
  75. (LPUART_UART_IP_SW_PATCH_VERSION_C != LPUART_UART_IP_SW_PATCH_VERSION))
  76. #error "Software Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h are different"
  77. #endif
  78. /* Checks against Lpuart_Uart_Ip_HwAccess.h */
  79. #if (LPUART_UART_IP_VENDOR_ID_C != LPUART_UART_IP_HWACCESS_VENDOR_ID)
  80. #error "Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h have different vendor ids"
  81. #endif
  82. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION) || \
  83. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION) || \
  84. (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION))
  85. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h are different"
  86. #endif
  87. #if ((LPUART_UART_IP_SW_MAJOR_VERSION_C != LPUART_UART_IP_HWACCESS_SW_MAJOR_VERSION) || \
  88. (LPUART_UART_IP_SW_MINOR_VERSION_C != LPUART_UART_IP_HWACCESS_SW_MINOR_VERSION) || \
  89. (LPUART_UART_IP_SW_PATCH_VERSION_C != LPUART_UART_IP_HWACCESS_SW_PATCH_VERSION))
  90. #error "Software Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h are different"
  91. #endif
  92. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  93. /* Checks against Dma_Ip.h */
  94. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  95. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DMA_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  96. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != DMA_IP_AR_RELEASE_MINOR_VERSION_H))
  97. #error "AutoSar Version Numbers of Lpuart_Uart_Ip.c and Dma_Ip.h are different"
  98. #endif
  99. #endif
  100. /* Checks against Devassert.h */
  101. #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
  102. #if (STD_ON == LPUART_UART_IP_DEV_ERROR_DETECT)
  103. /* Check if Lpuart_Uart_Ip.c file and Devassert.h file are of the same Autosar version */
  104. #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  105. (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION))
  106. #error "AutoSar Version Numbers of Lpuart_Uart_Ip.c and Devassert.h are different"
  107. #endif
  108. #endif /* (STD_ON == LPUART_UART_IP_DEV_ERROR_DETECT) */
  109. #endif /* #ifdef LPUART_UART_IP_DEV_ERROR_DETECT */
  110. #endif
  111. /*==================================================================================================
  112. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  113. ==================================================================================================*/
  114. /*==================================================================================================
  115. * LOCAL MACROS
  116. ==================================================================================================*/
  117. #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
  118. #if (LPUART_UART_IP_DEV_ERROR_DETECT == STD_ON)
  119. #define LPUART_UART_IP_DEV_ASSERT(x) DevAssert(x)
  120. #else
  121. #define LPUART_UART_IP_DEV_ASSERT(x) (void)(x)
  122. #endif
  123. #endif
  124. /* @brief Address of the least significant byte or word in a 32-bit register (depends on endianness) */
  125. #define LPUART_UART_IP_LSBW_ADDR(reg) ((uint32)(&(reg)))
  126. /*==================================================================================================
  127. * LOCAL CONSTANTS
  128. ==================================================================================================*/
  129. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  130. #define LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION (10U)
  131. #define LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION (2U)
  132. #endif
  133. /*==================================================================================================
  134. * LOCAL VARIABLES
  135. ==================================================================================================*/
  136. #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  137. #include "Uart_MemMap.h"
  138. /** @brief Array of UART driver runtime state structures */
  139. Lpuart_Uart_Ip_StateStructureType Lpuart_Uart_Ip_apStateStructure[LPUART_UART_IP_NUMBER_OF_INSTANCES];
  140. #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  141. #include "Uart_MemMap.h"
  142. #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED
  143. #include "Uart_MemMap.h"
  144. /* Pointer to lpuart runtime state structure */
  145. static Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
  146. /** @brief User config structure. */
  147. const Lpuart_Uart_Ip_UserConfigType * Lpuart_Uart_Ip_apUserConfig[LPUART_UART_IP_NUMBER_OF_INSTANCES];
  148. #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  149. #include "Uart_MemMap.h"
  150. #define UART_START_SEC_CONST_UNSPECIFIED
  151. #include "Uart_MemMap.h"
  152. /* Table of base addresses for lpuart instances. */
  153. static LPUART_Type * const Lpuart_Uart_Ip_apBases[LPUART_UART_IP_NUMBER_OF_INSTANCES] = IP_LPUART_BASE_PTRS;
  154. #define UART_STOP_SEC_CONST_UNSPECIFIED
  155. #include "Uart_MemMap.h"
  156. /*==================================================================================================
  157. * GLOBAL CONSTANTS
  158. ==================================================================================================*/
  159. /*==================================================================================================
  160. * GLOBAL VARIABLES
  161. ==================================================================================================*/
  162. /*==================================================================================================
  163. * LOCAL FUNCTION PROTOTYPES
  164. ==================================================================================================*/
  165. /*==================================================================================================
  166. * LOCAL FUNCTIONS
  167. ==================================================================================================*/
  168. #define UART_START_SEC_CODE
  169. #include "Uart_MemMap.h"
  170. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingInt(const uint8 Instance,
  171. const uint8 * TxBuff,
  172. const uint32 TxSize);
  173. static void Lpuart_Uart_Ip_CompleteSendDataUsingInt(const uint8 Instance);
  174. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingInt(const uint8 Instance,
  175. uint8 * RxBuff,
  176. const uint32 RxSize);
  177. static void Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(const uint8 Instance);
  178. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  179. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingDma(const uint8 Instance,
  180. const uint8 * TxBuff,
  181. const uint32 TxSize);
  182. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingDma(const uint8 Instance,
  183. uint8 * RxBuff,
  184. const uint32 RxSize);
  185. static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable);
  186. #endif
  187. static void Lpuart_Uart_Ip_PutData(const uint8 Instance);
  188. static void Lpuart_Uart_Ip_GetData(const uint8 Instance);
  189. static void Lpuart_Uart_Ip_RxIrqHandler(const uint8 Instance);
  190. static void Lpuart_Uart_Ip_TxEmptyIrqHandler(const uint8 Instance);
  191. static void Lpuart_Uart_Ip_TxCompleteIrqHandler(const uint8 Instance);
  192. static void Lpuart_Uart_Ip_ErrIrqHandler(const uint8 Instance);
  193. static void Lpuart_Uart_Ip_StartGetData(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks);
  194. /*==================================================================================================
  195. * GLOBAL FUNCTIONS
  196. ==================================================================================================*/
  197. /*FUNCTION**********************************************************************
  198. *
  199. * Function Name : Lpuart_Uart_Ip_Init
  200. * Description : This function initializes a LPUART instance for operation.
  201. * This function will initialize the run-time state structure to keep track of
  202. * the on-going transfers, ungate the clock to the LPUART module, initialize the
  203. * module to user defined settings and default settings, configure the IRQ state
  204. * structure and enable the module-level interrupt to the core, and enable the
  205. * LPUART module transmitter and receiver.
  206. *
  207. * Implements : Lpuart_Uart_Ip_Init_Activity
  208. *END**************************************************************************/
  209. /* implements Lpuart_Uart_Ip_Init_Activity*/
  210. void Lpuart_Uart_Ip_Init(const uint8 Instance, const Lpuart_Uart_Ip_UserConfigType * UserConfig)
  211. {
  212. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  213. LPUART_UART_IP_DEV_ASSERT(UserConfig != NULL_PTR);
  214. /* Check if current instance is already initialized. */
  215. LPUART_UART_IP_DEV_ASSERT(NULL_PTR == Lpuart_Uart_Ip_apStateStructuresArray[Instance]);
  216. /* Check if Baudrate parameters are valid value */
  217. LPUART_UART_IP_DEV_ASSERT(UserConfig->BaudOverSamplingRatio <= 0x20U);
  218. LPUART_UART_IP_DEV_ASSERT((UserConfig->BaudRateDivisor <= 0x1FFFU) && \
  219. (UserConfig->BaudRateDivisor >= 1U));
  220. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  221. Lpuart_Uart_Ip_StateStructureType *UartStatePtr;
  222. uint32 Index;
  223. uint8 *ClearStructPtr;
  224. Lpuart_Uart_Ip_apStateStructuresArray[Instance] = UserConfig->StateStruct;
  225. UartStatePtr = Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  226. Lpuart_Uart_Ip_apUserConfig[Instance] = UserConfig;
  227. ClearStructPtr = (uint8 *)UartStatePtr;
  228. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  229. /* In DMA mode, only 7-bits and 8-bits chars are supported */
  230. LPUART_UART_IP_DEV_ASSERT((UserConfig->TransferType != LPUART_UART_IP_USING_DMA) || \
  231. ((LPUART_UART_IP_7_BITS_PER_CHAR == UserConfig->BitCountPerChar) || \
  232. (LPUART_UART_IP_8_BITS_PER_CHAR == UserConfig->BitCountPerChar)));
  233. #endif /* (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON) */
  234. /* For 10 bits per char, parity bit cannot be enabled */
  235. LPUART_UART_IP_DEV_ASSERT((UserConfig->BitCountPerChar != LPUART_UART_IP_10_BITS_PER_CHAR) || \
  236. (LPUART_UART_IP_PARITY_DISABLED == UserConfig->ParityMode));
  237. /* Clear the state struct for this instance. */
  238. for (Index = 0; Index < sizeof(Lpuart_Uart_Ip_StateStructureType); Index++)
  239. {
  240. ClearStructPtr[Index] = 0;
  241. }
  242. /* Initialize the LPUART instance */
  243. Lpuart_Uart_Ip_Hw_Init(Base);
  244. /* Check if Osr is between 4x and 7x oversampling.
  245. * If so, then "BOTHEDGE" sampling must be turned on */
  246. if (UserConfig->BaudOverSamplingRatio < 8U)
  247. {
  248. Lpuart_Uart_Ip_EnableBothEdgeSamplingCmd(Base);
  249. }
  250. /* Program the Osr value (bit value is one less than actual value) */
  251. Lpuart_Uart_Ip_SetOversamplingRatio(Base, (uint32)UserConfig->BaudOverSamplingRatio -1U);
  252. /* Write the Sbr value to the BAUD registers */
  253. Lpuart_Uart_Ip_SetBaudRateDivisor(Base, UserConfig->BaudRateDivisor);
  254. if (UserConfig->ParityMode != LPUART_UART_IP_PARITY_DISABLED)
  255. {
  256. Lpuart_Uart_Ip_SetBitCountPerChar(Base, UserConfig->BitCountPerChar, TRUE);
  257. }
  258. else
  259. {
  260. Lpuart_Uart_Ip_SetBitCountPerChar(Base, UserConfig->BitCountPerChar, FALSE);
  261. }
  262. Lpuart_Uart_Ip_SetParityMode(Base, UserConfig->ParityMode);
  263. Lpuart_Uart_Ip_SetStopBitCount(Base, UserConfig->StopBitsCount);
  264. /* Initialize last driver operation status */
  265. UartStatePtr->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
  266. UartStatePtr->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  267. /* Set the initial baudrate from user's structure */
  268. UartStatePtr->BaudRate = UserConfig->BaudRate;
  269. }
  270. /*FUNCTION**********************************************************************
  271. *
  272. * Function Name : Lpuart_Uart_Ip_Deinit
  273. * Description : This function shuts down the UART by disabling interrupts and
  274. * transmitter/receiver.
  275. *
  276. * Implements : Lpuart_Uart_Ip_Deinit_Activity
  277. *END**************************************************************************/
  278. /* implements Lpuart_Uart_Ip_Deinit_Activity*/
  279. void Lpuart_Uart_Ip_Deinit(const uint8 Instance)
  280. {
  281. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  282. uint32 StartTime;
  283. uint32 TimeoutTicks;
  284. uint32 ElapsedTicks = 0;
  285. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  286. /* Check if current instance is already de-initialized or is gated.*/
  287. LPUART_UART_IP_DEV_ASSERT(Lpuart_Uart_Ip_apStateStructuresArray[Instance] != NULL_PTR);
  288. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
  289. /* Wait until the data is completely shifted out of shift register */
  290. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
  291. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  292. {}
  293. /* Disble Tx data register empty and transmission complete interrupt */
  294. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
  295. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
  296. /* Disble Rx data register full */
  297. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
  298. /* Disable error interrupts */
  299. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, FALSE);
  300. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, FALSE);
  301. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, FALSE);
  302. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, FALSE);
  303. /* Clear our saved pointer to the state structure */
  304. Lpuart_Uart_Ip_apStateStructuresArray[Instance] = NULL_PTR;
  305. }
  306. /*FUNCTION**********************************************************************
  307. *
  308. * Function Name : Lpuart_Uart_Ip_SyncSend
  309. * Description : Send out multiple bytes of data using polling method.
  310. *
  311. * Implements : Lpuart_Uart_Ip_SyncSend_Activity
  312. *END**************************************************************************/
  313. /* implements Lpuart_Uart_Ip_SyncSend_Activity*/
  314. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncSend(const uint8 Instance,
  315. const uint8 *TxBuff,
  316. const uint32 TxSize,
  317. const uint32 Timeout)
  318. {
  319. /* Check the validity of the parameters */
  320. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  321. LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
  322. LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
  323. LPUART_Type * Base;
  324. Lpuart_Uart_Ip_StateStructureType * UartState;
  325. uint32 StartTime;
  326. uint32 TimeoutTicks;
  327. uint32 ElapsedTicks = 0;
  328. boolean IsReturn = FALSE;
  329. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  330. Base = Lpuart_Uart_Ip_apBases[Instance];
  331. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  332. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  333. SchM_Enter_Uart_UART_EXCLUSIVE_AREA_00();
  334. /* Check driver is not busy transmitting data from a previous asynchronous call */
  335. if (UartState->IsTxBusy)
  336. {
  337. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_00();
  338. RetVal = LPUART_UART_IP_STATUS_BUSY;
  339. IsReturn = TRUE;
  340. }
  341. if (!IsReturn)
  342. {
  343. UartState->IsTxBusy = TRUE;
  344. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_00();
  345. UartState->TxBuff = TxBuff;
  346. UartState->TxSize = TxSize;
  347. UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
  348. /* Disble Tx data register empty and transmission complete interrupt */
  349. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
  350. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
  351. /* Enable the LPUART transmitter */
  352. Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
  353. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LPUART_UART_IP_TIMEOUT_TYPE);
  354. while ((UartState->TxSize > 0U) && \
  355. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  356. {
  357. Lpuart_Uart_Ip_PutData(Instance);
  358. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_DATA_REG_EMPTY) && \
  359. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  360. {}
  361. }
  362. /* Disable the LPUART transmitter */
  363. Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
  364. /* Check if Timeout occur */
  365. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  366. {
  367. UartState->TransmitStatus = LPUART_UART_IP_STATUS_TIMEOUT;
  368. }else /* The transmit process is complete */
  369. {
  370. UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
  371. }
  372. UartState->IsTxBusy = FALSE;
  373. RetVal = UartState->TransmitStatus;
  374. }
  375. return RetVal;
  376. }
  377. /*FUNCTION**********************************************************************
  378. *
  379. * Function Name : Lpuart_Uart_Ip_AsyncSend
  380. * Description : This function sends data out through the LPUART module using
  381. * non-blocking method. The function will return immediately after calling this
  382. * function.
  383. *
  384. * Implements : Lpuart_Uart_Ip_AsyncSend_Activity
  385. *END**************************************************************************/
  386. /* implements Lpuart_Uart_Ip_AsyncSend_Activity*/
  387. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncSend(const uint8 Instance,
  388. const uint8 * TxBuff,
  389. const uint32 TxSize)
  390. {
  391. /* Check the validity of the parameters */
  392. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  393. LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
  394. LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
  395. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  396. Lpuart_Uart_Ip_StateStructureType * UartState;
  397. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  398. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  399. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  400. boolean IsReturn = FALSE;
  401. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  402. SchM_Enter_Uart_UART_EXCLUSIVE_AREA_01();
  403. /* Check it's not busy transmitting data from a previous function call */
  404. if (UartState->IsTxBusy)
  405. {
  406. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_01();
  407. RetVal = LPUART_UART_IP_STATUS_BUSY;
  408. IsReturn = TRUE;
  409. }
  410. if (!IsReturn)
  411. {
  412. UartState->IsTxBusy = TRUE;
  413. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_01();
  414. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  415. LPUART_UART_IP_DEV_ASSERT((LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType) ||
  416. (LPUART_UART_IP_USING_DMA == UartUserCfg->TransferType));
  417. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  418. {
  419. /* Start the transmission process using interrupts */
  420. RetVal = Lpuart_Uart_Ip_StartSendDataUsingInt(Instance, TxBuff, TxSize);
  421. }
  422. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  423. else
  424. {
  425. /* Start the transmission process using DMA */
  426. RetVal = Lpuart_Uart_Ip_StartSendDataUsingDma(Instance, TxBuff, TxSize);
  427. }
  428. #endif
  429. }
  430. return RetVal;
  431. }
  432. /*FUNCTION**********************************************************************
  433. *
  434. * Function Name : Lpuart_Uart_Ip_GetTransmitStatus
  435. * Description : This function returns whether the previous LPUART transmit has
  436. * finished. When performing non-blocking transmit, the user can call this
  437. * function to ascertain the state of the current transmission:
  438. * in progress (or busy) or complete (success). In addition, if the transmission
  439. * is still in progress, the user can obtain the number of words that have been
  440. * currently transferred.
  441. *
  442. * Implements : Lpuart_Uart_Ip_GetTransmitStatus_Activity
  443. *END**************************************************************************/
  444. /* implements Lpuart_Uart_Ip_GetTransmitStatus_Activity*/
  445. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetTransmitStatus(const uint8 Instance, uint32 * BytesRemaining)
  446. {
  447. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  448. const Lpuart_Uart_Ip_StateStructureType * UartState;
  449. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  450. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  451. const Dma_Ip_LogicChannelInfoParamType DmaLogicChnParam = DMA_IP_CH_GET_CURRENT_ITER_COUNT;
  452. #endif
  453. UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  454. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  455. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  456. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  457. if (BytesRemaining != NULL_PTR)
  458. {
  459. if (UartState->IsTxBusy)
  460. {
  461. /* Fill in the bytes not transferred yet. */
  462. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  463. {
  464. /* In interrupt-based communication, the remaining bytes are retrieved
  465. * from the state structure
  466. */
  467. *BytesRemaining = UartState->TxSize;;
  468. }
  469. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  470. else
  471. {
  472. /* In DMA-based communication, the remaining bytes are retrieved
  473. * from the current DMA major loop count
  474. */
  475. (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->TxDMAChannel, DmaLogicChnParam, BytesRemaining);
  476. }
  477. #endif
  478. }
  479. else
  480. {
  481. *BytesRemaining = 0;
  482. }
  483. }
  484. return UartState->TransmitStatus;
  485. }
  486. /*FUNCTION**********************************************************************
  487. *
  488. * Function Name : Lpuart_Uart_Ip_AbortSendingData
  489. * Description : This function terminates an non-blocking LPUART transmission
  490. * early. During a non-blocking LPUART transmission, the user has the option to
  491. * terminate the transmission early if the transmission is still in progress.
  492. *
  493. * Implements : Lpuart_Uart_Ip_AbortSendingData_Activity
  494. *END**************************************************************************/
  495. /* implements Lpuart_Uart_Ip_AbortSendingData_Activity*/
  496. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortSendingData(const uint8 Instance)
  497. {
  498. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  499. Lpuart_Uart_Ip_StateStructureType * UartState;
  500. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  501. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  502. boolean IsReturn = FALSE;
  503. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  504. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  505. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  506. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  507. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  508. /* Check if a transfer is running. */
  509. if (!UartState->IsTxBusy)
  510. {
  511. RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  512. IsReturn = TRUE;
  513. }
  514. if (!IsReturn)
  515. {
  516. /* Update the tx status */
  517. UartState->TransmitStatus = LPUART_UART_IP_STATUS_ABORTED;
  518. /* Stop the running transfer. */
  519. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  520. {
  521. Lpuart_Uart_Ip_CompleteSendDataUsingInt(Instance);
  522. }
  523. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  524. else
  525. {
  526. /* Release the DMA channel */
  527. (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
  528. Lpuart_Uart_Ip_CompleteSendUsingDma(Instance);
  529. }
  530. #endif
  531. /* Flush the Tx Buffer */
  532. Lpuart_Uart_Ip_FlushTxBuffer(Base);
  533. RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  534. }
  535. return RetVal;
  536. }
  537. /*FUNCTION**********************************************************************
  538. *
  539. * Function Name : Lpuart_Uart_Ip_SyncReceive
  540. * Description : Receive multiple bytes of data using polling method.
  541. *
  542. * Implements : Lpuart_Uart_Ip_SyncReceive_Activity
  543. *END**************************************************************************/
  544. /* implements Lpuart_Uart_Ip_SyncReceive_Activity*/
  545. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncReceive(const uint8 Instance,
  546. uint8 *RxBuff,
  547. const uint32 RxSize,
  548. const uint32 Timeout)
  549. {
  550. /* Check the validity of the parameters */
  551. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  552. LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
  553. LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
  554. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  555. Lpuart_Uart_Ip_StateStructureType * UartState;
  556. uint32 StartTime;
  557. uint32 TimeoutTicks;
  558. uint32 ElapsedTicks = 0;
  559. boolean IsReturn = FALSE;
  560. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  561. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  562. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  563. SchM_Enter_Uart_UART_EXCLUSIVE_AREA_02();
  564. /* Check driver is not busy receiving data from a previous asynchronous call */
  565. if (UartState->IsRxBusy)
  566. {
  567. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_02();
  568. RetVal = LPUART_UART_IP_STATUS_BUSY;
  569. IsReturn = TRUE;
  570. }
  571. if (!IsReturn)
  572. {
  573. UartState->IsRxBusy = TRUE;
  574. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_02();
  575. UartState->RxBuff = RxBuff;
  576. UartState->RxSize = RxSize;
  577. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
  578. /* Disble Rx data register full */
  579. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
  580. /* Enable the LPUART receiver */
  581. Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, TRUE);
  582. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LPUART_UART_IP_TIMEOUT_TYPE);
  583. Lpuart_Uart_Ip_StartGetData(Instance, &StartTime, &ElapsedTicks, TimeoutTicks);
  584. /* Check if Timeout occur */
  585. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  586. {
  587. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_TIMEOUT;
  588. }
  589. /* Check other success receiving case*/
  590. if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
  591. {
  592. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  593. }
  594. if ((0U == UartState->RxSize) && (LPUART_UART_IP_STATUS_RX_OVERRUN == UartState->ReceiveStatus))
  595. {
  596. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  597. }
  598. /* Disable the LPUART receiver */
  599. Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, FALSE);
  600. UartState->IsRxBusy = FALSE;
  601. /* Read dummy to clear RDRF flag */
  602. (void)Lpuart_Uart_Ip_Getchar(Base);
  603. RetVal = UartState->ReceiveStatus;
  604. }
  605. return RetVal;
  606. }
  607. /*FUNCTION**********************************************************************
  608. *
  609. * Function Name : Lpuart_Uart_Ip_StartGetData
  610. * Description : Start Getting Data in SyncReceive mode
  611. *
  612. *END**************************************************************************/
  613. static void Lpuart_Uart_Ip_StartGetData(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks)
  614. {
  615. Lpuart_Uart_Ip_StateStructureType * UartState;
  616. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  617. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  618. uint8 StatusIndex = 0U;
  619. uint32 Mask = 0U;
  620. const Lpuart_Uart_Ip_StatusFlagType Lpuart_Uart_Ip_StatusFlagTypeArray[4U] = {LPUART_UART_IP_RX_OVERRUN,
  621. LPUART_UART_IP_FRAME_ERR,
  622. LPUART_UART_IP_NOISE_DETECT,
  623. LPUART_UART_IP_PARITY_ERR};
  624. const Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_ReceiveStatusArray[4U] = {LPUART_UART_IP_STATUS_RX_OVERRUN,
  625. LPUART_UART_IP_STATUS_FRAMING_ERROR,
  626. LPUART_UART_IP_STATUS_NOISE_ERROR,
  627. LPUART_UART_IP_STATUS_PARITY_ERROR};
  628. const uint32 Lpuart_Uart_Ip_StatusRegMask[4U] = {LPUART_STAT_OR_MASK,
  629. LPUART_STAT_FE_MASK,
  630. LPUART_STAT_NF_MASK,
  631. LPUART_STAT_PF_MASK};
  632. while ((UartState->RxSize > 0U) && \
  633. !Lpuart_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  634. {
  635. /* Wait until data reception flag is set or timeout occurs if there is an error during reception */
  636. while (!Lpuart_Uart_Ip_GetStatusFlag((const LPUART_Type*)Base, LPUART_UART_IP_DATA_REG_FULL) && \
  637. !Lpuart_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  638. {}
  639. /* Check for errors on received data */
  640. for(StatusIndex = 0U; StatusIndex <= 3U; StatusIndex++)
  641. {
  642. if(Lpuart_Uart_Ip_GetStatusFlag((const LPUART_Type*)Base, Lpuart_Uart_Ip_StatusFlagTypeArray[StatusIndex]))
  643. {
  644. UartState->ReceiveStatus = Lpuart_Uart_Ip_ReceiveStatusArray[StatusIndex];
  645. Mask |= Lpuart_Uart_Ip_StatusRegMask[StatusIndex];
  646. }
  647. }
  648. if(Mask > 0U)
  649. {
  650. /* Disable the LPUART receiver */
  651. Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, FALSE);
  652. /* Clear the flag */
  653. Lpuart_Uart_Ip_ClearStatusFlagWithMask(Base, Mask);
  654. break;
  655. }
  656. else
  657. {
  658. /* Get received data */
  659. Lpuart_Uart_Ip_GetData(Instance);
  660. }
  661. }
  662. }
  663. /*FUNCTION**********************************************************************
  664. *
  665. * Function Name : Lpuart_Uart_Ip_ReceiveData
  666. * Description : This function receives data from LPUART module using
  667. * non-blocking method. This function returns immediately after initiating the
  668. * receive function. The application has to get the receive status to see when
  669. * the receive is complete. In other words, after calling non-blocking get
  670. * function, the application must get the receive status to check if receive
  671. * is completed or not.
  672. *
  673. * Implements : Lpuart_Uart_Ip_ReceiveData_Activity
  674. *END**************************************************************************/
  675. /* implements Lpuart_Uart_Ip_AsyncReceive_Activity*/
  676. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncReceive(const uint8 Instance,
  677. uint8 * RxBuff,
  678. const uint32 RxSize)
  679. {
  680. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  681. LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
  682. LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
  683. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  684. Lpuart_Uart_Ip_StateStructureType * UartState;
  685. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  686. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  687. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  688. boolean IsReturn = FALSE;
  689. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  690. SchM_Enter_Uart_UART_EXCLUSIVE_AREA_03();
  691. /* Check it's not busy receiving data from a previous function call */
  692. if (UartState->IsRxBusy)
  693. {
  694. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
  695. RetVal = LPUART_UART_IP_STATUS_BUSY;
  696. IsReturn = TRUE;
  697. }
  698. if (!IsReturn)
  699. {
  700. UartState->IsRxBusy = TRUE;
  701. SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
  702. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  703. LPUART_UART_IP_DEV_ASSERT((LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType) ||
  704. (LPUART_UART_IP_USING_DMA == UartUserCfg->TransferType));
  705. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  706. {
  707. /* Start the reception process using interrupts */
  708. RetVal = Lpuart_Uart_Ip_StartReceiveDataUsingInt(Instance, RxBuff, RxSize);
  709. }
  710. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  711. else
  712. {
  713. /* Start the reception process using DMA */
  714. RetVal = Lpuart_Uart_Ip_StartReceiveDataUsingDma(Instance, RxBuff, RxSize);
  715. }
  716. #endif
  717. }
  718. return RetVal;
  719. }
  720. /*FUNCTION**********************************************************************
  721. *
  722. * Function Name : Lpuart_Uart_Ip_GetReceiveStatus
  723. * Description : This function returns whether the previous LPUART receive is
  724. * complete. When performing a non-blocking receive, the user can call this
  725. * function to ascertain the state of the current receive progress: in progress
  726. * or complete. In addition, if the receive is still in progress, the user can
  727. * obtain the number of words that have been currently received.
  728. *
  729. * Implements : Lpuart_Uart_Ip_GetReceiveStatus_Activity
  730. *END**************************************************************************/
  731. /* implements Lpuart_Uart_Ip_GetReceiveStatus_Activity*/
  732. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetReceiveStatus(const uint8 Instance, uint32 * BytesRemaining)
  733. {
  734. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  735. const Lpuart_Uart_Ip_StateStructureType * UartState;
  736. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  737. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  738. const Dma_Ip_LogicChannelInfoParamType DmaLogicChnParam = DMA_IP_CH_GET_CURRENT_ITER_COUNT;
  739. #endif
  740. UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  741. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  742. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  743. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  744. if (BytesRemaining != NULL_PTR)
  745. {
  746. if (UartState->IsRxBusy)
  747. {
  748. /* Fill in the bytes transferred. */
  749. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  750. {
  751. /* In interrupt-based communication, the remaining bytes are retrieved
  752. * from the state structure
  753. */
  754. *BytesRemaining = UartState->RxSize;
  755. }
  756. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  757. else
  758. {
  759. /* In DMA-based communication, the remaining bytes are retrieved
  760. * from the current DMA major loop count
  761. */
  762. (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->RxDMAChannel, DmaLogicChnParam, BytesRemaining);
  763. }
  764. #endif
  765. }
  766. else
  767. {
  768. *BytesRemaining = 0;
  769. }
  770. }
  771. return UartState->ReceiveStatus;
  772. }
  773. /*FUNCTION**********************************************************************
  774. *
  775. * Function Name : Lpuart_Uart_Ip_AbortReceivingData
  776. * Description : Terminates a non-blocking receive early.
  777. *
  778. * Implements : Lpuart_Uart_Ip_AbortReceivingData_Activity
  779. *END**************************************************************************/
  780. /* implements Lpuart_Uart_Ip_AbortReceivingData_Activity*/
  781. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortReceivingData(const uint8 Instance)
  782. {
  783. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  784. Lpuart_Uart_Ip_StateStructureType * UartState;
  785. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  786. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  787. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  788. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  789. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  790. LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
  791. boolean IsReturn = FALSE;
  792. Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_ERROR;
  793. /* Check if a transfer is running. */
  794. if (!UartState->IsRxBusy)
  795. {
  796. RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  797. IsReturn = TRUE;
  798. }
  799. if (!IsReturn)
  800. {
  801. /* Update the rx status */
  802. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ABORTED;
  803. /* Stop the running transfer. */
  804. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  805. {
  806. Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
  807. }
  808. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  809. else
  810. {
  811. /* Release the DMA channel */
  812. (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
  813. Lpuart_Uart_Ip_CompleteReceiveUsingDma(Instance);
  814. }
  815. #endif
  816. /* Clear all the error flags */
  817. Lpuart_Uart_Ip_ClearErrorFlags(Base);
  818. /* Flush the Rx Buffer */
  819. Lpuart_Uart_Ip_FlushRxBuffer(Base);
  820. RetVal = LPUART_UART_IP_STATUS_SUCCESS;
  821. }
  822. return RetVal;
  823. }
  824. /*FUNCTION**********************************************************************
  825. *
  826. * Function Name : Lpuart_Uart_Ip_SetBaudRate
  827. * Description : Configures the LPUART baud rate.
  828. * In some LPUART instances the user must disable the transmitter/receiver
  829. * before calling this function.
  830. * Generally, this may be applied to all LPUARTs to ensure safe operation.
  831. *
  832. * Implements : Lpuart_Uart_Ip_SetBaudRate_Activity
  833. *END**************************************************************************/
  834. /* implements Lpuart_Uart_Ip_SetBaudRate_Activity*/
  835. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetBaudRate(const uint8 Instance,
  836. const Lpuart_Uart_Ip_BaudrateType DesiredBaudrate,
  837. const uint32 ClockFrequency)
  838. {
  839. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  840. uint16 Sbr;
  841. uint16 Idx;
  842. uint16 SbrTemp;
  843. uint32 Osr;
  844. uint32 TempDiff;
  845. uint32 CalculatedBaud;
  846. uint32 BaudDiff;
  847. uint32 MaxOsr;
  848. uint32 ExpectedBaud = (uint32)DesiredBaudrate;
  849. LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
  850. Lpuart_Uart_Ip_StateStructureType * UartState;
  851. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  852. Lpuart_Uart_Ip_StatusType Status = LPUART_UART_IP_STATUS_ERROR;
  853. LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
  854. if ((TRUE == UartState->IsTxBusy) || (TRUE == UartState->IsRxBusy))
  855. {
  856. Status = LPUART_UART_IP_STATUS_BUSY;
  857. }
  858. else
  859. {
  860. /* Check if current instance is clock gated off. */
  861. LPUART_UART_IP_DEV_ASSERT(ClockFrequency > 0U);
  862. /* Check if the desired baud rate can be configured with the current protocol clock. */
  863. LPUART_UART_IP_DEV_ASSERT(ClockFrequency >= (ExpectedBaud * 5U));
  864. /* This lpuart instantiation uses a slightly different baud rate calculation
  865. * The idea is to use the best OSR (over-sampling rate) possible
  866. * Note, Osr is typically hard-set to 16 in other lpuart instantiations
  867. * First calculate the baud rate using the minimum OSR possible (4) */
  868. Osr = 4;
  869. Sbr = (uint16)(ClockFrequency / (ExpectedBaud * Osr));
  870. CalculatedBaud = (ClockFrequency / ((uint32)Osr * (uint32)Sbr));
  871. if (CalculatedBaud > ExpectedBaud)
  872. {
  873. BaudDiff = CalculatedBaud - ExpectedBaud;
  874. }
  875. else
  876. {
  877. BaudDiff = ExpectedBaud - CalculatedBaud;
  878. }
  879. /* find maximum Osr */
  880. MaxOsr = ClockFrequency / ExpectedBaud;
  881. if (MaxOsr > 32U)
  882. {
  883. MaxOsr = 32U;
  884. }
  885. /* loop to find the best Osr value possible, one that generates minimum BaudDiff
  886. * iterate through the rest of the supported values of Osr */
  887. if (MaxOsr >= 5U)
  888. {
  889. for (Idx = 5U; Idx <= MaxOsr; Idx++)
  890. {
  891. /* calculate the temporary Sbr value */
  892. SbrTemp = (uint16)(ClockFrequency / (ExpectedBaud * Idx));
  893. /* calculate the baud rate based on the temporary Osr and Sbr values */
  894. CalculatedBaud = (ClockFrequency / ((uint32)Idx * (uint32)SbrTemp));
  895. if (CalculatedBaud > ExpectedBaud)
  896. {
  897. TempDiff = CalculatedBaud - ExpectedBaud;
  898. }
  899. else
  900. {
  901. TempDiff = ExpectedBaud - CalculatedBaud;
  902. }
  903. if (TempDiff <= BaudDiff)
  904. {
  905. BaudDiff = TempDiff;
  906. Osr = Idx; /* update and store the best Osr value calculated */
  907. Sbr = SbrTemp; /* update store the best Sbr value calculated */
  908. }
  909. }
  910. }
  911. /* Check if Osr is between 4x and 7x oversampling.
  912. * If so, then "BOTHEDGE" sampling must be turned on */
  913. if (Osr < 8U)
  914. {
  915. Lpuart_Uart_Ip_EnableBothEdgeSamplingCmd(Base);
  916. }
  917. /* program the Osr value (bit value is one less than actual value) */
  918. Lpuart_Uart_Ip_SetOversamplingRatio(Base, (Osr - 1U));
  919. /* write the Sbr value to the BAUD registers */
  920. Lpuart_Uart_Ip_SetBaudRateDivisor(Base, Sbr);
  921. UartState->BaudRate = CalculatedBaud;
  922. Status = LPUART_UART_IP_STATUS_SUCCESS;
  923. }
  924. return Status;
  925. }
  926. /*FUNCTION**********************************************************************
  927. *
  928. * Function Name : Lpuart_Uart_Ip_GetBaudRate
  929. * Description : Returns the LPUART configured baud rate.
  930. *
  931. * Implements : Lpuart_Uart_Ip_GetBaudRate_Activity
  932. *END**************************************************************************/
  933. /* implements Lpuart_Uart_Ip_GetBaudRate_Activity*/
  934. void Lpuart_Uart_Ip_GetBaudRate(const uint8 Instance, uint32 * ConfiguredBaudRate)
  935. {
  936. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  937. LPUART_UART_IP_DEV_ASSERT(ConfiguredBaudRate != NULL_PTR);
  938. const Lpuart_Uart_Ip_StateStructureType * UartState;
  939. UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  940. *ConfiguredBaudRate = UartState->BaudRate;
  941. }
  942. /*FUNCTION**********************************************************************
  943. *
  944. * Function Name : Lpuart_Uart_Ip_SetTxBuffer
  945. * Description : Sets the driver internal reference to the tx buffer.
  946. * Can be called from the tx callback to provide a different
  947. * buffer for continuous transmission.
  948. *
  949. * Implements : Lpuart_Uart_Ip_SetTxBuffer_Activity
  950. *END**************************************************************************/
  951. /* implements Lpuart_Uart_Ip_SetTxBuffer_Activity*/
  952. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetTxBuffer(const uint8 Instance,
  953. const uint8 * TxBuff,
  954. const uint32 TxSize)
  955. {
  956. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  957. LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
  958. LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
  959. Lpuart_Uart_Ip_StateStructureType * UartState;
  960. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  961. UartState->TxBuff = TxBuff;
  962. UartState->TxSize = TxSize;
  963. return LPUART_UART_IP_STATUS_SUCCESS;
  964. }
  965. /*FUNCTION**********************************************************************
  966. *
  967. * Function Name : Lpuart_Uart_Ip_SetRxBuffer
  968. * Description : Sets the driver internal reference to the rx buffer.
  969. * Can be called from the rx callback to provide a different
  970. * buffer for continuous reception.
  971. *
  972. * Implements : Lpuart_Uart_Ip_SetRxBuffer_Activity
  973. *END**************************************************************************/
  974. /* implements Lpuart_Uart_Ip_SetRxBuffer_Activity*/
  975. Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetRxBuffer(const uint8 Instance,
  976. uint8 * RxBuff,
  977. const uint32 RxSize)
  978. {
  979. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  980. LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
  981. LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
  982. Lpuart_Uart_Ip_StateStructureType * UartState;
  983. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  984. UartState->RxBuff = RxBuff;
  985. UartState->RxSize = RxSize;
  986. return LPUART_UART_IP_STATUS_SUCCESS;
  987. }
  988. //zhengchao
  989. static void Lpuart_Uart_Ip_RxIdleIrqHandler(uint32 Instance)
  990. {
  991. Lpuart_Uart_Ip_StateStructureType * UartState;
  992. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  993. LPUART_Type * Base;
  994. Base = Lpuart_Uart_Ip_apBases[Instance];
  995. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  996. UartUserCfg = (Lpuart_Uart_Ip_UserConfigType*) Lpuart_Uart_Ip_apUserConfig[Instance];
  997. /* Disable receive idle interrupt. */
  998. Lpuart_Uart_Ip_SetIntMode(Base, (uint32)LPUART_CTRL_ILIE_SHIFT, FALSE);
  999. /* Clear idle flag*/
  1000. Base->STAT |= LPUART_STAT_IDLE(0);
  1001. /* Invoke callback if there is one */
  1002. if (UartUserCfg->Callback != NULL_PTR)
  1003. {
  1004. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RECV_IDLE,UartUserCfg->CallbackParam);
  1005. }
  1006. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  1007. //Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2,STD_ON);
  1008. }
  1009. /*FUNCTION**********************************************************************
  1010. *
  1011. * Function Name : Lpuart_Uart_Ip_IrqHandler
  1012. * Description : Interrupt handler for LPUART.
  1013. * This handler uses the buffers stored in the Lpuart_Uart_Ip_StateStructureType structs to transfer
  1014. * data. This is not a public API as it is called by IRQ whenever an interrupt
  1015. * occurs.
  1016. *
  1017. *END**************************************************************************/
  1018. /* implements Lpuart_Uart_Ip_IrqHandler_Activity*/
  1019. void Lpuart_Uart_Ip_IrqHandler(const uint8 Instance)
  1020. {
  1021. LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
  1022. LPUART_Type * Base;
  1023. const Lpuart_Uart_Ip_StateStructureType * UartState;
  1024. Base = Lpuart_Uart_Ip_apBases[Instance];
  1025. UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1026. boolean IsReturn = FALSE;
  1027. /* Case of spurious interrupt when driver is not at all initialized or it is not in transmit/receive process*/
  1028. if (NULL_PTR == UartState)
  1029. {
  1030. /* Read dummy to clear RDRF flag if it is set*/
  1031. (void)Lpuart_Uart_Ip_Getchar(Base);
  1032. /* Clear all the error flags */
  1033. Lpuart_Uart_Ip_ClearErrorFlags(Base);
  1034. /* Transmit flags can not be cleared, return to exit */
  1035. }
  1036. else
  1037. {
  1038. Lpuart_Uart_Ip_ErrIrqHandler(Instance);
  1039. /* Handle receive data full interrupt */
  1040. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL))
  1041. {
  1042. if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL))
  1043. {
  1044. Lpuart_Uart_Ip_RxIrqHandler(Instance);
  1045. }
  1046. /* Case of spurious interrupt when the interupt enable flag is not set and respective interrupt status flag is set */
  1047. else
  1048. {
  1049. /* Read dummy to clear RDRF flag */
  1050. (void)Lpuart_Uart_Ip_Getchar(Base);
  1051. }
  1052. IsReturn = TRUE;
  1053. }
  1054. /* Handle transmitter data register empty interrupt */
  1055. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_DATA_REG_EMPTY) && (FALSE == IsReturn))
  1056. {
  1057. if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY))
  1058. {
  1059. Lpuart_Uart_Ip_TxEmptyIrqHandler(Instance);
  1060. IsReturn = TRUE;
  1061. }
  1062. /* Case of spurious interrupt when the interupt enable flag is not set and respective interrupt status flag is set */
  1063. else
  1064. {
  1065. /* Do nothing, because TDRE can not clear without affecting to normal operation*/
  1066. }
  1067. }
  1068. /* Handle transmission complete interrupt */
  1069. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && (FALSE == IsReturn))
  1070. {
  1071. if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE))
  1072. {
  1073. Lpuart_Uart_Ip_TxCompleteIrqHandler(Instance);
  1074. }
  1075. /* Case of spurious interrupt when the interupt enable flag is not set and respective interrupt status flag is set */
  1076. else
  1077. {
  1078. /* Do nothing, because TC can not clear without affecting to normal operation*/
  1079. }
  1080. }
  1081. /*Handle receiving data idle interrupt*///zhengchao
  1082. if (Lpuart_Uart_Ip_GetStatusFlag(Base, (uint32)LPUART_UART_IP_IDLE) && (FALSE == IsReturn))
  1083. {
  1084. if (Lpuart_Uart_Ip_GetIntMode(Base, (uint32)LPUART_UART_IP_IDLE))
  1085. {
  1086. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1,STD_OFF);
  1087. Lpuart_Uart_Ip_RxIdleIrqHandler(Instance);
  1088. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1,STD_ON);
  1089. //return;
  1090. }
  1091. else
  1092. {
  1093. /* Do nothing*/
  1094. }
  1095. }
  1096. }
  1097. }
  1098. /*FUNCTION**********************************************************************
  1099. *
  1100. * Function Name : Lpuart_Uart_Ip_RxIrqHandler
  1101. * Description : Rx Interrupt handler for LPUART.
  1102. * This function treats the rx full interrupt.
  1103. *
  1104. *END**************************************************************************/
  1105. static void Lpuart_Uart_Ip_RxIrqHandler(const uint8 Instance)
  1106. {
  1107. const Lpuart_Uart_Ip_StateStructureType * UartState;
  1108. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1109. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1110. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1111. /* Get data and put in receive buffer */
  1112. Lpuart_Uart_Ip_GetData(Instance);
  1113. /* Check if this was the last byte in the current buffer */
  1114. if (0U == UartState->RxSize)
  1115. {
  1116. /* Invoke callback if there is one (callback may reset the rx buffer for continuous reception) */
  1117. if (UartUserCfg->Callback != NULL_PTR)
  1118. {
  1119. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RX_FULL, UartUserCfg->CallbackParam);
  1120. }
  1121. }
  1122. /* Finish reception if this was the last byte received */
  1123. if (0U == UartState->RxSize)
  1124. {
  1125. /* Complete transfer (disable rx logic) */
  1126. Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
  1127. /* Invoke callback if there is one */
  1128. if (UartUserCfg->Callback != NULL_PTR)
  1129. {
  1130. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
  1131. }
  1132. }
  1133. }
  1134. /*FUNCTION**********************************************************************
  1135. *
  1136. * Function Name : Lpuart_Uart_Ip_TxEmptyIrqHandler
  1137. * Description : Tx Empty Interrupt handler for LPUART.
  1138. * This function treats the tx empty interrupt.
  1139. *
  1140. *END**************************************************************************/
  1141. static void Lpuart_Uart_Ip_TxEmptyIrqHandler(const uint8 Instance)
  1142. {
  1143. const Lpuart_Uart_Ip_StateStructureType * UartState;
  1144. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1145. LPUART_Type * Base;
  1146. Base = Lpuart_Uart_Ip_apBases[Instance];
  1147. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1148. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1149. /* Check if there are any more bytes to send */
  1150. if (UartState->TxSize > 0U)
  1151. {
  1152. /* Transmit the data */
  1153. Lpuart_Uart_Ip_PutData(Instance);
  1154. /* Check if this was the last byte in the current buffer */
  1155. if ((0U == UartState->TxSize) && (UartUserCfg->Callback != NULL_PTR))
  1156. {
  1157. /* Invoke callback if there is one (callback may reset the tx buffer for continuous transmission)*/
  1158. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_TX_EMPTY, UartUserCfg->CallbackParam);
  1159. }
  1160. /* If there's no new data, disable tx empty interrupt and enable transmission complete interrupt */
  1161. if (0U == UartState->TxSize)
  1162. {
  1163. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
  1164. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, TRUE);
  1165. }
  1166. }
  1167. }
  1168. /*FUNCTION**********************************************************************
  1169. *
  1170. * Function Name : Lpuart_Uart_Ip_TxCompleteIrqHandler
  1171. * Description : Tx Complete Interrupt handler for LPUART.
  1172. * This function treats the tx complete interrupt.
  1173. *
  1174. *END**************************************************************************/
  1175. static void Lpuart_Uart_Ip_TxCompleteIrqHandler(const uint8 Instance)
  1176. {
  1177. const Lpuart_Uart_Ip_StateStructureType * UartState;
  1178. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1179. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1180. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1181. if (0U == UartState->TxSize)
  1182. {
  1183. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  1184. {
  1185. /* Complete the interrupt based transfer */
  1186. Lpuart_Uart_Ip_CompleteSendDataUsingInt(Instance);
  1187. }
  1188. /* Invoke callback if there is one */
  1189. if (UartUserCfg->Callback != NULL_PTR)
  1190. {
  1191. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
  1192. }
  1193. }
  1194. }
  1195. /*FUNCTION**********************************************************************
  1196. *
  1197. * Function Name : Lpuart_Uart_Ip_ErrIrqHandler
  1198. * Description : Error Interrupt handler for LPUART.
  1199. * This function treats the error interrupts.
  1200. *
  1201. *END**************************************************************************/
  1202. static void Lpuart_Uart_Ip_ErrIrqHandler(const uint8 Instance)
  1203. {
  1204. Lpuart_Uart_Ip_StateStructureType * UartState;
  1205. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1206. LPUART_Type * Base;
  1207. boolean IsError = FALSE;
  1208. boolean IsReturn = FALSE;
  1209. Base = Lpuart_Uart_Ip_apBases[Instance];
  1210. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1211. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1212. /* Handle receive overrun interrupt */
  1213. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_RX_OVERRUN))
  1214. {
  1215. /* Clear the flag */
  1216. Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_RX_OVERRUN);
  1217. /* Case of spurious interrupt when interrupt enable bit is not set*/
  1218. if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN))
  1219. {
  1220. IsReturn = TRUE;
  1221. }
  1222. else
  1223. {
  1224. /* Update the status */
  1225. IsError = TRUE;
  1226. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_RX_OVERRUN;
  1227. }
  1228. }
  1229. /* Handle framing error interrupt */
  1230. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_FRAME_ERR) && (FALSE == IsReturn))
  1231. {
  1232. /* Clear the flag */
  1233. Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_FRAME_ERR);
  1234. /* Case of spurious interrupt when interrupt enable bit is not set*/
  1235. if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG))
  1236. {
  1237. IsReturn = TRUE;
  1238. }
  1239. else
  1240. {
  1241. /* Update the status */
  1242. IsError = TRUE;
  1243. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_FRAMING_ERROR;
  1244. }
  1245. }
  1246. /* Handle parity error interrupt */
  1247. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_PARITY_ERR) && (FALSE == IsReturn))
  1248. {
  1249. /* Clear the flag */
  1250. Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_PARITY_ERR);
  1251. /* Case of spurious interrupt when interrupt enable bit is not set*/
  1252. if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG))
  1253. {
  1254. IsReturn = TRUE;
  1255. }
  1256. else
  1257. {
  1258. /* Update the status */
  1259. IsError = TRUE;
  1260. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_PARITY_ERROR;
  1261. }
  1262. }
  1263. /* Handle noise error interrupt */
  1264. if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_NOISE_DETECT) && (FALSE == IsReturn))
  1265. {
  1266. /* Clear the flag */
  1267. Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_NOISE_DETECT);
  1268. /* Case of spurious interrupt when interrupt enable bit is not set*/
  1269. if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG))
  1270. {
  1271. IsReturn = TRUE;
  1272. }
  1273. else
  1274. {
  1275. /* Update the internal status */
  1276. IsError = TRUE;
  1277. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_NOISE_ERROR;
  1278. }
  1279. }
  1280. if (FALSE == IsReturn)
  1281. {
  1282. if (TRUE == IsError)
  1283. {
  1284. if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
  1285. {
  1286. /* Complete the transfer (disable rx logic) */
  1287. Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
  1288. }
  1289. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  1290. else
  1291. {
  1292. /* Complete the transfer (stop DMA channel) */
  1293. (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
  1294. Lpuart_Uart_Ip_CompleteReceiveUsingDma(Instance);
  1295. }
  1296. #endif
  1297. /* Invoke callback if there is one */
  1298. if (UartUserCfg->Callback != NULL_PTR)
  1299. {
  1300. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
  1301. }
  1302. }
  1303. }
  1304. }
  1305. /*FUNCTION**********************************************************************
  1306. *
  1307. * Function Name : Lpuart_Uart_Ip_StartSendDataUsingInt
  1308. * Description : Initiate (start) a transmit by beginning the process of
  1309. * sending data and enabling the interrupt.
  1310. * This is not a public API as it is called from other driver functions.
  1311. *
  1312. *END**************************************************************************/
  1313. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingInt(const uint8 Instance,
  1314. const uint8 * TxBuff,
  1315. const uint32 TxSize)
  1316. {
  1317. LPUART_Type * Base;
  1318. Lpuart_Uart_Ip_StateStructureType * UartState;
  1319. Base = Lpuart_Uart_Ip_apBases[Instance];
  1320. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1321. /* initialize the module driver state structure */
  1322. UartState->TxBuff = TxBuff;
  1323. UartState->TxSize = TxSize;
  1324. UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
  1325. /* Enable the LPUART transmitter */
  1326. Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
  1327. /* Enable tx empty interrupt */
  1328. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, TRUE);
  1329. return LPUART_UART_IP_STATUS_SUCCESS;
  1330. }
  1331. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  1332. /*FUNCTION**********************************************************************
  1333. *
  1334. * Function Name : Lpuart_Uart_Ip_StartSendDataUsingDma
  1335. * Description : Initiate (start) a transmit by beginning the process of
  1336. * sending data using DMA transfers.
  1337. * This is not a public API as it is called from other driver functions.
  1338. *
  1339. *END**************************************************************************/
  1340. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingDma(const uint8 Instance,
  1341. const uint8 * TxBuff,
  1342. const uint32 TxSize)
  1343. {
  1344. Lpuart_Uart_Ip_StateStructureType * UartState;
  1345. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1346. LPUART_Type * Base;
  1347. Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
  1348. Dma_Ip_ReturnType DmaReturnStatus;
  1349. Base = Lpuart_Uart_Ip_apBases[Instance];
  1350. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1351. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1352. /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
  1353. DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
  1354. DmaTransferList[0].Value = (uint32)TxBuff;
  1355. DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  1356. DmaTransferList[1].Value = LPUART_UART_IP_LSBW_ADDR(Base->DATA);
  1357. DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
  1358. DmaTransferList[2].Value = 1;
  1359. DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
  1360. DmaTransferList[3].Value = 0;
  1361. DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
  1362. DmaTransferList[4].Value = TxSize;
  1363. DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
  1364. DmaTransferList[5].Value = 1;
  1365. DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
  1366. DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
  1367. DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
  1368. DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
  1369. DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
  1370. DmaTransferList[8].Value = 1;
  1371. DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
  1372. DmaTransferList[9].Value = 1;
  1373. /* Update state structure */
  1374. UartState->TxBuff = TxBuff;
  1375. UartState->TxSize = 0U;
  1376. UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
  1377. /* Configure the transfer control descriptor for the DMA channel */
  1378. DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION);
  1379. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1380. /* Start the DMA channel */
  1381. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1382. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1383. /* Enable the LPUART transmitter */
  1384. Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
  1385. /* Enable tx DMA requests for the current instance */
  1386. Lpuart_Uart_Ip_SetTxDmaCmd(Base, TRUE);
  1387. return LPUART_UART_IP_STATUS_SUCCESS;
  1388. }
  1389. #endif
  1390. /*FUNCTION**********************************************************************
  1391. *
  1392. * Function Name : Lpuart_Uart_Ip_CompleteSendDataUsingInt
  1393. * Description : Finish up a transmit by completing the process of sending
  1394. * data and disabling the interrupt.
  1395. * This is not a public API as it is called from other driver functions.
  1396. *
  1397. *END**************************************************************************/
  1398. static void Lpuart_Uart_Ip_CompleteSendDataUsingInt(const uint8 Instance)
  1399. {
  1400. Lpuart_Uart_Ip_StateStructureType * UartState;
  1401. LPUART_Type * Base;
  1402. uint32 StartTime;
  1403. uint32 TimeoutTicks;
  1404. uint32 ElapsedTicks = 0;
  1405. Base = Lpuart_Uart_Ip_apBases[Instance];
  1406. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1407. if (LPUART_UART_IP_STATUS_BUSY != UartState->TransmitStatus)
  1408. {
  1409. /* If the transfer is aborted or timed out, disable tx empty interrupt */
  1410. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
  1411. }
  1412. /* Disable transmission complete interrupt */
  1413. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
  1414. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
  1415. /* Wait until the data is completely shifted out of shift register */
  1416. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
  1417. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1418. {}
  1419. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1420. {
  1421. /* In case timeout occur */
  1422. UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
  1423. }
  1424. /* Disable transmitter */
  1425. Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
  1426. if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
  1427. {
  1428. /* If the transfer is completed, update the transmit status */
  1429. UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
  1430. }
  1431. /* Update the internal busy flag */
  1432. UartState->IsTxBusy = FALSE;
  1433. }
  1434. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  1435. /*FUNCTION**********************************************************************
  1436. *
  1437. * Function Name : Lpuart_Uart_Ip_CompleteSendUsingDma
  1438. * Description : Finish up a transmit by completing the process of sending
  1439. * data and disabling the DMA requests. This is a callback for DMA major loop
  1440. * completion, so it must match the DMA callback signature.
  1441. *
  1442. *END**************************************************************************/
  1443. void Lpuart_Uart_Ip_CompleteSendUsingDma(uint8 Instance)
  1444. {
  1445. Lpuart_Uart_Ip_StateStructureType * UartState;
  1446. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1447. LPUART_Type * Base;
  1448. Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
  1449. Dma_Ip_ReturnType DmaReturnStatus;
  1450. Dma_Ip_LogicChannelStatusType DmaStatus;
  1451. uint32 StartTime;
  1452. uint32 TimeoutTicks;
  1453. uint32 ElapsedTicks = 0;
  1454. Base = Lpuart_Uart_Ip_apBases[Instance];
  1455. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1456. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1457. /* Get Dma Ip Logic Channel Status */
  1458. (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->TxDMAChannel, &DmaStatus);
  1459. if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
  1460. {
  1461. /* Reset the Dma Channel Error status. */
  1462. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
  1463. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1464. /* Update transmit status */
  1465. UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
  1466. /* Invoke callback if there is one */
  1467. if (UartUserCfg->Callback != NULL_PTR)
  1468. {
  1469. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
  1470. }
  1471. }
  1472. /* Invoke the callback when the buffer is finished;
  1473. * Application can provide another buffer inside the callback by calling Lpuart_Uart_Ip_SetTxBuffer */
  1474. if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
  1475. {
  1476. /* Invoke callback if there is one (callback may reset the tx buffer for continuous transmission)*/
  1477. if (UartUserCfg->Callback != NULL_PTR)
  1478. {
  1479. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_TX_EMPTY, UartUserCfg->CallbackParam);
  1480. }
  1481. }
  1482. /* If the callback has updated the tx buffer, update the DMA descriptor to continue the transfer;
  1483. * otherwise, stop the current transfer.
  1484. */
  1485. if ((UartState->TxSize > 0U) && (UartState->TransmitStatus != LPUART_UART_IP_STATUS_ERROR))
  1486. {
  1487. /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
  1488. DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
  1489. DmaTransferList[0].Value = (uint32)(UartState->TxBuff);
  1490. /* Update tx size and major loop count parameters for Dma_Ip_LogicChannelTransferListType */
  1491. DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
  1492. DmaTransferList[1].Value = UartState->TxSize;
  1493. /* Re-configure the transfer control descriptor for the DMA channel */
  1494. DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION);
  1495. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1496. /* Now that this tx is set up, clear remaining bytes count */
  1497. UartState->TxSize = 0U;
  1498. /* Re-start the channel */
  1499. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1500. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1501. }
  1502. else
  1503. {
  1504. /* Disable tx DMA requests for the current instance */
  1505. Lpuart_Uart_Ip_SetTxDmaCmd(Base, FALSE);
  1506. /* Wait until the last transmission complete */
  1507. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
  1508. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
  1509. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1510. {}
  1511. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1512. {
  1513. /* In case timeout occur */
  1514. UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
  1515. }
  1516. /* Disable the transmitter */
  1517. Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
  1518. if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
  1519. {
  1520. /* If the transfer is completed, update the transmit status */
  1521. UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
  1522. /* Invoke callback if there is one */
  1523. if (UartUserCfg->Callback != NULL_PTR)
  1524. {
  1525. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
  1526. }
  1527. }
  1528. /* Update the busy flag */
  1529. UartState->IsTxBusy = FALSE;
  1530. }
  1531. }
  1532. #endif
  1533. /*FUNCTION**********************************************************************
  1534. *
  1535. * Function Name : Lpuart_Uart_Ip_StartReceiveDataUsingInt
  1536. * Description : Initiate (start) a receive by beginning the process of
  1537. * receiving data and enabling the interrupt.
  1538. * This is not a public API as it is called from other driver functions.
  1539. *
  1540. *END**************************************************************************/
  1541. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingInt(const uint8 Instance,
  1542. uint8 * RxBuff,
  1543. const uint32 RxSize)
  1544. {
  1545. LPUART_Type * Base;
  1546. Lpuart_Uart_Ip_StateStructureType * UartState;
  1547. Base = Lpuart_Uart_Ip_apBases[Instance];
  1548. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1549. /* Initialize the module driver state struct to indicate transfer in progress
  1550. * and with the buffer and byte count data. */
  1551. UartState->IsRxBusy = TRUE;
  1552. UartState->RxBuff = RxBuff;
  1553. UartState->RxSize = RxSize;
  1554. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
  1555. /* Clear all the error flags */
  1556. Lpuart_Uart_Ip_ClearErrorFlags(Base);
  1557. /* Flush the Tx Buffer */
  1558. Lpuart_Uart_Ip_FlushRxBuffer(Base);
  1559. /* Enable the receiver */
  1560. Lpuart_Uart_Ip_SetReceiverCmd(Base, TRUE);
  1561. /* Enable error interrupts */
  1562. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, TRUE);
  1563. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, TRUE);
  1564. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, TRUE);
  1565. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, TRUE);
  1566. /* Enable receive data full interrupt */
  1567. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, TRUE);
  1568. return LPUART_UART_IP_STATUS_SUCCESS;
  1569. }
  1570. #if (STD_ON == LPUART_UART_IP_HAS_DMA_ENABLED)
  1571. /*FUNCTION**********************************************************************
  1572. *
  1573. * Function Name : Lpuart_Uart_Ip_StartReceiveDataUsingDma
  1574. * Description : Initiate (start) a receive by beginning the process of
  1575. * receiving data using DMA transfers.
  1576. * This is not a public API as it is called from other driver functions.
  1577. *
  1578. *END**************************************************************************/
  1579. static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingDma(const uint8 Instance,
  1580. uint8 * RxBuff,
  1581. const uint32 RxSize)
  1582. {
  1583. Lpuart_Uart_Ip_StateStructureType * UartState;
  1584. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1585. LPUART_Type * Base;
  1586. Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
  1587. Dma_Ip_ReturnType DmaReturnStatus;
  1588. Base = Lpuart_Uart_Ip_apBases[Instance];
  1589. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1590. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1591. /* Clear all the error flags */
  1592. Lpuart_Uart_Ip_ClearErrorFlags(Base);
  1593. /* Flush the Tx Buffer */
  1594. Lpuart_Uart_Ip_FlushRxBuffer(Base);
  1595. /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
  1596. DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
  1597. DmaTransferList[0].Value = LPUART_UART_IP_LSBW_ADDR(Base->DATA);
  1598. DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  1599. DmaTransferList[1].Value = (uint32)RxBuff;
  1600. DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
  1601. DmaTransferList[2].Value = 0;
  1602. DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
  1603. DmaTransferList[3].Value = 1;
  1604. DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
  1605. DmaTransferList[4].Value = RxSize;
  1606. DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
  1607. DmaTransferList[5].Value = 1;
  1608. DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
  1609. DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
  1610. DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
  1611. DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
  1612. DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
  1613. DmaTransferList[8].Value = 1;
  1614. DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
  1615. DmaTransferList[9].Value = 1;
  1616. /* Update the state structure */
  1617. UartState->RxBuff = RxBuff;
  1618. UartState->RxSize = 0U;
  1619. UartState->IsRxBusy = TRUE;
  1620. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
  1621. /* Configure the transfer control descriptor for the DMA channel */
  1622. DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION);
  1623. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1624. /* Start the DMA channel */
  1625. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1626. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1627. /* Enable the receiver */
  1628. Lpuart_Uart_Ip_SetReceiverCmd(Base, TRUE);
  1629. /* Enable error interrupts and enable rx DMA requests for the current instance */
  1630. Lpuart_Uart_Ip_SetupIntDmaMode(Instance, TRUE);
  1631. return LPUART_UART_IP_STATUS_SUCCESS;
  1632. }
  1633. #endif
  1634. /*FUNCTION**********************************************************************
  1635. *
  1636. * Function Name : Lpuart_Uart_Ip_CompleteReceiveDataUsingInt
  1637. * Description : Finish up a receive by completing the process of receiving data
  1638. * and disabling the interrupt.
  1639. * This is not a public API as it is called from other driver functions.
  1640. *
  1641. *END**************************************************************************/
  1642. static void Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(const uint8 Instance)
  1643. {
  1644. LPUART_Type * Base;
  1645. Lpuart_Uart_Ip_StateStructureType * UartState;
  1646. uint32 StartTime;
  1647. uint32 TimeoutTicks;
  1648. uint32 ElapsedTicks = 0;
  1649. Base = Lpuart_Uart_Ip_apBases[Instance];
  1650. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1651. /* Disable all error interrupts */
  1652. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, FALSE);
  1653. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, FALSE);
  1654. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, FALSE);
  1655. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, FALSE);
  1656. /* Disable receive data full and rx overrun interrupt. */
  1657. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
  1658. /* In Abort case, the transmission need to stop instantly */
  1659. if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
  1660. {
  1661. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
  1662. /* Wait until the data is completely received */
  1663. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
  1664. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1665. {}
  1666. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1667. {
  1668. /* In case timeout occur */
  1669. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
  1670. }
  1671. }
  1672. /* Disable receiver */
  1673. Lpuart_Uart_Ip_SetReceiverCmd(Base, FALSE);
  1674. /* Read dummy to clear RDRF flag */
  1675. (void)Lpuart_Uart_Ip_Getchar(Base);
  1676. /* Update the information of the module driver state */
  1677. UartState->IsRxBusy = FALSE;
  1678. if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
  1679. {
  1680. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  1681. }
  1682. }
  1683. #if (STD_ON == LPUART_UART_IP_HAS_DMA_ENABLED)
  1684. /*FUNCTION**********************************************************************
  1685. *
  1686. * Function Name : Lpuart_Uart_Ip_CompleteReceiveUsingDma
  1687. * Description : Finish up a receive by completing the process of receiving data
  1688. * and disabling the DMA requests. This is a callback for DMA major loop
  1689. * completion, so it must match the DMA callback signature.
  1690. *
  1691. *END**************************************************************************/
  1692. void Lpuart_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance)
  1693. {
  1694. Lpuart_Uart_Ip_StateStructureType * UartState;
  1695. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1696. LPUART_Type * Base;
  1697. Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
  1698. Dma_Ip_ReturnType DmaReturnStatus;
  1699. Dma_Ip_LogicChannelStatusType DmaStatus;
  1700. uint32 StartTime;
  1701. uint32 TimeoutTicks;
  1702. uint32 ElapsedTicks = 0;
  1703. Base = Lpuart_Uart_Ip_apBases[Instance];
  1704. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1705. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1706. /* Get Dma Ip Logic Channel Status */
  1707. (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->RxDMAChannel, &DmaStatus);
  1708. if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
  1709. {
  1710. /* Reset the Dma Channel Error status. */
  1711. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
  1712. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1713. /* Update transmit status */
  1714. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
  1715. /* Invoke callback if there is one */
  1716. if (UartUserCfg->Callback != NULL_PTR)
  1717. {
  1718. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
  1719. }
  1720. }
  1721. /* Invoke the callback when the buffer is finished */
  1722. if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
  1723. {
  1724. /* Application can provide another buffer inside the callback by calling Lpuart_Uart_Ip_SetRxBuffer */
  1725. if (UartUserCfg->Callback != NULL_PTR)
  1726. {
  1727. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RX_FULL, UartUserCfg->CallbackParam);
  1728. }
  1729. }
  1730. /* If the callback has updated the rx buffer, update the DMA descriptor to continue the transfer;
  1731. * otherwise, stop the current transfer.
  1732. */
  1733. if ((UartState->RxSize > 0U) && (UartState->ReceiveStatus != LPUART_UART_IP_STATUS_ERROR))
  1734. {
  1735. /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
  1736. DmaTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  1737. DmaTransferList[0].Value = (uint32)(UartState->RxBuff);
  1738. DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
  1739. DmaTransferList[1].Value = UartState->RxSize;
  1740. /* Re-configure the transfer control descriptor for the DMA channel */
  1741. DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION);
  1742. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1743. /* Now that this rx is set up, clear remaining bytes count */
  1744. UartState->RxSize = 0U;
  1745. /* Re-start the channel */
  1746. DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1747. LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
  1748. }
  1749. else
  1750. {
  1751. /* Disable error interrupts and disable rx DMA requests for the current instance*/
  1752. Lpuart_Uart_Ip_SetupIntDmaMode(Instance, FALSE);
  1753. /* In Abort case, the transmission need to stop instantly */
  1754. if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
  1755. {
  1756. /* Wait until the last transmission complete */
  1757. Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
  1758. while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
  1759. !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1760. {}
  1761. if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
  1762. {
  1763. /* In case timeout occur */
  1764. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
  1765. }
  1766. }
  1767. /* Disable receiver */
  1768. Lpuart_Uart_Ip_SetReceiverCmd(Base, FALSE);
  1769. /* Read dummy to clear RDRF flag */
  1770. (void)Lpuart_Uart_Ip_Getchar(Base);
  1771. /* Update the information of the module driver state */
  1772. UartState->IsRxBusy = FALSE;
  1773. /* If the current reception hasn't been aborted, update the status and call the callback */
  1774. if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
  1775. {
  1776. UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
  1777. /* Call the callback to notify application that the transfer is complete */
  1778. if (UartUserCfg->Callback != NULL_PTR)
  1779. {
  1780. UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
  1781. }
  1782. }
  1783. }
  1784. }
  1785. /*FUNCTION**********************************************************************
  1786. *
  1787. * Function Name : Lpuart_Uart_Ip_SetupIntDmaMode
  1788. * Description : Setup error interrupts and Setup rx DMA requests for
  1789. * the current instance
  1790. * This is not a public API as it is called from other driver functions.
  1791. *
  1792. *END**************************************************************************/
  1793. static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable)
  1794. {
  1795. LPUART_Type * Base;
  1796. Base = Lpuart_Uart_Ip_apBases[Instance];
  1797. /* Setup error interrupts */
  1798. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, Enable);
  1799. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, Enable);
  1800. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, Enable);
  1801. Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, Enable);
  1802. /* Setup rx DMA requests for the current instance */
  1803. Lpuart_Uart_Ip_SetRxDmaCmd(Base, Enable);
  1804. }
  1805. #endif
  1806. /*FUNCTION**********************************************************************
  1807. *
  1808. * Function Name : Lpuart_Uart_Ip_PutData
  1809. * Description : Write data to the buffer register, according to configured
  1810. * word length.
  1811. * This is not a public API as it is called from other driver functions.
  1812. *
  1813. *END**************************************************************************/
  1814. static void Lpuart_Uart_Ip_PutData(const uint8 Instance)
  1815. {
  1816. Lpuart_Uart_Ip_StateStructureType * UartState;
  1817. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1818. LPUART_Type * Base;
  1819. uint16 Data16b;
  1820. uint8 Data8b;
  1821. Base = Lpuart_Uart_Ip_apBases[Instance];
  1822. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1823. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1824. if ((LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar) || (LPUART_UART_IP_8_BITS_PER_CHAR == UartUserCfg->BitCountPerChar))
  1825. {
  1826. Data8b = *(UartState->TxBuff);
  1827. /* Update the state structure */
  1828. ++UartState->TxBuff;
  1829. --UartState->TxSize;
  1830. /* Transmit the data */
  1831. Lpuart_Uart_Ip_Putchar(Base, Data8b);
  1832. }
  1833. else
  1834. {
  1835. Data16b = (uint16)(*UartState->TxBuff);
  1836. /* Update the state structure */
  1837. if (1U == UartState->TxSize)
  1838. {
  1839. ++UartState->TxBuff;
  1840. --UartState->TxSize;
  1841. }
  1842. else
  1843. {
  1844. ++UartState->TxBuff;
  1845. Data16b |= (uint16)(((uint16)(*UartState->TxBuff)) << 8U);
  1846. ++UartState->TxBuff;
  1847. UartState->TxSize -= 2U;
  1848. }
  1849. /* Transmit the data */
  1850. if (LPUART_UART_IP_9_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
  1851. {
  1852. Lpuart_Uart_Ip_Putchar9(Base, Data16b);
  1853. }
  1854. else
  1855. {
  1856. Lpuart_Uart_Ip_Putchar10(Base, Data16b);
  1857. }
  1858. }
  1859. }
  1860. /*FUNCTION**********************************************************************
  1861. *
  1862. * Function Name : Lpuart_Uart_Ip_GetData
  1863. * Description : Read data from the buffer register, according to configured
  1864. * word length.
  1865. * This is not a public API as it is called from other driver functions.
  1866. *
  1867. *END**************************************************************************/
  1868. static void Lpuart_Uart_Ip_GetData(const uint8 Instance)
  1869. {
  1870. Lpuart_Uart_Ip_StateStructureType * UartState;
  1871. const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
  1872. const LPUART_Type * Base;
  1873. uint16 Data16b;
  1874. Base = (const LPUART_Type *)Lpuart_Uart_Ip_apBases[Instance];
  1875. UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
  1876. UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
  1877. if ((LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar) || (LPUART_UART_IP_8_BITS_PER_CHAR == UartUserCfg->BitCountPerChar))
  1878. {
  1879. /* Receive the data */
  1880. *(UartState->RxBuff) = Lpuart_Uart_Ip_Getchar(Base);
  1881. if (LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
  1882. {
  1883. *(UartState->RxBuff) &= 0x7FU;
  1884. }
  1885. /* Update the state structure */
  1886. ++UartState->RxBuff;
  1887. --UartState->RxSize;
  1888. }
  1889. else
  1890. {
  1891. if (LPUART_UART_IP_9_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
  1892. {
  1893. Data16b = Lpuart_Uart_Ip_Getchar9(Base);
  1894. }
  1895. else
  1896. {
  1897. Data16b = Lpuart_Uart_Ip_Getchar10(Base);
  1898. }
  1899. /* Get the data and update state structure */
  1900. if (1U == UartState->RxSize)
  1901. {
  1902. *(UartState->RxBuff) = (uint8)Data16b;
  1903. ++UartState->RxBuff;
  1904. --UartState->RxSize;
  1905. }
  1906. else
  1907. {
  1908. /* Write the least significant bits to the receive buffer */
  1909. *(UartState->RxBuff) = (uint8)(Data16b & 0xFFU);
  1910. ++UartState->RxBuff;
  1911. /* Write the ninth bit to the subsequent byte in the rx buffer */
  1912. *UartState->RxBuff = (uint8)(Data16b >> 8U);
  1913. ++UartState->RxBuff;
  1914. UartState->RxSize -= 2U;
  1915. }
  1916. }
  1917. }
  1918. #define UART_STOP_SEC_CODE
  1919. #include "Uart_MemMap.h"
  1920. #ifdef __cplusplus
  1921. }
  1922. /** @} */
  1923. #endif