Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FreeRTOS.h"
- #include "task.h"
- #include "semphr.h"
- #include "Console.h"
- #include "config.h"
- static SemaphoreHandle_t mutex = NULL;
- static void taskStrangeMutexDemo(void * params);
- void initStrangeMutexDemo() {
- configASSERT(mutex == NULL); /* should be called only once */
- configASSERT(mutex = xSemaphoreCreateMutex());
- xTaskCreate(
- taskStrangeMutexDemo, "Strange0", configMINIMAL_STACK_SIZE, NULL, BASE_TASK_PRIO, NULL);
- xTaskCreate(
- taskStrangeMutexDemo, "Strange1", configMINIMAL_STACK_SIZE, NULL, BASE_TASK_PRIO, NULL);
- }
- static void guardedMethod() {
- con_printf("Task %s is taking the mutex.\n", pcTaskGetTaskName(NULL));
- configASSERT(
- xSemaphoreTake(mutex, portMAX_DELAY));
- con_printf("Task %s has taken the mutex.\n", pcTaskGetTaskName(NULL));
- vTaskDelay(pdMS_TO_TICKS(1000));
- configASSERT(
- xSemaphoreGive(mutex));
- con_printf("Task %s has released the mutex.\n", pcTaskGetTaskName(NULL));
- }
- static void taskStrangeMutexDemo(void * params) {
- while (1) {
- guardedMethod();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement