2020-2021 Sunseeker Telemetry and Lighting System
timer_a.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // timer_a.h - Driver for the TIMER_A Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_TIMER_A_H__
8 #define __MSP430WARE_TIMER_A_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_TxA7__
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_A_getCounterValue that
29 // determines the maximum difference in counts of the TAxR register for a
30 // majority vote.
31 //
32 //*****************************************************************************
33 #define TIMER_A_THRESHOLD 50
34 
35 //*****************************************************************************
36 //
39 //
40 //*****************************************************************************
41 typedef struct Timer_A_initContinuousModeParam {
48  uint16_t clockSource;
71  uint16_t clockSourceDivider;
76  uint16_t timerInterruptEnable_TAIE;
82  uint16_t timerClear;
84  bool startTimer;
85 } Timer_A_initContinuousModeParam;
86 
87 //*****************************************************************************
88 //
91 //
92 //*****************************************************************************
93 typedef struct Timer_A_initCaptureModeParam {
104  uint16_t captureRegister;
111  uint16_t captureMode;
118  uint16_t captureInputSelect;
123  uint16_t synchronizeCaptureSource;
128  uint16_t captureInterruptEnable;
139  uint16_t captureOutputMode;
140 } Timer_A_initCaptureModeParam;
141 
142 //*****************************************************************************
143 //
146 //
147 //*****************************************************************************
148 typedef struct Timer_A_initUpDownModeParam {
155  uint16_t clockSource;
178  uint16_t clockSourceDivider;
180  uint16_t timerPeriod;
185  uint16_t timerInterruptEnable_TAIE;
190  uint16_t captureCompareInterruptEnable_CCR0_CCIE;
196  uint16_t timerClear;
198  bool startTimer;
199 } Timer_A_initUpDownModeParam;
200 
201 //*****************************************************************************
202 //
204 //
205 //*****************************************************************************
206 typedef struct Timer_A_outputPWMParam {
213  uint16_t clockSource;
236  uint16_t clockSourceDivider;
238  uint16_t timerPeriod;
249  uint16_t compareRegister;
260  uint16_t compareOutputMode;
262  uint16_t dutyCycle;
263 } Timer_A_outputPWMParam;
264 
265 //*****************************************************************************
266 //
268 //
269 //*****************************************************************************
270 typedef struct Timer_A_initUpModeParam {
277  uint16_t clockSource;
300  uint16_t clockSourceDivider;
303  uint16_t timerPeriod;
308  uint16_t timerInterruptEnable_TAIE;
313  uint16_t captureCompareInterruptEnable_CCR0_CCIE;
319  uint16_t timerClear;
321  bool startTimer;
322 } Timer_A_initUpModeParam;
323 
324 //*****************************************************************************
325 //
328 //
329 //*****************************************************************************
330 typedef struct Timer_A_initCompareModeParam {
341  uint16_t compareRegister;
346  uint16_t compareInterruptEnable;
357  uint16_t compareOutputMode;
359  uint16_t compareValue;
360 } Timer_A_initCompareModeParam;
361 
362 
363 //*****************************************************************************
364 //
365 // The following are values that can be passed to the param parameter for
366 // functions: Timer_A_initContinuousMode(), Timer_A_initUpMode(),
367 // Timer_A_initUpDownMode(), and Timer_A_outputPWM().
368 //
369 //*****************************************************************************
370 #define TIMER_A_CLOCKSOURCE_DIVIDER_1 0x00
371 #define TIMER_A_CLOCKSOURCE_DIVIDER_2 0x08
372 #define TIMER_A_CLOCKSOURCE_DIVIDER_3 0x02
373 #define TIMER_A_CLOCKSOURCE_DIVIDER_4 0x10
374 #define TIMER_A_CLOCKSOURCE_DIVIDER_5 0x04
375 #define TIMER_A_CLOCKSOURCE_DIVIDER_6 0x05
376 #define TIMER_A_CLOCKSOURCE_DIVIDER_7 0x06
377 #define TIMER_A_CLOCKSOURCE_DIVIDER_8 0x18
378 #define TIMER_A_CLOCKSOURCE_DIVIDER_10 0x0C
379 #define TIMER_A_CLOCKSOURCE_DIVIDER_12 0x0D
380 #define TIMER_A_CLOCKSOURCE_DIVIDER_14 0x0E
381 #define TIMER_A_CLOCKSOURCE_DIVIDER_16 0x0F
382 #define TIMER_A_CLOCKSOURCE_DIVIDER_20 0x14
383 #define TIMER_A_CLOCKSOURCE_DIVIDER_24 0x15
384 #define TIMER_A_CLOCKSOURCE_DIVIDER_28 0x16
385 #define TIMER_A_CLOCKSOURCE_DIVIDER_32 0x17
386 #define TIMER_A_CLOCKSOURCE_DIVIDER_40 0x1C
387 #define TIMER_A_CLOCKSOURCE_DIVIDER_48 0x1D
388 #define TIMER_A_CLOCKSOURCE_DIVIDER_56 0x1E
389 #define TIMER_A_CLOCKSOURCE_DIVIDER_64 0x1F
390 
391 //*****************************************************************************
392 //
393 // The following are values that can be passed to the timerMode parameter for
394 // functions: Timer_A_startCounter().
395 //
396 //*****************************************************************************
397 #define TIMER_A_STOP_MODE MC_0
398 #define TIMER_A_UP_MODE MC_1
399 #define TIMER_A_CONTINUOUS_MODE MC_2
400 #define TIMER_A_UPDOWN_MODE MC_3
401 
402 //*****************************************************************************
403 //
404 // The following are values that can be passed to the param parameter for
405 // functions: Timer_A_initContinuousMode(), Timer_A_initUpMode(), and
406 // Timer_A_initUpDownMode().
407 //
408 //*****************************************************************************
409 #define TIMER_A_DO_CLEAR TACLR
410 #define TIMER_A_SKIP_CLEAR 0x00
411 
412 //*****************************************************************************
413 //
414 // The following are values that can be passed to the param parameter for
415 // functions: Timer_A_initContinuousMode(), Timer_A_initUpMode(),
416 // Timer_A_initUpDownMode(), and Timer_A_outputPWM().
417 //
418 //*****************************************************************************
419 #define TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK TASSEL__TACLK
420 #define TIMER_A_CLOCKSOURCE_ACLK TASSEL__ACLK
421 #define TIMER_A_CLOCKSOURCE_SMCLK TASSEL__SMCLK
422 #define TIMER_A_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK TASSEL__INCLK
423 
424 //*****************************************************************************
425 //
426 // The following are values that can be passed to the param parameter for
427 // functions: Timer_A_initContinuousMode(), Timer_A_initUpMode(), and
428 // Timer_A_initUpDownMode().
429 //
430 //*****************************************************************************
431 #define TIMER_A_TAIE_INTERRUPT_ENABLE TAIE
432 #define TIMER_A_TAIE_INTERRUPT_DISABLE 0x00
433 
434 //*****************************************************************************
435 //
436 // The following are values that can be passed to the param parameter for
437 // functions: Timer_A_initUpMode(), and Timer_A_initUpDownMode().
438 //
439 //*****************************************************************************
440 #define TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE CCIE
441 #define TIMER_A_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_A_initCaptureMode(), and Timer_A_initCompareMode().
447 //
448 //*****************************************************************************
449 #define TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE 0x00
450 #define TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE CCIE
451 
452 //*****************************************************************************
453 //
454 // The following are values that can be passed to the param parameter for
455 // functions: Timer_A_initCaptureMode().
456 //
457 //*****************************************************************************
458 #define TIMER_A_CAPTURE_INPUTSELECT_CCIxA CCIS_0
459 #define TIMER_A_CAPTURE_INPUTSELECT_CCIxB CCIS_1
460 #define TIMER_A_CAPTURE_INPUTSELECT_GND CCIS_2
461 #define TIMER_A_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_A_setOutputMode(); the param parameter for
467 // functions: Timer_A_initCaptureMode(), Timer_A_initCompareMode(), and
468 // Timer_A_outputPWM().
469 //
470 //*****************************************************************************
471 #define TIMER_A_OUTPUTMODE_OUTBITVALUE OUTMOD_0
472 #define TIMER_A_OUTPUTMODE_SET OUTMOD_1
473 #define TIMER_A_OUTPUTMODE_TOGGLE_RESET OUTMOD_2
474 #define TIMER_A_OUTPUTMODE_SET_RESET OUTMOD_3
475 #define TIMER_A_OUTPUTMODE_TOGGLE OUTMOD_4
476 #define TIMER_A_OUTPUTMODE_RESET OUTMOD_5
477 #define TIMER_A_OUTPUTMODE_TOGGLE_SET OUTMOD_6
478 #define TIMER_A_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_A_setCompareValue(), and Timer_A_setOutputMode(); the
484 // captureCompareRegister parameter for functions:
485 // Timer_A_enableCaptureCompareInterrupt(),
486 // Timer_A_disableCaptureCompareInterrupt(),
487 // Timer_A_getCaptureCompareInterruptStatus(),
488 // Timer_A_getSynchronizedCaptureCompareInput(),
489 // Timer_A_getOutputForOutputModeOutBitValue(),
490 // Timer_A_getCaptureCompareCount(),
491 // Timer_A_setOutputForOutputModeOutBitValue(), and
492 // Timer_A_clearCaptureCompareInterrupt(); the param parameter for functions:
493 // Timer_A_initCaptureMode(), Timer_A_initCompareMode(), and
494 // Timer_A_outputPWM().
495 //
496 //*****************************************************************************
497 #define TIMER_A_CAPTURECOMPARE_REGISTER_0 0x02
498 #define TIMER_A_CAPTURECOMPARE_REGISTER_1 0x04
499 #define TIMER_A_CAPTURECOMPARE_REGISTER_2 0x06
500 #define TIMER_A_CAPTURECOMPARE_REGISTER_3 0x08
501 #define TIMER_A_CAPTURECOMPARE_REGISTER_4 0x0A
502 #define TIMER_A_CAPTURECOMPARE_REGISTER_5 0x0C
503 #define TIMER_A_CAPTURECOMPARE_REGISTER_6 0x0E
504 
505 //*****************************************************************************
506 //
507 // The following are values that can be passed to the param parameter for
508 // functions: Timer_A_initCaptureMode().
509 //
510 //*****************************************************************************
511 #define TIMER_A_CAPTUREMODE_NO_CAPTURE CM_0
512 #define TIMER_A_CAPTUREMODE_RISING_EDGE CM_1
513 #define TIMER_A_CAPTUREMODE_FALLING_EDGE CM_2
514 #define TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE CM_3
515 
516 //*****************************************************************************
517 //
518 // The following are values that can be passed to the param parameter for
519 // functions: Timer_A_initCaptureMode().
520 //
521 //*****************************************************************************
522 #define TIMER_A_CAPTURE_ASYNCHRONOUS 0x00
523 #define TIMER_A_CAPTURE_SYNCHRONOUS SCS
524 
525 //*****************************************************************************
526 //
527 // The following are values that can be passed to the mask parameter for
528 // functions: Timer_A_getCaptureCompareInterruptStatus() as well as returned by
529 // the Timer_A_getCaptureCompareInterruptStatus() function.
530 //
531 //*****************************************************************************
532 #define TIMER_A_CAPTURE_OVERFLOW COV
533 #define TIMER_A_CAPTURECOMPARE_INTERRUPT_FLAG CCIFG
534 
535 //*****************************************************************************
536 //
537 // The following are values that can be passed to the synchronized parameter
538 // for functions: Timer_A_getSynchronizedCaptureCompareInput().
539 //
540 //*****************************************************************************
541 #define TIMER_A_READ_SYNCHRONIZED_CAPTURECOMPAREINPUT SCCI
542 #define TIMER_A_READ_CAPTURE_COMPARE_INPUT CCI
543 
544 //*****************************************************************************
545 //
546 // The following are values that can be passed toThe following are values that
547 // can be returned by the Timer_A_getSynchronizedCaptureCompareInput()
548 // function.
549 //
550 //*****************************************************************************
551 #define TIMER_A_CAPTURECOMPARE_INPUT_HIGH 0x01
552 #define TIMER_A_CAPTURECOMPARE_INPUT_LOW 0x00
553 
554 //*****************************************************************************
555 //
556 // The following are values that can be passed to the outputModeOutBitValue
557 // parameter for functions: Timer_A_setOutputForOutputModeOutBitValue() as well
558 // as returned by the Timer_A_getOutputForOutputModeOutBitValue() function.
559 //
560 //*****************************************************************************
561 #define TIMER_A_OUTPUTMODE_OUTBITVALUE_HIGH OUT
562 #define TIMER_A_OUTPUTMODE_OUTBITVALUE_LOW 0x00
563 
564 //*****************************************************************************
565 //
566 // The following are values that can be passed toThe following are values that
567 // can be returned by the Timer_A_getInterruptStatus() function.
568 //
569 //*****************************************************************************
570 #define TIMER_A_INTERRUPT_NOT_PENDING 0x00
571 #define TIMER_A_INTERRUPT_PENDING 0x01
572 
573 //*****************************************************************************
574 //
575 // Prototypes for the APIs.
576 //
577 //*****************************************************************************
578 
579 //*****************************************************************************
580 //
597 //
598 //*****************************************************************************
599 extern void Timer_A_startCounter(uint16_t baseAddress,
600  uint16_t timerMode);
601 
602 //*****************************************************************************
603 //
612 //
613 //*****************************************************************************
614 extern void Timer_A_initContinuousMode(uint16_t baseAddress,
615  Timer_A_initContinuousModeParam *param);
616 
617 //*****************************************************************************
618 //
628 //
629 //*****************************************************************************
630 extern void Timer_A_initUpMode(uint16_t baseAddress,
631  Timer_A_initUpModeParam *param);
632 
633 //*****************************************************************************
634 //
644 //
645 //*****************************************************************************
646 extern void Timer_A_initUpDownMode(uint16_t baseAddress,
647  Timer_A_initUpDownModeParam *param);
648 
649 //*****************************************************************************
650 //
659 //
660 //*****************************************************************************
661 extern void Timer_A_initCaptureMode(uint16_t baseAddress,
662  Timer_A_initCaptureModeParam *param);
663 
664 //*****************************************************************************
665 //
674 //
675 //*****************************************************************************
676 extern void Timer_A_initCompareMode(uint16_t baseAddress,
677  Timer_A_initCompareModeParam *param);
678 
679 //*****************************************************************************
680 //
690 //
691 //*****************************************************************************
692 extern void Timer_A_enableInterrupt(uint16_t baseAddress);
693 
694 //*****************************************************************************
695 //
703 //
704 //*****************************************************************************
705 extern void Timer_A_disableInterrupt(uint16_t baseAddress);
706 
707 //*****************************************************************************
708 //
717 //
718 //*****************************************************************************
719 extern uint32_t Timer_A_getInterruptStatus(uint16_t baseAddress);
720 
721 //*****************************************************************************
722 //
741 //
742 //*****************************************************************************
743 extern void Timer_A_enableCaptureCompareInterrupt(uint16_t baseAddress,
744  uint16_t captureCompareRegister);
745 
746 //*****************************************************************************
747 //
764 //
765 //*****************************************************************************
766 extern void Timer_A_disableCaptureCompareInterrupt(uint16_t baseAddress,
767  uint16_t captureCompareRegister);
768 
769 //*****************************************************************************
770 //
792 //
793 //*****************************************************************************
794 extern uint32_t Timer_A_getCaptureCompareInterruptStatus(uint16_t baseAddress,
795  uint16_t captureCompareRegister,
796  uint16_t mask);
797 
798 //*****************************************************************************
799 //
807 //
808 //*****************************************************************************
809 extern void Timer_A_clear(uint16_t baseAddress);
810 
811 //*****************************************************************************
812 //
833 //
834 //*****************************************************************************
835 extern uint8_t Timer_A_getSynchronizedCaptureCompareInput(uint16_t baseAddress,
836  uint16_t captureCompareRegister,
837  uint16_t synchronized);
838 
839 //*****************************************************************************
840 //
857 //
858 //*****************************************************************************
859 extern uint8_t Timer_A_getOutputForOutputModeOutBitValue(uint16_t baseAddress,
860  uint16_t captureCompareRegister);
861 
862 //*****************************************************************************
863 //
878 //
879 //*****************************************************************************
880 extern uint16_t Timer_A_getCaptureCompareCount(uint16_t baseAddress,
881  uint16_t captureCompareRegister);
882 
883 //*****************************************************************************
884 //
905 //
906 //*****************************************************************************
907 extern void Timer_A_setOutputForOutputModeOutBitValue(uint16_t baseAddress,
908  uint16_t captureCompareRegister,
909  uint8_t outputModeOutBitValue);
910 
911 //*****************************************************************************
912 //
922 //
923 //*****************************************************************************
924 extern void Timer_A_outputPWM(uint16_t baseAddress,
925  Timer_A_outputPWMParam *param);
926 
927 //*****************************************************************************
928 //
936 //
937 //*****************************************************************************
938 extern void Timer_A_stop(uint16_t baseAddress);
939 
940 //*****************************************************************************
941 //
961 //
962 //*****************************************************************************
963 extern void Timer_A_setCompareValue(uint16_t baseAddress,
964  uint16_t compareRegister,
965  uint16_t compareValue);
966 
967 //*****************************************************************************
968 //
997 //
998 //*****************************************************************************
999 extern void Timer_A_setOutputMode(uint16_t baseAddress,
1000  uint16_t compareRegister,
1001  uint16_t compareOutputMode);
1002 
1003 //*****************************************************************************
1004 //
1012 //
1013 //*****************************************************************************
1014 extern void Timer_A_clearTimerInterrupt(uint16_t baseAddress);
1015 
1016 //*****************************************************************************
1017 //
1035 //
1036 //*****************************************************************************
1037 extern void Timer_A_clearCaptureCompareInterrupt(uint16_t baseAddress,
1038  uint16_t captureCompareRegister);
1039 
1040 //*****************************************************************************
1041 //
1052 //
1053 //*****************************************************************************
1054 extern uint16_t Timer_A_getCounterValue(uint16_t baseAddress);
1055 
1056 //*****************************************************************************
1057 //
1058 // Mark the end of the C bindings section for C++ compilers.
1059 //
1060 //*****************************************************************************
1061 #ifdef __cplusplus
1062 }
1063 #endif
1064 
1065 #endif
1066 #endif // __MSP430WARE_TIMER_A_H__
MPU_initThreeSegmentsParam param