-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
164 lines (122 loc) · 3.79 KB
/
main.cpp
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
RTOS
Copyright (C) 2019 Matthew Hardenburgh
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/.
*/
/**
* @file main.c
* @project RTOS
* @engineer Matthew Hardenburgh
* @license GPL v3
* @date 11/04/2019
*/
#include "main.h"
int readme = -1;
float voltageValue = -1;
uint32_t adcResolution;
Gpio greenLed;
Gpio blueLed;
Gpio redLed;
Gpio swtich1;
Gpio swtich2;
Gpio adcPin;
Pwm greenPwm;
uint32_t sequencerPriority = (uint32_t)ssPriority0::third|(uint32_t)ssPriority1::second|(uint32_t)ssPriority2::first|(uint32_t)ssPriority3::zeroth;
Adc testAdc;
// GeneralPurposeTimer myTimer;
/**
* These functions further help eliminate unwanted exceptions
*/
extern "C" void __cxa_pure_virtual()
{
while(1);
}
void __gnu_cxx::__verbose_terminate_handler()
{
while(1);
}
extern "C" void GPIO_Port_F_Handler(void)
{
if(swtich1.read() == 1)
{
redLed.write((uint32_t)setORClear::clear);
swtich1.interruptClear();
}
if(swtich1.read() == 0)
{
redLed.write((uint32_t)setORClear::set);
swtich1.interruptClear();
}
if(swtich2.read() == 1)
{
blueLed.write((uint32_t)setORClear::clear);
swtich2.interruptClear();
}
if(swtich2.read() == 0)
{
blueLed.write((uint32_t)setORClear::set);
swtich2.interruptClear();
}
}
// extern "C" void _16_32_Bit_Timer_0A_Handler(void)
// {
// if(greenLed.read() == set)
// {
// greenLed.write(clear);
// myTimer.clearInterrupt();
// }
// else if(greenLed.read() == clear)
// {
// greenLed.write(set);
// myTimer.clearInterrupt();
// }
// }
void pollTest(void)
{
(void)testAdc.getAdcSample();
readme = testAdc.getAdcSample();
testAdc.clearInterrupt();
}
extern "C" void SystemInit(void)
{
SystemControl::initializeGPIOHB();
SystemControl::initializeClock(_80MHz);
greenLed.initialize((uint32_t)PF3::M1PWM7, output);
blueLed.initialize((uint32_t)PF2::GPIO, output);
redLed.initialize((uint32_t)PF1::GPIO, output);
adcPin.initialize((uint32_t)PE3::AIN0, input);
greenPwm.initializeSingle(7, module1, 0xFFFF, 0xFFFF/2, 0x1, countDirectionPwm::down, (uint32_t)ACTZERO::invertPwm, true, (uint32_t)pwmUnitClockDivisor::_64);
testAdc.initializeModule((uint32_t)adcModule::module0, sequencerPriority, false, false);
adcResolution = Adc::getAdcResolution();
}
int main(void)
{
Nvic::disableInterrupts();
swtich1.initialize((uint32_t)PF4::GPIO, input, 3);
swtich2.initialize((uint32_t)PF0::GPIO, input, 3);
// myTimer.initializeForInterupt(periodic, shortTimer0, 80000000, down, concatenated, 3);
// myTimer.enableTimer();
Nvic::enableInterrupts();
testAdc.initializeForPolling((uint32_t)sampleSequencer::SS3, (uint32_t)ssTriggerSource::processor, (uint32_t)ssInputSrc0::AIN0, (uint32_t)ssControl0::END0|(uint32_t)ssControl0::IE0, pollTest);
testAdc.enableSampleSequencer();
testAdc.initiateSampling();
blueLed.write((uint32_t)setORClear::set);
redLed.write((uint32_t)setORClear::set);
while(1)
{
// Nvic::wfi();
testAdc.pollStatus();
voltageValue = (3.3/(1<<adcResolution))*readme;
voltageValue = voltageValue;
}
}