Rev 2952 Rev 2954
Line 19... Line 19...
19 #include "test.h" 19 #include "test.h"
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 #include <../../os/various/chprintf.h>
-   25 #include <chstreams.h.>
24   26  
25 /*MAX delka prikazu, ktery uzivatel muze zadat*/ 27 /*MAX delka prikazu, ktery uzivatel muze zadat*/
26 #define MAX_DELKA_PRIKAZU 10 28 #define MAX_DELKA_PRIKAZU 10
27   29  
28 /*Velikost GPS bufferu*/ 30 /*Velikost GPS bufferu*/
29 #define GPS_BUFFER 500 31 #define GPS_BUFFER 500
-   32 #define PWM_PERIODA_NORMAL 20000
-   33 #define PWM_SIRKA_NORMAL PWM_PERIODA_NORMAL/2
30   34  
31 extern NMEA_GPGGA GPGGA_informace; 35 extern NMEA_GPGGA GPGGA_informace;
32 Thread *tp_odpal = NULL; 36 Thread *tp_odpal = NULL;
33 uint8_t uvitaci_zprava[] = "\r\n\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\nVita vas Automaticky Vypoustec Meteobalonu 1.1\r\nZapojeni vyvodu:\r\n\tGPIOB10 - ventil\r\n\tGPIOB11 - lis\r\n\tGPIOB12 - zataveni balonu\r\n\tGPIOB13 - otevreni krytu\r\nPrikazy:\r\n\t<odpal> zahajeni sekvence vypousteni\n\r\t<zrus> zruseni vypousteni\n\r\t<help> napoveda\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\n\r\n"; 37 uint8_t uvitaci_zprava[] = "\r\n\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\nVita vas Automaticky Vypoustec Meteobalonu 1.1\r\nZapojeni vyvodu:\r\n\tGPIOB10 - ventil\r\n\tGPIOB11 - lis\r\n\tGPIOB12 - zataveni balonu\r\n\tGPIOB13 - otevreni krytu\r\nPrikazy:\r\n\t<odpal> zahajeni sekvence vypousteni\n\r\t<zrus> zruseni vypousteni\n\r\t<help> napoveda\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\n\r\n";
34   38  
-   39 static PWMConfig pwmcfg = {
-   40 10000, /* 10kHz PWM clock frequency. */
-   41 PWM_PERIODA_NORMAL, /* PWM period 1S (in ticks). */
-   42 NULL,
-   43 {
-   44 {PWM_OUTPUT_ACTIVE_HIGH, NULL},
-   45 {PWM_OUTPUT_ACTIVE_HIGH, NULL},
-   46 {PWM_OUTPUT_DISABLED, NULL},
-   47 {PWM_OUTPUT_DISABLED, NULL}
-   48 },
-   49 /* HW dependent part.*/
-   50 0
-   51 };
-   52  
35 /* 53 /*
36 * Konfigurace USART2 54 * Konfigurace USART2
37 */ 55 */
38   56  
39 static const SerialConfig USART2_config = 57 static const SerialConfig USART2_config =
Line 46... Line 64...
46 USART_CR2_STOP1_BITS | USART_CR2_LINEN, 64 USART_CR2_STOP1_BITS | USART_CR2_LINEN,
47 /*Initialization value for the CR3 register.*/ 65 /*Initialization value for the CR3 register.*/
48 0 66 0
49 }; 67 };
50   68  
-   69  
51 /* 70 /*
52 * GPT2 callback. 71 * GPT2 callback.
53 */ 72 */
54 static void gpt2cb(GPTDriver *gptp) 73 static void gpt2cb(GPTDriver *gptp)
55 { 74 {
56 (void)gptp; 75 (void)gptp;
57 palTogglePad(GPIOB, GPIOB_LED4); -  
58 /* Wakes up the thread.*/ 76 /* Wakes up the thread.*/
59 chSysLockFromIsr(); 77 chSysLockFromIsr();
60 if (tp_odpal != NULL) { 78 if (tp_odpal != NULL) {
61 tp_odpal->p_u.rdymsg = (msg_t)50; /* Znaci, ze se vlakno probouzi kvuli preruseni od GPT*/ 79 tp_odpal->p_u.rdymsg = (msg_t)50; /* Znaci, ze se vlakno probouzi kvuli preruseni od GPT*/
62 chSchReadyI(tp_odpal); 80 chSchReadyI(tp_odpal);
63 tp_odpal = NULL; 81 tp_odpal = NULL;
64 } 82 }
65 chSysUnlockFromIsr(); 83 chSysUnlockFromIsr();
66 } 84 }
67   85  
-   86  
68 /* 87 /*
69 *Konfigurace casovace 2 88 *Konfigurace casovace 2
70 */ 89 */
71 static const GPTConfig gpt2cfg = 90 static const GPTConfig gpt2cfg =
72 { 91 {
Line 80... Line 99...
80 */ 99 */
81 static WORKING_AREA(waThread_odpal, 128); 100 static WORKING_AREA(waThread_odpal, 128);
82 static msg_t Thread_odpal(void *arg) { 101 static msg_t Thread_odpal(void *arg) {
83 uint8_t stav = 0; // rika, ve ktere fazi je odpalovani 102 uint8_t stav = 0; // rika, ve ktere fazi je odpalovani
84 uint8_t odpal_povolen = 0; 103 uint8_t odpal_povolen = 0;
85 uint8_t msg_zrusen[] = "Odpal zrusen uzivatelem.\r\n"; -  
86 uint8_t odpal_pomocna = 0; 104 uint8_t odpal_pomocna = 0;
-   105 uint8_t pocet_opakovani = 1;
-   106 uint16_t perioda_casovace = 500;
87 (void)arg; 107 (void)arg;
88 chRegSetThreadName("Odpal_vlakno"); 108 chRegSetThreadName("Odpal_vlakno");
89 109
90 110
91 while (TRUE) 111 while (TRUE)
Line 101... Line 121...
101 /* Perform processing here.*/ 121 /* Perform processing here.*/
102 if(msg == 1) 122 if(msg == 1)
103 { 123 {
104 odpal_povolen = 1; 124 odpal_povolen = 1;
105 odpal_pomocna++; 125 odpal_pomocna++;
-   126 stav = 0;
-   127 pocet_opakovani = 1;
106 } 128 }
107 else if (msg == 2) //Pokud se ma odpal zrusit v prubehu 129 else if (msg == 2) //Pokud se ma odpal zrusit v prubehu vypousteni
108 { 130 {
109 /* 131 /*
110 * Pro jistotu se vypnou vsechny vystupy pri zruseni odpalu 132 * Pro jistotu se vypnou vsechny vystupy pri zruseni odpalu
111 */ 133 */
112 palClearPad(GPIOB, GPIOB_PIN10); 134 palClearPad(GPIOB, GPIOB_PIN10);
113 palClearPad(GPIOB, GPIOB_PIN11); 135 palClearPad(GPIOB, GPIOB_PIN11);
114 palClearPad(GPIOB, GPIOB_PIN12); 136 palClearPad(GPIOB, GPIOB_PIN12);
115 palClearPad(GPIOB, GPIOB_PIN13); 137 palClearPad(GPIOB, GPIOB_PIN13);
116 138
-   139 if(odpal_povolen == 1)
-   140 chprintf((BaseSequentialStream *)&SD1,"\r\nOdpal zrusen uzivatelem.\r\n");
-   141 else
-   142 chprintf((BaseSequentialStream *)&SD1,"Odpal nebyl aktivovan.\r\n");
-   143
117 odpal_povolen = 0; 144 odpal_povolen = 0;
118 odpal_pomocna = 0; 145 odpal_pomocna = 0;
119 stav = 0; 146 stav = 0;
120 sdWrite(&SD1, msg_zrusen, sizeof(msg_zrusen)/sizeof(uint8_t)); 147 pocet_opakovani = 1;
121 } 148 }
122 else if (msg == 50 && odpal_povolen == 1) // preruseni od GPT 149 else if (msg == 50 && odpal_povolen == 1) // preruseni od GPT
123 { 150 {
124 odpal_pomocna = 1; 151 odpal_pomocna = 1;
125 } 152 }
Line 127... Line 154...
127 { 154 {
128 odpal_pomocna = 2; // aby nepretelkla tato promenna 155 odpal_pomocna = 2; // aby nepretelkla tato promenna
129 switch (stav) 156 switch (stav)
130 { 157 {
131 case 0: 158 case 0:
-   159 if (pocet_opakovani == 1)
132 sdWrite(&SD1,"Vypousteni zahajeno!\r\n",sizeof("Vypousteni zahajeno!\r\n")/sizeof(char)); 160 chprintf((BaseSequentialStream *)&SD1,"Vypousteni zahajeno!\r\n");
-   161
-   162 if (pocet_opakovani <= 20)
-   163 {
133 sdWrite(&SD1,"(1/4)\tVentil otevren -> nafukovani balonu\r\n",sizeof("1/4)\tVentil otevren -> nafukovani balonu\r\n")/sizeof(char)); 164 //sdWrite(&SD1,,sizeof("1/4)\tVentil otevren -> nafukovani balonu\r\n")/sizeof(char));
-   165 chprintf((BaseSequentialStream *)&SD1,"(1/4)\tVentil otevren -> nafukovani balonu %d%%\r",pocet_opakovani*5);
134 palSetPad(GPIOB, GPIOB_PIN10); 166 palSetPad(GPIOB, GPIOB_PIN10);
135 gptStartOneShot(&GPTD2,10000); 167 gptStartOneShot(&GPTD2,perioda_casovace);
-   168 pocet_opakovani++;
-   169 if (pocet_opakovani == 21)
-   170 {
-   171 chprintf((BaseSequentialStream *)&SD1,"\r\n");
-   172 stav++;
-   173 pocet_opakovani = 1;
-   174 }
-   175 }
136 break; 176 break;
137 case 1: 177 case 1:
-   178 if (pocet_opakovani <= 10)
-   179 {
138 palClearPad(GPIOB, GPIOB_PIN10); 180 palClearPad(GPIOB, GPIOB_PIN10);
139 palSetPad(GPIOB, GPIOB_PIN11); 181 palSetPad(GPIOB, GPIOB_PIN11);
140 sdWrite(&SD1,"(2/4)\tPrepalovani lisu...\r\n",sizeof("(2/4)\tPrepalovani lisu...\r\n")/sizeof(char)); 182 chprintf((BaseSequentialStream *)&SD1,"(2/4)\tPrepalovani lisu... %d%%\r",pocet_opakovani*10);
141 gptStartOneShot(&GPTD2,5000); 183 gptStartOneShot(&GPTD2,perioda_casovace);
-   184 pocet_opakovani++;
-   185 if (pocet_opakovani == 11)
-   186 {
-   187 chprintf((BaseSequentialStream *)&SD1,"\r\n");
-   188 stav++;
-   189 pocet_opakovani = 1;
-   190 }
-   191 }
142 break; 192 break;
143 case 2: 193 case 2:
-   194 if (pocet_opakovani <= 10)
-   195 {
144 palClearPad(GPIOB, GPIOB_PIN11); 196 palClearPad(GPIOB, GPIOB_PIN11);
145 palSetPad(GPIOB, GPIOB_PIN12); 197 palSetPad(GPIOB, GPIOB_PIN12);
146 sdWrite(&SD1,"(3/4)\tZatavovani balonu...\r\n",sizeof("(3/4)\tZatavovani balonu...\r\n")/sizeof(char)); 198 chprintf((BaseSequentialStream *)&SD1,"(3/4)\tZatavovani balonu... %d%%\r",pocet_opakovani*10);
147 gptStartOneShot(&GPTD2,5000); 199 gptStartOneShot(&GPTD2,perioda_casovace);
-   200 pocet_opakovani++;
-   201 if (pocet_opakovani == 11)
-   202 {
-   203 chprintf((BaseSequentialStream *)&SD1,"\r\n");
-   204 stav++;
-   205 pocet_opakovani = 1;
-   206 }
-   207 }
148 break; 208 break;
149 case 3: 209 case 3:
-   210 if (pocet_opakovani <= 20)
-   211 {
150 palClearPad(GPIOB, GPIOB_PIN12); 212 palClearPad(GPIOB, GPIOB_PIN12);
151 palSetPad(GPIOB, GPIOB_PIN13); 213 palSetPad(GPIOB, GPIOB_PIN13);
152 sdWrite(&SD1,"(4/4)\tOtevirani vika...\r\n",sizeof("(4/4)\tOtevirani vika...\r\n")/sizeof(char)); 214 chprintf((BaseSequentialStream *)&SD1,"(4/4)\tOtevirani vika... %d%%\r",pocet_opakovani*5);
153 gptStartOneShot(&GPTD2,3000); 215 gptStartOneShot(&GPTD2,perioda_casovace);
-   216 pocet_opakovani++;
-   217 if (pocet_opakovani == 21)
-   218 {
-   219 chprintf((BaseSequentialStream *)&SD1,"\r\n");
-   220 stav++;
-   221 pocet_opakovani = 1;
-   222 }
-   223 }
154 break; 224 break;
155 case 4: 225 case 4:
156 palClearPad(GPIOB, GPIOB_PIN13); 226 palClearPad(GPIOB, GPIOB_PIN13);
157 sdWrite(&SD1,"Vypousteni ukonceno!\r\n",sizeof("Vypousteni ukonceno!\r\n")/sizeof(char)); 227 chprintf((BaseSequentialStream *)&SD1,"Vypousteni ukonceno!\r\n");
158 odpal_povolen = 0; 228 odpal_povolen = 0;
159 odpal_pomocna = 0; 229 odpal_pomocna = 0;
160 stav = 0; 230 stav = 0;
161 break; 231 break;
162 default: 232 default:
163 break; 233 break;
164 } 234 }
165 stav++; -  
166 } 235 }
167 } 236 }
168 } 237 }
169   238  
170   239  
Line 243... Line 312...
243 if (tp_odpal != NULL) { 312 if (tp_odpal != NULL) {
244 tp_odpal->p_u.rdymsg = (msg_t)1; /* odpal povolen*/ 313 tp_odpal->p_u.rdymsg = (msg_t)1; /* odpal povolen*/
245 chSchReadyI(tp_odpal); 314 chSchReadyI(tp_odpal);
246 tp_odpal = NULL; 315 tp_odpal = NULL;
247 } 316 }
248 chSysUnlockFromIsr(); 317 chSysUnlockFromIsr();
249 palTogglePad(GPIOB, GPIOB_LED4); -  
-   318  
250 } 319 }
251 else if (strcmp(prikaz,"zrus") == 0) 320 else if (strcmp(prikaz,"zrus") == 0)
252 { 321 {
253 /* Wakes up the thread.*/ 322 /* Wakes up the thread.*/
254 chSysLockFromIsr(); 323 chSysLockFromIsr();
255 if (tp_odpal != NULL) { 324 if (tp_odpal != NULL) {
256 tp_odpal->p_u.rdymsg = (msg_t)2; /* zakazano pokracovat v odpalovaci sekvenci*/ 325 tp_odpal->p_u.rdymsg = (msg_t)2; /* zakazano pokracovat v odpalovaci sekvenci*/
257 chSchReadyI(tp_odpal); 326 chSchReadyI(tp_odpal);
258 tp_odpal = NULL; 327 tp_odpal = NULL;
259 } 328 }
260 chSysUnlockFromIsr(); 329 chSysUnlockFromIsr();
261 } 330 }
262 else if (strcmp(prikaz,"help") == 0) 331 else if (strcmp(prikaz,"help") == 0)
263 { 332 {
264 sdWrite(&SD1, uvitaci_zprava, sizeof(uvitaci_zprava)/sizeof(uint8_t)); 333 sdWrite(&SD1, uvitaci_zprava, sizeof(uvitaci_zprava)/sizeof(uint8_t));
265 } 334 }
266 else 335 else
267 { 336 {
268 uint8_t zp_neplatny[] = "Neplatny prikaz, napiste <odpal> pro zahajeni sekvence\n\r ci <zrus> pro zruseni vypousteni\n\r"; 337 uint8_t zp_neplatny[] = "Neplatny prikaz!\r\n\t<odpal> pro zahajeni sekvence\n\r\t<zrus> pro zruseni vypousteni\n\r";
269 sdWrite(&SD1,zp_neplatny,sizeof(zp_neplatny)/sizeof(uint8_t)); 338 sdWrite(&SD1,zp_neplatny,sizeof(zp_neplatny)/sizeof(uint8_t));
270 palTogglePad(GPIOB, GPIOB_LED3); 339 palTogglePad(GPIOB, GPIOB_LED3);
271 } 340 }
272 } 341 }
273   342  
Line 309... Line 378...
309 palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); //RX 378 palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); //RX
310 379
311 /* 380 /*
312 * LED na vyvojove desce 381 * LED na vyvojove desce
313 */ 382 */
314 palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_OUTPUT_PUSHPULL); -  
315 palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL); 383 palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL);
316 384
317 /* 385 /*
318 * Porty pro vypousteci sekvenci 386 * Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs.
319 */ 387 */
320 palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); 388 pwmStart(&PWMD4, &pwmcfg);
321 palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); -  
322 palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL); 389 palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_ALTERNATE(2));
323 palSetPadMode(GPIOB, 13, PAL_MODE_OUTPUT_PUSHPULL); 390 pwmEnableChannel(&PWMD4,0,PWM_SIRKA_NORMAL);
-   391  
-   392
324 /* 393 /*
325 * Aktivuje timer2 a prejde tak do aktivniho stavu 394 * Porty pro vypousteci sekvenci
326 */ 395 */
-   396 palSetPadMode(GPIOB, GPIOB_PIN10, PAL_MODE_OUTPUT_PUSHPULL);
-   397 palClearPad(GPIOB, GPIOB_PIN10);
-   398 palSetPadMode(GPIOB, GPIOB_PIN11, PAL_MODE_OUTPUT_PUSHPULL);
327 gptStart(&GPTD2,&gpt2cfg); 399 palClearPad(GPIOB, GPIOB_PIN11);
-   400 palSetPadMode(GPIOB, GPIOB_PIN12, PAL_MODE_OUTPUT_PUSHPULL);
-   401 palClearPad(GPIOB, GPIOB_PIN12);
-   402 palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_OUTPUT_PUSHPULL);
-   403 palClearPad(GPIOB, GPIOB_PIN13);
328   404 /*
-   405 * Aktivuje timer2 a timer3 prejde tak do aktivniho stavu
329   406 */
-   407 gptStart(&GPTD2,&gpt2cfg);
330 /* 408 /*
331 * Vytvori vlakno pro prijem dat z GPS modulu 409 * Vytvori vlakno pro prijem dat z GPS modulu
332 */ 410 */
333 chThdCreateStatic(waThread_GPS, sizeof(waThread_GPS), NORMALPRIO, Thread_GPS, NULL); 411 chThdCreateStatic(waThread_GPS, sizeof(waThread_GPS), NORMALPRIO, Thread_GPS, NULL);
334 412
Line 342... Line 420...
342 * Normal main() thread activity, in this demo it does nothing except 420 * Normal main() thread activity, in this demo it does nothing except
343 * sleeping in a loop and check the button state, when the button is 421 * sleeping in a loop and check the button state, when the button is
344 * pressed the test procedure is launched with output on the serial 422 * pressed the test procedure is launched with output on the serial
345 * driver 1. 423 * driver 1.
346 */ 424 */
-   425  
347 while (TRUE) { 426 while (TRUE) {
-   427  
348 sdRead(&SD1,znaky,1); 428 sdRead(&SD1,znaky,1);
349 /*Kdyz uzivatel stiskne enter -> dekoduj a vykonej prikaz, nebo pokud je prikaz delsi, nez by mel byt, 429 /*Kdyz uzivatel stiskne enter -> dekoduj a vykonej prikaz, nebo pokud je prikaz delsi, nez by mel byt,
350 *prestane ukladat a upozorni uzivatele 430 *prestane ukladat a upozorni uzivatele
351 */ 431 */
352 if (znaky[0] == '\r' || pocet_znaku >= MAX_DELKA_PRIKAZU) 432 if (znaky[0] == '\r' || pocet_znaku >= MAX_DELKA_PRIKAZU)