2020-2021 Sunseeker Telemetry and Lighting System
timer_b.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // timer_b.h - Driver for the TIMER_B Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_TIMER_B_H__
8 #define __MSP430WARE_TIMER_B_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_TxB7__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "inc/hw_memmap.h"
26 //*****************************************************************************
27 //
28 // The following is a parameter used for Timer_B_getCounterValue that
29 // determines the maximum difference in counts of the TAxR register for a
30 // majority vote.
31 //
32 //*****************************************************************************
33 #define TIMER_B_THRESHOLD 50
34 
35 //*****************************************************************************
36 //
38 //
39 //*****************************************************************************
40 typedef struct Timer_B_outputPWMParam {
47  uint16_t clockSource;
70  uint16_t clockSourceDivider;
72  uint16_t timerPeriod;
83  uint16_t compareRegister;
94  uint16_t compareOutputMode;
96  uint16_t dutyCycle;
97 } Timer_B_outputPWMParam;
98 
99 //*****************************************************************************
100 //
102 //
103 //*****************************************************************************
104 typedef struct Timer_B_initUpModeParam {
111  uint16_t clockSource;
134  uint16_t clockSourceDivider;
137  uint16_t timerPeriod;
142  uint16_t timerInterruptEnable_TBIE;
147  uint16_t captureCompareInterruptEnable_CCR0_CCIE;
153  uint16_t timerClear;
155  bool startTimer;
156 } Timer_B_initUpModeParam;
157 
158 //*****************************************************************************
159 //
162 //
163 //*****************************************************************************
164 typedef struct Timer_B_initCaptureModeParam {
175  uint16_t captureRegister;
182  uint16_t captureMode;
189  uint16_t captureInputSelect;
194  uint16_t synchronizeCaptureSource;
199  uint16_t captureInterruptEnable;
210  uint16_t captureOutputMode;
211 } Timer_B_initCaptureModeParam;
212 
213 //*****************************************************************************
214 //
217 //
218 //*****************************************************************************
219 typedef struct Timer_B_initContinuousModeParam {
226  uint16_t clockSource;
249  uint16_t clockSourceDivider;
254  uint16_t timerInterruptEnable_TBIE;
260  uint16_t timerClear;
262  bool startTimer;
263 } Timer_B_initContinuousModeParam;
264 
265 //*****************************************************************************
266 //
269 //
270 //*****************************************************************************
271 typedef struct Timer_B_initUpDownModeParam {
278  uint16_t clockSource;
301  uint16_t clockSourceDivider;
303  uint16_t timerPeriod;
308  uint16_t timerInterruptEnable_TBIE;
313  uint16_t captureCompareInterruptEnable_CCR0_CCIE;
319  uint16_t timerClear;
321  bool startTimer;
322 } Timer_B_initUpDownModeParam;
323 
324 //*****************************************************************************
325 //
328 //
329 //*****************************************************************************
330 typedef struct Timer_B_initCompareModeParam {
341  uint16_t compareRegister;
346  uint16_t compareInterruptEnable;
357  uint16_t compareOutputMode;
359  uint16_t compareValue;
360 } Timer_B_initCompareModeParam;
361 
362 
363 //*****************************************************************************
364 //
365 // The following are values that can be passed to the param parameter for
366 // functions: Timer_B_initContinuousMode(), Timer_B_initUpMode(),
367 // Timer_B_initUpDownMode(), and Timer_B_outputPWM().
368 //
369 //*****************************************************************************
370 #define TIMER_B_CLOCKSOURCE_DIVIDER_1 0x00
371 #define TIMER_B_CLOCKSOURCE_DIVIDER_2 0x08
372 #define TIMER_B_CLOCKSOURCE_DIVIDER_3 0x02
373 #define TIMER_B_CLOCKSOURCE_DIVIDER_4 0x10
374 #define TIMER_B_CLOCKSOURCE_DIVIDER_5 0x04
375 #define TIMER_B_CLOCKSOURCE_DIVIDER_6 0x05
376 #define TIMER_B_CLOCKSOURCE_DIVIDER_7 0x06
377 #define TIMER_B_CLOCKSOURCE_DIVIDER_8 0x18
378 #define TIMER_B_CLOCKSOURCE_DIVIDER_10 0x0C
379 #define TIMER_B_CLOCKSOURCE_DIVIDER_12 0x0D
380 #define TIMER_B_CLOCKSOURCE_DIVIDER_14 0x0E
381 #define TIMER_B_CLOCKSOURCE_DIVIDER_16 0x0F
382 #define TIMER_B_CLOCKSOURCE_DIVIDER_20 0x14
383 #define TIMER_B_CLOCKSOURCE_DIVIDER_24 0x15
384 #define TIMER_B_CLOCKSOURCE_DIVIDER_28 0x16
385 #define TIMER_B_CLOCKSOURCE_DIVIDER_32 0x17
386 #define TIMER_B_CLOCKSOURCE_DIVIDER_40 0x1C
387 #define TIMER_B_CLOCKSOURCE_DIVIDER_48 0x1D
388 #define TIMER_B_CLOCKSOURCE_DIVIDER_56 0x1E
389 #define TIMER_B_CLOCKSOURCE_DIVIDER_64 0x1F
390 
391 //*****************************************************************************
392 //
393 // The following are values that can be passed to the timerMode parameter for
394 // functions: Timer_B_startCounter().
395 //
396 //*****************************************************************************
397 #define TIMER_B_STOP_MODE MC_0
398 #define TIMER_B_UP_MODE MC_1
399 #define TIMER_B_CONTINUOUS_MODE MC_2
400 #define TIMER_B_UPDOWN_MODE MC_3
401 
402 //*****************************************************************************
403 //
404 // The following are values that can be passed to the param parameter for
405 // functions: Timer_B_initContinuousMode(), Timer_B_initUpMode(), and
406 // Timer_B_initUpDownMode().
407 //
408 //*****************************************************************************
409 #define TIMER_B_DO_CLEAR TBCLR
410 #define TIMER_B_SKIP_CLEAR 0x00
411 
412 //*****************************************************************************
413 //
414 // The following are values that can be passed to the param parameter for
415 // functions: Timer_B_initContinuousMode(), Timer_B_initUpMode(),
416 // Timer_B_initUpDownMode(), and Timer_B_outputPWM().
417 //
418 //*****************************************************************************
419 #define TIMER_B_CLOCKSOURCE_EXTERNAL_TXCLK TBSSEL__TACLK
420 #define TIMER_B_CLOCKSOURCE_ACLK TBSSEL__ACLK
421 #define TIMER_B_CLOCKSOURCE_SMCLK TBSSEL__SMCLK
422 #define TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK TBSSEL__INCLK
423 
424 //*****************************************************************************
425 //
426 // The following are values that can be passed to the param parameter for
427 // functions: Timer_B_initContinuousMode(), Timer_B_initUpMode(), and
428 // Timer_B_initUpDownMode().
429 //
430 //*****************************************************************************
431 #define TIMER_B_TBIE_INTERRUPT_ENABLE TBIE
432 #define TIMER_B_TBIE_INTERRUPT_DISABLE 0x00
433 
434 //*****************************************************************************
435 //
436 // The following are values that can be passed to the param parameter for
437 // functions: Timer_B_initUpMode(), and Timer_B_initUpDownMode().
438 //
439 //*****************************************************************************
440 #define TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE CCIE
441 #define TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE 0x00
442 
443 //*****************************************************************************
444 //
445 // The following are values that can be passed to the param parameter for
446 // functions: Timer_B_initCaptureMode(), and Timer_B_initCompareMode().
447 //
448 //*****************************************************************************
449 #define TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE 0x00
450 #define TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLE CCIE
451 
452 //*****************************************************************************
453 //
454 // The following are values that can be passed to the param parameter for
455 // functions: Timer_B_initCaptureMode().
456 //
457 //*****************************************************************************
458 #define TIMER_B_CAPTURE_INPUTSELECT_CCIxA CCIS_0
459 #define TIMER_B_CAPTURE_INPUTSELECT_CCIxB CCIS_1
460 #define TIMER_B_CAPTURE_INPUTSELECT_GND CCIS_2
461 #define TIMER_B_CAPTURE_INPUTSELECT_Vcc CCIS_3
462 
463 //*****************************************************************************
464 //
465 // The following are values that can be passed to the compareOutputMode
466 // parameter for functions: Timer_B_setOutputMode(); the param parameter for
467 // functions: Timer_B_initCaptureMode(), Timer_B_initCompareMode(), and
468 // Timer_B_outputPWM().
469 //
470 //*****************************************************************************
471 #define TIMER_B_OUTPUTMODE_OUTBITVALUE OUTMOD_0
472 #define TIMER_B_OUTPUTMODE_SET OUTMOD_1
473 #define TIMER_B_OUTPUTMODE_TOGGLE_RESET OUTMOD_2
474 #define TIMER_B_OUTPUTMODE_SET_RESET OUTMOD_3
475 #define TIMER_B_OUTPUTMODE_TOGGLE OUTMOD_4
476 #define TIMER_B_OUTPUTMODE_RESET OUTMOD_5
477 #define TIMER_B_OUTPUTMODE_TOGGLE_SET OUTMOD_6
478 #define TIMER_B_OUTPUTMODE_RESET_SET OUTMOD_7
479 
480 //*****************************************************************************
481 //
482 // The following are values that can be passed to the compareRegister parameter
483 // for functions: Timer_B_setCompareValue(),
484 // Timer_B_initCompareLatchLoadEvent(), and Timer_B_setOutputMode(); the
485 // captureCompareRegister parameter for functions:
486 // Timer_B_enableCaptureCompareInterrupt(),
487 // Timer_B_disableCaptureCompareInterrupt(),
488 // Timer_B_getCaptureCompareInterruptStatus(),
489 // Timer_B_getSynchronizedCaptureCompareInput(),
490 // Timer_B_getOutputForOutputModeOutBitValue(),
491 // Timer_B_getCaptureCompareCount(),
492 // Timer_B_setOutputForOutputModeOutBitValue(), and
493 // Timer_B_clearCaptureCompareInterrupt(); the param parameter for functions:
494 // Timer_B_initCaptureMode(), Timer_B_initCompareMode(), and
495 // Timer_B_outputPWM().
496 //
497 //*****************************************************************************
498 #define TIMER_B_CAPTURECOMPARE_REGISTER_0 0x02
499 #define TIMER_B_CAPTURECOMPARE_REGISTER_1 0x04
500 #define TIMER_B_CAPTURECOMPARE_REGISTER_2 0x06
501 #define TIMER_B_CAPTURECOMPARE_REGISTER_3 0x08
502 #define TIMER_B_CAPTURECOMPARE_REGISTER_4 0x0A
503 #define TIMER_B_CAPTURECOMPARE_REGISTER_5 0x0C
504 #define TIMER_B_CAPTURECOMPARE_REGISTER_6 0x0E
505 
506 //*****************************************************************************
507 //
508 // The following are values that can be passed to the param parameter for
509 // functions: Timer_B_initCaptureMode().
510 //
511 //*****************************************************************************
512 #define TIMER_B_CAPTUREMODE_NO_CAPTURE CM_0
513 #define TIMER_B_CAPTUREMODE_RISING_EDGE CM_1
514 #define TIMER_B_CAPTUREMODE_FALLING_EDGE CM_2
515 #define TIMER_B_CAPTUREMODE_RISING_AND_FALLING_EDGE CM_3
516 
517 //*****************************************************************************
518 //
519 // The following are values that can be passed to the param parameter for
520 // functions: Timer_B_initCaptureMode().
521 //
522 //*****************************************************************************
523 #define TIMER_B_CAPTURE_ASYNCHRONOUS 0x00
524 #define TIMER_B_CAPTURE_SYNCHRONOUS SCS
525 
526 //*****************************************************************************
527 //
528 // The following are values that can be passed to the mask parameter for
529 // functions: Timer_B_getCaptureCompareInterruptStatus() as well as returned by
530 // the Timer_B_getCaptureCompareInterruptStatus() function.
531 //
532 //*****************************************************************************
533 #define TIMER_B_CAPTURE_OVERFLOW COV
534 #define TIMER_B_CAPTURECOMPARE_INTERRUPT_FLAG CCIFG
535 
536 //*****************************************************************************
537 //
538 // The following are values that can be passed to the synchronized parameter
539 // for functions: Timer_B_getSynchronizedCaptureCompareInput().
540 //
541 //*****************************************************************************
542 #define TIMER_B_READ_SYNCHRONIZED_CAPTURECOMPAREINPUT SCCI
543 #define TIMER_B_READ_CAPTURE_COMPARE_INPUT CCI
544 
545 //*****************************************************************************
546 //
547 // The following are values that can be passed toThe following are values that
548 // can be returned by the Timer_B_getSynchronizedCaptureCompareInput()
549 // function.
550 //
551 //*****************************************************************************
552 #define TIMER_B_CAPTURECOMPARE_INPUT_HIGH 0x01
553 #define TIMER_B_CAPTURECOMPARE_INPUT_LOW 0x00
554 
555 //*****************************************************************************
556 //
557 // The following are values that can be passed to the outputModeOutBitValue
558 // parameter for functions: Timer_B_setOutputForOutputModeOutBitValue() as well
559 // as returned by the Timer_B_getOutputForOutputModeOutBitValue() function.
560 //
561 //*****************************************************************************
562 #define TIMER_B_OUTPUTMODE_OUTBITVALUE_HIGH OUT
563 #define TIMER_B_OUTPUTMODE_OUTBITVALUE_LOW 0x0000
564 
565 //*****************************************************************************
566 //
567 // The following are values that can be passed to the counterLength parameter
568 // for functions: Timer_B_selectCounterLength().
569 //
570 //*****************************************************************************
571 #define TIMER_B_COUNTER_16BIT CNTL_0
572 #define TIMER_B_COUNTER_12BIT CNTL_1
573 #define TIMER_B_COUNTER_10BIT CNTL_2
574 #define TIMER_B_COUNTER_8BIT CNTL_3
575 
576 //*****************************************************************************
577 //
578 // The following are values that can be passed to the groupLatch parameter for
579 // functions: Timer_B_selectLatchingGroup().
580 //
581 //*****************************************************************************
582 #define TIMER_B_GROUP_NONE TBCLGRP_0
583 #define TIMER_B_GROUP_CL12_CL23_CL56 TBCLGRP_1
584 #define TIMER_B_GROUP_CL123_CL456 TBCLGRP_2
585 #define TIMER_B_GROUP_ALL TBCLGRP_3
586 
587 //*****************************************************************************
588 //
589 // The following are values that can be passed to the compareLatchLoadEvent
590 // parameter for functions: Timer_B_initCompareLatchLoadEvent().
591 //
592 //*****************************************************************************
593 #define TIMER_B_LATCH_ON_WRITE_TO_TBxCCRn_COMPARE_REGISTER CLLD_0
594 #define TIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_0_IN_UP_OR_CONT_MODE CLLD_1
595 #define TIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_0_IN_UPDOWN_MODE CLLD_2
596 #define TIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_CURRENT_COMPARE_LATCH_VALUE CLLD_3
597 
598 //*****************************************************************************
599 //
600 // The following are values that can be passed toThe following are values that
601 // can be returned by the Timer_B_getInterruptStatus() function.
602 //
603 //*****************************************************************************
604 #define TIMER_B_INTERRUPT_NOT_PENDING 0x00
605 #define TIMER_B_INTERRUPT_PENDING 0x01
606 
607 //*****************************************************************************
608 //
609 // Prototypes for the APIs.
610 //
611 //*****************************************************************************
612 
613 //*****************************************************************************
614 //
631 //
632 //*****************************************************************************
633 extern void Timer_B_startCounter(uint16_t baseAddress,
634  uint16_t timerMode);
635 
636 //*****************************************************************************
637 //
649 //
650 //*****************************************************************************
651 extern void Timer_B_initContinuousMode(uint16_t baseAddress,
652  Timer_B_initContinuousModeParam *param);
653 
654 //*****************************************************************************
655 //
668 //
669 //*****************************************************************************
670 extern void Timer_B_initUpMode(uint16_t baseAddress,
671  Timer_B_initUpModeParam *param);
672 
673 //*****************************************************************************
674 //
687 //
688 //*****************************************************************************
689 extern void Timer_B_initUpDownMode(uint16_t baseAddress,
690  Timer_B_initUpDownModeParam *param);
691 
692 //*****************************************************************************
693 //
702 //
703 //*****************************************************************************
704 extern void Timer_B_initCaptureMode(uint16_t baseAddress,
705  Timer_B_initCaptureModeParam *param);
706 
707 //*****************************************************************************
708 //
717 //
718 //*****************************************************************************
719 extern void Timer_B_initCompareMode(uint16_t baseAddress,
720  Timer_B_initCompareModeParam *param);
721 
722 //*****************************************************************************
723 //
733 //
734 //*****************************************************************************
735 extern void Timer_B_enableInterrupt(uint16_t baseAddress);
736 
737 //*****************************************************************************
738 //
746 //
747 //*****************************************************************************
748 extern void Timer_B_disableInterrupt(uint16_t baseAddress);
749 
750 //*****************************************************************************
751 //
760 //
761 //*****************************************************************************
762 extern uint32_t Timer_B_getInterruptStatus(uint16_t baseAddress);
763 
764 //*****************************************************************************
765 //
784 //
785 //*****************************************************************************
786 extern void Timer_B_enableCaptureCompareInterrupt(uint16_t baseAddress,
787  uint16_t captureCompareRegister);
788 
789 //*****************************************************************************
790 //
809 //
810 //*****************************************************************************
811 extern void Timer_B_disableCaptureCompareInterrupt(uint16_t baseAddress,
812  uint16_t captureCompareRegister);
813 
814 //*****************************************************************************
815 //
839 //
840 //*****************************************************************************
841 extern uint32_t Timer_B_getCaptureCompareInterruptStatus(uint16_t baseAddress,
842  uint16_t captureCompareRegister,
843  uint16_t mask);
844 
845 //*****************************************************************************
846 //
854 //
855 //*****************************************************************************
856 extern void Timer_B_clear(uint16_t baseAddress);
857 
858 //*****************************************************************************
859 //
882 //
883 //*****************************************************************************
884 extern uint8_t Timer_B_getSynchronizedCaptureCompareInput(uint16_t baseAddress,
885  uint16_t captureCompareRegister,
886  uint16_t synchronized);
887 
888 //*****************************************************************************
889 //
908 //
909 //*****************************************************************************
910 extern uint8_t Timer_B_getOutputForOutputModeOutBitValue(uint16_t baseAddress,
911  uint16_t captureCompareRegister);
912 
913 //*****************************************************************************
914 //
931 //
932 //*****************************************************************************
933 extern uint16_t Timer_B_getCaptureCompareCount(uint16_t baseAddress,
934  uint16_t captureCompareRegister);
935 
936 //*****************************************************************************
937 //
960 //
961 //*****************************************************************************
962 extern void Timer_B_setOutputForOutputModeOutBitValue(uint16_t baseAddress,
963  uint16_t captureCompareRegister,
964  uint16_t outputModeOutBitValue);
965 
966 //*****************************************************************************
967 //
977 //
978 //*****************************************************************************
979 extern void Timer_B_outputPWM(uint16_t baseAddress,
980  Timer_B_outputPWMParam *param);
981 
982 //*****************************************************************************
983 //
991 //
992 //*****************************************************************************
993 extern void Timer_B_stop(uint16_t baseAddress);
994 
995 //*****************************************************************************
996 //
1015 //
1016 //*****************************************************************************
1017 extern void Timer_B_setCompareValue(uint16_t baseAddress,
1018  uint16_t compareRegister,
1019  uint16_t compareValue);
1020 
1021 //*****************************************************************************
1022 //
1030 //
1031 //*****************************************************************************
1032 extern void Timer_B_clearTimerInterrupt(uint16_t baseAddress);
1033 
1034 //*****************************************************************************
1035 //
1054 //
1055 //*****************************************************************************
1056 extern void Timer_B_clearCaptureCompareInterrupt(uint16_t baseAddress,
1057  uint16_t captureCompareRegister);
1058 
1059 //*****************************************************************************
1060 //
1074 //
1075 //*****************************************************************************
1076 extern void Timer_B_selectCounterLength(uint16_t baseAddress,
1077  uint16_t counterLength);
1078 
1079 //*****************************************************************************
1080 //
1094 //
1095 //*****************************************************************************
1096 extern void Timer_B_selectLatchingGroup(uint16_t baseAddress,
1097  uint16_t groupLatch);
1098 
1099 //*****************************************************************************
1100 //
1125 //
1126 //*****************************************************************************
1127 extern void Timer_B_initCompareLatchLoadEvent(uint16_t baseAddress,
1128  uint16_t compareRegister,
1129  uint16_t compareLatchLoadEvent);
1130 
1131 //*****************************************************************************
1132 //
1143 //
1144 //*****************************************************************************
1145 extern uint16_t Timer_B_getCounterValue(uint16_t baseAddress);
1146 
1147 //*****************************************************************************
1148 //
1177 //
1178 //*****************************************************************************
1179 extern void Timer_B_setOutputMode(uint16_t baseAddress,
1180  uint16_t compareRegister,
1181  uint16_t compareOutputMode);
1182 
1183 //*****************************************************************************
1184 //
1185 // Mark the end of the C bindings section for C++ compilers.
1186 //
1187 //*****************************************************************************
1188 #ifdef __cplusplus
1189 }
1190 #endif
1191 
1192 #endif
1193 #endif // __MSP430WARE_TIMER_B_H__
MPU_initThreeSegmentsParam param