Choco OS  V.0.16.9.0
Join to the chocolate world
oc_uart_lld.c
1 
27 #include <oc_uart_lld.h>
28 #include <oc_mem_lld.h>
29 #include <oc_bits.h>
30 #include <oc_gpio_mslld.h>
31 #include <oc_array.h>
32 #include <oc_clock_lld.h>
33 #include <oc_dma_lld.h>
34 #include <oc_module.h>
35 #include <oc_lsf.h>
36 #include <oc_stdtypes.h>
37 #include <string.h>
38 
44 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
45 
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)
59 
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)
77 
78 
79 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
80 
86 #define _________________________________________TYPES_SECTION______________________________________________________________________________
87 
88 typedef struct
89 {
90  uint16_t Buffer[SOFTWARE_RING_COUNT];
91  uint16_t PutIndex;
92  uint16_t GetIndex;
93  uint16_t Counter;
95 
96 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
97 
98 
104 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
105 
106 static inline void PutToSoftwareRing ( SoftwareRing_t * Ring , uint16_t Data );
107 static inline uint16_t GetFromSoftwareRing( SoftwareRing_t * Ring );
108 static inline void ClearSoftwareRing ( SoftwareRing_t * Ring );
109 
110 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
111 
112 
118 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
119 
120 static oC_UART_LLD_Interrupt_t RxNotEmptyHandler = NULL;
121 static oC_UART_LLD_Interrupt_t TxNotFullHandler = NULL;
122 static SoftwareRing_t SoftwareRxRings[oC_ModuleChannel_NumberOfElements(UART)];
123 static SoftwareRing_t SoftwareTxRings[oC_ModuleChannel_NumberOfElements(UART)];
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;
132 #else
133 # error Number of UART channels is too big (max 64)
134 #endif
135 
136 
137 
138 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
139 
145 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
146 
147 //==========================================================================================================================================
152 //==========================================================================================================================================
153 bool oC_UART_LLD_IsChannelCorrect( oC_UART_Channel_t Channel )
154 {
155  return oC_Channel_IsCorrect(UART,Channel);
156 }
157 
158 //==========================================================================================================================================
163 //==========================================================================================================================================
164 bool oC_UART_LLD_IsChannelIndexCorrect( oC_UART_LLD_ChannelIndex_t ChannelIndex )
165 {
166  return ChannelIndex < oC_ModuleChannel_NumberOfElements(UART);
167 }
168 
169 //==========================================================================================================================================
174 //==========================================================================================================================================
175 oC_UART_LLD_ChannelIndex_t oC_UART_LLD_ChannelToChannelIndex( oC_UART_Channel_t Channel )
176 {
177  return oC_Channel_ToIndex(UART,Channel);
178 }
179 
180 //==========================================================================================================================================
185 //==========================================================================================================================================
186 oC_UART_Channel_t oC_UART_LLD_ChannelIndexToChannel( oC_UART_LLD_ChannelIndex_t Channel )
187 {
188  return oC_Channel_FromIndex(UART,Channel);
189 }
190 
191 //==========================================================================================================================================
196 //==========================================================================================================================================
197 oC_UART_Channel_t oC_UART_LLD_GetChannelOfModulePin( oC_UART_Pin_t ModulePin )
198 {
199  return oC_ModulePin_GetChannel(ModulePin);
200 }
201 
202 //==========================================================================================================================================
207 //==========================================================================================================================================
208 oC_ErrorCode_t oC_UART_LLD_TurnOnDriver( void )
209 {
210  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
211 
213 
214  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_UART_LLD))
215  {
216  oC_Module_TurnOn(oC_Module_UART_LLD);
217  errorCode = oC_ErrorCode_None;
218  RxNotEmptyHandler = NULL;
219  TxNotFullHandler = NULL;
220  UsedChannels = 0;
221 
222  }
223 
225 
226  return errorCode;
227 }
228 
229 //==========================================================================================================================================
234 //==========================================================================================================================================
235 oC_ErrorCode_t oC_UART_LLD_TurnOffDriver( void )
236 {
237  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
238 
240 
241  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
242  {
243  oC_Module_TurnOff(oC_Module_UART_LLD);
244  errorCode = oC_ErrorCode_None;
245  }
246 
248 
249  return errorCode;
250 }
251 
252 //==========================================================================================================================================
257 //==========================================================================================================================================
258 oC_ErrorCode_t oC_UART_LLD_SetDriverInterruptHandlers( oC_UART_LLD_Interrupt_t RxNotEmpty , oC_UART_LLD_Interrupt_t TxNotFull)
259 {
260  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
261 
263 
264  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
265  {
266  if(
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)
271  )
272  {
273  RxNotEmptyHandler = RxNotEmpty;
274  TxNotFullHandler = TxNotFull;
275  errorCode = oC_ErrorCode_None;
276  }
277  }
278 
280 
281  return errorCode;
282 }
283 
284 //==========================================================================================================================================
289 //==========================================================================================================================================
290 oC_ErrorCode_t oC_UART_LLD_SetPower( oC_UART_Channel_t Channel , oC_Power_t Power )
291 {
292  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
293  oC_InterruptPriotity_t uartPriority = 10;
294 
296 
297  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
298  {
299  if(
300  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
301  ErrorCondition( Power == oC_Power_On || Power == oC_Power_Off , oC_ErrorCode_PowerStateNotCorrect) &&
302  ErrorCondition( oC_Machine_SetPowerStateForChannel(Channel,Power) , oC_ErrorCode_CannotEnableChannel) &&
303  ErrorCondition( oC_Channel_EnableInterrupt(Channel,PeripheralInterrupt) , oC_ErrorCode_CannotEnableInterrupt) &&
304  ErrorCondition( oC_Channel_SetInterruptPriority(Channel,PeripheralInterrupt, uartPriority) , oC_ErrorCode_UARTInterruptConfigureError)
305  )
306  {
307  errorCode = oC_ErrorCode_None;
308  }
309  }
310 
312 
313  return errorCode;
314 }
315 
316 //==========================================================================================================================================
321 //==========================================================================================================================================
322 oC_ErrorCode_t oC_UART_LLD_ReadPower( oC_UART_Channel_t Channel , oC_Power_t * outPower )
323 {
324  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
325 
327 
328  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
329  {
330  if(
331  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
332  ErrorCondition( IsRam(outPower) , oC_ErrorCode_OutputAddressNotInRAM)
333  )
334  {
335  *outPower = oC_Machine_GetPowerStateForChannel(Channel);
336  errorCode = oC_ErrorCode_None;
337  }
338  }
339 
341 
342  return errorCode;
343 }
344 //==========================================================================================================================================
349 //==========================================================================================================================================
350 oC_ErrorCode_t oC_UART_LLD_DisableOperations( oC_UART_Channel_t Channel )
351 {
352  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
353 
355 
356  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
357  {
358  if(
359  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
360  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn)
361  )
362  {
363  UARTCTL(Channel)->UARTEN = 0;
364  UARTCTL(Channel)->RXE = 0;
365  UARTCTL(Channel)->TXE = 0;
366 
367  /* Waiting for end of transmissions */
368  while(IsChannelBusy(Channel));
369 
370  UARTLCRH(Channel)->FEN = 0;
371 
372  errorCode = oC_ErrorCode_None;
373  }
374  }
375 
377 
378  return errorCode;
379 }
380 
381 //==========================================================================================================================================
386 //==========================================================================================================================================
387 oC_ErrorCode_t oC_UART_LLD_EnableOperations( oC_UART_Channel_t Channel )
388 {
389  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
390 
392 
393  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
394  {
395  if(
396  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
397  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn)
398  )
399  {
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;
406 
407  errorCode = oC_ErrorCode_None;
408  }
409  }
410 
412 
413  return errorCode;
414 }
415 
416 //==========================================================================================================================================
421 //==========================================================================================================================================
422 oC_ErrorCode_t oC_UART_LLD_RestoreDefaultStateOnChannel( oC_UART_Channel_t Channel )
423 {
424  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
425 
427 
428  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
429  {
430  if(
431  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
432  ErrorCondition( oC_Machine_SetPowerStateForChannel(Channel,oC_Power_Off) , oC_ErrorCode_CannotRestoreDefaultState)
433  )
434  {
435 
436  errorCode = oC_ErrorCode_None;
437  }
438  }
439 
441 
442  return errorCode;
443 }
444 
445 //==========================================================================================================================================
450 //==========================================================================================================================================
451 oC_ErrorCode_t oC_UART_LLD_SetWordLength( oC_UART_Channel_t Channel , oC_UART_LLD_WordLength_t WordLength )
452 {
453  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
454 
456 
457  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
458  {
459  if(
460  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel ) &&
461  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn ) &&
462  ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled )
463  )
464  {
465  /*
466  * This assertion fails, when someone will add, or change the #oC_UART_LLD_WordLength_t type.
467  * Note, that values for word length are very important in lm4f machine, and when it is changed,
468  * this function must be re-implemented.
469  *
470  * Values for the WLEN in lm4f machine:
471  * Value | Word Length
472  * ------|-----------------------------
473  * 0 | 5 bits
474  * 1 | 6 bits
475  * 2 | 7 bits
476  * 3 | 8 bits
477  *
478  */
479  oC_STATIC_ASSERT(
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"
485  );
486 
487  UARTLCRH(Channel)->WLEN = WordLength;
488  errorCode = oC_ErrorCode_None;
489  }
490  }
491 
493 
494  return errorCode;
495 }
496 
497 //==========================================================================================================================================
502 //==========================================================================================================================================
503 oC_ErrorCode_t oC_UART_LLD_ReadWordLength( oC_UART_Channel_t Channel , oC_UART_LLD_WordLength_t * outWordLength )
504 {
505  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
506 
507  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
508  {
509  if(
510  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
511  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
512  ErrorCondition( IsRam(outWordLength) , oC_ErrorCode_OutputAddressNotInRAM)
513  )
514  {
515  /*
516  * This assertion fails, when someone will add, or change the #oC_UART_LLD_WordLength_t type.
517  * Note, that values for word length are very important in lm4f machine, and when it is changed,
518  * this function must be re-implemented.
519  *
520  * Values for the WLEN in lm4f machine:
521  * Value | Word Length
522  * ------|-----------------------------
523  * 0 | 5 bits
524  * 1 | 6 bits
525  * 2 | 7 bits
526  * 3 | 8 bits
527  *
528  */
529  oC_STATIC_ASSERT(
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"
535  );
536 
537  *outWordLength = UARTLCRH(Channel)->WLEN;
538  errorCode = oC_ErrorCode_None;
539  }
540  }
541 
542  return errorCode;
543 }
544 
545 //==========================================================================================================================================
550 //==========================================================================================================================================
551 oC_ErrorCode_t oC_UART_LLD_SetBitRate( oC_UART_Channel_t Channel , uint32_t BitRate )
552 {
553  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
554 
556 
557  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
558  {
559  if(
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)
564  )
565  {
566  oC_Frequency_t currentClockFrequency = oC_CLOCK_LLD_GetClockFrequency();
567  float brdFloat = 0;
568  uint8_t clockDivisor = 8;
569  static const float maxBrd = (float)(0x10000);
570 
571 #define CountBrd( clkFreq , clkDiv , BaudRate ) ((float)((clkFreq) / ( ((float)(clkDiv)) * ((float)(BaudRate)) )))
572 
573  brdFloat = CountBrd(currentClockFrequency,clockDivisor,BitRate);
574 
575  /* If baud rate divisor is too big, try to re-count it using grower clock divisor */
576  if(brdFloat > maxBrd )
577  {
578  clockDivisor = 16;
579  brdFloat = CountBrd(currentClockFrequency,clockDivisor,BitRate);
580  }
581 
582  if(brdFloat <= maxBrd )
583  {
584  oC_UInt_t integerBrdPart = (oC_UInt_t)brdFloat;
585  float fractionalBrdPart = brdFloat - (float)integerBrdPart;
586  /* Write integer part */
587  oC_Machine_WriteRegister(Channel, UARTIBRD , integerBrdPart );
588 
589  /* Write fractional part - the magic is from machine documentation, page 854 */
590  oC_Machine_WriteRegister(Channel, UARTFBRD , (oC_UInt_t) (fractionalBrdPart * 64 + 0.5));
591 
592  /* Selecting between 8 and 16 clock divisor */
593  UARTCTL(Channel)->HSE = (clockDivisor == 8) ? 1 : 0;
594 
595  errorCode = oC_ErrorCode_None;
596  }
597  else
598  {
599  errorCode = oC_ErrorCode_BitRateNotSupported;
600  }
601 
602 #undef CountBrd
603  }
604  }
605 
607 
608  return errorCode;
609 }
610 
611 //==========================================================================================================================================
616 //==========================================================================================================================================
617 oC_ErrorCode_t oC_UART_LLD_ReadBitRate( oC_UART_Channel_t Channel , uint32_t * outBitRate )
618 {
619  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
620 
621  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
622  {
623  if(
624  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
625  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
626  ErrorCondition( IsRam(outBitRate) , oC_ErrorCode_OutputAddressNotInRAM)
627  )
628  {
629  oC_Frequency_t currentClockFrequency = oC_CLOCK_LLD_GetClockFrequency();
630  oC_UInt_t integerBrdPart = oC_Machine_ReadRegister(Channel, UARTIBRD);
631  oC_UInt_t fractionalBrdPart = oC_Machine_ReadRegister(Channel, UARTFBRD);
632  float brd = (float)integerBrdPart;
633  float clockDivisor = (UARTCTL(Channel)->HSE == 1) ? 8 : 16;
634 
635  if(oC_AssignErrorCodeIfFalse(&errorCode , integerBrdPart != 0 || fractionalBrdPart != 0 , oC_ErrorCode_BitRateNotSet ))
636  {
637  /* This magic is from machine documentation from the page 854 */
638  brd += (((float)fractionalBrdPart) - 0.5) / 64;
639 
640  /* Protect again divide by 0 */
641  if(oC_AssignErrorCodeIfFalse(&errorCode , brd != 0 , oC_ErrorCode_MachineCanBeDamaged))
642  {
643  /* This magic is from machine documentation from the page 854 */
644  *outBitRate = (uint32_t)(currentClockFrequency / (clockDivisor * brd));
645 
646  errorCode = oC_ErrorCode_None;
647  }
648  }
649  }
650  }
651 
652  return errorCode;
653 }
654 
655 //==========================================================================================================================================
660 //==========================================================================================================================================
661 oC_ErrorCode_t oC_UART_LLD_SetParity( oC_UART_Channel_t Channel , oC_UART_LLD_Parity_t Parity )
662 {
663  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
664 
666 
667  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
668  {
669  if(
670  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
671  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
672  ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
673  )
674  {
675  if(Parity == oC_UART_LLD_Parity_Odd)
676  {
677  UARTLCRH(Channel)->PEN = 1;
678  UARTLCRH(Channel)->EPS = 0;
679  }
680  else if(Parity == oC_UART_LLD_Parity_Even)
681  {
682  UARTLCRH(Channel)->PEN = 1;
683  UARTLCRH(Channel)->EPS = 1;
684  }
685  else
686  {
687  UARTLCRH(Channel)->PEN = 0;
688  }
689 
690  errorCode = oC_ErrorCode_None;
691  }
692  }
693 
695 
696  return errorCode;
697 }
698 
699 //==========================================================================================================================================
704 //==========================================================================================================================================
705 oC_ErrorCode_t oC_UART_LLD_ReadParity( oC_UART_Channel_t Channel , oC_UART_LLD_Parity_t * outParity )
706 {
707  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
708 
709  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
710  {
711  if(
712  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
713  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
714  ErrorCondition( IsRam(outParity) , oC_ErrorCode_OutputAddressNotInRAM)
715  )
716  {
717  if(UARTLCRH(Channel)->PEN == 1)
718  {
719  if(UARTLCRH(Channel)->EPS == 0)
720  {
721  *outParity = oC_UART_LLD_Parity_Odd;
722  }
723  else
724  {
725  *outParity = oC_UART_LLD_Parity_Even;
726  }
727  }
728  else
729  {
730  *outParity = oC_UART_LLD_Parity_None;
731  }
732  errorCode = oC_ErrorCode_None;
733  }
734  }
735 
736  return errorCode;
737 }
738 
739 //==========================================================================================================================================
744 //==========================================================================================================================================
745 oC_ErrorCode_t oC_UART_LLD_SetStopBit( oC_UART_Channel_t Channel , oC_UART_LLD_StopBit_t StopBit )
746 {
747  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
748 
750 
751  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
752  {
753  if(
754  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
755  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
756  ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
757  )
758  {
759  if(StopBit == oC_UART_LLD_StopBit_1Bit)
760  {
761  UARTLCRH(Channel)->STP2 = 0;
762  }
763  else
764  {
765  UARTLCRH(Channel)->STP2 = 1;
766  }
767 
768  errorCode = oC_ErrorCode_None;
769  }
770  }
771 
773 
774 
775  return errorCode;
776 }
777 
778 //==========================================================================================================================================
783 //==========================================================================================================================================
784 oC_ErrorCode_t oC_UART_LLD_ReadStopBit( oC_UART_Channel_t Channel , oC_UART_LLD_StopBit_t * outStopBit )
785 {
786  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
787 
788  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
789  {
790  if(
791  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
792  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
793  ErrorCondition( IsRam(outStopBit) , oC_ErrorCode_OutputAddressNotInRAM)
794  )
795  {
796  if(UARTLCRH(Channel)->STP2 == 0)
797  {
798  *outStopBit = oC_UART_LLD_StopBit_1Bit;
799  }
800  else
801  {
802  *outStopBit = oC_UART_LLD_StopBit_2Bits;
803  }
804  errorCode = oC_ErrorCode_None;
805  }
806  }
807 
808  return errorCode;
809 }
810 
811 //==========================================================================================================================================
816 //==========================================================================================================================================
817 oC_ErrorCode_t oC_UART_LLD_SetBitOrder( oC_UART_Channel_t Channel , oC_UART_LLD_BitOrder_t BitOrder )
818 {
819  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
820 
822 
823  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
824  {
825  if(
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)
830  )
831  {
832  errorCode = oC_ErrorCode_None;
833  }
834  }
835 
837 
838  return errorCode;
839 }
840 
841 //==========================================================================================================================================
846 //==========================================================================================================================================
847 oC_ErrorCode_t oC_UART_LLD_ReadBitOrder( oC_UART_Channel_t Channel , oC_UART_LLD_BitOrder_t * outBitOrder )
848 {
849  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
850 
851  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
852  {
853  if(
854  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
855  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
856  ErrorCondition( IsRam(outBitOrder) , oC_ErrorCode_OutputAddressNotInRAM)
857  )
858  {
859  *outBitOrder = oC_UART_LLD_BitOrder_LSBFirst;
860  errorCode = oC_ErrorCode_None;
861  }
862  }
863 
864  return errorCode;
865 }
866 
867 //==========================================================================================================================================
872 //==========================================================================================================================================
873 oC_ErrorCode_t oC_UART_LLD_SetInvert( oC_UART_Channel_t Channel , oC_UART_LLD_Invert_t Invert )
874 {
875  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
876 
878 
879  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
880  {
881  if(
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)
886  )
887  {
888  errorCode = oC_ErrorCode_None;
889  }
890  }
891 
893 
894  return errorCode;
895 }
896 
897 //==========================================================================================================================================
902 //==========================================================================================================================================
903 oC_ErrorCode_t oC_UART_LLD_ReadInvert( oC_UART_Channel_t Channel , oC_UART_LLD_Invert_t * outInvert )
904 {
905  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
906 
907  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
908  {
909  if(
910  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
911  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
912  ErrorCondition( IsRam(outInvert) , oC_ErrorCode_OutputAddressNotInRAM)
913  )
914  {
915  *outInvert = oC_UART_LLD_Invert_NotInverted;
916  errorCode = oC_ErrorCode_None;
917  }
918  }
919 
920  return errorCode;
921 }
922 
923 //==========================================================================================================================================
928 //==========================================================================================================================================
929 oC_ErrorCode_t oC_UART_LLD_SetLoopback( oC_UART_Channel_t Channel , bool Loopback )
930 {
931  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
932 
934 
935  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
936  {
937  if(
938  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
939  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
940  ErrorCondition( AreOperationsDisabled(Channel) , oC_ErrorCode_ChannelOperationsNotDisabled)
941  )
942  {
943  if(Loopback)
944  {
945  UARTCTL(Channel)->LBE = 1;
946  }
947  else
948  {
949  UARTCTL(Channel)->LBE = 0;
950  }
951 
952  errorCode = oC_ErrorCode_None;
953  }
954  }
955 
957 
958  return errorCode;
959 }
960 
961 //==========================================================================================================================================
966 //==========================================================================================================================================
967 oC_ErrorCode_t oC_UART_LLD_ReadLoopback( oC_UART_Channel_t Channel , bool * outLoopback )
968 {
969  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
970 
971  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
972  {
973  if(
974  ErrorCondition( IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) &&
975  ErrorCondition( IsChannelPoweredOn(Channel) , oC_ErrorCode_ChannelNotPoweredOn) &&
976  ErrorCondition( IsRam(outLoopback) , oC_ErrorCode_OutputAddressNotInRAM)
977  )
978  {
979  *outLoopback = UARTCTL(Channel)->LBE == 1;
980  errorCode = oC_ErrorCode_None;
981  }
982  }
983 
984  return errorCode;
985 }
986 
987 //==========================================================================================================================================
992 //==========================================================================================================================================
993 oC_ErrorCode_t oC_UART_LLD_ConnectModulePin( oC_UART_Pin_t ModulePin )
994 {
995  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
996 
997  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
998  {
999  oC_UART_Channel_t channel = oC_ModulePin_GetChannel(ModulePin);
1000  oC_Pin_t pin = oC_ModulePin_GetPin(ModulePin);
1001 
1002  if(
1003  ErrorCondition( IsChannelCorrect(channel) , oC_ErrorCode_WrongChannel ) &&
1004  ErrorCondition( oC_GPIO_LLD_IsPinDefined(pin) , oC_ErrorCode_PinNotDefined )
1005  )
1006  {
1007  bool unused = false;
1008 
1010 
1011  if(
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) )
1016  )
1017  {
1018  errorCode = oC_ErrorCode_None;
1019  }
1020  else
1021  {
1022  oC_GPIO_LLD_SetPinsUnused(pin);
1023  }
1024 
1026  }
1027  }
1028 
1029  return errorCode;
1030 }
1031 
1032 //==========================================================================================================================================
1037 //==========================================================================================================================================
1038 oC_ErrorCode_t oC_UART_LLD_DisconnectModulePin( oC_UART_Pin_t ModulePin )
1039 {
1040  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1041 
1042  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1043  {
1044  oC_UART_Channel_t channel = oC_ModulePin_GetChannel(ModulePin);
1045  oC_Pin_t pin = oC_ModulePin_GetPin(ModulePin);
1046 
1047  if(
1048  ErrorCondition( IsChannelCorrect(channel) , oC_ErrorCode_WrongChannel ) &&
1049  ErrorCondition( oC_GPIO_LLD_IsPinDefined(pin) , oC_ErrorCode_PinNotDefined )
1050  )
1051  {
1052  errorCode = oC_ErrorCode_NotImplemented;
1053  }
1054  }
1055 
1056  return errorCode;
1057 }
1058 
1059 //==========================================================================================================================================
1064 //==========================================================================================================================================
1065 oC_ErrorCode_t oC_UART_LLD_SetChannelUsed( oC_UART_Channel_t Channel )
1066 {
1067  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1068 
1069  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1070  {
1072 
1073  if( ErrorCondition(IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) )
1074  {
1075  UsedChannels |= (1<<oC_Channel_ToIndex(UART,Channel));
1076  errorCode = oC_ErrorCode_None;
1077  }
1078 
1080  }
1081 
1082  return errorCode;
1083 }
1084 
1085 //==========================================================================================================================================
1090 //==========================================================================================================================================
1091 oC_ErrorCode_t oC_UART_LLD_SetChannelUnused( oC_UART_Channel_t Channel )
1092 {
1093  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1094 
1095  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1096  {
1098 
1099  if( ErrorCondition(IsChannelCorrect(Channel) , oC_ErrorCode_WrongChannel) )
1100  {
1101  UsedChannels &= ~(1<<oC_Channel_ToIndex(UART,Channel));
1102  errorCode = oC_ErrorCode_None;
1103  }
1104 
1106  }
1107 
1108  return errorCode;
1109 }
1110 
1111 //==========================================================================================================================================
1116 //==========================================================================================================================================
1117 bool oC_UART_LLD_IsChannelUsed( oC_UART_Channel_t Channel )
1118 {
1119  bool used = false;
1120 
1121  if(oC_Module_IsTurnedOn(oC_Module_UART_LLD))
1122  {
1123  if(IsChannelCorrect(Channel))
1124  {
1125  used = (UsedChannels & (1<<oC_Channel_ToIndex(UART,Channel))) == (1<<oC_Channel_ToIndex(UART,Channel));
1126  }
1127  }
1128 
1129  return used;
1130 }
1131 
1132 //==========================================================================================================================================
1137 //==========================================================================================================================================
1138 oC_ErrorCode_t oC_UART_LLD_ClearRxFifo( oC_UART_Channel_t Channel )
1139 {
1140  return oC_ErrorCode_NotImplemented;
1141 }
1142 
1143 //==========================================================================================================================================
1148 //==========================================================================================================================================
1149 bool oC_UART_LLD_IsRxFifoEmpty( oC_UART_Channel_t Channel )
1150 {
1151  return IsSoftwareRxRingEmpty(Channel);
1152 }
1153 //==========================================================================================================================================
1158 //==========================================================================================================================================
1159 bool oC_UART_LLD_IsTxFifoFull( oC_UART_Channel_t Channel )
1160 {
1161  return IsSoftwareTxRingFull(Channel);
1162 }
1163 
1164 //==========================================================================================================================================
1169 //==========================================================================================================================================
1170 void oC_UART_LLD_PutData( oC_UART_Channel_t Channel , char Data )
1171 {
1173  UARTIM(Channel)->TXIM = 1;
1174  if(IsSoftwareTxRingEmpty(Channel) && IsTxFifoEmpty(Channel))
1175  {
1176  UARTDR(Channel)->DATA = Data;
1177  }
1178  else
1179  {
1180  PutToSoftwareRing(&TxRing(Channel),Data);
1181  }
1183 }
1184 //==========================================================================================================================================
1189 //==========================================================================================================================================
1190 char oC_UART_LLD_GetData( oC_UART_Channel_t Channel )
1191 {
1192  return GetFromSoftwareRing(&RxRing(Channel));
1193 }
1194 //==========================================================================================================================================
1199 //==========================================================================================================================================
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 )
1201 {
1202  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1203 
1204  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1205  {
1206 
1207  if(
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)
1211  )
1212  {
1213  uint32_t foundPins = 0;
1214 
1215  errorCode = oC_ErrorCode_None;
1216 
1217  oC_ModulePin_ForeachDefined(modulePin)
1218  {
1219  if(modulePin->Pin == Pin && oC_Channel_IsCorrect(UART,modulePin->Channel) && modulePin->PinFunction == PinFunction)
1220  {
1221  if(outModulePinsArray != NULL)
1222  {
1223  if(foundPins < *ArraySize)
1224  {
1225  outModulePinsArray[foundPins] = modulePin->ModulePinIndex;
1226  }
1227  else
1228  {
1229  errorCode = oC_ErrorCode_OutputArrayToSmall;
1230  }
1231  }
1232  foundPins++;
1233  }
1234  }
1235 
1236  *ArraySize = foundPins;
1237  }
1238  }
1239 
1240  return errorCode;
1241 }
1242 
1243 //==========================================================================================================================================
1248 //==========================================================================================================================================
1249 oC_ErrorCode_t oC_UART_LLD_Write( oC_UART_Channel_t Channel , const char * Buffer , oC_UInt_t Size , oC_IoFlags_t IoFlags )
1250 {
1251  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1252 
1253  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1254  {
1255  if(
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)
1261  )
1262  {
1263  UARTDMACTL(Channel)->TXDMAE = 0;
1264 
1265  for(oC_UInt_t sendIndex = 0 ; sendIndex < Size ; sendIndex++ )
1266  {
1267  if( oC_Bits_AreBitsClearU32(IoFlags,oC_IoFlags_WaitForAllElements) && IsTxFifoFull(Channel) )
1268  {
1269  break;
1270  }
1271  while(IsTxFifoFull(Channel));
1272 
1273  UARTDR(Channel)->DATA = (uint8_t)Buffer[sendIndex];
1274  }
1275 
1276  errorCode = oC_ErrorCode_None;
1277  }
1278  }
1279 
1280  return errorCode;
1281 }
1282 
1283 //==========================================================================================================================================
1288 //==========================================================================================================================================
1289 oC_ErrorCode_t oC_UART_LLD_Read( oC_UART_Channel_t Channel , char * outBuffer , oC_UInt_t Size , oC_IoFlags_t IoFlags )
1290 {
1291  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1292 
1293  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_UART_LLD))
1294  {
1295  if(
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)
1301  )
1302  {
1303  UARTDMACTL(Channel)->RXDMAE = 0;
1304 
1305  errorCode = oC_ErrorCode_None;
1306 
1307  for(oC_UInt_t sendIndex = 0 ; sendIndex < Size ; sendIndex++ )
1308  {
1309  if( oC_Bits_AreBitsClearU32(IoFlags,oC_IoFlags_WaitForAllElements) && IsRxFifoEmpty(Channel) )
1310  {
1311  if(sendIndex == 0)
1312  {
1313  errorCode = oC_ErrorCode_NoneElementReceived;
1314  }
1315  break;
1316  }
1317  while(IsRxFifoEmpty(Channel));
1318 
1319  outBuffer[sendIndex] = UARTDR(Channel)->DATA;
1320 
1321  if((IoFlags & oC_IoFlags_ReadOneLine) && (outBuffer[sendIndex] == '\n' || outBuffer[sendIndex] == '\r'))
1322  {
1323  break;
1324  }
1325  }
1326 
1327  }
1328  }
1329 
1330  return errorCode;
1331 }
1332 
1333 //==========================================================================================================================================
1338 //==========================================================================================================================================
1339 oC_ErrorCode_t oC_UART_LLD_WriteWithDma( oC_UART_Channel_t Channel , const char * Buffer , oC_UInt_t Size )
1340 {
1341  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1342  oC_DMA_Channel_t channel = 0;
1343 
1344  if(
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)
1351  )
1352  {
1353  oC_DMA_LLD_PeripheralTradeConfig_t dmaConfig;
1354 
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;
1364 
1365  UARTDMACTL(Channel)->TXDMAE = 1;
1366 
1367  errorCode = oC_DMA_LLD_ConfigurePeripheralTrade(channel,&dmaConfig);
1368  }
1369 
1370  return errorCode;
1371 }
1372 
1373 //==========================================================================================================================================
1378 //==========================================================================================================================================
1379 oC_ErrorCode_t oC_UART_LLD_ReadWithDma( oC_UART_Channel_t Channel , char * outBuffer , oC_UInt_t Size )
1380 {
1381  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1382  oC_DMA_Channel_t channel = 0;
1383 
1384  if(
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)
1391  )
1392  {
1393  oC_DMA_LLD_PeripheralTradeConfig_t dmaConfig;
1394 
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;
1404 
1405  UARTDMACTL(Channel)->RXDMAE = 1;
1406 
1407  errorCode = oC_DMA_LLD_ConfigurePeripheralTrade(channel,&dmaConfig);
1408  }
1409 
1410  return errorCode;
1411 }
1412 
1413 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
1414 
1420 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
1421 
1422 
1423 //==========================================================================================================================================
1427 //==========================================================================================================================================
1428 static inline void PutToSoftwareRing( SoftwareRing_t * Ring , uint16_t Data )
1429 {
1430  if(Ring->Counter >= SOFTWARE_RING_COUNT)
1431  {
1432  /* If ring is full, take the oldest data */
1433  GetFromSoftwareRing(Ring);
1434  }
1435 
1436  Ring->Buffer[Ring->PutIndex++] = Data;
1437  Ring->Counter++;
1438 
1439  if(Ring->PutIndex >= SOFTWARE_RING_COUNT)
1440  {
1441  Ring->PutIndex = 0;
1442  }
1443 }
1444 
1445 //==========================================================================================================================================
1449 //==========================================================================================================================================
1450 static inline uint16_t GetFromSoftwareRing( SoftwareRing_t * Ring )
1451 {
1452  uint16_t data = 0xFFFF;
1453 
1454  if(Ring->Counter > 0)
1455  {
1456  Ring->Counter--;
1457  data = Ring->Buffer[Ring->GetIndex++];
1458  if(Ring->GetIndex >= SOFTWARE_RING_COUNT)
1459  {
1460  Ring->GetIndex = 0;
1461  }
1462  }
1463 
1464  return data;
1465 }
1466 
1467 //==========================================================================================================================================
1471 //==========================================================================================================================================
1472 static inline void ClearSoftwareRing( SoftwareRing_t * Ring )
1473 {
1474  memset(Ring,0,sizeof(SoftwareRing_t));
1475 }
1476 
1477 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
1478 
1479 
1485 #define _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
1486 
1487 #define MODULE_NAME UART
1488 #define INTERRUPT_TYPE_NAME PeripheralInterrupt
1489 
1490 //==========================================================================================================================================
1494 //==========================================================================================================================================
1496 {
1497  if(UARTRIS(Channel)->TXRIS == 1)
1498  {
1499  while(IsSoftwareTxRingEmpty(Channel) == false && (IsTxFifoFull(Channel) == false))
1500  {
1501  UARTDR(Channel)->DATA = GetFromSoftwareRing(&TxRing(Channel));
1502  }
1503 
1504  if(TxNotFullHandler)
1505  {
1506  TxNotFullHandler(Channel);
1507  }
1508 
1509  if(IsSoftwareTxRingEmpty(Channel))
1510  {
1511  UARTIM(Channel)->TXIM = 0;
1512  }
1513  }
1514 
1515  if(UARTRIS(Channel)->RXRIS == 1)
1516  {
1517  while(IsRxFifoEmpty(Channel) == false)
1518  {
1519  PutToSoftwareRing(&RxRing(Channel),UARTDR(Channel)->DATA);
1520  }
1521 
1522  if(RxNotEmptyHandler)
1523  {
1524  RxNotEmptyHandler(Channel);
1525  }
1526  }
1527 
1528  //clear all interrupt
1529  oC_Machine_WriteRegister(Channel,UARTICR,0x17F2);
1530 }
1531 #undef INTERRUPT_TYPE_NAME
1532 
1533 #undef _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
1534 
1535 
Something is powered on.
Definition: oc_stdtypes.h:252
double oC_Frequency_t
type to store frequency
Definition: oc_frequency.h:76
#define oC_Machine_ReadRegister(Channel, REGISTER_NAME)
redefinition of oC_Machine_ReadRegisterDirectStaticOffset
Definition: oc_machine.h:221
The file with interface for LSF module.
oC_InterruptPriotity_t
stores priority of interrupts
Definition: oc_mcs.h:174
The file with LLD interface for the MEM driver.
#define oC_Machine_WriteRegister(Channel, REGISTER_NAME, Value)
redefinition of oC_Machine_WriteRegisterDirectStaticOffset
Definition: oc_machine.h:200
The file with interface for the module library.
oC_Frequency_t oC_CLOCK_LLD_GetClockFrequency(void)
returns frequency of the system clock
Definition: oc_clock_lld.c:237
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Definition: oc_module.h:121
Something is powered off.
Definition: oc_stdtypes.h:251
The file with LLD interface for the CLOCK driver.
#define oC_Channel_IsCorrect(MODULE_NAME, Channel)
checks if channel is correct
Definition: oc_channels.h:283
static bool oC_Bits_AreBitsClearU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are clear
Definition: oc_bits.h:952
#define oC_Channel_FromIndex(MODULE_NAME, ChannelIndex)
returns channel according to index in module
Definition: oc_channels.h:313
#define oC_ModuleChannel_NumberOfElements(MODULE_NAME)
Number of elements in module channel.
Definition: oc_channels.h:465
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
The file with functions for the bits operation.
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
Definition: oc_mcs.h:755
Static array definitions.
static void PutToSoftwareRing(SoftwareRing_t *SoftwareRing, oC_Netif_t Netif, oC_Net_Packet_t *Packet)
puts packet to the software ring
Definition: oc_netifman.c:951
static oC_Power_t oC_Machine_GetPowerStateForChannel(oC_Channel_t Channel)
returns power state for channel
Definition: oc_machine.h:550
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
Definition: oc_mcs.h:784
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
#define oC_Channel_ToIndex(MODULE_NAME, Channel)
returns index in module according to channel
Definition: oc_channels.h:298
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
Definition: oc_netifman.c:987
#define oC_Channel_InterruptHandler(ChannelVariableName)
creates common interrupt handler for channel
Definition: oc_channels.h:514
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
Definition: oc_machine.h:593
FILE__DESCRIPTION
oC_Power_t
stores registers power state
Definition: oc_stdtypes.h:249
#define NULL
pointer to a zero
Definition: oc_null.h:37
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185