Choco OS  V.0.16.9.0
Join to the chocolate world
oc_clock_lld.c
1 
27 #include <oc_clock_lld.h>
28 #include <oc_mem_lld.h>
29 #include <oc_registers.h>
30 #include <oc_module.h>
31 #include <oc_mcs.h>
32 #include <oc_lsf.h>
33 #include <oc_sys_lld.h>
34 #include <oc_interrupts.h>
35 #include <oc_math.h>
36 
37 
38 
44 #define _________________________________________DEFINITIONS_SECTION________________________________________________________________________
45 
46 #define RegisterRCC oC_Register( SystemControl , RCC )
47 #define RegisterRCC2 oC_Register( SystemControl , RCC2 )
48 #define RegisterRIS oC_Register( SystemControl , RIS )
49 #define MAX_FREQUENCY oC_MACHINE_MAXIMUM_FREQUENCY
50 
51 #undef _________________________________________DEFINITIONS_SECTION________________________________________________________________________
52 
58 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
59 
60 #define IsRam(Address) oC_LSF_IsRamAddress(Address)
61 #define IsRom(Address) oC_LSF_IsRomAddress(Address)
62 
63 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
64 
70 #define _________________________________________TYPES_SECTION______________________________________________________________________________
71 
72 typedef enum
73 {
74  OscSource_MainOsc = 0x0 ,
75  OscSource_PrecisionInternalOsc = 0x1 ,
76  OscSource_PrecisionInternalOscDiv4 = 0x2 ,
77  OscSource_InternalOsc = 0x3 ,
78  OscSource_HibernationOsc = 0x7
79 } OscSource_t;
80 
81 typedef enum
82 {
83  Pll_DontUse ,
84  Pll_200MHz ,
85  Pll_400MHz
86 } Pll_t;
87 
88 typedef enum
89 {
90  Xtal_NotCorrect = 0 ,
91  Xtal_4MHz = 0x06 ,
92  Xtal_4MHz096kHz = 0x07 ,
93  Xtal_4MHz915200Hz = 0x08 ,
94  Xtal_5MHz = 0x09 ,
95  Xtal_5MHz120kHz = 0x0A ,
96  Xtal_6MHz = 0x0B ,
97  Xtal_6MHz144kHz = 0x0C ,
98  Xtal_7MHz372800Hz = 0x0D ,
99  Xtal_8MHz = 0x0E ,
100  Xtal_8MHz192kHz = 0x0F ,
101  Xtal_10MHz = 0x10 ,
102  Xtal_12MHz = 0x11 ,
103  Xtal_12MHz288kHz = 0x12 ,
104  Xtal_13MHz560kHz = 0x13 ,
105  Xtal_14MHz318180Hz = 0x14 ,
106  Xtal_16MHz = 0x15 ,
107  Xtal_16MHz384kHz = 0x16 ,
108  Xtal_18MHz = 0x17 ,
109  Xtal_20MHz = 0x18 ,
110  Xtal_24MHz = 0x19 ,
111  Xtal_25MHz = 0x1A
112 } Xtal_t;
113 
114 typedef enum
115 {
116  SysDiv_1 = 0x0 ,
117  SysDiv_2 = 0x1 ,
118  SysDiv_3 = 0x2 ,
119  SysDiv_4 = 0x3 ,
120  SysDiv_5 = 0x4 ,
121  SysDiv_6 = 0x5 ,
122  SysDiv_7 = 0x6 ,
123  SysDiv_8 = 0x7 ,
124  SysDiv_9 = 0x8 ,
125  SysDiv_10 = 0x9 ,
126  SysDiv_11 = 0xA ,
127  SysDiv_12 = 0xB ,
128  SysDiv_13 = 0xC ,
129  SysDiv_14 = 0xD ,
130  SysDiv_15 = 0xE ,
131  SysDiv_16 = 0xF ,
132  SysDiv_64 = 0x3F ,
133  SysDiv_128 = 0x7F
134 } SysDiv_t;
135 
136 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
137 
143 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
144 
145 static bool ConfigureClock ( OscSource_t OscSource , Xtal_t Xtal , Pll_t Pll , SysDiv_t SysDiv );
146 static Xtal_t GetXtalForFrequency ( oC_Frequency_t Frequency , oC_Frequency_t AcceptableDifference );
147 static bool FindDivisor ( oC_Frequency_t Frequency , oC_Frequency_t Difference , oC_Frequency_t OscillatorFrequency , Pll_t Pll , SysDiv_t * outSysDiv );
148 static void CallClockConfiguredEvent ( void );
149 
150 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
151 
157 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
158 
161 static oC_CLOCK_LLD_Interrupt_t ClockConfiguredHandler = NULL;
162 static const oC_Frequency_t XtalFrequencyArray[]= {
163  [Xtal_4MHz ] = 4000000 ,
164  [Xtal_4MHz096kHz ] = 4096000 ,
165  [Xtal_4MHz915200Hz ] = 4915200 ,
166  [Xtal_5MHz ] = 5000000 ,
167  [Xtal_5MHz120kHz ] = 5120000 ,
168  [Xtal_6MHz ] = 6000000 ,
169  [Xtal_6MHz144kHz ] = 6144000 ,
170  [Xtal_7MHz372800Hz ] = 7372800 ,
171  [Xtal_8MHz ] = 8000000 ,
172  [Xtal_8MHz192kHz ] = 8192000 ,
173  [Xtal_10MHz ] = 10000000 ,
174  [Xtal_12MHz ] = 12000000 ,
175  [Xtal_12MHz288kHz ] = 12288000 ,
176  [Xtal_13MHz560kHz ] = 13560000 ,
177  [Xtal_14MHz318180Hz ] = 14318180 ,
178  [Xtal_16MHz ] = 16000000 ,
179  [Xtal_16MHz384kHz ] = 16384000 ,
180  [Xtal_18MHz ] = 18000000 ,
181  [Xtal_20MHz ] = 20000000 ,
182  [Xtal_24MHz ] = 24000000 ,
183  [Xtal_25MHz ] = 25000000
184 };
185 static const oC_Frequency_t InternalOscilatorsFrequenciesArray[] = {
186  [OscSource_PrecisionInternalOsc ] = oC_MACHINE_PRECISION_INTERNAL_OSCILLATOR_FREQUENCY,
187  [OscSource_PrecisionInternalOscDiv4 ] = oC_MACHINE_PRECISION_INTERNAL_OSCILLATOR_FREQUENCY / 4,
188  [OscSource_InternalOsc ] = oC_MACHINE_INTERNAL_OSCILLATOR_FREQUENCY,
189 };
190 
191 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
192 
198 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
199 
202 
203 //==========================================================================================================================================
208 //==========================================================================================================================================
209 oC_ErrorCode_t oC_CLOCK_LLD_TurnOnDriver( void )
210 {
211  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
212 
214 
215  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_CLOCK_LLD))
216  {
217  /* ************************* NOTE ******************************
218  * ClockSource and ClockFrequency is specially not initialized *
219  * to not provide wrong informations about state of clock *
220  * configuration *
221  * *************************************************************/
222 
223  CurrentFrequency = oC_Machine_DefaultFrequency;
224  ClockSource = oC_CLOCK_LLD_ClockSource_Internal;
225  ClockConfiguredHandler = NULL;
226 
227  oC_Module_TurnOn(oC_Module_CLOCK_LLD);
228  errorCode = oC_ErrorCode_None;
229  }
230 
232 
233  return errorCode;
234 }
235 
236 //==========================================================================================================================================
241 //==========================================================================================================================================
242 oC_ErrorCode_t oC_CLOCK_LLD_TurnOffDriver( void )
243 {
244  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
245 
247 
248  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_CLOCK_LLD))
249  {
250 
251  oC_Module_TurnOff(oC_Module_CLOCK_LLD);
253 
254  if(errorCode != oC_ErrorCode_None)
255  {
256  errorCode = oC_ErrorCode_CannotRestoreDefaultState;
257  }
258  }
259 
261 
262  return errorCode;
263 }
264 
265 //==========================================================================================================================================
270 //==========================================================================================================================================
272 {
273  return ClockSource;
274 }
275 
276 //==========================================================================================================================================
281 //==========================================================================================================================================
283 {
284  return CurrentFrequency;
285 }
286 //==========================================================================================================================================
292 {
293  return MAX_FREQUENCY;
294 }
295 //==========================================================================================================================================
300 //==========================================================================================================================================
302 {
303  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
304 
305  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_CLOCK_LLD))
306  {
307  if(
308  oC_AssignErrorCodeIfFalse(&errorCode , ClockConfiguredHandler == NULL , oC_ErrorCode_InterruptHandlerAlreadySet ) &&
309  oC_AssignErrorCodeIfFalse(&errorCode , IsRom(Interrupt) || IsRam(Interrupt) , oC_ErrorCode_WrongEventHandlerAddress )
310  )
311  {
312  if( oC_MEM_LLD_IsFlashAddress(Interrupt) || oC_MEM_LLD_IsRamAddress(Interrupt) )
313  {
315  ClockConfiguredHandler = Interrupt;
316  errorCode = oC_ErrorCode_None;
318  }
319  }
320  }
321 
322  return errorCode;
323 }
324 
325 //==========================================================================================================================================
330 //==========================================================================================================================================
331 bool oC_CLOCK_LLD_DelayForMicroseconds( oC_UInt_t Microseconds )
332 {
333  oC_UInt_t numberOfCyclesPerMicrosecond = CurrentFrequency/1000000UL;
334 
335  oC_MCS_Delay(numberOfCyclesPerMicrosecond*Microseconds);
336 
337  return true;
338 }
339 
340 //==========================================================================================================================================
345 //==========================================================================================================================================
346 oC_ErrorCode_t oC_CLOCK_LLD_ConfigureInternalClock( oC_Frequency_t TargetFrequency , oC_Frequency_t PermissibleDifference )
347 {
348  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
349  Xtal_t xtal = GetXtalForFrequency(oC_Machine_DefaultFrequency , 0);
350 
351  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_CLOCK_LLD))
352  {
353  if(
354  oC_AssignErrorCodeIfFalse(&errorCode , TargetFrequency > 0 && PermissibleDifference >= 0 , oC_ErrorCode_WrongFrequency)
355  )
356  {
358  errorCode = oC_ErrorCode_FrequencyNotPossible;
359 
360  for(OscSource_t oscSource =OscSource_PrecisionInternalOsc;
361  (oscSource <= OscSource_InternalOsc) && (errorCode != oC_ErrorCode_None)
362  ;oscSource++)
363  {
364  for(Pll_t pll = Pll_DontUse ; pll <= Pll_400MHz ; pll++)
365  {
366  SysDiv_t sysDiv = SysDiv_1;
367 
368  if(FindDivisor(TargetFrequency,PermissibleDifference,InternalOscilatorsFrequenciesArray[oscSource],pll,&sysDiv))
369  {
370  if(ConfigureClock(oscSource , xtal , pll , sysDiv))
371  {
372  switch(pll)
373  {
374  case Pll_DontUse: CurrentFrequency = InternalOscilatorsFrequenciesArray[oscSource] / (sysDiv + 1); break;
375  case Pll_200MHz: CurrentFrequency = oC_MHz(200) / (sysDiv + 1); break;
376  case Pll_400MHz: CurrentFrequency = oC_MHz(400) / (sysDiv + 1); break;
377  }
378  ClockSource = oC_CLOCK_LLD_ClockSource_Internal;
379  errorCode = oC_ErrorCode_None;
380  CallClockConfiguredEvent();
381  break;
382  }
383  else
384  {
385  errorCode = oC_ErrorCode_ClockConfigurationError;
386  }
387  }
388 
389  /* Only the precision internal oscillator can be configured with PLL */
390  if(oscSource != OscSource_PrecisionInternalOsc)
391  {
392  break;
393  }
394  }
395  }
397  }
398  }
399 
400  return errorCode;
401 }
402 
403 //==========================================================================================================================================
408 //==========================================================================================================================================
409 oC_ErrorCode_t oC_CLOCK_LLD_ConfigureExternalClock( oC_Frequency_t TargetFrequency , oC_Frequency_t PermissibleDifference , oC_Frequency_t OscillatorFrequency )
410 {
411  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
412  Xtal_t xtal = GetXtalForFrequency(OscillatorFrequency , 0);
413 
414  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_CLOCK_LLD))
415  {
416  if(
417  oC_AssignErrorCodeIfFalse(&errorCode , TargetFrequency > 0 && OscillatorFrequency > 0 && PermissibleDifference >= 0 , oC_ErrorCode_WrongFrequency) &&
418  oC_AssignErrorCodeIfFalse(&errorCode , xtal != Xtal_NotCorrect , oC_ErrorCode_UnsupportedOscillator)
419  )
420  {
421  errorCode = oC_ErrorCode_FrequencyNotPossible;
422 
424 
425  for(Pll_t pll = Pll_DontUse ; pll <= Pll_400MHz ; pll++)
426  {
427  SysDiv_t sysDiv = SysDiv_1;
428 
429  if(FindDivisor(TargetFrequency,PermissibleDifference,OscillatorFrequency,pll,&sysDiv))
430  {
431  if(ConfigureClock(OscSource_MainOsc , xtal , pll , sysDiv))
432  {
433  switch(pll)
434  {
435  case Pll_DontUse: CurrentFrequency = OscillatorFrequency / (sysDiv + 1); break;
436  case Pll_200MHz: CurrentFrequency = oC_MHz(200) / (sysDiv + 1); break;
437  case Pll_400MHz: CurrentFrequency = oC_MHz(400) / (sysDiv + 1); break;
438  }
439 
440  ClockSource = oC_CLOCK_LLD_ClockSource_External;
441  errorCode = oC_ErrorCode_None;
442  CallClockConfiguredEvent();
443  break;
444  }
445  else
446  {
447  errorCode = oC_ErrorCode_ClockConfigurationError;
448  }
449  }
450  }
451 
453 
454  }
455  }
456  return errorCode;
457 }
458 
459 //==========================================================================================================================================
464 //==========================================================================================================================================
465 oC_ErrorCode_t oC_CLOCK_LLD_ConfigureHibernationClock( oC_Frequency_t TargetFrequency , oC_Frequency_t PermissibleDifference , oC_Frequency_t OscillatorFrequency )
466 {
467  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
468 
469  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_CLOCK_LLD))
470  {
471  if(
472  oC_AssignErrorCodeIfFalse(&errorCode , TargetFrequency > 0 && OscillatorFrequency > 0 && PermissibleDifference >= 0 , oC_ErrorCode_WrongFrequency) &&
473  oC_AssignErrorCodeIfFalse(&errorCode , OscillatorFrequency == oC_MACHINE_HIBERNATION_OSCILLATOR_FREQUENCY , oC_ErrorCode_UnsupportedOscillator)
474  )
475  {
476  /* XTal is set to default, because there is not any information about this in documentation */
477  Xtal_t xtal = GetXtalForFrequency(oC_Machine_DefaultFrequency , 0);
478  SysDiv_t sysDiv = SysDiv_1;
479 
480  if(FindDivisor(TargetFrequency,PermissibleDifference,OscillatorFrequency,Pll_DontUse,&sysDiv))
481  {
482  if(ConfigureClock(OscSource_HibernationOsc , xtal , Pll_DontUse , sysDiv))
483  {
484  CurrentFrequency = OscillatorFrequency / (sysDiv + 1);
485  ClockSource = oC_CLOCK_LLD_ClockSource_External;
486  errorCode = oC_ErrorCode_None;
487  CallClockConfiguredEvent();
488  }
489  else
490  {
491  errorCode = oC_ErrorCode_ClockConfigurationError;
492  }
493  }
494  else
495  {
496  errorCode = oC_ErrorCode_FrequencyNotPossible;
497  }
498  }
499  }
500 
501  return errorCode;
502 }
503 
504 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
505 
512 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
513 
514 //==========================================================================================================================================
518 //==========================================================================================================================================
519 static bool ConfigureClock( OscSource_t OscSource , Xtal_t Xtal , Pll_t Pll , SysDiv_t SysDiv )
520 {
521  bool success = true;
522  oC_RegisterType_(RCC) rcc;
523  oC_RegisterType_(RCC2) rcc2;
524 
525  rcc.Value = RegisterRCC->Value;
526  rcc2.Value = RegisterRCC2->Value;
527 
528  /*
529  * Bypass the PLL and system clock divider by setting the BYPASS bit and clearing the USESYS
530  * bit in the RCC register, thereby configuring the microcontroller to run off a "raw" clock source
531  * and allowing for the new PLL configuration to be validated before switching the system clock
532  * to the PLL.
533  */
534  rcc.BYPASS = 1;
535  rcc.USESYSDIV = 0;
536 
537  RegisterRCC->Value = rcc.Value;
538 
539  /*
540  * Select the crystal value (XTAL) and oscillator source (OSCSRC), and clear the PWRDN bit in
541  * RCC/RCC2. Setting the XTAL field automatically pulls valid PLL configuration data for the
542  * appropriate crystal, and clearing the PWRDN bit powers and enables the PLL and its output.
543  */
544  rcc.XTAL = Xtal;
545 
546  if(OscSource < OscSource_HibernationOsc)
547  {
548  rcc.OSCSRC = OscSource;
549  rcc2.USERCC2 = 1;
550  }
551  rcc2.OSCSRC2 = OscSource;
552 
553  rcc.PWRDN = 0;
554  rcc2.PWRDN2 = 0;
555 
556  RegisterRCC->Value = rcc.Value;
557  RegisterRCC2->Value = rcc2.Value;
558 
559  /*
560  * Select the desired system divider (SYSDIV) in RCC/RCC2 and set the USESYS bit in RCC. The
561  * SYSDIV field determines the system frequency for the microcontroller
562  */
563  if(Pll == Pll_DontUse)
564  {
565  if(SysDiv <= SysDiv_16)
566  {
567  rcc.SYSDIV = SysDiv;
568  rcc2.SYSDIV2 = SysDiv;
569  }
570  else if(SysDiv <= SysDiv_64)
571  {
572  rcc2.SYSDIV2 = SysDiv;
573  rcc2.USERCC2 = 1;
574  }
575  else
576  {
577  success = false;
578  }
579  }
580  else if(Pll == Pll_200MHz)
581  {
582  rcc2.DIV400 = 0;
583 
584  if(SysDiv <= SysDiv_2)
585  {
586  success = false;
587  }
588  else if(SysDiv <= SysDiv_16)
589  {
590  rcc.SYSDIV = SysDiv;
591  rcc2.SYSDIV2 = SysDiv;
592  }
593  else if(SysDiv < SysDiv_64)
594  {
595  rcc2.SYSDIV2 = SysDiv;
596  rcc2.USERCC2 = 1;
597  }
598  else
599  {
600  success = false;
601  }
602  }
603  else
604  {
605  rcc2.DIV400 = 1;
606  rcc2.USERCC2 = 1;
607 
608  if(SysDiv <= SysDiv_4)
609  {
610  success = false;
611  }
612  else
613  {
614  rcc2.SYSDIV2 = SysDiv >> 1;
615  rcc2.SYSDIV2LSB = SysDiv % 2;
616  }
617  }
618  rcc.USESYSDIV = 1;
619 
620  RegisterRCC->Value = rcc.Value;
621  RegisterRCC2->Value = rcc2.Value;
622 
623  oC_MCS_Delay(16);
624 
625  /*
626  * Wait for the PLL to lock by polling the PLLLRIS bit in the Raw Interrupt Status (RIS) register.
627  */
628  if(Pll != Pll_DontUse)
629  {
630  while(!RegisterRIS->PLLLRIS);
631 
632  /*
633  * Enable use of the PLL by clearing the BYPASS bit in RCC/RCC2.
634  */
635  RegisterRCC->BYPASS = 0;
636  RegisterRCC2->BYPASS2 = 0;
637 
638  oC_MCS_Delay(16);
639  }
640 
641  return success;
642 }
643 
644 //==========================================================================================================================================
653 //==========================================================================================================================================
654 static Xtal_t GetXtalForFrequency( oC_Frequency_t Frequency , oC_Frequency_t AcceptableDifference )
655 {
656  Xtal_t xtal = 0;
657 
658  for( Xtal_t x = Xtal_4MHz ; x <= Xtal_25MHz ; x++ )
659  {
660  if( oC_ABS( XtalFrequencyArray[x] , Frequency ) <= AcceptableDifference )
661  {
662  xtal = x;
663  break;
664  }
665  }
666 
667  return xtal;
668 }
669 
670 //==========================================================================================================================================
676 //==========================================================================================================================================
677 static bool FindDivisor( oC_Frequency_t Frequency , oC_Frequency_t Difference , oC_Frequency_t OscillatorFrequency , Pll_t Pll , SysDiv_t * outSysDiv )
678 {
679  bool found = false;
680  oC_Frequency_t frequencyToDivide = 0;
681  SysDiv_t startSysDiv = SysDiv_1;
682  SysDiv_t endSysDiv = SysDiv_64;
683 
684  if(Pll == Pll_DontUse)
685  {
686  frequencyToDivide = OscillatorFrequency;
687  startSysDiv = SysDiv_1;
688  endSysDiv = SysDiv_64;
689  }
690  else if(Pll == Pll_200MHz)
691  {
692  frequencyToDivide = oC_MHz(200);
693  startSysDiv = SysDiv_3;
694  endSysDiv = SysDiv_64;
695  }
696  else if(Pll == Pll_400MHz)
697  {
698  frequencyToDivide = oC_MHz(400);
699  startSysDiv = SysDiv_5;
700  endSysDiv = SysDiv_128;
701  }
702 
703  for(SysDiv_t sysDiv = startSysDiv ; sysDiv <= endSysDiv ; sysDiv++ )
704  {
705  /*
706  * This is for skipping one special case. I don't know why, but the 7 divisor in DIV400=1 mode is reserved.
707  */
708  if(Pll == Pll_400MHz && sysDiv == SysDiv_7)
709  {
710  continue;
711  }
712  oC_Frequency_t mainOscFrequency = frequencyToDivide / (sysDiv+1);
713 
714  if(oC_ABS(mainOscFrequency,Frequency) <= Difference)
715  {
716  found = true;
717  *outSysDiv = sysDiv;
718  break;
719  }
720  }
721 
722  return found;
723 }
724 
725 //==========================================================================================================================================
729 //==========================================================================================================================================
730 static void CallClockConfiguredEvent( void )
731 {
732  if( ClockConfiguredHandler)
733  {
734  ClockConfiguredHandler(CurrentFrequency);
735  }
736 }
737 
738 
739 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
The file with interface for registers module.
Basic math operations.
oC_ErrorCode_t oC_CLOCK_LLD_TurnOffDriver(void)
release the driver
Definition: oc_clock_lld.c:197
double oC_Frequency_t
type to store frequency
Definition: oc_frequency.h:76
oC_ErrorCode_t oC_CLOCK_LLD_SetClockConfiguredInterrupt(oC_CLOCK_LLD_Interrupt_t Interrupt)
configures an interrupt for clock configured event
Definition: oc_clock_lld.c:270
oC_CLOCK_LLD_ClockSource_t oC_CLOCK_LLD_GetClockSource(void)
returns source of the system clock
Definition: oc_clock_lld.c:226
oC_CLOCK_LLD_ClockSource_t
type for storing source of the system clock
Definition: oc_clock_lld.h:73
The file with interface for LSF module.
oC_Frequency_t oC_CLOCK_LLD_GetMaximumClockFrequency(void)
returns maximum frequency permissible for the machine
Definition: oc_clock_lld.c:259
oC_ErrorCode_t oC_CLOCK_LLD_ConfigureInternalClock(oC_Frequency_t TargetFrequency, oC_Frequency_t PermissibleDifference)
configures system clock in internal mode
Definition: oc_clock_lld.c:312
bool oC_MEM_LLD_IsFlashAddress(const void *Address)
checks if the pointer is in flash section
Definition: oc_mem_lld.c:433
an external source of the clock is used
Definition: oc_clock_lld.h:76
The file with LLD interface for the MEM driver.
#define oC_Machine_DefaultFrequency
returns default frequency of the machine clock
an internal clock source is used
Definition: oc_clock_lld.h:75
void oC_MCS_Delay(register oC_UInt_t Cycles)
delays operations for cycles
Definition: oc_mcs.c:679
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
oC_ErrorCode_t oC_CLOCK_LLD_TurnOnDriver(void)
initializes the driver to work
Definition: oc_clock_lld.c:160
The file with LLD interface for the CLOCK driver.
#define oC_ABS(A, B)
Definition: oc_math.h:46
oC_ErrorCode_t oC_CLOCK_LLD_ConfigureExternalClock(oC_Frequency_t TargetFrequency, oC_Frequency_t PermissibleDifference, oC_Frequency_t OscillatorFrequency)
configures system clock to work in external mode
Definition: oc_clock_lld.c:405
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
Contains machine core specific functions.
#define oC_MACHINE_HIBERNATION_OSCILLATOR_FREQUENCY
#define oC_MACHINE_PRECISION_INTERNAL_OSCILLATOR_FREQUENCY
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
Definition: oc_mcs.h:755
oC_ErrorCode_t oC_CLOCK_LLD_ConfigureHibernationClock(oC_Frequency_t TargetFrequency, oC_Frequency_t PermissibleDifference, oC_Frequency_t OscillatorFrequency)
configures system clock to work in hibernation mode
Definition: oc_clock_lld.c:510
The file with interface interrupt module.
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
void(* oC_CLOCK_LLD_Interrupt_t)(oC_Frequency_t Frequency)
type for storing interrupts pointers
Definition: oc_clock_lld.h:88
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_RegisterType_(REGISTER_NAME)
Returns name of type for storing register value.
Definition: oc_registers.h:73
The file with LLD interface for the SYS driver.
bool oC_CLOCK_LLD_DelayForMicroseconds(oC_UInt_t Microseconds)
perform a delay for us
Definition: oc_clock_lld.c:297
#define oC_MACHINE_INTERNAL_OSCILLATOR_FREQUENCY
bool oC_MEM_LLD_IsRamAddress(const void *Address)
checks if the pointer is in ram section
Definition: oc_mem_lld.c:400
#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