-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOs_TimerInt.h
More file actions
1225 lines (1079 loc) · 53 KB
/
Copy pathOs_TimerInt.h
File metadata and controls
1225 lines (1079 loc) · 53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************************************************
* COPYRIGHT
* --------------------------------------------------------------------------------------------------------------------
* \verbatim
* Copyright (c) 2017 by Vector Informatik GmbH. All rights reserved.
*
* This software is copyright protected and proprietary to Vector Informatik GmbH.
* Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
* All other rights remain with Vector Informatik GmbH.
* \endverbatim
* --------------------------------------------------------------------------------------------------------------------
* FILE DESCRIPTION
* ------------------------------------------------------------------------------------------------------------------*/
/**
* \ingroup Os_Kernel
* \defgroup Os_Timer Timer
* \brief High level timer hardware handling.
* \details
* This module provides abstraction from the functionality of different timer types:
* - Software timer (SW counter)
* - Periodic interval timer
* - High Resolution Timer / Free running timer
*
* Timer ISR
* ---------
* The OS provided timer ISR is implemented by using a category 2 ISR.
*
* 
*
* 
*
* 
*
*
* \{
*
* \file
* \brief Interface to high level timer hardware handling.
* \details --no details--
*
*
**********************************************************************************************************************/
/***********************************************************************************************************************
* REVISION HISTORY
* --------------------------------------------------------------------------------------------------------------------
* Refer to Os.h.
**********************************************************************************************************************/
#if !defined(OS_TIMERINT_H) /* PRQA S 0883 */ /* MD_Os_0883 */
# define OS_TIMERINT_H
/***********************************************************************************************************************
* INCLUDES
**********************************************************************************************************************/
/* AUTOSAR includes */
# include "Std_Types.h"
/* Os module declarations */
# include "Os_Timer_Types.h"
/* Os kernel module dependencies */
# include "Os_Counter_Types.h"
# include "Os_CounterInt.h"
# include "Os_Common_Types.h"
# include "Os_IsrInt.h"
/* Os HAL dependencies */
# include "Os_Hal_TimerInt.h"
#if !defined(OS_VCAST_INSTRUMENTATION_OS_TIMER)
/*VCAST_DONT_INSTRUMENT_START*/
#endif
/***********************************************************************************************************************
* GLOBAL CONSTANT MACROS
**********************************************************************************************************************/
/***********************************************************************************************************************
* GLOBAL FUNCTION MACROS
**********************************************************************************************************************/
/*! \def OS_TIMERSW_GETMAXCOUNTINGVALUE()
* \brief This macro is used to calculate the maximum counting value for a software counter.
* \details This value is needed for modulo calculation.
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERSW_GETMAXCOUNTINGVALUE(MaxAllowedValue) \
((((Os_TickType)(MaxAllowedValue))*2)+1) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPIT_GETMAXCOUNTINGVALUE()
* \brief This macro is used to calculate the maximum counting value for a PIT.
* \details This value is needed for modulo calculation.
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPIT_GETMAXCOUNTINGVALUE(MaxAllowedValue) \
OS_TIMERSW_GETMAXCOUNTINGVALUE((MaxAllowedValue)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERHRT_GETMAXCOUNTINGVALUE()
* \brief This macro is used to calculate the maximum counting value for a HRT.
* \details This value is needed for modulo calculation.
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERHRT_GETMAXCOUNTINGVALUE(MaxAllowedValue) \
((((Os_TickType)(MaxAllowedValue))*4)+3) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPFRT_GETMAXCOUNTINGVALUE()
* \brief This macro is used to calculate the maximum counting value for a PFRT (software part).
* \details This value is needed for modulo calculation.
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPFRT_GETMAXCOUNTINGVALUE(MaxAllowedValue) \
OS_TIMERSW_GETMAXCOUNTINGVALUE((MaxAllowedValue)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPFRT_HARDWAREGETMAXCOUNTINGVALUE()
* \brief This macro is used to calculate the maximum counting value for a PFRT (hardware part).
* \details This value is needed for modulo calculation.
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPFRT_HARDWAREGETMAXCOUNTINGVALUE(MaxAllowedValue) \
OS_TIMERHRT_GETMAXCOUNTINGVALUE((MaxAllowedValue)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERSW_GETMAXDIFFERENTIALVALUE()
* \brief This macro is used to calculate the maximum differential value between two software timer values.
* \details --no details--
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERSW_GETMAXDIFFERENTIALVALUE(MaxAllowedValue) \
((Os_TickType)(MaxAllowedValue)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPIT_GETMAXDIFFERENTIALVALUE()
* \brief This macro is used to calculate the maximum differential value between two PIT values.
* \details --no details--
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPIT_GETMAXDIFFERENTIALVALUE(MaxAllowedValue) \
(OS_TIMERSW_GETMAXDIFFERENTIALVALUE((MaxAllowedValue))) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERHRT_GETMAXDIFFERENTIALVALUE()
* \brief This macro is used to calculate the maximum differential value between two HRT values.
* \details --no details--
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERHRT_GETMAXDIFFERENTIALVALUE(MaxAllowedValue) \
((((Os_TickType)(MaxAllowedValue))*2)+1) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPFRT_GETMAXDIFFERENTIALVALUE()
* \brief This macro is used to calculate the maximum differential value between two PFRT values.
* \details --no details--
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPFRT_GETMAXDIFFERENTIALVALUE(MaxAllowedValue) \
(OS_TIMERSW_GETMAXDIFFERENTIALVALUE((MaxAllowedValue))) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! \def OS_TIMERPFRT_HARDWAREGETMAXDIFFERENTIALVALUE()
* \brief This macro is used to calculate the maximum differential value between two PFRT values (hardware part).
* \details --no details--
*
* \param[in] MaxAllowedValue Max allowed value of the counter.
*/
# define OS_TIMERPFRT_HARDWAREGETMAXDIFFERENTIALVALUE(MaxAllowedValue) \
(OS_TIMERHRT_GETMAXDIFFERENTIALVALUE((MaxAllowedValue))) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! Type cast from Os_TimerIsrConfigType to Os_IsrConfigType by use of base element addressing. */
#define OS_TIMER_CASTCONFIG_TIMERISR_2_ISR(Timer) (&((Timer).Isr)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/*! Type cast from Os_IsrType to Os_ThreadType by use of base element addressing. */
#define OS_ISR_CASTDYN_TIMERSW_2_TIMERPFRT(Timer) (&((Timer).Base)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
/***********************************************************************************************************************
* GLOBAL DATA TYPES AND STRUCTURES
**********************************************************************************************************************/
/*! Dynamic information of a software counter. */
typedef struct
{
/*! The current counter value of the software counter. */
Os_TickType Value;
/*! The next time stamp where Os_CounterWorkJobs() has to be called. */
Os_TickType Compare;
} Os_TimerSwType;
/*! Timer configuration for software counters.
* \extends Os_CounterConfigType_Tag
*/
struct Os_TimerSwConfigType_Tag
{
/*! General counter.
* This attribute must come first! */
Os_CounterConfigType Counter;
/*! Dynamic part of the software counter. */
P2VAR(Os_TimerSwType, TYPEDEF, OS_VAR_NOINIT) Dyn;
};
/*! Configuration information of a PIT driven hardware counter.
* \extends Os_TimerSwConfigType_Tag
*/
struct Os_TimerPitConfigType_Tag
{
/*! Software counter.
* This attribute must come first! */
Os_TimerSwConfigType SwCounter;
/*! Hardware specific information of the PIT. */
P2CONST(Os_Hal_TimerPitConfigType, TYPEDEF, OS_CONST) HwConfig;
};
/*! Dynamic information of a (range extended) HRT driven hardware counter. */
typedef struct
{
/*! A snapshot of the range extended counter value.
* The current value is calculated each time in Os_TimerHrtGetValue(). */
Os_TickType Value;
/*! The next time stamp where Os_CounterWorkJobs() has to be called. */
Os_TickType Compare;
/*! Time value mask. Set to 0 on timer initialization, set to MaxCountingValue on timer start.
* Used to keep the Value field at zero until the timer is started by Os_TimerHrtStart() */
Os_TickType ValueMask;
/*! Time stamp of the last hardware counter read. */
Os_Hal_TimerFrtTickType LastCounterValue;
/*! \brief The deviation between TickType values and FrtTickType values.
* \details This value has to be added when converting a TickType value into a FRT TickType value. */
Os_Hal_TimerFrtTickType HwTimeAtLogicalZero;
} Os_TimerHrtType;
/*! Timer configuration of a (software extended) HRT driven hardware counter.
* \extends Os_CounterConfigType_Tag
*/
struct Os_TimerHrtConfigType_Tag
{
/*! General counter.
* This attribute must come first! */
Os_CounterConfigType Counter;
/*! Dynamic information. */
P2VAR(Os_TimerHrtType, TYPEDEF, OS_VAR_NOINIT) Dyn;
/*! Hardware specific information of the FRT. */
P2CONST(Os_Hal_TimerFrtConfigType, TYPEDEF, OS_CONST) HwConfig;
};
/*! Dynamic information of a PFRT driven hardware counter. */
typedef struct
{
/*! Dynanmic data of the base class.
* This attribute must come first! */
Os_TimerSwType Base;
/*! Helds a copy of the compare value stored in hardware. */
Os_TickType Compare;
} Os_TimerPfrtType;
/*! Configuration information of a PFRT driven hardware counter.
* \extends Os_TimerSwConfigType_Tag
*/
struct Os_TimerPfrtConfigType_Tag
{
/*! Software counter.
* This attribute must come first! */
Os_TimerSwConfigType SwCounter;
/*! The period of the PFRT in ticks. */
Os_TickType Period;
/*! The maximum allowed difference between to related tick times. */
Os_TickType MaxDifferentialValue;
/*! Specifies the highest counter value which occurs in hardware. */
Os_TickType MaxCountingValue;
/*! Hardware specific information of the FRT. */
P2CONST(Os_Hal_TimerFrtConfigType, TYPEDEF, OS_CONST) HwConfig;
};
/*! Configuration information of a timer ISR.
* \extends Os_IsrConfigType_Tag */
struct Os_TimerIsrConfigType_Tag
{
/*! The timer ISR which is responsible for the counter. */
Os_IsrConfigType Isr;
/*! The hardware counter, which triggers the timer ISR. */
P2CONST(Os_CounterConfigType, TYPEDEF, OS_CONST) Counter;
};
/***********************************************************************************************************************
* GLOBAL DATA PROTOTYPES
**********************************************************************************************************************/
/***********************************************************************************************************************
* GLOBAL FUNCTION PROTOTYPES
**********************************************************************************************************************/
# define OS_START_SEC_CODE
# include "Os_MemMap_OsCode.h" /* PRQA S 5087 */ /* MD_MSR_19.1 */
/***********************************************************************************************************************
* Os_TimerSwInit()
**********************************************************************************************************************/
/*! \brief Initializes a software timer.
* \details Initialize counter value to zero.
*
* \param[in,out] Timer The timer to initialize. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerSwInit,
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerPitInit()
**********************************************************************************************************************/
/*! \brief Initializes a PIT driven counter.
* \details Initialize software counter value and PIT hardware.
*
* \param[in,out] Timer The timer to initialize. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPitInit,
(
P2CONST(Os_TimerPitConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerHrtInit()
**********************************************************************************************************************/
/*! \brief Initializes HRT driven counter.
* \details Initialize HRT hardware and the software part for range extension.
*
* \param[in,out] Timer The timer to initialize. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtInit,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerPfrtInit()
**********************************************************************************************************************/
/*! \brief Initializes periodic free running timer.
* \details Initialize FRT hardware and the related software timer.
*
* \param[in,out] Timer The timer to initialize. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPfrtInit,
(
P2CONST(Os_TimerPfrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerSwStart()
**********************************************************************************************************************/
/*! \brief Starts a software timer.
* \details There is nothing to be done for starting a software timer. Therefore, no preconditions.
*
* \param[in,out] Timer The timer to initialize.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerSwStart,
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerPitStart()
**********************************************************************************************************************/
/*! \brief Starts a PIT driven counter.
* \details Initialize the PIT hardware.
*
* \param[in,out] Timer The timer to start. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
*
* \trace SPEC-64005
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPitStart,
(
P2CONST(Os_TimerPitConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerHrtStart()
**********************************************************************************************************************/
/*! \brief Starts a HRT driven counter.
* \details Initialize HRT hardware.
*
* \param[in,out] Timer The timer to start. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
*
* \trace SPEC-64005
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtStart,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerSwGetValue()
**********************************************************************************************************************/
/*! \brief Returns the current counter value of a software timer.
* \details
*
* \param[in,out] Timer The timer to query. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given timer shall be prevented, if processor word width is smaller than
* with of Os_TickType.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerSwGetValue,
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerSwSetCompareValue()
**********************************************************************************************************************/
/*! \brief Sets the compare value variable of a software timer.
* \details --no details--
*
* \param[in,out] Timer The timer to modify. Parameter must not be NULL.
* \param[in] ExpirationTime The time stamp, which defines when the timer shall call Os_CounterWorkJobs().
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(
OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE, Os_TimerSwSetCompareValue,
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType ExpirationTime
));
/***********************************************************************************************************************
* Os_TimerSwUserModulo()
**********************************************************************************************************************/
/*! \brief Performs Value = Value mod MaxAllowedValue.
* \details Because the modulo operator (%) is assumed to be inefficient, an optimized modulo function is used,
* which has the assumption on the parameter Value as defined in the precondition. The optimization
* is to simply subtract MaxAllowedValue+1 in case the value is bigger than MaxAllowedValue.
*
* 
*
* \param[in] Timer The timer to query. Parameter must not be NULL.
* \param[in] Value The value to be limited.
*
* \return The limited value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre Value has to be in range 0 <= Value <= MaxCountingValue.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE, Os_TimerSwUserModulo,
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType Value
));
/***********************************************************************************************************************
* Os_TimerSwIncrement()
**********************************************************************************************************************/
/*! \brief Increment a given software timer.
* \details --no details--
*
* \param[in,out] Timer The timer to be incremented. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
* \pre Timer belongs to the local core.
**********************************************************************************************************************/
FUNC(void, OS_CODE) Os_TimerSwIncrement
(
P2CONST(Os_TimerSwConfigType, AUTOMATIC, OS_CONST) Timer
);
/***********************************************************************************************************************
* Os_TimerPfrtStart()
**********************************************************************************************************************/
/*! \brief Starts a PFRT driven counter.
* \details Initialize the underlying FRT hardware.
*
* \param[in,out] Timer The timer to start. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
*
* \trace SPEC-64005
**********************************************************************************************************************/
FUNC(void, OS_CODE) Os_TimerPfrtStart
(
P2CONST(Os_TimerPfrtConfigType, AUTOMATIC, OS_CONST) Timer
);
/***********************************************************************************************************************
* Os_TimerPitGetValue()
**********************************************************************************************************************/
/*! \brief Returns the current counter value of a PIT driven counter.
* \details --no details--
*
* \param[in,out] Timer The timer to query. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given timer shall be prevented, if processor word width is smaller than
* with of Os_TickType.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPitGetValue,
(
P2CONST(Os_TimerPitConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerPitSetCompareValue()
**********************************************************************************************************************/
/*! \brief Sets the compare value variable of a PIT driven counter.
* \details --no details--
*
* \param[in,out] Timer The timer to modify. Parameter must not be NULL.
* \param[in] ExpirationTime The time stamp, which defines when the timer shall call Os_CounterWorkJobs().
*
* \retval !0 ExpirationTime is in the past or now.
* \retval 0 ExpirationTime is in the future.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPitSetCompareValue,
(
P2CONST(Os_TimerPitConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType ExpirationTime
));
/***********************************************************************************************************************
* Os_TimerPitUserModulo()
**********************************************************************************************************************/
/*! \brief Performs Value = Value mod MaxAllowedValue.
* \details Modulo function for periodic interrupt timer.
*
* \param[in] Timer The counter to query. Parameter must not be NULL.
* \param[in] Value The value to be limited.
* Value has to be in range -MaxAllowedValue <= Value <= MaxCountingValue.
*
* \return The limited value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPitUserModulo,
(
P2CONST(Os_TimerPitConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType Value
));
/***********************************************************************************************************************
* Os_TimerPfrtUserModulo()
**********************************************************************************************************************/
/*! \brief Performs Value = Value mod MaxAllowedValue.
* \details Modulo function for periodic free running timer.
*
* \param[in] Timer The counter to query. Parameter must not be NULL.
* \param[in] Value The value to be limited.
* Value has to be in range -MaxAllowedValue <= Value <= MaxCountingValue.
*
* \return The limited value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPfrtUserModulo,
(
P2CONST(Os_TimerPfrtConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType Value
));
/***********************************************************************************************************************
* Os_TimerHrtGetValue()
**********************************************************************************************************************/
/*! \brief Returns the current value of a high resolution timer driven counter.
* \details --no details--
*
* \param[in,out] Timer The timer to query. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
* \pre The ValueMask of the given counter is zero or the maximum possible value in TickType
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtGetValue,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerPfrtGetValue()
**********************************************************************************************************************/
/*! \brief Returns the current value of a periodic free running timer driven counter.
* \details This function returns the value of the software timer.
*
* \param[in,out] Timer The timer to query. Parameter must not be NULL.
*
* \return The software counter value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
* \pre The ValueMask of the given counter is zero or the maximum possible value in TickType
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPfrtGetValue,
(
P2CONST(Os_TimerPfrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerHrtGetCounter()
**********************************************************************************************************************/
/*! \brief Returns the counter of the given timer.
* \details --no details--
*
* \param[in,out] Timer The timer to query. Parameter must not be NULL.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE P2CONST(Os_CounterConfigType, AUTOMATIC, OS_CONST), OS_CODE,
OS_ALWAYS_INLINE, Os_TimerHrtGetCounter,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerHrtTickType2FrtTickType()
**********************************************************************************************************************/
/*! \brief Converts the given TickType into a FrtTickType.
* \details --no details--
*
* \param[in] Timer The timer to query. Parameter must not be NULL.
* \param[in] Value The TickType into a FrtTickType value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_Hal_TimerFrtTickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtTickType2FrtTickType,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer,
TickType Value
));
/***********************************************************************************************************************
* Os_TimerHrtSetCompareValue()
**********************************************************************************************************************/
/*! \brief Sets the compare value of a HRT driven counter.
* \details If the ExpirationTime is the past or now, a peripheral interrupt has to be triggered: in the
* case the platform does not support this feature following algorithm is used to set compare value:
*
* 1- Read the current timestamp (timeBeforeSetCompare)
* 2- Set the compare value to timeBeforeSetCompare + delta + iterationId
* 3- Read again the timestamp (timeAfterSetCompare)
* 4- Update delta with the timestamps difference and increment iterationId
* 5- Loop until the compare value is in the future or now with respect to timeAfterSetCompare
*
* \param[in,out] Timer The timer to modify. Parameter must not be NULL.
* \param[in] ExpirationTime The time stamp, where the next interrupt shall occur.
* ExpirationTime-Now is in range -MaxAllowedValue to +MaxAllowedValue.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtSetCompareValue,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType ExpirationTime
));
/***********************************************************************************************************************
* Os_TimerPfrtSetCompareValue()
**********************************************************************************************************************/
/*! \brief Sets the compare value of a Periodic FRT driven counter.
* \details This function modifies the software timer of the PFRT.
*
* \param[in,out] Timer The timer to modify. Parameter must not be NULL.
* \param[in] ExpirationTime The time stamp, where the next interrupt shall occur.
* ExpirationTime-Now is in range -MaxAllowedValue to +MaxAllowedValue.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerPfrtSetCompareValue,
(
P2CONST(Os_TimerPfrtConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType ExpirationTime
));
/***********************************************************************************************************************
* Os_TimerHrtGetCompareValue()
**********************************************************************************************************************/
/*! \brief Get the compare value of a HRT driven counter.
* \details --no details--
*
* \param[in,out] Timer The timer to modify. Parameter must not be NULL.
*
* \return The next expiration time.
*
* \context OS_INTERNAL
*
* \reentrant TRUE for different timers.
* \synchronous TRUE
*
* \pre Concurrent access to given object is prevented by caller.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtGetCompareValue,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerHrtUserModulo()
**********************************************************************************************************************/
/*! \brief Performs Value = Value mod MaxAllowedValue.
* \details Cut off bits which are beyond MaxAllowedValue.
*
* 
*
* \param[in] Timer The timer to query. Parameter must not be NULL.
* \param[in] Value The value to be limited.
*
* \return The limited value.
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre MaxAllowedValue is 2^(n)-1.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerHrtUserModulo,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer,
Os_TickType Value
));
/***********************************************************************************************************************
* Os_TimerHrtAcknowledge()
**********************************************************************************************************************/
/*! \brief Acknowledges a HRT timer interrupt.
* \details --no details--
*
* \param[in] Timer The timer to acknowledge. Parameter must not be NULL
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre -
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE void, OS_CODE, OS_ALWAYS_INLINE, /* PRQA S 3219 */ /* MD_Os_3219 */
Os_TimerHrtAcknowledge,
(
P2CONST(Os_TimerHrtConfigType, AUTOMATIC, OS_CONST) Timer
));
/***********************************************************************************************************************
* Os_TimerSwAbsCounter2AbsTimerValue()
**********************************************************************************************************************/
/*! \brief Converts an absolute counter time stamp into an absolute SW timer time stamp.
* \details As there are two counter cycles within one SW Timer cycle, the counter value may be mapped to
* two different timer values:
*
* timerValue = CounterValue + n*(MaxAllowedValue+1) with n={0,1}
*
* Cycle | Value range
* ------------------|-----------------
* First cycle | 0 .. MaxAllowedValue
* Second cycle | MaxAllowedValue+1 .. 2*MaxAllowedValue+1
*
* As a consequence of #40 and #60, the expiry time will be reached up to MaxAllowedValue+1 ticks
* ahead of Now. So this function must not be called while still jobs for Now are in the job queue!
*
* \param[in] MaxAllowedValue The maximum value allowed value for CounterValue.
* \param[in] Now The current timer value. Now must be lower than or equal to MaxCountingValue.
* \param[in] CounterValue The counter value which shall be converted. CounterValue must be in
* range 0..MaxAllowedValue of the respective counter configuration.
*
* \return The absolute software timer value in range 0 <= Result <= MaxCountingValue
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*
* \pre All jobs which have to expire Now have already been removed from the job queue.
**********************************************************************************************************************/
OS_FUNC_ATTRIBUTE_DECLARATION(OS_LOCAL_INLINE Os_TickType, OS_CODE, OS_ALWAYS_INLINE,
Os_TimerSwAbsCounter2AbsTimerValue,
(
Os_TickType MaxAllowedValue,
Os_TickType Now,
Os_TickType CounterValue
));
/***********************************************************************************************************************
* Os_TimerPitAbsCounter2AbsTimerValue()
**********************************************************************************************************************/
/*! \brief Converts an absolute counter time stamp into an absolute PIT timer time stamp.
* \details Bypass conversion to Os_TimerSwAbsCounter2AbsTimerValue().
*
* \param[in] MaxAllowedValue The maximum value allowed value for CounterValue.
* \param[in] Now The current timer value. Now must be lower than or equal to MaxCountingValue.
* \param[in] CounterValue The counter value which shall be converted. CounterValue must be in
* range 0..MaxAllowedValue of the respective counter configuration.
*
* \return The absolute PIT value in range 0 <= Result <= MaxCountingValue
*
* \context OS_INTERNAL
*
* \reentrant TRUE
* \synchronous TRUE
*