27 #include <oc_uart_lld.h> 30 #include <oc_gpio_mslld.h> 44 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 46 #define SOFTWARE_RING_COUNT 10 47 #define IsRam(address) (oC_LSF_IsRamAddress(address)) 48 #define IsRom(address) (oC_LSF_IsRomAddress(address)) 49 #define IsChannelCorrect(channel) (oC_Channel_IsCorrect(UART,channel)) 50 #define IsChannelPoweredOn(channel) (oC_Machine_GetPowerStateForChannel(channel) == oC_Power_On) 51 #define IsChannelUsed(channel) (oC_Bits_IsBitSetU32(ChannelUsedFlags,(uint8_t)oC_Machine_ChannelToChannelIndex(UART,channel))) 52 #define IsChannelBusy(channel) (UARTFR(channel)->BUSY == 1) 53 #define AreOperationsDisabled(channel) (UARTCTL(channel)->UARTEN == 0) 54 #define AreOperationsEnabled(channel) (UARTCTL(channel)->UARTEN == 1) 55 #define IsRxFifoEmpty(channel) (UARTFR(channel)->RXFE == 1) 56 #define IsTxFifoEmpty(channel) (UARTFR(channel)->TXFE == 1) 57 #define IsRxFifoFull(channel) (UARTFR(channel)->RXFF == 1) 58 #define IsTxFifoFull(channel) (UARTFR(channel)->TXFF == 1) 60 #define UARTCTL(Channel) oC_Machine_Register(Channel,UARTCTL) 61 #define UARTFR(Channel) oC_Machine_Register(Channel,UARTFR) 62 #define UARTLCRH(Channel) oC_Machine_Register(Channel,UARTLCRH) 63 #define UARTDR(Channel) oC_Machine_Register(Channel,UARTDR) 64 #define UARTDMACTL(Channel) oC_Machine_Register(Channel,UARTDMACTL) 65 #define UARTIM(Channel) oC_Machine_Register(Channel,UARTIM) 66 #define UARTICR(Channel) oC_Machine_Register(Channel,UARTICR) 67 #define UARTRIS(Channel) oC_Machine_Register(Channel,UARTRIS) 68 #define UARTIFLS(Channel) oC_Machine_Register(Channel,UARTIFLS) 69 #define UARTCC(Channel) oC_Machine_Register(Channel,UARTCC) 70 #define RCGCUART oC_Register(SystemControl,RCGCUART) 71 #define RxRing(Channel) SoftwareRxRings[oC_Channel_ToIndex(UART,Channel)] 72 #define IsSoftwareRxRingEmpty(Channel) (RxRing(Channel).Counter == 0) 73 #define IsSoftwareRxRingFull(Channel) (RxRing(Channel).Counter == SOFTWARE_RING_COUNT) 74 #define TxRing(Channel) SoftwareTxRings[oC_Channel_ToIndex(UART,Channel)] 75 #define IsSoftwareTxRingEmpty(Channel) (TxRing(Channel).Counter == 0) 76 #define IsSoftwareTxRingFull(Channel) (TxRing(Channel).Counter == SOFTWARE_RING_COUNT) 79 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 86 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 90 uint16_t Buffer[SOFTWARE_RING_COUNT];
96 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 104 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 110 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 118 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 120 static oC_UART_LLD_Interrupt_t RxNotEmptyHandler =
NULL;
121 static oC_UART_LLD_Interrupt_t TxNotFullHandler =
NULL;
124 #if oC_ModuleChannel_NumberOfElements(UART) <= 8 125 static uint8_t UsedChannels = 0;
126 #elif oC_ModuleChannel_NumberOfElements(UART) <= 16 127 static uint16_t UsedChannels = 0;
128 #elif oC_ModuleChannel_NumberOfElements(UART) <= 32 129 static uint32_t UsedChannels = 0;
130 #elif oC_ModuleChannel_NumberOfElements(UART) <= 64 131 static uint64_t UsedChannels = 0;
133 # error Number of UART channels is too big (max 64) 138 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 145 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 153 bool oC_UART_LLD_IsChannelCorrect( oC_UART_Channel_t Channel )
164 bool oC_UART_LLD_IsChannelIndexCorrect( oC_UART_LLD_ChannelIndex_t ChannelIndex )
175 oC_UART_LLD_ChannelIndex_t oC_UART_LLD_ChannelToChannelIndex( oC_UART_Channel_t Channel )
186 oC_UART_Channel_t oC_UART_LLD_ChannelIndexToChannel( oC_UART_LLD_ChannelIndex_t Channel )
197 oC_UART_Channel_t oC_UART_LLD_GetChannelOfModulePin( oC_UART_Pin_t ModulePin )
199 return oC_ModulePin_GetChannel(ModulePin);
208 oC_ErrorCode_t oC_UART_LLD_TurnOnDriver(
void )
210 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
217 errorCode = oC_ErrorCode_None;
218 RxNotEmptyHandler =
NULL;
219 TxNotFullHandler =
NULL;
235 oC_ErrorCode_t oC_UART_LLD_TurnOffDriver(
void )
237 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
244 errorCode = oC_ErrorCode_None;
258 oC_ErrorCode_t oC_UART_LLD_SetDriverInterruptHandlers( oC_UART_LLD_Interrupt_t RxNotEmpty , oC_UART_LLD_Interrupt_t TxNotFull)
260 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
267 ErrorCondition( IsRam(RxNotEmpty) || IsRom(RxNotEmpty) , oC_ErrorCode_WrongEventHandlerAddress) &&
268 ErrorCondition( RxNotEmptyHandler ==
NULL , oC_ErrorCode_InterruptHandlerAlreadySet) &&
269 ErrorCondition( IsRam(TxNotFull) || IsRom(TxNotFull) , oC_ErrorCode_WrongEventHandlerAddress) &&
270 ErrorCondition( TxNotFullHandler ==
NULL , oC_ErrorCode_InterruptHandlerAlreadySet)
273 RxNotEmptyHandler = RxNotEmpty;
274 TxNotFullHandler = TxNotFull;
275 errorCode = oC_ErrorCode_None;
290 oC_ErrorCode_t oC_UART_LLD_SetPower( oC_UART_Channel_t Channel ,
oC_Power_t Power )
292 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
300 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
303 ErrorCondition( oC_Channel_EnableInterrupt(Channel,PeripheralInterrupt) , oC_ErrorCode_CannotEnableInterrupt) &&
304 ErrorCondition( oC_Channel_SetInterruptPriority(Channel,PeripheralInterrupt, uartPriority) , oC_ErrorCode_UARTInterruptConfigureError)
307 errorCode = oC_ErrorCode_None;
322 oC_ErrorCode_t oC_UART_LLD_ReadPower( oC_UART_Channel_t Channel ,
oC_Power_t * outPower )
324 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
331 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
332 ErrorCondition( IsRam(outPower) , oC_ErrorCode_OutputAddressNotInRAM)
336 errorCode = oC_ErrorCode_None;
350 oC_ErrorCode_t oC_UART_LLD_DisableOperations( oC_UART_Channel_t Channel )
352 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
359 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
360 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn)
363 UARTCTL(Channel)->UARTEN = 0;
364 UARTCTL(Channel)->RXE = 0;
365 UARTCTL(Channel)->TXE = 0;
368 while(IsChannelBusy(Channel));
370 UARTLCRH(Channel)->FEN = 0;
372 errorCode = oC_ErrorCode_None;
387 oC_ErrorCode_t oC_UART_LLD_EnableOperations( oC_UART_Channel_t Channel )
389 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
396 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
397 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn)
400 UARTCTL(Channel)->RXE = 1;
401 UARTCTL(Channel)->TXE = 1;
402 UARTCTL(Channel)->UARTEN = 1;
403 UARTIM(Channel)->RXIM = 1;
404 UARTIFLS(Channel)->RXIFLSEL = 0;
405 UARTIFLS(Channel)->TXIFLSEL = 0;
407 errorCode = oC_ErrorCode_None;
422 oC_ErrorCode_t oC_UART_LLD_RestoreDefaultStateOnChannel( oC_UART_Channel_t Channel )
424 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
431 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
436 errorCode = oC_ErrorCode_None;
451 oC_ErrorCode_t oC_UART_LLD_SetWordLength( oC_UART_Channel_t Channel , oC_UART_LLD_WordLength_t WordLength )
453 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
460 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel ) &&
461 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn ) &&
462 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled )
480 oC_UART_LLD_WordLength_5Bits == 0 &&
481 oC_UART_LLD_WordLength_6Bits == 1 &&
482 oC_UART_LLD_WordLength_7Bits == 2 &&
483 oC_UART_LLD_WordLength_8Bits == 3 ,
484 "WordLength values in the lm4f must have exactly values in range <0,3>! Please check function oC_UART_LLD_Set/ReadWordLength" 487 UARTLCRH(Channel)->WLEN = WordLength;
488 errorCode = oC_ErrorCode_None;
503 oC_ErrorCode_t oC_UART_LLD_ReadWordLength( oC_UART_Channel_t Channel , oC_UART_LLD_WordLength_t * outWordLength )
505 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
510 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
511 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
512 ErrorCondition( IsRam(outWordLength) , oC_ErrorCode_OutputAddressNotInRAM)
530 oC_UART_LLD_WordLength_5Bits == 0 &&
531 oC_UART_LLD_WordLength_6Bits == 1 &&
532 oC_UART_LLD_WordLength_7Bits == 2 &&
533 oC_UART_LLD_WordLength_8Bits == 3 ,
534 "WordLength values in the lm4f must have exactly values in range <0,3>! Please check function oC_UART_LLD_Set/ReadWordLength" 537 *outWordLength = UARTLCRH(Channel)->WLEN;
538 errorCode = oC_ErrorCode_None;
551 oC_ErrorCode_t oC_UART_LLD_SetBitRate( oC_UART_Channel_t Channel , uint32_t BitRate )
553 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
560 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
561 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
562 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled) &&
563 ErrorCondition( BitRate > 0 , oC_ErrorCode_BitRateNotCorrect)
568 uint8_t clockDivisor = 8;
569 static const float maxBrd = (float)(0x10000);
571 #define CountBrd( clkFreq , clkDiv , BaudRate ) ((float)((clkFreq) / ( ((float)(clkDiv)) * ((float)(BaudRate)) ))) 573 brdFloat = CountBrd(currentClockFrequency,clockDivisor,BitRate);
576 if(brdFloat > maxBrd )
579 brdFloat = CountBrd(currentClockFrequency,clockDivisor,BitRate);
582 if(brdFloat <= maxBrd )
584 oC_UInt_t integerBrdPart = (oC_UInt_t)brdFloat;
585 float fractionalBrdPart = brdFloat - (float)integerBrdPart;
593 UARTCTL(Channel)->HSE = (clockDivisor == 8) ? 1 : 0;
595 errorCode = oC_ErrorCode_None;
599 errorCode = oC_ErrorCode_BitRateNotSupported;
617 oC_ErrorCode_t oC_UART_LLD_ReadBitRate( oC_UART_Channel_t Channel , uint32_t * outBitRate )
619 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
624 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
625 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
626 ErrorCondition( IsRam(outBitRate) , oC_ErrorCode_OutputAddressNotInRAM)
632 float brd = (float)integerBrdPart;
633 float clockDivisor = (UARTCTL(Channel)->HSE == 1) ? 8 : 16;
635 if(oC_AssignErrorCodeIfFalse(&errorCode , integerBrdPart != 0 || fractionalBrdPart != 0 , oC_ErrorCode_BitRateNotSet ))
638 brd += (((float)fractionalBrdPart) - 0.5) / 64;
641 if(oC_AssignErrorCodeIfFalse(&errorCode , brd != 0 , oC_ErrorCode_MachineCanBeDamaged))
644 *outBitRate = (uint32_t)(currentClockFrequency / (clockDivisor * brd));
646 errorCode = oC_ErrorCode_None;
661 oC_ErrorCode_t oC_UART_LLD_SetParity( oC_UART_Channel_t Channel , oC_UART_LLD_Parity_t Parity )
663 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
670 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
671 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
672 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
675 if(Parity == oC_UART_LLD_Parity_Odd)
677 UARTLCRH(Channel)->PEN = 1;
678 UARTLCRH(Channel)->EPS = 0;
680 else if(Parity == oC_UART_LLD_Parity_Even)
682 UARTLCRH(Channel)->PEN = 1;
683 UARTLCRH(Channel)->EPS = 1;
687 UARTLCRH(Channel)->PEN = 0;
690 errorCode = oC_ErrorCode_None;
705 oC_ErrorCode_t oC_UART_LLD_ReadParity( oC_UART_Channel_t Channel , oC_UART_LLD_Parity_t * outParity )
707 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
712 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
713 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
714 ErrorCondition( IsRam(outParity) , oC_ErrorCode_OutputAddressNotInRAM)
717 if(UARTLCRH(Channel)->PEN == 1)
719 if(UARTLCRH(Channel)->EPS == 0)
721 *outParity = oC_UART_LLD_Parity_Odd;
725 *outParity = oC_UART_LLD_Parity_Even;
730 *outParity = oC_UART_LLD_Parity_None;
732 errorCode = oC_ErrorCode_None;
745 oC_ErrorCode_t oC_UART_LLD_SetStopBit( oC_UART_Channel_t Channel , oC_UART_LLD_StopBit_t StopBit )
747 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
754 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
755 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
756 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
759 if(StopBit == oC_UART_LLD_StopBit_1Bit)
761 UARTLCRH(Channel)->STP2 = 0;
765 UARTLCRH(Channel)->STP2 = 1;
768 errorCode = oC_ErrorCode_None;
784 oC_ErrorCode_t oC_UART_LLD_ReadStopBit( oC_UART_Channel_t Channel , oC_UART_LLD_StopBit_t * outStopBit )
786 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
791 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
792 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
793 ErrorCondition( IsRam(outStopBit) , oC_ErrorCode_OutputAddressNotInRAM)
796 if(UARTLCRH(Channel)->STP2 == 0)
798 *outStopBit = oC_UART_LLD_StopBit_1Bit;
802 *outStopBit = oC_UART_LLD_StopBit_2Bits;
804 errorCode = oC_ErrorCode_None;
817 oC_ErrorCode_t oC_UART_LLD_SetBitOrder( oC_UART_Channel_t Channel , oC_UART_LLD_BitOrder_t BitOrder )
819 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
826 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
827 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
828 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled) &&
829 ErrorCondition( BitOrder == oC_UART_LLD_BitOrder_LSBFirst , oC_ErrorCode_BitOrderNotSupported)
832 errorCode = oC_ErrorCode_None;
847 oC_ErrorCode_t oC_UART_LLD_ReadBitOrder( oC_UART_Channel_t Channel , oC_UART_LLD_BitOrder_t * outBitOrder )
849 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
854 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
855 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
856 ErrorCondition( IsRam(outBitOrder) , oC_ErrorCode_OutputAddressNotInRAM)
859 *outBitOrder = oC_UART_LLD_BitOrder_LSBFirst;
860 errorCode = oC_ErrorCode_None;
873 oC_ErrorCode_t oC_UART_LLD_SetInvert( oC_UART_Channel_t Channel , oC_UART_LLD_Invert_t Invert )
875 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
882 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
883 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
884 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled) &&
885 ErrorCondition( Invert == oC_UART_LLD_Invert_NotInverted , oC_ErrorCode_InvertNotSupported)
888 errorCode = oC_ErrorCode_None;
903 oC_ErrorCode_t oC_UART_LLD_ReadInvert( oC_UART_Channel_t Channel , oC_UART_LLD_Invert_t * outInvert )
905 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
910 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
911 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
912 ErrorCondition( IsRam(outInvert) , oC_ErrorCode_OutputAddressNotInRAM)
915 *outInvert = oC_UART_LLD_Invert_NotInverted;
916 errorCode = oC_ErrorCode_None;
929 oC_ErrorCode_t oC_UART_LLD_SetLoopback( oC_UART_Channel_t Channel ,
bool Loopback )
931 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
938 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
939 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
940 ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
945 UARTCTL(Channel)->LBE = 1;
949 UARTCTL(Channel)->LBE = 0;
952 errorCode = oC_ErrorCode_None;
967 oC_ErrorCode_t oC_UART_LLD_ReadLoopback( oC_UART_Channel_t Channel ,
bool * outLoopback )
969 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
974 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
975 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
976 ErrorCondition( IsRam(outLoopback) , oC_ErrorCode_OutputAddressNotInRAM)
979 *outLoopback = UARTCTL(Channel)->LBE == 1;
980 errorCode = oC_ErrorCode_None;
993 oC_ErrorCode_t oC_UART_LLD_ConnectModulePin( oC_UART_Pin_t ModulePin )
995 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
999 oC_UART_Channel_t channel = oC_ModulePin_GetChannel(ModulePin);
1000 oC_Pin_t pin = oC_ModulePin_GetPin(ModulePin);
1003 ErrorCondition( IsChannelCorrect(channel) , oC_ErrorCode_WrongChannel ) &&
1004 ErrorCondition( oC_GPIO_LLD_IsPinDefined(pin) , oC_ErrorCode_PinNotDefined )
1007 bool unused =
false;
1012 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ArePinsUnused(pin,&unused) ) &&
1013 ErrorCondition( unused , oC_ErrorCode_PinIsUsed ) &&
1014 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPinsUsed(pin) ) &&
1015 oC_AssignErrorCode(&errorCode , oC_GPIO_MSLLD_ConnectModulePin(ModulePin) )
1018 errorCode = oC_ErrorCode_None;
1022 oC_GPIO_LLD_SetPinsUnused(pin);
1038 oC_ErrorCode_t oC_UART_LLD_DisconnectModulePin( oC_UART_Pin_t ModulePin )
1040 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1044 oC_UART_Channel_t channel = oC_ModulePin_GetChannel(ModulePin);
1045 oC_Pin_t pin = oC_ModulePin_GetPin(ModulePin);
1048 ErrorCondition( IsChannelCorrect(channel) , oC_ErrorCode_WrongChannel ) &&
1049 ErrorCondition( oC_GPIO_LLD_IsPinDefined(pin) , oC_ErrorCode_PinNotDefined )
1052 errorCode = oC_ErrorCode_NotImplemented;
1065 oC_ErrorCode_t oC_UART_LLD_SetChannelUsed( oC_UART_Channel_t Channel )
1067 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1073 if( ErrorCondition(IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) )
1076 errorCode = oC_ErrorCode_None;
1091 oC_ErrorCode_t oC_UART_LLD_SetChannelUnused( oC_UART_Channel_t Channel )
1093 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1099 if( ErrorCondition(IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) )
1102 errorCode = oC_ErrorCode_None;
1117 bool oC_UART_LLD_IsChannelUsed( oC_UART_Channel_t Channel )
1123 if(IsChannelCorrect(Channel))
1138 oC_ErrorCode_t oC_UART_LLD_ClearRxFifo( oC_UART_Channel_t Channel )
1140 return oC_ErrorCode_NotImplemented;
1149 bool oC_UART_LLD_IsRxFifoEmpty( oC_UART_Channel_t Channel )
1151 return IsSoftwareRxRingEmpty(Channel);
1159 bool oC_UART_LLD_IsTxFifoFull( oC_UART_Channel_t Channel )
1161 return IsSoftwareTxRingFull(Channel);
1170 void oC_UART_LLD_PutData( oC_UART_Channel_t Channel ,
char Data )
1173 UARTIM(Channel)->TXIM = 1;
1174 if(IsSoftwareTxRingEmpty(Channel) && IsTxFifoEmpty(Channel))
1176 UARTDR(Channel)->DATA = Data;
1190 char oC_UART_LLD_GetData( oC_UART_Channel_t Channel )
1200 oC_ErrorCode_t oC_UART_LLD_ReadModulePinsOfPin( oC_Pin_t Pin , oC_UART_Pin_t * outModulePinsArray , uint32_t * ArraySize , oC_UART_PinFunction_t PinFunction )
1202 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1208 ErrorCondition( oC_GPIO_LLD_IsPinDefined(Pin) , oC_ErrorCode_PinNotDefined) &&
1209 ErrorCondition( IsRam(ArraySize) , oC_ErrorCode_OutputAddressNotInRAM) &&
1210 ErrorCondition(outModulePinsArray ==
NULL || IsRam(outModulePinsArray) , oC_ErrorCode_OutputAddressNotInRAM)
1213 uint32_t foundPins = 0;
1215 errorCode = oC_ErrorCode_None;
1217 oC_ModulePin_ForeachDefined(modulePin)
1219 if(modulePin->Pin == Pin &&
oC_Channel_IsCorrect(UART,modulePin->Channel) && modulePin->PinFunction == PinFunction)
1221 if(outModulePinsArray !=
NULL)
1223 if(foundPins < *ArraySize)
1225 outModulePinsArray[foundPins] = modulePin->ModulePinIndex;
1229 errorCode = oC_ErrorCode_OutputArrayToSmall;
1236 *ArraySize = foundPins;
1249 oC_ErrorCode_t oC_UART_LLD_Write( oC_UART_Channel_t Channel ,
const char * Buffer , oC_UInt_t Size , oC_IoFlags_t IoFlags )
1251 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1256 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
1257 ErrorCondition( IsRam(Buffer) || IsRom(Buffer) , oC_ErrorCode_WrongAddress) &&
1258 ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect) &&
1259 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
1260 ErrorCondition( AreOperationsEnabled(Channel) , oC_ErrorCode_ChannelOperationsNotEnabled)
1263 UARTDMACTL(Channel)->TXDMAE = 0;
1265 for(oC_UInt_t sendIndex = 0 ; sendIndex < Size ; sendIndex++ )
1271 while(IsTxFifoFull(Channel));
1273 UARTDR(Channel)->DATA = (uint8_t)Buffer[sendIndex];
1276 errorCode = oC_ErrorCode_None;
1289 oC_ErrorCode_t oC_UART_LLD_Read( oC_UART_Channel_t Channel ,
char * outBuffer , oC_UInt_t Size , oC_IoFlags_t IoFlags )
1291 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1296 ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
1297 ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
1298 ErrorCondition( IsRam(outBuffer) , oC_ErrorCode_OutputAddressNotInRAM) &&
1299 ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect) &&
1300 ErrorCondition( AreOperationsEnabled(Channel) , oC_ErrorCode_ChannelOperationsNotEnabled)
1303 UARTDMACTL(Channel)->RXDMAE = 0;
1305 errorCode = oC_ErrorCode_None;
1307 for(oC_UInt_t sendIndex = 0 ; sendIndex < Size ; sendIndex++ )
1313 errorCode = oC_ErrorCode_NoneElementReceived;
1317 while(IsRxFifoEmpty(Channel));
1319 outBuffer[sendIndex] = UARTDR(Channel)->DATA;
1321 if((IoFlags & oC_IoFlags_ReadOneLine) && (outBuffer[sendIndex] ==
'\n' || outBuffer[sendIndex] ==
'\r'))
1339 oC_ErrorCode_t oC_UART_LLD_WriteWithDma( oC_UART_Channel_t Channel ,
const char * Buffer , oC_UInt_t Size )
1341 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1342 oC_DMA_Channel_t channel = 0;
1345 oC_AssignErrorCodeIfFalse(&errorCode , IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
1346 oC_AssignErrorCodeIfFalse(&errorCode , IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
1347 oC_AssignErrorCodeIfFalse(&errorCode , IsRam(Buffer) || IsRom(Buffer) , oC_ErrorCode_WrongAddress) &&
1348 oC_AssignErrorCodeIfFalse(&errorCode , Size != 0 , oC_ErrorCode_SizeNotCorrect) &&
1349 oC_AssignErrorCode(&errorCode , oC_DMA_LLD_FindFreeDmaChannelForPeripheralTrade(&channel,Channel,oC_Machine_DmaSignalType_TX) ) &&
1350 ErrorCondition( AreOperationsEnabled(Channel) , oC_ErrorCode_ChannelOperationsNotEnabled)
1353 oC_DMA_LLD_PeripheralTradeConfig_t dmaConfig;
1355 dmaConfig.Buffer = (
void*)Buffer;
1356 dmaConfig.BufferSize = Size;
1357 dmaConfig.ElementSize =
sizeof(char);
1358 dmaConfig.PeripheralChannel = Channel;
1359 dmaConfig.PeripheralData = (
void*)&UARTDR(Channel)->Value;
1360 dmaConfig.Priority = oC_DMA_LLD_Priority_Medium;
1361 dmaConfig.SignalType = oC_Machine_DmaSignalType_TX;
1362 dmaConfig.TransferCompleteEventHandler =
NULL;
1363 dmaConfig.TransmitDirection = oC_DMA_LLD_Direction_Transmit;
1365 UARTDMACTL(Channel)->TXDMAE = 1;
1367 errorCode = oC_DMA_LLD_ConfigurePeripheralTrade(channel,&dmaConfig);
1379 oC_ErrorCode_t oC_UART_LLD_ReadWithDma( oC_UART_Channel_t Channel ,
char * outBuffer , oC_UInt_t Size )
1381 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1382 oC_DMA_Channel_t channel = 0;
1385 oC_AssignErrorCodeIfFalse(&errorCode , IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
1386 oC_AssignErrorCodeIfFalse(&errorCode , IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
1387 oC_AssignErrorCodeIfFalse(&errorCode , IsRam(outBuffer) , oC_ErrorCode_OutputAddressNotInRAM) &&
1388 oC_AssignErrorCodeIfFalse(&errorCode , Size > 0 , oC_ErrorCode_SizeNotCorrect) &&
1389 oC_AssignErrorCode(&errorCode , oC_DMA_LLD_FindFreeDmaChannelForPeripheralTrade(&channel,Channel,oC_Machine_DmaSignalType_RX) )&&
1390 ErrorCondition( AreOperationsEnabled(Channel) , oC_ErrorCode_ChannelOperationsNotEnabled)
1393 oC_DMA_LLD_PeripheralTradeConfig_t dmaConfig;
1395 dmaConfig.Buffer = (
void*)outBuffer;
1396 dmaConfig.BufferSize = Size;
1397 dmaConfig.ElementSize =
sizeof(char);
1398 dmaConfig.PeripheralChannel = Channel;
1399 dmaConfig.PeripheralData = (
void*)&UARTDR(Channel)->Value;
1400 dmaConfig.Priority = oC_DMA_LLD_Priority_Medium;
1401 dmaConfig.SignalType = oC_Machine_DmaSignalType_RX;
1402 dmaConfig.TransferCompleteEventHandler =
NULL;
1403 dmaConfig.TransmitDirection = oC_DMA_LLD_Direction_Receive;
1405 UARTDMACTL(Channel)->RXDMAE = 1;
1407 errorCode = oC_DMA_LLD_ConfigurePeripheralTrade(channel,&dmaConfig);
1413 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 1420 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1430 if(Ring->Counter >= SOFTWARE_RING_COUNT)
1436 Ring->Buffer[Ring->PutIndex++] = Data;
1439 if(Ring->PutIndex >= SOFTWARE_RING_COUNT)
1452 uint16_t data = 0xFFFF;
1454 if(Ring->Counter > 0)
1457 data = Ring->Buffer[Ring->GetIndex++];
1458 if(Ring->GetIndex >= SOFTWARE_RING_COUNT)
1477 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1485 #define _________________________________________INTERRUPTS_SECTION_________________________________________________________________________ 1487 #define MODULE_NAME UART 1488 #define INTERRUPT_TYPE_NAME PeripheralInterrupt 1497 if(UARTRIS(Channel)->TXRIS == 1)
1499 while(IsSoftwareTxRingEmpty(Channel) ==
false && (IsTxFifoFull(Channel) ==
false))
1504 if(TxNotFullHandler)
1506 TxNotFullHandler(Channel);
1509 if(IsSoftwareTxRingEmpty(Channel))
1511 UARTIM(Channel)->TXIM = 0;
1515 if(UARTRIS(Channel)->RXRIS == 1)
1517 while(IsRxFifoEmpty(Channel) ==
false)
1522 if(RxNotEmptyHandler)
1524 RxNotEmptyHandler(Channel);
1531 #undef INTERRUPT_TYPE_NAME 1533 #undef _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
double oC_Frequency_t
type to store frequency
#define oC_Machine_ReadRegister(Channel, REGISTER_NAME)
redefinition of oC_Machine_ReadRegisterDirectStaticOffset
The file with interface for LSF module.
oC_InterruptPriotity_t
stores priority of interrupts
The file with LLD interface for the MEM driver.
#define oC_Machine_WriteRegister(Channel, REGISTER_NAME, Value)
redefinition of oC_Machine_WriteRegisterDirectStaticOffset
The file with interface for the module library.
oC_Frequency_t oC_CLOCK_LLD_GetClockFrequency(void)
returns frequency of the system clock
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Something is powered off.
The file with LLD interface for the CLOCK driver.
#define oC_Channel_IsCorrect(MODULE_NAME, Channel)
checks if channel is correct
static bool oC_Bits_AreBitsClearU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are clear
#define oC_Channel_FromIndex(MODULE_NAME, ChannelIndex)
returns channel according to index in module
#define oC_ModuleChannel_NumberOfElements(MODULE_NAME)
Number of elements in module channel.
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
The file with functions for the bits operation.
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
Static array definitions.
static void PutToSoftwareRing(SoftwareRing_t *SoftwareRing, oC_Netif_t Netif, oC_Net_Packet_t *Packet)
puts packet to the software ring
static oC_Power_t oC_Machine_GetPowerStateForChannel(oC_Channel_t Channel)
returns power state for channel
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
#define oC_Channel_ToIndex(MODULE_NAME, Channel)
returns index in module according to channel
The file with LLD interface for the DMA driver.
static bool GetFromSoftwareRing(SoftwareRing_t *SoftwareRing, const oC_Net_Address_t *Address, oC_Net_Packet_t *outPacket, oC_Netif_t *outNetif, oC_NetifMan_PacketFilterFunction_t FilterFunction, const void *Parameter)
reads packet from the software ring
#define oC_Channel_InterruptHandler(ChannelVariableName)
creates common interrupt handler for channel
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
oC_Power_t
stores registers power state
#define NULL
pointer to a zero
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off