-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGpt.c
92 lines (85 loc) · 3.69 KB
/
Gpt.c
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
/******************************************************************************
*
* Module: Gpt
*
* File Name: Gpt.c
*
* Description: Source file for TM4C123GH6PM Microcontroller - SysTick Timer Driver.
*
* Author: Mohamed Tarek
******************************************************************************/
#include "Gpt.h"
#include "tm4c123gh6pm_registers.h"
#define SYSTICK_PRIORITY_MASK 0x1FFFFFFF
#define SYSTICK_INTERRUPT_PRIORITY 3
#define SYSTICK_PRIORITY_BITS_POS 29
/* Global pointer to function used to point upper layer functions
* to be used in Call Back */
static void (*g_SysTick_Call_Back_Ptr)(void) = NULL_PTR;
/************************************************************************************
* Service Name: SysTick_Handler
* Description: SysTick Timer ISR
************************************************************************************/
void SysTick_Handler(void)
{
/* Check if the Timer0_setCallBack is already called */
if(g_SysTick_Call_Back_Ptr != NULL_PTR)
{
(*g_SysTick_Call_Back_Ptr)(); /* call the function in the scheduler using call-back concept */
}
/* No need to clear the trigger flag (COUNT) bit ... it cleared automatically by the HW */
}
/************************************************************************************
* Service Name: SysTick_Start
* Sync/Async: Synchronous
* Reentrancy: reentrant
* Parameters (in): Tick_Time - Time in miliseconds
* Parameters (inout): None
* Parameters (out): None
* Return value: None
* Description: Function to Setup the SysTick Timer configuration to count n miliseconds:
* - Set the Reload value
* - Enable SysTick Timer with System clock 16Mhz
* - Enable SysTick Timer Interrupt and set its priority
************************************************************************************/
void SysTick_Start(uint16 Tick_Time)
{
SYSTICK_CTRL_REG = 0; /* Disable the SysTick Timer by Clear the ENABLE Bit */
SYSTICK_RELOAD_REG = 15999 * Tick_Time; /* Set the Reload value to count n miliseconds */
SYSTICK_CURRENT_REG = 0; /* Clear the Current Register value */
/* Configure the SysTick Control Register
* Enable the SysTick Timer (ENABLE = 1)
* Enable SysTick Interrupt (INTEN = 1)
* Choose the clock source to be System Clock (CLK_SRC = 1) */
SYSTICK_CTRL_REG |= 0x07;
/* Assign priority level 3 to the SysTick Interrupt */
NVIC_SYSTEM_PRI3_REG = (NVIC_SYSTEM_PRI3_REG & SYSTICK_PRIORITY_MASK) | (SYSTICK_INTERRUPT_PRIORITY << SYSTICK_PRIORITY_BITS_POS);
}
/************************************************************************************
* Service Name: SysTick_Stop
* Sync/Async: Synchronous
* Reentrancy: reentrant
* Parameters (in): None
* Parameters (inout): None
* Parameters (out): None
* Return value: None
* Description: Function to Stop the SysTick Timer.
************************************************************************************/
void SysTick_Stop(void)
{
SYSTICK_CTRL_REG = 0; /* Disable the SysTick Timer by Clear the ENABLE Bit */
}
/************************************************************************************
* Service Name: SysTick_SetCallBack
* Sync/Async: Synchronous
* Reentrancy: reentrant
* Parameters (in): Ptr2Func - Call Back function address
* Parameters (inout): None
* Parameters (out): None
* Return value: None
* Description: Function to Setup the SysTick Timer call back
************************************************************************************/
void SysTick_SetCallBack(void(*Ptr2Func)(void))
{
g_SysTick_Call_Back_Ptr = Ptr2Func;
}