From 9e05eaaf91c2596521e29b90ffa9adf3114c3b93 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 28 Jan 2011 20:11:32 +0100 Subject: Proper mutex usage, and protecting malloc and sbrk using them. Also showing this into the demo. --- demo.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'demo.c') diff --git a/demo.c b/demo.c index 41eaacb..59b41ca 100644 --- a/demo.c +++ b/demo.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -31,16 +32,22 @@ static void litLED(int led, int value) { } } +xSemaphoreHandle handle; + static void simpleTask1(void *p) { while (1) { + xSemaphoreTake(handle, portMAX_DELAY); BoardConsolePuts("Task 1"); + xSemaphoreGive(handle); vTaskDelay(1234); } } static void simpleTask2(void *p) { while (1) { + xSemaphoreTake(handle, portMAX_DELAY); BoardConsolePuts("Task 2"); + xSemaphoreGive(handle); vTaskDelay(1357); } } @@ -52,14 +59,16 @@ static void badTask(void *x) { } int main() { + handle = xSemaphoreCreateMutex(); + setupLEDs(); litLED(1, 0); litLED(2, 0); litLED(3, 0); litLED(4, 0); BoardConsolePuts("Creating simple tasks."); - xTaskCreate(simpleTask1, (signed char *) "st1", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY | portPRIVILEGE_BIT, NULL); - xTaskCreate(simpleTask2, (signed char *) "st2", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY | portPRIVILEGE_BIT, NULL); + xTaskCreate(simpleTask1, (signed char *) "st1", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL); + xTaskCreate(simpleTask2, (signed char *) "st2", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL); xTaskCreate(badTask, (signed char *) "bad", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL); BoardConsolePuts("Scheduler starting."); vTaskStartScheduler(); -- cgit v1.2.3