-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
131 lines (103 loc) · 4.68 KB
/
utils.c
File metadata and controls
131 lines (103 loc) · 4.68 KB
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
#include <MK64F12.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 initializes SW2 and SW3 push button switches
*---------------------------------------------------------*/
void bttn_Initialize(void) {
NVIC_EnableIRQ(PORTC_IRQn); /* Enable */
NVIC_EnableIRQ(PORTA_IRQn); /* Enable */
SIM->SCGC5 |= (1 << 9) | (1 << 11); /* Enable Clock to Port A & C */
PORTC->PCR[6] &= ~PORT_PCR_MUX_MASK; /* Configure Switch SW2 */
PORTA->PCR[4] &= ~PORT_PCR_MUX_MASK; /* Configure Switch SW3 */
PORTC->PCR[6] = 0xA0100; /* Connect Switch as interrupt */
PORTA->PCR[4] = 0xA0100; /* Connect Switch as interrupt */
PTC->PDDR &= ~GPIO_PDDR_PDD(1<<4); /* Assign switch to input */
PTA->PDDR &= ~GPIO_PDDR_PDD(1<<4); /* Assign switch to input */
}
/*----------------------------------------------------------------------------
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*/
PTB->PSOR = 1 << 21; /* Blue LED Off*/
PTE->PSOR = 1 << 26; /* Green LED Off*/
// 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();
PTB->PSOR = 1 << 21; /* Blue LED Off*/
PTE->PCOR = 1 << 26; /* Green LED On*/
PTB->PSOR = 1 << 22; /* Red LED Off*/
// 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();
PTE->PSOR = 1 << 26; /* Green LED Off*/
PTB->PSOR = 1 << 22; /* Red LED Off*/
PTB->PCOR = 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);
}