1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2017, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #include <ti/devices/msp432p4xx/driverlib/debug.h>
33 #include <ti/devices/msp432p4xx/driverlib/interrupt.h>
34 #include <ti/devices/msp432p4xx/driverlib/systick.h>
35
SysTick_enableModule(void)36 void SysTick_enableModule(void)
37 {
38 //
39 // Enable SysTick.
40 //
41 SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
42 }
43
SysTick_disableModule(void)44 void SysTick_disableModule(void)
45 {
46 //
47 // Disable SysTick.
48 //
49 SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk);
50 }
51
SysTick_registerInterrupt(void (* intHandler)(void))52 void SysTick_registerInterrupt(void (*intHandler)(void))
53 {
54 //
55 // Register the interrupt handler, returning an error if an error occurs.
56 //
57 Interrupt_registerInterrupt(FAULT_SYSTICK, intHandler);
58
59 }
60
SysTick_unregisterInterrupt(void)61 void SysTick_unregisterInterrupt(void)
62 {
63
64 //
65 // Unregister the interrupt handler.
66 //
67 Interrupt_unregisterInterrupt(FAULT_SYSTICK);
68 }
69
SysTick_enableInterrupt(void)70 void SysTick_enableInterrupt(void)
71 {
72 //
73 // Enable the SysTick interrupt.
74 //
75 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
76 }
77
SysTick_disableInterrupt(void)78 void SysTick_disableInterrupt(void)
79 {
80 //
81 // Disable the SysTick interrupt.
82 //
83 SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk);
84 }
85
SysTick_setPeriod(uint32_t period)86 void SysTick_setPeriod(uint32_t period)
87 {
88 //
89 // Check the arguments.
90 //
91 ASSERT((period > 0) && (period <= 16777216));
92
93 //
94 // Set the period of the SysTick counter.
95 //
96 SysTick->LOAD = period - 1;
97 }
98
SysTick_getPeriod(void)99 uint32_t SysTick_getPeriod(void)
100 {
101 //
102 // Return the period of the SysTick counter.
103 //
104 return (SysTick->LOAD + 1);
105 }
106
SysTick_getValue(void)107 uint32_t SysTick_getValue(void)
108 {
109 //
110 // Return the current value of the SysTick counter.
111 //
112 return (SysTick->VAL);
113 }
114