Line 20... |
Line 20... |
20 |
#include "serial.h" |
20 |
#include "serial.h" |
21 |
#include "gpt.h" |
21 |
#include "gpt.h" |
22 |
#include <string.h> |
22 |
#include <string.h> |
23 |
#include "keil/GPS_dekoduj.h" |
23 |
#include "keil/GPS_dekoduj.h" |
24 |
|
24 |
|
25 |
static void pwmpcb(PWMDriver *pwmp); |
- |
|
26 |
static void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n); |
- |
|
27 |
|
- |
|
28 |
/* Total number of channels to be sampled by a single ADC operation.*/ |
- |
|
29 |
#define ADC_GRP1_NUM_CHANNELS 2 |
- |
|
30 |
|
- |
|
31 |
/* Depth of the conversion buffer, channels are sampled four times each.*/ |
- |
|
32 |
#define ADC_GRP1_BUF_DEPTH 4 |
- |
|
33 |
|
- |
|
34 |
/*MAX delka prikazu, ktery uzivatel muze zadat*/ |
25 |
/*MAX delka prikazu, ktery uzivatel muze zadat*/ |
35 |
#define MAX_DELKA_PRIKAZU 10 |
26 |
#define MAX_DELKA_PRIKAZU 10 |
36 |
|
27 |
|
37 |
/*Velikost GPS bufferu*/ |
28 |
/*Velikost GPS bufferu*/ |
38 |
#define GPS_BUFFER 500 |
29 |
#define GPS_BUFFER 500 |
39 |
|
30 |
|
40 |
extern NMEA_GPGGA GPGGA_informace; |
31 |
extern NMEA_GPGGA GPGGA_informace; |
41 |
Thread *tp_odpal = NULL; |
32 |
Thread *tp_odpal = NULL; |
42 |
/* |
- |
|
43 |
* ADC samples buffer. |
- |
|
44 |
*/ |
- |
|
45 |
static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH]; |
- |
|
46 |
|
33 |
|
47 |
/* |
34 |
/* |
48 |
* ADC conversion group. |
- |
|
49 |
* Mode: Linear buffer, 4 samples of 2 channels, SW triggered. |
- |
|
50 |
* Channels: IN10 (48 cycles sample time) |
- |
|
51 |
* Sensor (192 cycles sample time) |
- |
|
52 |
*/ |
- |
|
53 |
static const ADCConversionGroup adcgrpcfg = { |
- |
|
54 |
FALSE, |
- |
|
55 |
ADC_GRP1_NUM_CHANNELS, |
- |
|
56 |
adccb, |
- |
|
57 |
NULL, |
- |
|
58 |
/* HW dependent part.*/ |
- |
|
59 |
0, /* CR1 */ |
- |
|
60 |
ADC_CR2_SWSTART, /* CR2 */ |
- |
|
61 |
0, |
- |
|
62 |
ADC_SMPR2_SMP_AN10(ADC_SAMPLE_48) | ADC_SMPR2_SMP_SENSOR(ADC_SAMPLE_192), |
- |
|
63 |
0, |
- |
|
64 |
ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS), |
- |
|
65 |
0, |
- |
|
66 |
0, |
- |
|
67 |
0, |
- |
|
68 |
ADC_SQR5_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR5_SQ1_N(ADC_CHANNEL_SENSOR) |
- |
|
69 |
}; |
- |
|
70 |
/* |
- |
|
71 |
* Konfigurace USART2 |
35 |
* Konfigurace USART2 |
72 |
*/ |
36 |
*/ |
73 |
|
37 |
|
74 |
static const SerialConfig USART2_config = |
38 |
static const SerialConfig USART2_config = |
75 |
{ |
39 |
{ |
Line 80... |
Line 44... |
80 |
/*Initialization value for the CR2 register.*/ |
44 |
/*Initialization value for the CR2 register.*/ |
81 |
USART_CR2_STOP1_BITS | USART_CR2_LINEN, |
45 |
USART_CR2_STOP1_BITS | USART_CR2_LINEN, |
82 |
/*Initialization value for the CR3 register.*/ |
46 |
/*Initialization value for the CR3 register.*/ |
83 |
0 |
47 |
0 |
84 |
}; |
48 |
}; |
85 |
//GPTDriver GPTD2; |
- |
|
- |
|
49 |
|
86 |
/* |
50 |
/* |
87 |
* GPT2 callback. |
51 |
* GPT2 callback. |
88 |
*/ |
52 |
*/ |
89 |
static void gpt2cb(GPTDriver *gptp) |
53 |
static void gpt2cb(GPTDriver *gptp) |
90 |
{ |
54 |
{ |
91 |
(void)gptp; |
55 |
(void)gptp; |
92 |
palTogglePad(GPIOB, GPIOB_LED4); |
56 |
palTogglePad(GPIOB, GPIOB_LED4); |
93 |
/* Wakes up the thread.*/ |
57 |
/* Wakes up the thread.*/ |
94 |
chSysLockFromIsr(); |
58 |
chSysLockFromIsr(); |
95 |
if (tp_odpal != NULL) { |
59 |
if (tp_odpal != NULL) { |
96 |
//tp_odpal->p_u.rdymsg = (msg_t)55; /* Sending the message, optional.*/ |
60 |
tp_odpal->p_u.rdymsg = (msg_t)50; /* Znaci, ze se vlakno probouzi kvuli preruseni od GPT*/ |
97 |
chSchReadyI(tp_odpal); |
61 |
chSchReadyI(tp_odpal); |
98 |
tp_odpal = NULL; |
62 |
tp_odpal = NULL; |
99 |
} |
63 |
} |
100 |
chSysUnlockFromIsr(); |
64 |
chSysUnlockFromIsr(); |
101 |
} |
65 |
} |
Line 108... |
Line 72... |
108 |
1000, /*1000Hz f*/ |
72 |
1000, /*1000Hz f*/ |
109 |
gpt2cb /*callback fce*/ |
73 |
gpt2cb /*callback fce*/ |
110 |
}; |
74 |
}; |
111 |
|
75 |
|
112 |
|
76 |
|
113 |
|
- |
|
114 |
/* |
- |
|
115 |
* PWM configuration structure. |
- |
|
116 |
* Cyclic callback enabled, channels 1 and 2 enabled without callbacks, |
- |
|
117 |
* the active state is a logic one. |
- |
|
118 |
*/ |
- |
|
119 |
static PWMConfig pwmcfg = { |
- |
|
120 |
10000, /* 10kHz PWM clock frequency. */ |
- |
|
121 |
10000, /* PWM period 1S (in ticks). */ |
- |
|
122 |
pwmpcb, |
- |
|
123 |
{ |
- |
|
124 |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, |
- |
|
125 |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, |
- |
|
126 |
{PWM_OUTPUT_DISABLED, NULL}, |
- |
|
127 |
{PWM_OUTPUT_DISABLED, NULL} |
- |
|
128 |
}, |
- |
|
129 |
/* HW dependent part.*/ |
- |
|
130 |
0 |
- |
|
131 |
}; |
- |
|
132 |
|
- |
|
133 |
/* |
- |
|
134 |
* USART konfigurace |
- |
|
135 |
*/ |
- |
|
136 |
|
- |
|
137 |
|
- |
|
138 |
/* |
- |
|
139 |
* PWM cyclic callback. |
- |
|
140 |
* A new ADC conversion is started. |
- |
|
141 |
*/ |
- |
|
142 |
static void pwmpcb(PWMDriver *pwmp) { |
- |
|
143 |
|
- |
|
144 |
(void)pwmp; |
- |
|
145 |
|
- |
|
146 |
/* Starts an asynchronous ADC conversion operation, the conversion |
- |
|
147 |
will be executed in parallel to the current PWM cycle and will |
- |
|
148 |
terminate before the next PWM cycle.*/ |
- |
|
149 |
chSysLockFromIsr(); |
- |
|
150 |
adcStartConversionI(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH); |
- |
|
151 |
chSysUnlockFromIsr(); |
- |
|
152 |
} |
- |
|
153 |
|
- |
|
154 |
/* |
- |
|
155 |
* ADC end conversion callback. |
- |
|
156 |
* The PWM channels are reprogrammed using the latest ADC samples. |
- |
|
157 |
* The latest samples are transmitted into a single SPI transaction. |
- |
|
158 |
*/ |
- |
|
159 |
void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) { |
- |
|
160 |
|
- |
|
161 |
(void) buffer; (void) n; |
- |
|
162 |
/* Note, only in the ADC_COMPLETE state because the ADC driver fires an |
- |
|
163 |
intermediate callback when the buffer is half full.*/ |
- |
|
164 |
if (adcp->state == ADC_COMPLETE) { |
- |
|
165 |
adcsample_t avg_ch1, avg_ch2; |
- |
|
166 |
|
- |
|
167 |
/* Calculates the average values from the ADC samples.*/ |
- |
|
168 |
avg_ch1 = (samples[0] + samples[2] + samples[4] + samples[6]) / 4; |
- |
|
169 |
avg_ch2 = (samples[1] + samples[3] + samples[5] + samples[7]) / 4; |
- |
|
170 |
|
- |
|
171 |
chSysLockFromIsr(); |
- |
|
172 |
|
- |
|
173 |
/* Changes the channels pulse width, the change will be effective |
- |
|
174 |
starting from the next cycle.*/ |
- |
|
175 |
pwmEnableChannelI(&PWMD4, 0, PWM_FRACTION_TO_WIDTH(&PWMD4, 4096, avg_ch1)); |
- |
|
176 |
pwmEnableChannelI(&PWMD4, 1, PWM_FRACTION_TO_WIDTH(&PWMD4, 4096, avg_ch2)); |
- |
|
177 |
|
- |
|
178 |
|
- |
|
179 |
chSysUnlockFromIsr(); |
- |
|
180 |
} |
- |
|
181 |
} |
- |
|
182 |
|
- |
|
183 |
/* |
77 |
/* |
184 |
* Vlakno pro ovladani odpalovaci sekvence |
78 |
* Vlakno pro ovladani odpalovaci sekvence |
185 |
*/ |
79 |
*/ |
186 |
static WORKING_AREA(waThread_odpal, 128); |
80 |
static WORKING_AREA(waThread_odpal, 128); |
187 |
static msg_t Thread_odpal(void *arg) { |
81 |
static msg_t Thread_odpal(void *arg) { |
188 |
uint8_t stav = 0; // rika, ve ktere fazi je odpalovani |
82 |
uint8_t stav = 0; // rika, ve ktere fazi je odpalovani |
189 |
uint8_t odpal_povolen = 0; |
83 |
uint8_t odpal_povolen = 0; |
- |
|
84 |
uint8_t msg_zrusen[] = "Odpal zrusen uzivatelem.\r\n"; |
- |
|
85 |
uint8_t odpal_pomocna = 0; |
190 |
(void)arg; |
86 |
(void)arg; |
191 |
chRegSetThreadName("Odpal_vlakno"); |
87 |
chRegSetThreadName("Odpal_vlakno"); |
- |
|
88 |
|
- |
|
89 |
|
192 |
while (TRUE) |
90 |
while (TRUE) |
193 |
{ |
91 |
{ |
194 |
msg_t msg; |
92 |
msg_t msg; |
195 |
|
93 |
|
196 |
/* Waiting for the IRQ to happen.*/ |
94 |
/* Waiting for the IRQ to happen.*/ |
Line 200... |
Line 98... |
200 |
msg = chThdSelf()->p_u.rdymsg; /* Retrieving the message, optional.*/ |
98 |
msg = chThdSelf()->p_u.rdymsg; /* Retrieving the message, optional.*/ |
201 |
chSysUnlock(); |
99 |
chSysUnlock(); |
202 |
/* Perform processing here.*/ |
100 |
/* Perform processing here.*/ |
203 |
if(msg == 1) |
101 |
if(msg == 1) |
204 |
{ |
102 |
{ |
205 |
odpal_povolen = 1; |
103 |
odpal_povolen = 1; |
- |
|
104 |
odpal_pomocna++; |
- |
|
105 |
} |
- |
|
106 |
else if (msg == 2) //Pokud se ma odpal zrusit v prubehu |
- |
|
107 |
{ |
- |
|
108 |
odpal_povolen = 0; |
- |
|
109 |
odpal_pomocna = 0; |
- |
|
110 |
stav = 0; |
- |
|
111 |
sdWrite(&SD1, msg_zrusen, sizeof(msg_zrusen)/sizeof(uint8_t)); |
206 |
} |
112 |
} |
- |
|
113 |
else if (msg == 50 && odpal_povolen == 1) // preruseni od GPT |
- |
|
114 |
{ |
207 |
if (odpal_povolen == 1) |
115 |
odpal_pomocna = 1; |
- |
|
116 |
} |
- |
|
117 |
if (odpal_povolen == 1 && odpal_pomocna <= 1) |
208 |
{ |
118 |
{ |
- |
|
119 |
odpal_pomocna = 2; // aby nepretelkla tato promenna |
209 |
switch (stav) |
120 |
switch (stav) |
210 |
{ |
121 |
{ |
211 |
case 0: |
122 |
case 0: |
212 |
sdWrite(&SD1,"0",2); |
123 |
sdWrite(&SD1,"0\r\n",3); |
213 |
gptStartOneShot(&GPTD2,1000); |
124 |
gptStartOneShot(&GPTD2,1000); |
214 |
break; |
125 |
break; |
215 |
case 1: |
126 |
case 1: |
216 |
sdWrite(&SD1,"1",2); |
127 |
sdWrite(&SD1,"1\r\n",3); |
217 |
gptStartOneShot(&GPTD2,1500); |
128 |
gptStartOneShot(&GPTD2,1500); |
218 |
break; |
129 |
break; |
219 |
case 2: |
130 |
case 2: |
220 |
sdWrite(&SD1,"2",2); |
131 |
sdWrite(&SD1,"2\r\n",3); |
221 |
gptStartOneShot(&GPTD2,2000); |
132 |
gptStartOneShot(&GPTD2,2000); |
222 |
break; |
133 |
break; |
223 |
case 3: |
134 |
case 3: |
224 |
sdWrite(&SD1,"3",2); |
135 |
sdWrite(&SD1,"3\r\n",3); |
225 |
gptStartOneShot(&GPTD2,3000); |
136 |
gptStartOneShot(&GPTD2,3000); |
226 |
break; |
137 |
break; |
227 |
case 4: |
138 |
case 4: |
228 |
sdWrite(&SD1,"4",2); |
139 |
sdWrite(&SD1,"4\r\n",3); |
229 |
gptStartOneShot(&GPTD2,5000); |
140 |
gptStartOneShot(&GPTD2,5000); |
230 |
break; |
141 |
break; |
231 |
default: |
142 |
default: |
232 |
sdWrite(&SD1,"konec",6); //posledni krok |
143 |
sdWrite(&SD1,"konec\r\n",7); //posledni krok |
233 |
odpal_povolen = 0; |
144 |
odpal_povolen = 0; |
- |
|
145 |
odpal_pomocna = 0; |
234 |
stav = 0; |
146 |
stav = 0; |
235 |
break; |
147 |
break; |
236 |
} |
148 |
} |
237 |
stav++; |
149 |
stav++; |
238 |
} |
150 |
} |
239 |
} |
151 |
} |
240 |
} |
152 |
} |
241 |
|
153 |
|
242 |
|
154 |
|
243 |
/* |
155 |
/* |
244 |
* Vlakno pro obsluhu GPS prijimace |
156 |
* Vlakno pro obsluhu GPS prijimace |
Line 254... |
Line 166... |
254 |
char *konec_retezce; |
166 |
char *konec_retezce; |
255 |
uint8_t pocet_znaku; |
167 |
uint8_t pocet_znaku; |
256 |
uint8_t NMEA_zprava[100]; |
168 |
uint8_t NMEA_zprava[100]; |
257 |
|
169 |
|
258 |
(void)arg; |
170 |
(void)arg; |
259 |
chRegSetThreadName("GPS_NMEA"); |
171 |
chRegSetThreadName("GPS_NMEA"); |
260 |
/* |
- |
|
261 |
* Activates the serial driver 2 using the driver default configuration. |
- |
|
262 |
* PA2 and PA3 are routed to USART2. |
- |
|
263 |
*/ |
- |
|
264 |
|
- |
|
265 |
sdStart(&SD2, &USART2_config); |
- |
|
266 |
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); //TX |
- |
|
267 |
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); //RX |
- |
|
268 |
|
- |
|
269 |
|
172 |
|
270 |
while (TRUE) { |
173 |
while (TRUE) { |
271 |
chThdSleepMilliseconds(1000); //neni potreba data vycitat rychleji |
174 |
chThdSleepMilliseconds(1000); //neni potreba data vycitat rychleji |
272 |
sdRead(&SD2,inBuffer,GPS_BUFFER); |
175 |
sdRead(&SD2,inBuffer,GPS_BUFFER); |
273 |
|
176 |
|
Line 303... |
Line 206... |
303 |
sdWrite(&SD2,"\r\n",2); |
206 |
sdWrite(&SD2,"\r\n",2); |
304 |
} |
207 |
} |
305 |
else |
208 |
else |
306 |
{ |
209 |
{ |
307 |
sdWrite(&SD2,"\r\n",2); |
210 |
sdWrite(&SD2,"\r\n",2); |
308 |
sdWrite(&SD2,"Nenalezen ukoncovaci znak NMEA zpravy *",sizeof("Nenalezen ukoncovaci znak NMEA zpravy *")/sizeof(char)); |
211 |
sdWrite(&SD2,"Nenalezen ukoncovaci znak NMEA zpravy *\r\n",sizeof("Nenalezen ukoncovaci znak NMEA zpravy *\r\n")/sizeof(char)); |
309 |
sdWrite(&SD2,inBuffer,GPS_BUFFER); |
212 |
sdWrite(&SD2,inBuffer,GPS_BUFFER); |
310 |
sdWrite(&SD2,"\r\n",2); |
- |
|
311 |
} |
213 |
} |
312 |
} |
214 |
} |
313 |
else |
215 |
else |
314 |
sdWrite(&SD2,"Nenalezen zacatek GPGGA zpravy",sizeof("Nenalezen zacatek GPGGA zpravy")/sizeof(char)); |
216 |
sdWrite(&SD2,"Nenalezen zacatek GPGGA zpravy\r\n",sizeof("Nenalezen zacatek GPGGA zpravy\r\n")/sizeof(char)); |
315 |
|
217 |
|
316 |
} |
218 |
} |
317 |
} |
219 |
} |
318 |
|
220 |
|
319 |
/* |
- |
|
320 |
* This is a periodic thread that does absolutely nothing except increasing |
- |
|
321 |
* a seconds counter. |
- |
|
322 |
*/ |
- |
|
323 |
static WORKING_AREA(waThread1, 128); |
- |
|
324 |
static msg_t Thread1(void *arg) { |
- |
|
325 |
static uint32_t seconds_counter; |
- |
|
326 |
|
- |
|
327 |
(void)arg; |
- |
|
328 |
chRegSetThreadName("counter"); |
- |
|
329 |
while (TRUE) { |
- |
|
330 |
chThdSleepMilliseconds(1000); |
- |
|
331 |
seconds_counter++; |
- |
|
332 |
} |
- |
|
333 |
} |
- |
|
334 |
|
- |
|
335 |
void dekodujPrikaz(char *prikaz) |
221 |
void dekodujPrikaz(char *prikaz) |
336 |
{ |
222 |
{ |
337 |
//int8_t porov; |
- |
|
338 |
//porov = strcmp(prikaz,"ahoj"); |
- |
|
339 |
if(strcmp(prikaz,"odpal") == 0) |
223 |
if(strcmp(prikaz,"odpal") == 0) |
340 |
{ |
224 |
{ |
341 |
/* Wakes up the thread.*/ |
225 |
/* Wakes up the thread.*/ |
342 |
chSysLockFromIsr(); |
226 |
chSysLockFromIsr(); |
343 |
if (tp_odpal != NULL) { |
227 |
if (tp_odpal != NULL) { |
Line 346... |
Line 230... |
346 |
tp_odpal = NULL; |
230 |
tp_odpal = NULL; |
347 |
} |
231 |
} |
348 |
chSysUnlockFromIsr(); |
232 |
chSysUnlockFromIsr(); |
349 |
palTogglePad(GPIOB, GPIOB_LED4); |
233 |
palTogglePad(GPIOB, GPIOB_LED4); |
350 |
} |
234 |
} |
351 |
else if (strcmp(prikaz,"zdar") == 0) |
235 |
else if (strcmp(prikaz,"zrus") == 0) |
352 |
{ |
236 |
{ |
- |
|
237 |
/* Wakes up the thread.*/ |
- |
|
238 |
chSysLockFromIsr(); |
- |
|
239 |
if (tp_odpal != NULL) { |
- |
|
240 |
tp_odpal->p_u.rdymsg = (msg_t)2; /* zakazano pokracovat v odpalovaci sekvenci*/ |
353 |
palTogglePad(GPIOB, GPIOB_LED3); |
241 |
chSchReadyI(tp_odpal); |
- |
|
242 |
tp_odpal = NULL; |
- |
|
243 |
} |
- |
|
244 |
chSysUnlockFromIsr(); |
354 |
} |
245 |
} |
355 |
else |
246 |
else |
356 |
{ |
247 |
{ |
357 |
uint8_t zp_neplatny[] = "Neplatny prikaz, spravny format *<prikaz>\n\r"; |
248 |
uint8_t zp_neplatny[] = "Neplatny prikaz, spravny format *<prikaz>\n\r"; |
358 |
sdWrite(&SD1,zp_neplatny,sizeof(zp_neplatny)/sizeof(uint8_t)); |
249 |
sdWrite(&SD1,zp_neplatny,sizeof(zp_neplatny)/sizeof(uint8_t)); |
359 |
palTogglePad(GPIOB, GPIOB_LED3); |
250 |
palTogglePad(GPIOB, GPIOB_LED3); |
360 |
} |
251 |
} |
361 |
} |
252 |
} |
362 |
|
- |
|
363 |
|
- |
|
364 |
|
253 |
|
365 |
/* |
254 |
/* |
366 |
* Application entry point. |
255 |
* Application entry point. |
367 |
*/ |
256 |
*/ |
368 |
int main(void) { |
257 |
int main(void) { |
- |
|
258 |
|
369 |
uint8_t znaky[20]; |
259 |
uint8_t znaky[20]; |
370 |
char prikaz[MAX_DELKA_PRIKAZU + 1]; |
260 |
char prikaz[MAX_DELKA_PRIKAZU + 1]; |
371 |
uint8_t pocet_znaku = 0; |
261 |
uint8_t pocet_znaku = 0; |
372 |
|
262 |
|
373 |
/* |
263 |
/* |
Line 378... |
Line 268... |
378 |
* RTOS is active. |
268 |
* RTOS is active. |
379 |
*/ |
269 |
*/ |
380 |
halInit(); |
270 |
halInit(); |
381 |
chSysInit(); |
271 |
chSysInit(); |
382 |
|
272 |
|
383 |
/* |
273 |
/* |
384 |
* Activates the serial driver 1 using the driver default configuration. |
274 |
* Activates the serial driver 1 using the driver default configuration. |
385 |
* PA9 and PA10 are routed to USART1. |
275 |
* PA9 and PA10 are routed to USART1. |
- |
|
276 |
* Komunikace s uzivatelem |
386 |
*/ |
277 |
*/ |
387 |
sdStart(&SD1, NULL); |
278 |
sdStart(&SD1, NULL); |
388 |
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); //TX |
279 |
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); //TX |
389 |
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); //RX |
280 |
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); //RX |
390 |
|
281 |
|
391 |
//gptObjectInit(&GPTD2); |
- |
|
392 |
/* |
- |
|
393 |
* aktivuje timer2 a prejde tak do aktivniho stavu |
- |
|
394 |
*/ |
- |
|
395 |
gptStart(&GPTD2,&gpt2cfg); |
- |
|
396 |
|
- |
|
397 |
/* |
- |
|
398 |
* If the user button is pressed after the reset then the test suite is |
- |
|
399 |
* executed immediately before activating the various device drivers in |
- |
|
400 |
* order to not alter the benchmark scores. |
- |
|
401 |
*/ |
- |
|
402 |
if (palReadPad(GPIOA, GPIOA_BUTTON)) |
- |
|
403 |
TestThread(&SD1); |
- |
|
404 |
|
- |
|
405 |
/* |
- |
|
406 |
* Initializes the SPI driver 2. The SPI2 signals are routed as follow: |
- |
|
407 |
* PB12 - NSS. |
- |
|
408 |
* PB13 - SCK. |
- |
|
409 |
* PB14 - MISO. |
- |
|
410 |
* PB15 - MOSI. |
- |
|
411 |
*/ |
- |
|
412 |
palSetPad(GPIOB, 12); |
- |
|
413 |
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL | |
- |
|
414 |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */ |
- |
|
415 |
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) | |
- |
|
416 |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */ |
- |
|
417 |
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5)); /* MISO. */ |
- |
|
418 |
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) | |
- |
|
419 |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */ |
- |
|
420 |
|
- |
|
421 |
/* |
- |
|
422 |
* Initializes the ADC driver 1 and enable the thermal sensor. |
- |
|
423 |
* The pin PC0 on the port GPIOC is programmed as analog input. |
- |
|
424 |
*/ |
- |
|
425 |
adcStart(&ADCD1, NULL); |
- |
|
426 |
adcSTM32EnableTSVREFE(); |
- |
|
427 |
palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG); |
- |
|
428 |
|
- |
|
429 |
/* |
282 |
/* |
430 |
* Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs. |
283 |
* Activates the serial driver 2 using the driver default configuration. |
- |
|
284 |
* PA2 and PA3 are routed to USART2. |
- |
|
285 |
*GPS |
431 |
*/ |
286 |
*/ |
432 |
pwmStart(&PWMD4, &pwmcfg); |
287 |
sdStart(&SD2, &USART2_config); |
433 |
//palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_ALTERNATE(2)); |
288 |
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); //TX |
434 |
palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_ALTERNATE(2)); |
289 |
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); //RX |
- |
|
290 |
|
435 |
/* |
291 |
/* |
436 |
* Zelena led aktivace portu |
292 |
* LED na vyvojove desce |
437 |
*/ |
293 |
*/ |
438 |
|
- |
|
439 |
palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_OUTPUT_PUSHPULL); |
294 |
palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_OUTPUT_PUSHPULL); |
440 |
palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL); |
295 |
palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL); |
441 |
|
296 |
|
442 |
/* |
297 |
/* |
443 |
* Creates the example thread. |
298 |
* Porty pro vypousteci sekvenci |
444 |
*/ |
299 |
*/ |
- |
|
300 |
palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); |
- |
|
301 |
palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); |
- |
|
302 |
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL); |
445 |
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
303 |
palSetPadMode(GPIOB, 13, PAL_MODE_OUTPUT_PUSHPULL); |
- |
|
304 |
/* |
- |
|
305 |
* Aktivuje timer2 a prejde tak do aktivniho stavu |
- |
|
306 |
*/ |
- |
|
307 |
gptStart(&GPTD2,&gpt2cfg); |
- |
|
308 |
|
446 |
|
309 |
|
447 |
/* |
310 |
/* |
448 |
* Vytvori vlakno pro prijem dat z GPS modulu |
311 |
* Vytvori vlakno pro prijem dat z GPS modulu |
449 |
*/ |
312 |
*/ |
450 |
chThdCreateStatic(waThread_GPS, sizeof(waThread_GPS), NORMALPRIO, Thread_GPS, NULL); |
313 |
chThdCreateStatic(waThread_GPS, sizeof(waThread_GPS), NORMALPRIO, Thread_GPS, NULL); |
- |
|
314 |
|
451 |
/* |
315 |
/* |
452 |
* Vytvori vlakno pro odpalovaci sekvenci |
316 |
* Vytvori vlakno pro odpalovaci sekvenci |
453 |
*/ |
317 |
*/ |
454 |
(void)chThdCreateStatic (waThread_odpal, sizeof(waThread_odpal), NORMALPRIO, Thread_odpal, NULL); |
318 |
chThdCreateStatic (waThread_odpal, sizeof(waThread_odpal), NORMALPRIO, Thread_odpal, NULL); |
455 |
|
- |
|
456 |
|
319 |
|
457 |
/* |
320 |
/* |
458 |
* Normal main() thread activity, in this demo it does nothing except |
321 |
* Normal main() thread activity, in this demo it does nothing except |
459 |
* sleeping in a loop and check the button state, when the button is |
322 |
* sleeping in a loop and check the button state, when the button is |
460 |
* pressed the test procedure is launched with output on the serial |
323 |
* pressed the test procedure is launched with output on the serial |
461 |
* driver 1. |
324 |
* driver 1. |
462 |
*/ |
325 |
*/ |
463 |
while (TRUE) { |
326 |
while (TRUE) { |
464 |
|
- |
|
465 |
sdRead(&SD1,znaky,1); |
327 |
sdRead(&SD1,znaky,1); |
466 |
/*Kdyz uzivatel stiskne enter -> dekoduj a vykonej prikaz*/ |
328 |
/*Kdyz uzivatel stiskne enter -> dekoduj a vykonej prikaz, nebo pokud je prikaz delsi, nez by mel byt, |
- |
|
329 |
*prestane ukladat a upozorni uzivatele |
- |
|
330 |
*/ |
467 |
if (znaky[0] == '\r') |
331 |
if (znaky[0] == '\r' || pocet_znaku >= MAX_DELKA_PRIKAZU) |
468 |
{ |
332 |
{ |
469 |
pocet_znaku = 0; |
333 |
pocet_znaku = 0; |
470 |
dekodujPrikaz(prikaz); |
334 |
dekodujPrikaz(prikaz); |
471 |
prikaz[0] = 0; |
335 |
prikaz[0] = 0; |
472 |
} |
336 |
} |
473 |
/*Uklada prikaz*/ |
337 |
/*Uklada prikaz*/ |
474 |
else if (pocet_znaku < MAX_DELKA_PRIKAZU) |
338 |
else |
475 |
{ |
339 |
{ |
476 |
prikaz[pocet_znaku + 1] = 0; |
340 |
prikaz[pocet_znaku + 1] = 0; |
477 |
prikaz[pocet_znaku++] = znaky[0]; |
341 |
prikaz[pocet_znaku++] = znaky[0]; |
478 |
} |
342 |
} |
479 |
/*Pokud je prikaz delsi, nez by mel byt, prestane ukladat a upozorni uzivatele*/ |
- |
|
480 |
else |
- |
|
481 |
{ |
- |
|
482 |
pocet_znaku = 0; |
- |
|
483 |
dekodujPrikaz(prikaz); |
- |
|
484 |
} |
- |
|
485 |
/* |
- |
|
486 |
if (palReadPad(GPIOA, GPIOA_BUTTON)) |
- |
|
487 |
|
- |
|
488 |
TestThread(&SD1); |
- |
|
489 |
chThdSleepMilliseconds(500); |
- |
|
490 |
*/ |
- |
|
491 |
} |
343 |
} |
492 |
} |
344 |
} |