Skip to content

Commit 9814d55

Browse files
committed
corrigido o problema que impedia a execução da função delay() dentro do
setup(). Criei uma nova estrutura em main.c onde a função setup() passa a ser uma tarefa executada uma unica vez antes de loop() que está em estado suspenso até que setup() setup termine e seja posta em modo suspenso. Para o arduino mega setup será removido quando loop() for iniciado. Estarei verificando se é interessante ativar vTaskDelete() para outros ATMega por questões de memoria.
1 parent 3c922a4 commit 9814d55

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

arduino.DuinOS.AVR/DuinOS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ inline void delay(const portTickType ticks)
7979
vTaskDelayUntil( &xLastWakeTime, ticks);
8080
}
8181
*/
82+
#if INCLUDE_vTaskDelete
83+
#define deleteTask(name) vTaskDelete(name);
84+
#endif
8285

8386
//This macro is quiet different from setPriority, because this works even in those CPUs wich does not support
8487
//the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup().

arduino.DuinOS.AVR/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
#define INCLUDE_vTaskPrioritySet 1
232232
#define INCLUDE_uxTaskPriorityGet 1
233233
//##If the following value is set to 1, change the memory managment scheme to heap_2.c:
234-
#define INCLUDE_vTaskDelete 0
234+
#define INCLUDE_vTaskDelete 1
235235
#define INCLUDE_vTaskCleanUpResources 0
236236
#define INCLUDE_vTaskSuspend 1
237237
#define INCLUDE_vTaskDelayUntil 1

arduino.DuinOS.AVR/main.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
#include <Arduino.h>
22

3+
34
unsigned portBASE_TYPE mainLoopPriority;
45

6+
xTaskHandle xHandleLoop;
7+
xTaskHandle xHandleSetup;
8+
59
void main_Task(void *pvParameters)
610
{
11+
#if INCLUDE_vTaskDelete
12+
vTaskDelete(xHandleSetup);
13+
#endif
714
for (;;) {
815
loop();
916
if (serialEventRun) serialEventRun();
1017
}
1118

1219
}
1320

21+
void setup_Task(void *pvParameters)
22+
{
23+
24+
setup();
25+
vTaskResume(xHandleLoop);
26+
vTaskSuspend(NULL);
27+
28+
}
29+
1430
int main(void)
1531
{
1632
mainLoopPriority = LOW_PRIORITY;
@@ -19,12 +35,16 @@ int main(void)
1935
#if defined(USBCON)
2036
USBDevice.attach();
2137
#endif
22-
23-
setup();
24-
25-
xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL);
38+
39+
// setup();
40+
41+
xTaskCreate(setup_Task, (signed portCHAR *) "setup", configMINIMAL_STACK_SIZE, NULL, HIGH_PRIORITY, &xHandleSetup);
42+
43+
xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, &xHandleLoop);
44+
vTaskSuspend(xHandleLoop);
45+
2646
vTaskStartScheduler();
27-
47+
2848
for (;;);
2949

3050
return 0;

0 commit comments

Comments
 (0)