2929
3030#define MULTIPLE_THREADS_TASKS_NUM 5
3131
32- static int nb_of_success = 0 ;
32+ // Unlocked spinlock, ready to use
33+ static portMUX_TYPE _spinlock = portMUX_INITIALIZER_UNLOCKED ;
34+ static volatile int nb_of_success = 0 ;
3335
3436static void test_task_install (void * arg )
3537{
@@ -42,7 +44,9 @@ static void test_task_install(void *arg)
4244 if (tinyusb_driver_install (& tusb_cfg ) == ESP_OK ) {
4345 test_device_wait ();
4446 TEST_ASSERT_EQUAL (ESP_OK , tinyusb_driver_uninstall ());
47+ taskENTER_CRITICAL (& _spinlock );
4548 nb_of_success ++ ;
49+ taskEXIT_CRITICAL (& _spinlock );
4650 }
4751
4852 // Notify the parent task that the task completed the job
@@ -70,19 +74,20 @@ TEST_CASE("Multitask: Install", "[runtime_config][full_speed][high_speed]")
7074 };
7175 TEST_ASSERT_EQUAL_MESSAGE (ESP_OK , usb_new_phy (& phy_conf , & phy_hdl ), "Unable to install USB PHY " );
7276
77+ taskENTER_CRITICAL (& _spinlock );
7378 nb_of_success = 0 ;
79+ taskEXIT_CRITICAL (& _spinlock );
7480 // Create tasks that will start the driver
7581 for (int i = 0 ; i < MULTIPLE_THREADS_TASKS_NUM ; i ++ ) {
76- TEST_ASSERT_EQUAL (pdTRUE , xTaskCreate (test_task_install ,
82+ TEST_ASSERT_EQUAL (pdPASS , xTaskCreate (test_task_install ,
7783 "InstallTask" ,
7884 4096 ,
7985 (void * ) xTaskGetCurrentTaskHandle (),
8086 4 + i ,
8187 NULL ));
8288 }
83-
84- // Wait until all tasks are finished
85- vTaskDelay (pdMS_TO_TICKS (5000 ));
89+ // Wait some time for all tasks to complete
90+ vTaskDelay (pdMS_TO_TICKS (1000 ));
8691 // Check if all tasks finished, we should get all notification from the tasks
8792 TEST_ASSERT_EQUAL_MESSAGE (MULTIPLE_THREADS_TASKS_NUM , ulTaskNotifyTake (pdTRUE , pdMS_TO_TICKS (5000 )), "Not all tasks finished" );
8893 // There should be only one task that was able to install the driver
0 commit comments