12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180 |
- #include "Port.h"
- #include "Dio.h"
- #ifdef __cplusplus
- extern "C"{
- #endif
- #include "Lpuart_Uart_Ip.h"
- #include "Lpuart_Uart_Ip_HwAccess.h"
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- #include "Dma_Ip.h"
- #endif
- #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
- #if (LPUART_UART_IP_DEV_ERROR_DETECT == STD_ON)
- #include "Devassert.h"
- #endif
- #endif
- #define LPUART_UART_IP_VENDOR_ID_C 43
- #define LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C 4
- #define LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C 4
- #define LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C 0
- #define LPUART_UART_IP_SW_MAJOR_VERSION_C 1
- #define LPUART_UART_IP_SW_MINOR_VERSION_C 0
- #define LPUART_UART_IP_SW_PATCH_VERSION_C 0
- #if (LPUART_UART_IP_VENDOR_ID_C != LPUART_UART_IP_VENDOR_ID)
- #error "Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h have different vendor ids"
- #endif
- #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION) || \
- (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MINOR_VERSION) || \
- (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C != LPUART_UART_IP_AR_RELEASE_REVISION_VERSION))
- #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h are different"
- #endif
- #if ((LPUART_UART_IP_SW_MAJOR_VERSION_C != LPUART_UART_IP_SW_MAJOR_VERSION) || \
- (LPUART_UART_IP_SW_MINOR_VERSION_C != LPUART_UART_IP_SW_MINOR_VERSION) || \
- (LPUART_UART_IP_SW_PATCH_VERSION_C != LPUART_UART_IP_SW_PATCH_VERSION))
- #error "Software Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip.h are different"
- #endif
- #if (LPUART_UART_IP_VENDOR_ID_C != LPUART_UART_IP_HWACCESS_VENDOR_ID)
- #error "Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h have different vendor ids"
- #endif
- #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION) || \
- (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION) || \
- (LPUART_UART_IP_AR_RELEASE_REVISION_VERSION_C != LPUART_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION))
- #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h are different"
- #endif
- #if ((LPUART_UART_IP_SW_MAJOR_VERSION_C != LPUART_UART_IP_HWACCESS_SW_MAJOR_VERSION) || \
- (LPUART_UART_IP_SW_MINOR_VERSION_C != LPUART_UART_IP_HWACCESS_SW_MINOR_VERSION) || \
- (LPUART_UART_IP_SW_PATCH_VERSION_C != LPUART_UART_IP_HWACCESS_SW_PATCH_VERSION))
- #error "Software Version Numbers of Lpuart_Uart_Ip.c and Lpuart_Uart_Ip_HwAccess.h are different"
- #endif
- #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
-
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DMA_IP_AR_RELEASE_MAJOR_VERSION_H) || \
- (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != DMA_IP_AR_RELEASE_MINOR_VERSION_H))
- #error "AutoSar Version Numbers of Lpuart_Uart_Ip.c and Dma_Ip.h are different"
- #endif
- #endif
-
- #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
- #if (STD_ON == LPUART_UART_IP_DEV_ERROR_DETECT)
-
- #if ((LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
- (LPUART_UART_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION))
- #error "AutoSar Version Numbers of Lpuart_Uart_Ip.c and Devassert.h are different"
- #endif
- #endif
- #endif
- #endif
- #ifdef LPUART_UART_IP_DEV_ERROR_DETECT
- #if (LPUART_UART_IP_DEV_ERROR_DETECT == STD_ON)
- #define LPUART_UART_IP_DEV_ASSERT(x) DevAssert(x)
- #else
- #define LPUART_UART_IP_DEV_ASSERT(x) (void)(x)
- #endif
- #endif
- #define LPUART_UART_IP_LSBW_ADDR(reg) ((uint32)(&(reg)))
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- #define LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION (10U)
- #define LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION (2U)
- #endif
- #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
- #include "Uart_MemMap.h"
- Lpuart_Uart_Ip_StateStructureType Lpuart_Uart_Ip_apStateStructure[LPUART_UART_IP_NUMBER_OF_INSTANCES];
- #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
- #include "Uart_MemMap.h"
- #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED
- #include "Uart_MemMap.h"
- static Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
- const Lpuart_Uart_Ip_UserConfigType * Lpuart_Uart_Ip_apUserConfig[LPUART_UART_IP_NUMBER_OF_INSTANCES];
- #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED
- #include "Uart_MemMap.h"
- #define UART_START_SEC_CONST_UNSPECIFIED
- #include "Uart_MemMap.h"
- static LPUART_Type * const Lpuart_Uart_Ip_apBases[LPUART_UART_IP_NUMBER_OF_INSTANCES] = IP_LPUART_BASE_PTRS;
- #define UART_STOP_SEC_CONST_UNSPECIFIED
- #include "Uart_MemMap.h"
- #define UART_START_SEC_CODE
- #include "Uart_MemMap.h"
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingInt(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize);
- static void Lpuart_Uart_Ip_CompleteSendDataUsingInt(const uint8 Instance);
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingInt(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize);
- static void Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(const uint8 Instance);
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingDma(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize);
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingDma(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize);
- static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable);
- #endif
- static void Lpuart_Uart_Ip_PutData(const uint8 Instance);
- static void Lpuart_Uart_Ip_GetData(const uint8 Instance);
- static void Lpuart_Uart_Ip_RxIrqHandler(const uint8 Instance);
- static void Lpuart_Uart_Ip_TxEmptyIrqHandler(const uint8 Instance);
- static void Lpuart_Uart_Ip_TxCompleteIrqHandler(const uint8 Instance);
- static void Lpuart_Uart_Ip_ErrIrqHandler(const uint8 Instance);
- static void Lpuart_Uart_Ip_StartGetData(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks);
- void Lpuart_Uart_Ip_Init(const uint8 Instance, const Lpuart_Uart_Ip_UserConfigType * UserConfig)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(UserConfig != NULL_PTR);
-
- LPUART_UART_IP_DEV_ASSERT(NULL_PTR == Lpuart_Uart_Ip_apStateStructuresArray[Instance]);
-
- LPUART_UART_IP_DEV_ASSERT(UserConfig->BaudOverSamplingRatio <= 0x20U);
- LPUART_UART_IP_DEV_ASSERT((UserConfig->BaudRateDivisor <= 0x1FFFU) && \
- (UserConfig->BaudRateDivisor >= 1U));
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- Lpuart_Uart_Ip_StateStructureType *UartStatePtr;
- uint32 Index;
- uint8 *ClearStructPtr;
- Lpuart_Uart_Ip_apStateStructuresArray[Instance] = UserConfig->StateStruct;
- UartStatePtr = Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- Lpuart_Uart_Ip_apUserConfig[Instance] = UserConfig;
- ClearStructPtr = (uint8 *)UartStatePtr;
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
-
- LPUART_UART_IP_DEV_ASSERT((UserConfig->TransferType != LPUART_UART_IP_USING_DMA) || \
- ((LPUART_UART_IP_7_BITS_PER_CHAR == UserConfig->BitCountPerChar) || \
- (LPUART_UART_IP_8_BITS_PER_CHAR == UserConfig->BitCountPerChar)));
- #endif
-
- LPUART_UART_IP_DEV_ASSERT((UserConfig->BitCountPerChar != LPUART_UART_IP_10_BITS_PER_CHAR) || \
- (LPUART_UART_IP_PARITY_DISABLED == UserConfig->ParityMode));
-
- for (Index = 0; Index < sizeof(Lpuart_Uart_Ip_StateStructureType); Index++)
- {
- ClearStructPtr[Index] = 0;
- }
-
- Lpuart_Uart_Ip_Hw_Init(Base);
-
- if (UserConfig->BaudOverSamplingRatio < 8U)
- {
- Lpuart_Uart_Ip_EnableBothEdgeSamplingCmd(Base);
- }
-
- Lpuart_Uart_Ip_SetOversamplingRatio(Base, (uint32)UserConfig->BaudOverSamplingRatio -1U);
-
- Lpuart_Uart_Ip_SetBaudRateDivisor(Base, UserConfig->BaudRateDivisor);
- if (UserConfig->ParityMode != LPUART_UART_IP_PARITY_DISABLED)
- {
- Lpuart_Uart_Ip_SetBitCountPerChar(Base, UserConfig->BitCountPerChar, TRUE);
- }
- else
- {
- Lpuart_Uart_Ip_SetBitCountPerChar(Base, UserConfig->BitCountPerChar, FALSE);
- }
- Lpuart_Uart_Ip_SetParityMode(Base, UserConfig->ParityMode);
- Lpuart_Uart_Ip_SetStopBitCount(Base, UserConfig->StopBitsCount);
-
- UartStatePtr->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
- UartStatePtr->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
-
- UartStatePtr->BaudRate = UserConfig->BaudRate;
- }
- void Lpuart_Uart_Ip_Deinit(const uint8 Instance)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
-
- LPUART_UART_IP_DEV_ASSERT(Lpuart_Uart_Ip_apStateStructuresArray[Instance] != NULL_PTR);
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
-
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, FALSE);
-
- Lpuart_Uart_Ip_apStateStructuresArray[Instance] = NULL_PTR;
- }
-
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncSend(const uint8 Instance,
- const uint8 *TxBuff,
- const uint32 TxSize,
- const uint32 Timeout)
- {
-
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
- LPUART_Type * Base;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- boolean IsReturn = FALSE;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- SchM_Enter_Uart_UART_EXCLUSIVE_AREA_00();
-
- if (UartState->IsTxBusy)
- {
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_00();
- RetVal = LPUART_UART_IP_STATUS_BUSY;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
- UartState->IsTxBusy = TRUE;
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_00();
- UartState->TxBuff = TxBuff;
- UartState->TxSize = TxSize;
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LPUART_UART_IP_TIMEOUT_TYPE);
- while ((UartState->TxSize > 0U) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
- Lpuart_Uart_Ip_PutData(Instance);
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_DATA_REG_EMPTY) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
- }
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
-
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_TIMEOUT;
- }else
- {
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
- }
- UartState->IsTxBusy = FALSE;
- RetVal = UartState->TransmitStatus;
- }
- return RetVal;
- }
-
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncSend(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize)
- {
-
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- boolean IsReturn = FALSE;
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- SchM_Enter_Uart_UART_EXCLUSIVE_AREA_01();
-
- if (UartState->IsTxBusy)
- {
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_01();
- RetVal = LPUART_UART_IP_STATUS_BUSY;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
- UartState->IsTxBusy = TRUE;
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_01();
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT((LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType) ||
- (LPUART_UART_IP_USING_DMA == UartUserCfg->TransferType));
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- RetVal = Lpuart_Uart_Ip_StartSendDataUsingInt(Instance, TxBuff, TxSize);
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- RetVal = Lpuart_Uart_Ip_StartSendDataUsingDma(Instance, TxBuff, TxSize);
- }
- #endif
- }
- return RetVal;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetTransmitStatus(const uint8 Instance, uint32 * BytesRemaining)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- const Dma_Ip_LogicChannelInfoParamType DmaLogicChnParam = DMA_IP_CH_GET_CURRENT_ITER_COUNT;
- #endif
- UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
- if (BytesRemaining != NULL_PTR)
- {
- if (UartState->IsTxBusy)
- {
-
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- *BytesRemaining = UartState->TxSize;;
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->TxDMAChannel, DmaLogicChnParam, BytesRemaining);
- }
- #endif
- }
- else
- {
- *BytesRemaining = 0;
- }
- }
- return UartState->TransmitStatus;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortSendingData(const uint8 Instance)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- boolean IsReturn = FALSE;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
-
- if (!UartState->IsTxBusy)
- {
- RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_ABORTED;
-
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
- Lpuart_Uart_Ip_CompleteSendDataUsingInt(Instance);
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
- Lpuart_Uart_Ip_CompleteSendUsingDma(Instance);
- }
- #endif
-
- Lpuart_Uart_Ip_FlushTxBuffer(Base);
- RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- }
- return RetVal;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SyncReceive(const uint8 Instance,
- uint8 *RxBuff,
- const uint32 RxSize,
- const uint32 Timeout)
- {
-
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- Lpuart_Uart_Ip_StateStructureType * UartState;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- boolean IsReturn = FALSE;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- SchM_Enter_Uart_UART_EXCLUSIVE_AREA_02();
-
- if (UartState->IsRxBusy)
- {
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_02();
- RetVal = LPUART_UART_IP_STATUS_BUSY;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
- UartState->IsRxBusy = TRUE;
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_02();
- UartState->RxBuff = RxBuff;
- UartState->RxSize = RxSize;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
-
- Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, TRUE);
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LPUART_UART_IP_TIMEOUT_TYPE);
- Lpuart_Uart_Ip_StartGetData(Instance, &StartTime, &ElapsedTicks, TimeoutTicks);
-
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_TIMEOUT;
- }
-
- if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
- {
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
- }
- if ((0U == UartState->RxSize) && (LPUART_UART_IP_STATUS_RX_OVERRUN == UartState->ReceiveStatus))
- {
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
- }
-
- Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, FALSE);
- UartState->IsRxBusy = FALSE;
-
- (void)Lpuart_Uart_Ip_Getchar(Base);
- RetVal = UartState->ReceiveStatus;
- }
- return RetVal;
- }
- static void Lpuart_Uart_Ip_StartGetData(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- uint8 StatusIndex = 0U;
- uint32 Mask = 0U;
- const Lpuart_Uart_Ip_StatusFlagType Lpuart_Uart_Ip_StatusFlagTypeArray[4U] = {LPUART_UART_IP_RX_OVERRUN,
- LPUART_UART_IP_FRAME_ERR,
- LPUART_UART_IP_NOISE_DETECT,
- LPUART_UART_IP_PARITY_ERR};
- const Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_ReceiveStatusArray[4U] = {LPUART_UART_IP_STATUS_RX_OVERRUN,
- LPUART_UART_IP_STATUS_FRAMING_ERROR,
- LPUART_UART_IP_STATUS_NOISE_ERROR,
- LPUART_UART_IP_STATUS_PARITY_ERROR};
- const uint32 Lpuart_Uart_Ip_StatusRegMask[4U] = {LPUART_STAT_OR_MASK,
- LPUART_STAT_FE_MASK,
- LPUART_STAT_NF_MASK,
- LPUART_STAT_PF_MASK};
- while ((UartState->RxSize > 0U) && \
- !Lpuart_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
-
- while (!Lpuart_Uart_Ip_GetStatusFlag((const LPUART_Type*)Base, LPUART_UART_IP_DATA_REG_FULL) && \
- !Lpuart_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
-
- for(StatusIndex = 0U; StatusIndex <= 3U; StatusIndex++)
- {
- if(Lpuart_Uart_Ip_GetStatusFlag((const LPUART_Type*)Base, Lpuart_Uart_Ip_StatusFlagTypeArray[StatusIndex]))
- {
- UartState->ReceiveStatus = Lpuart_Uart_Ip_ReceiveStatusArray[StatusIndex];
- Mask |= Lpuart_Uart_Ip_StatusRegMask[StatusIndex];
- }
- }
- if(Mask > 0U)
- {
-
- Lpuart_Uart_Ip_SetReceiverCmd((LPUART_Type *)Base, FALSE);
-
- Lpuart_Uart_Ip_ClearStatusFlagWithMask(Base, Mask);
- break;
- }
- else
- {
-
- Lpuart_Uart_Ip_GetData(Instance);
- }
- }
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AsyncReceive(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- boolean IsReturn = FALSE;
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- SchM_Enter_Uart_UART_EXCLUSIVE_AREA_03();
-
- if (UartState->IsRxBusy)
- {
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
- RetVal = LPUART_UART_IP_STATUS_BUSY;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
- UartState->IsRxBusy = TRUE;
- SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT((LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType) ||
- (LPUART_UART_IP_USING_DMA == UartUserCfg->TransferType));
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- RetVal = Lpuart_Uart_Ip_StartReceiveDataUsingInt(Instance, RxBuff, RxSize);
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- RetVal = Lpuart_Uart_Ip_StartReceiveDataUsingDma(Instance, RxBuff, RxSize);
- }
- #endif
- }
- return RetVal;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_GetReceiveStatus(const uint8 Instance, uint32 * BytesRemaining)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- const Dma_Ip_LogicChannelInfoParamType DmaLogicChnParam = DMA_IP_CH_GET_CURRENT_ITER_COUNT;
- #endif
- UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
- if (BytesRemaining != NULL_PTR)
- {
- if (UartState->IsRxBusy)
- {
-
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- *BytesRemaining = UartState->RxSize;
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->RxDMAChannel, DmaLogicChnParam, BytesRemaining);
- }
- #endif
- }
- else
- {
- *BytesRemaining = 0;
- }
- }
- return UartState->ReceiveStatus;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_AbortReceivingData(const uint8 Instance)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
- boolean IsReturn = FALSE;
- Lpuart_Uart_Ip_StatusType RetVal = LPUART_UART_IP_STATUS_ERROR;
-
- if (!UartState->IsRxBusy)
- {
- RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- IsReturn = TRUE;
- }
- if (!IsReturn)
- {
-
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ABORTED;
-
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
- Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
- Lpuart_Uart_Ip_CompleteReceiveUsingDma(Instance);
- }
- #endif
-
- Lpuart_Uart_Ip_ClearErrorFlags(Base);
-
- Lpuart_Uart_Ip_FlushRxBuffer(Base);
- RetVal = LPUART_UART_IP_STATUS_SUCCESS;
- }
- return RetVal;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetBaudRate(const uint8 Instance,
- const Lpuart_Uart_Ip_BaudrateType DesiredBaudrate,
- const uint32 ClockFrequency)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- uint16 Sbr;
- uint16 Idx;
- uint16 SbrTemp;
- uint32 Osr;
- uint32 TempDiff;
- uint32 CalculatedBaud;
- uint32 BaudDiff;
- uint32 MaxOsr;
- uint32 ExpectedBaud = (uint32)DesiredBaudrate;
- LPUART_Type * Base = Lpuart_Uart_Ip_apBases[Instance];
- Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- Lpuart_Uart_Ip_StatusType Status = LPUART_UART_IP_STATUS_ERROR;
- LPUART_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
- if ((TRUE == UartState->IsTxBusy) || (TRUE == UartState->IsRxBusy))
- {
- Status = LPUART_UART_IP_STATUS_BUSY;
- }
- else
- {
-
- LPUART_UART_IP_DEV_ASSERT(ClockFrequency > 0U);
-
- LPUART_UART_IP_DEV_ASSERT(ClockFrequency >= (ExpectedBaud * 5U));
-
- Osr = 4;
- Sbr = (uint16)(ClockFrequency / (ExpectedBaud * Osr));
- CalculatedBaud = (ClockFrequency / ((uint32)Osr * (uint32)Sbr));
- if (CalculatedBaud > ExpectedBaud)
- {
- BaudDiff = CalculatedBaud - ExpectedBaud;
- }
- else
- {
- BaudDiff = ExpectedBaud - CalculatedBaud;
- }
-
- MaxOsr = ClockFrequency / ExpectedBaud;
- if (MaxOsr > 32U)
- {
- MaxOsr = 32U;
- }
-
- if (MaxOsr >= 5U)
- {
- for (Idx = 5U; Idx <= MaxOsr; Idx++)
- {
-
- SbrTemp = (uint16)(ClockFrequency / (ExpectedBaud * Idx));
-
- CalculatedBaud = (ClockFrequency / ((uint32)Idx * (uint32)SbrTemp));
- if (CalculatedBaud > ExpectedBaud)
- {
- TempDiff = CalculatedBaud - ExpectedBaud;
- }
- else
- {
- TempDiff = ExpectedBaud - CalculatedBaud;
- }
- if (TempDiff <= BaudDiff)
- {
- BaudDiff = TempDiff;
- Osr = Idx;
- Sbr = SbrTemp;
- }
- }
- }
-
- if (Osr < 8U)
- {
- Lpuart_Uart_Ip_EnableBothEdgeSamplingCmd(Base);
- }
-
- Lpuart_Uart_Ip_SetOversamplingRatio(Base, (Osr - 1U));
-
- Lpuart_Uart_Ip_SetBaudRateDivisor(Base, Sbr);
- UartState->BaudRate = CalculatedBaud;
- Status = LPUART_UART_IP_STATUS_SUCCESS;
- }
- return Status;
- }
- void Lpuart_Uart_Ip_GetBaudRate(const uint8 Instance, uint32 * ConfiguredBaudRate)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(ConfiguredBaudRate != NULL_PTR);
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- *ConfiguredBaudRate = UartState->BaudRate;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetTxBuffer(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(TxSize > 0U);
- Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartState->TxBuff = TxBuff;
- UartState->TxSize = TxSize;
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetRxBuffer(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
- LPUART_UART_IP_DEV_ASSERT(RxSize > 0U);
- Lpuart_Uart_Ip_StateStructureType * UartState;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartState->RxBuff = RxBuff;
- UartState->RxSize = RxSize;
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- static void Lpuart_Uart_Ip_RxIdleIrqHandler(uint32 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = (Lpuart_Uart_Ip_UserConfigType*) Lpuart_Uart_Ip_apUserConfig[Instance];
-
- Lpuart_Uart_Ip_SetIntMode(Base, (uint32)LPUART_CTRL_ILIE_SHIFT, FALSE);
-
- Base->STAT |= LPUART_STAT_IDLE(0);
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RECV_IDLE,UartUserCfg->CallbackParam);
- }
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
-
- }
- void Lpuart_Uart_Ip_IrqHandler(const uint8 Instance)
- {
- LPUART_UART_IP_DEV_ASSERT(Instance < LPUART_UART_IP_NUMBER_OF_INSTANCES);
- LPUART_Type * Base;
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (const Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- boolean IsReturn = FALSE;
-
- if (NULL_PTR == UartState)
- {
-
- (void)Lpuart_Uart_Ip_Getchar(Base);
-
- Lpuart_Uart_Ip_ClearErrorFlags(Base);
-
- }
- else
- {
- Lpuart_Uart_Ip_ErrIrqHandler(Instance);
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL))
- {
- if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL))
- {
- Lpuart_Uart_Ip_RxIrqHandler(Instance);
- }
-
- else
- {
-
- (void)Lpuart_Uart_Ip_Getchar(Base);
- }
- IsReturn = TRUE;
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_DATA_REG_EMPTY) && (FALSE == IsReturn))
- {
- if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY))
- {
- Lpuart_Uart_Ip_TxEmptyIrqHandler(Instance);
- IsReturn = TRUE;
- }
-
- else
- {
-
- }
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && (FALSE == IsReturn))
- {
- if (Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE))
- {
- Lpuart_Uart_Ip_TxCompleteIrqHandler(Instance);
- }
-
- else
- {
-
- }
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, (uint32)LPUART_UART_IP_IDLE) && (FALSE == IsReturn))
- {
- if (Lpuart_Uart_Ip_GetIntMode(Base, (uint32)LPUART_UART_IP_IDLE))
- {
- Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1,STD_OFF);
- Lpuart_Uart_Ip_RxIdleIrqHandler(Instance);
- Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1,STD_ON);
-
- }
- else
- {
-
- }
- }
- }
- }
- static void Lpuart_Uart_Ip_RxIrqHandler(const uint8 Instance)
- {
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- Lpuart_Uart_Ip_GetData(Instance);
-
- if (0U == UartState->RxSize)
- {
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RX_FULL, UartUserCfg->CallbackParam);
- }
- }
-
- if (0U == UartState->RxSize)
- {
-
- Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
- }
- }
- }
- static void Lpuart_Uart_Ip_TxEmptyIrqHandler(const uint8 Instance)
- {
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- if (UartState->TxSize > 0U)
- {
-
- Lpuart_Uart_Ip_PutData(Instance);
-
- if ((0U == UartState->TxSize) && (UartUserCfg->Callback != NULL_PTR))
- {
-
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_TX_EMPTY, UartUserCfg->CallbackParam);
- }
-
- if (0U == UartState->TxSize)
- {
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, TRUE);
- }
- }
- }
- static void Lpuart_Uart_Ip_TxCompleteIrqHandler(const uint8 Instance)
- {
- const Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- if (0U == UartState->TxSize)
- {
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- Lpuart_Uart_Ip_CompleteSendDataUsingInt(Instance);
- }
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
- }
- }
- }
- static void Lpuart_Uart_Ip_ErrIrqHandler(const uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- boolean IsError = FALSE;
- boolean IsReturn = FALSE;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_RX_OVERRUN))
- {
-
- Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_RX_OVERRUN);
-
- if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN))
- {
- IsReturn = TRUE;
- }
- else
- {
-
- IsError = TRUE;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_RX_OVERRUN;
- }
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_FRAME_ERR) && (FALSE == IsReturn))
- {
-
- Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_FRAME_ERR);
-
- if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG))
- {
- IsReturn = TRUE;
- }
- else
- {
-
- IsError = TRUE;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_FRAMING_ERROR;
- }
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_PARITY_ERR) && (FALSE == IsReturn))
- {
-
- Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_PARITY_ERR);
-
- if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG))
- {
- IsReturn = TRUE;
- }
- else
- {
-
- IsError = TRUE;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_PARITY_ERROR;
- }
- }
-
- if (Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_NOISE_DETECT) && (FALSE == IsReturn))
- {
-
- Lpuart_Uart_Ip_ClearStatusFlag(Base, LPUART_UART_IP_NOISE_DETECT);
-
- if (!Lpuart_Uart_Ip_GetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG))
- {
- IsReturn = TRUE;
- }
- else
- {
-
- IsError = TRUE;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_NOISE_ERROR;
- }
- }
- if (FALSE == IsReturn)
- {
- if (TRUE == IsError)
- {
- if (LPUART_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
- {
-
- Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(Instance);
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- else
- {
-
- (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
- Lpuart_Uart_Ip_CompleteReceiveUsingDma(Instance);
- }
- #endif
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
- }
- }
- }
- }
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingInt(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize)
- {
- LPUART_Type * Base;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
-
- UartState->TxBuff = TxBuff;
- UartState->TxSize = TxSize;
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, TRUE);
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartSendDataUsingDma(const uint8 Instance,
- const uint8 * TxBuff,
- const uint32 TxSize)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
- Dma_Ip_ReturnType DmaReturnStatus;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
- DmaTransferList[0].Value = (uint32)TxBuff;
- DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
- DmaTransferList[1].Value = LPUART_UART_IP_LSBW_ADDR(Base->DATA);
- DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
- DmaTransferList[2].Value = 1;
- DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
- DmaTransferList[3].Value = 0;
- DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
- DmaTransferList[4].Value = TxSize;
- DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
- DmaTransferList[5].Value = 1;
- DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
- DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
- DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
- DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
- DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
- DmaTransferList[8].Value = 1;
- DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
- DmaTransferList[9].Value = 1;
-
- UartState->TxBuff = TxBuff;
- UartState->TxSize = 0U;
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_BUSY;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, TRUE);
-
- Lpuart_Uart_Ip_SetTxDmaCmd(Base, TRUE);
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- #endif
- static void Lpuart_Uart_Ip_CompleteSendDataUsingInt(const uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- LPUART_Type * Base;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- if (LPUART_UART_IP_STATUS_BUSY != UartState->TransmitStatus)
- {
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_DATA_REG_EMPTY, FALSE);
- }
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_TX_COMPLETE, FALSE);
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
-
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
- }
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
- if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
- {
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
- }
-
- UartState->IsTxBusy = FALSE;
- }
- #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
- void Lpuart_Uart_Ip_CompleteSendUsingDma(uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
- Dma_Ip_ReturnType DmaReturnStatus;
- Dma_Ip_LogicChannelStatusType DmaStatus;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->TxDMAChannel, &DmaStatus);
- if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
- {
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
- }
- }
-
- if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
- {
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_TX_EMPTY, UartUserCfg->CallbackParam);
- }
- }
-
- if ((UartState->TxSize > 0U) && (UartState->TransmitStatus != LPUART_UART_IP_STATUS_ERROR))
- {
-
- DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
- DmaTransferList[0].Value = (uint32)(UartState->TxBuff);
-
- DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
- DmaTransferList[1].Value = UartState->TxSize;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- UartState->TxSize = 0U;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
- }
- else
- {
-
- Lpuart_Uart_Ip_SetTxDmaCmd(Base, FALSE);
-
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_TX_COMPLETE) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_ERROR;
- }
-
- Lpuart_Uart_Ip_SetTransmitterCmd(Base, FALSE);
- if (LPUART_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
- {
-
- UartState->TransmitStatus = LPUART_UART_IP_STATUS_SUCCESS;
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
- }
- }
-
- UartState->IsTxBusy = FALSE;
- }
- }
- #endif
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingInt(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize)
- {
- LPUART_Type * Base;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
-
- UartState->IsRxBusy = TRUE;
- UartState->RxBuff = RxBuff;
- UartState->RxSize = RxSize;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
-
- Lpuart_Uart_Ip_ClearErrorFlags(Base);
-
- Lpuart_Uart_Ip_FlushRxBuffer(Base);
-
- Lpuart_Uart_Ip_SetReceiverCmd(Base, TRUE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, TRUE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, TRUE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, TRUE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, TRUE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, TRUE);
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- #if (STD_ON == LPUART_UART_IP_HAS_DMA_ENABLED)
- static Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_StartReceiveDataUsingDma(const uint8 Instance,
- uint8 * RxBuff,
- const uint32 RxSize)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
- Dma_Ip_ReturnType DmaReturnStatus;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- Lpuart_Uart_Ip_ClearErrorFlags(Base);
-
- Lpuart_Uart_Ip_FlushRxBuffer(Base);
-
- DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
- DmaTransferList[0].Value = LPUART_UART_IP_LSBW_ADDR(Base->DATA);
- DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
- DmaTransferList[1].Value = (uint32)RxBuff;
- DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
- DmaTransferList[2].Value = 0;
- DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
- DmaTransferList[3].Value = 1;
- DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
- DmaTransferList[4].Value = RxSize;
- DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
- DmaTransferList[5].Value = 1;
- DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
- DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
- DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
- DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
- DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
- DmaTransferList[8].Value = 1;
- DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
- DmaTransferList[9].Value = 1;
-
- UartState->RxBuff = RxBuff;
- UartState->RxSize = 0U;
- UartState->IsRxBusy = TRUE;
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_BUSY;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- Lpuart_Uart_Ip_SetReceiverCmd(Base, TRUE);
-
- Lpuart_Uart_Ip_SetupIntDmaMode(Instance, TRUE);
- return LPUART_UART_IP_STATUS_SUCCESS;
- }
- #endif
- static void Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(const uint8 Instance)
- {
- LPUART_Type * Base;
- Lpuart_Uart_Ip_StateStructureType * UartState;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, FALSE);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, FALSE);
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_DATA_REG_FULL, FALSE);
-
- if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
- {
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
-
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
-
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
- }
- }
-
- Lpuart_Uart_Ip_SetReceiverCmd(Base, FALSE);
-
- (void)Lpuart_Uart_Ip_Getchar(Base);
-
- UartState->IsRxBusy = FALSE;
- if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
- {
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
- }
- }
- #if (STD_ON == LPUART_UART_IP_HAS_DMA_ENABLED)
- void Lpuart_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- Dma_Ip_LogicChannelTransferListType DmaTransferList[LPUART_UART_IP_DMA_CONFIG_LIST_DIMENSION];
- Dma_Ip_ReturnType DmaReturnStatus;
- Dma_Ip_LogicChannelStatusType DmaStatus;
- uint32 StartTime;
- uint32 TimeoutTicks;
- uint32 ElapsedTicks = 0;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
-
- (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->RxDMAChannel, &DmaStatus);
- if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
- {
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_ERROR, UartUserCfg->CallbackParam);
- }
- }
-
- if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
- {
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RX_FULL, UartUserCfg->CallbackParam);
- }
- }
-
- if ((UartState->RxSize > 0U) && (UartState->ReceiveStatus != LPUART_UART_IP_STATUS_ERROR))
- {
-
- DmaTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
- DmaTransferList[0].Value = (uint32)(UartState->RxBuff);
- DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
- DmaTransferList[1].Value = UartState->RxSize;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LPUART_UART_IP_DMA_LEAST_CONFIG_LIST_DIMENSION);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
-
- UartState->RxSize = 0U;
-
- DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
- LPUART_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
- }
- else
- {
-
- Lpuart_Uart_Ip_SetupIntDmaMode(Instance, FALSE);
-
- if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
- {
-
- Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
- while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
- !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {}
- if (Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
- {
-
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_ERROR;
- }
- }
-
- Lpuart_Uart_Ip_SetReceiverCmd(Base, FALSE);
-
- (void)Lpuart_Uart_Ip_Getchar(Base);
-
- UartState->IsRxBusy = FALSE;
-
- if (LPUART_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
- {
- UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
-
- if (UartUserCfg->Callback != NULL_PTR)
- {
- UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_END_TRANSFER, UartUserCfg->CallbackParam);
- }
- }
- }
- }
- static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable)
- {
- LPUART_Type * Base;
- Base = Lpuart_Uart_Ip_apBases[Instance];
-
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, Enable);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, Enable);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, Enable);
- Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, Enable);
-
- Lpuart_Uart_Ip_SetRxDmaCmd(Base, Enable);
- }
- #endif
- static void Lpuart_Uart_Ip_PutData(const uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- LPUART_Type * Base;
- uint16 Data16b;
- uint8 Data8b;
- Base = Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- if ((LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar) || (LPUART_UART_IP_8_BITS_PER_CHAR == UartUserCfg->BitCountPerChar))
- {
- Data8b = *(UartState->TxBuff);
-
- ++UartState->TxBuff;
- --UartState->TxSize;
-
- Lpuart_Uart_Ip_Putchar(Base, Data8b);
- }
- else
- {
- Data16b = (uint16)(*UartState->TxBuff);
-
- if (1U == UartState->TxSize)
- {
- ++UartState->TxBuff;
- --UartState->TxSize;
- }
- else
- {
- ++UartState->TxBuff;
- Data16b |= (uint16)(((uint16)(*UartState->TxBuff)) << 8U);
- ++UartState->TxBuff;
- UartState->TxSize -= 2U;
- }
-
- if (LPUART_UART_IP_9_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
- {
- Lpuart_Uart_Ip_Putchar9(Base, Data16b);
- }
- else
- {
- Lpuart_Uart_Ip_Putchar10(Base, Data16b);
- }
- }
- }
- static void Lpuart_Uart_Ip_GetData(const uint8 Instance)
- {
- Lpuart_Uart_Ip_StateStructureType * UartState;
- const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
- const LPUART_Type * Base;
- uint16 Data16b;
- Base = (const LPUART_Type *)Lpuart_Uart_Ip_apBases[Instance];
- UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
- UartUserCfg = Lpuart_Uart_Ip_apUserConfig[Instance];
- if ((LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar) || (LPUART_UART_IP_8_BITS_PER_CHAR == UartUserCfg->BitCountPerChar))
- {
-
- *(UartState->RxBuff) = Lpuart_Uart_Ip_Getchar(Base);
- if (LPUART_UART_IP_7_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
- {
- *(UartState->RxBuff) &= 0x7FU;
- }
-
- ++UartState->RxBuff;
- --UartState->RxSize;
- }
- else
- {
- if (LPUART_UART_IP_9_BITS_PER_CHAR == UartUserCfg->BitCountPerChar)
- {
- Data16b = Lpuart_Uart_Ip_Getchar9(Base);
- }
- else
- {
- Data16b = Lpuart_Uart_Ip_Getchar10(Base);
- }
-
- if (1U == UartState->RxSize)
- {
- *(UartState->RxBuff) = (uint8)Data16b;
- ++UartState->RxBuff;
- --UartState->RxSize;
- }
- else
- {
-
- *(UartState->RxBuff) = (uint8)(Data16b & 0xFFU);
- ++UartState->RxBuff;
-
- *UartState->RxBuff = (uint8)(Data16b >> 8U);
- ++UartState->RxBuff;
- UartState->RxSize -= 2U;
- }
- }
- }
- #define UART_STOP_SEC_CODE
- #include "Uart_MemMap.h"
- #ifdef __cplusplus
- }
- #endif
|