-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
executable file
·143 lines (114 loc) · 4.29 KB
/
utils.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
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
#include <fsl_device_registers.h>
#include "utils.h"
/*----------------------------------------------------------------------------
Function that initializes LEDs
*----------------------------------------------------------------------------*/
void LED_Initialize(void) {
SIM->SCGC5 |= (1 << 10) | (1 << 13); /* Enable Clock to Port B & E */
PORTB->PCR[22] = (1 << 8) ; /* Pin PTB22 is GPIO */
PORTB->PCR[21] = (1 << 8); /* Pin PTB21 is GPIO */
PORTE->PCR[26] = (1 << 8); /* Pin PTE26 is GPIO */
PTB->PDOR = (1 << 21 | 1 << 22 ); /* switch Red/Green LED off */
PTB->PDDR = (1 << 21 | 1 << 22 ); /* enable PTB18/19 as Output */
PTE->PDOR = 1 << 26; /* switch Blue LED off */
PTE->PDDR = 1 << 26; /* enable PTE26 as Output */
}
/*----------------------------------------------------------------------------
Function that toggles the red LED
*----------------------------------------------------------------------------*/
void LEDRed_Toggle (void) {
PTB->PTOR = 1 << 22; /* Red LED Toggle */
}
/*----------------------------------------------------------------------------
Function that toggles the blue LED
*----------------------------------------------------------------------------*/
void LEDBlue_Toggle (void) {
PTB->PTOR = 1 << 21; /* Blue LED Toggle */
}
/*----------------------------------------------------------------------------
Function that toggles the green LED
*----------------------------------------------------------------------------*/
void LEDGreen_Toggle (void) {
PTE->PTOR = 1 << 26; /* Green LED Toggle */
}
/*----------------------------------------------------------------------------
Function that turns on Red LED & all the others off
*----------------------------------------------------------------------------*/
void LEDRed_On (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTB->PCOR = 1 << 22; /* Red LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
void LEDRed_Off (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTB->PSOR = 1 << 22; /* Red LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
/*----------------------------------------------------------------------------
Function that turns on Green LED & all the others off
*----------------------------------------------------------------------------*/
void LEDGreen_On (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTE->PCOR = 1 << 26; /* Green LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
void LEDGreen_Off (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTE->PSOR = 1 << 26; /* Green LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
/*----------------------------------------------------------------------------
Function that turns on Blue LED & all the others off
*----------------------------------------------------------------------------*/
void LEDBlue_On (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTB->PCOR = 1 << 21; /* Blue LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
void LEDBlue_Off (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTB->PSOR = 1 << 21; /* Blue LED On*/
// Restore interrupts
__set_PRIMASK(m);
}
/*----------------------------------------------------------------------------
Function that turns all LEDs off
*----------------------------------------------------------------------------*/
void LED_Off (void) {
// Save and disable interrupts (for atomic LED change)
uint32_t m;
m = __get_PRIMASK();
__disable_irq();
PTB->PSOR = 1 << 22; /* Green LED Off*/
PTB->PSOR = 1 << 21; /* Red LED Off*/
PTE->PSOR = 1 << 26; /* Blue LED Off*/
// Restore interrupts
__set_PRIMASK(m);
}
void delay(void){
int j;
for(j=0; j<1000000; j++);
}