-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
121 lines (91 loc) · 3.25 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
/*
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ch.hpp"
#include "hal.h"
#include "ch_test.h"
#include <string.h>
#include "library/include/currentControl.h"
#include "library/include/Commands.h"
#include "library/include/tester.h"
#include "library/include/ThreePhaseDriver.h"
using namespace chibios_rt;
/* Static threads instances.*/
static TesterThread testerTh;
static currentControlTh currentTh;
static ControllerTh controlTh(currentTh, testerTh, 0);
static CommandsTh commandsTh(controlTh);
static ThreePhaseDriver threePhaseDriver(controlTh, 0);
static SerialConfig uartCfg =
{
//115200 // bit rate
921600
};
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
System::init();
/*
* Activates the serial driver 2 using the driver default configuration.
* PA2(TX) and PA3(RX) are routed to USART2.
*/
/* sdInit(); should be used as we see in the SerialDriver state machine
, but it is already implicitely called in halInit();*/
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // used function : USART2_TX
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); // used function : USART2_RX
palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL);
//palSetPadMode(GPIOA, GPIOA_LED_GREEN, PAL_MODE_OUTPUT_OPENDRAIN);
sdStart(&SD2, &uartCfg);
//BaseSequentialStream * strm = (BaseSequentialStream *)&SD2;
//char data[] = "Hello World ! \n \r";
currentTh.start(NORMALPRIO+1);
testerTh.start(NORMALPRIO-2);
controlTh.start(NORMALPRIO+2);
commandsTh.start(NORMALPRIO);
threePhaseDriver.initDriver();
//chprintf(strm, "sinit\r\n");
threePhaseDriver.start(NORMALPRIO);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/
while (true) {
if (!palReadPad(GPIOC, GPIOC_BUTTON)) {
//sdWrite(&SD2, (uint8_t *) data, strlen(data)); // Writes "Hello World in the UART output
//test_execute((BaseSequentialStream *)&SD2);
//palTogglePad(GPIOC, 3);
//palSetPad(GPIOC, 3);
palSetPad(GPIOA, GPIOA_LED_GREEN);
threePhaseDriver.disableOutput();
while (true) {
if (palReadPad(GPIOC, GPIOC_BUTTON)) {
threePhaseDriver.enableOutput();
palSetPad(GPIOA, GPIOA_LED_GREEN);
//palClearPad(GPIOC, 3);
break;
} else
chThdSleepMilliseconds(300);
}
}
chThdSleepMilliseconds(500);
}
return 0;
}