forked from Mathias-L/STM32F4-Discovery-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
136 lines (111 loc) · 3.13 KB
/
main.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
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT 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.
ChibiOS/RT 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "shell.h"
#include "chprintf.h"
#include "myPWM.h"
#include "myADC.h"
#include "myUSB.h"
#include "myMisc.h"
/*
* assert Shell Commands to functions
*/
static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"toggle", cmd_toggle},
{"t", cmd_toggle},
{"blinkspeed", cmd_blinkspeed},
{"bs", cmd_blinkspeed},
{"cycle", cmd_cycle},
{"c", cmd_cycle},
{"ramp", cmd_ramp},
{"r", cmd_ramp},
{"measure", cmd_measure},
{"m", cmd_measure},
{"measureAnalog", cmd_measureA},
{"ma", cmd_measureA},
{"vref", cmd_Vref},
{"v", cmd_Vref},
{"temperature", cmd_Temperature},
{"te", cmd_Temperature},
{"measureDirect", cmd_measureDirect},
{"md", cmd_measureDirect},
{"measureContinuous", cmd_measureCont},
{"mc", cmd_measureCont},
{"readContinuousData", cmd_measureRead},
{"rd", cmd_measureRead},
{"stopContinuous", cmd_measureStop},
{"sc", cmd_measureStop},
{NULL, NULL}
};
/*
* Shell configuration
*/
#define SHELL_WA_SIZE THD_WA_SIZE(2048)
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&SDU1,
commands
};
/*
* Application entry point.
*/
int main(void) {
/*
* Shell thread
*/
Thread *shelltp = NULL;
/*
* 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();
chSysInit();
/*
* Activate custom stuff
*/
mypwmInit();
myADCinit();
/*
* Creates the blinker thread.
*/
startBlinker();
/*
* Activates the USB driver and then the USB bus pull-up on D+.
*/
myUSBinit();
/*
* Main loop, does nothing except spawn a shell when the old one was terminated
*/
while (TRUE) {
if (!shelltp && isUsbActive())
{
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
}
else if (chThdTerminated(shelltp)) {
chThdRelease(shelltp); /* Recovers memory of the previous shell. */
shelltp = NULL; /* Triggers spawning of a new shell. */
}
chThdSleepMilliseconds(1000);
}
}