diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-01-28 20:11:32 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-01-28 20:11:32 +0100 |
commit | 9e05eaaf91c2596521e29b90ffa9adf3114c3b93 (patch) | |
tree | 150d5d7fdbb6d9fbb93a4c1277a8132e1e423a07 /demo.c | |
parent | a0f170eb2100291429d31a057977a88ece219519 (diff) |
Proper mutex usage, and protecting malloc and sbrk using them. Also showing this into the demo.
Diffstat (limited to 'demo.c')
-rw-r--r-- | demo.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1,5 +1,6 @@ #include <FreeRTOS.h> #include <task.h> +#include <semphr.h> #include <lpc17xx_gpio.h> #include <BoardConsole.h> #include <osdebug.h> @@ -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(); |